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:
tthandClaude Opus 5.5 committed 2026-11-27 17:33:42 +01:00
1 parent c58274a2e1
commit 14f5892033
9 files changed
+260 -56

No files matched your search

+11 -5
View File
@@ -5,6 +5,7 @@
#include <WiFi.h>
#endif
#include <Mesh.h>
#include <helpers/CliArgs.h>
#define CMD_APP_START 1
#define CMD_SEND_TXT_MSG 2
@@ -2209,7 +2210,12 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
#endif
if (memcmp(command, "set pin ", 8) == 0) {
_prefs.ble_pin = atoi(&command[8]);
long pin; // atoi(): "abc" was PIN 0, i.e. a random one
if (!cli_args::parseInt(&command[8], 0, 999999, &pin)) {
strcpy(reply, "Error, PIN must be 0-999999");
return true;
}
_prefs.ble_pin = pin;
savePrefs();
sprintf(reply, "> pin is now %06d", _prefs.ble_pin);
return true;
@@ -2302,8 +2308,8 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
}
if (memcmp(command, "set adc.multiplier ", 19) == 0) { // same as CommonCLI
float mult = atof(&command[19]);
if (mult < 0.0f || mult > 10.0f) {
float mult = 0;
if (!cli_args::parseFloat(&command[19], 0.0f, 10.0f, &mult)) {
strcpy(reply, "Error, must be from 0 to 10");
} else if (board.setAdcMultiplier(mult)) {
_prefs.adc_multiplier = mult;
@@ -2334,8 +2340,8 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
return true;
}
if (memcmp(command, "set tz.offset ", 14) == 0) {
float tz = atof(&command[14]);
if (tz < -12 || tz > 14) {
float tz = 0;
if (!cli_args::parseFloat(&command[14], -12.0f, 14.0f, &tz)) {
strcpy(reply, "Error, must be from -12 to +14");
} else {
_prefs.tz_offset = tz;
+7 -1
View File
@@ -3,6 +3,7 @@
#include "MyMesh.h"
#include <helpers/NodeMaintenance.h>
#include <helpers/CliArgs.h>
// ===========================================================================
// CUSTOM (TeTeHacko): `blink [n]` -- make THIS board flash its LED on demand,
@@ -625,7 +626,12 @@ MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock,
bool txPwrHandleCommand(const char* command, char* reply) {
if (memcmp(command, "txpwr", 5) != 0 || (command[5] != 0 && command[5] != ' ')) return false;
if (command[5] == ' ') {
int dbm = atoi(&command[6]);
long dbm_l; // atoi() into int8_t: "250" went out as -6 dBm, "abc" as 0
if (!cli_args::parseInt(&command[6], -9, 30, &dbm_l)) {
strcpy(reply, "ERR - txpwr <-9..30 dBm>");
return true;
}
int dbm = dbm_l;
radio_driver.setTxPower((int8_t) dbm);
int16_t st = radio_driver.getLastTxPowerStatus();
sprintf(reply, "%s - txpwr %d dBm, RadioLib status %d%s", st == RADIOLIB_ERR_NONE ? "OK" : "ERR",