Expose Companion flood retry controls and clarify T096 fixed TX PA

This commit is contained in:
mikecarper committed 2026-09-26 10:31:54 -07:00
1 parent 90dee6cd1b
commit d4b3bb5678
9 files changed
+336 -12

No files matched your search

+20 -1
View File
@@ -51,6 +51,8 @@ int main(int argc,char** argv){
original.gps_interval=123;original.sf=7;original.cr=7;original.bw=62.5f;
original.tx_delay_factor=1.25f;original.direct_tx_delay_factor=0.75f;
original.interference_threshold=8;original.agc_reset_interval=15;original.tz_offset=-7;
original.flood_retry_attempts=4;original.flood_retry_max_path=3;
original.flood_retry_group_max_path=2;original.flood_retry_advert_enabled=0;
#ifdef TBEAM_1W
strcpy(original.fan_mode,"on");original.fan_lo=33;original.fan_hi=42;
#endif
@@ -84,6 +86,8 @@ int main(int argc,char** argv){
assert(loaded.freq==changed.freq&&loaded.ble_pin==original.ble_pin);
assert(loaded.tx_delay_factor==1.25f&&loaded.direct_tx_delay_factor==0.75f);
assert(loaded.interference_threshold==8&&loaded.agc_reset_interval==15&&loaded.tz_offset==-7);
assert(loaded.flood_retry_attempts==4&&loaded.flood_retry_max_path==3);
assert(loaded.flood_retry_group_max_path==2&&loaded.flood_retry_advert_enabled==0);
#ifdef TBEAM_1W
assert(!strcmp(loaded.fan_mode,"on")&&loaded.fan_lo==33&&loaded.fan_hi==42);
#endif
@@ -166,7 +170,22 @@ int main(int argc,char** argv){
assert(legacy.loadPrefs(loaded,lat,lon));
assert(loaded.tx_delay_factor==0.5f&&loaded.direct_tx_delay_factor==0.2f);
assert(loaded.interference_threshold==0&&loaded.agc_reset_interval==0&&loaded.tz_offset==0);
assert(loaded.flood_retry_attempts==15&&loaded.flood_retry_max_path==1);
assert(loaded.flood_retry_group_max_path==0xff&&loaded.flood_retry_advert_enabled==1);
assert(loaded.freq==original.freq&&loaded.ble_pin==original.ble_pin);
} else if(scenario==6){
DataStore legacy;legacy.fs.files["/new_prefs"]=disk;
#if defined(TBEAM_1W)
legacy.fs.files["/new_prefs"].resize(233);
#elif defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
legacy.fs.files["/new_prefs"].resize(323);
#else
legacy.fs.files["/new_prefs"].resize(226);
#endif
CompanionNodePrefs loaded;double lat=0,lon=0;
assert(legacy.loadPrefs(loaded,lat,lon));
assert(loaded.flood_retry_attempts==15&&loaded.flood_retry_max_path==1);
assert(loaded.flood_retry_group_max_path==0xff&&loaded.flood_retry_advert_enabled==1);
} else if(scenario==4){
DataStore legacy;legacy.fs.files["/node_prefs"]=disk;
legacy.fs.fail_write_after=17;
@@ -254,7 +273,7 @@ inline char* utoa(unsigned int value,char* output,int base){
str(ROOT / 'src/helpers/TxtDataHelpers.cpp'),
'-o', str(binary)], capture_output=True, text=True)
self.assertEqual(build.returncode, 0, build.stdout + build.stderr)
for scenario in range(6):
for scenario in range(7):
with self.subTest(scenario=scenario):
run = subprocess.run([str(binary), str(scenario)], capture_output=True, text=True)
self.assertEqual(run.returncode, 0, run.stdout + run.stderr)
+113
View File
@@ -0,0 +1,113 @@
"""Exercise Companion's production retry command parser and save semantics."""
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
HARNESS = r'''
#include <cassert>
#include <cstring>
#include <initializer_list>
#include "examples/companion_radio/CompanionRetry.h"
int main() {
CompanionNodePrefs prefs;
char reply[160] = {};
int saves = 0, cancels = 0;
bool save_ok = true;
auto save = [&]() { ++saves; return save_ok; };
auto cancel = [&]() { ++cancels; };
auto run = [&](const char* command) {
memset(reply, 0, sizeof(reply));
return mesh::companion::handleRetryCommand(
prefs, command, reply, sizeof(reply), save, cancel);
};
assert(run("get flood.retry.count") && !strcmp(reply, "> 15"));
assert(run("get flood.retry.path") && !strcmp(reply, "> 1"));
assert(run("get flood.retry.group.path") && !strcmp(reply, "> off"));
assert(run("get flood.retry.advert") && !strcmp(reply, "> on"));
assert(saves == 0);
assert(run("set flood.retry.count 8") && !strcmp(reply, "OK"));
assert(run("get flood.retry.count") && !strcmp(reply, "> 8"));
assert(run("set flood.retry.count 2") && !strcmp(reply, "OK"));
assert(run("get flood.retry.count") && !strcmp(reply, "> 2"));
assert(run("set flood.retry.path off") && !strcmp(reply, "OK"));
assert(run("get flood.retry.path") && !strcmp(reply, "> off"));
assert(run("set flood.retry.group.path 3") && !strcmp(reply, "OK"));
assert(run("get flood.retry.group.path") && !strcmp(reply, "> 3"));
assert(run("set flood.retry.advert off") && !strcmp(reply, "OK"));
assert(run("get flood.retry.advert") && !strcmp(reply, "> off"));
const int saved_before_invalid = saves;
for (const char* command : {"set flood.retry.count 16",
"set flood.retry.count -1",
"set flood.retry.count 3junk",
"set flood.retry.path 64",
"set flood.retry.group.path",
"set flood.retry.advert maybe"}) {
assert(run(command) && !strncmp(reply, "Error:", 6));
}
assert(saves == saved_before_invalid);
assert(prefs.flood_retry_attempts == 2);
assert(prefs.flood_retry_max_path == 0xff);
assert(prefs.flood_retry_group_max_path == 3);
assert(prefs.flood_retry_advert_enabled == 0);
save_ok = false;
assert(run("set flood.retry.count 0"));
assert(!strcmp(reply, "Error: retry setting could not be saved"));
assert(prefs.flood_retry_attempts == 2 && cancels == 0);
assert(run("set flood.retry.advert on"));
assert(prefs.flood_retry_advert_enabled == 0);
save_ok = true;
assert(run("set flood.retry.count 0") && !strcmp(reply, "OK"));
assert(prefs.flood_retry_attempts == 0 && cancels == 1);
assert(run("set flood.retry.count 0") && cancels == 1);
assert(!run("set flood.retry.bridge on"));
}
'''
class CompanionRetrySettingsTests(unittest.TestCase):
def test_retry_commands(self):
with tempfile.TemporaryDirectory() as directory:
work = Path(directory)
source = work / "retry.cpp"
binary = work / "retry"
source.write_text(HARNESS)
(work / "Utils.h").write_text('''#pragma once
#include <Arduino.h>
#include <cassert>
namespace mesh { struct Utils {
static void printHex(Stream&,const uint8_t*,size_t){assert(false);}
static void fromHex(uint8_t*,size_t,const char*){assert(false);}
}; }
''')
build = subprocess.run([
"g++", "-std=c++17", "-DNRF52_PLATFORM=1",
"-fsanitize=address,undefined", "-fno-sanitize-recover=all",
"-fno-pie", "-no-pie",
"-I", str(work),
"-I", str(ROOT / "test/fixtures/radio_profiles/mocks"),
"-I", str(ROOT / "test/mocks"),
"-I", str(ROOT / "src"),
"-I", str(ROOT),
str(source),
str(ROOT / "src/helpers/ConfigSerializer.cpp"),
str(ROOT / "src/helpers/DynamicConfigSerializer.cpp"),
str(ROOT / "src/helpers/CommonRadioPrefs.cpp"),
str(ROOT / "src/helpers/TxtDataHelpers.cpp"),
"-o", str(binary),
], capture_output=True, text=True)
self.assertEqual(build.returncode, 0, build.stdout + build.stderr)
run = subprocess.run([str(binary)], capture_output=True, text=True)
self.assertEqual(run.returncode, 0, run.stdout + run.stderr)
if __name__ == "__main__":
unittest.main()