mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 18:48:11 +00:00
XN297Dump improvements
Selection of address length Timing accuracy
This commit is contained in:
parent
e7b079ece7
commit
ded0487ce6
@ -13,12 +13,16 @@
|
||||
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// sub_protocol: 0=250Kbps, 1=1Mbps, 2=2Mbps. Other values default to 1Mbps.
|
||||
// RX_num = address length 3 or 4 or 5. Other values default to 5.
|
||||
// option = RF channel number 0..84 and -1 = scan all channels. Other values default to RF channel 0.
|
||||
|
||||
#ifdef XN297DUMP_NRF24L01_INO
|
||||
|
||||
#include "iface_nrf24l01.h"
|
||||
|
||||
// Parameters which can be modified
|
||||
#define XN297DUMP_PERIOD_DUMP 3000 // Multiplied by 50, default 3000=150ms
|
||||
#define XN297DUMP_PERIOD_DUMP 25000
|
||||
#define XN297DUMP_MAX_RF_CHANNEL 84 // Default 84
|
||||
|
||||
// Do not touch from there
|
||||
@ -27,6 +31,7 @@
|
||||
#define XN297DUMP_CRC_LENGTH 2
|
||||
|
||||
uint8_t address_length;
|
||||
uint16_t over;
|
||||
boolean scramble;
|
||||
|
||||
static void __attribute__((unused)) XN297Dump_init()
|
||||
@ -43,7 +48,7 @@ static void __attribute__((unused)) XN297Dump_init()
|
||||
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, speed=");
|
||||
debug("XN297 dump, address length=%d, speed=",address_length);
|
||||
switch(sub_protocol)
|
||||
{
|
||||
case 0:
|
||||
@ -71,10 +76,7 @@ static boolean __attribute__((unused)) XN297Dump_process_packet(void)
|
||||
{
|
||||
uint16_t crcxored;
|
||||
uint8_t packet_sc[XN297DUMP_MAX_PACKET_LEN], packet_un[XN297DUMP_MAX_PACKET_LEN];
|
||||
address_length=5;
|
||||
|
||||
while(address_length >= 3)
|
||||
{
|
||||
// init crc
|
||||
crc = 0xb5d2;
|
||||
|
||||
@ -83,7 +85,7 @@ static boolean __attribute__((unused)) XN297Dump_process_packet(void)
|
||||
{
|
||||
crc = crc16_update(crc, packet[i], 8);
|
||||
packet_un[address_length-1-i]=packet[i];
|
||||
packet_sc[address_length-1-i]=packet[i] ^= xn297_scramble[i];
|
||||
packet_sc[address_length-1-i]=packet[i] ^ xn297_scramble[i];
|
||||
}
|
||||
|
||||
// payload
|
||||
@ -110,14 +112,23 @@ static boolean __attribute__((unused)) XN297Dump_process_packet(void)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
address_length--;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void __attribute__((unused)) XN297Dump_overflow()
|
||||
{
|
||||
if(TIMER2_BASE->SR & TIMER_SR_UIF)
|
||||
{ // timer overflow
|
||||
if(over!=0xFFFF)
|
||||
over++;
|
||||
TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_UIF; // Clear Timer2 overflow flag
|
||||
}
|
||||
}
|
||||
static uint16_t XN297Dump_callback()
|
||||
{
|
||||
static uint16_t time=0;
|
||||
while(1)
|
||||
{
|
||||
if(option==0xFF && bind_counter>XN297DUMP_PERIOD_DUMP)
|
||||
{ // Scan frequencies
|
||||
hopping_frequency_no++;
|
||||
@ -139,15 +150,23 @@ static uint16_t XN297Dump_callback()
|
||||
| (1 << NRF24L01_00_CRCO)
|
||||
| (1 << NRF24L01_00_PWR_UP)
|
||||
| (1 << NRF24L01_00_PRIM_RX));
|
||||
over=0xFFFF;
|
||||
}
|
||||
XN297Dump_overflow();
|
||||
|
||||
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 C=%d ", hopping_frequency_no);
|
||||
uint16_t time_TCNT1=TCNT1;
|
||||
uint32_t time32=0;
|
||||
time=time_TCNT1-time;
|
||||
if(over!=0xFFFF)
|
||||
time32=(over<<16)+time;
|
||||
debug("RX: %5luus C=%d ", time32>>1 , hopping_frequency_no);
|
||||
time=time_TCNT1;
|
||||
over=0;
|
||||
if(XN297Dump_process_packet())
|
||||
{ // valid crc found
|
||||
debug("S=%c A=",scramble?'Y':'N');
|
||||
@ -168,6 +187,7 @@ static uint16_t XN297Dump_callback()
|
||||
}
|
||||
}
|
||||
|
||||
XN297Dump_overflow();
|
||||
// restart RX mode
|
||||
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit
|
||||
NRF24L01_SetTxRxMode(TXRX_OFF);
|
||||
@ -177,6 +197,7 @@ static uint16_t XN297Dump_callback()
|
||||
| (1 << NRF24L01_00_CRCO)
|
||||
| (1 << NRF24L01_00_PWR_UP)
|
||||
| (1 << NRF24L01_00_PRIM_RX));
|
||||
XN297Dump_overflow();
|
||||
}
|
||||
bind_counter++;
|
||||
if(IS_RX_FLAG_on) // Let the radio update the protocol
|
||||
@ -188,12 +209,18 @@ static uint16_t XN297Dump_callback()
|
||||
prev_option=option;
|
||||
}
|
||||
}
|
||||
return 50;
|
||||
XN297Dump_overflow();
|
||||
}
|
||||
return 100;
|
||||
}
|
||||
|
||||
uint16_t initXN297Dump(void)
|
||||
{
|
||||
BIND_DONE;
|
||||
over=0xFFFF;
|
||||
address_length=RX_num;
|
||||
if(address_length<3||address_length>5)
|
||||
address_length=5; //default
|
||||
XN297Dump_init();
|
||||
bind_counter=0;
|
||||
rf_ch_num=0xFF;
|
||||
|
Loading…
x
Reference in New Issue
Block a user