Repeater, room server, sensor, companion: set commands refuse out-of-range or non-numeric values instead of saving them
Changelog: Repeater, room server, sensor, companion: `set tx`, `set radio`, `set freq` and other number settings now refuse a value that is out of range or not a number, instead of saving it and answering OK. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c58274a2e1
commit
14f5892033
9 files changed
+260
-56
No files matched your search
+47
-24
@@ -1,4 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include "CliArgs.h"
|
||||
#include "CommonCLI.h"
|
||||
#include "TxtDataHelpers.h"
|
||||
#include "AdvertDataHelpers.h"
|
||||
@@ -354,12 +355,14 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
StrHelper::strncpy(tmp, &command[10], sizeof(tmp));
|
||||
const char *parts[5];
|
||||
int num = mesh::Utils::parseTextParts(tmp, parts, 5);
|
||||
float freq = num > 0 ? strtof(parts[0], nullptr) : 0.0f;
|
||||
float bw = num > 1 ? strtof(parts[1], nullptr) : 0.0f;
|
||||
uint8_t sf = num > 2 ? atoi(parts[2]) : 0;
|
||||
uint8_t cr = num > 3 ? atoi(parts[3]) : 0;
|
||||
int temp_timeout_mins = num > 4 ? atoi(parts[4]) : 0;
|
||||
if (freq >= 150.0f && freq <= 2500.0f && sf >= 5 && sf <= 12 && cr >= 5 && cr <= 8 && bw >= 7.0f && bw <= 500.0f && temp_timeout_mins > 0) {
|
||||
float freq = 0, bw = 0;
|
||||
long sf_l = 0, cr_l = 0, mins_l = 0;
|
||||
if (num == 5 && cli_args::parseFloat(parts[0], 150.0f, 2500.0f, &freq) &&
|
||||
cli_args::parseFloat(parts[1], 7.0f, 500.0f, &bw) &&
|
||||
cli_args::parseInt(parts[2], 5, 12, &sf_l) && cli_args::parseInt(parts[3], 5, 8, &cr_l) &&
|
||||
cli_args::parseInt(parts[4], 1, 10080, &mins_l)) {
|
||||
uint8_t sf = sf_l, cr = cr_l;
|
||||
int temp_timeout_mins = mins_l;
|
||||
_callbacks->applyTempRadioParams(freq, bw, sf, cr, temp_timeout_mins);
|
||||
sprintf(reply, "OK - temp params for %d mins", temp_timeout_mins);
|
||||
} else {
|
||||
@@ -733,18 +736,28 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
savePrefs();
|
||||
strcpy(reply, _prefs->disable_fwd ? "OK - repeat is now OFF" : "OK - repeat is now ON");
|
||||
} else if (memcmp(config, "lat ", 4) == 0) {
|
||||
_prefs->node_lat = atof(&config[4]);
|
||||
_prefs->getGpsPrefs()->applyGuardReference(*_sensors);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
float v;
|
||||
if (cli_args::parseFloat(&config[4], -90.0f, 90.0f, &v)) {
|
||||
_prefs->node_lat = v;
|
||||
_prefs->getGpsPrefs()->applyGuardReference(*_sensors);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be -90..90");
|
||||
}
|
||||
} else if (memcmp(config, "lon ", 4) == 0) {
|
||||
_prefs->node_lon = atof(&config[4]);
|
||||
_prefs->getGpsPrefs()->applyGuardReference(*_sensors);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
float v;
|
||||
if (cli_args::parseFloat(&config[4], -180.0f, 180.0f, &v)) {
|
||||
_prefs->node_lon = v;
|
||||
_prefs->getGpsPrefs()->applyGuardReference(*_sensors);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be -180..180");
|
||||
}
|
||||
} else if (memcmp(config, "flood.max.unscoped ", 19) == 0) {
|
||||
uint8_t m = atoi(&config[19]);
|
||||
if (m <= 64) {
|
||||
long m; // was uint8_t = atoi(): "300" became 44 and passed
|
||||
if (cli_args::parseInt(&config[19], 0, 64, &m)) {
|
||||
_prefs->flood_max_unscoped = m;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
@@ -752,8 +765,8 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
strcpy(reply, "Error, max 64");
|
||||
}
|
||||
} else if (memcmp(config, "flood.max.advert ", 17) == 0) {
|
||||
uint8_t m = atoi(&config[17]);
|
||||
if (m <= 64) {
|
||||
long m; // was uint8_t = atoi(): "300" became 44 and passed
|
||||
if (cli_args::parseInt(&config[17], 0, 64, &m)) {
|
||||
_prefs->flood_max_advert = m;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
@@ -761,8 +774,8 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
strcpy(reply, "Error, max 64");
|
||||
}
|
||||
} else if (memcmp(config, "flood.max ", 10) == 0) {
|
||||
uint8_t m = atoi(&config[10]);
|
||||
if (m <= 64) {
|
||||
long m; // was uint8_t = atoi(): "300" became 44 and passed
|
||||
if (cli_args::parseInt(&config[10], 0, 64, &m)) {
|
||||
_prefs->flood_max = m;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
@@ -800,9 +813,14 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
strcpy(reply, "OK");
|
||||
}
|
||||
} else if (sender_timestamp == 0 && memcmp(config, "freq ", 5) == 0) {
|
||||
_prefs->freq = atof(&config[5]);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK - reboot to apply");
|
||||
float f; // was atof(): "abc" saved 0, i.e. 150 MHz after the next boot's clamp
|
||||
if (cli_args::parseFloat(&config[5], 150.0f, 2500.0f, &f)) {
|
||||
_prefs->freq = f;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK - reboot to apply");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be 150-2500 MHz");
|
||||
}
|
||||
#ifdef WITH_BRIDGE
|
||||
} else if (memcmp(config, "bridge.enabled ", 15) == 0) {
|
||||
_prefs->bridge_enabled = memcmp(&config[15], "on", 2) == 0;
|
||||
@@ -885,7 +903,12 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
strcpy(reply, "on - shows on next advert");
|
||||
}
|
||||
} else if (memcmp(config, "adc.multiplier ", 15) == 0) {
|
||||
_prefs->adc_multiplier = atof(&config[15]);
|
||||
float m;
|
||||
if (!cli_args::parseFloat(&config[15], 0.0f, 10.0f, &m)) {
|
||||
strcpy(reply, "Error, must be 0-10 (0 = board default)");
|
||||
return;
|
||||
}
|
||||
_prefs->adc_multiplier = m;
|
||||
if (_board->setAdcMultiplier(_prefs->adc_multiplier)) {
|
||||
savePrefs();
|
||||
if (_prefs->adc_multiplier == 0.0f) {
|
||||
|
||||
Reference in new issue
Block a user