Share T096 Full mOTA memory with the offline queue

This commit is contained in:
mikecarper committed 2026-09-08 01:15:19 -07:00
1 parent d28535f503
commit 2ea493994e
26 files changed
+1198 -23

No files matched your search

+29 -2
View File
@@ -408,7 +408,9 @@ bool MyMesh::Frame::isChannelMsg() const {
}
int MyMesh::getOfflineQueueCapacity() const {
#if defined(ESP32_PLATFORM) && defined(BOARD_HAS_PSRAM)
#if defined(OTA_SHARED_COMPANION_QUEUE)
return offline_queue.capacity();
#elif defined(ESP32_PLATFORM) && defined(BOARD_HAS_PSRAM)
return offline_queue_capacity;
#else
return OFFLINE_QUEUE_SIZE;
@@ -416,11 +418,29 @@ int MyMesh::getOfflineQueueCapacity() const {
}
MyMesh::Frame& MyMesh::offlineQueueFrameAt(int logical_index) {
#if defined(OTA_SHARED_COMPANION_QUEUE)
return offline_queue.at((offline_queue_head + logical_index) % getOfflineQueueCapacity());
#else
return offline_queue[(offline_queue_head + logical_index) % getOfflineQueueCapacity()];
#endif
}
#if defined(OTA_SHARED_COMPANION_QUEUE)
mesh::ota::OtaContext* MyMesh::acquireOfflineQueueForOta(void* owner) {
MyMesh* mesh = static_cast<MyMesh*>(owner);
return mesh->offline_queue.acquire(mesh->offline_queue_len, mesh->offline_queue_head);
}
void MyMesh::releaseOfflineQueueFromOta(void* owner) {
MyMesh* mesh = static_cast<MyMesh*>(owner);
mesh->offline_queue.release(mesh->offline_queue_head);
}
#endif
void MyMesh::initializeOfflineQueue() {
#if defined(ESP32_PLATFORM) && defined(BOARD_HAS_PSRAM)
#if defined(OTA_SHARED_COMPANION_QUEUE)
mesh::ota::ota_set_context_storage(this, acquireOfflineQueueForOta, releaseOfflineQueueFromOta);
#elif defined(ESP32_PLATFORM) && defined(BOARD_HAS_PSRAM)
if (offline_queue != offline_queue_fallback || OFFLINE_QUEUE_SIZE <= offline_queue_capacity) return;
int requested_capacity = OFFLINE_QUEUE_SIZE;
@@ -2080,6 +2100,10 @@ bool MyMesh::scheduleTempRadio(float freq, float bw, uint8_t sf, uint8_t cr,
return false;
}
#if defined(OTA_SHARED_COMPANION_QUEUE)
if (!mesh::ota::ota_acquire_context(reply, reply_size)) return false;
mesh::ota::ota_ctx().release_when_idle = false;
#endif
_temp_radio_freq = freq;
_temp_radio_bw = bw;
_temp_radio_sf = sf;
@@ -8192,6 +8216,9 @@ void MyMesh::loop() {
}
#if COMPANION_FEATURE_TEMP_RADIO
serviceTempRadio();
#endif
#if defined(OTA_SHARED_COMPANION_QUEUE)
mesh::ota::ota_release_context_if_idle(isTempRadioActive() || _temp_radio_set_at != 0);
#endif
BaseChatMesh::loop();
#ifdef COMPANION_MESH_CLOCK_SYNC
+10 -1
View File
@@ -48,6 +48,10 @@
#include <helpers/TerminalCommandTracker.h>
#include <helpers/TerminalDisplayFilter.h>
#include <target.h>
#if defined(OTA_SHARED_COMPANION_QUEUE)
#include <helpers/BorrowableFrameBuffer.h>
#include <helpers/ota/OtaContext.h>
#endif
#ifdef COMPANION_MESH_CLOCK_SYNC
#include <helpers/ClientACL.h>
@@ -569,7 +573,12 @@ private:
void initializeOfflineQueue();
int offline_queue_len;
int offline_queue_head;
#if defined(ESP32_PLATFORM) && defined(BOARD_HAS_PSRAM)
#if defined(OTA_SHARED_COMPANION_QUEUE)
static_assert(OFFLINE_QUEUE_SIZE == 256, "Shared mOTA queue requires 256 normal slots");
mesh::BorrowableFrameBuffer<Frame, OFFLINE_QUEUE_SIZE, 128, mesh::ota::OtaContext> offline_queue;
static mesh::ota::OtaContext* acquireOfflineQueueForOta(void* owner);
static void releaseOfflineQueueFromOta(void* owner);
#elif defined(ESP32_PLATFORM) && defined(BOARD_HAS_PSRAM)
enum {
OFFLINE_QUEUE_PSRAM_FALLBACK_SIZE =
OFFLINE_QUEUE_SIZE < 16 ? OFFLINE_QUEUE_SIZE : 16
+25 -4
View File
@@ -222,6 +222,7 @@ public:
return false;
}
if (!mesh::ota::ota_acquire_context(reply, reply_size)) return false;
mesh::ota::OtaContext& context = mesh::ota::ota_ctx();
if (context.folder_active
&& context.folderLink() != mesh::ota::OtaContext::FOLDER_LINK_BLE) {
@@ -247,24 +248,32 @@ public:
bool stop(char* reply, size_t reply_size) override {
if (!reply || reply_size == 0) return false;
mesh::ota::OtaContext& context = mesh::ota::ota_ctx();
bluetooth_interface.setMotaStreamActive(false);
if (!mesh::ota::ota_context_if_active()) {
snprintf(reply, reply_size, "OK Bluetooth mOTA source stopped");
return true;
}
mesh::ota::OtaContext& context = mesh::ota::ota_ctx();
if (context.folder_active
&& context.folderLink() == mesh::ota::OtaContext::FOLDER_LINK_BLE) {
context.detach_folder();
context.manager.announce();
mesh::usbLoggingPort().println("Bluetooth mOTA source detached");
_last_packets_sent = context.manager.packetsSent()
- _packets_sent_at_start;
}
_last_packets_sent = context.manager.packetsSent()
- _packets_sent_at_start;
snprintf(reply, reply_size, "OK Bluetooth mOTA source stopped");
return true;
}
mesh::companion::MotaSourceStatus status() const override {
const mesh::ota::OtaContext& context = mesh::ota::ota_ctx();
mesh::companion::MotaSourceStatus result;
result.channel_ready = bluetooth_interface.isMotaChannelReady();
if (!mesh::ota::ota_context_if_active()) {
result.packets_sent = _last_packets_sent;
return result;
}
const mesh::ota::OtaContext& context = mesh::ota::ota_ctx();
result.attached = context.folder_active
&& context.folderLink() == mesh::ota::OtaContext::FOLDER_LINK_BLE
&& bluetooth_interface.isMotaStreamActive();
@@ -281,6 +290,10 @@ public:
}
void loop() {
if (!mesh::ota::ota_context_if_active()) {
bluetooth_interface.setMotaStreamActive(false);
return;
}
mesh::ota::OtaContext& context = mesh::ota::ota_ctx();
const bool owns_folder = context.folder_active
&& context.folderLink() == mesh::ota::OtaContext::FOLDER_LINK_BLE;
@@ -2054,9 +2067,17 @@ void halt() {
clear_bonds, stealth_pair_once,
bonded_only_peer_ptr)) {
interface_manager.removeInterface(&bluetooth_interface);
#if defined(NRF52_PLATFORM)
// A partly initialized Bluefruit stack cannot be started again safely.
// Leave the interface unregistered so the UI cannot advertise a PIN
// for it, and avoid consuming more heap every five seconds.
mesh::usbLoggingPort().println(
"Companion: Bluetooth initialization failed; reboot required");
#else
mesh::usbLoggingPort().println(
"Companion: Bluetooth initialization failed; retrying in 5 seconds");
scheduleCompanionBluetoothRetry();
#endif
return;
}
#if defined(ESP32_PLATFORM) && COMPANION_BT_MODEM_SLEEP_AVAILABLE
@@ -456,6 +456,14 @@ class HomeScreen : public UIScreen {
int next_sensors_refresh = 0;
void refresh_sensors() {
// CayenneLPP retains its requested capacity even if its allocation fails.
// Its add methods would then write through NULL when this page is opened.
if (sensors_lpp.getBuffer() == nullptr) {
sensors_nb = 0;
sensors_scroll = false;
sensors_scroll_offset = 0;
return;
}
if (millis() > next_sensors_refresh) {
sensors_lpp.reset();
sensors_nb = 0;
@@ -947,6 +955,12 @@ public:
} else if (_page == HomePage::SENSORS) {
int y = 18;
refresh_sensors();
if (sensors_lpp.getBuffer() == nullptr) {
display.setColor(UIColor::warning_txt);
display.drawTextCentered(display.width() / 2, 34,
"Sensors: low memory");
return 5000;
}
char buf[30];
char name[30];
LPPReader r(sensors_lpp.getBuffer(), sensors_lpp.getSize());