Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enter dfu mode #79

Merged
merged 3 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading