From 0008633d6ef844a1bec424c62ba4e7ed2f956207 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sat, 30 Nov 2019 12:11:08 +0100 Subject: [PATCH] Bayang RX: Sync --- Multiprotocol/Bayang_Rx_nrf24l01.ino | 32 ++++++++++++++++++++-------- Multiprotocol/Multiprotocol.ino | 1 + 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Multiprotocol/Bayang_Rx_nrf24l01.ino b/Multiprotocol/Bayang_Rx_nrf24l01.ino index 9cf833e18..3dbc3695b 100644 --- a/Multiprotocol/Bayang_Rx_nrf24l01.ino +++ b/Multiprotocol/Bayang_Rx_nrf24l01.ino @@ -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++) { @@ -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; } @@ -160,7 +161,8 @@ uint16_t Bayang_Rx_callback() telemetry_link = 1; } rx_data_started = true; - read_retry = 4; + rx_data_received = true; + read_retry = 8; pps_counter++; } } @@ -168,12 +170,11 @@ uint16_t Bayang_Rx_callback() 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; @@ -181,7 +182,20 @@ uint16_t Bayang_Rx_callback() 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 } diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 52471198d..7848abd6f 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -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