mirror of
				https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
				synced 2025-10-30 02:21:05 +00:00 
			
		
		
		
	Fix CRC in various places
This commit is contained in:
		
							parent
							
								
									502e8beafb
								
							
						
					
					
						commit
						6f419adb7f
					
				| @ -19,17 +19,17 @@ | ||||
| 
 | ||||
| #include "iface_nrf24l01.h" | ||||
| 
 | ||||
| #define CX10_BIND_COUNT		4360   // 6 seconds
 | ||||
| #define CX10_BIND_COUNT		4360	// 6 seconds
 | ||||
| #define CX10_PACKET_SIZE	15 | ||||
| #define CX10A_PACKET_SIZE	19       // CX10 blue board packets have 19-byte payload
 | ||||
| #define CX10A_PACKET_SIZE	19		// CX10 blue board packets have 19-byte payload
 | ||||
| #define Q2X2_PACKET_SIZE	21 | ||||
| #define CX10_PACKET_PERIOD	1316  // Timeout for callback in uSec
 | ||||
| #define CX10_PACKET_PERIOD	1316	// Timeout for callback in uSec
 | ||||
| #define CX10A_PACKET_PERIOD	6000 | ||||
| 
 | ||||
| #define CX10_INITIAL_WAIT     500 | ||||
| 
 | ||||
| // flags
 | ||||
| #define CX10_FLAG_FLIP       0x10 // goes to rudder channel
 | ||||
| #define CX10_FLAG_FLIP       0x10	// goes to rudder channel
 | ||||
| #define CX10_FLAG_MODE_MASK  0x03 | ||||
| #define CX10_FLAG_HEADLESS   0x04 | ||||
| // flags2
 | ||||
| @ -181,7 +181,7 @@ static void __attribute__((unused)) CX10_init() | ||||
| 	NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00);				// No Auto Acknowledgment on all data pipes
 | ||||
| 	NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, 0x01);			// Enable data pipe 0 only
 | ||||
| 	NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, packet_length);	// rx pipe 0 (used only for blue board)
 | ||||
|     NRF24L01_WriteReg(NRF24L01_05_RF_CH, CX10_RF_BIND_CHANNEL); | ||||
| 	NRF24L01_WriteReg(NRF24L01_05_RF_CH, CX10_RF_BIND_CHANNEL); | ||||
| 	NRF24L01_SetBitrate(NRF24L01_BR_1M);					// 1Mbps
 | ||||
| 	NRF24L01_SetPower(); | ||||
| } | ||||
| @ -220,7 +220,8 @@ uint16_t CX10_callback() | ||||
| 				NRF24L01_FlushTx(); | ||||
| 				NRF24L01_SetTxRxMode(TX_EN); | ||||
| 				CX10_Write_Packet(1); | ||||
| 				delayMicroseconds(400); | ||||
| 				// wait for packet to be sent
 | ||||
| 				while( (NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS)) == 0);	//delayMicroseconds(400);
 | ||||
| 				// switch to RX mode
 | ||||
| 				NRF24L01_SetTxRxMode(TXRX_OFF); | ||||
| 				NRF24L01_FlushRx(); | ||||
|  | ||||
| @ -168,10 +168,10 @@ void CYRF_SetPower(uint8_t val) | ||||
| /*
 | ||||
| * | ||||
| */ | ||||
| void CYRF_ConfigCRCSeed(uint16_t crc) | ||||
| void CYRF_ConfigCRCSeed(uint16_t crc_seed) | ||||
| { | ||||
| 	CYRF_WriteRegister(CYRF_15_CRC_SEED_LSB,crc & 0xff); | ||||
| 	CYRF_WriteRegister(CYRF_16_CRC_SEED_MSB,crc >> 8); | ||||
| 	CYRF_WriteRegister(CYRF_15_CRC_SEED_LSB,crc_seed & 0xff); | ||||
| 	CYRF_WriteRegister(CYRF_16_CRC_SEED_MSB,crc_seed >> 8); | ||||
| } | ||||
| /*
 | ||||
| * these are the recommended sop codes from Cyrpress | ||||
|  | ||||
| @ -38,7 +38,7 @@ enum{ | ||||
| #define HONTAI_POLY 0x8408 | ||||
| static void __attribute__((unused)) crc16(uint8_t *data_p, uint8_t length) | ||||
| { | ||||
| 	uint16_t crc = 0xffff; | ||||
| 	crc = 0xffff; | ||||
| 
 | ||||
| 	length -= 2; | ||||
| 	do | ||||
|  | ||||
| @ -111,8 +111,8 @@ static void __attribute__((unused)) cyrf_datainit() | ||||
| { | ||||
|     /* Use when already bound */ | ||||
|     uint8_t sop_idx = (0xff & (cyrfmfg_id[0] + cyrfmfg_id[1] + cyrfmfg_id[2] + cyrfmfg_id[3] - cyrfmfg_id[5])) % 19; | ||||
|     uint16_t crc =  (0xff & (cyrfmfg_id[1] - cyrfmfg_id[4] + cyrfmfg_id[5])) | | ||||
|                    ((0xff & (cyrfmfg_id[2] + cyrfmfg_id[3] - cyrfmfg_id[4] + cyrfmfg_id[5])) << 8); | ||||
|     crc =  (0xff & (cyrfmfg_id[1] - cyrfmfg_id[4] + cyrfmfg_id[5])) | | ||||
|            ((0xff & (cyrfmfg_id[2] + cyrfmfg_id[3] - cyrfmfg_id[4] + cyrfmfg_id[5])) << 8); | ||||
|     //CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x24);
 | ||||
