Reduce nRF52 Companion flash and stream Reader chapters

Use a 960-byte constant-time Ed25519 base table, compact hash/scalar code and unused-library trims while retaining Reader, BLE P-256 and the 8 KiB stack. RAK4631 Full saves 57,496 flash bytes and 3,152 static RAM bytes versus preview3.

Support complete chapters and verse ranges with bounded app continuation replies and cooperative terminal output. Use nonblocking TCP writes under reader backpressure. Add scalar/signature comparisons and a linked ARM crypto/stack CI gate.

Validated clean RAK4631, T1000-E, T096 and V4 Full builds, host regressions, and physical RAK chapter/reconnect and signing comparisons. Physical signing averages 35.9 ms versus 14.4 ms with the original table.
This commit is contained in:
mikecarper committed 2026-10-13 01:02:30 -07:00
1 parent 65820d0dd2
commit d2bea5fb10
21 files changed
+803 -86

No files matched your search

+24 -4
View File
@@ -8663,6 +8663,9 @@ Stream& MyMesh::terminalOutput() {
}
void MyMesh::resetTerminalSession() {
#if COMPANION_FEATURE_READER
mesh::cancelReaderCommand();
#endif
_terminal_recipient_set = false;
memset(_terminal_recipient_key, 0, sizeof(_terminal_recipient_key));
clearTerminalLogin();
@@ -9332,13 +9335,21 @@ void MyMesh::sendTerminalRawTrace(const char* arguments) {
target);
}
void MyMesh::handleTerminalCommand(char* command) {
#if defined(WITH_WEBCONFIG) && COMPANION_FEATURE_READER
bool MyMesh::streamTerminalBusy() const {
return mesh::readerCommandActive(_terminal_output);
}
#endif
void MyMesh::handleTerminalCommand(char* command, bool reader_prompt,
mesh::ReaderTryWrite reader_try_write) {
while (*command == ' ' || *command == '\t') command++;
if (*command == 0) return;
mesh::cli::normalizeCommandVerb(command);
#if COMPANION_FEATURE_READER
if (mesh::handleReaderCommand(command, terminalOutput())) return;
if (mesh::handleReaderCommand(command, terminalOutput(), reader_prompt,
reader_try_write)) return;
#endif
// Match the repeater ASCII reply envelope so unmodified serial packet
@@ -9847,7 +9858,7 @@ void MyMesh::handleTerminalCommand(char* command) {
terminalOutput().print(" get flash.health\r\n");
#endif
#if COMPANION_FEATURE_READER
terminalOutput().print(" get reader <chapter>:<verse> (World English Bible, offline)\r\n");
terminalOutput().print(" get reader <chapter>[:<verse>[-<last>]] [page] (World English Bible, offline)\r\n");
#endif
terminalOutput().print(" get pwrmgt.bootreason\r\n");
#if COMPANION_FEATURE_MEMORY_DIAGNOSTICS
@@ -10001,6 +10012,9 @@ void MyMesh::handleTerminalCommand(char* command) {
#endif
void MyMesh::enterCLIRescue() {
#if COMPANION_FEATURE_READER
mesh::cancelReaderCommand();
#endif
_cli_rescue = true;
cli_command[0] = 0;
_cli_line_overflow = false;
@@ -10608,7 +10622,7 @@ complete_line:
reply_buf[0] = 0;
#if COMPANION_FEATURE_READER
if (mesh::handleReaderCommand(cli_command, output)) {
// USB rescue is a text stream and can print the complete verse.
// USB rescue streams chapters/ranges cooperatively like the terminal.
} else
#endif
if (handleCommand(cli_command, 0, reply_buf)) {
@@ -10935,6 +10949,9 @@ void MyMesh::loop() {
serviceTerminalTrace();
#endif
servicePendingSerialReply();
#if COMPANION_FEATURE_READER
mesh::serviceReaderCommand();
#endif
serviceBinaryTraceReply();
serviceSigningSession();
if (!command_radio_apply_pending && saved_radio_apply_pending && !hasOutbound()
@@ -11085,6 +11102,9 @@ bool MyMesh::canRecoverUsbLogging() const {
}
bool MyMesh::hasPendingWork() const {
#if COMPANION_FEATURE_READER
if (mesh::readerCommandActive()) return true;
#endif
#if COMPANION_FEATURE_NOTIFICATIONS
if (_notifications.active()) return true;
#endif
+7 -2
View File
@@ -4,6 +4,7 @@
#include <Mesh.h>
#include "AbstractUITask.h"
#include "CompanionFeatures.h"
#include <helpers/CompanionReader.h>
/*------------ Frame Protocol --------------*/
#define FIRMWARE_VER_CODE 14
@@ -255,7 +256,10 @@ public:
bool ownsStreamTerminal(const Stream& output) const override {
return isNetworkTerminalMode(output);
}
void runStreamTerminal(char* command) override { handleTerminalCommand(command); }
void runStreamTerminal(char* command) override { handleTerminalCommand(command, false); }
#if COMPANION_FEATURE_READER
bool streamTerminalBusy() const override;
#endif
void endStreamTerminal(Stream& output) override;
#endif
void rebootNow() override;
@@ -301,7 +305,8 @@ public:
bool isTerminalWaitingForInput() const {
return _terminal_mode && _terminal_usb_silent;
}
void handleTerminalCommand(char* command);
void handleTerminalCommand(char* command, bool reader_prompt = true,
mesh::ReaderTryWrite reader_try_write = nullptr);
#if COMPANION_FEATURE_NETWORK_TERMINAL || defined(WITH_WEBCONFIG)
bool enterNetworkTerminalMode(Stream& output);
void exitNetworkTerminalMode(Stream& output);
+29 -2
View File
@@ -6,6 +6,7 @@
#include <Mesh.h>
#include <helpers/BluetoothMac.h>
#include "MyMesh.h"
#include <helpers/CompanionReader.h>
#include "CompanionBluetooth.h"
#include "CompanionWireless.h"
#include "CompanionWiFi.h"
@@ -989,6 +990,9 @@ static bool usb_terminal_host_reset_completion_pending = false;
static uint32_t usb_terminal_host_reset_retry_at = 0;
static void resetUsbTerminalHostSession() {
#if COMPANION_FEATURE_READER
mesh::cancelReaderCommand(&mesh::usbTerminalPort());
#endif
// Stop only work routed to the old USB host; a simultaneous BLE/WiFi
// transaction is independent and must continue. Clear the route after
// stopping its producer so no response can fall back to another transport.
@@ -1230,7 +1234,10 @@ static void serviceUsbTerminal() {
usb_logging_terminal_mode = false;
}
#endif
usbTerminalOutput().print("> ");
#if COMPANION_FEATURE_READER
if (!mesh::readerCommandActive(&usbTerminalOutput()))
#endif
usbTerminalOutput().print("> ");
return; // service at most one command per mesh loop
}
@@ -2087,6 +2094,7 @@ void halt() {
the same role CLI here as its USB terminal. Other OTA-enabled Companion
builds expose local maintenance commands and `ota ...` commands. */
#if defined(ESP32) && defined(WIFI_SSID) && defined(ENABLE_OTA)
#include <lwip/sockets.h>
#include <helpers/ota/OtaCli.h> // mesh::ota::handle_ota_command(line, reply, board)
#include <helpers/esp32/WiFiOtaSeeder.h>
#ifndef OTA_CONSOLE_TCP_PORT
@@ -2097,6 +2105,17 @@ void halt() {
static char ota_console_line[MAX_TRANS_UNIT * 2 + 32];
static size_t ota_console_len = 0;
static bool ota_console_discard_line = false;
#if COMPANION_FEATURE_NETWORK_TERMINAL && COMPANION_FEATURE_READER
static size_t ota_console_try_reader_write(Stream& output,
const uint8_t* data, size_t size) {
// WiFiClient::write retries socket readiness with one-second waits.
// A paused chapter reader must instead leave its cursor for the next loop.
const int socket = static_cast<WiFiClient&>(output).fd();
if (socket < 0) return 0;
const int written = ::send(socket, data, size, MSG_DONTWAIT);
return written > 0 ? static_cast<size_t>(written) : 0;
}
#endif
#if COMPANION_FEATURE_NETWORK_TERMINAL && defined(ENABLE_USB_INTERFACE)
static mesh::UsbTcpTerminalHandoff ota_console_usb_handoff;
#endif
@@ -2220,8 +2239,16 @@ void halt() {
ota_console_discard_line = false;
return;
}
#if COMPANION_FEATURE_READER
the_mesh.handleTerminalCommand(ota_console_line, true,
ota_console_try_reader_write);
#else
the_mesh.handleTerminalCommand(ota_console_line);
ota_console_client.print("> ");
#endif
#if COMPANION_FEATURE_READER
if (!mesh::readerCommandActive(&ota_console_client))
#endif
ota_console_client.print("> ");
#else
char reply[160]; reply[0] = 0;
if (!handleCompanionWirelessCommand(ota_console_line, reply, sizeof(reply), CompanionWirelessSource::Network)