Debug Console: files, screenshots and Update from SD over Wi-Fi

New commands everywhere: ls, rm and install <path> (Update from SD
without the Firmware page), all as Storage Service jobs. In Debug
Builds the console task answers get and put (one storage job per
transfer, file kept open, TCP flow control: about 300 KB/s, against
55 KB/s over serial) and screenshot (the RGB332 frame the UI composes
into). rdbg.py turns those into files and PNGs.

A failed put closes the connection: the rest of the file had been
parsed as commands. Card writes are retried 3 times after closing,
truncating to the last good byte and reopening, since FATFS keeps a
file in error after one failed write (seen once at 1.3 MB on this card).
onStorage() decides with one compare-and-swap whether the job or the
timeout wins, so an abandoned job can't touch a returned stack frame.

Verified on the device: screenshot; a get round trip byte-identical;
4 puts in a row; a tampered .ota refused by install; a good one put,
installed from SD, confirmed on Probation. The retry path itself has
not fired since it was added.

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-04 03:18:23 +02:00
co-authored by Claude Opus 5.5
parent 14ff13f634
commit 388e847cd4
6 changed files with 275 additions and 14 deletions
+16 -1
View File
@@ -6,10 +6,13 @@
#include <freertos/semphr.h>
#include <deque>
#include <functional>
#include <string>
#include "service.h"
#include "services/storage_service.h"
#include "services/wifi_service.h"
#include "ui/canvas.h"
class NetworkClient;
@@ -26,7 +29,9 @@ class DebugConsole : public Service {
public:
static constexpr uint16_t kPort = 2323;
explicit DebugConsole(WifiService& wifi);
DebugConsole(WifiService& wifi, StorageService& storage);
// The off-screen frame the UI composes into: `screenshot` sends it as it stands.
void setFrame(Canvas& frame) { frame_ = &frame; }
const char* name() const override { return "debug"; }
void start() override;
@@ -39,8 +44,18 @@ class DebugConsole : public Service {
void listen();
void serve(::NetworkClient& client);
bool authenticate(::NetworkClient& client);
// Binary commands, answered on this task: true if `line` was one.
bool binaryCommand(::NetworkClient& client, const std::string& line);
// Runs `job` on the storage task (where card access is safe) and waits for it. False if the
// card isn't mounted, in which case the storage task never runs it.
bool onStorage(std::function<void()> job);
void get(::NetworkClient& client, const std::string& path);
void put(::NetworkClient& client, const std::string& args);
void screenshot(::NetworkClient& client);
WifiService& wifi_;
StorageService& storage_;
Canvas* frame_ = nullptr;
TaskHandle_t task_ = nullptr;
SemaphoreHandle_t lock_;
std::deque<std::string> commands_;