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
|
// fire connected event
|
||||||
this.onConnected();
|
await this.onConnected();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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", () => {
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
class Constants {
|
class Constants {
|
||||||
|
|
||||||
|
static SupportedCompanionProtocolVersion = 1;
|
||||||
|
|
||||||
static SerialFrameTypes = {
|
static SerialFrameTypes = {
|
||||||
Incoming: 0x3e, // ">"
|
Incoming: 0x3e, // ">"
|
||||||
Outgoing: 0x3c, // "<"
|
Outgoing: 0x3c, // "<"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue