Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

chore(pro): link health in the heartbeat, dead code out, sparse 32 px font (#1420)

0xdiego25edd6ebc3cc91
diff --git a/cli/src/cable/cableFrame.ts b/cli/src/cable/cableFrame.ts
index a9e1ac92e..1ebc31d8c 100644
--- a/cli/src/cable/cableFrame.ts
+++ b/cli/src/cable/cableFrame.ts
@@ -121,6 +121,8 @@ export class CableDecoder {
*/
discardedBytes = 0
corruptFrames = 0
+ /** Sees the bytes about to be stepped over, in order, before they go (a panic's text rides in here). */
+ onDiscard?: (bytes: Uint8Array) => void
/**
* Forget any partial frame. Call when the port is reopened: leftover bytes belong to a session that has
@@ -170,7 +172,9 @@ export class CableDecoder {
* noise" on a link that is working perfectly.
*/
private discard(count: number): void {
- this.discardedBytes += Math.min(count, this.len)
+ const n = Math.min(count, this.len)
+ this.discardedBytes += n
+ if (n > 0) this.onDiscard?.(this.buf.subarray(0, n))
this.consume(count)
}
diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.ts
index eb879a259..53e1af729 100644
--- a/cli/src/cable/cableSession.spec.ts
+++ b/cli/src/cable/cableSession.spec.ts
@@ -58,6 +58,9 @@ class LoopbackPort implements CablePort {
this.onData(Buffer.from(encodeCableFrame(CableType.Json, Buffer.from(JSON.stringify(msg), 'utf8'))))
}
+ /** Bytes that are not (all) a frame, as the dial's boot ROM or panic handler writes them. */
+ raw(bytes: Buffer): void { this.onData(bytes) }
+
pcm(bytes: Buffer): void {
this.onData(Buffer.from(encodeCableFrame(CableType.Pcm, bytes)))
}
@@ -3481,4 +3484,46 @@ describe('hello capabilities', () => {
expect(port.types()).not.toContain('player.library')
} finally { await session.stop() }
})
+
+ describe('link counters in the dial log', () => {
+ const linkLines = (log: DialLog) => readFileSync(log.currentPath, 'utf8').split('\n').filter((l) => l.includes('[daemon] link'))
+
+ it('logs bytes and frames both ways at close, and keeps the printable text of non-frame bytes', async () => {
+ const log = tmpLog()
+ const { session, port } = await connect(makeHost(), log)
+ try {
+ port.say({ t: 'hello', product: 'harness', fw: '0.1.0', proto: 1, mac: 'aa:bb' })
+ await vi.waitFor(() => expect(port.types()).toContain('agents.end'))
+ port.raw(Buffer.concat([Buffer.from('Guru Meditation Error: Core 0 panic\x00\x01ab\x02'), Buffer.from([0xa5])]))
+ port.say({ t: 'hello', product: 'harness', mac: 'aa:bb' }) // a frame after the noise still decodes
+ await settle()
+ await port.close('unplugged')
+ await log.flush()
+ } finally { await session.stop() }
+ const [line] = linkLines(log)
+ const sentBytes = port.frames.reduce((n, f) => n + f.length, 0)
+ expect(line).toContain('link at close')
+ expect(line).toContain(`tx ${sentBytes} B in ${port.frames.length} frames`)
+ expect(line).toMatch(/rx \d+ B in 2 frames/)
+ expect(line).toMatch(/discarded \d+ B/)
+ expect(line).toContain('non-frame text: Guru Meditation Error: Core 0 panic')
+ expect(line).not.toContain('ab') // a two-character run is not text worth keeping
+ })
+
+ it('logs once a minute while connected, and caps the text at 200 characters', async () => {
+ vi.useFakeTimers({ toFake: ['Date'] })
+ const log = tmpLog()
+ const { session, port } = await connect(makeHost(), log)
+ try {
+ port.say({ t: 'hello', product: 'harness', fw: '0.1.0', proto: 1, mac: 'aa:bb' })
+ await vi.waitFor(() => expect(port.types()).toContain('agents.end'))
+ port.raw(Buffer.from('x'.repeat(500) + '\n'))
+ vi.setSystemTime(Date.now() + 61_000)
+ await vi.waitFor(async () => { await log.flush(); expect(linkLines(log).length).toBeGreaterThan(0) }, NEXT_TICKS)
+ } finally { vi.useRealTimers(); await session.stop() }
+ const [line] = linkLines(log)
+ expect(line).toMatch(/\] link · tx \d+ B in \d+ frames · rx \d+ B in 1 frames/)
+ expect(line.split('non-frame text: ')[1]).toHaveLength(200)
+ })
+ })
})
diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.ts
index 4d15be080..28d3e4313 100644
--- a/cli/src/cable/cableSession.ts
+++ b/cli/src/cable/cableSession.ts
@@ -43,6 +43,11 @@ const PING_EVERY_MS = 5_000
/** No bytes of any kind for this long → the handle is dead. Longer than the dial's own 15 s window, so a
* single late message cannot trip both sides at once and have each conclude the other left. */
const SILENCE_MS = 20_000
+/** How often a connected port's traffic counters go to the dial's log. */
+const LINK_LOG_MS = 60_000
+/** Non-frame text kept per logging interval, and the shortest printable run worth keeping. */
+const NOISE_MAX = 200
+const NOISE_RUN_MIN = 4
const REOPEN_EVERY_MS = 2_000
// How long one attempt at opening the port may take before it is abandoned.
//
@@ -563,6 +568,8 @@ const PET_TRANSIENT = new Set(['timeout', 'unreadable', 'memory', 'busy'])
export class CableSession {
private link: CablePort | null = null
private decoder = new CableDecoder()
+ /** This port's traffic since it opened, logged once a minute and when it closes (see logLink). */
+ private traffic = { at: 0, tx: 0, txFrames: 0, rx: 0, rxFrames: 0, corrupt: 0, discarded: 0, run: '', noise: '' }
private timer: NodeJS.Timeout | null = null
private greetedMac: string | null = null
/** This session has spoken with a real dial at least once. Never reset: a port that has been a dial
@@ -795,6 +802,7 @@ export class CableSession {
if (this.stopped) return
// The firmware beats once a minute; the gap is marked in the dial's own log, where it is read.
this.dialLog.tick(this.isConnected)
+ if (this.isConnected && Date.now() - this.traffic.at >= LINK_LOG_MS) this.logLink('link')
if (!this.link?.isOpen) {
await this.tryOpen()
return
@@ -938,6 +946,10 @@ export class CableSession {
if (opened.path !== this.foreignPort) this.foreignPort = null
this.bytesSinceOpen = 0
this.framesSinceOpen = 0
+ this.traffic = {
+ at: Date.now(), tx: 0, txFrames: 0, rx: 0, rxFrames: 0,
+ corrupt: this.decoder.corruptFrames, discarded: this.decoder.discardedBytes, run: '', noise: '',
+ }
this.link = opened
// Leftover bytes belong to a session that has ended; carrying them across would put a stale
// half-frame in front of the first real frame of the new one.
@@ -966,6 +978,7 @@ export class CableSession {
}
private onClosed(why: string): void {
+ if (this.traffic.rx || this.traffic.tx) this.logLink('link at close')
this.log(`cable: closed (${why})`)
this.cancelFormVoice()
this.cancelSearchVoice()
@@ -1028,6 +1041,43 @@ export class CableSession {
static readonly BUDGET = { garbageBytes: 64 * 1024, frames: 2_000, decodeMs: 500 }
private budget = { since: 0, garbage: 0, frames: 0, ms: 0 }
+ /**
+ * This port's counters in the dial's log, to read beside the firmware's own `alive` line: a gap between
+ * what one side wrote and the other decoded is the lossy link. Plus the printable runs of the bytes the
+ * decoder stepped over (at most NOISE_MAX characters a minute), so a device panic's text is kept.
+ */
+ private logLink(label: string): void {
+ const t = this.traffic
+ this.keepRun()
+ this.log(`cable: ${label} · tx ${t.tx} B in ${t.txFrames} frames · rx ${t.rx} B in ${t.rxFrames} frames · corrupt ${this.decoder.corruptFrames - t.corrupt} · discarded ${this.decoder.discardedBytes - t.discarded} B${t.noise ? ` · non-frame text: ${t.noise}` : ''}`)
+ t.at = Date.now()
+ t.noise = ''
+ }
+
+ /** Close the current run of printable discarded bytes into the minute's text, if it is long enough to read. */
+ private keepRun(): void {
+ const t = this.traffic
+ if (t.run.length >= NOISE_RUN_MIN && t.noise.length < NOISE_MAX) {
+ t.noise = `${t.noise}${t.noise ? ' | ' : ''}${t.run}`.slice(0, NOISE_MAX)
+ }
+ t.run = ''
+ }
+
+ private noted = (bytes: Uint8Array): void => {
+ for (const b of bytes) {
+ if (b >= 0x20 && b < 0x7f) {
+ if (this.traffic.run.length < NOISE_MAX) this.traffic.run += String.fromCharCode(b)
+ } else this.keepRun()
+ }
+ }
+
+ /** One frame to the dial, counted. */
+ private async put(link: CablePort, bytes: Uint8Array): Promise<void> {
+ await link.write(bytes)
+ this.traffic.tx += bytes.length
+ this.traffic.txFrames++
+ }
+
private onBytes(chunk: Buffer): void {
const started = performance.now()
const discarded = this.decoder.discardedBytes
@@ -1056,8 +1106,11 @@ export class CableSession {
private decode(chunk: Buffer, counted: () => void): void {
this.lastRx = Date.now()
this.bytesSinceOpen += chunk.length
+ this.traffic.rx += chunk.length
+ this.decoder.onDiscard = this.noted
this.decoder.feed(chunk, (frame) => {
counted()
+ this.traffic.rxFrames++
this.framesSinceOpen += 1
if (frame.type === CableType.Json) {
let msg: Message
@@ -1760,7 +1813,7 @@ export class CableSession {
candidate.version,
async (slice) => {
if (!this.link?.isOpen) throw new Error('port closed mid-transfer')
- await this.link.write(encodeCableFrame(CableType.Fw, slice))
+ await this.put(this.link, encodeCableFrame(CableType.Fw, slice))
},
(line) => this.log(line),
{ offsets: this.greetedBoard === 'pro' && this.greetedOta === 'v1' },
@@ -1869,7 +1922,7 @@ export class CableSession {
id,
async (slice) => {
if (!this.link?.isOpen) throw new Error('port closed mid-transfer')
- await this.link.write(encodeCableFrame(CableType.Pet, slice))
+ await this.put(this.link, encodeCableFrame(CableType.Pet, slice))
},
(line) => this.log(line.replace('firmware', 'pet')),
),
@@ -2197,7 +2250,7 @@ export class CableSession {
private async send(msg: Message): Promise<boolean> {
if (!this.link?.isOpen) return false
try {
- await this.link.write(encodeCableFrame(CableType.Json, Buffer.from(JSON.stringify(msg), 'utf8')))
+ await this.put(this.link, encodeCableFrame(CableType.Json, Buffer.from(JSON.stringify(msg), 'utf8')))
return true
} catch (err) {
this.log(`cable: write failed (${(err as Error).message})`)
diff --git a/devices/harness-pro/README.md b/devices/harness-pro/README.md
index dbb6adc2b..f2faa061d 100644
--- a/devices/harness-pro/README.md
+++ b/devices/harness-pro/README.md
@@ -62,7 +62,7 @@ The generator copies the round's Codex timings and geometry as literals, so a re
## Size
No Wi-Fi: the Pro talks over the cable only, and the module's ESP32-C5 is held in reset. Fonts 42 and 56 carry masks
-only for `# > _ ?` (`test_fonts.py` fails on any other character drawn at those sizes). The image is about 1.87 MB;
+only for `# > _ ?`, and font 32 only for `> _` (`test_fonts.py` fails on any other character drawn at those sizes). The image is about 1.87 MB;
`docs/size-baseline.txt` has the before and after.
## Layout
@@ -82,12 +82,14 @@ only for `# > _ ?` (`test_fonts.py` fails on any other character drawn at those
## Daemon contract
The device follows [docs/cable.md](docs/cable.md). A capability in the hello turns on extra daemon output; a daemon
-that predates one ignores it. The four capabilities:
+that predates one ignores it. The six capabilities:
- `swarms: "members-v1"`: agent ids and members on each swarm tab.
- `recap: "long-v1"`: the full answer text on a summary.
- `activity: "steps-v1"`: step, action and elapsed time on turn activity.
+- `stats: "turn-v1"`: the counts on a finished turn (tests, commits, tokens).
- `player: "library-v1"`: the paged player library request and reply.
+- `ota: "v1"`: the daemon may offer firmware over the cable.
## Further reading
diff --git a/devices/harness-pro/docs/cable.md b/devices/harness-pro/docs/cable.md
index 6600770cc..ef67882ea 100644
--- a/devices/harness-pro/docs/cable.md
+++ b/devices/harness-pro/docs/cable.md
@@ -26,8 +26,11 @@ Full key list, in the order the Pro sends it:
| `swarms` | `"members-v1"` | capability |
| `recap` | `"long-v1"` | capability |
| `activity` | `"steps-v1"` | capability |
+| `stats` | `"turn-v1"` | capability |
| `player` | `"library-v1"` | capability |
+| `ota` | `"v1"` | capability: the Pro takes firmware offers |
| `mac` | `aa:bb:...` | existing |
+| `settings` | object | existing: brightness, character, face, voiceLang, muted, quiet, straightTitle, focusFace, scrollReversed, round |
Dropped from the branch's hello: `speech` (`pcm16-v1`). The Pro does not take speech output.
diff --git a/devices/harness-pro/firmware/fonts/Inter-Medium.ttf b/devices/harness-pro/firmware/fonts/Inter-Medium.ttf
deleted file mode 100644
index 458cd0601..000000000
Binary files a/devices/harness-pro/firmware/fonts/Inter-Medium.ttf and /dev/null differ
diff --git a/devices/harness-pro/firmware/fonts/README.md b/devices/harness-pro/firmware/fonts/README.md
index 37129dc14..45653b7d6 100644
--- a/devices/harness-pro/firmware/fonts/README.md
+++ b/devices/harness-pro/firmware/fonts/README.md
@@ -4,7 +4,7 @@ Pets faces (always these files, whatever `PRO_FONT` is; baked by `scripts/gen_fo
| File | Source | Version | sha256 |
|---|---|---|---|
-| Inter-Bold.ttf, Inter-SemiBold.ttf, Inter-Medium.ttf, Inter-Regular.ttf | `extras/ttf/` of https://github.com/rsms/inter/releases/download/v4.1/Inter-4.1.zip (zip sha256 `9883fdd4a49d4fb66bd8177ba6625ef9a64aa45899767dde3d36aa425756b11e`) | Inter 4.1 | Bold `288316099b1e0a47a4716d159098005eef7c0066921f34e3200393dbdb01947f`, SemiBold `78a843fade9d4612a5567302fb595b56976eb5fcebf4fea5a5912d638bafcde3`, Medium `97ad806f526e41546d46365bb3a393145f75b7b1568913db74549ad8b8dba872`, Regular `40d692fce188e4471e2b3cba937be967878f631ad3ebbbdcd587687c7ebe0c82` |
+| Inter-Bold.ttf, Inter-SemiBold.ttf, Inter-Regular.ttf | `extras/ttf/` of https://github.com/rsms/inter/releases/download/v4.1/Inter-4.1.zip (zip sha256 `9883fdd4a49d4fb66bd8177ba6625ef9a64aa45899767dde3d36aa425756b11e`) | Inter 4.1 | Bold `288316099b1e0a47a4716d159098005eef7c0066921f34e3200393dbdb01947f`, SemiBold `78a843fade9d4612a5567302fb595b56976eb5fcebf4fea5a5912d638bafcde3`, Regular `40d692fce188e4471e2b3cba937be967878f631ad3ebbbdcd587687c7ebe0c82` |
| JetBrainsMono-Medium.ttf | `fonts/ttf/` of https://github.com/JetBrains/JetBrainsMono/releases/download/v2.304/JetBrainsMono-2.304.zip (zip sha256 `6f6376c6ed2960ea8a963cd7387ec9d76e3f629125bc33d1fdcd7eb7012f7bbf`) | JetBrains Mono 2.304 | `31c92d01a8a08528b718a43addf0ad3df0af2ca4b7b3290a452f70f358e14d3d` |
Base faces (`ht_pro_*`, from `LiberationSans-Regular.ttf` when the system font is not used; baked by `scripts/gen_fonts.py`, SIL OFL 1.1):
diff --git a/devices/harness-pro/firmware/main/app/pod_glue.c b/devices/harness-pro/firmware/main/app/pod_glue.c
index 7f80c7a2d..bf992c8dd 100644
--- a/devices/harness-pro/firmware/main/app/pod_glue.c
+++ b/devices/harness-pro/firmware/main/app/pod_glue.c
@@ -150,12 +150,6 @@ pod_out_t pod_ui_swarms(pod_ui_t *u, const cable_swarm_t *items, int n, const ca
return synced(u);
}
-pod_out_t pod_ui_status(pod_ui_t *u, const char *id, const char *status, uint32_t now_ms)
-{
- pod_model_library_status(&u->model, id, status, now_ms);
- return synced(u);
-}
-
pod_out_t pod_ui_turn(pod_ui_t *u, const char *id, const char *kind, const char *text, int elapsed_s, uint32_t now_ms)
{
pod_model_turn(&u->model, id, kind, text, elapsed_s, now_ms);
@@ -394,7 +388,7 @@ pod_out_t pod_ui_touch(pod_ui_t *u, bool down, int x, int y, uint32_t now_ms, bo
u->anchor_y = y;
if (host_scrolls(u) && u->scroll_emit) {
if (!u->scroll_begun) { // from the DOWN's point and time, so the first MOVE carries the travel so far
- ht_scroll_begin(&u->scroll, u->start_x, u->start_y, u->down_ms, u->scroll_reversed, false, u->scroll_emit,
+ ht_scroll_begin(&u->scroll, u->start_x, u->start_y, u->down_ms, u->scroll_reversed, u->scroll_emit,
u->scroll_ctx);
u->scroll_begun = true;
}
diff --git a/devices/harness-pro/firmware/main/app/pod_glue.h b/devices/harness-pro/firmware/main/app/pod_glue.h
index 1c909c07c..7e456e34e 100644
--- a/devices/harness-pro/firmware/main/app/pod_glue.h
+++ b/devices/harness-pro/firmware/main/app/pod_glue.h
@@ -106,7 +106,6 @@ pod_out_t pod_ui_roster(pod_ui_t *, const pod_roster_row_t *rows, int n);
// `members` may be NULL (no agentIds); its i-th entry belongs to items[i].
pod_out_t pod_ui_swarms(pod_ui_t *, const cable_swarm_t *items, int n, const cable_swarm_members_t *members,
const char *selected, const cable_tile_t *tiles, int tile_count);
-pod_out_t pod_ui_status(pod_ui_t *, const char *id, const char *status, uint32_t now_ms);
pod_out_t pod_ui_turn(pod_ui_t *, const char *id, const char *kind, const char *text, int elapsed_s, uint32_t now_ms);
// turn.stats for an agent (-1 leaves a field unknown); unknown agents are ignored.
pod_out_t pod_ui_turn_stats(pod_ui_t *, const char *id, int32_t passed, int32_t failed, int32_t commits, int32_t tokens_in, int32_t tokens_out);
diff --git a/devices/harness-pro/firmware/main/app/pro_app.c b/devices/harness-pro/firmware/main/app/pro_app.c
index 064383651..a35d52b68 100644
--- a/devices/harness-pro/firmware/main/app/pro_app.c
+++ b/devices/harness-pro/firmware/main/app/pro_app.c
@@ -2,7 +2,7 @@
// contacts become Pod gestures, and the render task draws Pod's frame. The rules here are the ones the Pod build of
// the round dial's ui_habitat.c followed (docs/port-inventory.md; row ids R* and P* below name its entries).
//
-// THREADS: three tasks meet here. The cable_link task (6 KB stack) calls the pro_app_* callbacks; the touch task
+// THREADS: three tasks meet here. The cable_link task (STACK_CABLE_LINK, 12 KB) calls the pro_app_* callbacks; the touch task
// calls pro_app_touch; the render task ticks, draws and paints. One recursive mutex guards the Pod object, the
// busy/question/machine tables and the dirty flag. Nothing that leaves the device is sent under it: effects and
// requests are queued while the mutex is held and sent by leave() after it is released.
@@ -17,6 +17,7 @@
#include "app/pro_voice.h"
#include "audio/audio_capture.h"
#include "audio/pro_recorder.h"
+#include "cable/cable_link.h"
#include "cable/pro_cable.h"
#include "pro_app_api.h"
#include "pro_display.h"
@@ -24,6 +25,7 @@
#include "sys/config_store.h"
#include "sys/fw_update.h"
#include "sys/ram_telemetry.h"
+#include "task_stacks.h"
#include "theme.h"
#include "esp_attr.h"
@@ -41,7 +43,6 @@
static const char *TAG = "pro";
-#define RENDER_STACK 24576 // the ROM inflater and the 24-row strips want room (SRC's Pro render task)
#define IDLE_SLEEP_MS 300000u // no touch for this long and the screen sleeps (R / P25)
#define HEARTBEAT_MS 60000u
#define FX_MAX 4 // effects queued under the lock until leave()
@@ -52,7 +53,7 @@ static const char *TAG = "pro";
// Pod's model, scenes and tables. All in PSRAM: the model alone is ~130 KB, two scenes of 192 runs ~80 KB (R18).
static EXT_RAM_BSS_ATTR pod_ui_t s_pod;
static EXT_RAM_BSS_ATTR ht_scene_t s_scene[2];
-static EXT_RAM_BSS_ATTR pod_roster_row_t s_rows[POD_AGENTS_MAX]; // not on the 6 KB cable_link stack (P9)
+static EXT_RAM_BSS_ATTR pod_roster_row_t s_rows[POD_AGENTS_MAX]; // not on the cable_link stack (P9)
static EXT_RAM_BSS_ATTR struct { char id[ID_MAX], machine_id[ID_MAX]; } s_info[POD_AGENTS_MAX]; // the roster's machine ids
static EXT_RAM_BSS_ATTR char s_busy[POD_AGENTS_MAX][ID_MAX]; // agents in a live turn ("" = free slot)
static EXT_RAM_BSS_ATTR char s_quest[POD_AGENTS_MAX][ID_MAX]; // agents with an open question
@@ -297,14 +298,6 @@ void pro_app_link(bool up, const char *machine)
leave();
}
-bool pro_app_linked(void)
-{
- pro_app_lock();
- const bool linked = s_linked;
- pro_app_unlock();
- return linked;
-}
-
// ---- roster, tabs, library ------------------------------------------------------------------------------
void pro_app_agents(const pro_agent_row_t *rows, int n)
@@ -848,13 +841,19 @@ static void heartbeat(uint32_t frames, uint32_t raster_max_us, uint32_t frame_ma
last = now;
pro_touch_stats_t touch;
pro_touch_stats(&touch);
+ const cable_link_stats_t link = cable_link_stats();
+ uint32_t bad = 0, unknown = 0;
+ pro_cable_counters(&bad, &unknown);
// The host watches this line while the renderer is alive, including while asleep.
- ESP_LOGI(TAG, "alive up=%lus heap=%u/%u psram=%u touches=%lu read_fails=%lu frames=%lu raster_max_us=%lu frame_max_us=%lu stack_free=%u muted=%d%s%s",
+ ESP_LOGI(TAG, "alive up=%lus heap=%u/%u psram=%u touches=%lu read_fails=%lu frames=%lu raster_max_us=%lu frame_max_us=%lu stack_free=%u muted=%d link_rx=%lu link_frames=%lu link_corrupt=%lu link_discarded=%lu link_dropped_logs=%lu msg_bad=%lu msg_unknown=%lu%s%s",
(unsigned long)(now / 1000), (unsigned)heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
(unsigned)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL), (unsigned)heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
(unsigned long)touch.presses, (unsigned long)touch.read_failures, (unsigned long)frames,
(unsigned long)raster_max_us, (unsigned long)frame_max_us,
- (unsigned)uxTaskGetStackHighWaterMark(NULL), (int)pro_settings_muted(), touch.controller_ok ? "" : " TOUCH-DEAD", pro_app_asleep() ? " asleep" : "");
+ (unsigned)uxTaskGetStackHighWaterMark(NULL), (int)pro_settings_muted(),
+ (unsigned long)link.rx_bytes, (unsigned long)link.frames_ok, (unsigned long)link.corrupt_frames,
+ (unsigned long)link.discarded_bytes, (unsigned long)link.dropped_logs, (unsigned long)bad, (unsigned long)unknown,
+ touch.controller_ok ? "" : " TOUCH-DEAD", pro_app_asleep() ? " asleep" : "");
ram_telemetry_periodic("alive"); // the heap checkpoint, and every tenth time the long-lived tasks' stack marks
}
@@ -927,10 +926,10 @@ void pro_app_start(void)
pro_frame_init();
pro_display_set_brightness(config_load_brightness());
pro_app_bump_activity();
- BaseType_t ok = xTaskCreatePinnedToCore(render_task, "pro_render", RENDER_STACK, NULL, 5, &s_renderer, 1);
+ BaseType_t ok = xTaskCreatePinnedToCore(render_task, "pro_render", STACK_RENDER, NULL, 5, &s_renderer, 1);
assert(ok == pdPASS);
(void)ok;
- ESP_LOGI(TAG, "app up: Pod, render stack %d B", RENDER_STACK);
+ ESP_LOGI(TAG, "app up: Pod, render stack %d B", STACK_RENDER);
}
// ---- firmware update (sys/fw_update.c calls these, from the cable task) -----------------------------------------
@@ -1028,8 +1027,6 @@ bool pro_app_test_take_dirty(void)
return dirty;
}
-bool pro_app_test_take_force_frame(void) { return atomic_exchange(&s_force_frame, false); }
-
void pro_app_test_reset(void)
{
if (!s_lock) s_lock = xSemaphoreCreateRecursiveMutex();
diff --git a/devices/harness-pro/firmware/main/app/pro_app.h b/devices/harness-pro/firmware/main/app/pro_app.h
index 5df625760..ccb6c9016 100644
--- a/devices/harness-pro/firmware/main/app/pro_app.h
+++ b/devices/harness-pro/firmware/main/app/pro_app.h
@@ -39,7 +39,6 @@ void pro_app_button_hold(void);
void pro_app_notice(const char *text);
// Leave the Talk frame whose recording is over (pod_ui_talk_over), redrawing.
void pro_app_talk_over(void);
-bool pro_app_linked(void);
// Why a recording for this agent must not start (the copy is the screen's), or NULL when it may.
const char *pro_app_voice_block_reason(const char *agent_id);
// The agent has an unanswered question (pro_app_question and not yet closed or answered by a new turn).
@@ -57,5 +56,4 @@ bool pro_app_take_scene(ht_scene_t *scene); // draw the model into `scene` whe
// ---- host test seams ----
pod_ui_t *pro_app_test_pod(void);
bool pro_app_test_take_dirty(void); // the scene needs a redraw; clears the flag
-bool pro_app_test_take_force_frame(void); // the next awake frame must paint the whole glass; clears the flag
void pro_app_test_reset(void); // a fresh model; link down; nothing busy, open or requested
diff --git a/devices/harness-pro/firmware/main/app/pro_touch.c b/devices/harness-pro/firmware/main/app/pro_touch.c
index cd1c5d2e3..365535093 100644
--- a/devices/harness-pro/firmware/main/app/pro_touch.c
+++ b/devices/harness-pro/firmware/main/app/pro_touch.c
@@ -4,12 +4,12 @@
#include <stdatomic.h>
#include "app/pro_app.h"
+#include "task_stacks.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
-#define TOUCH_STACK 10240 // SRC's Pro stack: a tap runs Pod's gesture and (after the lock is released) a cable send
#define DEAD_AFTER 8 // failed reads in a row before the controller counts as dead in the log
static atomic_uint s_presses, s_failures, s_streak, s_last_press_ms;
@@ -68,7 +68,7 @@ static void touch_task(void *arg)
void pro_touch_start(void)
{
- BaseType_t ok = xTaskCreatePinnedToCore(touch_task, "pro_touch", TOUCH_STACK, NULL, 7, NULL, 1);
+ BaseType_t ok = xTaskCreatePinnedToCore(touch_task, "pro_touch", STACK_TOUCH, NULL, 7, NULL, 1);
assert(ok == pdPASS);
(void)ok;
}
diff --git a/devices/harness-pro/firmware/main/audio/audio_capture.c b/devices/harness-pro/firmware/main/audio/audio_capture.c
index 734038d3a..d54279c0c 100644
--- a/devices/harness-pro/firmware/main/audio/audio_capture.c
+++ b/devices/harness-pro/firmware/main/audio/audio_capture.c
@@ -7,6 +7,7 @@
#include "board/board_i2c.h"
#include "board_pins.h"
+#include "task_stacks.h"
#include "driver/i2s_std.h"
#include "esp_codec_dev.h"
#include "esp_codec_dev_defaults.h"
@@ -188,7 +189,7 @@ void audio_beep_init(void)
esp_codec_dev_cfg_t dev_cfg = { .dev_type = ESP_CODEC_DEV_TYPE_OUT, .codec_if = s_es8311, .data_if = s_data_if };
s_spk = esp_codec_dev_new(&dev_cfg);
if (!s_spk) { speaker_init_failed("device allocation"); return; }
- if (xTaskCreate(beep_task, "beep", 4096, NULL, 5, &s_beep_task) != pdPASS) {
+ if (xTaskCreate(beep_task, "beep", STACK_BEEP, NULL, 5, &s_beep_task) != pdPASS) {
s_beep_task = NULL;
speaker_init_failed("task allocation");
return;
diff --git a/devices/harness-pro/firmware/main/audio/pro_recorder.c b/devices/harness-pro/firmware/main/audio/pro_recorder.c
index 68e94d134..c02d697a7 100644
--- a/devices/harness-pro/firmware/main/audio/pro_recorder.c
+++ b/devices/harness-pro/firmware/main/audio/pro_recorder.c
@@ -18,12 +18,11 @@
#include "freertos/task.h"
#include "sys/config_store.h"
#include "sys/ram_telemetry.h"
+#include "task_stacks.h"
#define CAPTURE_SAMPLES 160 // 10 ms at 16 kHz
#define BUFFER_BYTES 32768 // the same ring as the round firmware: a power of two, in PSRAM
#define VOICE_CHUNK 1024 // one cable frame of PCM
-#define CAPTURE_STACK 5120 // as the round firmware
-#define SENDER_STACK 5120
static const char *TAG = "pro_rec";
static TaskHandle_t s_capture_task, s_sender_task;
@@ -155,8 +154,8 @@ bool pro_rec_init(void)
return false;
}
voice_buffer_init(&s_buffer, s_storage, BUFFER_BYTES);
- const BaseType_t a = xTaskCreatePinnedToCore(capture, "voice_capture", CAPTURE_STACK, NULL, 6, &s_capture_task, 0);
- const BaseType_t b = xTaskCreatePinnedToCore(sender, "voice_send", SENDER_STACK, NULL, 4, &s_sender_task, 0);
+ const BaseType_t a = xTaskCreatePinnedToCore(capture, "voice_capture", STACK_VOICE, NULL, 6, &s_capture_task, 0);
+ const BaseType_t b = xTaskCreatePinnedToCore(sender, "voice_send", STACK_VOICE, NULL, 4, &s_sender_task, 0);
if (a != pdPASS || b != pdPASS) {
if (s_capture_task) vTaskDelete(s_capture_task);
if (s_sender_task) vTaskDelete(s_sender_task);
diff --git a/devices/harness-pro/firmware/main/board/board.h b/devices/harness-pro/firmware/main/board/board.h
index 7953bcbf4..33b275325 100644
--- a/devices/harness-pro/firmware/main/board/board.h
+++ b/devices/harness-pro/firmware/main/board/board.h
@@ -24,10 +24,6 @@ const board_t *board(void);
// One line, for the boot log and the daemon.
const char *board_describe(void);
-// Was a factory reset asked for by holding a button through power-on? Never on the Pro: its only switch
-// is the one that turns the board on, so it is by definition held at this moment.
-bool board_factory_reset_requested(void);
-
// The module's Wi-Fi coprocessor (ESP32-C5) is unused: this firmware talks over the cable only. Drive its enable
// low so it stays in reset instead of running its own firmware.
void board_pro_hold_coprocessor(void);
diff --git a/devices/harness-pro/firmware/main/board/board_pro.c b/devices/harness-pro/firmware/main/board/board_pro.c
index e40299c05..bc5499d6f 100644
--- a/devices/harness-pro/firmware/main/board/board_pro.c
+++ b/devices/harness-pro/firmware/main/board/board_pro.c
@@ -41,13 +41,3 @@ const char *board_describe(void)
{
return "board=harness-pro touch=gt911 pmic=ip5306 lcd=st7703/720x720";
}
-
-/*
- * Never. There is no button this could read.
- *
- * The Pro's only switch is its power button, and pressing it is how the board got here — at the moment
- * app_main asks this question the button is, by construction, still down. Reading it would factory-reset
- * the device on every single power-on. A reset gesture for this board has to be something else (a touch
- * held through boot, say) and is not invented here.
- */
-bool board_factory_reset_requested(void) { return false; }
diff --git a/devices/harness-pro/firmware/main/board/power.h b/devices/harness-pro/firmware/main/board/power.h
index 1c556bb69..a81266178 100644
--- a/devices/harness-pro/firmware/main/board/power.h
+++ b/devices/harness-pro/firmware/main/board/power.h
@@ -10,14 +10,7 @@ void power_hold_init(void);
// Idempotent; safe to call from any task.
bool power_init(void);
-// Battery charge percent 0..100, or -1 if unknown (no driver/battery/read error).
-int power_battery_pct(void);
-
// True while the battery is actively charging (drives the charge bolt). False if unknown.
bool power_is_charging(void);
-// True while plugged into external power — actively charging OR full/standby. Use this (not
-// power_is_charging) to decide "on the charger", so a full battery still counts as plugged in.
-bool power_is_on_external(void);
-
diff --git a/devices/harness-pro/firmware/main/board/power_pro.c b/devices/harness-pro/firmware/main/board/power_pro.c
index 1c1663d69..d3f7ca757 100644
--- a/devices/harness-pro/firmware/main/board/power_pro.c
+++ b/devices/harness-pro/firmware/main/board/power_pro.c
@@ -36,6 +36,4 @@ bool power_init(void)
}
// No cell, charger polling or battery ADC allocation in the dock-only build.
-int power_battery_pct(void) { return -1; }
bool power_is_charging(void) { return false; }
-bool power_is_on_external(void) { return true; }
diff --git a/devices/harness-pro/firmware/main/board/ptt_pro.c b/devices/harness-pro/firmware/main/board/ptt_pro.c
index 02ee087ab..ba3937f5c 100644
--- a/devices/harness-pro/firmware/main/board/ptt_pro.c
+++ b/devices/harness-pro/firmware/main/board/ptt_pro.c
@@ -7,6 +7,7 @@
#include "board_pins.h"
#include "pro_button_filter.h"
+#include "task_stacks.h"
#include "driver/gpio.h"
#include "esp_log.h"
@@ -75,5 +76,5 @@ static void ptt_task(void *arg)
void ptt_start(void)
{
- xTaskCreate(ptt_task, "ptt", 4096, NULL, 5, NULL);
+ xTaskCreate(ptt_task, "ptt", STACK_PTT, NULL, 5, NULL);
}
diff --git a/devices/harness-pro/firmware/main/cable/cable_json_guard.h b/devices/harness-pro/firmware/main/cable/cable_json_guard.h
index 1b5cb0971..3232c49ee 100644
--- a/devices/harness-pro/firmware/main/cable/cable_json_guard.h
+++ b/devices/harness-pro/firmware/main/cable/cable_json_guard.h
@@ -9,7 +9,7 @@ enum { CABLE_JSON_MAX = CABLE_MAX_PAYLOAD + 1, CABLE_JSON_DEPTH = 12,
// Bound recursive JSON parsing before it reaches cJSON. The cable vocabulary
// uses at most a few object/array layers; the parser's default 1000-level limit
-// cannot fit the device's 6 KiB reader stack. No allocation or recursion here.
+// cannot fit the device's reader stack (STACK_CABLE_LINK). No allocation or recursion here.
// Lexical values/keys/containers also have a budget: a flat array must not
// spend the whole internal heap on cJSON nodes. No extra payload copy is needed.
// This checks framing/shape only; cJSON still validates the complete grammar.
diff --git a/devices/harness-pro/firmware/main/cable/cable_link.c b/devices/harness-pro/firmware/main/cable/cable_link.c
index ea26ec92c..985364529 100644
--- a/devices/harness-pro/firmware/main/cable/cable_link.c
+++ b/devices/harness-pro/firmware/main/cable/cable_link.c
@@ -9,6 +9,7 @@
#include "esp_log.h"
#include "esp_timer.h"
#include "last_words.h"
+#include "task_stacks.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
@@ -35,7 +36,7 @@ static const char *TAG = "cable";
//
// So the rule this file keeps: RX_BUF ≥ the largest number of bytes the peer may have in flight while
// this task is blocked. The firmware transfer is the only sender that can saturate the link, and its
-// credit window is 16 KB (docs/specs/cable-protocol.md, "Firmware update"). 32 KB is that window twice
+// credit window is 16 KB (docs/cable.md, "Firmware update"). 32 KB is that window twice
// over, for scheduling jitter. Changing either number without the other reintroduces exactly this bug.
#define USJ_RX_BUF (32 * 1024)
@@ -69,15 +70,11 @@ static const char *TAG = "cable";
// the screen.
#define LOG_WRITE_WAIT_MS 5
-// Reader task stack. The frame callback runs on this task, so it carries whatever the message layer
-// eventually does — JSON parsing, LVGL updates, and during a firmware install esp_ota_write() plus a
-// SHA-256 over the image read back out of flash.
-//
-// 12 KiB. The host proxy (test_pro_cable.c) measured the parser at 6.9 KB on Linux clang-18 with sanitizers, past
-// the old 6 KiB; ram_telemetry_periodic() reports this task's real high-water mark by name ("cable_link"), and
-// that is the figure to tune from. The failure this margin is against is real — the OTA path on this board's own
-// earlier firmware overflowed an 8 KiB stack and shipped devices that could not update themselves.
-#define READER_STACK 12288
+// Reader task stack: STACK_CABLE_LINK (task_stacks.h). The frame callback runs on this task, so it carries whatever
+// the message layer does — JSON parsing, Pod's feeds, and during a firmware install esp_ota_write() plus a SHA-256
+// over the image read back out of flash. The host proxy (test_pro_cable.c) measured the parser at 6.9 KB on Linux
+// clang-18 with sanitizers; the failure the margin is against is real — the OTA path on this board's own earlier
+// firmware overflowed an 8 KiB stack and shipped devices that could not update themselves.
// One log line's worth of formatted text. Anything longer is truncated rather than split: a log line is
// diagnostic, and half of one that arrives is worth more than a mechanism that could deadlock producing
@@ -89,6 +86,7 @@ static cable_frame_cb s_cb;
static cable_tick_cb s_tick;
static void *s_ctx;
static atomic_bool s_running;
+static atomic_uint s_rx_bytes, s_frames_ok; // written on the reader, read by the heartbeat
// Serialises the shared encode buffer AND the write, so two tasks sending at once cannot interleave
// halves of two frames onto the wire. A frame split down the middle by a second sender is not something
@@ -166,6 +164,13 @@ void cable_link_set_log_framing(bool on)
// ── link ────────────────────────────────────────────────────────────────────────────────────────────
+// Counts each decoded frame, then hands it on.
+static void count_frame(uint8_t version, uint8_t type, const uint8_t *payload, size_t payload_len, void *ctx)
+{
+ atomic_fetch_add_explicit(&s_frames_ok, 1, memory_order_relaxed);
+ s_cb(version, type, payload, payload_len, ctx);
+}
+
static void reader_task(void *arg)
{
(void)arg;
@@ -181,7 +186,8 @@ static void reader_task(void *arg)
// Never fails and never rejects: everything arriving here is untrusted, starts mid-stream after
// every boot, and the only useful response to a byte that makes no sense is to step over it.
if (n > 0) {
- cable_decoder_feed(&s_decoder, chunk, (size_t)n, s_cb, s_ctx);
+ atomic_fetch_add_explicit(&s_rx_bytes, (unsigned)n, memory_order_relaxed);
+ cable_decoder_feed(&s_decoder, chunk, (size_t)n, count_frame, s_ctx);
last_rx_us = now;
}
if (s_tick) s_tick(s_ctx);
@@ -221,7 +227,7 @@ bool cable_link_start(cable_frame_cb cb, cable_tick_cb tick, void *ctx)
// The new task may receive a welcome before xTaskCreate returns. Make the
// installed driver/send path visible before that callback can run.
s_running = true;
- if (xTaskCreate(reader_task, "cable_link", READER_STACK, NULL, 5, NULL) != pdPASS) {
+ if (xTaskCreate(reader_task, "cable_link", STACK_CABLE_LINK, NULL, 5, NULL) != pdPASS) {
s_running = false;
ESP_LOGE(TAG, "reader task create failed — no link to the daemon");
usb_serial_jtag_driver_uninstall();
@@ -285,7 +291,17 @@ void cable_link_counters(uint32_t *corrupt_frames, uint32_t *discarded_bytes)
if (discarded_bytes) *discarded_bytes = s_decoder.discarded_bytes;
}
-uint32_t cable_link_dropped_logs(void) { return atomic_load(&s_dropped_logs); }
+cable_link_stats_t cable_link_stats(void)
+{
+ // The decoder's two counters are plain words that only the reader writes; a 32-bit read is not torn.
+ return (cable_link_stats_t){
+ .rx_bytes = atomic_load_explicit(&s_rx_bytes, memory_order_relaxed),
+ .frames_ok = atomic_load_explicit(&s_frames_ok, memory_order_relaxed),
+ .corrupt_frames = s_decoder.corrupt_frames,
+ .discarded_bytes = s_decoder.discarded_bytes,
+ .dropped_logs = atomic_load_explicit(&s_dropped_logs, memory_order_relaxed),
+ };
+}
void cable_link_reset_decoder(void)
{
diff --git a/devices/harness-pro/firmware/main/cable/cable_link.h b/devices/harness-pro/firmware/main/cable/cable_link.h
index 94adbe163..9a4f321a2 100644
--- a/devices/harness-pro/firmware/main/cable/cable_link.h
+++ b/devices/harness-pro/firmware/main/cable/cable_link.h
@@ -36,7 +36,7 @@
//
// `cb` is invoked once per decoded frame, ON THE READER TASK, with the payload pointing into the
// decoder's own buffer — it is only valid for the duration of the call. Anything that must outlive it
-// gets copied by the callback. Anything that touches LVGL takes display_lock() first.
+// gets copied by the callback. Anything shared with the render task takes pro_app_lock() first.
//
// Returns false if the driver would not install, which leaves the dial running with no link rather than
// failing to boot: a device that shows "Not connected" is diagnosable from across the room, and a device
@@ -80,15 +80,22 @@ void cable_link_set_log_framing(bool on);
//
// It is therefore useful for exactly one thing: noticing that the cable left, or that the machine went
// to sleep. The layer above uses it as the end of a session. A session that ends because the DAEMON quit
-// with the cable still in is invisible here — see the hello cadence in cable_client.c for what stands in.
+// with the cable still in is invisible here — see the hello cadence in pro_cable.c for what stands in.
bool cable_link_host_present(void);
-// Framing health. The RATE is the diagnosis, not the totals: a handful of discarded bytes right after
-// boot is the bootloader's parting words and is expected, while a steady trickle during a session means
+// Framing health, cumulative since boot. The RATE is the diagnosis, not the totals: a handful of discarded bytes
+// right after boot is the bootloader's parting words and is expected, while a steady trickle during a session means
// the two sides disagree about the format or the cable is bad. Without a count those look identical.
+// Safe from any task; the reader owns the writes.
+typedef struct {
+ uint32_t rx_bytes; // bytes read off the port
+ uint32_t frames_ok; // frames decoded and delivered
+ uint32_t corrupt_frames; // a frame whose CRC or length failed
+ uint32_t discarded_bytes; // bytes stepped over between frames
+ uint32_t dropped_logs; // logs skipped because the transport was busy or stalled
+} cable_link_stats_t;
+cable_link_stats_t cable_link_stats(void);
void cable_link_counters(uint32_t *corrupt_frames, uint32_t *discarded_bytes);
-// Logs skipped because the transport was busy or stalled; diagnostic only.
-uint32_t cable_link_dropped_logs(void);
// Drop any half-received frame. For the layer above to call when it decides a session has ended and a
// new one begun — leftover bytes belong to the old one, and carrying them across puts a stale half-frame
diff --git a/devices/harness-pro/firmware/main/cable/pro_cable.c b/devices/harness-pro/firmware/main/cable/pro_cable.c
index 379980e46..2dc4e53d8 100644
--- a/devices/harness-pro/firmware/main/cable/pro_cable.c
+++ b/devices/harness-pro/firmware/main/cable/pro_cable.c
@@ -7,6 +7,7 @@
#include <string.h>
#include "board/board.h"
+#include "cJSON.h"
#include "cable_features.h"
#include "cable_frame.h"
#include "cable_json_guard.h"
@@ -27,6 +28,7 @@
#include "sys/device_mac.h"
#include "sys/fw_update.h"
#include "sys/last_words.h"
+#include "task_stacks.h"
static const char *TAG = "pro_cable";
@@ -40,7 +42,7 @@ static const char *TAG = "pro_cable";
#define SILENCE_MS 15000
#define NOTIF_ROWS 16 // notif.replace items kept (the daemon sends at most 8)
-// Everything below runs on the cable_link task (6 KB stack) unless the comment says otherwise. Parsing therefore
+// Everything below runs on the cable_link task (12 KB stack) unless the comment says otherwise. Parsing therefore
// goes into static scratch, never into a stack local over 1 KB (the host test caps every frame at 1024 B).
_Static_assert(POD_RECAP_BYTES == PRO_RECAP_BYTES, "the recap buffers of pro_cable and Pod must agree");
@@ -892,7 +894,7 @@ void pro_cable_on_frame(uint8_t version, uint8_t type, const uint8_t *payload, s
s_unknown++;
return;
}
- // Parse straight from the bounded frame; the guard caps depth and token count so cJSON fits the 6 KB stack.
+ // Parse straight from the bounded frame; the guard caps depth and token count so cJSON fits the cable_link stack.
if (!cable_json_guard(payload, payload_len)) { s_bad++; ESP_LOGW(TAG, "frame refused by the guard: %u B", (unsigned)payload_len); return; }
const char *end = NULL;
cJSON *root = cJSON_ParseWithLengthOpts((const char *)payload, payload_len, &end, false);
@@ -958,7 +960,7 @@ void pro_cable_start(void)
s_upload_lock = xSemaphoreCreateMutex();
if (!s_upload_lock) { ESP_LOGE(TAG, "no memory for the upload lock - link disabled"); return; }
s_last_rx_us = esp_timer_get_time();
- if (xTaskCreate(hello_task, "cable_hello", 4096, NULL, 4, &hello) != pdPASS) {
+ if (xTaskCreate(hello_task, "cable_hello", STACK_CABLE_HELLO, NULL, 4, &hello) != pdPASS) {
ESP_LOGE(TAG, "hello task create failed - no handshake");
return;
}
diff --git a/devices/harness-pro/firmware/main/cable/pro_cable.h b/devices/harness-pro/firmware/main/cable/pro_cable.h
index cf671db69..8a134cf38 100644
--- a/devices/harness-pro/firmware/main/cable/pro_cable.h
+++ b/devices/harness-pro/firmware/main/cable/pro_cable.h
@@ -5,8 +5,6 @@
#include <stddef.h>
#include <stdint.h>
-#include "cJSON.h"
-
// The second byte pair of the frame names the product; this names it again in the hello (cable_frame.h).
#define CABLE_PRODUCT "harness"
#define CABLE_PROTO_VERSION 3 // 3: + question.close (a question answered on another client)
@@ -41,7 +39,7 @@ bool pro_cable_library_supported(void); // welcome.features names player.librar
const char *pro_cable_fw_version(void);
// ---- seams ----
-// Host-test only (nothing on the device reads them): messages dropped as malformed / ignored as unknown.
+// Messages dropped as malformed / ignored as unknown, cumulative (the heartbeat prints them; the host tests read them).
void pro_cable_counters(uint32_t *bad, uint32_t *unknown);
// cable_link's callbacks (also what test_pro_cable.c feeds). on_frame runs on the cable_link task.
void pro_cable_on_frame(uint8_t version, uint8_t type, const uint8_t *payload, size_t payload_len, void *ctx);
diff --git a/devices/harness-pro/firmware/main/display/pro_canvas.c b/devices/harness-pro/firmware/main/display/pro_canvas.c
index cb3e73cb9..c4a372c73 100644
--- a/devices/harness-pro/firmware/main/display/pro_canvas.c
+++ b/devices/harness-pro/firmware/main/display/pro_canvas.c
@@ -143,66 +143,6 @@ bool ht_pro_text(ht_scene_t *s, int x, int y, int width, const ht_pro_font_t *fo
r->w = ink_width > 0 ? ink_width : 1;
return true;
}
-/* Return a bounded UTF-8 line and advance past one word-wrap boundary. */
-static void line(const char **cursor, const ht_pro_font_t *font, int width, char out[HT_TEXT_BYTES])
-{
- const char *begin = *cursor, *p, *last_space = NULL, *end;
- while (*begin == ' ') begin++;
- p = end = begin;
- int advance = 0, extent = 0;
- while (*p && *p != '\n') {
- const char *start = p;
- unsigned cp = code(font, ht_utf8_next(&p));
- const ht_pro_glyph_t *g = &font->glyphs[cp - font->first];
- int next_extent = max_(extent, advance + g->width);
- if (max_(next_extent, advance + g->advance) > width || p - begin >= HT_TEXT_BYTES) {
- p = start;
- if (last_space) p = last_space;
- break;
- }
- advance += g->advance; extent = next_extent; end = p;
- if (cp == ' ') last_space = start;
- }
- if (!*p || *p == '\n') end = p;
- else if (p > begin) end = p;
- if (end == begin && *p && *p != '\n') { ht_utf8_next(&p); end = p; }
- size_t bytes = (size_t)(end - begin);
- if (bytes >= HT_TEXT_BYTES) bytes = HT_TEXT_BYTES - 1;
- memcpy(out, begin, bytes); out[bytes] = 0;
- while (bytes && out[bytes-1] == ' ') out[--bytes] = 0;
- p = end;
- if (*p == '\n') p++; else while (*p == ' ') p++;
- *cursor = p;
-}
-int ht_pro_text_rows(const char *text, const ht_pro_font_t *font, int width)
-{
- if (!font || width <= 0 || !text || !*text) return 0;
- char visible[4096], row[HT_TEXT_BYTES];
- ht_display_text_ex(visible, sizeof visible, text, font);
- const char *p = visible; int count = 0;
- while (*p) { line(&p, font, width, row); count++; }
- return count;
-}
-int ht_pro_wrap(ht_scene_t *s, int x, int y, int width, int rows, int skip,
- const ht_pro_font_t *font, uint16_t ink, const char *text)
-{
- if (!font || width <= 0 || rows <= 0 || !text) return 0;
- char visible[4096], row[HT_TEXT_BYTES];
- ht_display_text_ex(visible, sizeof visible, text, font);
- const char *p = visible; int shown = 0;
- while (*p && skip-- > 0) line(&p, font, width, row);
- while (*p && shown < rows) {
- line(&p, font, width, row);
- ht_pro_text(s, x, y + shown * font->height, width, font, ink, row);
- shown++;
- }
- return shown;
-}
-void ht_pro_center(ht_scene_t *s, int y, const ht_pro_font_t *f, uint16_t ink, const char *text)
-{
- int width = min_(ht_pro_width(f, text), HT_WIDTH - 80);
- ht_pro_text(s, (HT_WIDTH-width)/2, y, width, f, ink, text);
-}
bool ht_pro_rect(ht_scene_t *s, int x, int y, int w, int h, int radius, uint16_t ink)
{
ht_run_t *r = run(s, PRO_RECT, x, y, w, h);
diff --git a/devices/harness-pro/firmware/main/display/pro_canvas.h b/devices/harness-pro/firmware/main/display/pro_canvas.h
index dfb9ede3f..99970dd2d 100644
--- a/devices/harness-pro/firmware/main/display/pro_canvas.h
+++ b/devices/harness-pro/firmware/main/display/pro_canvas.h
@@ -29,12 +29,8 @@ static inline bool ht_pro_can_draw(const ht_pro_font_t *f, uint32_t cp)
return ht_pro_extra_pos(f, cp) >= 0;
}
int ht_pro_width(const ht_pro_font_t *font, const char *text);
-int ht_pro_text_rows(const char *text, const ht_pro_font_t *font, int width);
bool ht_pro_text(ht_scene_t *s, int x, int y, int width, const ht_pro_font_t *font,
uint16_t ink, const char *text);
-int ht_pro_wrap(ht_scene_t *s, int x, int y, int width, int rows, int skip,
- const ht_pro_font_t *font, uint16_t ink, const char *text);
-void ht_pro_center(ht_scene_t *s, int y, const ht_pro_font_t *font, uint16_t ink, const char *text);
bool ht_pro_rect(ht_scene_t *s, int x, int y, int w, int h, int radius, uint16_t ink);
// Like ht_pro_rect, but each corner pixel is blended onto the colour under it by its coverage of the circle.
bool ht_pro_rect_aa(ht_scene_t *s, int x, int y, int w, int h, int radius, uint16_t ink);
diff --git a/devices/harness-pro/firmware/main/display/pro_panel_bus.c b/devices/harness-pro/firmware/main/display/pro_panel_bus.c
index d1f778d52..385706c88 100644
--- a/devices/harness-pro/firmware/main/display/pro_panel_bus.c
+++ b/devices/harness-pro/firmware/main/display/pro_panel_bus.c
@@ -21,7 +21,6 @@ static const char *TAG = "pro_panel_bus";
static esp_lcd_panel_io_handle_t s_io;
static esp_lcd_dsi_bus_handle_t s_bus;
static esp_ldo_channel_handle_t s_phy_pwr;
-static uint8_t s_level;
/*
* Backlight. An AP3032 boost drives the LED string and its feedback pin is what this PWM moves, so the
@@ -65,20 +64,10 @@ void pro_backlight_init(void)
void pro_backlight_set(uint8_t level)
{
- s_level = level;
ledc_set_duty(LEDC_LOW_SPEED_MODE, BL_CHANNEL, (uint32_t)BL_MAX_DUTY * level / 255u);
ledc_update_duty(LEDC_LOW_SPEED_MODE, BL_CHANNEL);
}
-uint8_t pro_backlight_level(void) { return s_level; }
-
-void pro_backlight_log(void)
-{
- ESP_LOGI(TAG, "backlight · BL_EN(GPIO%d)=%d · PWM GPIO%d · duty=%lu/%d · inverted",
- BSP_LCD_BL_EN, gpio_get_level(BSP_LCD_BL_EN), BSP_LCD_BL_PWM,
- (unsigned long)ledc_get_duty(LEDC_LOW_SPEED_MODE, BL_CHANNEL), BL_MAX_DUTY);
-}
-
void pro_backlight_enable(bool on)
{
gpio_set_level(BSP_LCD_BL_EN, on ? 1 : 0);
diff --git a/devices/harness-pro/firmware/main/display/pro_panel_bus.h b/devices/harness-pro/firmware/main/display/pro_panel_bus.h
index e2b36a9a2..039c240e7 100644
--- a/devices/harness-pro/firmware/main/display/pro_panel_bus.h
+++ b/devices/harness-pro/firmware/main/display/pro_panel_bus.h
@@ -28,11 +28,3 @@ void pro_backlight_set(uint8_t level);
// pixels: cutting the DSI stream instead would need a full re-init to come back from.
void pro_backlight_enable(bool on);
-// What the backlight is ACTUALLY being driven with, logged — so a brightness bug and a video bug can be
-// told apart from the log instead of by eye. This is why the enable pin is read back rather than
-// remembered: the two failures look identical on the glass.
-void pro_backlight_log(void);
-
-// What pro_backlight_set() was last given. The idle blank restores through this rather than reading the
-// duty back out and converting, which lost a step to integer division every time it blanked.
-uint8_t pro_backlight_level(void);
diff --git a/devices/harness-pro/firmware/main/display/scroll.c b/devices/harness-pro/firmware/main/display/scroll.c
index 98e0fb2eb..c2966de8f 100644
--- a/devices/harness-pro/firmware/main/display/scroll.c
+++ b/devices/harness-pro/firmware/main/display/scroll.c
@@ -1,5 +1,4 @@
#include "scroll.h"
-#include "terminal.h" // HT_WIDTH / HT_FACE_PX: a rim is a property of the face
#include <stdlib.h>
#define CLAIM_PX 24
@@ -7,51 +6,6 @@
#define REPORT_MS 16
#define MAX_SPEED 6000
-bool ht_scroll_on_rim(int x, int y)
-{
-#if HT_FACE_PX >= 720
- /*
- * A SQUARE HAS NO RIM, so nothing is ever on it.
- *
- * The annulus below is a 466 circle's: centred on (233,233) with radii 178..233. Left alone on a
- * 720 face it keeps that centre, so the band lands in the top-left quadrant and sweeps straight
- * across the screen — and a press that starts on the rim is cancelled by the app layer. The symptom is not a wrong scroll. It is taps over a third of
- * the screen doing nothing at all, which is precisely what the first Pro build did.
- *
- * Returning false here also makes bearing() and the rim_radius bookkeeping dead on this board:
- * they are only ever reached through a rim candidate.
- */
- (void)x; (void)y;
- return false;
-#else
- x -= 233; y -= 233;
- int r = x * x + y * y;
- return r >= 178 * 178 && r <= 233 * 233;
-#endif
-}
-// Monotonic octant approximation: 1024 units per turn, clockwise. No trig/FPU in touch.
-static int bearing(int x, int y)
-{
- x -= 233; y -= 233;
- int ax = abs(x), ay = abs(y);
- int angle = ax >= ay ? (ax ? 128 * ay / ax : 0) : 256 - 128 * ax / ay;
- if (x < 0) angle = 512 - angle;
- if (y < 0) angle = 1024 - angle;
- return angle & 1023;
-}
-
-uint32_t ht_scroll_coast_ms(int velocity)
-{
- unsigned speed = (unsigned)abs(velocity), duration = 0;
- if (speed > MAX_SPEED) speed = MAX_SPEED;
- // Rounded up, including a final frame; intentionally errs toward braking, never voice.
- while (speed >= 40) {
- speed = speed * 906 / 1000;
- duration += 16;
- }
- return duration ? duration + 32 : 0;
-}
-
static void measure(ht_scroll_t *g, int delta, uint32_t now)
{
uint32_t dt = now - g->at;
@@ -62,46 +16,18 @@ static void measure(ht_scroll_t *g, int delta, uint32_t now)
g->velocity = (3 * speed + 2 * g->velocity) / 5;
g->at = now;
}
-void ht_scroll_begin(ht_scroll_t *g, int x, int y, uint32_t now, bool reversed, bool rim_enabled,
+void ht_scroll_begin(ht_scroll_t *g, int x, int y, uint32_t now, bool reversed,
ht_scroll_emit_t emit, void *ctx)
{
ht_scroll_cancel(g);
*g = (ht_scroll_t){.sx = x, .sy = y, .y = y, .at = now,
.sign = reversed ? -1 : 1, .emit = emit, .ctx = ctx};
- g->rim_candidate = rim_enabled && ht_scroll_on_rim(x, y);
- g->rim_angle = bearing(x, y);
- g->rim_radius = (x - 233) * (x - 233) + (y - 233) * (y - 233);
// A touch stops the preceding fling immediately; movement waits for a direction claim.
g->live = emit(HT_SCROLL_DOWN, 0, 0, ctx);
}
void ht_scroll_move(ht_scroll_t *g, int x, int y, uint32_t now)
{
if (!g->live) return;
- if (g->rim_candidate) {
- int r = (x - 233) * (x - 233) + (y - 233) * (y - 233);
- int angle = bearing(x, y), delta = (angle - g->rim_angle + 1536) % 1024 - 512;
- if (r < 155 * 155 || r > 238 * 238 || abs(r - g->rim_radius) > 15000 || abs(delta) > 128) {
- ht_scroll_cancel(g); // a radial stroke or bad sample cannot become a pane swipe
- return;
- }
- g->rim_angle = angle;
- if (!g->axis) g->rim_travel += delta;
- g->rim_remainder -= delta * 600; // clockwise reads further down; 600 glass px/turn
- g->pending += g->rim_remainder / 1024;
- g->rim_remainder %= 1024;
- if (abs(g->pending) > 2048) {
- ht_scroll_cancel(g); // bounded backpressure; never emit an unbounded desktop jump
- return;
- }
- if (!g->axis && abs(g->rim_travel) >= 48) g->axis = 3;
- if (g->axis == 3 && (abs(g->pending) >= REPORT_PX || now - g->at >= REPORT_MS)) {
- if (!g->pending || g->emit(HT_SCROLL_MOVE, g->sign * g->pending, 0, g->ctx)) {
- g->pending = 0;
- g->at = now;
- }
- }
- return;
- }
if (!g->axis) {
int dx = abs(x - g->sx), dy = abs(y - g->sy);
if (dx >= CLAIM_PX && dx * 4 > dy * 5) g->axis = 2;
@@ -121,16 +47,15 @@ void ht_scroll_move(ht_scroll_t *g, int x, int y, uint32_t now)
}
bool ht_scroll_end(ht_scroll_t *g, int x, int y, uint32_t now)
{
- if (!g->live) return g->rim_candidate;
+ if (!g->live) return false;
ht_scroll_move(g, x, y, now);
- if (!g->live) return g->rim_candidate;
- bool claimed = g->axis == 1 || g->axis == 3;
+ if (!g->live) return false;
+ bool claimed = g->axis == 1;
if (claimed) measure(g, g->pending, now);
- if (g->rim_candidate) g->velocity = 0; // a wheel stops under the finger, without a fling
g->emit(HT_SCROLL_UP, claimed ? g->sign * g->pending : 0,
claimed ? g->sign * g->velocity : 0, g->ctx);
g->live = false;
- return claimed || g->rim_candidate;
+ return claimed;
}
void ht_scroll_cancel(ht_scroll_t *g)
{
diff --git a/devices/harness-pro/firmware/main/display/scroll.h b/devices/harness-pro/firmware/main/display/scroll.h
index 03828a2da..4ab10a35a 100644
--- a/devices/harness-pro/firmware/main/display/scroll.h
+++ b/devices/harness-pro/firmware/main/display/scroll.h
@@ -7,19 +7,15 @@ typedef enum { HT_SCROLL_DOWN, HT_SCROLL_MOVE, HT_SCROLL_UP } ht_scroll_phase_t;
typedef bool (*ht_scroll_emit_t)(ht_scroll_phase_t phase, int dy, int velocity, void *ctx);
typedef struct {
int sx, sy, y, pending, velocity, sign;
- int rim_angle, rim_travel, rim_remainder, rim_radius;
uint32_t at;
- unsigned axis; // 0 undecided, 1 vertical, 2 horizontal, 3 circular
- bool live, rim_candidate;
+ unsigned axis; // 0 undecided, 1 vertical, 2 horizontal
+ bool live;
ht_scroll_emit_t emit;
void *ctx;
} ht_scroll_t;
-void ht_scroll_begin(ht_scroll_t *g, int x, int y, uint32_t now, bool reversed, bool rim_enabled,
+void ht_scroll_begin(ht_scroll_t *g, int x, int y, uint32_t now, bool reversed,
ht_scroll_emit_t emit, void *ctx);
void ht_scroll_move(ht_scroll_t *g, int x, int y, uint32_t now);
// True means vertical travel owns the gesture, even if it ended back at its starting point.
bool ht_scroll_end(ht_scroll_t *g, int x, int y, uint32_t now);
void ht_scroll_cancel(ht_scroll_t *g);
-// Conservative tap-to-brake window for the desktop's 0.002/second decay and 40px/s stop.
-uint32_t ht_scroll_coast_ms(int velocity);
-bool ht_scroll_on_rim(int x, int y);
diff --git a/devices/harness-pro/firmware/main/display/terminal.c b/devices/harness-pro/firmware/main/display/terminal.c
index 6cff0dafe..ede157447 100644
--- a/devices/harness-pro/firmware/main/display/terminal.c
+++ b/devices/harness-pro/firmware/main/display/terminal.c
@@ -90,7 +90,8 @@ static const char *display_fallback(uint32_t cp, char scratch[12])
}
// An explicit, lossless identifier is preferable to inventing a meaning or
// showing '?' (which could be part of the author's actual message).
- snprintf(scratch, 12, "[U+%04lX]", (unsigned long)cp);
+ // Unicode tops out at U+10FFFF (6 hex digits), which fits; the mask lets GCC see that too (-Wformat-truncation).
+ snprintf(scratch, 12, "[U+%04lX]", (unsigned long)(cp & 0x1FFFFF));
return scratch;
}
typedef struct {
diff --git a/devices/harness-pro/firmware/main/pod/pod_model.c b/devices/harness-pro/firmware/main/pod/pod_model.c
index a21e35c42..2711c698e 100644
--- a/devices/harness-pro/firmware/main/pod/pod_model.c
+++ b/devices/harness-pro/firmware/main/pod/pod_model.c
@@ -132,7 +132,7 @@ static int make_room(pod_model_t *m, const rank_t *newcomer) {
}
// ── change detection ─────────────────────────────────────────────────────────────────────────────────
-// These feeds run on the cable_link task (6 KB stack): a pod_agent_t is ~2.7 KB (recap[]), so a feed must not
+// These feeds run on the cable_link task (12 KB stack, the parser takes ~7 of it): a pod_agent_t is ~2.7 KB (recap[]), so a feed must not
// hold a copy of one to see whether it changed anything. It takes a 64-bit FNV-1a signature of the agent's
// visible fields before and after instead. Left out: seen, lib_seen, src and age_s (sweep bookkeeping that is
// never a visible change); event_ms only when `with_event` is false (a fresh stamp alone is not one).
@@ -360,8 +360,8 @@ void pod_model_swarms(pod_model_t *m, const cable_swarm_t *items, const char *co
void pod_model_swarms_meta(pod_model_t *m, const cable_swarm_t *items, const char *const *agent_ids[],
const uint8_t agent_id_counts[], int n, const char *selected,
const cable_tile_t *tiles, int tile_count, const pod_member_meta_t (*meta)[POD_PANES_MAX]) {
- // ~9.7 KB: far over the cable_link task's 6 KB stack, so it is file-static. Every model feed is single-writer
- // (the cable task, under display_lock), so one scratch is never used by two callers at once.
+ // ~9.7 KB: far over the cable_link task's 12 KB stack, so it is file-static. Every model feed is single-writer
+ // (the cable task, under pro_app_lock), so one scratch is never used by two callers at once.
static EXT_RAM_BSS_ATTR pod_tab_t nt[POD_TABS_MAX];
memset(nt, 0, sizeof nt);
if (n < 0 || !items) n = 0;
diff --git a/devices/harness-pro/firmware/main/pod/pod_pet.c b/devices/harness-pro/firmware/main/pod/pod_pet.c
index 25cea89b6..bedea6a7a 100644
--- a/devices/harness-pro/firmware/main/pod/pod_pet.c
+++ b/devices/harness-pro/firmware/main/pod/pod_pet.c
@@ -347,15 +347,6 @@ bool pod_logo_draw_faded(ht_scene_t *s, int x, int y, int size, const char *engi
}
bool pod_logo_draw(ht_scene_t *s, int x, int y, int size, const char *engine) { return pod_logo_draw_faded(s, x, y, size, engine, 255); }
-void pod_mark_default(ht_scene_t *s, int x, int y, uint16_t ground)
-{
- const int side = POD_DEFAULT_MARK_SIDE;
- ht_pro_rect(s, x, y, side, side, 7, ht_rgb(0x9aa09a));
- ht_pro_rect(s, x + 2, y + 2, side - 4, side - 4, 5, ground);
- int w = ht_pro_width(&ht_pro_24, ">_");
- ht_pro_text(s, x + (side - w) / 2, y + (side - ht_pro_24.height) / 2 - 2, w, &ht_pro_24, ht_rgb(0x6f746f), ">_");
-}
-
// The default mark at any size: the outline box, its inside and ">_" in the largest font that fits.
void pod_mark_default_big(ht_scene_t *s, int x, int y, int size, uint16_t ground)
{
diff --git a/devices/harness-pro/firmware/main/pod/pod_pet.h b/devices/harness-pro/firmware/main/pod/pod_pet.h
index 877bcac4d..46d90e7e4 100644
--- a/devices/harness-pro/firmware/main/pod/pod_pet.h
+++ b/devices/harness-pro/firmware/main/pod/pod_pet.h
@@ -57,9 +57,8 @@ int pod_logo_cover_size(int side);
// logo; nothing is added then. The chip draws POD_LOGO_CHIP; covers draw pod_logo_cover_size(side).
bool pod_logo_draw(ht_scene_t *s, int x, int y, int size, const char *engine);
bool pod_logo_draw_faded(ht_scene_t *s, int x, int y, int size, const char *engine, unsigned opacity); // 1..254 of 255
-// The mark for an engine that has none (an unknown engine, an agent the roster has not named): a 34 x 34 rounded
-// outline square with ">_" in it (ht_pro_24 does not fit a 27 px one), on `ground` inside; it fits the 36 px chip slot.
+// The mark for an engine that has none (an unknown engine, an agent the roster has not named): a rounded outline
+// square with ">_" in it, on `ground` inside; at the 34 px minimum it fits the 36 px chip slot.
// POD_DEFAULT_MARK_RUNS runs.
enum { POD_DEFAULT_MARK_RUNS = 3, POD_DEFAULT_MARK_SIDE = 34 };
-void pod_mark_default(ht_scene_t *s, int x, int y, uint16_t ground);
void pod_mark_default_big(ht_scene_t *s, int x, int y, int size, uint16_t ground); // the same at any size (the update screen's)
diff --git a/devices/harness-pro/firmware/main/pro_app_api.h b/devices/harness-pro/firmware/main/pro_app_api.h
index 4869c79bf..869e82550 100644
--- a/devices/harness-pro/firmware/main/pro_app_api.h
+++ b/devices/harness-pro/firmware/main/pro_app_api.h
@@ -1,7 +1,7 @@
// What pro_cable tells the app. pro_cable parses the daemon's messages and calls these; pro_app (Task 6) implements
// them, and test_pro_cable.c stubs them with a recorder.
//
-// EVERY CALL RUNS ON THE cable_link TASK (6 KB stack). A pointer argument is valid only until the call returns:
+// EVERY CALL RUNS ON THE cable_link TASK (STACK_CABLE_LINK, 12 KB). A pointer argument is valid only until the call returns:
// copy what must outlive it. A NULL string means "the daemon did not send that field" (an older daemon sends
// less); "" means it sent an empty one. None of these is ever called with a string longer than its stated cap, and
// every cut is on a UTF-8 boundary.
diff --git a/devices/harness-pro/firmware/main/sys/config_store.c b/devices/harness-pro/firmware/main/sys/config_store.c
index f2015b814..e515b45bd 100644
--- a/devices/harness-pro/firmware/main/sys/config_store.c
+++ b/devices/harness-pro/firmware/main/sys/config_store.c
@@ -1,87 +1,12 @@
#include "config_store.h"
-#include <stdlib.h>
#include <string.h>
#include "nvs_flash.h"
#include "nvs.h"
#include "esp_log.h"
-#include "esp_random.h"
-#include "mbedtls/sha256.h"
static const char *TAG = "config";
static const char *NS = "pair";
-static void read_str(nvs_handle_t h, const char *key, char *dst, size_t cap); // defined below
-
-// SHA-256(salt_hex || pattern) → 64-char lowercase hex. salt_hex is the stored per-device salt.
-static void lock_hash(const char *salt_hex, const char *pattern, char out_hex[65])
-{
- mbedtls_sha256_context ctx;
- mbedtls_sha256_init(&ctx);
- mbedtls_sha256_starts(&ctx, 0); // 0 = SHA-256
- mbedtls_sha256_update(&ctx, (const unsigned char *)salt_hex, strlen(salt_hex));
- mbedtls_sha256_update(&ctx, (const unsigned char *)pattern, strlen(pattern));
- uint8_t digest[32] = { 0 };
- mbedtls_sha256_finish(&ctx, digest);
- mbedtls_sha256_free(&ctx);
- for (int i = 0; i < 32; i++) snprintf(out_hex + i * 2, 3, "%02x", digest[i]);
-}
-
-void config_set_lock(const char *pattern)
-{
- if (!pattern || !pattern[0]) return;
- uint8_t salt[8];
- esp_fill_random(salt, sizeof(salt));
- char salt_hex[17];
- for (int i = 0; i < 8; i++) snprintf(salt_hex + i * 2, 3, "%02x", salt[i]);
- char hex[65];
- lock_hash(salt_hex, pattern, hex);
- nvs_handle_t h;
- if (nvs_open(NS, NVS_READWRITE, &h) != ESP_OK) return;
- nvs_set_str(h, "lock_salt", salt_hex);
- nvs_set_str(h, "lock_hash", hex);
- nvs_set_u8(h, "lock_on", 1);
- nvs_commit(h);
- nvs_close(h);
- ESP_LOGI(TAG, "lock set");
-}
-
-bool config_lock_enabled(void)
-{
- nvs_handle_t h;
- if (nvs_open(NS, NVS_READONLY, &h) != ESP_OK) return false;
- uint8_t on = 0;
- if (nvs_get_u8(h, "lock_on", &on) != ESP_OK) on = 0;
- nvs_close(h);
- return on == 1;
-}
-
-bool config_check_lock(const char *pattern)
-{
- if (!pattern || !pattern[0]) return false;
- nvs_handle_t h;
- if (nvs_open(NS, NVS_READONLY, &h) != ESP_OK) return false;
- char salt_hex[33] = "", want[80] = "";
- read_str(h, "lock_salt", salt_hex, sizeof(salt_hex));
- read_str(h, "lock_hash", want, sizeof(want));
- nvs_close(h);
- if (!salt_hex[0] || !want[0]) return false;
- char hex[65];
- lock_hash(salt_hex, pattern, hex);
- return strcasecmp(hex, want) == 0;
-}
-
-void config_clear_lock(void)
-{
- nvs_handle_t h;
- if (nvs_open(NS, NVS_READWRITE, &h) != ESP_OK) return;
- nvs_erase_key(h, "lock_salt");
- nvs_erase_key(h, "lock_hash");
- nvs_set_u8(h, "lock_on", 0);
- nvs_commit(h);
- nvs_close(h);
- ESP_LOGI(TAG, "lock cleared");
-}
-
void config_store_init(void)
{
esp_err_t err = nvs_flash_init();
@@ -160,14 +85,3 @@ bool config_save_muted(bool muted)
ESP_LOGI(TAG, "save_muted %d: %s", (int)muted, ok ? "ok" : "FAILED");
return ok;
}
-
-bool config_clear_all(void)
-{
- nvs_handle_t h;
- if (nvs_open(NS, NVS_READWRITE, &h) != ESP_OK) return false;
- nvs_erase_all(h);
- bool ok = nvs_commit(h) == ESP_OK;
- nvs_close(h);
- ESP_LOGW(TAG, "clear_all: %s", ok ? "ok" : "FAILED");
- return ok;
-}
diff --git a/devices/harness-pro/firmware/main/sys/config_store.h b/devices/harness-pro/firmware/main/sys/config_store.h
index 34d97a24f..096363ab7 100644
--- a/devices/harness-pro/firmware/main/sys/config_store.h
+++ b/devices/harness-pro/firmware/main/sys/config_store.h
@@ -1,6 +1,6 @@
// The device's own settings, in NVS.
//
-// Local display, sound, gesture, voice-language and screen-lock preferences. Everything this file
+// Local display, sound and voice-language preferences. Everything this file
// used to hold — the WiFi networks, the backend URL, the device
// token, the SDS provisioning blob, the E2EE identity and its pinned peers, the last-selected machine —
// existed so the device could find a network and prove who it was to a backend. A cable answers both, and
@@ -31,12 +31,3 @@ void config_load_voicelang(char *out, size_t cap);
// Pro uses the same en/vi choice for its built-in interface. False means the
// preference was not durably saved; leave a retry available in the picker.
bool config_save_voicelang(const char *lang);
-
-// Screen lock: a 3x3 pattern, stored as a short digit string.
-bool config_lock_enabled(void);
-bool config_check_lock(const char *pattern);
-void config_set_lock(const char *pattern);
-void config_clear_lock(void);
-
-// Factory reset: forget all of the above.
-bool config_clear_all(void);
diff --git a/devices/harness-pro/firmware/main/sys/fw_update.c b/devices/harness-pro/firmware/main/sys/fw_update.c
index 6dd314ad6..a6173c776 100644
--- a/devices/harness-pro/firmware/main/sys/fw_update.c
+++ b/devices/harness-pro/firmware/main/sys/fw_update.c
@@ -18,7 +18,7 @@
static const char *TAG = "fw";
-// Read-back buffer for the hash. Small and static on purpose: this runs on the cable task (6 KB stack, whose
+// Read-back buffer for the hash. Small and static on purpose: this runs on the cable task (12 KB stack, whose
// frames are capped at compile time), which also carries esp_ota_write().
#define VERIFY_CHUNK 1024
// No slice for this long ends the transfer. The daemon's keepalives prove the host is alive, not that an
diff --git a/devices/harness-pro/firmware/main/sys/ram_telemetry.c b/devices/harness-pro/firmware/main/sys/ram_telemetry.c
index 672b00d52..d09e842f8 100644
--- a/devices/harness-pro/firmware/main/sys/ram_telemetry.c
+++ b/devices/harness-pro/firmware/main/sys/ram_telemetry.c
@@ -64,33 +64,6 @@ void *ram_psram_alloc(size_t bytes, const char *owner)
return ptr;
}
-void *ram_psram_calloc(size_t count, size_t size, const char *owner)
-{
- if (count && size > SIZE_MAX / count) {
- note_psram_failure(owner, SIZE_MAX);
- return NULL;
- }
- void *ptr = heap_caps_calloc(count, size, APP_PSRAM_CAPS);
- if (!ptr && count && size) note_psram_failure(owner, count * size);
- return ptr;
-}
-
-void *ram_psram_realloc(void *ptr, size_t bytes, const char *owner)
-{
- void *next = heap_caps_realloc(ptr, bytes, APP_PSRAM_CAPS);
- if (!next && bytes) note_psram_failure(owner, bytes);
- return next;
-}
-
-char *ram_psram_strdup(const char *src, const char *owner)
-{
- if (!src) return NULL;
- size_t bytes = strlen(src) + 1;
- char *dst = ram_psram_alloc(bytes, owner);
- if (dst) memcpy(dst, src, bytes);
- return dst;
-}
-
static void log_task_stack(const char *name)
{
TaskHandle_t task = xTaskGetHandle(name);
diff --git a/devices/harness-pro/firmware/main/sys/ram_telemetry.h b/devices/harness-pro/firmware/main/sys/ram_telemetry.h
index be435155b..ba97e8298 100644
--- a/devices/harness-pro/firmware/main/sys/ram_telemetry.h
+++ b/devices/harness-pro/firmware/main/sys/ram_telemetry.h
@@ -14,9 +14,6 @@ void ram_telemetry_checkpoint(const char *tag);
// stack high-water marks.
void ram_telemetry_periodic(const char *tag);
-// PSRAM-only application allocations. They never silently consume internal RAM
-// and record failures in the telemetry counters.
+// A PSRAM-only application allocation. It never silently consumes internal RAM
+// and records a failure in the telemetry counters.
void *ram_psram_alloc(size_t bytes, const char *owner);
-void *ram_psram_calloc(size_t count, size_t size, const char *owner);
-void *ram_psram_realloc(void *ptr, size_t bytes, const char *owner);
-char *ram_psram_strdup(const char *src, const char *owner);
diff --git a/devices/harness-pro/firmware/main/task_stacks.h b/devices/harness-pro/firmware/main/task_stacks.h
new file mode 100644
index 000000000..99afdda75
--- /dev/null
+++ b/devices/harness-pro/firmware/main/task_stacks.h
@@ -0,0 +1,11 @@
+// Task stack sizes, in bytes, in one place. Comments elsewhere name the task, not the number.
+// ram_telemetry_periodic() reports each task's real high-water mark by name: tune from that.
+#pragma once
+
+#define STACK_CABLE_LINK 12288 // cable_link reader: also runs pro_cable's parser, Pod's feeds and the OTA write (host proxy: 6.9 KB parser)
+#define STACK_RENDER 24576 // pro_render: the ROM inflater and the 24-row strips want room
+#define STACK_TOUCH 10240 // pro_touch: a tap runs Pod's gesture and (after the lock is released) a cable send
+#define STACK_CABLE_HELLO 4096
+#define STACK_BEEP 4096
+#define STACK_PTT 4096
+#define STACK_VOICE 5120 // voice_capture and voice_send
diff --git a/devices/harness-pro/firmware/scripts/gen_fonts.py b/devices/harness-pro/firmware/scripts/gen_fonts.py
index 280d2a930..390e293fc 100644
--- a/devices/harness-pro/firmware/scripts/gen_fonts.py
+++ b/devices/harness-pro/firmware/scripts/gen_fonts.py
@@ -5,7 +5,7 @@
Emits ht_pro_24, ht_pro_32, ht_pro_42 and ht_pro_56 (ht_pro_font_t, see main/display/pro_font_type.h).
The default font is the system sans on macOS when present, else the bundled Liberation Sans.
-Also emits the Pets faces (ph_sb_*, ph_md_*, ph_rg_*, ph_mono_*) from the committed Inter / JetBrains Mono TTFs in
+Also emits the Pets faces (ph_sb_*, ph_rg_*, ph_mono_*, ph_num_*, ph_bd_*) from the committed Inter / JetBrains Mono TTFs in
fonts/, whatever --font says: full coverage, plus the CONSOLE_EXTRA marks appended after the Vietnamese entries.
The output is a build artifact; it is generated at build time and never committed.
"""
@@ -19,9 +19,10 @@ ROOT = Path(__file__).resolve().parents[1]
SYSTEM_FONT = Path('/System/Library/Fonts/Helvetica.ttc')
BUNDLED_FONT = ROOT / 'fonts' / 'LiberationSans-Regular.ttf'
SIZES = (24, 32, 42, 56)
-# Pod draws only these characters at the two big sizes (test_only_sparse_chars_drawn guards it), so only they
+# Pod draws only these characters at the big sizes (test_only_sparse_chars_drawn guards it), so only they
# get masks. Every other glyph keeps its metrics and points at a shared run of zeros (draws nothing).
-SPARSE = {42: "#>_?", 56: "#>_?"}
+# 32 is only ever the ">_" of the default engine mark (pod_mark_default_big).
+SPARSE = {32: ">_", 42: "#>_?", 56: "#>_?"}
# The 90 Vietnamese precomposed letters, then the 12 letters outside that block.
# Keep in sync with ht_pro_vietnamese_index().
VIETNAMESE = list(range(0x1ea0, 0x1efa)) + [0x102, 0x103, 0x110, 0x111, 0x128, 0x129,
diff --git a/devices/harness-pro/firmware/test/golden.sh b/devices/harness-pro/firmware/test/golden.sh
index ef13132c8..027c8b38f 100644
--- a/devices/harness-pro/firmware/test/golden.sh
+++ b/devices/harness-pro/firmware/test/golden.sh
@@ -26,8 +26,8 @@ if [[ -n "${PRO_FONT:-}" ]]; then
case "$PRO_FONT" in /*) ;; *) PRO_FONT="$fw/$PRO_FONT" ;; esac
font_args=(--font "$PRO_FONT")
fi
-/usr/local/bin/python3 "$fw/scripts/gen_fonts.py" ${font_args[@]+"${font_args[@]}"} --out "$out/pro_fonts.c"
-cc -std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Werror -O1 -g -DHT_FACE_PX=720 -I"$disp" -I"$fw/main" -I"$here/host_stubs" \
+python3 "$fw/scripts/gen_fonts.py" ${font_args[@]+"${font_args[@]}"} --out "$out/pro_fonts.c"
+cc -std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Werror -O1 -g -DHT_FACE_PX=720 -I"$disp" -I"$fw/main" \
-o "$out/pod_render" "$here/pod_render.c" "$fw"/main/pod/*.c "$fw"/main/pod/home/*.c "$disp/pro_canvas.c" "$disp/terminal.c" "$out/pro_fonts.c"
screens=(tabs tabs:bell tabs:mock tabs:0+2 tabs:2+2 tabs:long tabs:9 tabs:linkdown tabs:1 tabs:3 tabs:5 tabs:seven tabs:single tabs:notices tabs:none
diff --git a/devices/harness-pro/firmware/test/host_stubs/cJSON.h b/devices/harness-pro/firmware/test/host_stubs/cJSON.h
deleted file mode 100644
index 1a2c1dfea..000000000
--- a/devices/harness-pro/firmware/test/host_stubs/cJSON.h
+++ /dev/null
@@ -1,4 +0,0 @@
-// Host-test stand-in for ESP-IDF's cJSON.h: cable_client.h includes it, but the pure Pod model only
-// needs the cable_swarm_t / cable_tile_t shapes, never a cJSON call.
-#pragma once
-typedef struct cJSON cJSON;
diff --git a/devices/harness-pro/firmware/test/pod_pet_ground.c b/devices/harness-pro/firmware/test/pod_pet_ground.c
index ec910af71..4fd9e5925 100644
--- a/devices/harness-pro/firmware/test/pod_pet_ground.c
+++ b/devices/harness-pro/firmware/test/pod_pet_ground.c
@@ -1,7 +1,7 @@
// Dev helper (not run by run.sh): rasters every scene of every pet (ht_pets and Codex) over a strongly coloured ground and reports
// opaque near-white pixels connected (4-way) to the outside of the art -- background baked into the frames.
// Also scans the source frames: near-white palette cells reachable from a frame's transparent border.
-// cc -std=c11 -O1 -DHT_FACE_PX=720 -I $h -I main -I test/host_stubs \
+// cc -std=c11 -O1 -DHT_FACE_PX=720 -I $h -I main \
// -o out test/pod_pet_ground.c $p/{engine_logos,pets,pod_draw,pod_pet}.c $h/{pro_canvas,terminal}.c $g
// out <ground-rgb-hex> <dir> writes <dir>/pet-ground-<engine>.ppm (convert to PNG separately)
#include <stdio.h>
diff --git a/devices/harness-pro/firmware/test/pod_pet_strip.c b/devices/harness-pro/firmware/test/pod_pet_strip.c
index 41577229a..69d070c43 100644
--- a/devices/harness-pro/firmware/test/pod_pet_strip.c
+++ b/devices/harness-pro/firmware/test/pod_pet_strip.c
@@ -1,7 +1,7 @@
// Dev helper (not run by run.sh): rasters each scene of claude, codex and muse at 4 clock points to a PPM.
// Build and run from devices/harness-pro/firmware, with fonts from scripts/gen_fonts.py --out $g:
// h=main/display; p=main/pod; g=/tmp/pro_fonts.c
-// cc -std=c11 -O1 -DHT_FACE_PX=720 -I $h -I main -I test/host_stubs \
+// cc -std=c11 -O1 -DHT_FACE_PX=720 -I $h -I main \
// -o /tmp/claude-503/pod_pet_strip test/pod_pet_strip.c $p/{engine_logos,pets,pod_draw,pod_pet}.c \
// $h/{pro_canvas,terminal}.c $g
// /tmp/claude-503/pod_pet_strip /tmp/claude-503/pod_pets.ppm
diff --git a/devices/harness-pro/firmware/test/pod_render.py b/devices/harness-pro/firmware/test/pod_render.py
index 319e7b699..68f68420b 100644
--- a/devices/harness-pro/firmware/test/pod_render.py
+++ b/devices/harness-pro/firmware/test/pod_render.py
@@ -53,7 +53,7 @@ def main() -> int:
exe = out / "pod_render"
cmd = ["cc", "-std=c11", "-D_DEFAULT_SOURCE", "-Wall", "-Wextra", "-Werror", "-O1", "-g",
"-DHT_FACE_PX=720",
- f"-I{disp}", f"-I{fw / 'main'}", f"-I{here / 'host_stubs'}",
+ f"-I{disp}", f"-I{fw / 'main'}",
"-o", str(exe), str(here / "pod_render.c"), *sorted(str(p) for p in (fw / "main" / "pod").glob("**/*.c")),
str(disp / "pro_canvas.c"), str(disp / "terminal.c"), str(fonts)]
subprocess.run(cmd, check=True)
diff --git a/devices/harness-pro/firmware/test/run.sh b/devices/harness-pro/firmware/test/run.sh
index 0560875d7..cae11d0f5 100755
--- a/devices/harness-pro/firmware/test/run.sh
+++ b/devices/harness-pro/firmware/test/run.sh
@@ -2,7 +2,6 @@
# Host tests for the Harness Pro firmware's pure C (main/pod and the compositor in main/display).
# Needs no arguments and no board. Fonts are generated into a temp directory: set PRO_FONT=/path/to/font.ttf
# to override the generator's default (macOS Helvetica when present, else the bundled Liberation Sans).
-# host_stubs/ stands in for ESP-IDF headers the model includes but never calls.
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fw="$(cd "$here/.." && pwd)"
@@ -25,12 +24,13 @@ python3 "$fw/scripts/gen_pro_ask.py" --check # the asking look: the "?" bubble
python3 "$here/test_pro_ask.py"
python3 "$here/codex_size.py" # Codex's on-screen size against the pre-change baseline
-# Stack guard. Pod's model, nav and glue run on the cable_link task (6 KB stack, under display_lock); the render
-# task (24 KB) draws. A frame over the limit overflows the small stack on the device ("Stack protection fault"),
-# so every function frame is capped at compile time: -Wframe-larger-than with -Werror fails the suite.
+# Stack guard. Pod's model, nav and glue run on the cable_link task (STACK_CABLE_LINK, 12 KB, under pro_app_lock); the
+# render task (24 KB) draws. A frame over the limit overflows the stack on the device ("Stack protection fault"), so
+# every function frame is capped at compile time: -Wframe-larger-than with -Werror fails the suite. The caps (1 KB for
+# the cable task's code) predate the 12 KB stack and are kept: a tighter cap than the stack needs is only margin.
# -D_DEFAULT_SOURCE: glibc hides POSIX calls (strnlen, strcasecmp) under a strict -std=c11; newlib and macOS do not.
cflags=(-std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Werror -O1 -g -fsanitize="${SANITIZERS:-undefined,bounds}"
- -DHT_FACE_PX=720 -I"$disp" -I"$fw/main" -I"$here/host_stubs")
+ -DHT_FACE_PX=720 -I"$disp" -I"$fw/main")
objs=()
build_obj() { # build_obj <limit-bytes> <source>...
local limit="$1"; shift
@@ -42,7 +42,7 @@ build_obj() { # build_obj <limit-bytes> <source>...
done
}
cable_task=("$pod/pod_model.c" "$pod/pod_nav.c")
-[[ -f "$fw/main/app/pod_glue.c" ]] && cable_task+=("$fw/main/app/pod_glue.c")
+cable_task+=("$fw/main/app/pod_glue.c")
render_task=("$pod/pod_draw.c" "$pod/pod_pet.c" "$pod/pod_view.c" "$pod/pod_shared.c" "$pod/pod_time.c" "$pod"/home/*.c)
other=()
for f in "$pod"/*.c; do
@@ -72,7 +72,7 @@ cc "${cflags[@]}" -o "$out/pod_render" "$here/pod_render.c" "${objs[@]}"
px="$(dd if="$out/pets.ppm" bs=1 skip=$(( 15 + (690 * 720 + 10) * 3 )) count=3 2>/dev/null | od -An -tx1 | tr -d ' \n')"
# #151413 through RGB565 and back to the PPM's 8 bits is 101410.
[[ "$px" == "101410" ]] || { echo "run.sh: pets pixel (10,690) is $px, want 101410 (#151413 in RGB565)" >&2; exit 1; }
-echo "pets home: pixel (10,690) = #221F1D"
+echo "pets home: pixel (10,690) = #151413"
# Pets render time: every screen within 85% of its pre-change host time (test_ph_perf.sh; opt-in: runs only with PH_PERF=1, since absolute host microseconds are flaky on CI machines).
bash "$here/test_ph_perf.sh"
@@ -84,8 +84,7 @@ cc "${cflags[@]}" -I"$fw/test/host_esp" -o "$out/test_pro_frame" "$fw/test/test_
"$out/test_pro_frame"
# pro_cable: the daemon's JSON in, pro_app_* out. Real cJSON from the ESP-IDF checkout (CI has the sparse one at
-# $IDF_PATH), a recording stub of pro_app_api.h and a stub cable_link (test_pro_cable.c). host_stubs/ is NOT on this
-# include path: its cJSON.h is a typedef for the Pod model, and this test needs the real one.
+# $IDF_PATH), a recording stub of pro_app_api.h and a stub cable_link (test_pro_cable.c).
IDF_PATH="${IDF_PATH:-$HOME/esp/esp-idf-5.5.4}"
cjson="$IDF_PATH/components/json/cJSON"
if [[ ! -f "$cjson/cJSON.c" ]]; then
@@ -96,7 +95,7 @@ cable="$fw/main/cable"
cc_flags=(-std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Werror -O1 -g -fsanitize="${SANITIZERS:-undefined,bounds}"
-I"$fw/main" -I"$cable" -I"$here/host_esp" -I"$cjson")
cobjs=()
-cable_obj() { # cable_obj <limit-bytes> <source>... (every frame capped, like the cable_link task's 6 KB stack needs)
+cable_obj() { # cable_obj <limit-bytes> <source>... (every frame capped at 1 KB, as the cable_link task's stack wants)
local limit="$1"; shift
local src o
for src in "$@"; do
diff --git a/devices/harness-pro/firmware/test/stress_pro_app.c b/devices/harness-pro/firmware/test/stress_pro_app.c
index fd155377a..6fdb56b4c 100644
--- a/devices/harness-pro/firmware/test/stress_pro_app.c
+++ b/devices/harness-pro/firmware/test/stress_pro_app.c
@@ -12,6 +12,7 @@
#include "app/pro_app.h"
#include "app/pro_touch.h"
#include "app/pro_voice.h"
+#include "cable/cable_link.h"
#include "cable/pro_cable.h"
#include "pro_app_api.h"
#include "pro_canvas.h"
@@ -63,6 +64,8 @@ static int lib_req_offset = -1;
static uint32_t lib_req_id;
bool pro_cable_request_library(int offset, uint32_t request) { CHECK(LOCK_DEPTH == 0); lib_req_offset = offset; lib_req_id = request; return true; }
bool pro_cable_library_supported(void) { return true; }
+cable_link_stats_t cable_link_stats(void) { return (cable_link_stats_t){0}; }
+void pro_cable_counters(uint32_t *bad, uint32_t *unknown) { *bad = 0; *unknown = 0; }
void pro_voice_begin(const char *agent) { (void)agent; }
void pro_voice_end(bool send) { (void)send; }
bool pro_voice_open(void) { return false; }
diff --git a/devices/harness-pro/firmware/test/stress_pro_app.sh b/devices/harness-pro/firmware/test/stress_pro_app.sh
index 0a40d6c91..5b2f087b6 100644
--- a/devices/harness-pro/firmware/test/stress_pro_app.sh
+++ b/devices/harness-pro/firmware/test/stress_pro_app.sh
@@ -7,7 +7,7 @@ out="$(mktemp -d)"
trap 'rm -rf "$out"' EXIT
python3 "$fw/scripts/gen_fonts.py" --out "$out/pro_fonts.c" >/dev/null
cc -std=c11 -D_DEFAULT_SOURCE -w -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=undefined -DHT_FACE_PX=720 \
- -I"$fw/main/app" -I"$fw/main" -I"$fw/main/display" -I"$here/host_esp" -I"$here/host_stubs" -I"$fw/main/pod" \
+ -I"$fw/main/app" -I"$fw/main" -I"$fw/main/display" -I"$here/host_esp" -I"$fw/main/pod" \
"$here/stress_pro_app.c" "$fw"/main/pod/*.c "$fw"/main/pod/home/*.c "$fw/main/app/pod_glue.c" "$fw/main/app/pro_app.c" "$fw/main/app/pro_touch.c" \
"$fw/main/display/scroll.c" "$fw/main/display/pro_canvas.c" "$fw/main/display/terminal.c" "$out/pro_fonts.c" \
-lpthread -o "$out/stress"
diff --git a/devices/harness-pro/firmware/test/test_fonts.py b/devices/harness-pro/firmware/test/test_fonts.py
index 8d2c074b5..d57f2bfe3 100644
--- a/devices/harness-pro/firmware/test/test_fonts.py
+++ b/devices/harness-pro/firmware/test/test_fonts.py
@@ -89,7 +89,7 @@ class FontTests(unittest.TestCase):
def test_codepoints_have_ink(self):
fonts = parse(self.out)
- for size in (24, 32): # 42 and 56 are sparse: see test_sparse_sizes_have_empty_masks
+ for size in (24,): # 32, 42 and 56 are sparse: see test_sparse_sizes_have_empty_masks
for cp in [ord('A'), ord('g'), 0xB7] + VIET:
self.assertTrue(ink(fonts[size], cp), 'U+%04X at %d' % (cp, size))
@@ -116,16 +116,18 @@ class FontTests(unittest.TestCase):
def test_sparse_sizes_have_empty_masks(self):
fonts = parse(self.out)
- for size in (42, 56):
+ sys.path.insert(0, str(PRO / 'scripts'))
+ import gen_fonts
+ for size in (32, 42, 56):
for cp in CODEPOINTS:
- self.assertEqual(ink(fonts[size], cp), cp in map(ord, '#>_?'), 'U+%04X at %d' % (cp, size))
+ self.assertEqual(ink(fonts[size], cp), cp in map(ord, gen_fonts.SPARSE[size]), 'U+%04X at %d' % (cp, size))
def test_sparse_sizes_keep_metrics(self):
sys.path.insert(0, str(PRO / 'scripts'))
import gen_fonts
saved, gen_fonts.SPARSE = getattr(gen_fonts, 'SPARSE', {}), {}
try:
- full = {size: gen_fonts.bake(LIBERATION, size) for size in (42, 56)}
+ full = {size: gen_fonts.bake(LIBERATION, size) for size in (32, 42, 56)}
finally:
gen_fonts.SPARSE = saved
fonts = parse(self.out)
@@ -134,19 +136,19 @@ class FontTests(unittest.TestCase):
self.assertEqual([g[1:3] for g in glyphs], [g[1:] for g in fonts[size]['glyphs']], size)
def test_only_sparse_chars_drawn(self):
- use = re.compile(r'ht_pro_(42|56)\b')
+ use = re.compile(r'ht_pro_(32|42|56)\b')
for path in sorted((PRO / 'main').rglob('*.c')):
for n, line in enumerate(path.read_text().splitlines(), 1):
if not use.search(line) or line.lstrip().startswith(('//', '/*', '*')):
continue
where = '%s:%d' % (path.relative_to(PRO), n)
if path.name == 'pod_pet.c' and re.search(r'fonts\[\]\s*=\s*\{[^}]*&ht_pro_56', line):
- continue # the font table in mark_default_big; its only text is ">_"
+ continue # the font table in pod_mark_default_big; its only text is ">_"
if 'ht_pro_text' not in line and 'ht_pro_width' not in line and 'centered(' not in line:
- self.fail('%s: cannot judge use of ht_pro_42/56: %s' % (where, line.strip()))
+ self.fail('%s: cannot judge use of ht_pro_32/42/56: %s' % (where, line.strip()))
lits = re.findall(r'"((?:[^"\\]|\\.)*)"', line)
self.assertTrue(lits and all(set(l) <= set('#>_?') for l in lits),
- '%s: non-sparse text at 42/56: %s' % (where, line.strip()))
+ '%s: non-sparse text at 32/42/56: %s' % (where, line.strip()))
CS = {'ph_sb_48': ('Inter-SemiBold', 48), 'ph_sb_34': ('Inter-SemiBold', 34), 'ph_sb_26': ('Inter-SemiBold', 26),
diff --git a/devices/harness-pro/firmware/test/test_ph_perf.sh b/devices/harness-pro/firmware/test/test_ph_perf.sh
index edb0c2bd5..18515e039 100755
--- a/devices/harness-pro/firmware/test/test_ph_perf.sh
+++ b/devices/harness-pro/firmware/test/test_ph_perf.sh
@@ -18,7 +18,7 @@ if [[ -n "${PRO_FONT:-}" ]]; then
font_args=(--font "$PRO_FONT")
fi
python3 "$fw/scripts/gen_fonts.py" ${font_args[@]+"${font_args[@]}"} --out "$out/pro_fonts.c"
-cc -std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Werror -O2 -DHT_FACE_PX=720 -I"$disp" -I"$fw/main" -I"$here/host_stubs" \
+cc -std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Werror -O2 -DHT_FACE_PX=720 -I"$disp" -I"$fw/main" \
-o "$out/pod_render" "$here/pod_render.c" "$fw"/main/pod/*.c "$fw"/main/pod/home/*.c \
"$disp/pro_canvas.c" "$disp/terminal.c" "$out/pro_fonts.c"
diff --git a/devices/harness-pro/firmware/test/test_pro_app.py b/devices/harness-pro/firmware/test/test_pro_app.py
index 04b79c7e4..6bcdda223 100644
--- a/devices/harness-pro/firmware/test/test_pro_app.py
+++ b/devices/harness-pro/firmware/test/test_pro_app.py
@@ -36,6 +36,7 @@ code = r'''
#include "app/pro_app.h"
#include "app/pro_touch.h"
#include "app/pro_voice.h"
+#include "cable/cable_link.h"
#include "cable/pro_cable.h"
#include "pro_app_api.h"
#include "pro_canvas.h"
@@ -123,6 +124,8 @@ bool pro_cable_request_library(int offset, uint32_t request) {
return LIB.ok;
}
bool pro_cable_library_supported(void) { return LIB.supported; }
+cable_link_stats_t cable_link_stats(void) { return (cable_link_stats_t){0}; }
+void pro_cable_counters(uint32_t *bad, uint32_t *unknown) { *bad = 0; *unknown = 0; }
static bool GATE_IN_BEGIN; // the race: an offer's gate lands while a voice start is between its gate check and its begin
void pro_voice_begin(const char *agent) {
CHECK(LOCK_DEPTH == 0);
@@ -858,7 +861,7 @@ static void notice_shows_three_seconds(void) {
CHECK(S.count <= HT_RUNS);
}
-// Every pro_app callback runs on the device's cable_link task: a 6 KB stack. The render task has 24 KB. This runs the
+// Every pro_app callback runs on the device's cable_link task: a 12 KB stack. The render task has 24 KB. This runs the
// exact on-device sequence (link up, empty roster, empty swarms, library pages, then populated feeds) through the real
// callbacks on a small painted stack with a guard below it, and fails if they touch more than the budget (a ~10 KB local
// also faults on the guard, as the device did: "Stack protection fault"). The draw then runs on the main stack, as the
@@ -914,7 +917,7 @@ static void *cable_task(void *arg) {
}
#define STACK_BYTES 16384 // the smallest stack pthreads accept everywhere (macOS refuses less)
-#define CABLE_STACK_BUDGET 3584 // of the device's 6 KB: the rest is the cable_link task's own parse and dispatch frames
+#define CABLE_STACK_BUDGET 3584 // of the device's 12 KB: kept at its old, tighter figure (the parser alone is ~7 KB of the rest)
static void *idle_task(void *arg) { (void)arg; return NULL; }
// Run fn on a fresh STACK_BYTES stack painted with 0xA5; return the bytes it touched (the high-water mark).
// The stack is mmap'd with a PROT_NONE page below it, so running past the 16 KB faults like the device's guard does.
@@ -2284,7 +2287,7 @@ test_no_turn()
cc = os.environ.get("CC", "cc")
sanitize = "-fsanitize=" + os.environ.get("SANITIZERS", "undefined,bounds")
-include = ["-I", str(APP), "-I", str(MAIN), "-I", str(DISP), "-I", str(HERE / "host_esp"), "-I", str(HERE / "host_stubs"),
+include = ["-I", str(APP), "-I", str(MAIN), "-I", str(DISP), "-I", str(HERE / "host_esp"),
"-I", str(POD)]
failures = []
with tempfile.TemporaryDirectory(prefix="harness-pro-app-") as directory:
@@ -2300,7 +2303,7 @@ with tempfile.TemporaryDirectory(prefix="harness-pro-app-") as directory:
modules = sorted(POD.glob("*.c")) + sorted(POD.glob("*/*.c")) + [APP / "pod_glue.c", APP / "pro_app.c", APP / "pro_touch.c", DISP / "scroll.c",
DISP / "pro_canvas.c", DISP / "terminal.c", fonts]
for label, extra in (("upright", []),):
- # The callbacks run on the cable_link task's 6 KB stack, the touch task's contact path on 10 KB: no frame of
+ # The callbacks run on the cable_link task's 12 KB stack, the touch task's contact path on 10 KB: no frame of
# pro_app.c, pro_touch.c or the glue may pass 1 KB.
for guarded in (APP / "pod_glue.c", APP / "pro_app.c", APP / "pro_touch.c"):
subprocess.run([cc, "-std=c11", "-D_DEFAULT_SOURCE", "-Wall", "-Wextra", "-Werror", "-Wframe-larger-than=1024", "-O1", "-DHT_FACE_PX=720",
diff --git a/devices/harness-pro/firmware/test/test_pro_cable.c b/devices/harness-pro/firmware/test/test_pro_cable.c
index c38f7061b..9e9d38a33 100644
--- a/devices/harness-pro/firmware/test/test_pro_cable.c
+++ b/devices/harness-pro/firmware/test/test_pro_cable.c
@@ -23,6 +23,7 @@
#include "pod/pod_model.h"
#include "pro_app_api.h"
#include "sys/device_mac.h"
+#include "task_stacks.h"
#include "sys/last_words.h"
#include "board/board.h"
#include "sys/config_store.h"
@@ -616,7 +617,7 @@ static void test_session_machines_library_voice(void)
}
// ---- the small stack -------------------------------------------------------------------------------------
-// pro_cable's parser runs on the cable_link task: 6 KB, shared with the reader loop and the decoder. This runs the
+// pro_cable's parser runs on the cable_link task: STACK_CABLE_LINK (12 KB), shared with the reader loop and the decoder. This runs the
// heaviest frames on a thread whose stack is painted first, and measures how deep it went.
#define PAINT 0xA5
static size_t used_bytes;
@@ -661,9 +662,9 @@ static void *painted_entry(void *arg)
static void pro_cable_test_small_stack(void)
{
- // (1) A real thread at the device's size: max(12288, PTHREAD_STACK_MIN). The OS minimum is 16 KB on macOS and
- // glibc, so this proves the parser runs on a thread of that kind, not that 6 KB is enough.
- size_t want = 12288 > (size_t)PTHREAD_STACK_MIN ? 12288 : (size_t)PTHREAD_STACK_MIN;
+ // (1) A real thread at the device's size: max(STACK_CABLE_LINK, PTHREAD_STACK_MIN). The OS minimum is 16 KB on macOS and
+ // glibc, so this proves the parser runs on a thread of that kind, not that the stack is enough.
+ size_t want = STACK_CABLE_LINK > (size_t)PTHREAD_STACK_MIN ? STACK_CABLE_LINK : (size_t)PTHREAD_STACK_MIN;
pthread_attr_t attr;
pthread_t th;
CHECK(pthread_attr_init(&attr) == 0 && pthread_attr_setstacksize(&attr, want) == 0);
@@ -671,7 +672,7 @@ static void pro_cable_test_small_stack(void)
pthread_attr_destroy(&attr);
// (2) The real measurement: our own 64 KB stack, painted, and the deepest untouched byte read back. The parser
- // plus the reader loop's own frames (decoder + 256 B read chunk, < 1.5 KB) must fit in READER_STACK (cable_link.c, 12288).
+ // plus the reader loop's own frames (decoder + 256 B read chunk, < 1.5 KB) must fit in STACK_CABLE_LINK (task_stacks.h).
const size_t size = 64 * 1024 > (size_t)PTHREAD_STACK_MIN ? 64 * 1024 : (size_t)PTHREAD_STACK_MIN; // 128 KB minimum on aarch64 glibc
unsigned char *stack = NULL;
CHECK(posix_memalign((void **)&stack, 4096, size) == 0);
diff --git a/devices/harness-pro/firmware/test/test_pro_hello.py b/devices/harness-pro/firmware/test/test_pro_hello.py
index 702fd12f5..28e2e32ef 100644
--- a/devices/harness-pro/firmware/test/test_pro_hello.py
+++ b/devices/harness-pro/firmware/test/test_pro_hello.py
@@ -54,7 +54,7 @@ with tempfile.TemporaryDirectory() as d:
src = Path(d) / "hello.c"
src.write_text(code)
exe = Path(d) / "hello"
- subprocess.run(["cc", "-std=c11", "-D_DEFAULT_SOURCE", "-Wall", "-Werror", "-Wno-unused-function", "-o", str(exe), str(src)], check=True)
+ subprocess.run(["cc", "-std=c11", "-D_DEFAULT_SOURCE", "-Wall", "-Werror", "-o", str(exe), str(src)], check=True)
lines = subprocess.run([str(exe)], check=True, capture_output=True, text=True).stdout.split()
# The settings object: every key the app's DeviceSettings.fromJson requires, with its JSON type. Otherwise the app
diff --git a/devices/harness-pro/firmware/test/test_pro_voice_gate.py b/devices/harness-pro/firmware/test/test_pro_voice_gate.py
index 38e5301fd..e09265cbb 100644
--- a/devices/harness-pro/firmware/test/test_pro_voice_gate.py
+++ b/devices/harness-pro/firmware/test/test_pro_voice_gate.py
@@ -35,6 +35,7 @@ code = r'''
#include "app/pro_voice.h"
#include "audio/audio_capture.h"
#include "audio/pro_recorder.h"
+#include "cable/cable_link.h"
#include "cable/pro_cable.h"
#include "pro_app_api.h"
#include "pro_canvas.h"
@@ -108,6 +109,8 @@ bool pro_cable_send_open(const char *id) { CHECK(LOCK_DEPTH == 0); (void)id; CAB
bool pro_cable_send_scroll(pro_scroll_phase_t p, int dy, int v) { CHECK(LOCK_DEPTH == 0); (void)p; (void)dy; (void)v; return true; }
bool pro_cable_request_library(int offset, uint32_t request) { CHECK(LOCK_DEPTH == 0); (void)offset; (void)request; return true; }
bool pro_cable_library_supported(void) { return false; }
+cable_link_stats_t cable_link_stats(void) { return (cable_link_stats_t){0}; }
+void pro_cable_counters(uint32_t *bad, uint32_t *unknown) { *bad = 0; *unknown = 0; }
bool pro_cable_voice_cancel(const char *id) { CHECK(LOCK_DEPTH == 0); CAB.cancels++; snprintf(CAB.cancel_id, sizeof CAB.cancel_id, "%s", id); return true; }
// The recorder: the capture and sender tasks are replaced by flags the test flips.
@@ -525,7 +528,7 @@ def check_sources():
check_sources()
cc = os.environ.get("CC", "cc")
sanitize = "-fsanitize=" + os.environ.get("SANITIZERS", "undefined,bounds")
-include = ["-I", str(APP), "-I", str(MAIN), "-I", str(DISP), "-I", str(HERE / "host_esp"), "-I", str(HERE / "host_stubs"),
+include = ["-I", str(APP), "-I", str(MAIN), "-I", str(DISP), "-I", str(HERE / "host_esp"),
"-I", str(POD)]
failures = []
with tempfile.TemporaryDirectory(prefix="harness-pro-voice-") as directory:
@@ -540,11 +543,11 @@ with tempfile.TemporaryDirectory(prefix="harness-pro-voice-") as directory:
source.write_text(code)
modules = sorted(POD.glob("*.c")) + sorted(POD.glob("*/*.c")) + [APP / "pod_glue.c", APP / "pro_app.c", APP / "pro_touch.c", AUDIO / "pro_voice.c", DISP / "scroll.c",
DISP / "pro_canvas.c", DISP / "terminal.c", fonts]
- # The voice state machine runs on the touch, render and cable_link tasks (6 KB stack): no frame past 1 KB.
+ # The voice state machine runs on the touch, render and cable_link tasks: no frame past 1 KB.
subprocess.run([cc, "-std=c11", "-D_DEFAULT_SOURCE", "-Wall", "-Wextra", "-Werror", "-Wframe-larger-than=1024", "-O1", "-DHT_FACE_PX=720",
"-DPRO_VOICE_TEST_HOOK", *include, "-c", str(AUDIO / "pro_voice.c"), "-o", os.devnull], check=True)
executable = directory / "pro_voice_gate"
- subprocess.run([cc, "-std=c11", "-D_DEFAULT_SOURCE", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-O1", "-g", sanitize,
+ subprocess.run([cc, "-std=c11", "-D_DEFAULT_SOURCE", "-Wall", "-Wextra", "-Werror", "-O1", "-g", sanitize,
"-DHT_FACE_PX=720", "-DPRO_VOICE_TEST_HOOK", *include, str(source), *map(str, modules), "-lpthread", "-o", str(executable)],
check=True)
result = subprocess.run([str(executable)], text=True, capture_output=True)