Skip to content

Commit c52ac2c

Browse files
committed
Fix XN297Dump enhanced payload detection
1 parent 09f39ea commit c52ac2c

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

Multiprotocol/XN297Dump_nrf24l01.ino

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,29 +119,34 @@ static boolean __attribute__((unused)) XN297Dump_process_packet(void)
119119
}
120120

121121
//Try enhanced payload
122-
crc = 0xb5d2;
122+
uint16_t crc_save = 0xb5d2;
123123
packet_length=0;
124-
for (uint8_t i = 0; i < XN297DUMP_MAX_PACKET_LEN-XN297DUMP_CRC_LENGTH; i++)
124+
for (uint8_t i = 0; i < XN297DUMP_MAX_PACKET_LEN-XN297DUMP_CRC_LENGTH; i++)
125125
{
126126
packet_sc[i]=packet[i]^xn297_scramble[i];
127+
crc = crc_save;
127128
crc16_update( packet[i], 8);
129+
crc_save = crc;
128130
crc16_update( packet[i+1] & 0xC0, 2);
129131
crcxored=(packet[i+1]<<10)|(packet[i+2]<<2)|(packet[i+3]>>6) ;
130-
if((crc ^ pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[i - 3])) == crcxored)
131-
{ // Found a valid CRC for the enhanced payload mode
132-
packet_length=i;
133-
scramble=true;
134-
i++;
135-
packet_sc[i]=packet[i]^xn297_scramble[i];
136-
memcpy(packet_un,packet_sc,packet_length+2); // unscramble packet
137-
break;
138-
}
139-
if((crc ^ pgm_read_word(&xn297_crc_xorout_enhanced[i - 3])) == crcxored)
140-
{ // Found a valid CRC for the enhanced payload mode
141-
packet_length=i;
142-
scramble=false;
143-
memcpy(packet_un,packet,packet_length+2); // packet is unscrambled
144-
break;
132+
if(i>=3)
133+
{
134+
if((crc ^ pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[i - 3])) == crcxored)
135+
{ // Found a valid CRC for the enhanced payload mode
136+
packet_length=i;
137+
scramble=true;
138+
i++;
139+
packet_sc[i]=packet[i]^xn297_scramble[i];
140+
memcpy(packet_un,packet_sc,packet_length+2); // unscramble packet
141+
break;
142+
}
143+
if((crc ^ pgm_read_word(&xn297_crc_xorout_enhanced[i - 3])) == crcxored)
144+
{ // Found a valid CRC for the enhanced payload mode
145+
packet_length=i;
146+
scramble=false;
147+
memcpy(packet_un,packet,packet_length+2); // packet is unscrambled
148+
break;
149+
}
145150
}
146151
}
147152
if(packet_length!=0)
@@ -324,7 +329,7 @@ static uint16_t XN297Dump_callback()
324329
switch(bitrate)
325330
{
326331
case XN297DUMP_250K:
327-
XN297_Configure(XN297_CRCEN, scramble?XN297_SCRAMBLED:XN297_UNSCRAMBLED, XN297_250K);
332+
XN297_Configure(XN297_CRCEN, scramble?XN297_SCRAMBLED:XN297_UNSCRAMBLED, XN297_250K, true);
328333
debug("250K");
329334
break;
330335
case XN297DUMP_2M:

Multiprotocol/XN297_EMU.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ const uint16_t xn297_crc_xorout_enhanced[] = {
5353
0xABFC, 0xE68E, 0x0DE7, 0x28A2, 0x1965 };
5454
#endif
5555

56-
static bool __attribute__((unused)) XN297_Configure(bool crc_en, bool scramble_en, bool bitrate)
56+
static bool __attribute__((unused)) XN297_Configure(bool crc_en, bool scramble_en, bool bitrate, bool force_nrf)
5757
{
5858
xn297_crc = crc_en;
5959
xn297_scramble_enabled = scramble_en;
6060
xn297_bitrate = bitrate;
6161
xn297_rf = XN297_NRF;
6262

6363
#if defined(NRF24L01_INSTALLED) and defined(CC2500_INSTALLED)
64-
if(bitrate == XN297_1M)
64+
if(bitrate == XN297_1M || force_nrf)
6565
xn297_rf = XN297_NRF; // Use NRF24L01
6666
else
6767
xn297_rf = XN297_CC2500; // Use CC2500

Multiprotocol/iface_xn297.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
//////////////
2525
// Functions
26-
static bool __attribute__((unused)) XN297_Configure(bool, bool, bool);
26+
static bool __attribute__((unused)) XN297_Configure(bool, bool, bool, bool force_nrf=false);
2727
static void __attribute__((unused)) XN297_SetTXAddr(const uint8_t*, uint8_t);
2828
static void __attribute__((unused)) XN297_SetRXAddr(const uint8_t*, uint8_t);
2929
static void __attribute__((unused)) XN297_SetTxRxMode(enum TXRX_State);

0 commit comments

Comments
 (0)