Merge branch 'testable' of https://github.com/Genaker/LoraSA into testable

This commit is contained in:
Egor
2024-12-24 14:23:49 -08:00
9 changed files with 87 additions and 60 deletions

View File

@@ -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");

View File

@@ -7,7 +7,7 @@
#include <LiLyGo.h>
#include <config.h>
#ifdef HELTEC
#ifndef ARDUINO_USB_CDC_ON_BOOT
#define SERIAL0 Serial
#else
#define SERIAL0 Serial0

View File

@@ -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;

View File

@@ -12,7 +12,7 @@ struct ScanRange
struct LoRaConfig
{
uint16_t freq;
float freq;
uint16_t bw;
uint8_t sf;
uint8_t cr;
@@ -49,6 +49,8 @@ struct Config
scan_ranges(NULL), log_data_json_interval(1000),
listen_on_serial0(String("none")), listen_on_serial1(String("readline")),
listen_on_usb(String("readline")), rx_lora(NULL), tx_lora(NULL),
// Enable Lora Send:
// rx_lora(configureLora("freq:920")),tx_lora(configureLora("freq:916"))
is_host(false) {};
bool write_config(const char *path);

View File

@@ -1,4 +1,7 @@
#include "models.h"
#include <algorithm>
using namespace std;
#include <cstring>
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]++;

View File

@@ -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();

View File

@@ -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

View File

@@ -569,9 +569,6 @@ 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,
true); // false = calibration is needed here

View File

@@ -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;
}