|     CYRF_PROGMEM_ConfigSOPCode(DEVO_j6pro_sopcodes[sop_idx]); | ||||
|     CYRF_ConfigCRCSeed(crc); | ||||
|  | ||||
| @ -19,7 +19,7 @@ | ||||
| #define VERSION_MAJOR		1 | ||||
| #define VERSION_MINOR		3 | ||||
| #define VERSION_REVISION	2 | ||||
| #define VERSION_PATCH_LEVEL	3 | ||||
| #define VERSION_PATCH_LEVEL	4 | ||||
| 
 | ||||
| //******************
 | ||||
| // Protocols
 | ||||
|  | ||||
| @ -58,7 +58,7 @@ static void __attribute__((unused)) NCC_init() | ||||
| const uint8_t NCC_xor[]={0x80, 0x44, 0x64, 0x75, 0x6C, 0x71, 0x2A, 0x36, 0x7C, 0xF1, 0x6E, 0x52, 0x09, 0x9D}; | ||||
| static void __attribute__((unused)) NCC_Crypt_Packet() | ||||
| { | ||||
| 	uint16_t crc=0; | ||||
| 	crc=0; | ||||
| 	for(uint8_t i=0; i< NCC_TX_PACKET_LEN-2; i++) | ||||
| 	{ | ||||
| 		packet[i]^=NCC_xor[i]; | ||||
| @ -70,7 +70,7 @@ static void __attribute__((unused)) NCC_Crypt_Packet() | ||||
| } | ||||
| static boolean __attribute__((unused)) NCC_Decrypt_Packet() | ||||
| { | ||||
| 	uint16_t crc=0; | ||||
| 	crc=0; | ||||
| 	debug("RX: "); | ||||
| 	for(uint8_t i=0; i< NCC_RX_PACKET_LEN-2; i++) | ||||
| 	{ | ||||
|  | ||||
| @ -378,7 +378,7 @@ void XN297_WritePayload(uint8_t* msg, uint8_t len) | ||||
| 	if (xn297_crc) | ||||
| 	{ | ||||
| 		uint8_t offset = xn297_addr_len < 4 ? 1 : 0; | ||||
| 		uint16_t crc = 0xb5d2; | ||||
| 		crc = 0xb5d2; | ||||
| 		for (uint8_t i = offset; i < last; ++i) | ||||
| 			crc16_update( buf[i], 8); | ||||
| 		if(xn297_scramble_enabled) | ||||
| @ -443,7 +443,7 @@ void XN297_WriteEnhancedPayload(uint8_t* msg, uint8_t len, uint8_t noack) | ||||
| 	if (xn297_crc) | ||||
| 	{ | ||||
| 		uint8_t offset = xn297_addr_len < 4 ? 1 : 0; | ||||
| 		uint16_t crc = 0xb5d2; | ||||
| 		crc = 0xb5d2; | ||||
| 		for (uint8_t i = offset; i < last; ++i) | ||||
| 			crc16_update( packet[i], 8); | ||||
| 		crc16_update( packet[last] & 0xc0, 2); | ||||
| @ -482,7 +482,7 @@ boolean XN297_ReadPayload(uint8_t* msg, uint8_t len) | ||||
| 		return true;	// No CRC so OK by default...
 | ||||
| 
 | ||||
| 	// Calculate CRC
 | ||||
| 	uint16_t crc = 0xb5d2; | ||||
| 	crc = 0xb5d2; | ||||
| 	//process address
 | ||||
| 	for (uint8_t i = 0; i < xn297_addr_len; ++i) | ||||
| 	{ | ||||
| @ -529,7 +529,7 @@ uint8_t XN297_ReadEnhancedPayload(uint8_t* msg, uint8_t len) | ||||
| 		return pcf_size;	// No CRC so OK by default...
 | ||||
| 
 | ||||
| 	// Calculate CRC
 | ||||
| 	uint16_t crc = 0xb5d2; | ||||
| 	crc = 0xb5d2; | ||||
| 	//process address
 | ||||
| 	for (uint8_t i = 0; i < xn297_addr_len; ++i) | ||||
| 	{ | ||||
| @ -775,7 +775,8 @@ void LT8900_SetAddress(uint8_t *address,uint8_t addr_size) | ||||
| uint8_t LT8900_ReadPayload(uint8_t* msg, uint8_t len) | ||||
| { | ||||
| 	uint8_t i,pos=0,shift,end,buffer[32]; | ||||
| 	unsigned int crc=LT8900_CRC_Initial_Data,a; | ||||
| 	unsigned int a; | ||||
| 	crc=LT8900_CRC_Initial_Data; | ||||
| 	pos=LT8900_buffer_overhead_bits/8-LT8900_buffer_start; | ||||
| 	end=pos+len+(LT8900_Flags&_BV(LT8900_PACKET_LENGTH_EN)?1:0)+(LT8900_Flags&_BV(LT8900_CRC_ON)?2:0); | ||||
| 	//Read payload
 | ||||
| @ -817,8 +818,9 @@ uint8_t LT8900_ReadPayload(uint8_t* msg, uint8_t len) | ||||
| 
 | ||||
| void LT8900_WritePayload(uint8_t* msg, uint8_t len) | ||||
| { | ||||
| 	unsigned int crc=LT8900_CRC_Initial_Data,a,mask; | ||||
| 	unsigned int a,mask; | ||||
| 	uint8_t i, pos=0,tmp, buffer[64], pos_final,shift; | ||||
| 	crc=LT8900_CRC_Initial_Data; | ||||
| 	//Add packet len
 | ||||
| 	if(LT8900_Flags&_BV(LT8900_PACKET_LENGTH_EN)) | ||||
| 	{ | ||||
|  | ||||
| @ -146,7 +146,7 @@ static void __attribute__((unused)) XN297L_WritePayload(uint8_t* msg, uint8_t le | ||||
| 		} | ||||
| 
 | ||||
| 		// crc
 | ||||
| 		uint16_t crc = 0xb5d2; | ||||
| 		crc = 0xb5d2; | ||||
| 		for (uint8_t i = 0; i < last; ++i) | ||||
| 			crc16_update( buf[i], 8); | ||||
| 		if(xn297_scramble_enabled) | ||||
| @ -227,7 +227,7 @@ static void __attribute__((unused)) XN297L_WriteEnhancedPayload(uint8_t* msg, ui | ||||
| 		// crc
 | ||||
| 		//if (xn297_crc)
 | ||||
| 		{ | ||||
| 			uint16_t crc = 0xb5d2; | ||||
| 			crc = 0xb5d2; | ||||
| 			for (uint8_t i = 0; i < last; ++i) | ||||
| 				crc16_update( buf[i], 8); | ||||
| 			crc16_update( buf[last] & 0xc0, 2); | ||||
| @ -396,7 +396,7 @@ static void __attribute__((unused)) NRF250K_WritePayload(uint8_t* msg, uint8_t l | ||||
| 			buf[last++] = msg[i]; | ||||
| 
 | ||||
| 		// crc
 | ||||
| 		uint16_t crc = 0xffff; | ||||
| 		crc = 0xffff; | ||||
| 		for (uint8_t i = 1; i < last; ++i) | ||||
| 			crc16_update( buf[i], 8); | ||||
| 		buf[last++] = crc >> 8; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user