Skip to content

Commit

Permalink
Bayang RX: Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
pascallanger committed Nov 30, 2019
1 parent 396c005 commit 0008633
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
32 changes: 23 additions & 9 deletions Multiprotocol/Bayang_Rx_nrf24l01.ino
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ static void __attribute__((unused)) Bayang_Rx_build_telemetry_packet()
uint8_t idx = 0;

packet_in[idx++] = RX_LQI;
packet_in[idx++] = RX_LQI; // no RSSI
packet_in[idx++] = 0; // start channel
packet_in[idx++] = 10; // number of channels in packet
packet_in[idx++] = RX_LQI>>1; // no RSSI: 125..0
packet_in[idx++] = 0; // start channel
packet_in[idx++] = 10; // number of channels in packet

// convert & pack channels
for (uint8_t i = 0; i < packet_in[3]; i++) {
Expand Down Expand Up @@ -104,7 +104,8 @@ uint16_t initBayang_Rx()
Bayang_Rx_init_nrf24l01();
hopping_frequency_no = 0;
rx_data_started = false;

rx_data_received = false;

if (IS_BIND_IN_PROGRESS) {
phase = BAYANG_RX_BIND;
}
Expand Down Expand Up @@ -160,28 +161,41 @@ uint16_t Bayang_Rx_callback()
telemetry_link = 1;
}
rx_data_started = true;
read_retry = 4;
rx_data_received = true;
read_retry = 8;
pps_counter++;
}
}
// packets per second
if (millis() - pps_timer >= 1000) {
pps_timer = millis();
debugln("%d pps", pps_counter);
RX_LQI = pps_counter / 2;
RX_LQI = pps_counter >> 1;
pps_counter = 0;
}

// frequency hopping
if (read_retry++ >= 4) {
if (read_retry++ >= 8) {
hopping_frequency_no++;
if (hopping_frequency_no >= BAYANG_RX_RF_NUM_CHANNELS)
hopping_frequency_no = 0;
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]);
NRF24L01_FlushRx();
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
if (rx_data_started)
read_retry = 0;
{
if(rx_data_received)
{ // In sync
rx_data_received = false;
read_retry = 5;
return 1500;
}
else
{ // packet lost
read_retry = 0;
if(RX_LQI==0) // communication lost
rx_data_started=false;
}
}
else
read_retry = -16; // retry longer until first packet is caught
}
Expand Down
1 change: 1 addition & 0 deletions Multiprotocol/Multiprotocol.ino
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets
//RX protocols
#if defined(AFHDS2A_RX_A7105_INO) || defined(FRSKY_RX_CC2500_INO) || defined(BAYANG_RX_NRF24L01_INO)
bool rx_data_started;
bool rx_data_received;
bool rx_disable_lna;
uint16_t rx_rc_chan[16];
#endif
Expand Down

0 comments on commit 0008633

Please sign in to comment.