|
|
|
@ -1,7 +1,6 @@ |
|
|
|
import { Logger } from "tslog"; |
|
|
|
|
|
|
|
import { create, fromBinary, toBinary } from "@bufbuild/protobuf"; |
|
|
|
import * as Protobuf from "@meshtastic/protobufs"; |
|
|
|
import { Logger } from "tslog"; |
|
|
|
|
|
|
|
import { Constants } from "./constants.ts"; |
|
|
|
import type { Destination, PacketMetadata, Transport } from "./types.ts"; |
|
|
|
@ -40,6 +39,8 @@ export class MeshDevice { |
|
|
|
|
|
|
|
public xModem: Xmodem; |
|
|
|
|
|
|
|
private _heartbeatIntervalId: ReturnType<typeof setInterval> | undefined; |
|
|
|
|
|
|
|
constructor(transport: Transport, configId?: number) { |
|
|
|
this.log = new Logger({ |
|
|
|
name: "iMeshDevice", |
|
|
|
@ -741,6 +742,18 @@ export class MeshDevice { |
|
|
|
return this.sendRaw(toBinary(Protobuf.Mesh.ToRadioSchema, toRadio)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Initializes the heartbeat interval, which sends a heartbeat ping every interval milliseconds. |
|
|
|
*/ |
|
|
|
public setHeartbeatInterval(interval: number): void { |
|
|
|
if (this._heartbeatIntervalId !== undefined) { |
|
|
|
clearInterval(this._heartbeatIntervalId); |
|
|
|
} |
|
|
|
this._heartbeatIntervalId = setInterval(() => { |
|
|
|
this.heartbeat(); |
|
|
|
}, interval); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Sends a trace route packet to the designated node |
|
|
|
*/ |
|
|
|
@ -798,6 +811,11 @@ export class MeshDevice { |
|
|
|
/** Disconnects from the device **/ |
|
|
|
public async disconnect(): Promise<void> { |
|
|
|
this.log.debug(Emitter[Emitter.Disconnect], "🔌 Disconnecting from device"); |
|
|
|
|
|
|
|
if (this._heartbeatIntervalId !== undefined) { |
|
|
|
clearInterval(this._heartbeatIntervalId); |
|
|
|
} |
|
|
|
|
|
|
|
this.complete(); |
|
|
|
await this.transport.toDevice.close(); |
|
|
|
} |
|
|
|
|