mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
add ability to reboot device
This commit is contained in:
parent
77803c5fca
commit
8125faaccf
3 changed files with 46 additions and 0 deletions
|
|
@ -172,6 +172,12 @@ class Connection extends EventEmitter {
|
|||
await this.sendToRadioFrame(data.toBytes());
|
||||
}
|
||||
|
||||
async sendCommandReboot() {
|
||||
const data = new BufferWriter();
|
||||
data.writeByte(Constants.CommandCodes.Reboot);
|
||||
await this.sendToRadioFrame(data.toBytes());
|
||||
}
|
||||
|
||||
onFrameReceived(frame) {
|
||||
|
||||
// emit received frame
|
||||
|
|
@ -938,6 +944,34 @@ class Connection extends EventEmitter {
|
|||
});
|
||||
}
|
||||
|
||||
reboot() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
|
||||
// reject promise when we receive err
|
||||
const onErr = () => {
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
reject();
|
||||
}
|
||||
|
||||
// assume device rebooted after a short delay
|
||||
setTimeout(() => {
|
||||
this.off(Constants.ResponseCodes.Err, onErr);
|
||||
resolve();
|
||||
}, 1000);
|
||||
|
||||
// listen for events
|
||||
this.once(Constants.ResponseCodes.Err, onErr);
|
||||
|
||||
// reboot
|
||||
await this.sendCommandReboot();
|
||||
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Connection;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class Constants {
|
|||
ShareContact: 16,
|
||||
ExportContact: 17,
|
||||
ImportContact: 18,
|
||||
Reboot: 19,
|
||||
}
|
||||
|
||||
static ResponseCodes = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue