Update MeshCore features and OTA layout handling

This commit is contained in:
mikecarper committed 2026-08-18 23:17:42 -07:00
1 parent 0c4619bcc3
commit 47993d178e
74 files changed
+1696 -1169

No files matched your search

+80 -2
View File
@@ -818,8 +818,10 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
bool SensorMesh::handleIncomingMsg(ClientInfo& from, uint32_t timestamp, uint8_t* data, uint8_t flags, size_t len) {
MESH_DEBUG_PRINT("handleIncomingMsg: unhandled msg from ");
#ifdef MESH_DEBUG
mesh::Utils::printHex(Serial, from.id.pub_key, PUB_KEY_SIZE);
Serial.printf(": %s\n", data);
if (mesh::isUsbLoggingEnabled()) {
mesh::Utils::printHex(Serial, from.id.pub_key, PUB_KEY_SIZE);
Serial.printf(": %s\n", data);
}
#endif
return false;
}
@@ -1286,3 +1288,79 @@ void SensorMesh::loop() {
dirty_contacts_expiry = 0;
}
}
bool SensorMesh::isMillisTimerDue(unsigned long timestamp) const {
return timestamp && millisHasNowPassed(timestamp);
}
uint32_t SensorMesh::limitSleepToMillisTimer(unsigned long timestamp,
uint32_t sleep_secs) const {
if (!timestamp || sleep_secs == 0) return sleep_secs;
unsigned long now = millis();
if ((long)(now - timestamp) >= 0) return 0;
uint32_t remaining_secs = (timestamp - now + 999UL) / 1000UL;
return remaining_secs < sleep_secs ? remaining_secs : sleep_secs;
}
bool SensorMesh::hasPendingWork() const {
if (_cli.hasActiveUserGpioTimer()) return true;
if (radio_driver.isWatchdogObserving()) return true;
if (radio_driver.isCalibratingNoiseFloor()) return true;
if (hasQueuedWorkDue() || hasRetryWorkDue()) return true;
if (isMillisTimerDue(next_flood_advert)
|| isMillisTimerDue(next_local_advert)
|| isMillisTimerDue(dirty_contacts_expiry)) return true;
if (num_alert_tasks > 0
&& isMillisTimerDue(alert_tasks[0]->send_expiry)) return true;
const bool radio_apply_backoff = radio_apply_retry_at
&& !millisHasNowPassed(radio_apply_retry_at);
if (!radio_apply_backoff
&& (isMillisTimerDue(set_radio_at) || isMillisTimerDue(revert_radio_at)
|| (saved_radio_apply_pending && !temp_radio_applied))) return true;
uint32_t now_secs = getRTCClock()->getCurrentTime();
return now_secs >= last_read_time + SENSOR_READ_INTERVAL_SECS;
}
uint32_t SensorMesh::getPowerSaveSleepSeconds(uint32_t max_secs) const {
if (max_secs == 0 || hasPendingWork()) return 0;
uint32_t sleep_secs = max_secs;
uint32_t wake_delay_ms;
if (getNextQueueWakeDelay(wake_delay_ms)) {
uint32_t wake_delay_secs = (wake_delay_ms + 999UL) / 1000UL;
if (wake_delay_secs < sleep_secs) sleep_secs = wake_delay_secs;
}
if (getNextRetryWakeDelay(wake_delay_ms)) {
uint32_t wake_delay_secs = (wake_delay_ms + 999UL) / 1000UL;
if (wake_delay_secs < sleep_secs) sleep_secs = wake_delay_secs;
}
sleep_secs = limitSleepToMillisTimer(next_flood_advert, sleep_secs);
sleep_secs = limitSleepToMillisTimer(next_local_advert, sleep_secs);
sleep_secs = limitSleepToMillisTimer(dirty_contacts_expiry, sleep_secs);
if (num_alert_tasks > 0) {
sleep_secs = limitSleepToMillisTimer(alert_tasks[0]->send_expiry,
sleep_secs);
}
const bool radio_apply_backoff = radio_apply_retry_at
&& !millisHasNowPassed(radio_apply_retry_at);
if (radio_apply_backoff) {
sleep_secs = limitSleepToMillisTimer(radio_apply_retry_at, sleep_secs);
} else {
sleep_secs = limitSleepToMillisTimer(set_radio_at, sleep_secs);
sleep_secs = limitSleepToMillisTimer(revert_radio_at, sleep_secs);
}
uint32_t now_secs = getRTCClock()->getCurrentTime();
uint32_t sensor_due = last_read_time + SENSOR_READ_INTERVAL_SECS;
if (now_secs < sensor_due) {
uint32_t sensor_delay = sensor_due - now_secs;
if (sensor_delay < sleep_secs) sleep_secs = sensor_delay;
}
return sleep_secs;
}
+8
View File
@@ -66,6 +66,7 @@ public:
const char* getRole() override { return FIRMWARE_ROLE; }
const char* getNodeName() { return _prefs.node_name; }
NodePrefs* getNodePrefs() { return &_prefs; }
uint32_t getPowerSaveSleepSeconds(uint32_t max_secs) const;
void savePrefs(
PrefsSaveRouting::Scope scope = PrefsSaveRouting::Scope::Common) override {
_cli.savePrefs(_fs, scope);
@@ -213,6 +214,10 @@ private:
uint8_t radio_apply_failures;
bool applySavedRadioParams();
bool isMillisTimerDue(unsigned long timestamp) const;
uint32_t limitSleepToMillisTimer(unsigned long timestamp,
uint32_t sleep_secs) const;
bool hasPendingWork() const;
uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood);
uint8_t handleRequest(uint8_t perms, uint32_t sender_timestamp, uint8_t req_type, uint8_t* payload, size_t payload_len);
@@ -226,6 +231,9 @@ private:
void applyGpsPrefs() {
sensors.setPowerSavingEnabled(_prefs.powersaving_enabled != 0);
sensors.setSettingValue("gps", _prefs.gps_enabled?"1":"0");
char interval_str[12];
sprintf(interval_str, "%u", _prefs.gps_interval);
sensors.setSettingValue("gps_interval", interval_str);
}
#endif
};
+18
View File
@@ -56,6 +56,7 @@ void halt() {
}
static char command[160];
static const unsigned long POWERSAVING_FIRST_SLEEP_SECS = 120;
void setup() {
Serial.begin(115200);
@@ -179,4 +180,21 @@ void loop() {
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.loop();
#endif
if (the_mesh.getNodePrefs()->powersaving_enabled
&& !board.isUsbDataConnected()) {
uint32_t sleep_secs = the_mesh.getPowerSaveSleepSeconds(30);
#ifdef HAS_EXTERNAL_WATCHDOG
if (sleep_secs > 0) external_watchdog.feed();
#endif
#if defined(NRF52_PLATFORM)
if (sleep_secs > 0) board.sleep(0);
#else
if (sleep_secs > 0
&& the_mesh.millisHasNowPassed(
POWERSAVING_FIRST_SLEEP_SECS * 1000UL)) {
board.sleep(sleep_secs);
}
#endif
}
}