M3 step 3: the Radio Service, receive only

One task owns the SX1262 and does all its SPI behind the card's bus lock;
the main loop posts requests and DIO1 only wakes the task. It listens
while a client asks (App, Capture, Console) and sleeps otherwise, with a
ring of the last 32 packets (9.8 KB, freed when idle). No transmit path.
The Cap's antenna switch (expander P0) is set on the main loop, which
owns the I2C bus. `lora probe` now runs on the radio task and checks the
DIO1 interrupt with a receive timeout; `lora status`, `lora rx on|off`,
`lora preset`, and `lora custom` for other LoRa settings.

Measured: DIO1 works (timeout after 105 ms); four 1.7 MB uploads and
Gemini pages to the card while listening, no radio or card errors; task
stack peak 2.0 KB. Twenty minutes on LongFast and LoRaWAN: no packets,
and a noise floor of -83 to -94 dBm at the desk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
2026-10-05 19:49:46 +02:00
co-authored by Claude Opus 5.5
parent 30a827070b
commit 594748e99a
5 changed files with 489 additions and 138 deletions
+27 -3
View File
@@ -20,7 +20,6 @@
#include "key_mapper.h"
#include "platform/console.h"
#include "platform/crash_report.h"
#include "platform/lora_probe.h"
#include "platform/nvs_store.h"
#include "platform/system_info.h"
#include "service_manager.h"
@@ -32,6 +31,7 @@
#include "services/gemini_service.h"
#include "services/gnss_service.h"
#include "services/power_service.h"
#include "services/radio_service.h"
#include "services/storage_service.h"
#include "services/update_service.h"
#include "services/wifi_service.h"
@@ -57,6 +57,7 @@ static StorageService* storageService;
static PowerService* power;
static ClockService* clockService;
static GnssService* gnssService;
static RadioService* radioService;
static GeminiService* geminiService;
static SavedNetworks* savedNetworks;
static WifiService* wifi;
@@ -151,6 +152,7 @@ void setup() {
clockService = new ClockService(settings, bus);
geminiService = new GeminiService(nvs, *storageService, *clockService, bus);
gnssService = new GnssService(settings, *clockService, *storageService, bus);
radioService = new RadioService();
savedNetworks = new SavedNetworks(nvs);
savedNetworks->load();
wifi = new WifiService(settings, *savedNetworks, *clockService);
@@ -162,6 +164,7 @@ void setup() {
services.add(*clockService);
services.add(*battery);
services.add(*gnssService);
services.add(*radioService);
services.add(*storageService);
services.add(*wifi);
services.add(*irc);
@@ -348,7 +351,8 @@ static const char* const kHelp =
"reboot restart\n"
"boot other restart into the other app slot (manual Rollback)\n"
"log level <0-5> ESP-IDF log level (0 none ... 5 verbose)\n"
"lora probe find the LoRa radio: chip, oscillator, antenna switch, noise floor (receive only)\n"
"lora probe | lora status | lora rx on|off | lora preset <name> the LoRa radio, receive only\n"
"lora custom <MHz> <BW kHz> <SF> <CR 5-8> <sync hex> [preamble] e.g. 868.1 125 7 5 34 8 (LoRaWAN)\n"
"gnss status | gnss restart | gnss track start|stop | gnss nmea on|off | gnss send <sentence without $ and checksum>\n"
"crash the last crash: firmware, reason, task, backtrace\n"
"coredump erase forget the core dump in flash\n"
@@ -412,7 +416,27 @@ static void runCommand(String line) {
});
}
if (line.startsWith("install ")) update->installFromSd(line.substring(8).c_str()); // Update from SD
if (line == "lora probe") loraProbe(console);
if (line == "lora probe" && radioService) radioService->probe(console);
if (line == "lora status" && radioService) radioService->printStatus(console);
if ((line == "lora rx on" || line == "lora rx off") && radioService) radioService->setEcho(line.endsWith("on"));
if (line.startsWith("lora custom ") && radioService) {
double mhz = 0, bw = 0;
unsigned sf = 0, cr = 0, sync = 0, preamble = 8;
int n = sscanf(line.c_str() + 12, "%lf %lf %u %u %x %u", &mhz, &bw, &sf, &cr, &sync, &preamble);
// Inside what the Cap's SX1262 tunes (868 to 923 MHz) and LoRa's own limits.
if (n < 5 || mhz < 863 || mhz > 928 || bw < 7 || bw > 500 || sf < 5 || sf > 12 || cr < 5 || cr > 8 || sync > 0xFF)
console.println("lora custom: usage: lora custom <MHz> <BW kHz> <SF 5-12> <CR 5-8> <sync hex> [preamble]");
else {
radioService->setConfig({static_cast<uint32_t>(mhz * 1e6 + 0.5), static_cast<float>(bw), static_cast<uint8_t>(sf),
static_cast<uint8_t>(cr), static_cast<uint8_t>(sync), static_cast<uint16_t>(preamble), "Custom"});
console.printf("lora custom: %.3f MHz, BW %.1f kHz, SF %u, CR 4/%u, sync 0x%02X, preamble %u\n", mhz, bw, sf, cr, sync, preamble);
}
}
if (line.startsWith("lora preset ") && radioService) {
const meshtastic::Preset* p = meshtastic::findPreset(line.substring(12).c_str());
if (p) radioService->setPreset(*p);
console.printf("lora preset: %s\n", p ? p->name : "unknown (LongFast LongSlow MediumSlow MediumFast ShortSlow ShortFast LongMod)");
}
if (line == "gnss status" && gnssService) gnssService->printStatus(console, millis());
if ((line == "gnss nmea on" || line == "gnss nmea off") && gnssService) gnssService->setEcho(line.endsWith("on"));
if (line == "gnss restart" && gnssService) gnssService->restart(millis());