tell device what protocol version we support when connected

This commit is contained in:
liamcottle 2025-04-08 12:36:42 +12:00
parent e73632456d
commit 0210b5a438
6 changed files with 21 additions and 9 deletions

View file

@ -72,7 +72,7 @@ class BleConnection extends Connection {
}); });
// fire connected event // fire connected event
this.onConnected(); await this.onConnected();
} }

View file

@ -8,8 +8,18 @@ import RandomUtils from "../random_utils.js";
class Connection extends EventEmitter { class Connection extends EventEmitter {
onConnected() { async onConnected() {
// tell device what protocol version we support
try {
await this.deviceQuery(Constants.SupportedCompanionProtocolVersion);
} catch(e) {
// ignore
}
// tell clients we are connected
this.emit("connected"); this.emit("connected");
} }
onDisconnected() { onDisconnected() {
@ -319,7 +329,7 @@ class Connection extends EventEmitter {
} else if(responseCode === Constants.PushCodes.TraceData){ } else if(responseCode === Constants.PushCodes.TraceData){
this.onTraceDataPush(bufferReader); this.onTraceDataPush(bufferReader);
} else { } else {
console.log("unhandled frame", frame); console.log(`unhandled frame: code=${responseCode}`, frame);
} }
} }

View file

@ -22,8 +22,8 @@ class NodeJSSerialConnection extends SerialConnection {
baudRate: 115200, baudRate: 115200,
}); });
this.serialPort.on("open", () => { this.serialPort.on("open", async () => {
this.onConnected(); await this.onConnected();
}); });
this.serialPort.on("close", () => { this.serialPort.on("close", () => {

View file

@ -36,8 +36,8 @@ class TCPConnection extends Connection {
}); });
// connect to server // connect to server
this.socket.connect(this.port, this.host, () => { this.socket.connect(this.port, this.host, async () => {
this.onConnected(); await this.onConnected();
}); });
} }

View file

@ -17,8 +17,8 @@ class WebSerialConnection extends SerialConnection {
}); });
// fire connected callback after constructor has returned // fire connected callback after constructor has returned
setTimeout(() => { setTimeout(async () => {
this.onConnected(); await this.onConnected();
}, 0); }, 0);
} }

View file

@ -1,5 +1,7 @@
class Constants { class Constants {
static SupportedCompanionProtocolVersion = 1;
static SerialFrameTypes = { static SerialFrameTypes = {
Incoming: 0x3e, // ">" Incoming: 0x3e, // ">"
Outgoing: 0x3c, // "<" Outgoing: 0x3c, // "<"