diff --git a/nodered.js b/nodered.js index 64d273e..9410051 100644 --- a/nodered.js +++ b/nodered.js @@ -239,7 +239,7 @@ export class Node { const wires = config.wires; if (wires) { this.#outputs = wires.map(wire => wire.map(target => this.#flow.getNode(target))); - if (!config.dones && !config.errors) + if (!config.dones && !config.errors && !config.statuses) return; } else { @@ -293,25 +293,23 @@ export class Node { return this.send(result); } status(status) { - const source = { - id: this.id - }; + trace.left(JSON.stringify({status}), this.id); + + const statuses = this.#outputs.statuses; + if (!statuses) + return; const msg = { status: { ...status, }, - source + source: { + id: this.id, + type: this.constructor.type, + name: this.name + } }; - trace.left(JSON.stringify(msg), this.id); - - const statuses = this.#outputs.statuses; - if (!statuses) - return; - - source.type = this.constructor.type; - source.name = this.name; for (let i = 0, length = statuses.length; i < length; i++) RED.mcu.enqueue(msg, statuses[i]); } @@ -429,6 +427,7 @@ class DebugNode extends Node { #statusType; #statusVal; #oldStatus; + #active; onStart(config) { super.onStart(config); @@ -440,6 +439,7 @@ class DebugNode extends Node { this.#toStatus = config.tostatus; this.#statusType = config.statusType; this.#statusVal = config.statusVal; + this.#active = config.active } onMessage(msg, done) { // to prevent endless loops -> 21-debug.js:123 @@ -448,17 +448,9 @@ class DebugNode extends Node { return; } - // Feed msg back to the editor. - trace.left(JSON.stringify({ - input: { - ...msg, - source: { - id: this.id, - type: this.constructor.type, - name: this.name - } - } - }), this.id); + // Feed msg back to the editor + if (this.#active) + trace.left(JSON.stringify({input: msg}), this.id); // Process msg for xsbug let value = this.#getter(msg); @@ -466,7 +458,7 @@ class DebugNode extends Node { if (this.#console) { if (value instanceof Uint8Array) value = Hex.toString(value); - trace(("object" === typeof value) ? JSON.stringify(value) : value, "\n"); + trace("", ("object" === typeof value) ? JSON.stringify(value) : value, "\n"); } if (this.#sidebar) { @@ -478,13 +470,15 @@ class DebugNode extends Node { type: this.constructor.type, name: this.name } - } - trace.right(JSON.stringify(value)); + }; + trace("", JSON.stringify(value), "\n"); } if (this.#toStatus) { const statusVal = this.#statusVal(msg); // NR says: #statusVal shall return typeof string! if (statusVal !== this.#oldStatus) { + if (statusVal.length > 32) + statusVal = statusVal.slice(0, 32) + "…"; this.status({fill: "grey", shape: "dot", text: statusVal}); this.#oldStatus = statusVal; } @@ -492,6 +486,10 @@ class DebugNode extends Node { done(); } + onCommand(options) { + if ("debug" === options.command) + this.#active = !!options.active; + } static type = "debug"; static { @@ -1402,6 +1400,7 @@ globalThis.clearInterval = Timer.clear; globalThis.setTimeout = Timer.set; globalThis.clearTimeout = Timer.clear; globalThis.console = Console; +globalThis.Buffer = Buffer; globalThis.RED = RED; globalThis.module = Object.freeze({ diff --git a/readme.md b/readme.md index f804b53..7f4b0cd 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # Node-RED MCU Edition Copyright 2022, Moddable Tech, Inc. All rights reserved.
Peter Hoddie
-Updated October 31, 2022
+Updated November 2, 2022
## Introduction This document introduces an implementation of the Node-RED runtime that runs on resource-constrained microcontrollers (MCUs). [Node-RED](https://nodered.org/) is a popular visual environment that describes itself as "a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways." @@ -297,9 +297,12 @@ Comment nodes are removed at build-time. ### Debug - [X] Console output is displayed in the xsbug log pane -- [X] Sidebar output is displayed in the xsbug message pane +- [X] Sidebar output is displayed in the xsbug log pane - [X] Display of selected property or complete message - [X] Output to node status +- [X] Active +- [X] Relay to Node-RED Editor +- [ ] JSONata expression ### Function - [X] "On Start" and "On Message" handlers @@ -341,6 +344,7 @@ Function node implements support for calling `done()` if function's source code ### Status - [X] "Report status from all nodes" - [X] "Report status from selected nodes" +- [X] Status relayed to Node-RED Editor ### Complete - [X] Implemented