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
this.onConnected();
await this.onConnected();
}

View file

@ -8,8 +8,18 @@ import RandomUtils from "../random_utils.js";
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");
}
onDisconnected() {
@ -319,7 +329,7 @@ class Connection extends EventEmitter {
} else if(responseCode === Constants.PushCodes.TraceData){
this.onTraceDataPush(bufferReader);
} 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,
});
this.serialPort.on("open", () => {
this.onConnected();
this.serialPort.on("open", async () => {
await this.onConnected();
});
this.serialPort.on("close", () => {

View file

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

View file

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

View file

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