mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 16:48:10 +00:00
Add XN297 Dump protocol
Protocol number: 63 Sub protocols: 0=250Kb, 1=1Mb, 2=2Mb Option: -1=scan RF channels, 0-84=RF channel DEBUG_SERIAL must be enabled If a valid frame is received the frame will be sent on the serial port.
This commit is contained in:
parent
2dcb6b1987
commit
6748f6ce78
@ -109,8 +109,6 @@ static uint8_t tx_payload_len = 0; // Length of the packet stored in packet
|
||||
static uint8_t rx_payload_len = 0; // Length of the packet stored in rx_packet
|
||||
static uint8_t rx_packet[MAX_PACKET_SIZE]; // For reading in ACK payloads
|
||||
|
||||
static uint16_t cflie_counter;
|
||||
static uint32_t packet_counter;
|
||||
static uint8_t data_rate;
|
||||
|
||||
enum {
|
||||
@ -194,8 +192,6 @@ static void send_packet()
|
||||
// Transmit the payload
|
||||
NRF24L01_WritePayload(packet, tx_payload_len);
|
||||
|
||||
++packet_counter;
|
||||
|
||||
// // Check and adjust transmission power.
|
||||
NRF24L01_SetPower();
|
||||
}
|
||||
@ -256,7 +252,6 @@ static void send_search_packet()
|
||||
|
||||
NRF24L01_WritePayload(buf, sizeof(buf));
|
||||
|
||||
++packet_counter;
|
||||
}
|
||||
|
||||
// Frac 16.16
|
||||
@ -782,7 +777,6 @@ static uint16_t cflie_callback()
|
||||
break;
|
||||
case PKT_TIMEOUT:
|
||||
send_search_packet();
|
||||
cflie_counter = CFLIE_BIND_COUNT;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -45,4 +45,4 @@
|
||||
45,E01X,E012,E015,E016H
|
||||
46,V911S
|
||||
47,GD00X,V1,V2
|
||||
63,Test
|
||||
63,XN_DUMP,250K,1M,2M
|
||||
|
@ -19,7 +19,7 @@
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_REVISION 1
|
||||
#define VERSION_PATCH_LEVEL 39
|
||||
#define VERSION_PATCH_LEVEL 40
|
||||
|
||||
//******************
|
||||
// Protocols
|
||||
@ -74,7 +74,7 @@ enum PROTOCOLS
|
||||
PROTO_E01X = 45, // =>NRF24L01
|
||||
PROTO_V911S = 46, // =>NRF24L01
|
||||
PROTO_GD00X = 47, // =>NRF24L01
|
||||
PROTO_TEST = 63, // =>NRF24L01
|
||||
PROTO_XN297DUMP = 63, // =>NRF24L01
|
||||
};
|
||||
|
||||
enum Flysky
|
||||
|
@ -1222,10 +1222,10 @@ static void protocol_init()
|
||||
remote_callback = GD00X_callback;
|
||||
break;
|
||||
#endif
|
||||
#if defined(TEST_NRF24L01_INO)
|
||||
case PROTO_TEST:
|
||||
next_callback=initTest();
|
||||
remote_callback = Test_callback;
|
||||
#if defined(XN297DUMP_NRF24L01_INO)
|
||||
case PROTO_XN297DUMP:
|
||||
next_callback=initXN297Dump();
|
||||
remote_callback = XN297Dump_callback;
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
@ -1315,7 +1315,7 @@ void update_serial_data()
|
||||
else
|
||||
#endif
|
||||
option=rx_ok_buff[3]; // Use radio-defined option value
|
||||
|
||||
|
||||
#ifdef FAILSAFE_ENABLE
|
||||
bool failsafe=false;
|
||||
if(rx_ok_buff[0]&0x02)
|
||||
|
@ -303,3 +303,7 @@
|
||||
#if MAX_PPM_CHANNELS>16
|
||||
#error MAX_PPM_CHANNELS must be below or equal to 16. The default for this value is 16.
|
||||
#endif
|
||||
|
||||
#if defined (STM32_BOARD) && defined (DEBUG_SERIAL) && defined (NRF24L01_INSTALLED)
|
||||
#define XN297DUMP_NRF24L01_INO
|
||||
#endif
|
||||
|
198
Multiprotocol/XN297Dump_nrf24l01.ino
Normal file
198
Multiprotocol/XN297Dump_nrf24l01.ino
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
This project is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Multiprotocol is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef XN297DUMP_NRF24L01_INO
|
||||
|
||||
#include "iface_nrf24l01.h"
|
||||
|
||||
// Parameters which can be modified
|
||||
#define XN297DUMP_ADDRESS_LENGTH 5 // Default address length is 5, valid address length is between 3 and 5
|
||||
#define XN297DUMP_PERIOD_DUMP 2000 // Multiplied by 50, default 2000=100ms
|
||||
#define XN297DUMP_MAX_RF_CHANNEL 84 // Default 84
|
||||
|
||||
// Do not touch from there
|
||||
#define XN297DUMP_INITIAL_WAIT 500
|
||||
#define XN297DUMP_MAX_PACKET_LEN 32
|
||||
#define XN297DUMP_CRC_LENGTH 2
|
||||
|
||||
static void __attribute__((unused)) XN297Dump_init()
|
||||
{
|
||||
NRF24L01_Initialize();
|
||||
NRF24L01_SetTxRxMode(RX_EN);
|
||||
|
||||
NRF24L01_FlushTx();
|
||||
NRF24L01_FlushRx();
|
||||
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit
|
||||
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_03_SETUP_AW, 0x01); // 3 bytes RX/TX address
|
||||
NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, (uint8_t*)"\x55\x0F\x71", 3); // set up RX address to xn297 preamble
|
||||
NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, XN297DUMP_MAX_PACKET_LEN); // Enable rx pipe 0
|
||||
|
||||
debug("XN297 dump, scramble=%c, address length=%d, speed=",RX_num?'N':'Y', XN297DUMP_ADDRESS_LENGTH);
|
||||
switch(sub_protocol)
|
||||
{
|
||||
case 0:
|
||||
NRF24L01_SetBitrate(NRF24L01_BR_250K);
|
||||
debugln("250K");
|
||||
break;
|
||||
case 2:
|
||||
NRF24L01_SetBitrate(NRF24L01_BR_2M);
|
||||
debugln("2M");
|
||||
break;
|
||||
default:
|
||||
NRF24L01_SetBitrate(NRF24L01_BR_1M);
|
||||
debugln("1M");
|
||||
break;
|
||||
|
||||
}
|
||||
NRF24L01_Activate(0x73); // Activate feature register
|
||||
NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes
|
||||
NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x01);
|
||||
NRF24L01_Activate(0x73);
|
||||
NRF24L01_SetPower();
|
||||
}
|
||||
|
||||
static boolean __attribute__((unused)) XN297Dump_process_packet(void)
|
||||
{
|
||||
uint8_t packet_ori[XN297DUMP_MAX_PACKET_LEN];
|
||||
memcpy(packet_ori,packet,XN297DUMP_MAX_PACKET_LEN);
|
||||
packet_length=XN297DUMP_MAX_PACKET_LEN-XN297DUMP_CRC_LENGTH;
|
||||
|
||||
while(packet_length > XN297DUMP_ADDRESS_LENGTH)
|
||||
{
|
||||
// init crc
|
||||
crc = 0xb5d2;
|
||||
|
||||
// unscramble address
|
||||
for (uint8_t i = 0; i < XN297DUMP_ADDRESS_LENGTH; i++)
|
||||
{
|
||||
crc = crc16_update(crc, packet[i], 8);
|
||||
rx_id[i]=packet[i];
|
||||
if (!RX_num)
|
||||
rx_id[i] ^= xn297_scramble[i];
|
||||
}
|
||||
// reverse address order
|
||||
for (uint8_t i = 0; i < XN297DUMP_ADDRESS_LENGTH; i++)
|
||||
packet[i]=rx_id[XN297DUMP_ADDRESS_LENGTH-1-i];
|
||||
|
||||
// unscramble payload
|
||||
for (uint8_t i = XN297DUMP_ADDRESS_LENGTH; i < packet_length; i++)
|
||||
{
|
||||
crc = crc16_update(crc, packet[i], 8);
|
||||
if (!RX_num)
|
||||
packet[i] ^= xn297_scramble[i];
|
||||
packet[i] = bit_reverse(packet[i]);
|
||||
}
|
||||
|
||||
// check crc
|
||||
if (RX_num)
|
||||
crc ^= pgm_read_word(&xn297_crc_xorout[packet_length - 3]);
|
||||
else
|
||||
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[packet_length - 3]);
|
||||
if( (crc >> 8) == packet[packet_length] && (crc & 0xff) == packet[packet_length + 1])
|
||||
return true;
|
||||
packet_length--;
|
||||
memcpy(packet,packet_ori,XN297DUMP_MAX_PACKET_LEN);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint16_t XN297Dump_callback()
|
||||
{
|
||||
if(option==0xFF && bind_counter>XN297DUMP_PERIOD_DUMP)
|
||||
{ // Scan frequencies
|
||||
hopping_frequency_no++;
|
||||
bind_counter=0;
|
||||
}
|
||||
if(hopping_frequency_no!=rf_ch_num)
|
||||
{ // Channel has changed
|
||||
if(hopping_frequency_no>XN297DUMP_MAX_RF_CHANNEL)
|
||||
hopping_frequency_no=0; // Invalid channel 0 by default
|
||||
rf_ch_num=hopping_frequency_no;
|
||||
debugln("Channel=%d,0x%02X",hopping_frequency_no,hopping_frequency_no)
|
||||
NRF24L01_WriteReg(NRF24L01_05_RF_CH,hopping_frequency_no);
|
||||
// switch to RX mode
|
||||
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit
|
||||
NRF24L01_SetTxRxMode(TXRX_OFF);
|
||||
NRF24L01_SetTxRxMode(RX_EN);
|
||||
NRF24L01_FlushRx();
|
||||
NRF24L01_WriteReg(NRF24L01_00_CONFIG, (0 << NRF24L01_00_EN_CRC) // switch to RX mode and disable CRC
|
||||
| (1 << NRF24L01_00_CRCO)
|
||||
| (1 << NRF24L01_00_PWR_UP)
|
||||
| (1 << NRF24L01_00_PRIM_RX));
|
||||
}
|
||||
|
||||
if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR))
|
||||
{ // RX fifo data ready
|
||||
if(NRF24L01_ReadReg(NRF24L01_09_CD) || option != 0xFF)
|
||||
{
|
||||
NRF24L01_ReadPayload(packet,XN297DUMP_MAX_PACKET_LEN);
|
||||
debug_time("RX: ");
|
||||
debug("us %d ", option);
|
||||
if(XN297Dump_process_packet())
|
||||
{ // valid crc found
|
||||
debug("A=");
|
||||
for(uint8_t i=0; i<XN297DUMP_ADDRESS_LENGTH; i++)
|
||||
{
|
||||
debug(" %02X",packet[i]);
|
||||
}
|
||||
debug(" P(%d)=",packet_length-XN297DUMP_ADDRESS_LENGTH);
|
||||
for(uint8_t i=XN297DUMP_ADDRESS_LENGTH; i<packet_length; i++)
|
||||
{
|
||||
debug(" %02X",packet[i]);
|
||||
}
|
||||
debugln("");
|
||||
}
|
||||
else
|
||||
{
|
||||
debugln("Bad CRC");
|
||||
}
|
||||
}
|
||||
|
||||
// restart RX mode
|
||||
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit
|
||||
NRF24L01_SetTxRxMode(TXRX_OFF);
|
||||
NRF24L01_SetTxRxMode(RX_EN);
|
||||
NRF24L01_FlushRx();
|
||||
NRF24L01_WriteReg(NRF24L01_00_CONFIG, (0 << NRF24L01_00_EN_CRC) // switch to RX mode and disable CRC
|
||||
| (1 << NRF24L01_00_CRCO)
|
||||
| (1 << NRF24L01_00_PWR_UP)
|
||||
| (1 << NRF24L01_00_PRIM_RX));
|
||||
}
|
||||
bind_counter++;
|
||||
if(IS_RX_FLAG_on) // Let the radio update the protocol
|
||||
{
|
||||
if(Update_All()) return 10000; // New protocol selected
|
||||
if(prev_option!=option)
|
||||
{ // option has changed
|
||||
hopping_frequency_no=option;
|
||||
prev_option=option;
|
||||
}
|
||||
}
|
||||
return 50;
|
||||
}
|
||||
|
||||
uint16_t initXN297Dump(void)
|
||||
{
|
||||
BIND_DONE;
|
||||
XN297Dump_init();
|
||||
bind_counter=0;
|
||||
rf_ch_num=0xFF;
|
||||
prev_option=option^0x55;
|
||||
return XN297DUMP_INITIAL_WAIT;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user