From 551dded4dc0bcf07594a83b5c72b31c0f13e300e Mon Sep 17 00:00:00 2001 From: chk <79915315+ChKendel@users.noreply.github.com> Date: Sun, 14 Jun 2026 13:57:02 +0200 Subject: [PATCH] Fix Read .grbl --- src/active/activeState.js | 11 ++++++++++- src/routes/active.js | 4 ++-- test/activeState.test.js | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/active/activeState.js b/src/active/activeState.js index 7f598fa..08555ff 100644 --- a/src/active/activeState.js +++ b/src/active/activeState.js @@ -47,7 +47,8 @@ class ActiveState { } } - /** API-Repräsentation (ActiveState). currentLine = driver-nativ (Radian). */ + /** API-Repräsentation (ActiveState). currentLine = driver-nativ (Radian); + * lines = volle Programmliste in GRAD (wie gespeichert) — für die Anzeige (FShow). */ getState() { const currentLine = this.lines.length ? units.toExecutable(this.lines[this.cursor]) : null; return { @@ -55,11 +56,19 @@ class ActiveState { cursor: this.cursor, lineCount: this.lines.length, currentLine, + lines: this.lines, playing: this.playing, version: this.version, }; } + /** FShow: lädt bei Bedarf das Default-Programm (Lesen mit implizitem log) und + * liefert den vollen Zustand inkl. Zeilenliste. */ + async show() { + await this._ensureActive(); + return this.getState(); + } + /** * Setzt ein Programm aktiv (FLoad). Existiert es nicht, wird es leer angelegt * (nötig für Teaching). Ein vorher aktives Programm wird zuvor persistiert. diff --git a/src/routes/active.js b/src/routes/active.js index 36a5c60..76145aa 100644 --- a/src/routes/active.js +++ b/src/routes/active.js @@ -9,8 +9,8 @@ const { ApiError } = require('../errors'); const router = express.Router(); const asyncH = (fn) => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next); -// GET /api/active -router.get('/', (req, res) => res.json(active.getState())); +// GET /api/active (FShow) — lädt bei Bedarf das Default-Programm, liefert volle Liste +router.get('/', asyncH(async (req, res) => res.json(await active.show()))); // PUT /api/active (FLoad) — existiert nicht → leer anlegen (für Teaching) router.put( diff --git a/test/activeState.test.js b/test/activeState.test.js index 3bf98b6..f8c18dc 100644 --- a/test/activeState.test.js +++ b/test/activeState.test.js @@ -82,6 +82,22 @@ test('Stepping ohne aktives Programm → auto-lädt Default (leer → EMPTY_PROG expect(a.programId).toBe(cfg.defaultProgramId); // Default wurde geladen }); +test('FShow ohne FLoad → auto-lädt Default und liefert volle Zeilenliste', async () => { + await store.write(cfg.defaultProgramId, { + name: 'log', + lines: [ + 'G90 G1 x0 y300 z0 a90.00 b-90.00 c0.00 e0.00 f1000 ;1', + 'G90 G1 x10 y300 z0 a0.00 b-90.00 c0.00 e0.00 f1000 ;2', + ], + }); + const a = new ActiveState(); + const state = await a.show(); // frisch, ohne vorheriges FLoad/FPoint + expect(state.programId).toBe(cfg.defaultProgramId); + expect(state.lineCount).toBe(2); + expect(state.lines).toHaveLength(2); // volle Liste für die Anzeige + expect(state.lines[0]).toContain('a90.00'); // in Grad, wie gespeichert +}); + test('Stepping nach Neustart liest Default-Programm von Disk (FFirst ohne FLoad)', async () => { // Simuliert: log.gcode liegt auf Disk, frischer ActiveState (wie nach Container-Neustart) await store.write(cfg.defaultProgramId, {