Merge meshcore-dev dev with companion and board integrations
This commit is contained in:
commit
4139e7e24d
78 files changed
+1904
-190
No files matched your search
@@ -825,6 +825,13 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
+ sizeof(loaded_prefs.bluetooth_stealth_peer_type)
|
||||
+ sizeof(loaded_prefs.bluetooth_stealth_peer)
|
||||
+ sizeof(loaded_prefs.bluetooth_stealth_mode),
|
||||
226, // prior 215-byte image plus radio timing, interference, AGC and timezone
|
||||
#ifdef TBEAM_1W
|
||||
233, // fan mode and low/high thermistor thresholds
|
||||
#endif
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
323, // Pico W additionally persists its SSID/password (ESP32 uses NVS)
|
||||
#endif
|
||||
};
|
||||
const uint32_t prefs_size = file.size();
|
||||
bool known_size = false;
|
||||
@@ -939,6 +946,23 @@ bool DataStore::loadPrefsInt(const char *filename,
|
||||
sizeof(loaded_prefs.bluetooth_stealth_peer)); // 208
|
||||
readOptionalField(&loaded_prefs.bluetooth_stealth_mode,
|
||||
sizeof(loaded_prefs.bluetooth_stealth_mode)); // 214
|
||||
readOptionalField(&loaded_prefs.tx_delay_factor, sizeof(loaded_prefs.tx_delay_factor));
|
||||
readOptionalField(&loaded_prefs.direct_tx_delay_factor, sizeof(loaded_prefs.direct_tx_delay_factor));
|
||||
readOptionalField(&loaded_prefs.interference_threshold, sizeof(loaded_prefs.interference_threshold));
|
||||
readOptionalField(&loaded_prefs.agc_reset_interval, sizeof(loaded_prefs.agc_reset_interval));
|
||||
readOptionalField(&loaded_prefs.tz_offset, sizeof(loaded_prefs.tz_offset));
|
||||
#ifdef TBEAM_1W
|
||||
readOptionalField(loaded_prefs.fan_mode, sizeof(loaded_prefs.fan_mode));
|
||||
readOptionalField(&loaded_prefs.fan_lo, sizeof(loaded_prefs.fan_lo));
|
||||
readOptionalField(&loaded_prefs.fan_hi, sizeof(loaded_prefs.fan_hi));
|
||||
loaded_prefs.fan_mode[sizeof(loaded_prefs.fan_mode) - 1] = 0;
|
||||
#endif
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
readOptionalField(loaded_prefs.wifi_ssid, sizeof(loaded_prefs.wifi_ssid));
|
||||
readOptionalField(loaded_prefs.wifi_pwd, sizeof(loaded_prefs.wifi_pwd));
|
||||
loaded_prefs.wifi_ssid[sizeof(loaded_prefs.wifi_ssid) - 1] = 0;
|
||||
loaded_prefs.wifi_pwd[sizeof(loaded_prefs.wifi_pwd) - 1] = 0;
|
||||
#endif
|
||||
|
||||
// Any bytes left over form only part of a historically appended field.
|
||||
// Preserve the file and defaults rather than treating that tail as EOF.
|
||||
@@ -1065,6 +1089,31 @@ bool DataStore::savePrefs(const CompanionNodePrefs& _prefs, double node_lat, dou
|
||||
sizeof(_prefs.bluetooth_stealth_mode))
|
||||
== sizeof(_prefs.bluetooth_stealth_mode);
|
||||
|
||||
success = success && file.write((uint8_t *)&_prefs.tx_delay_factor,
|
||||
sizeof(_prefs.tx_delay_factor)) == sizeof(_prefs.tx_delay_factor);
|
||||
success = success && file.write((uint8_t *)&_prefs.direct_tx_delay_factor,
|
||||
sizeof(_prefs.direct_tx_delay_factor)) == sizeof(_prefs.direct_tx_delay_factor);
|
||||
success = success && file.write((uint8_t *)&_prefs.interference_threshold,
|
||||
sizeof(_prefs.interference_threshold)) == sizeof(_prefs.interference_threshold);
|
||||
success = success && file.write((uint8_t *)&_prefs.agc_reset_interval,
|
||||
sizeof(_prefs.agc_reset_interval)) == sizeof(_prefs.agc_reset_interval);
|
||||
success = success && file.write((uint8_t *)&_prefs.tz_offset,
|
||||
sizeof(_prefs.tz_offset)) == sizeof(_prefs.tz_offset);
|
||||
#ifdef TBEAM_1W
|
||||
success = success && file.write((uint8_t *)_prefs.fan_mode,
|
||||
sizeof(_prefs.fan_mode)) == sizeof(_prefs.fan_mode);
|
||||
success = success && file.write((uint8_t *)&_prefs.fan_lo,
|
||||
sizeof(_prefs.fan_lo)) == sizeof(_prefs.fan_lo);
|
||||
success = success && file.write((uint8_t *)&_prefs.fan_hi,
|
||||
sizeof(_prefs.fan_hi)) == sizeof(_prefs.fan_hi);
|
||||
#endif
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
success = success && file.write((uint8_t *)_prefs.wifi_ssid,
|
||||
sizeof(_prefs.wifi_ssid)) == sizeof(_prefs.wifi_ssid);
|
||||
success = success && file.write((uint8_t *)_prefs.wifi_pwd,
|
||||
sizeof(_prefs.wifi_pwd)) == sizeof(_prefs.wifi_pwd);
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) || defined(ESP32_PLATFORM) || defined(RP2040_PLATFORM)
|
||||
success = file.commit(success);
|
||||
if (!success) MESH_DEBUG_PRINTLN("DataStore: atomic preferences write failed");
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#endif
|
||||
|
||||
#include <Arduino.h> // needed for PlatformIO
|
||||
#ifdef ENABLE_WIFI_INTERFACE
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
#include <Mesh.h>
|
||||
#include <helpers/CompanionHardwareCommandCompat.h>
|
||||
#include <helpers/CompanionStatusResponse.h>
|
||||
@@ -291,6 +294,10 @@ static mesh::Packet* emergency_client_repeat_packet;
|
||||
#define ERR_CODE_FILE_IO_ERROR 5
|
||||
#define ERR_CODE_ILLEGAL_ARG 6
|
||||
|
||||
// Copied from simple_repeater (could probably be shared)
|
||||
#define CTL_TYPE_NODE_DISCOVER_REQ 0x80
|
||||
#define CTL_TYPE_NODE_DISCOVER_RESP 0x90
|
||||
|
||||
#define MAX_SIGN_DATA_LEN (8 * 1024) // 8K
|
||||
static constexpr unsigned long SIGN_SESSION_TIMEOUT_MILLIS = 120000;
|
||||
|
||||
@@ -571,7 +578,7 @@ uint32_t MyMesh::getCADFailMaxDuration() const {
|
||||
}
|
||||
|
||||
int MyMesh::getInterferenceThreshold() const {
|
||||
return 0; // disabled for now, until currentRSSI() problem is resolved
|
||||
return _prefs.interference_threshold;
|
||||
}
|
||||
|
||||
int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
|
||||
@@ -580,11 +587,11 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
|
||||
}
|
||||
|
||||
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
|
||||
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * 0.5f);
|
||||
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * _prefs.tx_delay_factor);
|
||||
return getRNG()->nextInt(0, 5*t + 1);
|
||||
}
|
||||
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
|
||||
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * 0.2f);
|
||||
uint32_t t = (_radio->getEstAirtimeFor(packet->getPathByteLen() + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
|
||||
return getRNG()->nextInt(0, 5*t + 1);
|
||||
}
|
||||
|
||||
@@ -788,6 +795,60 @@ int MyMesh::getRecentlyHeard(AdvertPath dest[], int max_num) {
|
||||
return max_num;
|
||||
}
|
||||
|
||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
int MyMesh::getDiscoveredNodes(DiscoveredNode nodes[], int max_num) {
|
||||
if (!nodes || max_num <= 0) return 0;
|
||||
if (max_num > DISCOVERED_NODES_TABLE_SIZE) max_num = DISCOVERED_NODES_TABLE_SIZE;
|
||||
if (max_num > disc_nodes_count) max_num = disc_nodes_count;
|
||||
|
||||
for (int i = 0; i < max_num; i++) {
|
||||
nodes[i] = discovered_nodes[i];
|
||||
}
|
||||
return max_num;
|
||||
}
|
||||
|
||||
bool MyMesh::requestRepeatersDiscovery() {
|
||||
uint8_t cmd_bytes[6];
|
||||
cmd_bytes[0] = CTL_TYPE_NODE_DISCOVER_REQ | 1; // DISCOVER_REQ | prefix only
|
||||
cmd_bytes[1] = 0xFF; // Repeaters
|
||||
getRNG()->random(&cmd_bytes[2], 4); // tag
|
||||
disc_nodes_count = 0;
|
||||
disc_node_req_active = false;
|
||||
memcpy(&disc_node_req_tag, &cmd_bytes[2], sizeof(disc_node_req_tag));
|
||||
mesh::Packet* req = createControlData(cmd_bytes, sizeof(cmd_bytes));
|
||||
if (req) {
|
||||
sendZeroHop(req);
|
||||
disc_node_req_active = true;
|
||||
disc_node_req_at = millis();
|
||||
return disc_node_req_active;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MyMesh::checkControlDataForPendingDiscovery(uint8_t payload[], size_t p_len) {
|
||||
if (!disc_node_req_active
|
||||
|| static_cast<uint32_t>(millis() - disc_node_req_at) >= 30000UL
|
||||
|| (p_len < 14)
|
||||
|| ((payload[0] & 0xF0) != CTL_TYPE_NODE_DISCOVER_RESP)
|
||||
|| (disc_nodes_count >= DISCOVERED_NODES_TABLE_SIZE)
|
||||
|| (memcmp(&payload[2], &disc_node_req_tag, 4))) {
|
||||
return;
|
||||
}
|
||||
memcpy(&discovered_nodes[disc_nodes_count].pubkey_prefix, &payload[6], 8);
|
||||
discovered_nodes[disc_nodes_count].type = payload[0] & 0xF;
|
||||
discovered_nodes[disc_nodes_count].snr_out = ((int8_t)payload[1]) / 4.0;
|
||||
discovered_nodes[disc_nodes_count].snr_in = _radio->getLastSNR();
|
||||
ContactInfo* c = lookupContactByPubKey(&payload[6], 8);
|
||||
if (c != NULL) {
|
||||
StrHelper::strncpy(discovered_nodes[disc_nodes_count].name, c->name,
|
||||
sizeof(discovered_nodes[disc_nodes_count].name));
|
||||
} else {
|
||||
discovered_nodes[disc_nodes_count].name[0] = 0;
|
||||
}
|
||||
disc_nodes_count ++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if COMPANION_FEATURE_TEXT_TERMINAL
|
||||
void MyMesh::onContactVisit(const ContactInfo& contact) {
|
||||
if (contact.type == ADV_TYPE_NONE) return;
|
||||
@@ -1453,6 +1514,9 @@ void MyMesh::onControlDataRecv(mesh::Packet *packet) {
|
||||
MESH_DEBUG_PRINTLN("onControlDataRecv(), payload_len too long: %d", packet->payload_len);
|
||||
return;
|
||||
}
|
||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
checkControlDataForPendingDiscovery(packet->payload, packet->payload_len);
|
||||
#endif
|
||||
int i = 0;
|
||||
out_frame[i++] = PUSH_CODE_CONTROL_DATA;
|
||||
out_frame[i++] = (int8_t)(packet->getSNR() * 4);
|
||||
@@ -1620,6 +1684,7 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
||||
_temp_radio_failures = 0;
|
||||
_temp_radio_applied = false;
|
||||
#endif
|
||||
cli_command[0] = 0;
|
||||
offline_queue_len = 0;
|
||||
offline_queue_head = 0;
|
||||
#if defined(ESP32_PLATFORM) && defined(BOARD_HAS_PSRAM)
|
||||
@@ -1642,7 +1707,9 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
||||
send_unscoped = false;
|
||||
|
||||
// defaults
|
||||
_prefs.airtime_factor = 1.0; // one half
|
||||
_prefs.airtime_factor = 1.0;
|
||||
_prefs.tx_delay_factor = 0.5f;
|
||||
_prefs.direct_tx_delay_factor = 0.2f;
|
||||
strcpy(_prefs.node_name, "NONAME");
|
||||
_prefs.freq = LORA_FREQ;
|
||||
_prefs.sf = LORA_SF;
|
||||
@@ -1656,7 +1723,11 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
||||
_prefs.gps_interval = 0; // Use the default 1-second fix-processing interval
|
||||
_prefs.autoadd_config = DEFAULT_AUTOADD_CONFIG;
|
||||
_prefs.path_hash_mode = DEFAULT_PATH_HASH_MODE;
|
||||
#ifdef RADIO_FEM_TXGAIN
|
||||
_prefs.radio_fem_txgain = RADIO_FEM_TXGAIN;
|
||||
#else
|
||||
_prefs.radio_fem_txgain = 0;
|
||||
#endif
|
||||
#ifdef DEFAULT_RX_DELAY_BASE
|
||||
_prefs.rx_delay_base = DEFAULT_RX_DELAY_BASE;
|
||||
#endif
|
||||
@@ -1865,6 +1936,10 @@ void MyMesh::begin(bool has_display, bool radio_available) {
|
||||
|
||||
// sanitise bad pref values
|
||||
_prefs.rx_delay_base = constrain(_prefs.rx_delay_base, 0, 20.0f);
|
||||
if (!isfinite(_prefs.tx_delay_factor)) _prefs.tx_delay_factor = 0.5f;
|
||||
if (!isfinite(_prefs.direct_tx_delay_factor)) _prefs.direct_tx_delay_factor = 0.2f;
|
||||
_prefs.tx_delay_factor = constrain(_prefs.tx_delay_factor, 0, 2.0f);
|
||||
_prefs.direct_tx_delay_factor = constrain(_prefs.direct_tx_delay_factor, 0, 2.0f);
|
||||
if (!isfinite(_prefs.airtime_factor)) _prefs.airtime_factor = 1.0f;
|
||||
// `set dutycycle 1` stores factor 99; the legacy `set af` input limit is
|
||||
// narrower, but must not truncate an accepted duty cycle on restart.
|
||||
@@ -4519,8 +4594,8 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
writeErrFrame(ERR_CODE_NOT_FOUND); // bad channel_idx
|
||||
} else if (data_type == DATA_TYPE_RESERVED) {
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else if (payload_len > MAX_CHANNEL_DATA_LENGTH) {
|
||||
MESH_DEBUG_PRINTLN("CMD_SEND_CHANNEL_DATA payload too long: %d > %d", payload_len, MAX_CHANNEL_DATA_LENGTH);
|
||||
} else if (payload_len > MAX_GROUP_DATA_LENGTH) {
|
||||
MESH_DEBUG_PRINTLN("CMD_SEND_CHANNEL_DATA payload too long: %d > %d", payload_len, MAX_GROUP_DATA_LENGTH);
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else if (sendGroupData(channel.channel, path, path_len, data_type, payload, payload_len)) {
|
||||
writeOKFrame();
|
||||
@@ -8406,7 +8481,8 @@ static bool isCompanionRadioPrefsCommand(const char* command) {
|
||||
|
||||
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"
|
||||
"get rxdelay", "get path.hash.mode", "get multi.acks",
|
||||
"get txdelay", "get direct.txdelay", "get int.thresh", "get agc.reset.interval"
|
||||
};
|
||||
for (const char* candidate : exact_commands) {
|
||||
if (strcmp(command, candidate) == 0) return true;
|
||||
@@ -8414,7 +8490,8 @@ static bool isCompanionRadioPrefsCommand(const char* command) {
|
||||
|
||||
static const char* const set_prefixes[] = {
|
||||
"set radio ", "set af ", "set dutycycle ", "set rxdelay ",
|
||||
"set path.hash.mode ", "set multi.acks "
|
||||
"set path.hash.mode ", "set multi.acks ", "set txdelay ",
|
||||
"set direct.txdelay ", "set int.thresh ", "set agc.reset.interval "
|
||||
};
|
||||
for (const char* prefix : set_prefixes) {
|
||||
if (strncmp(command, prefix, strlen(prefix)) == 0) return true;
|
||||
@@ -8612,6 +8689,10 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp,
|
||||
const uint8_t previous_cr = _prefs.cr;
|
||||
const float previous_af = _prefs.airtime_factor;
|
||||
const float previous_rxdelay = _prefs.rx_delay_base;
|
||||
const float previous_txdelay = _prefs.tx_delay_factor;
|
||||
const float previous_direct_txdelay = _prefs.direct_tx_delay_factor;
|
||||
const uint8_t previous_interference = _prefs.interference_threshold;
|
||||
const uint8_t previous_agc = _prefs.agc_reset_interval;
|
||||
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;
|
||||
@@ -8640,6 +8721,10 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp,
|
||||
_prefs.cr = previous_cr;
|
||||
_prefs.airtime_factor = previous_af;
|
||||
_prefs.rx_delay_base = previous_rxdelay;
|
||||
_prefs.tx_delay_factor = previous_txdelay;
|
||||
_prefs.direct_tx_delay_factor = previous_direct_txdelay;
|
||||
_prefs.interference_threshold = previous_interference;
|
||||
_prefs.agc_reset_interval = previous_agc;
|
||||
_prefs.path_hash_mode = previous_hash_mode;
|
||||
_prefs.multi_acks = previous_multi_acks;
|
||||
_prefs.rx_ps_rx_us = previous_rx_us;
|
||||
@@ -8691,13 +8776,92 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp,
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
if (strcmp(command, "get wifi.ssid") == 0) {
|
||||
const char* ssid = _prefs.wifi_ssid[0] ? _prefs.wifi_ssid : WIFI_SSID;
|
||||
snprintf(reply, reply_capacity, "> %s", *ssid ? ssid : "(not set)");
|
||||
return true;
|
||||
}
|
||||
if (strcmp(command, "get wifi.enabled") == 0) {
|
||||
snprintf(reply, reply_capacity, "> %d", _prefs.wifi_enabled);
|
||||
return true;
|
||||
}
|
||||
if (strcmp(command, "get wifi.status") == 0 || strcmp(command, "get wifi.ip") == 0) {
|
||||
const bool connected = WiFi.status() == WL_CONNECTED;
|
||||
if (strcmp(command, "get wifi.status") == 0) {
|
||||
snprintf(reply, reply_capacity, "> %s", connected ? "connected" : "disconnected");
|
||||
} else {
|
||||
snprintf(reply, reply_capacity, "> %s", connected ? WiFi.localIP().toString().c_str() : "(not connected)");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const bool set_ssid = strncmp(command, "set wifi.ssid ", 14) == 0;
|
||||
const bool set_pwd = strncmp(command, "set wifi.pwd ", 13) == 0;
|
||||
const bool set_enabled = strncmp(command, "set wifi.enabled ", 17) == 0;
|
||||
const bool clear_wifi = strcmp(command, "set wifi.clear") == 0;
|
||||
if (set_ssid || set_pwd || set_enabled || clear_wifi) {
|
||||
char old_ssid[sizeof(_prefs.wifi_ssid)], old_pwd[sizeof(_prefs.wifi_pwd)];
|
||||
memcpy(old_ssid, _prefs.wifi_ssid, sizeof(old_ssid));
|
||||
memcpy(old_pwd, _prefs.wifi_pwd, sizeof(old_pwd));
|
||||
const uint8_t old_enabled = _prefs.wifi_enabled;
|
||||
const char* value = command + (set_ssid ? 14 : set_pwd ? 13 : set_enabled ? 17 : 0);
|
||||
int32_t enabled = 0;
|
||||
if ((set_ssid && strlen(value) >= sizeof(_prefs.wifi_ssid))
|
||||
|| (set_pwd && strlen(value) >= sizeof(_prefs.wifi_pwd))
|
||||
|| (set_enabled && (!mesh::cli::parseIntegerStrict(value, enabled) || enabled < 0 || enabled > 1))) {
|
||||
strcpy(reply, "Error: invalid WiFi setting");
|
||||
return true;
|
||||
}
|
||||
if (set_ssid) strcpy(_prefs.wifi_ssid, value);
|
||||
if (set_pwd) strcpy(_prefs.wifi_pwd, value);
|
||||
if (set_enabled) _prefs.wifi_enabled = enabled;
|
||||
if (clear_wifi) { _prefs.wifi_ssid[0] = 0; _prefs.wifi_pwd[0] = 0; }
|
||||
if (savePrefs()) strcpy(reply, "OK - reboot to apply WiFi settings");
|
||||
else {
|
||||
memcpy(_prefs.wifi_ssid, old_ssid, sizeof(old_ssid));
|
||||
memcpy(_prefs.wifi_pwd, old_pwd, sizeof(old_pwd));
|
||||
_prefs.wifi_enabled = old_enabled;
|
||||
strcpy(reply, "Error: WiFi setting could not be saved");
|
||||
}
|
||||
memset(old_pwd, 0, sizeof(old_pwd));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (strcmp(command, "get tz.offset") == 0) {
|
||||
sprintf(reply, "> %d", _prefs.tz_offset);
|
||||
return true;
|
||||
}
|
||||
if (strncmp(command, "set tz.offset ", 14) == 0) {
|
||||
int32_t tz;
|
||||
if (!mesh::cli::parseIntegerStrict(command + 14, tz) || tz < -12 || tz > 14) {
|
||||
strcpy(reply, "Error, must be from -12 to +14");
|
||||
} else {
|
||||
const int8_t previous = _prefs.tz_offset;
|
||||
_prefs.tz_offset = tz;
|
||||
if (savePrefs()) strcpy(reply, "OK");
|
||||
else {
|
||||
_prefs.tz_offset = previous;
|
||||
strcpy(reply, "Error: timezone could not be saved");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // not handled
|
||||
}
|
||||
|
||||
void MyMesh::checkCLIRescueCmd() {
|
||||
Stream& output = mesh::usbTerminalPort();
|
||||
Stream& input = mesh::usbCompanionPort();
|
||||
int len = strlen(cli_command);
|
||||
// `cli_command` must stay NUL-terminated within its bounds. If it ever isn't,
|
||||
// strlen() above can return >= sizeof(cli_command) and the loop below would
|
||||
// then index past the buffer, so clamp defensively.
|
||||
if (len >= (int)sizeof(cli_command)) {
|
||||
cli_command[0] = 0;
|
||||
len = 0;
|
||||
}
|
||||
while (input.available() && len < sizeof(cli_command)-1) {
|
||||
char c = input.read();
|
||||
if (c != '\n') {
|
||||
@@ -8706,8 +8870,9 @@ void MyMesh::checkCLIRescueCmd() {
|
||||
}
|
||||
output.print(c); // echo
|
||||
}
|
||||
if (len == sizeof(cli_command)-1) { // command buffer full
|
||||
cli_command[sizeof(cli_command)-1] = '\r';
|
||||
if (len == sizeof(cli_command)-1) { // buffer full: treat as a completed line
|
||||
cli_command[sizeof(cli_command)-2] = '\r'; // place end-of-line marker inside the buffer
|
||||
cli_command[sizeof(cli_command)-1] = 0; // keep the buffer NUL-terminated
|
||||
}
|
||||
|
||||
if (len > 0 && cli_command[len - 1] == '\r') { // received complete line
|
||||
@@ -9051,6 +9216,11 @@ void MyMesh::loop() {
|
||||
checkCLIRescueCmd();
|
||||
} else {
|
||||
checkSerialInterface();
|
||||
#if defined(ENABLE_WIFI_INTERFACE) && defined(RP2040_PLATFORM) && !defined(ENABLE_USB_INTERFACE)
|
||||
// RP2040 WiFi builds are headless and have no way into the rescue CLI (that needs a
|
||||
// display + long-press), so serve config commands on the otherwise unused USB serial
|
||||
checkCLIRescueCmd();
|
||||
#endif
|
||||
}
|
||||
servicePendingRadioParamApply();
|
||||
|
||||
|
||||
@@ -122,6 +122,16 @@ struct AdvertPath {
|
||||
uint8_t path[MAX_PATH_SIZE];
|
||||
};
|
||||
|
||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
struct DiscoveredNode {
|
||||
uint8_t pubkey_prefix[9];
|
||||
float snr_in;
|
||||
float snr_out;
|
||||
char name[32];
|
||||
uint8_t type;
|
||||
};
|
||||
#endif
|
||||
|
||||
class MyMesh : public BaseChatMesh, public DataStoreHost, public UIShutdownGuard
|
||||
#if COMPANION_FEATURE_TEXT_TERMINAL
|
||||
, public ContactVisitor
|
||||
@@ -241,6 +251,11 @@ public:
|
||||
|
||||
int getRecentlyHeard(AdvertPath dest[], int max_num);
|
||||
|
||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
bool requestRepeatersDiscovery();
|
||||
int getDiscoveredNodes(DiscoveredNode nodes[], int max_num);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
#if COMPANION_FEATURE_TEMP_RADIO
|
||||
bool isTempRadioActive() const override {
|
||||
@@ -256,6 +271,9 @@ protected:
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
uint32_t getRadioWatchdogMillis() const override { return 0; }
|
||||
#endif
|
||||
int getAGCResetInterval() const override {
|
||||
return ((int)_prefs.agc_reset_interval) * 4000; // milliseconds
|
||||
}
|
||||
int calcRxDelay(float score, uint32_t air_time) const override;
|
||||
uint32_t getRetransmitDelay(const mesh::Packet *packet) override;
|
||||
uint32_t getDirectRetransmitDelay(const mesh::Packet *packet) override;
|
||||
@@ -671,6 +689,21 @@ private:
|
||||
|
||||
#define ADVERT_PATH_TABLE_SIZE 16
|
||||
AdvertPath advert_paths[ADVERT_PATH_TABLE_SIZE]; // circular table
|
||||
|
||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
#ifdef UI_RECENT_LIST_SIZE
|
||||
#define DISCOVERED_NODES_TABLE_SIZE UI_RECENT_LIST_SIZE
|
||||
#else
|
||||
#define DISCOVERED_NODES_TABLE_SIZE 4
|
||||
#endif
|
||||
DiscoveredNode discovered_nodes[DISCOVERED_NODES_TABLE_SIZE]; // not circular, latest discovered nodes are not kept
|
||||
uint32_t disc_node_req_tag = 0;
|
||||
uint32_t disc_node_req_at = 0;
|
||||
bool disc_node_req_active = false;
|
||||
uint32_t disc_nodes_count = 0;
|
||||
|
||||
void checkControlDataForPendingDiscovery(uint8_t payload[], size_t p_len);
|
||||
#endif
|
||||
};
|
||||
|
||||
extern MyMesh the_mesh;
|
||||
@@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(ENABLE_WIFI_INTERFACE) && !defined(WIFI_SSID)
|
||||
#define WIFI_SSID ""
|
||||
#endif
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <cstdint>
|
||||
|
||||
@@ -81,6 +85,20 @@ public:
|
||||
mesh::companion::BLUETOOTH_PEER_ADDRESS_NONE;
|
||||
uint8_t bluetooth_stealth_peer[mesh::companion::BLUETOOTH_MAC_BYTES] = {};
|
||||
uint8_t bluetooth_stealth_mode = mesh::companion::BLUETOOTH_STEALTH_OFF;
|
||||
float tx_delay_factor = 0.5f;
|
||||
float direct_tx_delay_factor = 0.2f;
|
||||
uint8_t interference_threshold = 0;
|
||||
uint8_t agc_reset_interval = 0; // seconds / 4
|
||||
int8_t tz_offset = 0;
|
||||
#ifdef TBEAM_1W
|
||||
char fan_mode[5] = "auto";
|
||||
uint8_t fan_lo = 30;
|
||||
uint8_t fan_hi = 36;
|
||||
#endif
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
char wifi_ssid[33] = {};
|
||||
char wifi_pwd[64] = {};
|
||||
#endif
|
||||
|
||||
private:
|
||||
class RadioPrefs : public CommonRadioPrefs {
|
||||
@@ -93,14 +111,23 @@ private:
|
||||
def("sf", _parent->sf);
|
||||
def("cr", _parent->cr);
|
||||
def("cad", _parent->cad_enabled);
|
||||
def("int_thr", _parent->interference_threshold);
|
||||
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("f_txdelay", _parent->tx_delay_factor);
|
||||
def("d_txdelay", _parent->direct_tx_delay_factor);
|
||||
def("agc_int", _parent->agc_reset_interval);
|
||||
def("hash_mode", _parent->path_hash_mode);
|
||||
def("multi_ack", _parent->multi_acks);
|
||||
#ifdef TBEAM_1W
|
||||
def("fan", _parent->fan_mode, sizeof(_parent->fan_mode));
|
||||
def("fan_lo", _parent->fan_lo);
|
||||
def("fan_hi", _parent->fan_hi);
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -127,17 +154,11 @@ private:
|
||||
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 { }
|
||||
void setAirtimeFactor(float af) override { _parent->airtime_factor = af; markDirty(); }
|
||||
bool isCadEnabled() const override { return _parent->cad_enabled; }
|
||||
void setCadEnabled(bool en) override { _parent->cad_enabled = en; markDirty(); }
|
||||
uint8_t getIntThresh() const override { return _parent->interference_threshold; }
|
||||
void setIntThresh(uint8_t t) override { _parent->interference_threshold = t; markDirty(); }
|
||||
uint8_t getRxGain() const override { return _parent->rx_boosted_gain; }
|
||||
void setRxGain(uint8_t value) override {
|
||||
_parent->rx_boosted_gain = value;
|
||||
@@ -149,26 +170,20 @@ private:
|
||||
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 { }
|
||||
void setRxDelay(float d) override { _parent->rx_delay_base = d; markDirty(); }
|
||||
uint8_t getAgcResetInt() const override { return _parent->agc_reset_interval * 4; }
|
||||
void setAgcResetInt(uint8_t secs) override { _parent->agc_reset_interval = secs / 4; markDirty(); }
|
||||
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 { }
|
||||
void setMultiAcks(uint8_t m) override { _parent->multi_acks = m; markDirty(); }
|
||||
float getFloodTxDelay() const override { return _parent->tx_delay_factor; }
|
||||
void setFloodTxDelay(float d) override { _parent->tx_delay_factor = d; markDirty(); }
|
||||
float getDirectTxDelay() const override { return _parent->direct_tx_delay_factor; }
|
||||
void setDirectTxDelay(float d) override { _parent->direct_tx_delay_factor = d; markDirty(); }
|
||||
uint8_t getFEMRxGain() const override { return _parent->radio_fem_rxgain; }
|
||||
void setFEMRxGain(uint8_t value) override {
|
||||
_parent->radio_fem_rxgain = value;
|
||||
|
||||
@@ -53,19 +53,29 @@ MultiSerialInterface interface_manager;
|
||||
// include nrf52 bluetooth interface
|
||||
#include <helpers/nrf52/SerialBLEInterface.h>
|
||||
SerialBLEInterface bluetooth_interface;
|
||||
#elif defined(RP2040_PLATFORM)
|
||||
// include rp2040 (Pico W / CYW43) bluetooth interface
|
||||
#include <helpers/rp2040/SerialBLEInterface.h>
|
||||
SerialBLEInterface bluetooth_interface;
|
||||
#else
|
||||
#error "SerialBLEInterface is not defined for this platform"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// include wifi interface
|
||||
#ifdef WIFI_SSID
|
||||
#if defined(ENABLE_WIFI_INTERFACE) || defined(WIFI_SSID)
|
||||
#ifndef WIFI_SSID
|
||||
#define WIFI_SSID ""
|
||||
#endif
|
||||
#ifndef WIFI_PWD
|
||||
#define WIFI_PWD ""
|
||||
#endif
|
||||
#ifndef TCP_PORT
|
||||
#define TCP_PORT 5000
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
// include esp32 wifi interface
|
||||
#include <helpers/esp32/SerialWifiInterface.h>
|
||||
#include <helpers/wifi/SerialWifiInterface.h>
|
||||
#include <helpers/WiFiSetupPortal.h>
|
||||
#include <helpers/CLICommandUtils.h>
|
||||
#include <helpers/WiFiReconnectPolicy.h>
|
||||
@@ -86,6 +96,19 @@ MultiSerialInterface interface_manager;
|
||||
#ifndef WIFI_PWD
|
||||
#define WIFI_PWD ""
|
||||
#endif
|
||||
#elif defined(RP2040_PLATFORM)
|
||||
#include <helpers/wifi/SerialWifiInterface.h>
|
||||
SerialWifiInterface wifi_interface;
|
||||
static uint32_t last_wifi_reconnect_attempt = 0;
|
||||
static bool pico_wifi_active = false;
|
||||
static char pico_wifi_ssid[33] = {};
|
||||
static char pico_wifi_pwd[64] = {};
|
||||
#ifndef WIFI_RETRY_INTERVAL
|
||||
#define WIFI_RETRY_INTERVAL 30000UL
|
||||
#endif
|
||||
#ifndef WIFI_RETRY_TIMEOUT
|
||||
#define WIFI_RETRY_TIMEOUT 5000UL
|
||||
#endif
|
||||
#else
|
||||
#error "SerialWifiInterface is not defined for this platform"
|
||||
#endif
|
||||
@@ -2795,7 +2818,7 @@ void setup() {
|
||||
#endif
|
||||
|
||||
// add wifi interface
|
||||
#ifdef WIFI_SSID
|
||||
#if defined(ESP32) && defined(WIFI_SSID)
|
||||
wifi_interface.setSessionChangedCallback(cancelCompanionWiFiSession, nullptr);
|
||||
#if defined(COMPANION_EXCLUSIVE_WIFI_BLE)
|
||||
if (companionTransportWiFiActiveAtBoot()) {
|
||||
@@ -2859,6 +2882,30 @@ void setup() {
|
||||
#endif
|
||||
|
||||
// add usb interface
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
wifi_interface.setSessionChangedCallback([](void*) {
|
||||
if (interface_manager.isReplyRouteFor(&wifi_interface)) {
|
||||
the_mesh.cancelSerialResponseStream();
|
||||
}
|
||||
the_mesh.cancelSerialOperationsForRoute(&wifi_interface);
|
||||
interface_manager.forgetReplyRouteForDisconnected(&wifi_interface);
|
||||
}, nullptr);
|
||||
const auto* wifi_prefs = the_mesh.getNodePrefs();
|
||||
StrHelper::strncpy(pico_wifi_ssid,
|
||||
wifi_prefs->wifi_ssid[0] ? wifi_prefs->wifi_ssid : WIFI_SSID,
|
||||
sizeof(pico_wifi_ssid));
|
||||
StrHelper::strncpy(pico_wifi_pwd,
|
||||
wifi_prefs->wifi_ssid[0] ? wifi_prefs->wifi_pwd : WIFI_PWD,
|
||||
sizeof(pico_wifi_pwd));
|
||||
pico_wifi_active = wifi_prefs->wifi_enabled && pico_wifi_ssid[0];
|
||||
if (pico_wifi_active) {
|
||||
WiFi.setTimeout(WIFI_RETRY_TIMEOUT);
|
||||
WiFi.beginNoBlock(pico_wifi_ssid, pico_wifi_pwd);
|
||||
last_wifi_reconnect_attempt = millis();
|
||||
wifi_interface.begin(TCP_PORT);
|
||||
interface_manager.addInterface(InterfaceType::WiFi, &wifi_interface);
|
||||
}
|
||||
#endif
|
||||
#if defined(ENABLE_USB_INTERFACE)
|
||||
#if COMPANION_FEATURE_USB_MOTA_SOURCE
|
||||
usb_serial_interface.begin(mesh::usbCompanionPort(),
|
||||
@@ -2953,6 +3000,15 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#if defined(RP2040_PLATFORM) && defined(ENABLE_WIFI_INTERFACE)
|
||||
if (pico_wifi_active && WiFi.status() != WL_CONNECTED
|
||||
&& static_cast<uint32_t>(millis() - last_wifi_reconnect_attempt)
|
||||
>= WIFI_RETRY_INTERVAL) {
|
||||
WiFi.setTimeout(WIFI_RETRY_TIMEOUT);
|
||||
WiFi.beginNoBlock(pico_wifi_ssid, pico_wifi_pwd);
|
||||
last_wifi_reconnect_attempt = millis();
|
||||
}
|
||||
#endif
|
||||
mesh::wireless::control().service(millis());
|
||||
#if defined(NRF52_PLATFORM)
|
||||
board.feedWatchdog();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "../CompanionWiFi.h"
|
||||
#include "target.h"
|
||||
#include <time.h>
|
||||
#ifdef WIFI_SSID
|
||||
#if defined(ENABLE_WIFI_INTERFACE) || defined(WIFI_SSID)
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
#if UI_WIFI_SETUP_HOME_PAGE == 1
|
||||
@@ -28,10 +28,6 @@
|
||||
#include <esp_timer.h>
|
||||
#endif
|
||||
|
||||
#ifndef UI_TZ_OFFSET
|
||||
#define UI_TZ_OFFSET 0
|
||||
#endif
|
||||
|
||||
#ifndef AUTO_OFF_MILLIS
|
||||
#define AUTO_OFF_MILLIS 15000 // 15 seconds
|
||||
#endif
|
||||
@@ -406,6 +402,9 @@ class HomeScreen : public UIScreen {
|
||||
#endif
|
||||
#if UI_WIFI_SETUP_HOME_PAGE == 1
|
||||
WIFI_SETUP,
|
||||
#endif
|
||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
DISCOVERY,
|
||||
#endif
|
||||
Count // keep as last
|
||||
};
|
||||
@@ -423,6 +422,12 @@ class HomeScreen : public UIScreen {
|
||||
uint32_t _uptime_last_millis;
|
||||
uint64_t _uptime_millis;
|
||||
AdvertPath recent[UI_RECENT_LIST_SIZE];
|
||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
DiscoveredNode discovered[UI_RECENT_LIST_SIZE];
|
||||
uint32_t discovery_req_time = 0;
|
||||
bool discovery_disp_names = true; // by default desplay names if available (removes SNR_O)
|
||||
#endif
|
||||
|
||||
|
||||
int renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) {
|
||||
// Convert millivolts to percentage
|
||||
@@ -829,7 +834,7 @@ public:
|
||||
#ifdef UI_SHOW_CLOCK
|
||||
display.setTextSize(3);
|
||||
uint32_t now = _rtc->getCurrentTime();
|
||||
int8_t tz = UI_TZ_OFFSET; // for now draw time from Santo Domingo ...
|
||||
int8_t tz = _node_prefs->tz_offset;
|
||||
now += (int32_t)tz * 3600;
|
||||
DateTime dt (now);
|
||||
sprintf(tmp, "%02d:%02d", dt.hour(), dt.minute());
|
||||
@@ -1099,6 +1104,40 @@ public:
|
||||
} else if (_page == HomePage::WIFI_SETUP) {
|
||||
drawCompanionWiFiSetupPage(display);
|
||||
#endif
|
||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
} else if (_page == HomePage::DISCOVERY) {
|
||||
int count = the_mesh.getDiscoveredNodes(discovered, UI_RECENT_LIST_SIZE);
|
||||
display.setColor(UIColor::primary_txt);
|
||||
int y = 20;
|
||||
for (int i = 0; i < count; i++, y += 11) {
|
||||
char name[32];
|
||||
auto a = &discovered[i];
|
||||
if ((a->name[0] == 0) || !discovery_disp_names) {
|
||||
mesh::Utils::toHex(name, a->pubkey_prefix, 4);
|
||||
} else {
|
||||
StrHelper::strncpy(name, a->name, sizeof(name));
|
||||
}
|
||||
char filtered_name[sizeof(name)];
|
||||
char snr_s[24];
|
||||
if (strlen(name) <= 8) { // display snr_o
|
||||
snprintf(snr_s, sizeof(snr_s), "%02.1f>%02.1f", a->snr_out, a->snr_in);
|
||||
} else {
|
||||
snprintf(snr_s, sizeof(snr_s), "%02.1f", a->snr_in);
|
||||
}
|
||||
int snr_width = display.getTextWidth(snr_s);
|
||||
int max_name_width = display.width() - snr_width - 1;
|
||||
display.translateUTF8ToBlocks(filtered_name, name, sizeof(filtered_name));
|
||||
display.drawTextEllipsized(0, y, max_name_width, filtered_name);
|
||||
display.setCursor(display.width() - snr_width - 1, y);
|
||||
display.print(snr_s);
|
||||
}
|
||||
if (discovery_req_time && static_cast<uint32_t>(millis() - discovery_req_time) < 5000) {
|
||||
return 1000; // more frequent updates just after req
|
||||
} else if (count < UI_RECENT_LIST_SIZE -1) { // show only 5 sec after last disc
|
||||
y = 10 + 11 * UI_RECENT_LIST_SIZE;
|
||||
display.drawTextCentered(display.width() / 2, y, "discover: " PRESS_LABEL);
|
||||
}
|
||||
#endif
|
||||
#ifndef UI_NO_HIBERNATE
|
||||
} else if (_page == HomePage::SHUTDOWN) {
|
||||
display.setColor(UIColor::corp_blue);
|
||||
@@ -1141,6 +1180,11 @@ public:
|
||||
if (_page == HomePage::RECENT) {
|
||||
_task->showAlert("Recent adverts", 800);
|
||||
}
|
||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
if (_page == HomePage::DISCOVERY) {
|
||||
_task->showAlert("Repeater disc", 800);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
#ifdef COMPANION_EXCLUSIVE_WIFI_BLE
|
||||
@@ -1223,6 +1267,19 @@ public:
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
if (key == KEY_ENTER && _page == HomePage::DISCOVERY) {
|
||||
if (!discovery_req_time || static_cast<uint32_t>(millis() - discovery_req_time) >= 5000) {
|
||||
the_mesh.requestRepeatersDiscovery();
|
||||
discovery_req_time = millis();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (key == KEY_SELECT && _page == HomePage::DISCOVERY) {
|
||||
discovery_disp_names = !discovery_disp_names;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#ifndef UI_NO_HIBERNATE
|
||||
if (key == KEY_ENTER && _page == HomePage::SHUTDOWN) {
|
||||
_shutdown_init = true; // need to wait for button to be released
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "target.h"
|
||||
#include "u8g2_icons.h"
|
||||
|
||||
#ifdef WIFI_SSID
|
||||
#if defined(ENABLE_WIFI_INTERFACE) || defined(WIFI_SSID)
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
@@ -181,7 +181,7 @@ public:
|
||||
display.setCursor(0, 19);
|
||||
display.print(tmp);
|
||||
|
||||
#ifdef WIFI_SSID
|
||||
#ifdef ENABLE_WIFI_INTERFACE
|
||||
IPAddress ip = WiFi.localIP();
|
||||
snprintf(tmp, sizeof(tmp), "IP: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
display.setTextSize(1);
|
||||
|
||||
@@ -171,6 +171,13 @@ void loop() {
|
||||
#endif
|
||||
Stream& console = mesh::usbConsolePort();
|
||||
int len = strlen(command);
|
||||
// `command` must stay NUL-terminated within its bounds. If it ever isn't,
|
||||
// strlen() above can return >= sizeof(command) and the loop below would then
|
||||
// index past the buffer, so clamp defensively.
|
||||
if (len >= (int)sizeof(command)) {
|
||||
command[0] = 0;
|
||||
len = 0;
|
||||
}
|
||||
while (usb_ready && console.available() && len < sizeof(command)-1) {
|
||||
char c = console.read();
|
||||
if (c != '\n') {
|
||||
@@ -179,8 +186,9 @@ void loop() {
|
||||
}
|
||||
console.print(c);
|
||||
}
|
||||
if (len == sizeof(command)-1) { // command buffer full
|
||||
command[sizeof(command)-1] = '\r';
|
||||
if (len == sizeof(command)-1) { // buffer full: treat as a completed line
|
||||
command[sizeof(command)-2] = '\r'; // place end-of-line marker inside the buffer
|
||||
command[sizeof(command)-1] = 0; // keep the buffer NUL-terminated
|
||||
}
|
||||
|
||||
if (len > 0 && command[len - 1] == '\r') { // received complete line
|
||||
|
||||
@@ -642,6 +642,13 @@ public:
|
||||
BaseChatMesh::loop();
|
||||
|
||||
int len = strlen(command);
|
||||
// `command` must stay NUL-terminated within its bounds. If it ever isn't,
|
||||
// strlen() above can return >= sizeof(command) and the loop below would then
|
||||
// index past the buffer, so clamp defensively.
|
||||
if (len >= (int)sizeof(command)) {
|
||||
command[0] = 0;
|
||||
len = 0;
|
||||
}
|
||||
while (Serial.available() && len < sizeof(command)-1) {
|
||||
char c = Serial.read();
|
||||
if (c != '\n') {
|
||||
@@ -650,8 +657,9 @@ public:
|
||||
}
|
||||
Serial.print(c);
|
||||
}
|
||||
if (len == sizeof(command)-1) { // command buffer full
|
||||
command[sizeof(command)-1] = '\r';
|
||||
if (len == sizeof(command)-1) { // buffer full: treat as a completed line
|
||||
command[sizeof(command)-2] = '\r'; // place end-of-line marker inside the buffer
|
||||
command[sizeof(command)-1] = 0; // keep the buffer NUL-terminated
|
||||
}
|
||||
|
||||
if (len > 0 && command[len - 1] == '\r') { // received complete line
|
||||
|
||||
@@ -165,6 +165,13 @@ void loop() {
|
||||
#endif
|
||||
Stream& console = mesh::usbConsolePort();
|
||||
int len = strlen(command);
|
||||
// `command` must stay NUL-terminated within its bounds. If it ever isn't,
|
||||
// strlen() above can return >= sizeof(command) and the loop below would then
|
||||
// index past the buffer, so clamp defensively.
|
||||
if (len >= (int)sizeof(command)) {
|
||||
command[0] = 0;
|
||||
len = 0;
|
||||
}
|
||||
while (usb_ready && console.available() && len < sizeof(command)-1) {
|
||||
char c = console.read();
|
||||
if (c != '\n') {
|
||||
@@ -173,8 +180,9 @@ void loop() {
|
||||
}
|
||||
console.print(c);
|
||||
}
|
||||
if (len == sizeof(command)-1) { // command buffer full
|
||||
command[sizeof(command)-1] = '\r';
|
||||
if (len == sizeof(command)-1) { // buffer full: treat as a completed line
|
||||
command[sizeof(command)-2] = '\r'; // place end-of-line marker inside the buffer
|
||||
command[sizeof(command)-1] = 0; // keep the buffer NUL-terminated
|
||||
}
|
||||
|
||||
if (len > 0 && command[len - 1] == '\r') { // received complete line
|
||||
|
||||
Reference in new issue
Block a user