blepwr/fairness: opravy z review-three

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-10-06 23:46:40 +02:00
1 parent b3db81151f
commit 81ccbc2051
4 files changed
+37 -15

No files matched your search

+20 -8
View File
@@ -483,11 +483,15 @@ bool identHandleCommand(const char* command, char* reply) {
|| (p >= 2 && p <= 8);
}
static void bleConnTxPowerPersist(int8_t p) {
// true when the value will come back after a reboot
static bool bleConnTxPowerPersist(int8_t p) {
InternalFS.remove(BLE_PWR_FILE); // FILE_O_WRITE appends; start clean
if (p == RPT_BLE_CONN_TX_POWER) return; // default needs no file
if (p == RPT_BLE_CONN_TX_POWER) return true; // default needs no file
auto f = InternalFS.open(BLE_PWR_FILE, Adafruit_LittleFS_Namespace::FILE_O_WRITE);
if (f) { f.write((uint8_t)p); f.close(); }
if (!f) return false;
bool ok = f.write((uint8_t)p) == 1;
f.close();
return ok;
}
static int8_t bleConnTxPowerLoad() {
@@ -543,20 +547,28 @@ bool identHandleCommand(const char* command, char* reply) {
// rejects anything else, hence the applied/failed count in the reply.
if (memcmp(command, "blepwr", 6) == 0 && (command[6] == 0 || command[6] == ' ')) {
if (command[6] == ' ') {
int8_t p = (int8_t) atoi(&command[7]);
// strict parse: now that the value is saved, a typo must not become
// permanent (atoi turned "216" into -40 and "abc" into 0)
char* end;
long v = strtol(&command[7], &end, 10);
if (end == &command[7] || *end != 0 || !bleConnTxPowerValid((int) v)) {
strcpy(reply, "ERR - blepwr <dBm>: -40,-20,-16,-12,-8,-4,0,2..8");
return true;
}
int8_t p = (int8_t) v;
int live = 0;
int ok = bleApplyConnTxPower(p, &live);
// only latch a value the radio actually accepted, otherwise the next
// reconnect would silently re-apply a bogus one
bool applied = (live == 0 || ok > 0);
// with no live connection nothing has vetted the value yet
if (live == 0 && !bleConnTxPowerValid(p)) applied = false;
bool saved = false;
if (applied) {
ble_conn_tx_power = p;
bleConnTxPowerPersist(p);
saved = bleConnTxPowerPersist(p);
}
sprintf(reply, "%s - BLE conn tx %d dBm (%d/%d conn)%s",
applied ? "OK" : "ERR", (int) p, ok, live, applied ? ", saved" : "");
applied ? "OK" : "ERR", (int) p, ok, live,
applied ? (saved ? ", saved" : ", NOT saved") : "");
} else {
sprintf(reply, "BLE conn tx: %d dBm, adv tx: %d dBm",
(int) ble_conn_tx_power, (int) Bluefruit.getTxPower());