From 83d580c2c4bcb6bca757fd591b1c0fe8daede130 Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 5 Jan 2025 18:03:02 -0800 Subject: [PATCH] RSSI ENV and sign --- lib/config/config.cpp | 2 +- lib/config/config.h | 5 ++++ src/main.cpp | 68 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/lib/config/config.cpp b/lib/config/config.cpp index 07a9a57..90b8936 100644 --- a/lib/config/config.cpp +++ b/lib/config/config.cpp @@ -352,7 +352,7 @@ LoRaConfig *configureLora(String cfg) bw : 500, sf : 7, cr : 5, - tx_power : 1, + tx_power : DEFAULT_LORA_TX_POWER, preamble_len : 8, sync_word : 0x1e, crc : false, diff --git a/lib/config/config.h b/lib/config/config.h index 7eaaca0..2fc219a 100644 --- a/lib/config/config.h +++ b/lib/config/config.h @@ -73,6 +73,11 @@ LoRaConfig *configureLora(String cfg); #ifndef DEFAULT_LORA_ENABLED #define DEFAULT_LORA_ENABLED false #endif + +#ifndef DEFAULT_LORA_TX_POWER +#define DEFAULT_LORA_TX_POWER 1 +#endif + #define CREATE_MISSING_CONFIG true struct Config { diff --git a/src/main.cpp b/src/main.cpp index f63ca41..51bce55 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -159,6 +159,14 @@ size_t scan_pages_sz = 0; ScanPage *scan_pages; size_t scan_page = 0; +struct RSSIData +{ + short rssi; + unsigned long int time; +}; + +std::unordered_map historyRSSI; + // MHZ per page // to put everything into one page set RANGE_PER_PAGE = FREQ_END - 800 uint64_t RANGE_PER_PAGE; // FREQ_END - CONF_FREQ_BEGIN @@ -1515,10 +1523,22 @@ void display_scan_result(ScanTaskResult &dump); std::unordered_map findMaxRssi(int16_t *rssis, uint32_t *freqs_khz, int dump_sz, int level = 80); +void dumpHashMap(const std::unordered_map &map) +{ + + for (const auto &entry : map) + { + Serial.println("Key: " + String(entry.first) + + ", RSSI: " + String(entry.second.rssi) + + ", Time: " + String(entry.second.time) + " ms\n"); + } +} + void display_raw_scan(ScanTaskResult &dump) { // display.setDisplayRotation(1); // display.println("Host Mode ->"); + dumpHashMap(historyRSSI); size_t dump_sz = dump.sz; int16_t *rssi = dump.rssis; @@ -1526,30 +1546,59 @@ void display_raw_scan(ScanTaskResult &dump) std::unordered_map maxMhzRssi = findMaxRssi(rssi, fr, dump_sz, abs(TRIGGER_LEVEL)); - Serial.println("PRINT SIZE :" + String(maxMhzRssi.size())); + int lx = 0; int ly = 0; int i = 0; + String frSign = ":"; for (const auto &pair : maxMhzRssi) { if (i == 0 && maxMhzRssi.size() > 0) { display.clear(); } + int16_t rssi = pair.second; int16_t fr = (int)pair.first; - Serial.println("PRINT FR:" + String(fr) + ":" + String(rssi) + " lx " + - String(lx)); + if (historyRSSI.find(fr) != historyRSSI.end()) + { + // Clear old RSSI + if (millis() - historyRSSI[fr].time > 60 * 1000) + { + historyRSSI.erase(fr); + } + else + { + if (abs(historyRSSI[fr].rssi) > abs(rssi)) + { + frSign = "<"; + } + else if (abs(historyRSSI[fr].rssi) < abs(rssi)) + { + frSign = ">"; + } + else + { + frSign = "="; + } + } + } + + // Save previous value + historyRSSI[fr] = {(short)abs(rssi), millis()}; + Serial.println("RSSI:" + String(historyRSSI[fr].rssi) + "/" + + String(historyRSSI[fr].time) + ":" + String(millis())); + // screen overflow protection if (lx < 130) { - display.drawString(lx, ly, String(fr) + ":" + String(rssi)); - Serial.println("PRINT FR:" + String(fr) + ":" + String(rssi)); + display.drawString(lx, ly, String(fr) + frSign + String(rssi)); + // go to next line ly = ly + 10; - if (ly > 60) + if (ly > 55) { ly = 0; @@ -1666,8 +1715,8 @@ void sendMessage(RoutedMessage &m) { if (config.is_host && TxComms != NULL) { - checkRadio(*TxComms); // waiting for peer to squak first, so message sending - // will land on the receiving cycle + checkRadio(*TxComms); // waiting for peer to squak first, so message + // sending will land on the receiving cycle } loraSendMessage(*m.message); @@ -2216,8 +2265,6 @@ void doScan() #endif } -std::unordered_map previousPac = {/*{916, true}, {915, true}*/}; - std::unordered_map findMaxRssi(int16_t *rssis, uint32_t *freqs_khz, int dump_sz, int level) { @@ -2238,7 +2285,6 @@ std::unordered_map findMaxRssi(int16_t *rssis, uint32_t *freqs_khz } } } - return maxRssiPerMHz; }