mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2026-12-06 07:37:38 +00:00
XN297 emu: CRC xorout for unscrambled enhanced mode (#1206)
XN297_WriteEnhancedPayload() and XN297_ReadEnhancedPayload() (outside XN297Dump builds) started the CRC from 0xB5D2 without the final XOR when scrambling is off, unlike the normal payloads and XN297Dump, which receives unscrambled enhanced packets with the xorout. Now TX and RX start from 0xFFFF and end with ~crc ^ (xn297_lfsr >> 14) in all modes, as the normal payloads do: xn297_lfsr is 0 when scrambling is off. No protocol uses unscrambled enhanced mode so far; STM32 -48 bytes.
This commit is contained in:
1 parent
fc6814b705
commit
b2507527d6
1 file changed
+4
-11
@@ -315,7 +315,7 @@ static void __attribute__((unused)) XN297_WriteEnhancedPayload(uint8_t* msg, uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// address
|
// address
|
||||||
crc = xn297_scramble_enabled ? 0xFFFF : 0xB5D2; // unscrambled: no xorout
|
crc = 0xFFFF;
|
||||||
XN297_scramble_init();
|
XN297_scramble_init();
|
||||||
for (uint8_t i = 0; i < xn297_addr_len; ++i)
|
for (uint8_t i = 0; i < xn297_addr_len; ++i)
|
||||||
buf[last++] = XN297_crc_scramble(xn297_tx_addr[xn297_addr_len-i-1]);
|
buf[last++] = XN297_crc_scramble(xn297_tx_addr[xn297_addr_len-i-1]);
|
||||||
@@ -344,8 +344,7 @@ static void __attribute__((unused)) XN297_WriteEnhancedPayload(uint8_t* msg, uin
|
|||||||
// crc
|
// crc
|
||||||
if (xn297_crc)
|
if (xn297_crc)
|
||||||
{
|
{
|
||||||
if (xn297_scramble_enabled)
|
crc = ~crc ^ (xn297_lfsr >> 14);
|
||||||
crc = ~crc ^ (xn297_lfsr >> 14);
|
|
||||||
|
|
||||||
buf[last++] |= (crc >> 8) >> 2;
|
buf[last++] |= (crc >> 8) >> 2;
|
||||||
buf[last++] = ((crc >> 8) << 6) | ((crc & 0xff) >> 2);
|
buf[last++] = ((crc >> 8) << 6) | ((crc & 0xff) >> 2);
|
||||||
@@ -428,12 +427,7 @@ static uint8_t __attribute__((unused)) XN297_ReadEnhancedPayload(uint8_t* msg, u
|
|||||||
// Read payload
|
// Read payload
|
||||||
XN297_ReceivePayload(buffer, len+2); // Read pcf + payload + CRC
|
XN297_ReceivePayload(buffer, len+2); // Read pcf + payload + CRC
|
||||||
// Decode payload, calculate CRC
|
// Decode payload, calculate CRC
|
||||||
#ifdef XN297DUMP_NRF24L01_INO
|
crc = 0xFFFF;
|
||||||
bool xorout = true;
|
|
||||||
#else
|
|
||||||
bool xorout = xn297_scramble_enabled; // unscrambled: no xorout
|
|
||||||
#endif
|
|
||||||
crc = xorout ? 0xFFFF : 0xB5D2;
|
|
||||||
XN297_scramble_init();
|
XN297_scramble_init();
|
||||||
for (uint8_t i = 0; i < xn297_addr_len; ++i)
|
for (uint8_t i = 0; i < xn297_addr_len; ++i)
|
||||||
XN297_unscramble_crc(xn297_rx_addr[xn297_addr_len-i-1]);
|
XN297_unscramble_crc(xn297_rx_addr[xn297_addr_len-i-1]);
|
||||||
@@ -450,8 +444,7 @@ static uint8_t __attribute__((unused)) XN297_ReadEnhancedPayload(uint8_t* msg, u
|
|||||||
if (!xn297_crc)
|
if (!xn297_crc)
|
||||||
return pcf_size; // No CRC so OK by default...
|
return pcf_size; // No CRC so OK by default...
|
||||||
|
|
||||||
if (xorout)
|
crc = ~crc ^ (xn297_lfsr >> 14);
|
||||||
crc = ~crc ^ (xn297_lfsr >> 14);
|
|
||||||
uint16_t crcxored=(buffer[pcf_size+1]<<10)|(buffer[pcf_size+2]<<2)|(buffer[pcf_size+3]>>6) ;
|
uint16_t crcxored=(buffer[pcf_size+1]<<10)|(buffer[pcf_size+2]<<2)|(buffer[pcf_size+3]>>6) ;
|
||||||
if( crc == crcxored)
|
if( crc == crcxored)
|
||||||
return pcf_size; // CRC OK
|
return pcf_size; // CRC OK
|
||||||
|
|||||||
Reference in new issue
Block a user