diff --git a/package.json b/package.json index f1af550..21a4833 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@meshtastic/js", - "version": "2.2.17-2", + "version": "2.2.17-3", "description": "Browser library for interfacing with meshtastic devices", "license": "GPL-3.0-only", "scripts": { diff --git a/src/meshDevice.ts b/src/meshDevice.ts index 61c0275..2ca4416 100755 --- a/src/meshDevice.ts +++ b/src/meshDevice.ts @@ -1,10 +1,14 @@ -import { Logger } from "tslog"; -import { broadcastNum, minFwVer } from "./constants.js"; -import { EventSystem } from "./utils/eventSystem.js"; -import { Queue } from "./utils/queue.js"; -import { Xmodem } from "./utils/xmodem.js"; -import * as Types from "./types.js"; -import * as Protobuf from "./protobufs.js"; +import { Logger } from 'tslog'; + +import { + broadcastNum, + minFwVer, +} from './constants.js'; +import * as Protobuf from './protobufs.js'; +import * as Types from './types.js'; +import { EventSystem } from './utils/eventSystem.js'; +import { Queue } from './utils/queue.js'; +import { Xmodem } from './utils/xmodem.js'; /** Base class for connection methods to extend */ export abstract class MeshDevice { @@ -601,6 +605,27 @@ export abstract class MeshDevice { ); } + /** Enter DFU mode on the current node. */ + public async enterDfuMode(): Promise { + this.log.debug( + Types.Emitter[Types.Emitter.enterDfuMode], + `🔌 Entering DFU mode`, + ); + + const dfu = new Protobuf.AdminMessage({ + payloadVariant: { + case: "enterDfuModeRequest", + value: true, + }, + }); + + return await this.sendPacket( + dfu.toBinary(), + Protobuf.PortNum.ADMIN_APP, + "self", + ); + } + /** Factory resets the current node */ public async factoryReset(): Promise { this.log.debug( diff --git a/src/types.ts b/src/types.ts index aee3d30..4775d96 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ -import * as Protobuf from "./protobufs.js"; -import { BleConnection } from "./adapters/bleConnection.js"; -import { HttpConnection } from "./adapters/httpConnection.js"; -import { SerialConnection } from "./adapters/serialConnection.js"; +import { BleConnection } from './adapters/bleConnection.js'; +import { HttpConnection } from './adapters/httpConnection.js'; +import { SerialConnection } from './adapters/serialConnection.js'; +import * as Protobuf from './protobufs.js'; export interface QueueItem { id: number; @@ -111,6 +111,7 @@ export enum Emitter { reboot = 28, rebootOTA = 29, factoryReset = 30, + enterDfuMode = 31, } export interface LogEvent {