Skip to content

Commit

Permalink
Merge pull request #79 from meshtastic/enter-dfu
Browse files Browse the repository at this point in the history
Add enter dfu mode
  • Loading branch information
thebentern authored Dec 31, 2023
2 parents 4146339 + 33b6ca1 commit ce918ee
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
39 changes: 32 additions & 7 deletions src/meshDevice.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -601,6 +605,27 @@ export abstract class MeshDevice {
);
}

/** Enter DFU mode on the current node. */
public async enterDfuMode(): Promise<Number> {
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<number> {
this.log.debug(
Expand Down
9 changes: 5 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -111,6 +111,7 @@ export enum Emitter {
reboot = 28,
rebootOTA = 29,
factoryReset = 30,
enterDfuMode = 31,
}

export interface LogEvent {
Expand Down

0 comments on commit ce918ee

Please sign in to comment.