Apply infrastructure radio changes after a two-second reply handoff
Persist set freq and set radio atomically, then apply through the existing safe radio scheduler without rebooting. Retain the old tuple until the delay and reply handoff finish, including queued room/sensor replies and TX-complete callbacks. End temporary sessions when accepting a permanent change. Display applied RF settings even when radio2 is off. Share radio validation across immediate and scheduled setters to preserve STM32 Mini flash capacity. Update command documentation, regression coverage, and CI. Validated production timing, persistence, display, CLI, fleet/reply, RX, sleep and Morse regressions. W12 repeater, room-server and sensor builds pass. Canonical STM32 Mini Repeater passes flash and RAM admission with 448 bytes of flash remaining. Physical W12 RF testing was not performed.
This commit is contained in:
1 parent
c98684021a
commit
4f76345b67
22 files changed
+414
-67
No files matched your search
Vendored
+6
@@ -55,6 +55,7 @@ struct Prefs {
|
||||
uint8_t sf=7, cr=5, interference_threshold=0, agc_reset_interval=0;
|
||||
uint8_t path_hash_mode=0, multi_acks=0, rx_ps_level=0, rx_ps_preamble=0;
|
||||
int8_t tx_power_dbm=10;
|
||||
uint16_t primary_radio_preamble=0;
|
||||
uint32_t rx_ps_rx_us=1000, rx_ps_sleep_us=1000;
|
||||
bool cad_enabled=false, rx_boosted_gain=false, rx_powersaving_enabled=false;
|
||||
uint8_t extra_sf[4]={};
|
||||
@@ -111,6 +112,11 @@ public:
|
||||
uint8_t _rx_settings_pending=0;
|
||||
uint32_t _rx_settings_retry_at=0;
|
||||
void savePrefs() { callbacks.savePrefs(); }
|
||||
bool applyAndSavePrimaryRadioParams(float f,float bw,uint8_t sf,uint8_t cr,uint16_t preamble,char* reply) {
|
||||
if (!savePrimaryRadioParams(f,bw,sf,cr,preamble)) return false;
|
||||
strcpy(reply,"OK - applying in 2s"); return true;
|
||||
}
|
||||
@PRIMARY_VALIDATE@
|
||||
bool trySavePrefs() { savePrefs(); return true; }
|
||||
void applyAndSaveTxPower(int8_t power, char* reply);
|
||||
void servicePendingTxPower();
|
||||
|
||||
@@ -325,6 +325,8 @@ namespace mesh { struct Utils {
|
||||
fixture = template.replace('@SET@', ' else '.join(set_blocks))
|
||||
fixture = fixture.replace('@GET@', ' else '.join(get_blocks))
|
||||
fixture = fixture.replace('@DISPATCH@', dispatch)
|
||||
fixture = fixture.replace('@PRIMARY_VALIDATE@', extract_braced(
|
||||
source, 'bool CommonCLI::acceptsPrimaryRadioParams(').replace('CommonCLI::', ''))
|
||||
fixture = fixture.replace('@KEY_EQUALS@', extract_braced(source, 'static bool configKeyEquals('))
|
||||
fixture = fixture.replace('@TX_METHODS@', '\n'.join(
|
||||
extract_braced(source, signature).replace('CommonCLI::', 'CLI::')
|
||||
|
||||
@@ -84,6 +84,7 @@ struct CommonCLI {
|
||||
void savePrefs(FILESYSTEM*,PrefsSaveRouting::Scope);
|
||||
bool saveCommonPrefs();
|
||||
bool savePrimaryRadioParams(float,float,uint8_t,uint8_t,uint16_t);
|
||||
bool acceptsPrimaryRadioParams(float,float,uint8_t,uint8_t,uint16_t);
|
||||
static void recalculateRxPowerSavingFromLevel(NodePrefs* p) {
|
||||
p->rx_ps_rx_us=p->sf*100; p->rx_ps_sleep_us=p->cr*200;
|
||||
}
|
||||
@@ -176,6 +177,8 @@ int main() {
|
||||
assert(cli.loadTail({0,64,0,1,0xff})==64 && cli.prefs.gps_sync_interval_hours==48);
|
||||
for(float bad : {NAN,INFINITY,149.0f,2501.0f})
|
||||
assert(!cli.savePrimaryRadioParams(bad,125,9,6,0));
|
||||
for(float bad : {NAN,INFINITY,-INFINITY,-125.0f})
|
||||
assert(!cli.savePrimaryRadioParams(920,bad,9,6,0));
|
||||
assert(cli.fs.files["/com_prefs"]==committed);
|
||||
}
|
||||
'''
|
||||
@@ -263,7 +266,8 @@ int main() {
|
||||
fields = re.sub(r'\b'+macro+r'\b', value, fields)
|
||||
methods = '\n'.join(extract_braced(source, signature) for signature in (
|
||||
'void CommonCLI::savePrefs(FILESYSTEM*', 'bool CommonCLI::saveCommonPrefs(',
|
||||
'bool CommonCLI::savePrimaryRadioParams('))
|
||||
'bool CommonCLI::savePrimaryRadioParams(',
|
||||
'bool CommonCLI::acceptsPrimaryRadioParams('))
|
||||
serializer = 'template<typename Writer>\n' + extract_braced(source, 'static bool writeCommonPrefsImage(')
|
||||
tail = extract_braced(source, 'if (file.available() >= (int)sizeof(_prefs->bridge_format))')
|
||||
code = HARNESS.replace('@FIELDS@',fields).replace('@METHODS@',("\n#include <stddef.h>\ntemplate<typename Writer>\n" + extract_braced(source, "static void writeCommonRetryPrefs(") + "\n" + methods))
|
||||
|
||||
@@ -193,6 +193,7 @@ int main(int argc,char** argv){
|
||||
|
||||
PRIMARY_EXTRA = r'''
|
||||
struct PrimaryFixture {
|
||||
@PRIMARY_ACCEPT@
|
||||
fs::FS disk;Mesh mesh;PhysicalRadio physical;RadioProfileCLI profiles;MyMesh node;
|
||||
FleetChannel fleet{&disk,&node};LocalIdentity publisher;unsigned dispatched=0;char reply[160]={};
|
||||
PrimaryFixture(){fake_ms=1000;node.rtc.now=mesh.clock.now;profiles.begin(&disk,&physical,&mesh.clock,true);
|
||||
@@ -400,6 +401,7 @@ uint16_t rxPowerSavingPreambleForParams(uint8_t,float){return 32;}
|
||||
start=cli.index(' } else if (memcmp(config, "radioat ", 8) == 0)')
|
||||
end=cli.index(' } else if (memcmp(config, "lat ", 4) == 0)',start)
|
||||
primary_extra=PRIMARY_EXTRA.replace('@PRIMARY_SET@',cli[start:end])
|
||||
primary_extra=primary_extra.replace('@PRIMARY_ACCEPT@',body(cli,'bool CommonCLI::acceptsPrimaryRadioParams(').replace('CommonCLI::','').replace('_radio_profiles','profiles'))
|
||||
physical,secondary=HARNESS.split('struct Fixture {',1)
|
||||
secondary=('struct Fixture {'+secondary).replace(' assert(argc==2);const std::string scenario=argv[1];Fixture f;',
|
||||
' assert(argc==2);if(!strncmp(argv[1],"primary_",8))return primary(argc,argv);const std::string scenario=argv[1];Fixture f;')
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
"""Run permanent CLI setters, delay and room/sensor apply paths from production."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from test_repeater_radio_timing_integration import method
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
HARNESS = r'''
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <math.h>
|
||||
#include <initializer_list>
|
||||
#include <helpers/CLICommandUtils.h>
|
||||
#include <helpers/RadioProfileCommandUtils.h>
|
||||
#define MAX_LORA_TX_POWER 22
|
||||
#include <helpers/radiolib/RadioPowerLimits.h>
|
||||
#define MESH_DEBUG_PRINTLN(...) ((void)0)
|
||||
static uint32_t now_ms=100;
|
||||
uint32_t millis(){return now_ms;}
|
||||
bool isValidLoRaBandwidth(float bw){return bw==62.5f || bw==125;}
|
||||
struct Prefs {
|
||||
float freq=910.51f,bw=62.5f;
|
||||
uint8_t sf=7,cr=5,rx_ps_level=0;
|
||||
uint16_t primary_radio_preamble=32,rx_ps_preamble=0;
|
||||
uint32_t rx_ps_rx_us=100,rx_ps_sleep_us=200;
|
||||
int8_t tx_power_dbm=30;
|
||||
bool rx_powersaving_enabled=false;
|
||||
};
|
||||
struct Callbacks {virtual bool scheduleNormalRadio()=0;};
|
||||
namespace mesh {
|
||||
enum class RadioParamApplyResult{APPLIED,BUSY,FAILED};
|
||||
struct RadioProfileCLI {
|
||||
static bool parseSuffix(const char*,unsigned,char*,size_t,uint16_t&);
|
||||
bool acceptsPrimary(float,float,uint8_t,uint8_t,uint16_t){return true;}
|
||||
void adoptPrimaryPreamble(uint16_t){}
|
||||
void appendPrimaryChirpWarning(char*,size_t,uint8_t,float,uint16_t){}
|
||||
RadioParamApplyResult applyPrimary(float,float,uint8_t,uint8_t,bool,uint16_t,const uint32_t*) {
|
||||
return RadioParamApplyResult::APPLIED;
|
||||
}
|
||||
};
|
||||
@SUFFIX@
|
||||
}
|
||||
struct CommonCLI {
|
||||
Prefs* _prefs;
|
||||
Callbacks* _callbacks;
|
||||
mesh::RadioProfileCLI _radio_profiles;
|
||||
uint32_t _primary_radio_apply_at=0;
|
||||
bool save_ok=true;
|
||||
unsigned saves=0;
|
||||
bool saveCommonPrefs(){++saves;return save_ok;}
|
||||
bool savePrimaryRadioParams(float,float,uint8_t,uint8_t,uint16_t);
|
||||
bool acceptsPrimaryRadioParams(float,float,uint8_t,uint8_t,uint16_t);
|
||||
bool applyAndSavePrimaryRadioParams(float,float,uint8_t,uint8_t,uint16_t,char*);
|
||||
bool primaryRadioApplyReady(bool reply_idle=true);
|
||||
void command(const char*,char*);
|
||||
mesh::RadioProfileCLI& radioProfiles(){return _radio_profiles;}
|
||||
static void recalculateRxPowerSavingFromLevel(Prefs* p){p->rx_ps_rx_us=300;p->rx_ps_sleep_us=400;}
|
||||
static bool calculateRxPowerSavingLevel(uint8_t,uint8_t,float,uint32_t,uint32_t*,uint32_t*){return true;}
|
||||
};
|
||||
void appendRxPowerSavingAdjustmentNote(char*,Prefs*,uint8_t,float){}
|
||||
uint32_t rxPowerSavingPreambleForParams(uint8_t,float){return 16;}
|
||||
uint32_t nextRadioApplyRetryDelay(uint8_t& failures){++failures;return 1000;}
|
||||
struct {bool supportsRxPowerSaving(){return false;}} radio_driver;
|
||||
struct Role:Callbacks {
|
||||
Prefs _prefs;
|
||||
CommonCLI _cli{&_prefs,this};
|
||||
uint32_t set_radio_at=0,revert_radio_at=0,radio_apply_retry_at=0;
|
||||
uint8_t radio_apply_failures=0,active_cr=5,pending_sf=7,pending_cr=5;
|
||||
uint16_t pending_preamble=32;
|
||||
float pending_freq=911,pending_bw=125,active_freq=910.51f;
|
||||
bool temp_radio_applied=false,saved_radio_apply_pending=false,outbound=false,apply_ok=true;
|
||||
struct Manager {unsigned queued=0;unsigned getOutboundTotal(){return queued;}} manager;
|
||||
Manager* _mgr=&manager;
|
||||
unsigned apply_attempts=0;
|
||||
uint32_t futureMillis(uint32_t delay){return now_ms+delay;}
|
||||
bool millisHasNowPassed(uint32_t at){return int32_t(now_ms-at)>=0;}
|
||||
bool hasOutbound(){return outbound;}
|
||||
bool applySavedRadioParams(){++apply_attempts;if(!apply_ok)return false;active_freq=_prefs.freq;return true;}
|
||||
bool scheduleNormalRadio() override;
|
||||
void servicePendingPrimaryRadioSettings(bool tx_gap=false);
|
||||
};
|
||||
@METHODS@
|
||||
void CommonCLI::command(const char* config,char* reply) {
|
||||
@RADIO@
|
||||
else @FREQ@
|
||||
}
|
||||
int main(){
|
||||
for(const char* command:{"freq 915.25","radio 915.25,125,9,6,48"}) {
|
||||
for(bool temporary:{false,true}) {
|
||||
now_ms=100;
|
||||
Role node;node.temp_radio_applied=temporary;
|
||||
char reply[160]{};
|
||||
node._cli.save_ok=false;
|
||||
node._cli.command(command,reply);
|
||||
assert(strstr(reply,"Error") && node._prefs.freq==910.51f);
|
||||
assert(node._prefs.tx_power_dbm==30 && node._prefs.rx_ps_rx_us==100);
|
||||
assert(!node._cli._primary_radio_apply_at && !node.saved_radio_apply_pending);
|
||||
node._cli.save_ok=true;
|
||||
node._cli.command(command,reply);
|
||||
assert(strstr(reply,"applying in 2s") && strstr(reply,"TX power limited to 22"));
|
||||
assert(node._prefs.freq==915.25f && node.active_freq==910.51f);
|
||||
assert(node.saved_radio_apply_pending);
|
||||
if(command[0]=='f')assert(node._prefs.bw==62.5f && node._prefs.primary_radio_preamble==32);
|
||||
else assert(node._prefs.bw==125 && node._prefs.sf==9 && node._prefs.cr==6 && node._prefs.primary_radio_preamble==48);
|
||||
for(now_ms=101;now_ms<2100;now_ms+=333) {
|
||||
node.servicePendingPrimaryRadioSettings(true);
|
||||
assert(node.apply_attempts==0 && node.active_freq==910.51f);
|
||||
}
|
||||
now_ms=2100;node.outbound=true;
|
||||
node.servicePendingPrimaryRadioSettings();
|
||||
assert(node.apply_attempts==0); // Keep the current reply on the old tuple.
|
||||
node.outbound=false;node.manager.queued=1;
|
||||
node.servicePendingPrimaryRadioSettings(true);
|
||||
assert(node.apply_attempts==0); // A different packet finishing cannot lose our queued reply.
|
||||
node.manager.queued=0;node.apply_ok=false;
|
||||
node.servicePendingPrimaryRadioSettings();
|
||||
assert(node.apply_attempts==1 && node.saved_radio_apply_pending);
|
||||
node.apply_ok=true;now_ms=3100;
|
||||
node.servicePendingPrimaryRadioSettings();
|
||||
assert(node.active_freq==915.25f && !node.saved_radio_apply_pending && !node.temp_radio_applied);
|
||||
}
|
||||
}
|
||||
// A second accepted edit restarts the two-second handoff; malformed edits
|
||||
// neither save nor replace an already accepted deadline.
|
||||
Role node; char reply[160];now_ms=100;
|
||||
node._cli.command("freq 915",reply);
|
||||
now_ms=1500;node._cli.command("freq 916",reply);
|
||||
assert(node._cli._primary_radio_apply_at==3500);
|
||||
unsigned saves=node._cli.saves;
|
||||
for(const char* invalid:{"freq nan","freq 149","radio 915,125,13,5","radio 915,125,7,5,7"}) {
|
||||
node._cli.command(invalid,reply);
|
||||
assert(strstr(reply,"Error") && node._cli.saves==saves && node._cli._primary_radio_apply_at==3500);
|
||||
}
|
||||
now_ms=3499;node.servicePendingPrimaryRadioSettings(true);assert(node.apply_attempts==0);
|
||||
now_ms=3500;node.servicePendingPrimaryRadioSettings();assert(node.active_freq==916);
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class InfrastructureRadioApplyTest(unittest.TestCase):
|
||||
def test_room_and_sensor_permanent_cli_handoff(self):
|
||||
common = (ROOT / "src/helpers/CommonCLI.cpp").read_text()
|
||||
helpers = "\n".join(method(common, signature) for signature in (
|
||||
"bool CommonCLI::savePrimaryRadioParams(",
|
||||
"bool CommonCLI::acceptsPrimaryRadioParams(",
|
||||
"bool CommonCLI::applyAndSavePrimaryRadioParams(",
|
||||
"bool CommonCLI::primaryRadioApplyReady("))
|
||||
suffix = method((ROOT / "src/helpers/RadioProfileCLI.cpp").read_text(),
|
||||
"bool RadioProfileCLI::parseSuffix(")
|
||||
def setter(key):
|
||||
anchor = common.index(f'memcmp(config, "{key} ",')
|
||||
start = common.rfind('} else if (', 0, anchor) + len('} else ')
|
||||
return method(common[start:], 'if (').replace('#ifdef WITH_BRIDGE\n', '')
|
||||
for file, role in (("simple_room_server/MyMesh.cpp", "MyMesh"),
|
||||
("simple_sensor/SensorMesh.cpp", "SensorMesh")):
|
||||
with self.subTest(role=role), tempfile.TemporaryDirectory() as temp:
|
||||
source = (ROOT / "examples" / file).read_text()
|
||||
methods = helpers + "\n" + "\n".join(
|
||||
method(source, signature).replace(role + "::", "Role::")
|
||||
for signature in (f"bool {role}::scheduleNormalRadio()",
|
||||
f"void {role}::servicePendingPrimaryRadioSettings("))
|
||||
code = HARNESS.replace('@METHODS@', methods).replace('@SUFFIX@', suffix)
|
||||
code = code.replace('@RADIO@', setter('radio')).replace('@FREQ@', setter('freq'))
|
||||
cpp = Path(temp) / "test.cpp"
|
||||
binary = Path(temp) / "test"
|
||||
cpp.write_text(code)
|
||||
subprocess.run(['c++', '-std=c++17', '-I'+str(ROOT/'src'),
|
||||
str(cpp), '-o', str(binary)], check=True)
|
||||
subprocess.run([str(binary)], check=True)
|
||||
|
||||
def test_screens_show_applied_tuple_with_radio2_off_or_on(self):
|
||||
# Compile the actual render/signature/dashboard selection blocks. A
|
||||
# saved edit must not move the screen before the PHY accepts it.
|
||||
selections = []
|
||||
for role in ('simple_repeater', 'simple_room_server', 'simple_sensor'):
|
||||
source = (ROOT / 'examples' / role / 'UITask.cpp').read_text()
|
||||
offset = 0
|
||||
while True:
|
||||
start = source.find('float freq = _node_prefs->freq;', offset)
|
||||
if start < 0:
|
||||
break
|
||||
condition = source.index('if (', start)
|
||||
block = method(source[condition:], 'if (')
|
||||
end = condition + len(block)
|
||||
selections.append(source[start:end] + '\nreturn {freq,bw,sf,cr};')
|
||||
offset = end
|
||||
if 'bool UITask::buildDashboardContext(' in source:
|
||||
start = source.index('ctx->freq = _node_prefs->freq;',
|
||||
source.index('bool UITask::buildDashboardContext('))
|
||||
condition = source.index('if (profiles', start)
|
||||
end = condition + len(method(source[condition:], 'if ('))
|
||||
selections.append('View context; View* ctx=&context;\n' + source[start:end]
|
||||
+ '\nreturn context;')
|
||||
self.assertEqual(len(selections), 7)
|
||||
code = r'''
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <RadioProfiles.h>
|
||||
#include <helpers/ui/RadioProfileDisplayPage.h>
|
||||
#include <helpers/ui/DisplayFrameSignature.h>
|
||||
struct View{float freq,bw;uint8_t sf,cr;const char* radio_label="";};
|
||||
static View saved{920,125,9,6};
|
||||
static View* _node_prefs=&saved;
|
||||
static mesh::RadioProfiles state;
|
||||
static const mesh::RadioProfiles* configuredRadioProfiles(){return &state;}
|
||||
static bool secondary_page=false;
|
||||
static bool showingSecondaryRadioProfilePage(){return secondary_page;}
|
||||
'''
|
||||
for i, selection in enumerate(selections):
|
||||
# Dashboard declares its own profiles pointer.
|
||||
setup = '' if 'const mesh::RadioProfiles* profiles' in selection else (
|
||||
'const auto* profiles=configuredRadioProfiles();')
|
||||
code += f'View render{i}(){{' + setup + (
|
||||
'const bool dual_radio=state.enabled();'
|
||||
'uint32_t signature=DisplayFrameSignature::INITIAL;') + selection + '}\n'
|
||||
code += 'int main(){\n'
|
||||
for i in range(len(selections)):
|
||||
code += f'''
|
||||
state.primary.freq=910.51f;state.primary.bw=62.5f;state.primary.sf=7;state.primary.cr=5;
|
||||
state.secondary.params.freq=911;state.secondary.params.bw=125;state.secondary.params.sf=8;state.secondary.params.cr=6;
|
||||
state.secondary.mode=mesh::RadioProfileMode::Off;secondary_page=true;
|
||||
auto v{i}=render{i}();assert(v{i}.freq==910.51f && v{i}.bw==62.5f && v{i}.sf==7);
|
||||
state.primary.freq=920;state.primary.bw=125;state.primary.sf=9;
|
||||
v{i}=render{i}();assert(v{i}.freq==920 && v{i}.bw==125 && v{i}.sf==9);
|
||||
state.primary_temporary=true;state.primary.freq=912;
|
||||
v{i}=render{i}();assert(v{i}.freq==912);
|
||||
state.secondary.mode=mesh::RadioProfileMode::Rx;
|
||||
v{i}=render{i}();assert(v{i}.freq==911 && v{i}.sf==8);
|
||||
secondary_page=false;v{i}=render{i}();assert(v{i}.freq==912);
|
||||
'''
|
||||
code += '}\n'
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
cpp = Path(temp) / 'display.cpp'
|
||||
binary = Path(temp) / 'display'
|
||||
cpp.write_text(code)
|
||||
subprocess.run(['c++', '-std=c++17', '-I'+str(ROOT/'src'), str(cpp),
|
||||
'-o', str(binary)], check=True)
|
||||
subprocess.run([str(binary)], check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -394,11 +394,31 @@ class LocalCliAccessTest(unittest.TestCase):
|
||||
struct Prefs {
|
||||
float freq=910.525f,bw=62.5f;
|
||||
uint8_t sf=7,cr=5;
|
||||
uint16_t primary_radio_preamble=32;
|
||||
int8_t tx_power_dbm=30;
|
||||
} prefs;
|
||||
Prefs* _prefs=&prefs;
|
||||
int saves=0;
|
||||
void savePrefs(){++saves;}
|
||||
int schedules=0;
|
||||
bool save_ok=true;
|
||||
bool savePrimaryRadioParams(float f,float bw,uint8_t sf,uint8_t cr,uint16_t preamble) {
|
||||
++saves;
|
||||
if (!save_ok) return false;
|
||||
_prefs->freq=f; _prefs->bw=bw; _prefs->sf=sf; _prefs->cr=cr;
|
||||
_prefs->primary_radio_preamble=preamble;
|
||||
_prefs->tx_power_dbm=mesh::clampLoRaTxPower(_prefs->tx_power_dbm,f);
|
||||
return true;
|
||||
}
|
||||
bool applyAndSavePrimaryRadioParams(float f,float bw,uint8_t sf,uint8_t cr,uint16_t preamble,char* reply){
|
||||
const auto previous_power=_prefs->tx_power_dbm;
|
||||
if(!savePrimaryRadioParams(f,bw,sf,cr,preamble)) {
|
||||
strcpy(reply,"Error: radio settings could not be saved");return false;
|
||||
}
|
||||
++schedules;
|
||||
strcpy(reply,previous_power!=_prefs->tx_power_dbm ?
|
||||
"OK - applying in 2s; TX power limited" : "OK - applying in 2s");
|
||||
return true;
|
||||
}
|
||||
void set(const char* config,uint32_t sender_timestamp,char* reply) {
|
||||
''' + setter + r'''
|
||||
}
|
||||
@@ -408,7 +428,7 @@ int main() {
|
||||
prefs=Prefs{};
|
||||
set("freq 915.25",stamp,reply);
|
||||
assert(prefs.freq==915.25f && prefs.tx_power_dbm==22);
|
||||
assert(strstr(reply,"reboot to apply") && strstr(reply,"TX power limited"));
|
||||
assert(strstr(reply,"applying in 2s") && strstr(reply,"TX power limited"));
|
||||
assert(prefs.bw==62.5f && prefs.sf==7 && prefs.cr==5);
|
||||
for(const char* bad:{"freq 149.9","freq 2500.1","freq 920oops",
|
||||
"freq NaN","freq inf","freq 1e3","freq "}) {
|
||||
@@ -418,10 +438,15 @@ int main() {
|
||||
}
|
||||
for(const char* boundary:{"freq 150","freq 2500"}) {
|
||||
set(boundary,stamp,reply);
|
||||
assert(strstr(reply,"OK - reboot to apply"));
|
||||
assert(strstr(reply,"OK - applying in 2s"));
|
||||
}
|
||||
}
|
||||
assert(saves==9);
|
||||
assert(saves==9 && schedules==9);
|
||||
const float previous=prefs.freq;
|
||||
save_ok=false;
|
||||
set("freq 920",0,reply);
|
||||
assert(strstr(reply,"Error") && prefs.freq==previous && schedules==9);
|
||||
assert(prefs.primary_radio_preamble==32);
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
|
||||
@@ -139,6 +139,7 @@ public:
|
||||
Callbacks* _callbacks = &callbacks;
|
||||
uint8_t _rx_settings_pending = 0;
|
||||
uint32_t _rx_settings_retry_at = 0;
|
||||
uint32_t _primary_radio_apply_at = 0;
|
||||
bool _tx_power_pending = false, _common_save_result_known = false, _common_save_succeeded = false;
|
||||
struct Profiles {
|
||||
bool pending = false;
|
||||
|
||||
@@ -90,6 +90,8 @@ struct CLI {
|
||||
CLI& radioProfiles() { return *this; }
|
||||
RadioPrefs* prefs = nullptr;
|
||||
int* saves = nullptr;
|
||||
uint32_t _primary_radio_apply_at = 0;
|
||||
@PRIMARY_READY@
|
||||
bool save_success = true;
|
||||
unsigned save_attempts = 0;
|
||||
unsigned fail_on_save = 0;
|
||||
@@ -204,6 +206,26 @@ static void startTemp(MyMesh& m, int minutes) {
|
||||
assert(m.temp_radio_applied);
|
||||
}
|
||||
int main() {
|
||||
for (uint32_t start : {100U, 0xFFFFFC18U, 0xFFFFF830U}) {
|
||||
MyMesh m;
|
||||
now_ms = start;
|
||||
m._cli._primary_radio_apply_at = now_ms + 2000;
|
||||
if (!m._cli._primary_radio_apply_at) m._cli._primary_radio_apply_at = 1;
|
||||
m.scheduleNormalRadio();
|
||||
m.processScheduledRadioSettings(true);
|
||||
assert(m.restores == 0 && m.saved_radio_apply_pending);
|
||||
now_ms = start + 1999;
|
||||
m.processScheduledRadioSettings(true); // A TX gap cannot bypass the delay.
|
||||
assert(m.restores == 0);
|
||||
now_ms = start + 2001;
|
||||
m.temp_radio_reply_barrier.held = true;
|
||||
m.processScheduledRadioSettings(true);
|
||||
assert(m.restores == 0); // Even after 2s, let the exact reply finish.
|
||||
m.temp_radio_reply_barrier.held = false;
|
||||
m.processScheduledRadioSettings(true);
|
||||
assert(m.restores == 1 && !m.saved_radio_apply_pending);
|
||||
}
|
||||
|
||||
for (unsigned failure = 0; failure <
|
||||
#ifdef USE_LR2021
|
||||
4
|
||||
@@ -530,6 +552,11 @@ int main() {
|
||||
'''
|
||||
|
||||
|
||||
HARNESS = HARNESS.replace("@PRIMARY_READY@", method(
|
||||
(ROOT / "src/helpers/CommonCLI.cpp").read_text(),
|
||||
"bool CommonCLI::primaryRadioApplyReady(").replace("CommonCLI::", "")
|
||||
.replace("bool reply_idle)", "bool reply_idle=true)"))
|
||||
|
||||
class RepeaterRadioTimingIntegrationTest(unittest.TestCase):
|
||||
def compile_and_run(self, source):
|
||||
with tempfile.TemporaryDirectory(prefix="meshcore-temp-timing-") as temp:
|
||||
|
||||
Reference in new issue
Block a user