Merge upstream dev companion CLI updates
This commit is contained in:
commit
2143d3e04b
46 files changed
+1976
-163
No files matched your search
@@ -121,14 +121,31 @@ static const uint32_t COMMAND_RADIO_APPLY_TIMEOUT_MS = 5000UL;
|
||||
#define CMD_SET_DEFAULT_FLOOD_SCOPE 63
|
||||
#define CMD_GET_DEFAULT_FLOOD_SCOPE 64
|
||||
#define CMD_SEND_RAW_PACKET 65
|
||||
#define CMD_GET_RADIO_FEM_RXGAIN 66
|
||||
#define CMD_SET_RADIO_FEM_RXGAIN 67
|
||||
#define CMD_GET_RADIO_RXGAIN 68
|
||||
#define CMD_SET_RADIO_RXGAIN 69
|
||||
#define CMD_GET_WIFI_POWER_SAVE 70
|
||||
#define CMD_SET_WIFI_POWER_SAVE 71
|
||||
#define CMD_GET_BLUETOOTH_NAME 72
|
||||
#define CMD_SET_BLUETOOTH_NAME 73
|
||||
#define CMD_RUN_CLI_COMMAND 66 // v14+
|
||||
|
||||
// Fork-specific host-to-device commands use the highest currently unused
|
||||
// block below 0x80. Bit 7 is reserved by the transport for device-to-host
|
||||
// push frames, so command IDs must remain in the low half of the byte range.
|
||||
#define CMD_GET_RADIO_FEM_RXGAIN 0x78
|
||||
#define CMD_SET_RADIO_FEM_RXGAIN 0x79
|
||||
#define CMD_GET_RADIO_RXGAIN 0x7A
|
||||
#define CMD_SET_RADIO_RXGAIN 0x7B
|
||||
#define CMD_GET_WIFI_POWER_SAVE 0x7C
|
||||
#define CMD_SET_WIFI_POWER_SAVE 0x7D
|
||||
#define CMD_GET_BLUETOOTH_NAME 0x7E
|
||||
#define CMD_SET_BLUETOOTH_NAME 0x7F
|
||||
|
||||
// Compatibility aliases used by this fork before upstream assigned 0x42 to
|
||||
// CMD_RUN_CLI_COMMAND. A one-byte 0x42 frame remains distinguishable from the
|
||||
// official command, whose frame always includes CLI text.
|
||||
#define LEGACY_CMD_GET_RADIO_FEM_RXGAIN 0x42
|
||||
#define LEGACY_CMD_SET_RADIO_FEM_RXGAIN 0x43
|
||||
#define LEGACY_CMD_GET_RADIO_RXGAIN 0x44
|
||||
#define LEGACY_CMD_SET_RADIO_RXGAIN 0x45
|
||||
#define LEGACY_CMD_GET_WIFI_POWER_SAVE 0x46
|
||||
#define LEGACY_CMD_SET_WIFI_POWER_SAVE 0x47
|
||||
#define LEGACY_CMD_GET_BLUETOOTH_NAME 0x48
|
||||
#define LEGACY_CMD_SET_BLUETOOTH_NAME 0x49
|
||||
|
||||
#if defined(RADIO_FEM_RXGAIN) && (RADIO_FEM_RXGAIN == 0)
|
||||
static constexpr uint8_t DEFAULT_FEM_RX_GAIN = 0;
|
||||
@@ -170,6 +187,7 @@ static constexpr uint8_t DEFAULT_FEM_RX_GAIN = 1;
|
||||
#define RESP_ALLOWED_REPEAT_FREQ 26
|
||||
#define RESP_CODE_CHANNEL_DATA_RECV 27
|
||||
#define RESP_CODE_DEFAULT_FLOOD_SCOPE 28
|
||||
#define RESP_CODE_CLI_REPLY 29 // v14+, a reply to CMD_RUN_CLI_COMMAND
|
||||
|
||||
#define MAX_CHANNEL_DATA_LENGTH (MAX_FRAME_SIZE - 9)
|
||||
|
||||
@@ -943,8 +961,7 @@ void MyMesh::onMessageRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t
|
||||
queueMessage(from, TXT_TYPE_PLAIN, pkt, sender_timestamp, NULL, 0, text);
|
||||
}
|
||||
|
||||
void MyMesh::onCommandDataRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp,
|
||||
const char *text) {
|
||||
void MyMesh::onCommandDataRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp, const char *text) {
|
||||
markConnectionActive(from); // in case this is from a server, and we have a connection
|
||||
bool terminal_command_reply = false;
|
||||
uint32_t terminal_command_elapsed_millis = 0;
|
||||
@@ -957,6 +974,18 @@ void MyMesh::onCommandDataRecv(const ContactInfo &from, mesh::Packet *pkt, uint3
|
||||
terminal_command_reply, terminal_command_elapsed_millis);
|
||||
}
|
||||
|
||||
void MyMesh::onCLICommandRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp,
|
||||
const char *text, char* reply) {
|
||||
markConnectionActive(from); // in case this is from a server, and we have a connection
|
||||
if (from.isRemoteCLIAllowed()) {
|
||||
if (!handleCommand(text, sender_timestamp, reply)) {
|
||||
strcat(reply, "Unknown command"); // reply may have cmd prefix from 'text'
|
||||
}
|
||||
} else {
|
||||
queueMessage(from, TXT_TYPE_CLI_COMMAND, pkt, sender_timestamp, NULL, 0, text);
|
||||
}
|
||||
}
|
||||
|
||||
void MyMesh::onSignedMessageRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp,
|
||||
const uint8_t *sender_prefix, const char *text) {
|
||||
markConnectionActive(from);
|
||||
@@ -1739,6 +1768,8 @@ void MyMesh::begin(bool has_display, bool radio_available) {
|
||||
}
|
||||
|
||||
void MyMesh::configureRadioFromPrefs() {
|
||||
board.attachDynamicPrefs(_prefs.getCustom());
|
||||
|
||||
if (!_radio_available) {
|
||||
saved_radio_apply_pending = false;
|
||||
board.setLoRaFemLnaEnabled(_prefs.radio_fem_rxgain);
|
||||
@@ -2039,6 +2070,81 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
|
||||
|
||||
if (handleCadCommand(command, reply, reply_size)) return true;
|
||||
|
||||
if (strcmp(command, "get radio.rxgain") == 0) {
|
||||
if (!radio_driver.supportsRxBoostedGainMode()) {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
} else {
|
||||
snprintf(reply, reply_size, "> %s",
|
||||
_prefs.rx_boosted_gain ? "on" : "off");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncmp(command, "set radio.rxgain ", 17) == 0) {
|
||||
const char* value = command + 17;
|
||||
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
|
||||
snprintf(reply, reply_size,
|
||||
"Error: use set radio.rxgain on|off");
|
||||
} else if (!radio_driver.supportsRxBoostedGainMode()) {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
} else if (!applyAndSaveRxBoostedGain(strcmp(value, "on") == 0)) {
|
||||
snprintf(reply, reply_size, "Error: radio busy or save failed");
|
||||
} else {
|
||||
snprintf(reply, reply_size, "OK - radio.rxgain %s", value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(command, "get radio.fem.rxgain") == 0) {
|
||||
if (!board.canControlLoRaFemLna()) {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
} else {
|
||||
snprintf(reply, reply_size, "> %s",
|
||||
board.isLoRaFemLnaEnabled() ? "on" : "off");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncmp(command, "set radio.fem.rxgain ", 21) == 0) {
|
||||
const char* value = command + 21;
|
||||
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
|
||||
snprintf(reply, reply_size,
|
||||
"Error: use set radio.fem.rxgain on|off");
|
||||
} else if (!board.canControlLoRaFemLna()) {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
} else if (!applyAndSaveFemRxGain(strcmp(value, "on") == 0)) {
|
||||
snprintf(reply, reply_size, "Error: failed to apply or save FEM RX gain");
|
||||
} else {
|
||||
snprintf(reply, reply_size, "OK - radio.fem.rxgain %s", value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(command, "get radio.fem.txgain") == 0) {
|
||||
if (!board.canControlLoRaFemPaGain()) {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
} else {
|
||||
snprintf(reply, reply_size, "> %s",
|
||||
board.isLoRaFemPaGainEnabled() ? "on" : "off");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncmp(command, "set radio.fem.txgain ", 21) == 0) {
|
||||
const char* value = command + 21;
|
||||
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
|
||||
snprintf(reply, reply_size,
|
||||
"Error: use set radio.fem.txgain on|off");
|
||||
} else if (!board.canControlLoRaFemPaGain()) {
|
||||
snprintf(reply, reply_size, "Error: unsupported");
|
||||
} else if (!applyAndSaveFemTxGain(strcmp(value, "on") == 0)) {
|
||||
snprintf(reply, reply_size, "Error: failed to apply or save FEM TX gain");
|
||||
} else {
|
||||
snprintf(reply, reply_size, "OK - radio.fem.txgain %s", value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(command, "get display.rotation") == 0) {
|
||||
if (_ui == NULL || !_ui->supportsDisplayRotation()) {
|
||||
snprintf(reply, reply_size, "Error: display rotation is unsupported");
|
||||
@@ -3099,6 +3205,24 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
memcpy(&out_frame[i], _prefs.node_name, tlen);
|
||||
i += tlen;
|
||||
_serial->writeFrame(out_frame, i);
|
||||
} else if (cmd_frame[0] == CMD_RUN_CLI_COMMAND && len >= 2) { // V14+
|
||||
int i = 1;
|
||||
char *text = (char *)&cmd_frame[i];
|
||||
int tlen = len - i;
|
||||
if (memchr(text, 0, tlen) != NULL) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else {
|
||||
text[tlen] = 0; // ensure null
|
||||
|
||||
reply_buf[0] = 0;
|
||||
if (!handleCommand(text, 0, reply_buf)) {
|
||||
strcat(reply_buf, "Unknown command"); // reply_buf may have cmd prefix from 'text'
|
||||
}
|
||||
out_frame[0] = RESP_CODE_CLI_REPLY;
|
||||
int rlen = strlen(reply_buf);
|
||||
memcpy(&out_frame[1], reply_buf, rlen);
|
||||
_serial->writeFrame(out_frame, 1 + rlen);
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_SEND_TXT_MSG && len >= 14) {
|
||||
int i = 1;
|
||||
uint8_t txt_type = cmd_frame[i++];
|
||||
@@ -3109,7 +3233,7 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
uint8_t *pub_key_prefix = &cmd_frame[i];
|
||||
i += 6;
|
||||
ContactInfo *recipient = lookupContactByPubKey(pub_key_prefix, 6);
|
||||
if (recipient && (txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_CLI_DATA)) {
|
||||
if (recipient && (txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_CLI_DATA || txt_type == TXT_TYPE_CLI_COMMAND)) {
|
||||
char *text = (char *)&cmd_frame[i];
|
||||
int tlen = len - i;
|
||||
uint32_t est_timeout;
|
||||
@@ -3126,11 +3250,11 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
|
||||
int result;
|
||||
uint32_t expected_ack;
|
||||
if (txt_type == TXT_TYPE_CLI_DATA) {
|
||||
if (txt_type == TXT_TYPE_CLI_DATA || txt_type == TXT_TYPE_CLI_COMMAND) {
|
||||
const uint32_t logical_request_id = msg_timestamp;
|
||||
msg_timestamp = getRTCClock()->getCurrentTimeUnique(); // Use node's RTC instead of app timestamp to avoid tripping replay protection
|
||||
result = sendCommandData(*recipient, msg_timestamp, attempt, text,
|
||||
est_timeout, logical_request_id);
|
||||
result = sendCommandData(*recipient, msg_timestamp, attempt, txt_type,
|
||||
text, est_timeout, logical_request_id);
|
||||
expected_ack = 0; // no Ack expected
|
||||
} else {
|
||||
const uint32_t app_timestamp = msg_timestamp;
|
||||
@@ -3989,8 +4113,11 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
} else {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_GET_RADIO_FEM_RXGAIN) {
|
||||
if (!board.canControlLoRaFemLna()) {
|
||||
} else if (cmd_frame[0] == CMD_GET_RADIO_FEM_RXGAIN
|
||||
|| cmd_frame[0] == LEGACY_CMD_GET_RADIO_FEM_RXGAIN) {
|
||||
if (len != 1) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else if (!board.canControlLoRaFemLna()) {
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
} else {
|
||||
out_frame[0] = RESP_CODE_OK;
|
||||
@@ -3998,30 +4125,37 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
memcpy(&out_frame[1], &value, 1);
|
||||
_serial->writeFrame(out_frame, 2);
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_SET_RADIO_FEM_RXGAIN && len >= 2) {
|
||||
uint8_t value = cmd_frame[1];
|
||||
if (!board.canControlLoRaFemLna()) {
|
||||
} else if (cmd_frame[0] == CMD_SET_RADIO_FEM_RXGAIN
|
||||
|| cmd_frame[0] == LEGACY_CMD_SET_RADIO_FEM_RXGAIN) {
|
||||
uint8_t value = len >= 2 ? cmd_frame[1] : 0;
|
||||
if (len != 2) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else if (!board.canControlLoRaFemLna()) {
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
} else if (value <= 1) {
|
||||
if (applyAndSaveFemRxGain(value != 0)) {
|
||||
writeOKFrame();
|
||||
} else {
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
writeErrFrame(ERR_CODE_BAD_STATE);
|
||||
}
|
||||
} else {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_GET_RADIO_RXGAIN) {
|
||||
if (!radio_driver.supportsRxBoostedGainMode()) {
|
||||
} else if (cmd_frame[0] == CMD_GET_RADIO_RXGAIN
|
||||
|| cmd_frame[0] == LEGACY_CMD_GET_RADIO_RXGAIN) {
|
||||
if (len != 1) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else if (!radio_driver.supportsRxBoostedGainMode()) {
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
} else {
|
||||
out_frame[0] = RESP_CODE_OK;
|
||||
out_frame[1] = _prefs.rx_boosted_gain ? 1 : 0;
|
||||
_serial->writeFrame(out_frame, 2);
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_SET_RADIO_RXGAIN && len >= 2) {
|
||||
uint8_t value = cmd_frame[1];
|
||||
if (value > 1) {
|
||||
} else if (cmd_frame[0] == CMD_SET_RADIO_RXGAIN
|
||||
|| cmd_frame[0] == LEGACY_CMD_SET_RADIO_RXGAIN) {
|
||||
uint8_t value = len >= 2 ? cmd_frame[1] : 0;
|
||||
if (len != 2 || value > 1) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else if (!radio_driver.supportsRxBoostedGainMode()) {
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
@@ -4030,41 +4164,57 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
} else {
|
||||
writeOKFrame();
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_GET_WIFI_POWER_SAVE) {
|
||||
#if defined(ESP32) && defined(WIFI_SSID)
|
||||
out_frame[0] = RESP_CODE_OK;
|
||||
out_frame[1] = getCompanionWiFiPowerSave();
|
||||
_serial->writeFrame(out_frame, 2);
|
||||
#else
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
#endif
|
||||
} else if (cmd_frame[0] == CMD_SET_WIFI_POWER_SAVE && len >= 2) {
|
||||
#if defined(ESP32) && defined(WIFI_SSID)
|
||||
const uint8_t value = cmd_frame[1];
|
||||
if (value > mesh::wifi::kPowerSaveMax) {
|
||||
} else if (cmd_frame[0] == CMD_GET_WIFI_POWER_SAVE
|
||||
|| cmd_frame[0] == LEGACY_CMD_GET_WIFI_POWER_SAVE) {
|
||||
if (len != 1) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else {
|
||||
char reply[160];
|
||||
if (applyAndSaveWiFiPowerSaving(
|
||||
companionWiFiPowerSaveName(value), reply, sizeof(reply))) {
|
||||
writeOKFrame();
|
||||
} else {
|
||||
writeErrFrame(ERR_CODE_BAD_STATE);
|
||||
}
|
||||
}
|
||||
#if defined(ESP32) && defined(WIFI_SSID)
|
||||
out_frame[0] = RESP_CODE_OK;
|
||||
out_frame[1] = getCompanionWiFiPowerSave();
|
||||
_serial->writeFrame(out_frame, 2);
|
||||
#else
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
#endif
|
||||
} else if (cmd_frame[0] == CMD_GET_BLUETOOTH_NAME) {
|
||||
out_frame[0] = RESP_CODE_OK;
|
||||
out_frame[1] = mesh::companion::hasCustomBluetoothName(
|
||||
_prefs.bluetooth_name) ? 1 : 0;
|
||||
char* effective_name = reinterpret_cast<char*>(&out_frame[2]);
|
||||
mesh::companion::formatBluetoothName(
|
||||
effective_name, MAX_FRAME_SIZE - 1, _prefs.bluetooth_name,
|
||||
BLE_NAME_PREFIX, _prefs.node_name);
|
||||
_serial->writeFrame(out_frame, 2 + strlen(effective_name));
|
||||
} else if (cmd_frame[0] == CMD_SET_BLUETOOTH_NAME) {
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_SET_WIFI_POWER_SAVE
|
||||
|| cmd_frame[0] == LEGACY_CMD_SET_WIFI_POWER_SAVE) {
|
||||
if (len != 2) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else {
|
||||
#if defined(ESP32) && defined(WIFI_SSID)
|
||||
const uint8_t value = cmd_frame[1];
|
||||
if (value > mesh::wifi::kPowerSaveMax) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else {
|
||||
char reply[160];
|
||||
if (applyAndSaveWiFiPowerSaving(
|
||||
companionWiFiPowerSaveName(value), reply, sizeof(reply))) {
|
||||
writeOKFrame();
|
||||
} else {
|
||||
writeErrFrame(ERR_CODE_BAD_STATE);
|
||||
}
|
||||
}
|
||||
#else
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
#endif
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_GET_BLUETOOTH_NAME
|
||||
|| cmd_frame[0] == LEGACY_CMD_GET_BLUETOOTH_NAME) {
|
||||
if (len != 1) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else {
|
||||
out_frame[0] = RESP_CODE_OK;
|
||||
out_frame[1] = mesh::companion::hasCustomBluetoothName(
|
||||
_prefs.bluetooth_name) ? 1 : 0;
|
||||
char* effective_name = reinterpret_cast<char*>(&out_frame[2]);
|
||||
mesh::companion::formatBluetoothName(
|
||||
effective_name, MAX_FRAME_SIZE - 1, _prefs.bluetooth_name,
|
||||
BLE_NAME_PREFIX, _prefs.node_name);
|
||||
_serial->writeFrame(out_frame, 2 + strlen(effective_name));
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_SET_BLUETOOTH_NAME
|
||||
|| cmd_frame[0] == LEGACY_CMD_SET_BLUETOOTH_NAME) {
|
||||
const size_t name_len = len - 1;
|
||||
if (name_len > mesh::companion::BLUETOOTH_NAME_MAX_BYTES
|
||||
|| memchr(&cmd_frame[1], 0, name_len) != NULL) {
|
||||
@@ -4362,22 +4512,37 @@ void MyMesh::scheduleContactWriteAfterRelease(const ContactInfo& contact) {
|
||||
bool MyMesh::applyAndSaveFemRxGain(bool enabled) {
|
||||
if (!board.canControlLoRaFemLna()) return false;
|
||||
|
||||
const bool changed = board.isLoRaFemLnaEnabled() != enabled;
|
||||
const bool previous_hardware = board.isLoRaFemLnaEnabled();
|
||||
const uint8_t previous_pref = _prefs.radio_fem_rxgain;
|
||||
const uint8_t previous_override = _prefs.radio_fem_rxgain_override;
|
||||
const bool changed = previous_hardware != enabled;
|
||||
if (!board.setLoRaFemLnaEnabled(enabled)) return false;
|
||||
|
||||
if (changed && _radio_available) _radio->recalibrateNoiseFloor();
|
||||
_prefs.radio_fem_rxgain = enabled ? 1 : 0;
|
||||
_prefs.radio_fem_rxgain_override = 1;
|
||||
savePrefs();
|
||||
if (!savePrefs()) {
|
||||
_prefs.radio_fem_rxgain = previous_pref;
|
||||
_prefs.radio_fem_rxgain_override = previous_override;
|
||||
board.setLoRaFemLnaEnabled(previous_hardware);
|
||||
if (changed && _radio_available) _radio->recalibrateNoiseFloor();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyMesh::applyAndSaveFemTxGain(bool enabled) {
|
||||
if (!board.canControlLoRaFemPaGain()) return false;
|
||||
const bool previous_hardware = board.isLoRaFemPaGainEnabled();
|
||||
const uint8_t previous_pref = _prefs.radio_fem_txgain;
|
||||
if (!board.setLoRaFemPaGainEnabled(enabled)) return false;
|
||||
|
||||
_prefs.radio_fem_txgain = enabled ? 1 : 0;
|
||||
savePrefs();
|
||||
if (!savePrefs()) {
|
||||
_prefs.radio_fem_txgain = previous_pref;
|
||||
board.setLoRaFemPaGainEnabled(previous_hardware);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4387,8 +4552,15 @@ bool MyMesh::applyAndSaveRxBoostedGain(bool enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint8_t previous_pref = _prefs.rx_boosted_gain;
|
||||
_prefs.rx_boosted_gain = enabled ? 1 : 0;
|
||||
savePrefs();
|
||||
if (!savePrefs()) {
|
||||
_prefs.rx_boosted_gain = previous_pref;
|
||||
if (_radio_available) {
|
||||
radio_driver.setRxBoostedGainMode(previous_pref != 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5140,9 +5312,9 @@ void MyMesh::sendTerminalCommand(ContactInfo& recipient,
|
||||
|
||||
const size_t command_len =
|
||||
on_air_command == NULL ? 0 : strlen(on_air_command);
|
||||
if (command_len == 0 || command_len > MAX_TEXT_LEN) {
|
||||
if (command_len == 0 || command_len > MAX_CORRELATED_CLI_TEXT_LEN) {
|
||||
terminalOutput().printf(" ERROR: remote command must be 1-%u UTF-8 bytes\r\n",
|
||||
(unsigned)MAX_TEXT_LEN);
|
||||
(unsigned)MAX_CORRELATED_CLI_TEXT_LEN);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5151,7 +5323,16 @@ void MyMesh::sendTerminalCommand(ContactInfo& recipient,
|
||||
const uint32_t timestamp = getRTCClock()->getCurrentTimeUnique();
|
||||
const uint32_t command_started_at = _ms->getMillis();
|
||||
uint32_t est_timeout = 0;
|
||||
const int result = sendCommandData(recipient, timestamp, 0, on_air_command,
|
||||
// Legacy server roles used CLI_DATA for requests as well as replies. Keep
|
||||
// that interoperable request form for deployed Repeaters, Rooms, and
|
||||
// Sensors; Chat/Companion nodes need the explicit CLI_COMMAND direction.
|
||||
const bool is_server_role = recipient.type == ADV_TYPE_REPEATER
|
||||
|| recipient.type == ADV_TYPE_ROOM
|
||||
|| recipient.type == ADV_TYPE_SENSOR;
|
||||
const uint8_t txt_type = is_server_role
|
||||
? TXT_TYPE_CLI_DATA : TXT_TYPE_CLI_COMMAND;
|
||||
const int result = sendCommandData(recipient, timestamp, 0,
|
||||
txt_type, on_air_command,
|
||||
est_timeout, logical_request_id);
|
||||
if (result == MSG_SEND_FAILED) {
|
||||
terminalOutput().print(" ERROR: unable to send remote command\r\n");
|
||||
@@ -5891,6 +6072,176 @@ void MyMesh::enterCLIRescue() {
|
||||
Serial.println("========= CLI Rescue =========");
|
||||
}
|
||||
|
||||
static bool isCompanionRadioPrefsCommand(const char* command) {
|
||||
if (command == NULL) return false;
|
||||
|
||||
static const char* const exact_commands[] = {
|
||||
"get radio", "get freq", "get af", "get dutycycle", "get tx",
|
||||
"get rxdelay", "get path.hash.mode", "get multi.acks"
|
||||
};
|
||||
for (const char* candidate : exact_commands) {
|
||||
if (strcmp(command, candidate) == 0) return true;
|
||||
}
|
||||
|
||||
static const char* const set_prefixes[] = {
|
||||
"set radio ", "set af ", "set dutycycle ", "set rxdelay ",
|
||||
"set path.hash.mode ", "set multi.acks "
|
||||
};
|
||||
for (const char* prefix : set_prefixes) {
|
||||
if (strncmp(command, prefix, strlen(prefix)) == 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp,
|
||||
char* reply) {
|
||||
if (command == NULL || reply == NULL) return false;
|
||||
size_t reply_capacity = 160;
|
||||
while (*command == ' ' || *command == '\t') command++;
|
||||
|
||||
if (strlen(command) > 3 && command[2] == '|') {
|
||||
// Optional two-character request prefix used by Companion CLI clients.
|
||||
memcpy(reply, command, 3);
|
||||
reply += 3;
|
||||
reply_capacity -= 3;
|
||||
*reply = 0;
|
||||
command += 3;
|
||||
while (*command == ' ' || *command == '\t') command++;
|
||||
}
|
||||
|
||||
if (handleLocalControlCommand(command, reply, reply_capacity)) return true;
|
||||
|
||||
if (strncmp(command, "set tx ", 7) == 0) {
|
||||
int32_t parsed = 0;
|
||||
if (!mesh::cli::parseIntegerStrict(command + 7, parsed)) {
|
||||
strcpy(reply, "Error: invalid TX power");
|
||||
} else if (parsed < -9 || parsed > MAX_LORA_TX_POWER) {
|
||||
snprintf(reply, reply_capacity, "Error: TX power must be -9 to %d",
|
||||
MAX_LORA_TX_POWER);
|
||||
} else {
|
||||
const int8_t previous = _prefs.tx_power_dbm;
|
||||
const int8_t requested = static_cast<int8_t>(parsed);
|
||||
if (_radio_available && !radio_driver.setTxPower(requested)) {
|
||||
strcpy(reply, "Error: radio busy or TX power rejected");
|
||||
} else {
|
||||
_prefs.tx_power_dbm = requested;
|
||||
if (!savePrefs()) {
|
||||
_prefs.tx_power_dbm = previous;
|
||||
if (_radio_available) radio_driver.setTxPower(previous);
|
||||
strcpy(reply, "Error: TX power changed but save failed");
|
||||
} else {
|
||||
strcpy(reply, "OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isCompanionRadioPrefsCommand(command)) {
|
||||
const float previous_freq = _prefs.freq;
|
||||
const float previous_bw = _prefs.bw;
|
||||
const uint8_t previous_sf = _prefs.sf;
|
||||
const uint8_t previous_cr = _prefs.cr;
|
||||
const float previous_af = _prefs.airtime_factor;
|
||||
const float previous_rxdelay = _prefs.rx_delay_base;
|
||||
const uint8_t previous_hash_mode = _prefs.path_hash_mode;
|
||||
const uint8_t previous_multi_acks = _prefs.multi_acks;
|
||||
const uint32_t previous_rx_us = _prefs.rx_ps_rx_us;
|
||||
const uint32_t previous_sleep_us = _prefs.rx_ps_sleep_us;
|
||||
|
||||
if (!_prefs.getRadioPrefs()->handleCommand(
|
||||
command, sender_timestamp, reply)) {
|
||||
return false;
|
||||
}
|
||||
if (_prefs.getRadioPrefs()->isDirty()) {
|
||||
if (strncmp(command, "set radio ", 10) == 0) {
|
||||
recalcRxPowerSavingFromLevel(
|
||||
_prefs.rx_ps_level, _prefs.sf, _prefs.bw,
|
||||
_prefs.rx_ps_preamble, &_prefs.rx_ps_rx_us,
|
||||
&_prefs.rx_ps_sleep_us);
|
||||
}
|
||||
if (!savePrefs()) {
|
||||
_prefs.freq = previous_freq;
|
||||
_prefs.bw = previous_bw;
|
||||
_prefs.sf = previous_sf;
|
||||
_prefs.cr = previous_cr;
|
||||
_prefs.airtime_factor = previous_af;
|
||||
_prefs.rx_delay_base = previous_rxdelay;
|
||||
_prefs.path_hash_mode = previous_hash_mode;
|
||||
_prefs.multi_acks = previous_multi_acks;
|
||||
_prefs.rx_ps_rx_us = previous_rx_us;
|
||||
_prefs.rx_ps_sleep_us = previous_sleep_us;
|
||||
_prefs.clearDirty();
|
||||
strcpy(reply, "Error: setting changed but save failed");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Hook for future variant-specific commands not covered by the shared,
|
||||
// runtime-aware FEM handlers above.
|
||||
if (board.handleCommand(command, sender_timestamp, reply)) {
|
||||
if (_prefs.isDirty() && !savePrefs()) {
|
||||
strcpy(reply, "Error: board setting changed but save failed");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncmp(command, "set name ", 9) == 0) {
|
||||
const char* name = command + 9;
|
||||
if (!AdvertDataParser::isValidName(name)) {
|
||||
strcpy(reply, "Error, bad chars");
|
||||
} else {
|
||||
char previous[sizeof(_prefs.node_name)];
|
||||
memcpy(previous, _prefs.node_name, sizeof(previous));
|
||||
StrHelper::strncpy(_prefs.node_name, name, sizeof(_prefs.node_name));
|
||||
if (!savePrefs()) {
|
||||
memcpy(_prefs.node_name, previous, sizeof(_prefs.node_name));
|
||||
strcpy(reply, "Error: name changed but save failed");
|
||||
} else {
|
||||
strcpy(reply, "OK");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (strcmp(command, "get name") == 0) {
|
||||
snprintf(reply, reply_capacity, "> %s", _prefs.node_name);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncmp(command, "set pin ", 8) == 0) {
|
||||
int32_t parsed = 0;
|
||||
if (!mesh::cli::parseIntegerStrict(command + 8, parsed)
|
||||
|| parsed < 0 || parsed > 999999) {
|
||||
strcpy(reply, "Error: pin must be 0-999999");
|
||||
} else {
|
||||
const uint32_t previous = _prefs.ble_pin;
|
||||
_prefs.ble_pin = static_cast<uint32_t>(parsed);
|
||||
if (!savePrefs()) {
|
||||
_prefs.ble_pin = previous;
|
||||
strcpy(reply, "Error: pin changed but save failed");
|
||||
} else {
|
||||
snprintf(reply, reply_capacity, "> pin is now %06lu",
|
||||
(unsigned long)_prefs.ble_pin);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(command, "board") == 0) {
|
||||
snprintf(reply, reply_capacity, "%s", board.getManufacturerName());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(command, "ver") == 0) {
|
||||
snprintf(reply, reply_capacity, "%s (Build: %s)", FIRMWARE_VERSION,
|
||||
FIRMWARE_BUILD_DATE);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void MyMesh::checkCLIRescueCmd() {
|
||||
int len = strlen(cli_command);
|
||||
while (Serial.available() && len < sizeof(cli_command)-1) {
|
||||
@@ -5908,15 +6259,10 @@ void MyMesh::checkCLIRescueCmd() {
|
||||
if (len > 0 && cli_command[len - 1] == '\r') { // received complete line
|
||||
cli_command[len - 1] = 0; // replace newline with C string null terminator
|
||||
|
||||
if (memcmp(cli_command, "set ", 4) == 0) {
|
||||
const char* config = &cli_command[4];
|
||||
if (memcmp(config, "pin ", 4) == 0) {
|
||||
_prefs.ble_pin = atoi(&config[4]);
|
||||
savePrefs();
|
||||
Serial.printf(" > pin is now %06d\n", _prefs.ble_pin);
|
||||
} else {
|
||||
Serial.printf(" Error: unknown config: %s\n", config);
|
||||
}
|
||||
reply_buf[0] = 0;
|
||||
if (handleCommand(cli_command, 0, reply_buf)) {
|
||||
// command was handled, print reply output
|
||||
Serial.print(" "); Serial.print(reply_buf); Serial.println();
|
||||
} else if (strcmp(cli_command, "rebuild") == 0) {
|
||||
bool success = _store->formatFileSystem();
|
||||
if (success) {
|
||||
|
||||
@@ -249,6 +249,8 @@ protected:
|
||||
const char *text) override;
|
||||
void onCommandDataRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp,
|
||||
const char *text) override;
|
||||
void onCLICommandRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp,
|
||||
const char *text, char* reply) override;
|
||||
void onSignedMessageRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp,
|
||||
const uint8_t *sender_prefix, const char *text) override;
|
||||
void onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packet *pkt, uint32_t timestamp,
|
||||
@@ -281,7 +283,10 @@ protected:
|
||||
|
||||
public:
|
||||
bool savePrefs() {
|
||||
return _store->savePrefs(_prefs, sensors.node_lat, sensors.node_lon);
|
||||
const bool saved =
|
||||
_store->savePrefs(_prefs, sensors.node_lat, sensors.node_lon);
|
||||
if (saved) _prefs.clearDirty();
|
||||
return saved;
|
||||
}
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
@@ -313,6 +318,7 @@ private:
|
||||
}
|
||||
|
||||
void checkCLIRescueCmd();
|
||||
bool handleCommand(const char* text, uint32_t sender_timestamp, char* reply);
|
||||
void checkSerialInterface();
|
||||
bool applyAndSaveFemRxGain(bool enabled);
|
||||
bool applyAndSaveFemTxGain(bool enabled);
|
||||
@@ -466,6 +472,7 @@ private:
|
||||
#endif
|
||||
bool send_unscoped; // force un-scoped flood (instead of using send_scope)
|
||||
char cli_command[80];
|
||||
char reply_buf[166];
|
||||
uint8_t app_target_ver;
|
||||
uint8_t *sign_data;
|
||||
uint32_t sign_data_len;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <cstdint> // For uint8_t, uint32_t
|
||||
#include <cstdint>
|
||||
|
||||
#include <helpers/CommonRadioPrefs.h>
|
||||
#include <helpers/DynamicConfigSerializer.h>
|
||||
|
||||
#include "BluetoothName.h"
|
||||
|
||||
#define TELEM_MODE_DENY 0
|
||||
@@ -16,57 +21,181 @@
|
||||
// an explicit user choice remains persistent.
|
||||
#define COMPANION_POWERSAVING_POLICY_VERSION 1
|
||||
|
||||
struct CompanionNodePrefs { // persisted to file
|
||||
float airtime_factor;
|
||||
char node_name[32];
|
||||
float freq;
|
||||
uint8_t sf;
|
||||
uint8_t cr;
|
||||
uint8_t multi_acks;
|
||||
uint8_t manual_add_contacts;
|
||||
float bw;
|
||||
int8_t tx_power_dbm;
|
||||
uint8_t telemetry_mode_base;
|
||||
uint8_t telemetry_mode_loc;
|
||||
uint8_t telemetry_mode_env;
|
||||
float rx_delay_base;
|
||||
uint32_t ble_pin;
|
||||
uint8_t advert_loc_policy;
|
||||
uint8_t buzzer_quiet;
|
||||
uint8_t gps_enabled; // GPS enabled flag (0=disabled, 1=enabled)
|
||||
uint32_t gps_interval; // GPS read interval in seconds; 0 uses the 1-second default
|
||||
uint8_t autoadd_config; // bitmask for auto-add contacts config
|
||||
uint8_t rx_boosted_gain; // SX126x RX boosted gain mode (0=power saving, 1=boosted)
|
||||
uint8_t radio_fem_rxgain; // LoRa FEM RX gain setting
|
||||
uint8_t client_repeat;
|
||||
uint8_t path_hash_mode; // which path mode to use when sending
|
||||
uint8_t autoadd_max_hops; // 0 = no limit, 1 = direct (0 hops), N = up to N-1 hops (max 64)
|
||||
char default_scope_name[31];
|
||||
uint8_t default_scope_key[16];
|
||||
uint8_t radio_fem_rxgain_override; // 1 once the user overrides the build default
|
||||
uint8_t vibe_quiet; // haptic quiet mode; appended for prefs compatibility
|
||||
uint8_t radio_fem_txgain; // LoRa FEM TX gain; appended for prefs compatibility
|
||||
uint8_t rx_powersaving_enabled; // SX126x/LR11xx receive duty cycling
|
||||
uint32_t rx_ps_rx_us; // receive window in microseconds
|
||||
uint32_t rx_ps_sleep_us; // sleep window in microseconds
|
||||
uint8_t rx_ps_level; // 0=manual timings, 1..10=level-derived
|
||||
uint8_t rx_ps_preamble; // 0=auto from SF, otherwise 16 or 32
|
||||
uint8_t powersaving_enabled; // device CPU/GPS idle power saving
|
||||
uint8_t wifi_enabled; // Companion WiFi radio and services
|
||||
uint8_t powersaving_policy_version; // one-time default migration marker
|
||||
uint8_t usb_logging_enabled; // live USB packet/debug output
|
||||
char bluetooth_name[mesh::companion::BLUETOOTH_NAME_SIZE];
|
||||
// exact BLE name; empty uses BLE_NAME_PREFIX + node_name
|
||||
uint16_t display_rotation_degrees; // 0=board default; otherwise 90/180/270
|
||||
uint8_t cad_enabled; // hardware channel activity detection
|
||||
uint16_t cad_scan_timeout_ms; // 0=derive from SF/BW
|
||||
uint16_t cad_retry_delay_ms; // 0=Mesh adaptive default
|
||||
uint16_t cad_max_duration_ms; // 0=Dispatcher default
|
||||
// Companion preferences remain stored by DataStore's explicit, append-only
|
||||
// binary field list. The adapter objects are appended after every persisted
|
||||
// field, and node latitude/longitude deliberately remain separate DataStore
|
||||
// arguments, so the established field offsets and on-device format do not move.
|
||||
class CompanionNodePrefs {
|
||||
public:
|
||||
float airtime_factor = 0;
|
||||
char node_name[32] = {};
|
||||
float freq = 0;
|
||||
uint8_t sf = 0;
|
||||
uint8_t cr = 0;
|
||||
uint8_t multi_acks = 0;
|
||||
uint8_t manual_add_contacts = 0;
|
||||
float bw = 0;
|
||||
int8_t tx_power_dbm = 0;
|
||||
uint8_t telemetry_mode_base = 0;
|
||||
uint8_t telemetry_mode_loc = 0;
|
||||
uint8_t telemetry_mode_env = 0;
|
||||
float rx_delay_base = 0;
|
||||
uint32_t ble_pin = 0;
|
||||
uint8_t advert_loc_policy = 0;
|
||||
uint8_t buzzer_quiet = 0;
|
||||
uint8_t gps_enabled = 0; // GPS enabled flag (0=disabled, 1=enabled)
|
||||
uint32_t gps_interval = 0; // seconds; 0 uses the 1-second default
|
||||
uint8_t autoadd_config = 0; // bitmask for auto-add contacts config
|
||||
uint8_t rx_boosted_gain = 0; // SX126x RX boosted gain mode
|
||||
uint8_t radio_fem_rxgain = 0; // external LoRa FEM RX gain
|
||||
uint8_t client_repeat = 0;
|
||||
uint8_t path_hash_mode = 0;
|
||||
uint8_t autoadd_max_hops = 0;
|
||||
char default_scope_name[31] = {};
|
||||
uint8_t default_scope_key[16] = {};
|
||||
|
||||
// Append-only binary preference tail. Do not insert persisted fields above
|
||||
// or between these entries without updating DataStore's compatibility map.
|
||||
uint8_t radio_fem_rxgain_override = 0;
|
||||
uint8_t vibe_quiet = 0;
|
||||
uint8_t radio_fem_txgain = 0;
|
||||
uint8_t rx_powersaving_enabled = 0;
|
||||
uint32_t rx_ps_rx_us = 0;
|
||||
uint32_t rx_ps_sleep_us = 0;
|
||||
uint8_t rx_ps_level = 0;
|
||||
uint8_t rx_ps_preamble = 0;
|
||||
uint8_t powersaving_enabled = 0;
|
||||
uint8_t wifi_enabled = 0;
|
||||
uint8_t powersaving_policy_version = 0;
|
||||
uint8_t usb_logging_enabled = 0;
|
||||
char bluetooth_name[mesh::companion::BLUETOOTH_NAME_SIZE] = {};
|
||||
uint16_t display_rotation_degrees = 0;
|
||||
uint8_t cad_enabled = 0;
|
||||
uint16_t cad_scan_timeout_ms = 0;
|
||||
uint16_t cad_retry_delay_ms = 0;
|
||||
uint16_t cad_max_duration_ms = 0;
|
||||
|
||||
private:
|
||||
class RadioPrefs : public CommonRadioPrefs {
|
||||
CompanionNodePrefs* _parent;
|
||||
|
||||
protected:
|
||||
void structure() override {
|
||||
def("freq", _parent->freq);
|
||||
def("bw", _parent->bw);
|
||||
def("sf", _parent->sf);
|
||||
def("cr", _parent->cr);
|
||||
def("cad", _parent->cad_enabled);
|
||||
def("rxgain", _parent->rx_boosted_gain);
|
||||
def("fem_rxgain", _parent->radio_fem_rxgain);
|
||||
def("fem_txgain", _parent->radio_fem_txgain);
|
||||
def("tx", _parent->tx_power_dbm);
|
||||
def("af", _parent->airtime_factor);
|
||||
def("rxdelay", _parent->rx_delay_base);
|
||||
def("hash_mode", _parent->path_hash_mode);
|
||||
def("multi_ack", _parent->multi_acks);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit RadioPrefs(CompanionNodePrefs* parent) : _parent(parent) { }
|
||||
|
||||
float getFreq() const override { return _parent->freq; }
|
||||
void setFreq(float value) override {
|
||||
_parent->freq = value;
|
||||
markDirty();
|
||||
}
|
||||
float getBandwidth() const override { return _parent->bw; }
|
||||
void setBandwidth(float value) override {
|
||||
_parent->bw = value;
|
||||
markDirty();
|
||||
}
|
||||
uint8_t getSpreadFactor() const override { return _parent->sf; }
|
||||
void setSpreadFactor(uint8_t value) override {
|
||||
_parent->sf = value;
|
||||
markDirty();
|
||||
}
|
||||
uint8_t getCodingRate() const override { return _parent->cr; }
|
||||
void setCodingRate(uint8_t value) override {
|
||||
_parent->cr = value;
|
||||
markDirty();
|
||||
}
|
||||
float getAirtimeFactor() const override { return _parent->airtime_factor; }
|
||||
void setAirtimeFactor(float value) override {
|
||||
_parent->airtime_factor = value;
|
||||
markDirty();
|
||||
}
|
||||
bool isCadEnabled() const override { return _parent->cad_enabled != 0; }
|
||||
void setCadEnabled(bool enabled) override {
|
||||
_parent->cad_enabled = enabled ? 1 : 0;
|
||||
markDirty();
|
||||
}
|
||||
uint8_t getIntThresh() const override { return 0; }
|
||||
void setIntThresh(uint8_t) override { }
|
||||
uint8_t getRxGain() const override { return _parent->rx_boosted_gain; }
|
||||
void setRxGain(uint8_t value) override {
|
||||
_parent->rx_boosted_gain = value;
|
||||
markDirty();
|
||||
}
|
||||
int8_t getTxPower() const override { return _parent->tx_power_dbm; }
|
||||
void setTxPower(int8_t value) override {
|
||||
_parent->tx_power_dbm = value;
|
||||
markDirty();
|
||||
}
|
||||
float getRxDelay() const override { return _parent->rx_delay_base; }
|
||||
void setRxDelay(float value) override {
|
||||
_parent->rx_delay_base = value;
|
||||
markDirty();
|
||||
}
|
||||
uint8_t getAgcResetInt() const override { return 0; }
|
||||
void setAgcResetInt(uint8_t) override { }
|
||||
uint8_t getHashMode() const override { return _parent->path_hash_mode; }
|
||||
void setHashMode(uint8_t value) override {
|
||||
_parent->path_hash_mode = value;
|
||||
markDirty();
|
||||
}
|
||||
uint8_t getMultiAcks() const override { return _parent->multi_acks; }
|
||||
void setMultiAcks(uint8_t value) override {
|
||||
_parent->multi_acks = value;
|
||||
markDirty();
|
||||
}
|
||||
float getFloodTxDelay() const override { return 0.5f; }
|
||||
void setFloodTxDelay(float) override { }
|
||||
float getDirectTxDelay() const override { return 0.2f; }
|
||||
void setDirectTxDelay(float) override { }
|
||||
uint8_t getFEMRxGain() const override { return _parent->radio_fem_rxgain; }
|
||||
void setFEMRxGain(uint8_t value) override {
|
||||
_parent->radio_fem_rxgain = value;
|
||||
_parent->radio_fem_rxgain_override = 1;
|
||||
markDirty();
|
||||
}
|
||||
uint8_t getFEMTxGain() const override { return _parent->radio_fem_txgain; }
|
||||
void setFEMTxGain(uint8_t value) override {
|
||||
_parent->radio_fem_txgain = value;
|
||||
markDirty();
|
||||
}
|
||||
};
|
||||
|
||||
// Runtime-only adapters must remain after the persisted field block above.
|
||||
RadioPrefs radio;
|
||||
DynamicConfigSerializer custom;
|
||||
|
||||
public:
|
||||
CompanionNodePrefs() : radio(this), custom(&radio) { }
|
||||
|
||||
// Keep the upstream repeat API while retaining the existing binary prefs
|
||||
// layout used by this branch.
|
||||
bool isRepeatEn() const { return client_repeat != 0; }
|
||||
void setRepeatEn(bool enabled) { client_repeat = enabled ? 1 : 0; }
|
||||
|
||||
CommonRadioPrefs* getRadioPrefs() { return &radio; }
|
||||
KeyValueStore* getCustom() { return &custom; }
|
||||
|
||||
bool isDirty() const {
|
||||
return radio.isDirty() || custom.isDirty();
|
||||
}
|
||||
|
||||
void clearDirty() {
|
||||
radio.clearDirty();
|
||||
custom.clearDirty();
|
||||
}
|
||||
};
|
||||
|
||||
inline bool migrateCompanionPowerSavingDefault(CompanionNodePrefs& prefs) {
|
||||
|
||||
@@ -2691,7 +2691,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
memcpy(&sender_timestamp, data, 4); // timestamp (by sender's RTC clock - which could be wrong)
|
||||
uint8_t flags = (data[4] >> 2); // message attempt number, and other flags
|
||||
|
||||
if (!(flags == TXT_TYPE_PLAIN || flags == TXT_TYPE_CLI_DATA)) {
|
||||
if (!(flags == TXT_TYPE_PLAIN || flags == TXT_TYPE_CLI_DATA || flags == TXT_TYPE_CLI_COMMAND)) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: unsupported text type received: flags=%02x", (uint32_t)flags);
|
||||
} else {
|
||||
// len can be > original length, but 'text' will be padded with zeroes
|
||||
@@ -3563,6 +3563,8 @@ void MyMesh::begin(FILESYSTEM *fs) {
|
||||
board.setLoRaFemPaGainEnabled(_prefs.radio_fem_txgain);
|
||||
setRxPowerSaving(_prefs.rx_powersaving_enabled, _prefs.rx_ps_rx_us, _prefs.rx_ps_sleep_us);
|
||||
|
||||
board.attachDynamicPrefs(_prefs.getCustom());
|
||||
|
||||
updateAdvertTimer();
|
||||
updateFloodAdvertTimer();
|
||||
next_recent_repeater_sweep = futureMillis(RECENT_REPEATER_SWEEP_INTERVAL_MILLIS);
|
||||
|
||||
@@ -800,7 +800,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
memcpy(&sender_timestamp, data, 4); // timestamp (by sender's RTC clock - which could be wrong)
|
||||
uint8_t flags = (data[4] >> 2); // message attempt number, and other flags
|
||||
|
||||
if (!(flags == TXT_TYPE_PLAIN || flags == TXT_TYPE_CLI_DATA)) {
|
||||
if (!(flags == TXT_TYPE_PLAIN || flags == TXT_TYPE_CLI_DATA || flags == TXT_TYPE_CLI_COMMAND)) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: unsupported command flags received: flags=%02x", (uint32_t)flags);
|
||||
return;
|
||||
}
|
||||
@@ -845,7 +845,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
// advanced this client's room-post replay timestamp.
|
||||
send_ack = true;
|
||||
}
|
||||
} else { // TXT_TYPE_CLI_DATA
|
||||
} else { // TXT_TYPE_CLI_DATA or TXT_TYPE_CLI_COMMAND
|
||||
uint32_t request_id = sender_timestamp;
|
||||
mesh::RemoteCliRequest::parse(data, len, 5, request_id);
|
||||
const uint32_t command_fingerprint =
|
||||
@@ -1316,6 +1316,8 @@ void MyMesh::begin(FILESYSTEM *fs) {
|
||||
board.setLoRaFemPaGainEnabled(_prefs.radio_fem_txgain);
|
||||
setRxPowerSaving(_prefs.rx_powersaving_enabled, _prefs.rx_ps_rx_us, _prefs.rx_ps_sleep_us);
|
||||
|
||||
board.attachDynamicPrefs(_prefs.getCustom());
|
||||
|
||||
updateAdvertTimer();
|
||||
updateFloodAdvertTimer();
|
||||
|
||||
|
||||
@@ -257,6 +257,10 @@ protected:
|
||||
|
||||
void onCommandDataRecv(const ContactInfo& from, mesh::Packet* pkt, uint32_t sender_timestamp, const char *text) override {
|
||||
}
|
||||
|
||||
void onCLICommandRecv(const ContactInfo& contact, mesh::Packet* pkt, uint32_t sender_timestamp, const char *text, char* reply) override {
|
||||
}
|
||||
|
||||
void onSignedMessageRecv(const ContactInfo& from, mesh::Packet* pkt, uint32_t sender_timestamp, const uint8_t *sender_prefix, const char *text) override {
|
||||
}
|
||||
|
||||
|
||||
@@ -774,7 +774,7 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
|
||||
sendAckTo(*from, ack_hash, packet->getPathHashSize());
|
||||
}
|
||||
}
|
||||
} else if (flags == TXT_TYPE_CLI_DATA) {
|
||||
} else if (flags == TXT_TYPE_CLI_DATA || flags == TXT_TYPE_CLI_COMMAND) {
|
||||
from->last_timestamp = sender_timestamp;
|
||||
from->last_activity = getRTCClock()->getCurrentTime();
|
||||
|
||||
@@ -1004,6 +1004,8 @@ void SensorMesh::begin(FILESYSTEM* fs) {
|
||||
board.setLoRaFemPaGainEnabled(_prefs.radio_fem_txgain);
|
||||
setRxPowerSaving(_prefs.rx_powersaving_enabled, _prefs.rx_ps_rx_us, _prefs.rx_ps_sleep_us);
|
||||
|
||||
board.attachDynamicPrefs(_prefs.getCustom());
|
||||
|
||||
updateAdvertTimer();
|
||||
updateFloodAdvertTimer();
|
||||
|
||||
|
||||
Reference in new issue
Block a user