@@ -92,15 +92,15 @@ static boolean __attribute__((unused)) XN297Dump_process_packet(void)
9292 // address
9393 for (uint8_t i = 0 ; i < address_length; i++)
9494 {
95- crc = crc16_update (crc, packet[i], 8 );
95+ crc16_update ( packet[i], 8 );
9696 packet_un[address_length-1 -i]=packet[i];
9797 packet_sc[address_length-1 -i]=packet[i] ^ xn297_scramble[i];
9898 }
9999
100100 // payload
101101 for (uint8_t i = address_length; i < XN297DUMP_MAX_PACKET_LEN-XN297DUMP_CRC_LENGTH; i++)
102102 {
103- crc = crc16_update (crc, packet[i], 8 );
103+ crc16_update ( packet[i], 8 );
104104 packet_sc[i] = bit_reverse (packet[i]^xn297_scramble[i]);
105105 packet_un[i] = bit_reverse (packet[i]);
106106 // check crc
@@ -125,14 +125,13 @@ static boolean __attribute__((unused)) XN297Dump_process_packet(void)
125125 // Try enhanced payload
126126 crc = 0xb5d2 ;
127127 packet_length=0 ;
128- uint16_t crc_enh;
129128 for (uint8_t i = 0 ; i < XN297DUMP_MAX_PACKET_LEN-XN297DUMP_CRC_LENGTH; i++)
130129 {
131130 packet_sc[i]=packet[i]^xn297_scramble[i];
132- crc = crc16_update (crc, packet[i], 8 );
133- crc_enh = crc16_update (crc, packet[i+1 ] & 0xC0 , 2 );
131+ crc16_update ( packet[i], 8 );
132+ crc16_update ( packet[i+1 ] & 0xC0 , 2 );
134133 crcxored=(packet[i+1 ]<<10 )|(packet[i+2 ]<<2 )|(packet[i+3 ]>>6 ) ;
135- if ((crc_enh ^ pgm_read_word (&xn297_crc_xorout_scrambled_enhanced[i - 3 ])) == crcxored)
134+ if ((crc ^ pgm_read_word (&xn297_crc_xorout_scrambled_enhanced[i - 3 ])) == crcxored)
136135 { // Found a valid CRC for the enhanced payload mode
137136 packet_length=i;
138137 scramble=true ;
@@ -141,7 +140,7 @@ static boolean __attribute__((unused)) XN297Dump_process_packet(void)
141140 memcpy (packet_un,packet_sc,packet_length+2 ); // unscramble packet
142141 break ;
143142 }
144- if ((crc_enh ^ pgm_read_word (&xn297_crc_xorout_enhanced[i - 3 ])) == crcxored)
143+ if ((crc ^ pgm_read_word (&xn297_crc_xorout_enhanced[i - 3 ])) == crcxored)
145144 { // Found a valid CRC for the enhanced payload mode
146145 packet_length=i;
147146 scramble=false ;
@@ -629,10 +628,10 @@ static uint16_t XN297Dump_callback()
629628 if (phase==0 )
630629 {
631630 address_length=4 ;
632- memcpy (rx_tx_addr, (uint8_t *)" \xE7\xE7\xE7\xE7 " , 4 );
633- bitrate=XN297DUMP_250K ;
634- packet_length=14 ;
635- hopping_frequency_no=5 ; // bind 5 , normal 44
631+ memcpy (rx_tx_addr, (uint8_t *)" \xEE\x96\x54\x0E " , address_length );
632+ bitrate=XN297DUMP_1M ;
633+ packet_length=32 ;
634+ hopping_frequency_no=48 ; // bind ? , normal 48
636635
637636 NRF24L01_Initialize ();
638637 NRF24L01_SetTxRxMode (TXRX_OFF);
@@ -679,23 +678,59 @@ static uint16_t XN297Dump_callback()
679678 if (NRF24L01_ReadReg (NRF24L01_09_CD))
680679 {
681680 NRF24L01_ReadPayload (packet, packet_length);
682- crc=0 ;
681+ #define XN_DEB 0 // 6 //0
682+ #define XN_LON 32 // 4 //32
683+ bool ok=true ;
684+ uint8_t buffer[40 ];
685+ memcpy (buffer,packet,packet_length);
686+ if (memcmp (&packet_in[XN_DEB],&packet[XN_DEB],XN_LON))
687+ {
688+ // realign bits
689+ for (uint8_t i=0 ; i<packet_length; i++)
690+ buffer[i]=buffer[i+2 ];
691+
692+ // check for validity and decode
693+ memset (packet_in,0 ,packet_length);
694+ for (uint8_t i=0 ; i<packet_length-2 ; i++)
695+ {
696+ for (uint8_t j=0 ;j<2 ;j++)
697+ {
698+ packet_in[i>>2 ] >>= 1 ;
699+ if ( (buffer[i]&0xC0 ) == 0xC0 && (buffer[i]&0x30 ) == 0x00 )
700+ packet_in[i>>2 ] |= 0x80 ;
701+ else if ( (buffer[i]&0xC0 ) == 0x00 && (buffer[i]&0x30 ) == 0x30 )
702+ packet_in[i>>2 ] |= 0x00 ;
703+ else
704+ ok=false ; // error
705+ buffer[i] <<= 4 ;
706+ }
707+ }
708+ if (ok)
709+ {
710+ debug (" P:(%02X,%02X):" ,packet[0 ],packet[1 ]);
711+ for (uint8_t i=0 ;i<packet_length/4 ;i++)
712+ debug (" %02X" ,packet_in[i]);
713+ debugln (" " );
714+ memcpy (packet_in,packet,packet_length);
715+ }
716+ }
717+ /* crc=0;
683718 for (uint8_t i = 1; i < 12; ++i)
684- crc = crc16_update (crc, packet[i], 8 );
719+ crc16_update( packet[i], 8);
685720 if(packet[12]==((crc>>8)&0xFF) && packet[13]==(crc&0xFF))
686721 if(memcmp(&packet_in[1],&packet[1],packet_length-1))
687722 {
688723 /*debug("P:");
689724 for(uint8_t i=0;i<packet_length;i++)
690725 debug(" %02X",packet[i]);
691726 debug(" CRC: %04X",crc);
692- debugln("");*/
727+ debugln("");
693728 debug("P(%02X):",packet[0]);
694729 for(uint8_t i=1;i<packet_length-2;i++)
695730 debug(" %02X",((bit_reverse(packet[i])<<1)|(bit_reverse(packet[i-1])>>7))&0xFF);
696731 debugln("");
697732 memcpy(packet_in,packet,packet_length);
698- }
733+ }*/
699734 }
700735 // restart RX mode
701736 NRF24L01_WriteReg (NRF24L01_07_STATUS, 0x70 ); // Clear data ready, data sent, and retransmit
0 commit comments