* CommonRadioPrefs refactors done

This commit is contained in:
Scott Powell committed 2026-08-23 17:30:30 +10:00
1 parent 41588d8052
commit b4f7e941fa
5 files changed
+220 -119

No files matched your search

+145 -2
View File
@@ -1,6 +1,7 @@
#include "CommonRadioPrefs.h"
#include "TxtDataHelpers.h"
#include "Utils.h"
#include "target.h"
bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) {
if (strcmp(command, "get radio") == 0) {
@@ -24,13 +25,28 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
setCodingRate(cr);
setFreq(freq);
setBandwidth(bw);
// NOTE: savePrefs() should be handled by caller
strcpy(reply, "OK - reboot to apply");
} else {
strcpy(reply, "Error, invalid radio params");
}
return true;
}
if (strcmp(command, "get freq") == 0) {
sprintf(reply, "> %s", StrHelper::ftoa(getFreq()));
return true;
}
if (strcmp(command, "get af") == 0) {
sprintf(reply, "> %s", StrHelper::ftoa(getAirtimeFactor()));
return true;
}
if (memcmp(command, "set af ", 7) == 0) {
setAirtimeFactor(atof(&command[7]));
strcpy(reply, "OK");
return true;
}
if (strcmp(command, "get dutycycle") == 0) {
float dc = 100.0f / (getAirtimeFactor() + 1.0f);
int dc_int = (int)dc;
@@ -44,7 +60,6 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
strcpy(reply, "ERROR: dutycycle must be 1-100");
} else {
setAirtimeFactor((100.0f / dc) - 1.0f);
// NOTE: savePrefs() should be handled by caller
float actual = 100.0f / (getAirtimeFactor() + 1.0f);
int a_int = (int)actual;
int a_frac = (int)((actual - a_int) * 10.0f + 0.5f);
@@ -52,5 +67,133 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
}
return true;
}
if (strcmp(command, "get int.thresh") == 0) {
sprintf(reply, "> %d", (uint32_t) getIntThresh());
return true;
}
if (memcmp(command, "set int.thresh ", 15) == 0) {
setIntThresh(atoi(&command[15]));
strcpy(reply, "OK");
return true;
}
if (strcmp(command, "get cad") == 0) {
sprintf(reply, "> %s", isCadEnabled() ? "on" : "off");
return true;
}
if (memcmp(command, "set cad ", 8) == 0) {
setCadEnabled(memcmp(&command[8], "on", 2) == 0);
strcpy(reply, "OK");
return true;
}
if (strcmp(command, "get radio.rxgain") == 0) {
sprintf(reply, "> %s", getRxGain() != 0 ? "on" : "off");
return true;
}
if (memcmp(command, "set radio.rxgain ", 17) == 0) {
bool enabled = memcmp(&command[17], "on", 2) == 0;
setRxGain(enabled);
if (radio_driver.setRxBoostedGainMode(enabled)) {
strcpy(reply, "OK");
} else {
strcpy(reply, "Error: unsupported");
}
return true;
}
if (memcmp(command, "get tx", 6) == 0 && (command[6] == 0 || command[6] == ' ')) {
sprintf(reply, "> %d", (int32_t) getTxPower());
return true;
}
if (memcmp(command, "set tx ", 7) == 0) {
setTxPower(atoi(&command[7]));
radio_driver.setTxPower(getTxPower());
strcpy(reply, "OK");
return true;
}
if (strcmp(command, "get rxdelay") == 0) {
sprintf(reply, "> %s", StrHelper::ftoa(getRxDelay()));
return true;
}
if (memcmp(command, "set rxdelay ", 12) == 0) {
float db = atof(&command[12]);
if (db >= 0 && db <= 20.0f) {
setRxDelay(db);
strcpy(reply, "OK");
} else {
strcpy(reply, "Error, must be 0-20");
}
return true;
}
if (strcmp(command, "get agc.reset.interval") == 0) {
sprintf(reply, "> %d", (uint32_t) getAgcResetInt());
return true;
}
if (memcmp(command, "set agc.reset.interval ", 23) == 0) {
setAgcResetInt(atoi(&command[23]));
sprintf(reply, "OK - interval rounded to %d", (uint32_t) getAgcResetInt());
return true;
}
if (strcmp(command, "get path.hash.mode") == 0) {
sprintf(reply, "> %d", (uint32_t)getHashMode());
return true;
}
if (memcmp(command, "set path.hash.mode ", 19) == 0) {
const char* config = command + 19;
uint8_t mode = atoi(config);
if (mode < 3) {
setHashMode(mode);
strcpy(reply, "OK");
} else {
strcpy(reply, "Error, must be 0,1, or 2");
}
return true;
}
if (strcmp(command, "get multi.acks") == 0) {
sprintf(reply, "> %d", (uint32_t) getMultiAcks());
return true;
}
if (memcmp(command, "set multi.acks ", 15) == 0) {
setMultiAcks(atoi(&command[15]));
strcpy(reply, "OK");
return true;
}
if (strcmp(command, "get txdelay") == 0) {
sprintf(reply, "> %s", StrHelper::ftoa(getFloodTxDelay()));
return true;
}
if (memcmp(command, "set txdelay ", 12) == 0) {
float f = atof(&command[12]);
if (f >= 0 && f <= 2.0f) {
setFloodTxDelay(f);
strcpy(reply, "OK");
} else {
strcpy(reply, "Error, must be 0-2");
}
return true;
}
if (strcmp(command, "get direct.txdelay") == 0) {
sprintf(reply, "> %s", StrHelper::ftoa(getDirectTxDelay()));
return true;
}
if (memcmp(command, "set direct.txdelay ", 19) == 0) {
float f = atof(&command[19]);
if (f >= 0 && f <= 2.0f) {
setDirectTxDelay(f);
strcpy(reply, "OK");
} else {
strcpy(reply, "Error, must be 0-2");
}
return true;
}
return false; // not handled
}