Skip to content

Commit 97b6a18

Browse files
author
Scott Powell
committed
Merge branch 'dev'
2 parents 05fa1ba + fc6aa0e commit 97b6a18

File tree

46 files changed

+955
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+955
-145
lines changed

examples/companion_radio/main.cpp

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#include <SPIFFS.h>
88
#endif
99

10-
#define RADIOLIB_STATIC_ONLY 1
11-
#include <RadioLib.h>
12-
#include <helpers/RadioLibWrappers.h>
1310
#include <helpers/ArduinoHelpers.h>
1411
#include <helpers/StaticPoolPacketManager.h>
1512
#include <helpers/SimpleMeshTables.h>
@@ -89,11 +86,11 @@ static uint32_t _atoi(const char* sp) {
8986
#define FIRMWARE_VER_CODE 3
9087

9188
#ifndef FIRMWARE_BUILD_DATE
92-
#define FIRMWARE_BUILD_DATE "25 Mar 2025"
89+
#define FIRMWARE_BUILD_DATE "30 Mar 2025"
9390
#endif
9491

9592
#ifndef FIRMWARE_VERSION
96-
#define FIRMWARE_VERSION "v1.4.1"
93+
#define FIRMWARE_VERSION "v1.4.2"
9794
#endif
9895

9996
#define CMD_APP_START 1
@@ -197,7 +194,6 @@ struct NodePrefs { // persisted to file
197194

198195
class MyMesh : public BaseChatMesh {
199196
FILESYSTEM* _fs;
200-
RADIO_CLASS* _phy;
201197
IdentityStore* _identity_store;
202198
NodePrefs _prefs;
203199
uint32_t pending_login;
@@ -229,9 +225,9 @@ class MyMesh : public BaseChatMesh {
229225
AckTableEntry expected_ack_table[EXPECTED_ACK_TABLE_SIZE]; // circular table
230226
int next_ack_idx;
231227

232-
void loadMainIdentity(mesh::RNG& trng) {
228+
void loadMainIdentity() {
233229
if (!_identity_store->load("_main", self_id)) {
234-
self_id = mesh::LocalIdentity(&trng); // create new random identity
230+
self_id = radio_new_identity(); // create new random identity
235231
saveMainIdentity(self_id);
236232
}
237233
}
@@ -488,7 +484,7 @@ class MyMesh : public BaseChatMesh {
488484
}
489485

490486
void logRxRaw(float snr, float rssi, const uint8_t raw[], int len) override {
491-
if (_serial->isConnected()) {
487+
if (_serial->isConnected() && len+3 <= MAX_FRAME_SIZE) {
492488
int i = 0;
493489
out_frame[i++] = PUSH_CODE_LOG_RX_DATA;
494490
out_frame[i++] = (int8_t)(snr * 4);
@@ -709,8 +705,8 @@ class MyMesh : public BaseChatMesh {
709705

710706
public:
711707

712-
MyMesh(RADIO_CLASS& phy, RadioLibWrapper& rw, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
713-
: BaseChatMesh(rw, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), _serial(NULL), _phy(&phy)
708+
MyMesh(mesh::Radio& radio, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
709+
: BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), _serial(NULL)
714710
{
715711
_iter_started = false;
716712
offline_queue_len = 0;
@@ -767,7 +763,7 @@ class MyMesh : public BaseChatMesh {
767763
}
768764
}
769765

770-
void begin(FILESYSTEM& fs, mesh::RNG& trng, bool has_display) {
766+
void begin(FILESYSTEM& fs, bool has_display) {
771767
_fs = &fs;
772768

773769
BaseChatMesh::begin();
@@ -778,7 +774,7 @@ class MyMesh : public BaseChatMesh {
778774
_identity_store = new IdentityStore(fs, "/identity");
779775
#endif
780776

781-
loadMainIdentity(trng);
777+
loadMainIdentity();
782778

783779
// load persisted prefs
784780
if (_fs->exists("/new_prefs")) {
@@ -793,7 +789,8 @@ class MyMesh : public BaseChatMesh {
793789
if (_prefs.ble_pin == 0) {
794790
#ifdef HAS_UI
795791
if (has_display) {
796-
_active_ble_pin = trng.nextInt(100000, 999999); // random pin each session
792+
StdRNG rng;
793+
_active_ble_pin = rng.nextInt(100000, 999999); // random pin each session
797794
} else {
798795
_active_ble_pin = BLE_PIN_CODE; // otherwise static pin
799796
}
@@ -814,11 +811,8 @@ class MyMesh : public BaseChatMesh {
814811
addChannel("Public", PUBLIC_GROUP_PSK); // pre-configure Andy's public channel
815812
loadChannels();
816813

817-
_phy->setFrequency(_prefs.freq);
818-
_phy->setSpreadingFactor(_prefs.sf);
819-
_phy->setBandwidth(_prefs.bw);
820-
_phy->setCodingRate(_prefs.cr);
821-
_phy->setOutputPower(_prefs.tx_power_dbm);
814+
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
815+
radio_set_tx_power(_prefs.tx_power_dbm);
822816
}
823817

824818
const char* getNodeName() { return _prefs.node_name; }
@@ -1153,10 +1147,7 @@ class MyMesh : public BaseChatMesh {
11531147
_prefs.bw = (float)bw / 1000.0;
11541148
savePrefs();
11551149

1156-
_phy->setFrequency(_prefs.freq);
1157-
_phy->setSpreadingFactor(_prefs.sf);
1158-
_phy->setBandwidth(_prefs.bw);
1159-
_phy->setCodingRate(_prefs.cr);
1150+
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
11601151
MESH_DEBUG_PRINTLN("OK: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d", freq, bw, (uint32_t)sf, (uint32_t)cr);
11611152

11621153
writeOKFrame();
@@ -1170,7 +1161,7 @@ class MyMesh : public BaseChatMesh {
11701161
} else {
11711162
_prefs.tx_power_dbm = cmd_frame[1];
11721163
savePrefs();
1173-
_phy->setOutputPower(_prefs.tx_power_dbm);
1164+
radio_set_tx_power(_prefs.tx_power_dbm);
11741165
writeOKFrame();
11751166
}
11761167
} else if (cmd_frame[0] == CMD_SET_TUNING_PARAMS) {
@@ -1431,7 +1422,7 @@ class MyMesh : public BaseChatMesh {
14311422

14321423
StdRNG fast_rng;
14331424
SimpleMeshTables tables;
1434-
MyMesh the_mesh(radio, *new WRAPPER_CLASS(radio, board), fast_rng, *new VolatileRTCClock(), tables);
1425+
MyMesh the_mesh(radio_driver, fast_rng, *new VolatileRTCClock(), tables); // TODO: test with 'rtc_clock' in target.cpp
14351426

14361427
void halt() {
14371428
while (1) ;
@@ -1444,9 +1435,7 @@ void setup() {
14441435

14451436
if (!radio_init()) { halt(); }
14461437

1447-
fast_rng.begin(radio.random(0x7FFFFFFF));
1448-
1449-
RadioNoiseListener trng(radio);
1438+
fast_rng.begin(radio_get_rng_seed());
14501439

14511440
#ifdef HAS_UI
14521441
DisplayDriver* disp = NULL;
@@ -1459,7 +1448,7 @@ void setup() {
14591448

14601449
#if defined(NRF52_PLATFORM)
14611450
InternalFS.begin();
1462-
the_mesh.begin(InternalFS, trng,
1451+
the_mesh.begin(InternalFS,
14631452
#ifdef HAS_UI
14641453
disp != NULL
14651454
#else
@@ -1477,7 +1466,7 @@ void setup() {
14771466
the_mesh.startInterface(serial_interface);
14781467
#elif defined(ESP32)
14791468
SPIFFS.begin(true);
1480-
the_mesh.begin(SPIFFS, trng,
1469+
the_mesh.begin(SPIFFS,
14811470
#ifdef HAS_UI
14821471
disp != NULL
14831472
#else

examples/simple_repeater/main.cpp

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
#include <SPIFFS.h>
88
#endif
99

10-
#define RADIOLIB_STATIC_ONLY 1
11-
#include <RadioLib.h>
1210
#include <helpers/ArduinoHelpers.h>
1311
#include <helpers/StaticPoolPacketManager.h>
1412
#include <helpers/SimpleMeshTables.h>
1513
#include <helpers/IdentityStore.h>
16-
#include <helpers/AutoDiscoverRTCClock.h>
1714
#include <helpers/AdvertDataHelpers.h>
1815
#include <helpers/TxtDataHelpers.h>
1916
#include <helpers/CommonCLI.h>
@@ -23,11 +20,11 @@
2320
/* ------------------------------ Config -------------------------------- */
2421

2522
#ifndef FIRMWARE_BUILD_DATE
26-
#define FIRMWARE_BUILD_DATE "25 Mar 2025"
23+
#define FIRMWARE_BUILD_DATE "30 Mar 2025"
2724
#endif
2825

2926
#ifndef FIRMWARE_VERSION
30-
#define FIRMWARE_VERSION "v1.4.1"
27+
#define FIRMWARE_VERSION "v1.4.2"
3128
#endif
3229

3330
#ifndef LORA_FREQ
@@ -69,6 +66,8 @@
6966
static UITask ui_task(display);
7067
#endif
7168

69+
#define FIRMWARE_ROLE "repeater"
70+
7271
#define PACKET_LOG_FILE "/packet_log"
7372

7473
/* ------------------------------ Code -------------------------------- */
@@ -108,10 +107,7 @@ struct ClientInfo {
108107
#define CLI_REPLY_DELAY_MILLIS 1500
109108

110109
class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
111-
RadioLibWrapper* my_radio;
112110
FILESYSTEM* _fs;
113-
RADIO_CLASS* _phy;
114-
mesh::MainBoard* _board;
115111
unsigned long next_local_advert, next_flood_advert;
116112
bool _logging;
117113
NodePrefs _prefs;
@@ -147,17 +143,17 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
147143
stats.batt_milli_volts = board.getBattMilliVolts();
148144
stats.curr_tx_queue_len = _mgr->getOutboundCount();
149145
stats.curr_free_queue_len = _mgr->getFreeCount();
150-
stats.last_rssi = (int16_t) my_radio->getLastRSSI();
151-
stats.n_packets_recv = my_radio->getPacketsRecv();
152-
stats.n_packets_sent = my_radio->getPacketsSent();
146+
stats.last_rssi = (int16_t) radio_driver.getLastRSSI();
147+
stats.n_packets_recv = radio_driver.getPacketsRecv();
148+
stats.n_packets_sent = radio_driver.getPacketsSent();
153149
stats.total_air_time_secs = getTotalAirTime() / 1000;
154150
stats.total_up_time_secs = _ms->getMillis() / 1000;
155151
stats.n_sent_flood = getNumSentFlood();
156152
stats.n_sent_direct = getNumSentDirect();
157153
stats.n_recv_flood = getNumRecvFlood();
158154
stats.n_recv_direct = getNumRecvDirect();
159155
stats.n_full_events = getNumFullEvents();
160-
stats.last_snr = (int16_t)(my_radio->getLastSNR() * 4);
156+
stats.last_snr = (int16_t)(radio_driver.getLastSNR() * 4);
161157
stats.n_direct_dups = ((SimpleMeshTables *)getTables())->getNumDirectDups();
162158
stats.n_flood_dups = ((SimpleMeshTables *)getTables())->getNumFloodDups();
163159

@@ -474,11 +470,10 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
474470
}
475471

476472
public:
477-
MyMesh(RADIO_CLASS& phy, mesh::MainBoard& board, RadioLibWrapper& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
473+
MyMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables)
478474
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
479-
_phy(&phy), _board(&board), _cli(board, this, &_prefs, this)
475+
_cli(board, this, &_prefs, this)
480476
{
481-
my_radio = &radio;
482477
memset(known_clients, 0, sizeof(known_clients));
483478
next_local_advert = next_flood_advert = 0;
484479
_logging = false;
@@ -510,18 +505,16 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
510505
// load persisted prefs
511506
_cli.loadPrefs(_fs);
512507

513-
_phy->setFrequency(_prefs.freq);
514-
_phy->setSpreadingFactor(_prefs.sf);
515-
_phy->setBandwidth(_prefs.bw);
516-
_phy->setCodingRate(_prefs.cr);
517-
_phy->setOutputPower(_prefs.tx_power_dbm);
508+
radio_set_params(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
509+
radio_set_tx_power(_prefs.tx_power_dbm);
518510

519511
updateAdvertTimer();
520512
updateFloodAdvertTimer();
521513
}
522514

523515
const char* getFirmwareVer() override { return FIRMWARE_VERSION; }
524516
const char* getBuildDate() override { return FIRMWARE_BUILD_DATE; }
517+
const char* getRole() override { return FIRMWARE_ROLE; }
525518
const char* getNodeName() { return _prefs.node_name; }
526519

527520
void savePrefs() override {
@@ -582,7 +575,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
582575
}
583576

584577
void setTxPower(uint8_t power_dbm) override {
585-
_phy->setOutputPower(power_dbm);
578+
radio_set_tx_power(power_dbm);
586579
}
587580

588581
void loop() {
@@ -609,14 +602,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
609602
StdRNG fast_rng;
610603
SimpleMeshTables tables;
611604

612-
#ifdef ESP32
613-
ESP32RTCClock fallback_clock;
614-
#else
615-
VolatileRTCClock fallback_clock;
616-
#endif
617-
AutoDiscoverRTCClock rtc_clock(fallback_clock);
618-
619-
MyMesh the_mesh(radio, board, *new WRAPPER_CLASS(radio, board), *new ArduinoMillis(), fast_rng, rtc_clock, tables);
605+
MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables);
620606

621607
void halt() {
622608
while (1) ;
@@ -629,14 +615,10 @@ void setup() {
629615
delay(1000);
630616

631617
board.begin();
632-
#ifdef ESP32
633-
fallback_clock.begin();
634-
#endif
635-
rtc_clock.begin(Wire);
636618

637619
if (!radio_init()) { halt(); }
638620

639-
fast_rng.begin(radio.random(0x7FFFFFFF));
621+
fast_rng.begin(radio_get_rng_seed());
640622

641623
FILESYSTEM* fs;
642624
#if defined(NRF52_PLATFORM)
@@ -652,8 +634,7 @@ void setup() {
652634
#endif
653635
if (!store.load("_main", the_mesh.self_id)) {
654636
MESH_DEBUG_PRINTLN("Generating new keypair");
655-
RadioNoiseListener rng(radio);
656-
the_mesh.self_id = mesh::LocalIdentity(&rng); // create new random identity
637+
the_mesh.self_id = radio_new_identity(); // create new random identity
657638
store.save("_main", the_mesh.self_id);
658639
}
659640

0 commit comments

Comments
 (0)