From ebe09d2c90f82afce7d80b5a17718606eff47450 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 31 Dec 2023 08:54:16 -0600 Subject: [PATCH 1/3] Add enter dfu mode --- src/meshDevice.ts | 39 ++++++++++++++++++++++++++++++++------- src/types.ts | 9 +++++---- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/meshDevice.ts b/src/meshDevice.ts index 61c0275..cec5537 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 reboot = new Protobuf.AdminMessage({ + payloadVariant: { + case: "enterDfuModeRequest", + value: true, + }, + }); + + return await this.sendPacket( + reboot.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 { From 17333df6ff9b7dac2fd8c65cc7f8b307038b521c Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 31 Dec 2023 08:58:06 -0600 Subject: [PATCH 2/3] Change local name --- src/meshDevice.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/meshDevice.ts b/src/meshDevice.ts index cec5537..2ca4416 100755 --- a/src/meshDevice.ts +++ b/src/meshDevice.ts @@ -612,7 +612,7 @@ export abstract class MeshDevice { `🔌 Entering DFU mode`, ); - const reboot = new Protobuf.AdminMessage({ + const dfu = new Protobuf.AdminMessage({ payloadVariant: { case: "enterDfuModeRequest", value: true, @@ -620,7 +620,7 @@ export abstract class MeshDevice { }); return await this.sendPacket( - reboot.toBinary(), + dfu.toBinary(), Protobuf.PortNum.ADMIN_APP, "self", ); From 33b6ca19414be8182ddc2d1ed53eb0261d1ea547 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 31 Dec 2023 09:01:36 -0600 Subject: [PATCH 3/3] Bump build number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": {