From c6833ee3b020fa411f54992ba01443e003d05390 Mon Sep 17 00:00:00 2001 From: Sassa NF Date: Tue, 24 Dec 2024 12:56:56 +0000 Subject: [PATCH 1/3] Fixup - RadioLib now supports calibration --- src/main.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8650b37..d9736d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -569,12 +569,9 @@ bool setFrequency(float curr_freq) state = state1; #elif USING_SX1276 state = radio.setFrequency(freq); -#elif defined(USING_LR1121) - state = radio.setFrequency(r.current_frequency, - true); // true = no calibration need here #else state = radio.setFrequency(r.current_frequency, - false); // false = calibration is needed here + true); // true = no calibration need here #endif if (state != RADIOLIB_ERR_NONE) { From de5f3c8e61afdf19fe98b08277241efba80fb9b9 Mon Sep 17 00:00:00 2001 From: Sassa NF Date: Tue, 24 Dec 2024 11:59:54 +0000 Subject: [PATCH 2/3] Support USB comms on Heltec --- lib/comms/comms.cpp | 28 +++++++++++++++++++--------- lib/comms/comms.h | 2 +- lib/config/config.cpp | 9 +++++---- lib/config/config.h | 2 +- platformio.ini | 2 ++ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/comms/comms.cpp b/lib/comms/comms.cpp index 19e66fb..53781b3 100644 --- a/lib/comms/comms.cpp +++ b/lib/comms/comms.cpp @@ -43,28 +43,38 @@ void _onReceive1() Comms1->_onReceive(); } +#if ARDUINO_USB_MODE +#define IF_CDC_EVENT(e, data) \ + arduino_hw_cdc_event_data_t *data = (arduino_hw_cdc_event_data_t *)event_data; \ + if (event_base == ARDUINO_HW_CDC_EVENTS && event_id == ARDUINO_HW_CDC_##e) +#else +#define IF_CDC_EVENT(e, data) \ + arduino_usb_cdc_event_data_t *data = (arduino_usb_cdc_event_data_t *)event_data; \ + if (event_base == ARDUINO_USB_CDC_EVENTS && event_id == ARDUINO_USB_CDC_##e) +#endif + void _onUsbEvent0(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { - if (event_base == ARDUINO_HW_CDC_EVENTS) - { - arduino_hw_cdc_event_data_t *data = (arduino_hw_cdc_event_data_t *)event_data; - if (event_id == ARDUINO_HW_CDC_RX_EVENT) - { - _onReceiveUsb(data->rx.len); - } - } + IF_CDC_EVENT(RX_EVENT, data) { _onReceiveUsb(data->rx.len); } } bool Comms::initComms(Config &c) { bool fine = false; -#ifndef HELTEC + +#ifdef ARDUINO_USB_CDC_ON_BOOT if (c.listen_on_usb.equalsIgnoreCase("readline")) { // comms using readline plaintext protocol HostComms = new ReadlineComms("Host", Serial); +#if ARDUINO_USB_MODE + // if Serial is HWCDC... Serial.onEvent(ARDUINO_HW_CDC_RX_EVENT, _onUsbEvent0); +#else + // if Serial is USBCDC... + Serial.onEvent(ARDUINO_USB_CDC_RX_EVENT, _onUsbEvent0); +#endif Serial.begin(); Serial.println("Initialized communications on Serial using readline protocol"); diff --git a/lib/comms/comms.h b/lib/comms/comms.h index 455a8d4..b852a06 100644 --- a/lib/comms/comms.h +++ b/lib/comms/comms.h @@ -7,7 +7,7 @@ #include #include -#ifdef HELTEC +#ifndef ARDUINO_USB_CDC_ON_BOOT #define SERIAL0 Serial #else #define SERIAL0 Serial0 diff --git a/lib/config/config.cpp b/lib/config/config.cpp index cb46edd..2b2ec69 100644 --- a/lib/config/config.cpp +++ b/lib/config/config.cpp @@ -384,21 +384,22 @@ LoRaConfig *configureLora(String cfg) } String k = param.substring(0, j); + param = param.substring(j + 1); if (k.equalsIgnoreCase("sync_word")) { - lora->sync_word = (uint8_t)fromHex(param.substring(j + 1)); + lora->sync_word = (uint8_t)fromHex(param); continue; } - int v = param.substring(j + 1).toInt(); - if (k.equalsIgnoreCase("freq")) { - lora->freq = (uint16_t)v; + lora->freq = param.toFloat(); continue; } + int v = param.toInt(); + if (k.equalsIgnoreCase("bw")) { lora->bw = (uint16_t)v; diff --git a/lib/config/config.h b/lib/config/config.h index b4f32f6..770f7ac 100644 --- a/lib/config/config.h +++ b/lib/config/config.h @@ -12,7 +12,7 @@ struct ScanRange struct LoRaConfig { - uint16_t freq; + float freq; uint16_t bw; uint8_t sf; uint8_t cr; diff --git a/platformio.ini b/platformio.ini index 5723634..6696f87 100644 --- a/platformio.ini +++ b/platformio.ini @@ -34,6 +34,8 @@ lib_deps = build_flags = -DHELTEC_POWER_BUTTON -DHELTEC + -DARDUINO_USB_CDC_ON_BOOT=1 + -DARDUINO_USB_MODE=1 [env:heltec_wifi_lora_32_V3-OSD] platform = espressif32 From aa38b5663c3f1954f6e5ef8b1288848244beb417 Mon Sep 17 00:00:00 2001 From: Sassa NF Date: Tue, 24 Dec 2024 18:36:24 +0000 Subject: [PATCH 3/3] Fixup waterfall --- lib/models/WaterfallModel.cpp | 7 ++- lib/models/models.h | 2 +- test/test_waterfall.cpp | 90 ++++++++++++++++++++--------------- 3 files changed, 57 insertions(+), 42 deletions(-) diff --git a/lib/models/WaterfallModel.cpp b/lib/models/WaterfallModel.cpp index 99f7816..5f02972 100644 --- a/lib/models/WaterfallModel.cpp +++ b/lib/models/WaterfallModel.cpp @@ -1,4 +1,7 @@ #include "models.h" +#include +using namespace std; + #include WaterfallModel::WaterfallModel(size_t w, uint64_t base_dt, size_t m_sz, @@ -67,13 +70,13 @@ void WaterfallModel::reset(uint64_t t0, size_t w) * and it gets added to incomplete minute. This gets repeated for incomplete * minutes, etc. */ -size_t WaterfallModel::updateModel(uint16_t t, size_t x, uint16_t y) +size_t WaterfallModel::updateModel(uint64_t t, size_t x, uint16_t y) { size_t changed = 1; while (t > times[0]) { - changed = push(); + changed = max(changed, push()); } counts[0][x]++; diff --git a/lib/models/models.h b/lib/models/models.h index ce8de8f..0a09abd 100644 --- a/lib/models/models.h +++ b/lib/models/models.h @@ -18,7 +18,7 @@ struct WaterfallModel WaterfallModel(size_t w, uint64_t base_dt, size_t m_sz, const size_t *multiples); void reset(uint64_t t0, size_t width); - size_t updateModel(uint16_t t, size_t x, uint16_t y); + size_t updateModel(uint64_t t, size_t x, uint16_t y); size_t push(); char *toString(); diff --git a/test/test_waterfall.cpp b/test/test_waterfall.cpp index 1875065..69cb3bc 100644 --- a/test/test_waterfall.cpp +++ b/test/test_waterfall.cpp @@ -50,8 +50,11 @@ void test_push() m.reset(0, 1); uint64_t i = 0; + size_t update_to = 0; for (; i < 10; i++) - m.updateModel(i, 0, 1); + update_to = max(update_to, m.updateModel(i, 0, 1)); + + TEST_ASSERT_EQUAL_INT(6, update_to); r = m.toString(); TEST_ASSERT_EQUAL_STRING("w:1 b:34 " @@ -92,8 +95,11 @@ void test_push() r); delete r; + update_to = 0; for (; i < 100; i += 10) - m.updateModel(i, 0, 1); + update_to = max(update_to, m.updateModel(i, 0, 1)); + + TEST_ASSERT_EQUAL_INT(13, update_to); r = m.toString(); TEST_ASSERT_EQUAL_STRING("w:1 b:34 " @@ -134,8 +140,11 @@ void test_push() r); delete r; + update_to = 0; for (; i < 10000; i++) - m.updateModel(i, 0, 1); + update_to = max(update_to, m.updateModel(i, 0, 1)); + + TEST_ASSERT_EQUAL_INT(34, update_to); r = m.toString(); TEST_ASSERT_EQUAL_STRING("w:1 b:34 " @@ -176,45 +185,48 @@ void test_push() r); delete r; - for (; i < 5000; i++) - m.updateModel(i, 0, 1); + update_to = 0; + for (; i < 15000; i++) + update_to = max(update_to, m.updateModel(i, 0, 1)); + + TEST_ASSERT_EQUAL_INT(34, update_to); r = m.toString(); TEST_ASSERT_EQUAL_STRING("w:1 b:34 " - "[dt:1 t:9999 [ c:1 e:1 ]" - "dt:1 t:9998 [ c:1 e:1 ]" - "dt:1 t:9997 [ c:1 e:1 ]" - "dt:1 t:9996 [ c:1 e:1 ]" - "dt:1 t:9995 [ c:1 e:1 ]" - "dt:5 t:9995 [ c:4 e:4 ]" - "dt:5 t:9990 [ c:5 e:5 ]" - "dt:5 t:9985 [ c:5 e:5 ]" - "dt:15 t:9990 [ c:5 e:5 ]" - "dt:15 t:9975 [ c:15 e:15 ]" - "dt:15 t:9960 [ c:15 e:15 ]" - "dt:15 t:9945 [ c:15 e:15 ]" - "dt:60 t:9960 [ c:30 e:30 ]" - "dt:60 t:9900 [ c:60 e:60 ]" - "dt:60 t:9840 [ c:60 e:60 ]" - "dt:60 t:9780 [ c:60 e:60 ]" - "dt:60 t:9720 [ c:60 e:60 ]" - "dt:60 t:9660 [ c:60 e:60 ]" - "dt:60 t:9600 [ c:60 e:60 ]" - "dt:60 t:9540 [ c:60 e:60 ]" - "dt:60 t:9480 [ c:60 e:60 ]" - "dt:60 t:9420 [ c:60 e:60 ]" - "dt:60 t:9360 [ c:60 e:60 ]" - "dt:60 t:9300 [ c:60 e:60 ]" - "dt:60 t:9240 [ c:60 e:60 ]" - "dt:60 t:9180 [ c:60 e:60 ]" - "dt:60 t:9120 [ c:60 e:60 ]" - "dt:900 t:9900 [ c:60 e:60 ]" - "dt:900 t:9000 [ c:900 e:900 ]" - "dt:900 t:8100 [ c:900 e:900 ]" - "dt:900 t:7200 [ c:900 e:900 ]" - "dt:3600 t:7200 [ c:2700 e:2700 ]" - "dt:3600 t:3600 [ c:3520 e:3520 ]" - "dt:3600 t:3600 [ c:0 e:0 ] ]", + "[dt:1 t:14999 [ c:1 e:1 ]" + "dt:1 t:14998 [ c:1 e:1 ]" + "dt:1 t:14997 [ c:1 e:1 ]" + "dt:1 t:14996 [ c:1 e:1 ]" + "dt:1 t:14995 [ c:1 e:1 ]" + "dt:5 t:14995 [ c:4 e:4 ]" + "dt:5 t:14990 [ c:5 e:5 ]" + "dt:5 t:14985 [ c:5 e:5 ]" + "dt:15 t:14985 [ c:10 e:10 ]" + "dt:15 t:14970 [ c:15 e:15 ]" + "dt:15 t:14955 [ c:15 e:15 ]" + "dt:15 t:14940 [ c:15 e:15 ]" + "dt:60 t:14940 [ c:45 e:45 ]" + "dt:60 t:14880 [ c:60 e:60 ]" + "dt:60 t:14820 [ c:60 e:60 ]" + "dt:60 t:14760 [ c:60 e:60 ]" + "dt:60 t:14700 [ c:60 e:60 ]" + "dt:60 t:14640 [ c:60 e:60 ]" + "dt:60 t:14580 [ c:60 e:60 ]" + "dt:60 t:14520 [ c:60 e:60 ]" + "dt:60 t:14460 [ c:60 e:60 ]" + "dt:60 t:14400 [ c:60 e:60 ]" + "dt:60 t:14340 [ c:60 e:60 ]" + "dt:60 t:14280 [ c:60 e:60 ]" + "dt:60 t:14220 [ c:60 e:60 ]" + "dt:60 t:14160 [ c:60 e:60 ]" + "dt:60 t:14100 [ c:60 e:60 ]" + "dt:900 t:14400 [ c:540 e:540 ]" + "dt:900 t:13500 [ c:900 e:900 ]" + "dt:900 t:12600 [ c:900 e:900 ]" + "dt:900 t:11700 [ c:900 e:900 ]" + "dt:3600 t:10800 [ c:3600 e:3600 ]" + "dt:3600 t:7200 [ c:3600 e:3600 ]" + "dt:3600 t:3600 [ c:3520 e:3520 ] ]", r); delete r; }