Add adaptive RAK4631 SD storage to full firmware profiles

This commit is contained in:
mikecarper committed 2026-10-16 01:18:26 -07:00
1 parent 9181e3e0ec
commit 774c2adc80
54 files changed
+3962 -477

No files matched your search

+10
View File
@@ -53,6 +53,9 @@
#endif
#if defined(ENABLE_OTA)
#include <helpers/ota/OtaContext.h>
#if defined(OTA_RAK15002_SD_STORE) && defined(ETHERNET_USE_RAK13800)
bool handleRak4631PeripheralCommand(const char* command, char* reply, size_t capacity);
#endif
#endif
#if defined(ENABLE_OTA)
#include <helpers/ota/OtaSpeedConfig.h>
@@ -3787,6 +3790,9 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
size_t reply_size) {
if (!command || !reply || reply_size == 0) return false;
while (*command == ' ') command++;
#if defined(OTA_RAK15002_SD_STORE) && defined(ETHERNET_USE_RAK13800)
if (handleRak4631PeripheralCommand(command, reply, reply_size)) return true;
#endif
#if defined(MESH_HIL_TX_FREQ_MHZ)
if (mesh::handleHilTxFrequencyCommand(command, reply, reply_size)) return true;
#endif
@@ -10234,6 +10240,10 @@ void MyMesh::handleTerminalCommand(char* command, bool reader_prompt,
terminalOutput().print(" get ethernet / get ethernet.radio\r\n"
" set ethernet.radio <MHz>,<kHz>,<SF>,<CR>[,<preamble>]\r\n"
" set ethernet on|off (saved; trusted-LAN KISS TCP 5003, radio2 only)\r\n");
#endif
#if defined(OTA_RAK15002_SD_STORE) && defined(ETHERNET_USE_RAK13800)
terminalOutput().print(" get eth / set eth on|off (physical RAK13800; default off, this boot)\r\n"
" get sdcard [free] / ota cache [on|off] (RAK15002; mutually exclusive with Ethernet)\r\n");
#endif
terminalOutput().print(" get pwrmgt.bootreason\r\n");
#if COMPANION_FEATURE_MEMORY_DIAGNOSTICS
+51
View File
@@ -653,6 +653,53 @@ static void cancelCompanionEthernetSession(void*) {
the_mesh.cancelSerialOperationsForRoute(&ethernet_interface);
interface_manager.forgetReplyRouteForDisconnected(&ethernet_interface);
}
#if defined(OTA_RAK15002_SD_STORE) && defined(ETHERNET_USE_RAK13800)
static bool prepareCompanionRakEthernet(void*) {
auto* context = mesh::ota::ota_context_if_active();
return !context || context->prepareRakSdForEthernet();
}
static bool canReleaseCompanionRakEthernet(void*) {
auto* context = mesh::ota::ota_context_if_active();
return !context || context->canReleaseRakSdForEthernet();
}
static bool releasedCompanionRakEthernet(void*) {
auto* context = mesh::ota::ota_context_if_active();
return !context || context->releasedRakSdEthernet();
}
bool handleRak4631PeripheralCommand(const char* command, char* reply, size_t capacity) {
const bool get = strcmp(command, "get eth") == 0;
const char* value = strncmp(command, "set eth ", 8) == 0 ? command + 8 : nullptr;
if (get || value) {
if (value && strcmp(value, "on") && strcmp(value, "off")) {
snprintf(reply, capacity, "Error: use set eth on|off");
} else if (value && !(strcmp(value, "on") == 0
? ethernet_interface.tryEnable() : ethernet_interface.tryDisable())) {
snprintf(reply, capacity, "Error: %s", ethernet_interface.last_error());
} else {
snprintf(reply, capacity, "%s eth=%s; RAK13800 (this boot)", get ? ">" : "OK -",
ethernet_interface.hardwareActive() ? "on" : "off");
}
return true;
}
if (strcmp(command, "get sdcard") == 0 || strcmp(command, "get sdcard free") == 0) {
if (ethernet_interface.hardwareActive()) {
snprintf(reply, capacity, "Error: turn Ethernet off before accessing SD");
} else if (mesh::ota::ota_acquire_context(reply, capacity)) {
uint64_t used = 0, free = 0;
auto& card = mesh::ota::ota_ctx().sdStagingStore();
if (card.getSpace(board, used, free)) {
snprintf(reply, capacity, "> SD used=%llu free=%llu bytes; ota cache for archive status",
(unsigned long long)used, (unsigned long long)free);
} else {
snprintf(reply, capacity, "Error: %s", card.last_error());
}
}
return true;
}
return false;
}
#endif
#endif
#if defined(ENABLE_USB_INTERFACE)
@@ -3950,6 +3997,10 @@ void setup() {
// add ethernet interface
#if defined(ETHERNET_ENABLED)
ethernet_interface.setSessionChangedCallback(cancelCompanionEthernetSession, nullptr);
#if defined(OTA_RAK15002_SD_STORE) && defined(ETHERNET_USE_RAK13800)
ethernet_interface.setSpiOwnershipHooks(prepareCompanionRakEthernet,
canReleaseCompanionRakEthernet, releasedCompanionRakEthernet, nullptr);
#endif
ethernet_interface.begin();
interface_manager.addInterface(InterfaceType::Ethernet, &ethernet_interface);
#endif
+26
View File
@@ -86,17 +86,40 @@ static bool prepareCombinedEthernet(void*, char* error, size_t capacity) {
snprintf(error, capacity, "Error: OTA storage is not ready");
return false;
}
#if defined(OTA_RAK15002_SD_STORE)
if (mesh::ota::ota_rak15002_sd_card_present()) {
snprintf(error, capacity, "Error: RAK15002 SD card fitted; Ethernet shares its IO slot");
return false;
}
if (!context->prepareRakSdForEthernet() ||
!mesh::ota::rak4631_try_acquire_spi(mesh::ota::RakSharedSpiOwner::Ethernet)) {
snprintf(error, capacity, "Error: Ethernet bus is locked by OTA activity or storage");
return false;
}
return true;
#else
return context->prepareRakEthernet(error, capacity);
#endif
}
static bool canReleaseCombinedEthernet(void*) {
auto* context = mesh::ota::ota_context_if_active();
#if defined(OTA_RAK15002_SD_STORE)
return context && context->canReleaseRakSdForEthernet();
#else
return context && context->canReleaseRakEthernet();
#endif
}
static bool releaseCombinedEthernet(void*) {
auto* context = mesh::ota::ota_context_if_active();
#if defined(OTA_RAK15002_SD_STORE)
if (!context || !context->releasedRakSdEthernet()) return false;
mesh::ota::rak4631_release_spi(mesh::ota::RakSharedSpiOwner::Ethernet);
return true;
#else
return context && context->releaseRakEthernet();
#endif
}
#endif
@@ -372,6 +395,9 @@ void setup() {
hooks.prepare = prepareCombinedEthernet;
hooks.can_release = canReleaseCombinedEthernet;
hooks.released = releaseCombinedEthernet;
#if defined(OTA_RAK15002_SD_STORE)
hooks.storage_conflict = [](void*) { return mesh::ota::ota_rak15002_sd_card_present(); };
#endif
ethernet_configure(hooks); // First prototype defaults OFF on every restart.
#endif
ethernet_start_task();
+48
View File
@@ -41,6 +41,42 @@ SimpleMeshTables tables;
MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables);
#include "../InfrastructureWireless.h"
#if defined(ETHERNET_ENABLED) && defined(OTA_RAK15002_SD_STORE)
#include <helpers/ota/OtaContext.h>
// The RAK15002 and RAK13800 occupy the same IO-slot chip select. Ethernet is
// opt-in, and only the mesh thread may release cached sources/staging owners
// and reserve the bus before its asynchronous DHCP worker starts.
static bool prepareSdEthernet(void*, char* error, size_t capacity) {
auto* context = mesh::ota::ota_context_if_active();
if (!context) {
snprintf(error, capacity, "Error: OTA storage is not ready");
return false;
}
if (mesh::ota::ota_rak15002_sd_card_present()) {
snprintf(error, capacity, "Error: RAK15002 SD card fitted; Ethernet shares its IO slot");
return false;
}
if (!context->prepareRakSdForEthernet() ||
!mesh::ota::rak4631_try_acquire_spi(mesh::ota::RakSharedSpiOwner::Ethernet)) {
snprintf(error, capacity, "Error: Ethernet bus is locked by OTA activity or storage");
return false;
}
return true;
}
static bool canReleaseSdEthernet(void*) {
auto* context = mesh::ota::ota_context_if_active();
return context && context->canReleaseRakSdForEthernet();
}
static bool releaseSdEthernet(void*) {
auto* context = mesh::ota::ota_context_if_active();
if (!context || !context->releasedRakSdEthernet()) return false;
mesh::ota::rak4631_release_spi(mesh::ota::RakSharedSpiOwner::Ethernet);
return true;
}
#endif
void halt() {
while (1) ;
}
@@ -226,6 +262,14 @@ void setup() {
#endif
#ifdef ETHERNET_ENABLED
#if defined(OTA_RAK15002_SD_STORE)
EthernetCliHooks hooks;
hooks.prepare = prepareSdEthernet;
hooks.can_release = canReleaseSdEthernet;
hooks.released = releaseSdEthernet;
hooks.storage_conflict = [](void*) { return mesh::ota::ota_rak15002_sd_card_present(); };
ethernet_configure(hooks); // Shared IO slot defaults OFF on every restart.
#endif
ethernet_start_task();
#endif
@@ -316,7 +360,11 @@ void loop() {
#ifdef ETHERNET_ENABLED
ethernet_loop_maintain();
#if defined(OTA_RAK15002_SD_STORE)
if (ethernet_take_session_reset() || !ethernet_get_enabled()) {
#else
if (ethernet_take_session_reset() || !ethernet_client.connected()) {
#endif
the_mesh.cancelLocalOutput(ethernet_client);
ethernet_command[0] = 0;
}