From 79e88ce37359b80ab0bcf593dffbf92411f6f617 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Fri, 22 Jul 2022 11:18:34 +0100 Subject: [PATCH] feat: Make devtools --serial work add devtools --diagnostics --- package.json | 2 +- src/devtools.ts | 17 +++++++++++------ src/index.ts | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 4cff714..407a6fb 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "dependencies": { "commander": "^9.0.0", "faye-websocket": "^0.11.4", - "jacdac-ts": "^1.24.19" + "jacdac-ts": "^1.25.0" }, "devDependencies": { "@semantic-release/exec": "^6.0.3", diff --git a/src/devtools.ts b/src/devtools.ts index 1da253c..fce10b7 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -9,6 +9,7 @@ import { createProxyBridge, randomDeviceId, PACKET_RECEIVE_NO_DEVICE, + Flags, } from "jacdac-ts" import { enableLogging } from "./jdlogging" import { createTransports, TransportsOptions } from "./transports" @@ -51,13 +52,15 @@ export async function devToolsCommand( internet?: boolean logging?: boolean trace?: string + diagnostics?: boolean } & TransportsOptions ) { - const { packets, internet, trace, logging } = options || {} + const { packets, internet, trace, logging, diagnostics } = options || {} const port = 8081 const tcpPort = 8082 const listenHost = internet ? undefined : "127.0.0.1" + if (diagnostics) Flags.diagnostics = true if (trace) fs.writeFileSync(trace, "") log(`Jacdac dev tools`) @@ -84,11 +87,7 @@ export async function devToolsCommand( }) // passive bus to sniff packets - const bridge = createProxyBridge((data, sender) => { - clients - .filter(c => c[SENDER_FIELD] !== sender) - .forEach(c => c.send(Buffer.from(data))) - }) + const transports = createTransports(options) const bus = new JDBus(transports, { client: false, @@ -97,9 +96,15 @@ export async function devToolsCommand( }) bus.passive = true bus.on(ERROR, e => error(e)) + const bridge = createProxyBridge((data, sender) => { + clients + .filter(c => c[SENDER_FIELD] !== sender) + .forEach(c => c.send(Buffer.from(data))) + }) bus.addBridge(bridge) const processPacket = (message: Buffer | Uint8Array, sender: string) => { const data = new Uint8Array(message) + bus.transports.map(transport => transport.sendPacketWhenConnectedAsync(data)) bridge.receiveFrameOrPacket(data, sender) } diff --git a/src/index.ts b/src/index.ts index 4640955..2d918e9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,7 @@ async function mainCli() { .option("-t, --trace ", "save all packets to named file") .option("-w, --internet", "allow connections from non-localhost") .option("-u, --usb", "listen to Jacdac over USB (requires usb)") + .option("-d, --diagnostics", "print more debug info") .option( "-s, --serial", "listen to Jacdac over SERIAL (requires serialport)"