Public Access
Debug Builds: the console over Wi-Fi (Debug Console, TCP 2323)
cardputer-adv-debug (-DRORO_DEBUG, version +debug) adds a Debug Console: after a token line, a client gets the last 6 KB of console output, live lines (ESP-IDF logs included) and the serial commands. The socket task only queues lines; the main loop runs them. Release builds compile none of it. The token lives in ~/.config/roro9stack/debug-token, created by _docker.sh and passed into the container. All output now goes through `console`, which never waits for USB: a host that was attached but not reading stalled the main loop up to 2 s per line. New commands everywhere: info (slots with their versions from NVS, since the framework stamps its own into each image), tasks, reboot, boot other, log level, help. scripts/rdbg.py is the client; flash.sh --debug builds it; CI builds both variants. ADR 0004. Verified on the device: USB-flashed, then updated over Wi-Fi to a Debug Build that confirmed on Probation; both slots hold Debug Builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
+153
-89
@@ -15,12 +15,15 @@
|
||||
#include "event_bus.h"
|
||||
#include "file_receiver.h"
|
||||
#include "key_mapper.h"
|
||||
#include "platform/console.h"
|
||||
#include "platform/nvs_store.h"
|
||||
#include "platform/system_info.h"
|
||||
#include "service_manager.h"
|
||||
#include "platform/identity.h"
|
||||
#include "services/battery_service.h"
|
||||
#include "services/irc_service.h"
|
||||
#include "services/clock_service.h"
|
||||
#include "services/debug_console.h"
|
||||
#include "services/power_service.h"
|
||||
#include "services/storage_service.h"
|
||||
#include "services/update_service.h"
|
||||
@@ -49,6 +52,9 @@ static SavedNetworks* savedNetworks;
|
||||
static WifiService* wifi;
|
||||
static IrcService* irc;
|
||||
static UpdateService* update;
|
||||
#ifdef RORO_DEBUG
|
||||
static DebugConsole* debugConsole;
|
||||
#endif
|
||||
static Notifier* notifier;
|
||||
static LauncherApp launcher;
|
||||
static AppManager* apps;
|
||||
@@ -102,6 +108,7 @@ void setup() {
|
||||
nvs.begin();
|
||||
UpdateService::bootGuard(nvs); // first: before anything that could crash on new firmware
|
||||
Serial.setRxBufferSize(2 * FileReceiver::kChunk); // before the port opens; sd put sends 1 chunk at a time
|
||||
Serial.setTxBufferSize(2048); // the console skips Serial when it's full: room for a burst like `tasks`
|
||||
|
||||
auto cfg = M5.config();
|
||||
M5Cardputer.begin(cfg, true);
|
||||
@@ -128,6 +135,10 @@ void setup() {
|
||||
services.add(*wifi);
|
||||
services.add(*irc);
|
||||
services.add(*update);
|
||||
#ifdef RORO_DEBUG
|
||||
debugConsole = new DebugConsole(*wifi);
|
||||
services.add(*debugConsole);
|
||||
#endif
|
||||
|
||||
apps = new AppManager(launcher);
|
||||
launcher.setManager(*apps);
|
||||
@@ -138,16 +149,17 @@ void setup() {
|
||||
apps->registerApp({"demo", "Widget demo", true, new DemoApp(bus)});
|
||||
apps->registerApp({"setup", "Setup", true, new SetupApp(settings, *apps)});
|
||||
|
||||
bus.subscribe(EventType::Notification, [](const Event& e) { Serial.printf("notification: %s\n", e.text); });
|
||||
bus.subscribe(EventType::Notification, [](const Event& e) { console.printf("notification: %s\n", e.text); });
|
||||
|
||||
if (!screen.begin()) Serial.println("frame buffer allocation failed");
|
||||
if (!screen.begin()) console.println("frame buffer allocation failed");
|
||||
services.startAll(millis());
|
||||
apps->begin();
|
||||
if (!settings.getBool(Setting::SetupDone)) apps->openModal("setup");
|
||||
Serial.printf("%s %s ready, free heap %u\n", kProductName, versionString(), ESP.getFreeHeap());
|
||||
console.printf("%s %s ready, free heap %u, last start: %s\n", kProductName, versionString(), ESP.getFreeHeap(),
|
||||
system_info::resetReason());
|
||||
}
|
||||
|
||||
// Dev aid: serial commands to drive the UI without the keyboard.
|
||||
// Dev aid: commands to drive the UI without the keyboard, from the serial port or the Debug Console.
|
||||
static bool listingWanted = false;
|
||||
|
||||
static void printListingWhenReady() {
|
||||
@@ -157,9 +169,9 @@ static void printListingWhenReady() {
|
||||
for (size_t i = 0; i < listing.size(); i++) {
|
||||
uint64_t bytes = 0;
|
||||
for (auto& f : listing[i]) bytes += f.bytes;
|
||||
Serial.printf("sd list: %-20s %u files, %s\n", kCleanupCategories[i].label, (unsigned)listing[i].size(),
|
||||
formatBytes(bytes).c_str());
|
||||
for (auto& f : listing[i]) Serial.printf(" %s (%u B)\n", f.path.c_str(), (unsigned)f.bytes);
|
||||
console.printf("sd list: %-20s %u files, %s\n", kCleanupCategories[i].label, (unsigned)listing[i].size(),
|
||||
formatBytes(bytes).c_str());
|
||||
for (auto& f : listing[i]) console.printf(" %s (%u B)\n", f.path.c_str(), (unsigned)f.bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,6 +270,132 @@ static void uploadStep() {
|
||||
}
|
||||
}
|
||||
|
||||
static const char* const kHelp =
|
||||
"info firmware, uptime, memory, Wi-Fi, app slots\n"
|
||||
"tasks FreeRTOS tasks: state, priority, free stack, CPU\n"
|
||||
"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"
|
||||
"key <name|char> press a key: up down left right select back home, or one character\n"
|
||||
"wifi status | wifi add <ssid><TAB><password>\n"
|
||||
"irc start | irc dump | irc say <buffer> <text>\n"
|
||||
"sd list | cat <path> | log <text> | burst | sound on|off | short | normal\n"
|
||||
#ifdef RORO_DEBUG
|
||||
"crash abort|wdt crash on purpose (to test crash reports and Safe Mode)\n"
|
||||
"quit close the Debug Console connection\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static void runCommand(String line) {
|
||||
line.trim();
|
||||
if (line.isEmpty()) return;
|
||||
if (line == "help") console.print(kHelp);
|
||||
if (line == "info") {
|
||||
system_info::printSystem(console);
|
||||
console.printf("wifi: %s, ip %s, rssi %d | sd: %s\n", wifi->ssid().c_str(), wifi->ip().c_str(), wifi->rssi(),
|
||||
storageService->state().present ? "present" : "none");
|
||||
console.printf("update: %s\n", update->onProbation() ? "on probation" : "confirmed");
|
||||
system_info::printSlots(console, nvs);
|
||||
}
|
||||
if (line == "tasks") system_info::printTasks(console);
|
||||
if (line == "reboot") {
|
||||
console.println("restarting");
|
||||
delay(300);
|
||||
ESP.restart();
|
||||
}
|
||||
if (line == "boot other") console.printf("boot other: %s\n", system_info::bootOtherSlot());
|
||||
if (line.startsWith("log level ")) {
|
||||
int level = line.substring(10).toInt();
|
||||
esp_log_level_set("*", static_cast<esp_log_level_t>(constrain(level, 0, 5)));
|
||||
console.printf("log level: %d\n", constrain(level, 0, 5));
|
||||
}
|
||||
#ifdef RORO_DEBUG
|
||||
if (line == "crash abort") abort();
|
||||
if (line == "crash wdt")
|
||||
for (;;) {} // the main loop never yields: the task watchdog fires
|
||||
#endif
|
||||
if (line == "burst")
|
||||
for (int i = 1; i <= 5; i++)
|
||||
bus.publish(Event::withText(EventType::Notification, ("Burst " + String(i)).c_str(), 0));
|
||||
if (line.startsWith("key ")) { // key up|down|left|right|select|back|home
|
||||
String k = line.substring(4);
|
||||
Key key = k == "up" ? Key::Up : k == "down" ? Key::Down : k == "left" ? Key::Left
|
||||
: k == "right" ? Key::Right : k == "back" ? Key::Back : k == "home" ? Key::Home : Key::Select;
|
||||
KeyEvent ev = k.length() == 1 && k[0] > ' ' ? KeyEvent::character((unsigned char)k[0]) : KeyEvent::of(key);
|
||||
if (!power->onKey(millis())) apps->handleKey(ev);
|
||||
}
|
||||
if (line.startsWith("wifi add ")) { // wifi add <ssid>\t<password>: credentials never touch the repo
|
||||
int tab = line.indexOf('\t');
|
||||
std::string ssid = (tab > 0 ? line.substring(9, tab) : line.substring(9)).c_str();
|
||||
std::string pass = tab > 0 ? line.substring(tab + 1).c_str() : "";
|
||||
std::string error = savedNetworks->add(ssid, pass);
|
||||
console.printf("wifi add: %s\n", error.empty() ? "ok" : error.c_str());
|
||||
wifi->savedNetworksChanged();
|
||||
}
|
||||
if (line.startsWith("log ") && !line.startsWith("log level ")) { // appends to a test IRC Log
|
||||
std::string path = storage::dailyLogPath({"irc", "dev", "#test"}, clockService->localDate());
|
||||
storageService->appendLine(path, clockService->displayTime() + " " + line.substring(4).c_str());
|
||||
console.printf("log: queued to %s\n", path.c_str());
|
||||
}
|
||||
if (line.startsWith("cat ")) {
|
||||
std::string path = line.substring(4).c_str();
|
||||
File f = SD.open(path.c_str());
|
||||
if (!f) console.printf("cat: cannot open %s\n", path.c_str());
|
||||
else {
|
||||
console.printf("--- %s (%u B) ---\n", path.c_str(), (unsigned)f.size());
|
||||
int shown = 0;
|
||||
while (f.available() && shown < 1200) { console.write(f.read()); shown++; }
|
||||
console.println("\n--- end ---");
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
if (line.startsWith("sd put ")) startUpload(line.substring(7)); // then raw bytes: see uploadStep()
|
||||
if (line == "sd list") {
|
||||
storageService->requestListing();
|
||||
listingWanted = true;
|
||||
}
|
||||
if (line == "irc start") irc->connect();
|
||||
if (line.startsWith("irc say ")) { // irc say <buffer index> <text>
|
||||
String rest = line.substring(8);
|
||||
int space = rest.indexOf(' ');
|
||||
int b = rest.substring(0, space).toInt();
|
||||
std::string text = rest.substring(space + 1).c_str();
|
||||
irc->withSession([&](IrcSession& s) { s.input(b, text, clockService->utcNow()); });
|
||||
}
|
||||
if (line == "irc dump") {
|
||||
console.printf("irc: status %d, unread %d, heap %u min %u\n", (int)irc->status(), irc->totalUnread(),
|
||||
ESP.getFreeHeap(), ESP.getMinFreeHeap());
|
||||
IrcConfig c = irc->draftConfig(); // which login is configured, never the secrets
|
||||
console.printf("irc: nick %s, sasl %s, nickserv %s, autojoin %u channels\n", c.nick.c_str(),
|
||||
c.saslUser.empty() || c.saslPassword.empty() ? "off" : "on",
|
||||
c.nickservPassword.empty() ? "off" : "on", (unsigned)c.autojoin.size());
|
||||
irc->withSession([](IrcSession& s) {
|
||||
for (int i = 0; i < s.bufferCount(); i++) {
|
||||
const auto& b = s.buffer(i);
|
||||
console.printf("irc buffer %d %s unread %d%s\n", i, b.name.c_str(), b.unread, b.joined ? " joined" : "");
|
||||
size_t from = 0;
|
||||
for (size_t j = from; j < b.lines.size(); j++)
|
||||
console.printf(" <%s> %s\n", b.lines[j].nick.c_str(), b.lines[j].text.c_str());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (line == "wifi status")
|
||||
console.printf("wifi: state %d ssid '%s' rssi %d ip %s clock %s heap %u min %u | fw %s%s\n",
|
||||
(int)wifi->state(), wifi->ssid().c_str(), wifi->rssi(), wifi->ip().c_str(),
|
||||
clockService->displayTime().c_str(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), versionString(),
|
||||
update->onProbation() ? " (on probation)" : "");
|
||||
if (line == "sound off") settings.setBool(Setting::Sound, false);
|
||||
if (line == "sound on") settings.setBool(Setting::Sound, true);
|
||||
if (line == "short") {
|
||||
settings.setInt(Setting::DimTimeoutS, 5);
|
||||
settings.setInt(Setting::OffTimeoutS, 10);
|
||||
}
|
||||
if (line == "normal") {
|
||||
settings.setInt(Setting::OffTimeoutS, 60);
|
||||
settings.setInt(Setting::DimTimeoutS, 30);
|
||||
}
|
||||
}
|
||||
|
||||
static void serialCommands() {
|
||||
if (upload.active()) return readUploadBytes(); // raw file bytes, not commands
|
||||
static String line;
|
||||
@@ -267,87 +405,7 @@ static void serialCommands() {
|
||||
line += c;
|
||||
continue;
|
||||
}
|
||||
line.trim();
|
||||
if (line == "burst")
|
||||
for (int i = 1; i <= 5; i++)
|
||||
bus.publish(Event::withText(EventType::Notification, ("Burst " + String(i)).c_str(), 0));
|
||||
if (line.startsWith("key ")) { // key up|down|left|right|select|back|home
|
||||
String k = line.substring(4);
|
||||
Key key = k == "up" ? Key::Up : k == "down" ? Key::Down : k == "left" ? Key::Left
|
||||
: k == "right" ? Key::Right : k == "back" ? Key::Back : k == "home" ? Key::Home : Key::Select;
|
||||
KeyEvent ev = k.length() == 1 && k[0] > ' ' ? KeyEvent::character((unsigned char)k[0]) : KeyEvent::of(key);
|
||||
if (!power->onKey(millis())) apps->handleKey(ev);
|
||||
}
|
||||
if (line.startsWith("wifi add ")) { // wifi add <ssid>\t<password>: credentials never touch the repo
|
||||
int tab = line.indexOf('\t');
|
||||
std::string ssid = (tab > 0 ? line.substring(9, tab) : line.substring(9)).c_str();
|
||||
std::string pass = tab > 0 ? line.substring(tab + 1).c_str() : "";
|
||||
std::string error = savedNetworks->add(ssid, pass);
|
||||
Serial.printf("wifi add: %s\n", error.empty() ? "ok" : error.c_str());
|
||||
wifi->savedNetworksChanged();
|
||||
}
|
||||
if (line.startsWith("log ")) { // appends to a test IRC Log
|
||||
std::string path = storage::dailyLogPath({"irc", "dev", "#test"}, clockService->localDate());
|
||||
storageService->appendLine(path, clockService->displayTime() + " " + line.substring(4).c_str());
|
||||
Serial.printf("log: queued to %s\n", path.c_str());
|
||||
}
|
||||
if (line.startsWith("cat ")) {
|
||||
std::string path = line.substring(4).c_str();
|
||||
File f = SD.open(path.c_str());
|
||||
if (!f) Serial.printf("cat: cannot open %s\n", path.c_str());
|
||||
else {
|
||||
Serial.printf("--- %s (%u B) ---\n", path.c_str(), (unsigned)f.size());
|
||||
int shown = 0;
|
||||
while (f.available() && shown < 1200) { Serial.write(f.read()); shown++; }
|
||||
Serial.println("\n--- end ---");
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
if (line.startsWith("sd put ")) startUpload(line.substring(7)); // then raw bytes: see uploadStep()
|
||||
if (line == "sd list") {
|
||||
storageService->requestListing();
|
||||
listingWanted = true;
|
||||
}
|
||||
if (line == "irc start") irc->connect();
|
||||
if (line.startsWith("irc say ")) { // irc say <buffer index> <text>
|
||||
String rest = line.substring(8);
|
||||
int space = rest.indexOf(' ');
|
||||
int b = rest.substring(0, space).toInt();
|
||||
std::string text = rest.substring(space + 1).c_str();
|
||||
irc->withSession([&](IrcSession& s) { s.input(b, text, clockService->utcNow()); });
|
||||
}
|
||||
if (line == "irc dump") {
|
||||
Serial.printf("irc: status %d, unread %d, heap %u min %u\n", (int)irc->status(), irc->totalUnread(),
|
||||
ESP.getFreeHeap(), ESP.getMinFreeHeap());
|
||||
IrcConfig c = irc->draftConfig(); // which login is configured, never the secrets
|
||||
Serial.printf("irc: nick %s, sasl %s, nickserv %s, autojoin %u channels\n", c.nick.c_str(),
|
||||
c.saslUser.empty() || c.saslPassword.empty() ? "off" : "on",
|
||||
c.nickservPassword.empty() ? "off" : "on", (unsigned)c.autojoin.size());
|
||||
irc->withSession([](IrcSession& s) {
|
||||
for (int i = 0; i < s.bufferCount(); i++) {
|
||||
const auto& b = s.buffer(i);
|
||||
Serial.printf("irc buffer %d %s unread %d%s\n", i, b.name.c_str(), b.unread, b.joined ? " joined" : "");
|
||||
size_t from = 0;
|
||||
for (size_t j = from; j < b.lines.size(); j++)
|
||||
Serial.printf(" <%s> %s\n", b.lines[j].nick.c_str(), b.lines[j].text.c_str());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (line == "wifi status")
|
||||
Serial.printf("wifi: state %d ssid '%s' rssi %d ip %s clock %s heap %u min %u | fw %s%s\n",
|
||||
(int)wifi->state(), wifi->ssid().c_str(), wifi->rssi(), wifi->ip().c_str(),
|
||||
clockService->displayTime().c_str(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), versionString(),
|
||||
update->onProbation() ? " (on probation)" : "");
|
||||
if (line == "sound off") settings.setBool(Setting::Sound, false);
|
||||
if (line == "sound on") settings.setBool(Setting::Sound, true);
|
||||
if (line == "short") {
|
||||
settings.setInt(Setting::DimTimeoutS, 5);
|
||||
settings.setInt(Setting::OffTimeoutS, 10);
|
||||
}
|
||||
if (line == "normal") {
|
||||
settings.setInt(Setting::OffTimeoutS, 60);
|
||||
settings.setInt(Setting::DimTimeoutS, 30);
|
||||
}
|
||||
runCommand(line);
|
||||
line = "";
|
||||
}
|
||||
}
|
||||
@@ -362,6 +420,12 @@ void loop() {
|
||||
uint32_t now = millis();
|
||||
|
||||
serialCommands();
|
||||
#ifdef RORO_DEBUG
|
||||
for (std::string remote; debugConsole->takeCommand(remote);) {
|
||||
console.printf("> %s\n", remote.c_str()); // so the transcript reads the same on both ends
|
||||
runCommand(remote.c_str());
|
||||
}
|
||||
#endif
|
||||
uploadStep();
|
||||
printListingWhenReady();
|
||||
M5Cardputer.update();
|
||||
@@ -380,7 +444,7 @@ void loop() {
|
||||
|
||||
if (now - lastLog > 10000) {
|
||||
lastLog = now;
|
||||
Serial.printf("status: heap %u min %u\n", ESP.getFreeHeap(), ESP.getMinFreeHeap());
|
||||
console.printf("status: heap %u min %u\n", ESP.getFreeHeap(), ESP.getMinFreeHeap());
|
||||
}
|
||||
|
||||
// Firmware Update: its progress takes over the screen, then the device restarts when it's safe.
|
||||
|
||||
Reference in New Issue
Block a user