Fix CRC in various places

This commit is contained in:
Pascal Langer 2021-01-16 16:50:45 +01:00
parent 502e8beafb
commit 6f419adb7f
8 changed files with 27 additions and 24 deletions

View File

@ -220,7 +220,8 @@ uint16_t CX10_callback()
NRF24L01_FlushTx(); NRF24L01_FlushTx();
NRF24L01_SetTxRxMode(TX_EN); NRF24L01_SetTxRxMode(TX_EN);
CX10_Write_Packet(1); 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 // switch to RX mode
NRF24L01_SetTxRxMode(TXRX_OFF); NRF24L01_SetTxRxMode(TXRX_OFF);
NRF24L01_FlushRx(); NRF24L01_FlushRx();

View File

@ -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_15_CRC_SEED_LSB,crc_seed & 0xff);
CYRF_WriteRegister(CYRF_16_CRC_SEED_MSB,crc >> 8); CYRF_WriteRegister(CYRF_16_CRC_SEED_MSB,crc_seed >> 8);
} }
/* /*
* these are the recommended sop codes from Cyrpress * these are the recommended sop codes from Cyrpress

View File

@ -38,7 +38,7 @@ enum{
#define HONTAI_POLY 0x8408 #define HONTAI_POLY 0x8408
static void __attribute__((unused)) crc16(uint8_t *data_p, uint8_t length) static void __attribute__((unused)) crc16(uint8_t *data_p, uint8_t length)
{ {
uint16_t crc = 0xffff; crc = 0xffff;
length -= 2; length -= 2;
do do

View File

@ -111,7 +111,7 @@ static void __attribute__((unused)) cyrf_datainit()
{ {
/* Use when already bound */ /* 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; 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])) | 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); ((0xff & (cyrfmfg_id[2] + cyrfmfg_id[3] - cyrfmfg_id[4] + cyrfmfg_id[5])) << 8);
//CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x24); //CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x24);
CYRF_PROGMEM_ConfigSOPCode(DEVO_j6pro_sopcodes[sop_idx]); CYRF_PROGMEM_ConfigSOPCode(DEVO_j6pro_sopcodes[sop_idx]);

View File

@ -19,7 +19,7 @@
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 3 #define VERSION_MINOR 3
#define VERSION_REVISION 2 #define VERSION_REVISION 2
#define VERSION_PATCH_LEVEL 3 #define VERSION_PATCH_LEVEL 4
//****************** //******************
// Protocols // Protocols

View File

@ -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}; 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() 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++) for(uint8_t i=0; i< NCC_TX_PACKET_LEN-2; i++)
{ {
packet[i]^=NCC_xor[i]; packet[i]^=NCC_xor[i];
@ -70,7 +70,7 @@ static void __attribute__((unused)) NCC_Crypt_Packet()
} }
static boolean __attribute__((unused)) NCC_Decrypt_Packet() static boolean __attribute__((unused)) NCC_Decrypt_Packet()
{ {
uint16_t crc=0; crc=0;
debug("RX: "); debug("RX: ");
for(uint8_t i=0; i< NCC_RX_PACKET_LEN-2; i++) for(uint8_t i=0; i< NCC_RX_PACKET_LEN-2; i++)
{ {

View File

@ -378,7 +378,7 @@ void XN297_WritePayload(uint8_t* msg, uint8_t len)
if (xn297_crc) if (xn297_crc)
{ {
uint8_t offset = xn297_addr_len < 4 ? 1 : 0; uint8_t offset = xn297_addr_len < 4 ? 1 : 0;
uint16_t crc = 0xb5d2; crc = 0xb5d2;
for (uint8_t i = offset; i < last; ++i) for (uint8_t i = offset; i < last; ++i)
crc16_update( buf[i], 8); crc16_update( buf[i], 8);
if(xn297_scramble_enabled) if(xn297_scramble_enabled)
@ -443,7 +443,7 @@ void XN297_WriteEnhancedPayload(uint8_t* msg, uint8_t len, uint8_t noack)
if (xn297_crc) if (xn297_crc)
{ {
uint8_t offset = xn297_addr_len < 4 ? 1 : 0; uint8_t offset = xn297_addr_len < 4 ? 1 : 0;
uint16_t crc = 0xb5d2; crc = 0xb5d2;
for (uint8_t i = offset; i < last; ++i) for (uint8_t i = offset; i < last; ++i)
crc16_update( packet[i], 8); crc16_update( packet[i], 8);
crc16_update( packet[last] & 0xc0, 2); 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... return true; // No CRC so OK by default...
// Calculate CRC // Calculate CRC
uint16_t crc = 0xb5d2; crc = 0xb5d2;
//process address //process address
for (uint8_t i = 0; i < xn297_addr_len; ++i) 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... return pcf_size; // No CRC so OK by default...
// Calculate CRC // Calculate CRC
uint16_t crc = 0xb5d2; crc = 0xb5d2;
//process address //process address
for (uint8_t i = 0; i < xn297_addr_len; ++i) 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 LT8900_ReadPayload(uint8_t* msg, uint8_t len)
{ {
uint8_t i,pos=0,shift,end,buffer[32]; 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; 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); end=pos+len+(LT8900_Flags&_BV(LT8900_PACKET_LENGTH_EN)?1:0)+(LT8900_Flags&_BV(LT8900_CRC_ON)?2:0);
//Read payload //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) 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; uint8_t i, pos=0,tmp, buffer[64], pos_final,shift;
crc=LT8900_CRC_Initial_Data;
//Add packet len //Add packet len
if(LT8900_Flags&_BV(LT8900_PACKET_LENGTH_EN)) if(LT8900_Flags&_BV(LT8900_PACKET_LENGTH_EN))
{ {

View File

@ -146,7 +146,7 @@ static void __attribute__((unused)) XN297L_WritePayload(uint8_t* msg, uint8_t le
} }
// crc // crc
uint16_t crc = 0xb5d2; crc = 0xb5d2;
for (uint8_t i = 0; i < last; ++i) for (uint8_t i = 0; i < last; ++i)
crc16_update( buf[i], 8); crc16_update( buf[i], 8);
if(xn297_scramble_enabled) if(xn297_scramble_enabled)
@ -227,7 +227,7 @@ static void __attribute__((unused)) XN297L_WriteEnhancedPayload(uint8_t* msg, ui
// crc // crc
//if (xn297_crc) //if (xn297_crc)
{ {
uint16_t crc = 0xb5d2; crc = 0xb5d2;
for (uint8_t i = 0; i < last; ++i) for (uint8_t i = 0; i < last; ++i)
crc16_update( buf[i], 8); crc16_update( buf[i], 8);
crc16_update( buf[last] & 0xc0, 2); 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]; buf[last++] = msg[i];
// crc // crc
uint16_t crc = 0xffff; crc = 0xffff;
for (uint8_t i = 1; i < last; ++i) for (uint8_t i = 1; i < last; ++i)
crc16_update( buf[i], 8); crc16_update( buf[i], 8);
buf[last++] = crc >> 8; buf[last++] = crc >> 8;