From 8601149051d20c0770a88da470362b3ff4e22fbb Mon Sep 17 00:00:00 2001 From: goebish Date: Sat, 14 Sep 2019 16:07:49 +0200 Subject: [PATCH] Fix scanner telemetry (#262) * Fix scanner telemetry * Take several samples per channel, keep maximum value --- Multiprotocol/Scanner_cc2500.ino | 47 +++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/Multiprotocol/Scanner_cc2500.ino b/Multiprotocol/Scanner_cc2500.ino index 5c7aaf4..6b09b21 100644 --- a/Multiprotocol/Scanner_cc2500.ino +++ b/Multiprotocol/Scanner_cc2500.ino @@ -18,8 +18,9 @@ #include "iface_cc2500.h" #define SCAN_MAX_RADIOCHANNEL 249 // 2483 MHz -#define SCAN_CHANNEL_LOCK_TIME 300 // with precalibration, channel requires only 90 usec for synthesizer to settle -#define SCAN_AVERAGE_INTVL 30 +#define SCAN_CHANNEL_LOCK_TIME 210 // with precalibration, channel requires only 90 usec for synthesizer to settle +#define SCAN_AVERAGE_INTVL 20 +#define SCAN_MAX_COUNT 5 #define SCAN_CHANS_PER_PACKET 5 static uint8_t scan_tlm_index; @@ -96,25 +97,38 @@ static int __attribute__((unused)) Scanner_scan_rssi() uint16_t Scanner_callback() { + static uint8_t max_count, max_rssi; + uint8_t rssi; switch (phase) { case SCAN_CHANNEL_CHANGE: - rf_ch_num++; - if (rf_ch_num >= (SCAN_MAX_RADIOCHANNEL + 1)) - rf_ch_num = 0; - if (scan_tlm_index++ == 0) - pkt[0] = rf_ch_num; // start channel for telemetry packet - Scanner_scan_next(); - phase = SCAN_GET_RSSI; + if(telemetry_link == 0) { + max_count = 0; + max_rssi = 0; + rf_ch_num++; + if (rf_ch_num >= (SCAN_MAX_RADIOCHANNEL + 1)) + rf_ch_num = 0; + if (scan_tlm_index++ == 0) + pkt[0] = rf_ch_num; // start channel for telemetry packet + Scanner_scan_next(); + phase = SCAN_GET_RSSI; + } return SCAN_CHANNEL_LOCK_TIME; case SCAN_GET_RSSI: - phase = SCAN_CHANNEL_CHANGE; - pkt[scan_tlm_index] = Scanner_scan_rssi(); - if (scan_tlm_index == SCAN_CHANS_PER_PACKET) - { - // send data to TX - telemetry_link = 1; - scan_tlm_index = 0; + rssi = Scanner_scan_rssi(); + if(rssi >= max_rssi) { + max_rssi = rssi; + pkt[scan_tlm_index] = rssi; + } + max_count++; + if(max_count > SCAN_MAX_COUNT) { + phase = SCAN_CHANNEL_CHANGE; + if (scan_tlm_index == SCAN_CHANS_PER_PACKET) + { + // send data to TX + telemetry_link = 1; + scan_tlm_index = 0; + } } } return SCAN_AVERAGE_INTVL; @@ -124,6 +138,7 @@ uint16_t initScanner(void) { rf_ch_num = SCAN_MAX_RADIOCHANNEL; scan_tlm_index = 0; + telemetry_link = 0; phase = SCAN_CHANNEL_CHANGE; Scanner_cc2500_init(); CC2500_Strobe(CC2500_SRX);