Merge branch 'main' into rx_delay

# Conflicts:
#	examples/companion_radio/main.cpp
#	examples/simple_secure_chat/main.cpp
This commit is contained in:
Scott Powell
2025-02-09 13:06:01 +11:00
3 changed files with 44 additions and 39 deletions

View File

@@ -48,9 +48,9 @@
#include <helpers/BaseChatMesh.h>
#define SEND_TIMEOUT_BASE_MILLIS 300
#define SEND_TIMEOUT_BASE_MILLIS 500
#define FLOOD_SEND_TIMEOUT_FACTOR 16.0f
#define DIRECT_SEND_PERHOP_FACTOR 5.0f
#define DIRECT_SEND_PERHOP_FACTOR 6.0f
#define DIRECT_SEND_PERHOP_EXTRA_MILLIS 250
#define PUBLIC_GROUP_PSK "izOH6cXN6mrJ5e26oRXNcg=="
@@ -100,6 +100,7 @@ static uint32_t _atoi(const char* sp) {
#define CMD_SYNC_NEXT_MESSAGE 10
#define CMD_SET_RADIO_PARAMS 11
#define CMD_SET_RADIO_TX_POWER 12
#define CMD_RESET_PATH 13
#define RESP_CODE_OK 0
#define RESP_CODE_ERR 1
@@ -137,6 +138,7 @@ struct NodePrefs { // persisted to file
class MyMesh : public BaseChatMesh {
FILESYSTEM* _fs;
RADIO_CLASS* _phy;
NodePrefs _prefs;
uint32_t expected_ack_crc; // TODO: keep table of expected ACKs
mesh::GroupChannel* _public;
@@ -389,8 +391,8 @@ protected:
public:
MyMesh(RadioLibWrapper& radio, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
: BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), _serial(NULL)
MyMesh(RADIO_CLASS& phy, RadioLibWrapper& rw, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables)
: BaseChatMesh(rw, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables), _serial(NULL), _phy(&phy)
{
_iter_started = false;
offline_queue_len = 0;
@@ -406,12 +408,6 @@ public:
_prefs.tx_power_dbm = LORA_TX_POWER;
}
float getFreqPref() const { return _prefs.freq; }
uint8_t getSFPref() const { return _prefs.sf; }
uint8_t getCRPref() const { return _prefs.cr; }
float getBWPref() const { return _prefs.bw; }
uint8_t getTxPowerPref() const { return _prefs.tx_power_dbm; }
void begin(FILESYSTEM& fs, BaseSerialInterface& serial, mesh::RNG& trng) {
_fs = &fs;
_serial = &serial;
@@ -439,6 +435,12 @@ public:
loadContacts();
_public = addChannel(PUBLIC_GROUP_PSK); // pre-configure Andy's public channel
_phy->setFrequency(_prefs.freq);
_phy->setSpreadingFactor(_prefs.sf);
_phy->setBandwidth(_prefs.bw);
_phy->setCodingRate(_prefs.cr);
_phy->setOutputPower(_prefs.tx_power_dbm);
}
void savePrefs() {
@@ -590,6 +592,17 @@ public:
} else {
writeErrFrame();
}
} else if (cmd_frame[0] == CMD_RESET_PATH && len >= 1+32) {
uint8_t* pub_key = &cmd_frame[1];
ContactInfo* recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE);
if (recipient) {
recipient->out_path_len = -1;
//recipient->lastmod = ?? shouldn't be needed, app already has this version of contact
saveContacts();
writeOKFrame();
} else {
writeErrFrame(); // unknown contact
}
} else if (cmd_frame[0] == CMD_ADD_UPDATE_CONTACT && len >= 1+32+2+1) {
uint8_t* pub_key = &cmd_frame[1];
ContactInfo* recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE);
@@ -632,7 +645,14 @@ public:
_prefs.freq = (float)freq / 1000.0;
_prefs.bw = (float)bw / 1000.0;
savePrefs();
writeOKFrame(); // reboot now required!
_phy->setFrequency(_prefs.freq);
_phy->setSpreadingFactor(_prefs.sf);
_phy->setBandwidth(_prefs.bw);
_phy->setCodingRate(_prefs.cr);
MESH_DEBUG_PRINTLN("OK: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d", freq, bw, (uint32_t)sf, (uint32_t)cr);
writeOKFrame();
} else {
MESH_DEBUG_PRINTLN("Error: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d", freq, bw, (uint32_t)sf, (uint32_t)cr);
writeErrFrame();
@@ -643,7 +663,8 @@ public:
} else {
_prefs.tx_power_dbm = cmd_frame[1];
savePrefs();
writeOKFrame(); // reboot now required!
_phy->setOutputPower(_prefs.tx_power_dbm);
writeOKFrame();
}
} else {
writeErrFrame();
@@ -706,7 +727,7 @@ RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BU
#endif
StdRNG fast_rng;
SimpleMeshTables tables;
MyMesh the_mesh(*new WRAPPER_CLASS(radio, board), fast_rng, *new VolatileRTCClock(), tables);
MyMesh the_mesh(radio, *new WRAPPER_CLASS(radio, board), fast_rng, *new VolatileRTCClock(), tables);
void halt() {
while (1) ;
@@ -767,22 +788,6 @@ void setup() {
#else
#error "need to define filesystem"
#endif
if (LORA_FREQ != the_mesh.getFreqPref()) {
radio.setFrequency(the_mesh.getFreqPref());
}
if (LORA_SF != the_mesh.getSFPref()) {
radio.setSpreadingFactor(the_mesh.getSFPref());
}
if (LORA_BW != the_mesh.getBWPref()) {
radio.setBandwidth(the_mesh.getBWPref());
}
if (LORA_CR != the_mesh.getCRPref()) {
radio.setCodingRate(the_mesh.getCRPref());
}
if (LORA_TX_POWER != the_mesh.getTxPowerPref()) {
radio.setOutputPower(the_mesh.getTxPowerPref());
}
}
void loop() {

View File

@@ -51,7 +51,7 @@
#define ADMIN_PASSWORD "password"
#endif
#define MIN_LOCAL_ADVERT_INTERVAL 8
#define MIN_LOCAL_ADVERT_INTERVAL 60
#if defined(HELTEC_LORA_V3)
#include <helpers/HeltecV3Board.h>
@@ -123,7 +123,7 @@ struct NodePrefs { // persisted to file
float freq;
uint8_t tx_power_dbm;
uint8_t disable_fwd;
uint8_t advert_interval; // minutes
uint8_t advert_interval; // minutes / 2
uint8_t unused;
float rx_delay_base;
float tx_delay_factor;
@@ -192,14 +192,14 @@ class MyMesh : public mesh::Mesh {
}
void checkAdvertInterval() {
if (_prefs.advert_interval < MIN_LOCAL_ADVERT_INTERVAL) {
if (_prefs.advert_interval * 2 < MIN_LOCAL_ADVERT_INTERVAL) {
_prefs.advert_interval = 0; // turn it off, now that device has been manually configured
}
}
void updateAdvertTimer() {
if (_prefs.advert_interval > 0) { // schedule local advert timer
next_local_advert = futureMillis(_prefs.advert_interval * 60 * 1000);
next_local_advert = futureMillis((uint32_t)_prefs.advert_interval * 2 * 60 * 1000);
} else {
next_local_advert = 0; // stop the timer
}
@@ -425,7 +425,7 @@ public:
_prefs.password[sizeof(_prefs.password)-1] = 0; // truncate if necessary
_prefs.freq = LORA_FREQ;
_prefs.tx_power_dbm = LORA_TX_POWER;
_prefs.advert_interval = 2; // default to 2 minutes for NEW installs
_prefs.advert_interval = 1; // default to 2 minutes for NEW installs
}
float getFreqPref() const { return _prefs.freq; }
@@ -533,10 +533,10 @@ public:
int mins = _atoi(&config[16]);
if (mins > 0 && mins < MIN_LOCAL_ADVERT_INTERVAL) {
sprintf(reply, "Error: min is %d mins", MIN_LOCAL_ADVERT_INTERVAL);
} else if (mins > 120) {
strcpy(reply, "Error: max is 120 mins");
} else if (mins > 240) {
strcpy(reply, "Error: max is 240 mins");
} else {
_prefs.advert_interval = (uint8_t)mins;
_prefs.advert_interval = (uint8_t)(mins / 2);
updateAdvertTimer();
savePrefs();
strcpy(reply, "OK");

View File

@@ -42,9 +42,9 @@
#include <helpers/BaseChatMesh.h>
#define SEND_TIMEOUT_BASE_MILLIS 300
#define SEND_TIMEOUT_BASE_MILLIS 500
#define FLOOD_SEND_TIMEOUT_FACTOR 16.0f
#define DIRECT_SEND_PERHOP_FACTOR 5.0f
#define DIRECT_SEND_PERHOP_FACTOR 6.0f
#define DIRECT_SEND_PERHOP_EXTRA_MILLIS 250
#define PUBLIC_GROUP_PSK "izOH6cXN6mrJ5e26oRXNcg=="