mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
tell device what protocol version we support when connected
This commit is contained in:
parent
e73632456d
commit
0210b5a438
6 changed files with 21 additions and 9 deletions
|
|
@ -72,7 +72,7 @@ class BleConnection extends Connection {
|
|||
});
|
||||
|
||||
// fire connected event
|
||||
this.onConnected();
|
||||
await this.onConnected();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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", () => {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ class WebSerialConnection extends SerialConnection {
|
|||
});
|
||||
|
||||
// fire connected callback after constructor has returned
|
||||
setTimeout(() => {
|
||||
this.onConnected();
|
||||
setTimeout(async () => {
|
||||
await this.onConnected();
|
||||
}, 0);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
class Constants {
|
||||
|
||||
static SupportedCompanionProtocolVersion = 1;
|
||||
|
||||
static SerialFrameTypes = {
|
||||
Incoming: 0x3e, // ">"
|
||||
Outgoing: 0x3c, // "<"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue