Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@meshtastic/meshtasticjs

Package Overview
Dependencies
Maintainers
1
Versions
181
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@meshtastic/meshtasticjs - npm Package Compare versions

Comparing version 0.6.101 to 0.6.102

44

dist/client.d.ts
import { IBLEConnection } from "./iBleConnection.js";
import { IHTTPConnection } from "./iHttpConnection.js";
import { Types } from "./index.js";
import { ISerialConnection } from "./iSerialConnection.js";
import type { DeviceInterface } from "./types.js";
export declare type IConnection = IBLEConnection | IHTTPConnection | ISerialConnection;
/**
* Allows to create new connections to devices and manages them.
* Alternatively, new connections can be created directly by instantiating
* their respective the interface classes.
* Allows to create new connections to devices and manages them. Alternatively,
* new connections can be created directly by instantiating their respective the
* interface classes.
*/
export declare class Client {
/**
* Array containing all created connection interfaces
*/
deviceInterfaces: Array<IBLEConnection | IHTTPConnection | ISerialConnection>;
/** Array containing all created connection interfaces */
deviceInterfaces: Types.ConnectionType[];
constructor();
/**
* Creates a new Bluetooth Low Enery connection interface
*
* @param {number} [configId] Desired instance config ID
* @returns {IBLEConnection} Resulting BLE connection object
*/
createBLEConnection(): IBLEConnection;
createBLEConnection(configId?: number): IBLEConnection;
/**
* Creates a new HTTP(S) connection interface
*
* @param {number} [configId] Desired instance config ID
* @returns {IHTTPConnection} Resulting HTTP connection object
*/
createHTTPConnection(configId: number): IHTTPConnection;
createHTTPConnection(configId?: number): IHTTPConnection;
/**
* Creates a new Serial connection interface
*
* @param {number} [configId] Desired instance config ID
* @returns {ISerialConnection} Resulting Serial connection object
*/
createSerialConnection(configId: number): ISerialConnection;
createSerialConnection(configId?: number): ISerialConnection;
/**
* Adds an already created connection interface to the client
* @param connectionObj Desired Bluetooth, Serial or HTTP connection to add
*
* @param {Types.IConnectionType} connectionObj Desired BLE, Serial or HTTP
* connection to add
* @returns {void}
*/
addConnection(connectionObj: DeviceInterface): void;
addConnection(connectionObj: Types.ConnectionType): void;
/**
* Removes a connection interface from the client
* @param connectionObj Desired Bluetooth, Serial or HTTP connection to remove
*
* @param {Types.IConnectionType} connectionObj Desired Bluetooth, Serial or
* HTTP connection to remove
* @returns {void}
*/
removeConnection(connectionObj: DeviceInterface): void;
removeConnection(connectionObj: Types.ConnectionType): void;
}

@@ -5,10 +5,8 @@ import { IBLEConnection } from "./iBleConnection.js";

/**
* Allows to create new connections to devices and manages them.
* Alternatively, new connections can be created directly by instantiating
* their respective the interface classes.
* Allows to create new connections to devices and manages them. Alternatively,
* new connections can be created directly by instantiating their respective the
* interface classes.
*/
export class Client {
/**
* Array containing all created connection interfaces
*/
/** Array containing all created connection interfaces */
deviceInterfaces;

@@ -20,5 +18,8 @@ constructor() {

* Creates a new Bluetooth Low Enery connection interface
*
* @param {number} [configId] Desired instance config ID
* @returns {IBLEConnection} Resulting BLE connection object
*/
createBLEConnection() {
const iBLEConnection = new IBLEConnection();
createBLEConnection(configId) {
const iBLEConnection = new IBLEConnection(configId);
this.deviceInterfaces.push(iBLEConnection);

@@ -29,2 +30,5 @@ return iBLEConnection;

* Creates a new HTTP(S) connection interface
*
* @param {number} [configId] Desired instance config ID
* @returns {IHTTPConnection} Resulting HTTP connection object
*/

@@ -38,2 +42,5 @@ createHTTPConnection(configId) {

* Creates a new Serial connection interface
*
* @param {number} [configId] Desired instance config ID
* @returns {ISerialConnection} Resulting Serial connection object
*/

@@ -47,3 +54,6 @@ createSerialConnection(configId) {

* Adds an already created connection interface to the client
* @param connectionObj Desired Bluetooth, Serial or HTTP connection to add
*
* @param {Types.IConnectionType} connectionObj Desired BLE, Serial or HTTP
* connection to add
* @returns {void}
*/

@@ -55,3 +65,6 @@ addConnection(connectionObj) {

* Removes a connection interface from the client
* @param connectionObj Desired Bluetooth, Serial or HTTP connection to remove
*
* @param {Types.IConnectionType} connectionObj Desired Bluetooth, Serial or
* HTTP connection to remove
* @returns {void}
*/

@@ -58,0 +71,0 @@ removeConnection(connectionObj) {

@@ -0,25 +1,15 @@

/** Bluetooth Low Energy ToRadio characteristic */
export declare const toRadioUUID = "f75c76d2-129e-4dad-a1dd-7866124401e7";
/** Bluetooth Low Energy FromRadio characteristic */
export declare const fromRadioUUID = "8ba2bcc2-ee02-4a55-a531-c525c5e454d5";
/**
* Bluetooth Low Energy ToRadio characteristic
* Bluetooth Low Energy FromNum characteristic, provides BLE notification on new
* FromRadio message and a message counter
*/
export declare const TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7";
/**
* Bluetooth Low Energy FromRadio characteristic
*/
export declare const FROMRADIO_UUID = "8ba2bcc2-ee02-4a55-a531-c525c5e454d5";
/**
* Bluetooth Low Energy FromNum characteristic,
* provides BLE notification on new FromRadio message and a message counter
*/
export declare const FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453";
/**
* Bluetooth Service characteristic, used to identify Meshtastic devices
*/
export declare const SERVICE_UUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd";
/**
* Broadcast destination number
*/
export declare const BROADCAST_NUM = 4294967295;
/**
* Minimum device firmware version supported by this version of the library.
*/
export declare const MIN_FW_VERSION = 1.3;
export declare const fromNumUUID = "ed9da18c-a800-4f66-a670-aa7547e34453";
/** Bluetooth Service characteristic, used to identify Meshtastic devices */
export declare const serviceUUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd";
/** Broadcast destination number */
export declare const broadCastNum = 4294967295;
/** Minimum device firmware version supported by this version of the library. */
export declare const minFwVer = 1.3;

@@ -0,26 +1,16 @@

/** Bluetooth Low Energy ToRadio characteristic */
export const toRadioUUID = "f75c76d2-129e-4dad-a1dd-7866124401e7";
/** Bluetooth Low Energy FromRadio characteristic */
export const fromRadioUUID = "8ba2bcc2-ee02-4a55-a531-c525c5e454d5";
/**
* Bluetooth Low Energy ToRadio characteristic
* Bluetooth Low Energy FromNum characteristic, provides BLE notification on new
* FromRadio message and a message counter
*/
export const TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7";
/**
* Bluetooth Low Energy FromRadio characteristic
*/
export const FROMRADIO_UUID = "8ba2bcc2-ee02-4a55-a531-c525c5e454d5";
/**
* Bluetooth Low Energy FromNum characteristic,
* provides BLE notification on new FromRadio message and a message counter
*/
export const FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453";
/**
* Bluetooth Service characteristic, used to identify Meshtastic devices
*/
export const SERVICE_UUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd";
/**
* Broadcast destination number
*/
export const BROADCAST_NUM = 0xffffffff;
/**
* Minimum device firmware version supported by this version of the library.
*/
export const MIN_FW_VERSION = 1.3;
export const fromNumUUID = "ed9da18c-a800-4f66-a670-aa7547e34453";
/** Bluetooth Service characteristic, used to identify Meshtastic devices */
export const serviceUUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd";
/** Broadcast destination number */
export const broadCastNum = 0xffffffff;
/** Minimum device firmware version supported by this version of the library. */
export const minFwVer = 1.3;
//# sourceMappingURL=constants.js.map
/// <reference types="web-bluetooth" />
import { Types } from "./index.js";
import { IMeshDevice } from "./iMeshDevice.js";
import type { BLEConnectionParameters } from "./types.js";
/**
* Allows to connect to a Meshtastic device via bluetooth
*/
/** Allows to connect to a Meshtastic device via bluetooth */
export declare class IBLEConnection extends IMeshDevice {
/**
* Defines the connection type as ble
*/
/** Defines the connection type as ble */
connType: string;
/**
* Currently connected BLE device
*/
device: BluetoothDevice | void;
/**
* Short Description
*/
/** Currently connected BLE device */
device: BluetoothDevice | undefined;
/** Short Description */
service: BluetoothRemoteGATTService | undefined;
/**
* Short Description
*/
/** Short Description */
toRadioCharacteristic: BluetoothRemoteGATTCharacteristic | undefined;
/**
* Short Description
*/
/** Short Description */
fromRadioCharacteristic: BluetoothRemoteGATTCharacteristic | undefined;
/**
* Short Description
*/
/** Short Description */
fromNumCharacteristic: BluetoothRemoteGATTCharacteristic | undefined;
/**
* States if the device was force disconnected by a user
*/
/** States if the device was force disconnected by a user */
userInitiatedDisconnect: boolean;
/**
* Set when a read promise has yet to be resolved, to prevent simultaneous reads.
*/
constructor(configId?: number);
/**
* Gets web bluetooth support avaliability for the device
*
* @returns {Promise<void>}
*/

@@ -46,2 +29,4 @@ supported(): Promise<boolean>;

* Gets list of bluetooth devices that can be passed to `connect`
*
* @returns {Promise<BluetoothDevice[]>} Array of avaliable BLE devices
*/

@@ -51,2 +36,6 @@ getDevices(): Promise<BluetoothDevice[]>;

* Opens browser dialog to select a device
*
* @param {RequestDeviceOptions} [filter] Filter to apply to
* `navigator.bluetooth.requestDevice()`
* @returns {Promise<BluetoothDevice>} Returned BLE device
*/

@@ -56,22 +45,25 @@ getDevice(filter?: RequestDeviceOptions): Promise<BluetoothDevice>;

* Initiates the connect process to a Meshtastic device via Bluetooth
* @param parameters ble connection parameters
*
* @param {Types.BLEConnectionParameters} parameters Ble connection parameters
* @param {BluetoothDevice} parameters.device Externally obtained bluetooth
* device to use
* @param {RequestDeviceOptions} parameters.deviceFilter Device request filter
*/
connect({ device, deviceFilter }: BLEConnectionParameters): Promise<void>;
/**
* Disconnects from the Meshtastic device
*/
connect({ device, deviceFilter }: Types.BLEConnectionParameters): Promise<void>;
/** Disconnects from the Meshtastic device */
disconnect(): void;
/**
* Pings device to check if it is avaliable
* @todo implement
*
* @todo Implement
*/
ping(): Promise<boolean>;
/**
* Short description
*/
/** Short description */
protected readFromRadio(): Promise<void>;
/**
* Sends supplied protobuf message to the radio
*
* @param {Uint8Array} data Raw bytes to send to the radio
*/
protected writeToRadio(data: Uint8Array): Promise<void>;
}

@@ -1,42 +0,21 @@

import { Types } from "./index.js";
import { FROMNUM_UUID, FROMRADIO_UUID, SERVICE_UUID, TORADIO_UUID } from "./constants.js";
import { LogRecord_Level } from "./generated/mesh.js";
import { Protobuf, Types } from "./index.js";
import { fromNumUUID, fromRadioUUID, serviceUUID, toRadioUUID } from "./constants.js";
import { IMeshDevice } from "./iMeshDevice.js";
import { typedArrayToBuffer } from "./utils/general.js";
/**
* Allows to connect to a Meshtastic device via bluetooth
*/
/** Allows to connect to a Meshtastic device via bluetooth */
export class IBLEConnection extends IMeshDevice {
/**
* Defines the connection type as ble
*/
/** Defines the connection type as ble */
connType;
/**
* Currently connected BLE device
*/
/** Currently connected BLE device */
device;
/**
* Short Description
*/
/** Short Description */
service;
/**
* Short Description
*/
/** Short Description */
toRadioCharacteristic;
/**
* Short Description
*/
/** Short Description */
fromRadioCharacteristic;
/**
* Short Description
*/
/** Short Description */
fromNumCharacteristic;
/**
* States if the device was force disconnected by a user
*/
/** States if the device was force disconnected by a user */
userInitiatedDisconnect;
/**
* Set when a read promise has yet to be resolved, to prevent simultaneous reads.
*/
// pendingRead: boolean;
constructor(configId) {

@@ -55,2 +34,4 @@ super(configId);

* Gets web bluetooth support avaliability for the device
*
* @returns {Promise<void>}
*/

@@ -62,2 +43,4 @@ supported() {

* Gets list of bluetooth devices that can be passed to `connect`
*
* @returns {Promise<BluetoothDevice[]>} Array of avaliable BLE devices
*/

@@ -69,6 +52,10 @@ getDevices() {

* Opens browser dialog to select a device
*
* @param {RequestDeviceOptions} [filter] Filter to apply to
* `navigator.bluetooth.requestDevice()`
* @returns {Promise<BluetoothDevice>} Returned BLE device
*/
getDevice(filter) {
return navigator.bluetooth.requestDevice(filter ?? {
filters: [{ services: [SERVICE_UUID] }]
filters: [{ services: [serviceUUID] }]
});

@@ -78,35 +65,29 @@ }

* Initiates the connect process to a Meshtastic device via Bluetooth
* @param parameters ble connection parameters
*
* @param {Types.BLEConnectionParameters} parameters Ble connection parameters
* @param {BluetoothDevice} parameters.device Externally obtained bluetooth
* device to use
* @param {RequestDeviceOptions} parameters.deviceFilter Device request filter
*/
async connect({ device, deviceFilter }) {
/**
* Check for API avaliability
*/
/** Check for API avaliability */
if (!navigator.bluetooth) {
this.log(Types.EmitterScope.iBleConnection, Types.Emitter.connect, `This browser doesn't support the WebBluetooth API`, LogRecord_Level.WARNING);
this.log(Types.EmitterScope.iBleConnection, Types.Emitter.connect, `This browser doesn't support the WebBluetooth API`, Protobuf.LogRecord_Level.WARNING);
}
/**
* Set device state to connecting
*/
/** Set device state to connecting */
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONNECTING);
/**
* Set device if specified, else request.
*/
/** Set device if specified, else request. */
this.device = device ?? (await this.getDevice(deviceFilter));
/**
* Setup event listners
*/
/** Setup event listners */
this.device.addEventListener("gattserverdisconnected", () => {
this.log(Types.EmitterScope.iBleConnection, Types.Emitter.connect, "Device disconnected", LogRecord_Level.INFO);
this.log(Types.EmitterScope.iBleConnection, Types.Emitter.connect, "Device disconnected", Protobuf.LogRecord_Level.INFO);
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_DISCONNECTED);
this.complete();
});
/**
* Connect to device
*/
/** Connect to device */
await this.device.gatt?.connect();
this.service = await this.device.gatt?.getPrimaryService(SERVICE_UUID);
this.toRadioCharacteristic = await this.service?.getCharacteristic(TORADIO_UUID);
this.fromRadioCharacteristic = await this.service?.getCharacteristic(FROMRADIO_UUID);
this.fromNumCharacteristic = await this.service?.getCharacteristic(FROMNUM_UUID);
this.service = await this.device.gatt?.getPrimaryService(serviceUUID);
this.toRadioCharacteristic = await this.service?.getCharacteristic(toRadioUUID);
this.fromRadioCharacteristic = await this.service?.getCharacteristic(fromRadioUUID);
this.fromNumCharacteristic = await this.service?.getCharacteristic(fromNumUUID);
await this.fromNumCharacteristic?.startNotifications();

@@ -117,7 +98,5 @@ this.fromNumCharacteristic?.addEventListener("characteristicvaluechanged", () => {

this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONNECTED);
await this.configure();
this.configure();
}
/**
* Disconnects from the Meshtastic device
*/
/** Disconnects from the Meshtastic device */
disconnect() {

@@ -131,3 +110,4 @@ this.userInitiatedDisconnect = true;

* Pings device to check if it is avaliable
* @todo implement
*
* @todo Implement
*/

@@ -137,5 +117,3 @@ async ping() {

}
/**
* Short description
*/
/** Short description */
async readFromRadio() {

@@ -151,13 +129,11 @@ // if (this.pendingRead) {

.then((value) => {
if (value) {
readBuffer = value.buffer;
if (value.byteLength > 0) {
void this.handleFromRadio(new Uint8Array(readBuffer, 0));
}
readBuffer = value.buffer;
if (value.byteLength > 0) {
void this.handleFromRadio(new Uint8Array(readBuffer, 0));
}
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONNECTED);
})
.catch(({ message }) => {
.catch((e) => {
readBuffer = new ArrayBuffer(0);
this.log(Types.EmitterScope.iBleConnection, Types.Emitter.readFromRadio, message, LogRecord_Level.ERROR);
this.log(Types.EmitterScope.iBleConnection, Types.Emitter.readFromRadio, `❌ ${e.message}`, Protobuf.LogRecord_Level.ERROR);
});

@@ -169,2 +145,4 @@ }

* Sends supplied protobuf message to the radio
*
* @param {Uint8Array} data Raw bytes to send to the radio
*/

@@ -171,0 +149,0 @@ async writeToRadio(data) {

@@ -0,18 +1,10 @@

import { Types } from "./index.js";
import { IMeshDevice } from "./iMeshDevice.js";
import type { HTTPConnectionParameters } from "./types.js";
/**
* Allows to connect to a Meshtastic device over HTTP(S)
*/
/** Allows to connect to a Meshtastic device over HTTP(S) */
export declare class IHTTPConnection extends IMeshDevice {
/**
* Defines the connection type as http
*/
/** Defines the connection type as http */
connType: string;
/**
* URL of the device that is to be connected to.
*/
/** URL of the device that is to be connected to. */
url: string;
/**
* Enables receiving messages all at once, versus one per request
*/
/** Enables receiving messages all at once, versus one per request */
receiveBatchRequests: boolean;

@@ -25,21 +17,26 @@ readLoop: ReturnType<typeof setInterval> | null;

* Initiates the connect process to a Meshtastic device via HTTP(S)
* @param parameters http connection parameters
*
* @param {Types.HTTPConnectionParameters} parameters Http connection
* parameters
* @param {string} parameters.address IP/hostname to use
* @param {number} [parameters.fetchInterval=3000] How often to check for new
* packets. Default is `3000`
* @param {boolean} [parameters.receiveBatchRequests=false] Should packets be
* fetched individually or all at once. Default is `false`
* @param {boolean} [parameters.tls=false] Should TLS be used for requests.
* Default is `false`
*/
connect({ address, fetchInterval, receiveBatchRequests, tls }: HTTPConnectionParameters): Promise<void>;
/**
* Disconnects from the Meshtastic device
*/
connect({ address, fetchInterval, receiveBatchRequests, tls }: Types.HTTPConnectionParameters): Promise<void>;
/** Disconnects from the Meshtastic device */
disconnect(): void;
/**
* Pings device to check if it is avaliable
*/
/** Pings device to check if it is avaliable */
ping(): Promise<boolean>;
/**
* Reads any avaliable protobuf messages from the radio
*/
/** Reads any avaliable protobuf messages from the radio */
protected readFromRadio(): Promise<void>;
/**
* Sends supplied protobuf message to the radio
*
* @param {Uint8Array} data Raw bytes to send
*/
protected writeToRadio(data: Uint8Array): Promise<void>;
}

@@ -1,20 +0,11 @@

import { Types } from "./index.js";
import { LogRecord_Level } from "./generated/mesh.js";
import { Protobuf, Types } from "./index.js";
import { IMeshDevice } from "./iMeshDevice.js";
import { typedArrayToBuffer } from "./utils/general.js";
/**
* Allows to connect to a Meshtastic device over HTTP(S)
*/
/** Allows to connect to a Meshtastic device over HTTP(S) */
export class IHTTPConnection extends IMeshDevice {
/**
* Defines the connection type as http
*/
/** Defines the connection type as http */
connType;
/**
* URL of the device that is to be connected to.
*/
/** URL of the device that is to be connected to. */
url;
/**
* Enables receiving messages all at once, versus one per request
*/
/** Enables receiving messages all at once, versus one per request */
receiveBatchRequests;

@@ -35,17 +26,26 @@ readLoop;

* Initiates the connect process to a Meshtastic device via HTTP(S)
* @param parameters http connection parameters
*
* @param {Types.HTTPConnectionParameters} parameters Http connection
* parameters
* @param {string} parameters.address IP/hostname to use
* @param {number} [parameters.fetchInterval=3000] How often to check for new
* packets. Default is `3000`
* @param {boolean} [parameters.receiveBatchRequests=false] Should packets be
* fetched individually or all at once. Default is `false`
* @param {boolean} [parameters.tls=false] Should TLS be used for requests.
* Default is `false`
*/
async connect({ address, fetchInterval, receiveBatchRequests, tls }) {
async connect({ address, fetchInterval = 3000, receiveBatchRequests = false, tls = false }) {
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONNECTING);
this.receiveBatchRequests = !!receiveBatchRequests;
this.receiveBatchRequests = receiveBatchRequests;
this.url = `${tls ? "https://" : "http://"}${address}`;
if (this.deviceStatus === Types.DeviceStatusEnum.DEVICE_CONNECTING &&
(await this.ping())) {
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.connect, `Ping succeeded, starting configuration and request timer.`, LogRecord_Level.DEBUG);
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.connect, `Ping succeeded, starting configuration and request timer.`, Protobuf.LogRecord_Level.DEBUG);
this.configure();
this.readLoop = setInterval(() => {
this.readFromRadio().catch((e) => {
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.connect, e.message, LogRecord_Level.ERROR);
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.connect, `❌ ${e.message}`, Protobuf.LogRecord_Level.ERROR);
});
}, fetchInterval ? fetchInterval : 5000);
}, fetchInterval);
}

@@ -65,5 +65,3 @@ else {

}
/**
* Disconnects from the Meshtastic device
*/
/** Disconnects from the Meshtastic device */
disconnect() {

@@ -77,7 +75,5 @@ this.abortController.abort();

}
/**
* Pings device to check if it is avaliable
*/
/** Pings device to check if it is avaliable */
async ping() {
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.ping, `Attempting device ping.`, LogRecord_Level.DEBUG);
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.ping, `Attempting device ping.`, Protobuf.LogRecord_Level.DEBUG);
const { signal } = this.abortController;

@@ -90,5 +86,5 @@ let pingSuccessful = false;

})
.catch(({ message }) => {
.catch((e) => {
pingSuccessful = false;
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.ping, message, LogRecord_Level.ERROR);
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.ping, `❌ ${e.message}`, Protobuf.LogRecord_Level.ERROR);
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_RECONNECTING);

@@ -98,5 +94,3 @@ });

}
/**
* Reads any avaliable protobuf messages from the radio
*/
/** Reads any avaliable protobuf messages from the radio */
async readFromRadio() {

@@ -125,5 +119,5 @@ if (this.peningRequest) {

})
.catch(({ message }) => {
.catch((e) => {
this.peningRequest = false;
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.readFromRadio, message, LogRecord_Level.ERROR);
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.readFromRadio, `❌ ${e.message}`, Protobuf.LogRecord_Level.ERROR);
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_RECONNECTING);

@@ -135,2 +129,4 @@ });

* Sends supplied protobuf message to the radio
*
* @param {Uint8Array} data Raw bytes to send
*/

@@ -150,7 +146,7 @@ async writeToRadio(data) {

await this.readFromRadio().catch((e) => {
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.writeToRadio, e.message, LogRecord_Level.ERROR);
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.writeToRadio, `❌ ${e.message}`, Protobuf.LogRecord_Level.ERROR);
});
})
.catch(({ message }) => {
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.writeToRadio, message, LogRecord_Level.ERROR);
.catch((e) => {
this.log(Types.EmitterScope.iHttpConnection, Types.Emitter.writeToRadio, `❌ ${e.message}`, Protobuf.LogRecord_Level.ERROR);
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_RECONNECTING);

@@ -157,0 +153,0 @@ });

import { SubEvent } from "sub-events";
import type { Channel } from "./generated/channel.js";
import { User } from "./generated/mesh.js";
import { PortNum } from "./generated/portnums.js";
import { Protobuf, Types } from "./index.js";
import type { ConnectionParameters, LogEventPacket } from "./types.js";
import { Queue } from "./utils/queue.js";
/**
* Base class for connection methods to extend
*/
/** Base class for connection methods to extend */
export declare abstract class IMeshDevice {
/**
* Abstract property that states the connection type
*/
/** Abstract property that states the connection type */
protected abstract connType: string;
/**
* Logs to the console and the logging event emitter
*/
/** Logs to the console and the logging event emitter */
protected log: (scope: Types.EmitterScope, emitter: Types.Emitter, message: string, level: Protobuf.LogRecord_Level, packet?: Uint8Array) => void;
/**
* Describes the current state of the device
*/
/** Describes the current state of the device */
protected deviceStatus: Types.DeviceStatusEnum;
/**
* Describes the current state of the device
*/
/** Describes the current state of the device */
protected isConfigured: boolean;
/**
* Device's node number
*/
/** Device's node number */
private myNodeInfo;
/**
* Randomly generated number to ensure confiuration lockstep
*/
/** Randomly generated number to ensure confiuration lockstep */
configId: number;
/**
* Keeps track of all requests sent to the radio that have callbacks
* TODO: Update description
* Keeps track of all requests sent to the radio that have callbacks TODO:
* Update description
*/
queue: Queue;
constructor(configId?: number);
/**
* Abstract method that writes data to the radio
*/
/** Abstract method that writes data to the radio */
protected abstract writeToRadio(data: Uint8Array): Promise<void>;
/**
* Abstract method that connects to the radio
*/
protected abstract connect(parameters: ConnectionParameters): Promise<void>;
/**
* Abstract method that disconnects from the radio
*/
/** Abstract method that connects to the radio */
protected abstract connect(parameters: Types.ConnectionParameters): Promise<void>;
/** Abstract method that disconnects from the radio */
protected abstract disconnect(): void;
/**
* Abstract method that pings the radio
*/
/** Abstract method that pings the radio */
protected abstract ping(): Promise<boolean>;
/**
* Fires when a new FromRadio message has been received from the device
* @event
*
* @event onLogEvent
*/
readonly onLogEvent: SubEvent<LogEventPacket>;
readonly onLogEvent: SubEvent<Types.LogEventPacket>;
/**
* Fires when a new FromRadio message has been received from the device
* @event
*
* @event onFromRadio
*/
readonly onFromRadio: SubEvent<Protobuf.FromRadio>;
/**
* Fires when a new FromRadio message containing a Data packet has been received from the device
* @event
* Fires when a new FromRadio message containing a Data packet has been
* received from the device
*
* @event onMeshPacket
*/

@@ -75,12 +53,18 @@ readonly onMeshPacket: SubEvent<Protobuf.MeshPacket>;

* Fires when a new MyNodeInfo message has been received from the device
*
* @event onMyNodeInfo
*/
readonly onMyNodeInfo: SubEvent<Protobuf.MyNodeInfo>;
/**
* Fires when a new MeshPacket message containing a NodeInfo packet has been received from device
* @event
* Fires when a new MeshPacket message containing a NodeInfo packet has been
* received from device
*
* @event onNodeInfoPacket
*/
readonly onNodeInfoPacket: SubEvent<Types.NodeInfoPacket>;
/**
* Fires when a new MeshPacket message containing a User packet has been received from device
* @event
* Fires when a new MeshPacket message containing a User packet has been
* received from device
*
* @event onUserPacket
*/

@@ -90,3 +74,4 @@ readonly onUserPacket: SubEvent<Types.UserPacket>;

* Fires when a new Channel message is recieved
* @event
*
* @event onChannelPacket
*/

@@ -96,3 +81,4 @@ readonly onChannelPacket: SubEvent<Types.ChannelPacket>;

* Fires when a new Config message is recieved
* @event
*
* @event onConfigPacket
*/

@@ -102,68 +88,95 @@ readonly onConfigPacket: SubEvent<Types.ConfigPacket>;

* Fires when a new ModuleConfig message is recieved
* @event
*
* @event onModuleConfigPacket
*/
readonly onModuleConfigPacket: SubEvent<Types.ModuleConfigPacket>;
/**
* Fires when a new MeshPacket message containing a Ping packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Ping packet has been
* received from device
*
* @event onPingPacket
*/
readonly onPingPacket: SubEvent<Types.PingPacket>;
/**
* Fires when a new MeshPacket message containing a IP Tunnel packet has been received from device
* @event
* Fires when a new MeshPacket message containing a IP Tunnel packet has been
* received from device
*
* @event onIpTunnelPacket
*/
readonly onIpTunnelPacket: SubEvent<Types.IpTunnelPacket>;
/**
* Fires when a new MeshPacket message containing a Serial packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Serial packet has been
* received from device
*
* @event onSerialPacket
*/
readonly onSerialPacket: SubEvent<Types.SerialPacket>;
/**
* Fires when a new MeshPacket message containing a Store and Forward packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Store and Forward packet
* has been received from device
*
* @event onStoreForwardPacket
*/
readonly onStoreForwardPacket: SubEvent<Types.StoreForwardPacket>;
/**
* Fires when a new MeshPacket message containing a Store and Forward packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Store and Forward packet
* has been received from device
*
* @event onRangeTestPacket
*/
readonly onRangeTestPacket: SubEvent<Types.RangeTestPacket>;
/**
* Fires when a new MeshPacket message containing a Telemetry packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Telemetry packet has been
* received from device
*
* @event onTelemetryPacket
*/
readonly onTelemetryPacket: SubEvent<Types.TelemetryPacket>;
/**
* Fires when a new MeshPacket message containing a Private packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Private packet has been
* received from device
*
* @event onPrivatePacket
*/
readonly onPrivatePacket: SubEvent<Types.PrivatePacket>;
/**
* Fires when a new MeshPacket message containing a ATAK packet has been received from device
* @event
* Fires when a new MeshPacket message containing a ATAK packet has been
* received from device
*
* @event onAtakPacket
*/
readonly onAtakPacket: SubEvent<Types.AtakPacket>;
/**
* Fires when a new MeshPacket message containing a Routing packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Routing packet has been
* received from device
*
* @event onRoutingPacket
*/
readonly onRoutingPacket: SubEvent<Types.RoutingPacket>;
/**
* Fires when a new MeshPacket message containing a Position packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Position packet has been
* received from device
*
* @event onPositionPacket
*/
readonly onPositionPacket: SubEvent<Types.PositionPacket>;
/**
* Fires when a new MeshPacket message containing a Text packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Text packet has been
* received from device
*
* @event onMessagePacket
*/
readonly onMessagePacket: SubEvent<Types.MessagePacket>;
/**
* Fires when a new MeshPacket message containing a Remote Hardware packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Remote Hardware packet has
* been received from device
*
* @event onRemoteHardwarePacket
*/
readonly onRemoteHardwarePacket: SubEvent<Types.RemoteHardwarePacket>;
/**
* Fires when a new MeshPacket message containing a Waypoint packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Waypoint packet has been
* received from device
*
* @event onWaypointPacket
*/

@@ -173,8 +186,11 @@ readonly onWaypointPacket: SubEvent<Types.WaypointPacket>;

* Fires when the devices connection or configuration status changes
* @event
*
* @event onDeviceStatus
*/
readonly onDeviceStatus: SubEvent<Types.DeviceStatusEnum>;
/**
* Fires when a new FromRadio message containing a Text packet has been received from device
* @event
* Fires when a new FromRadio message containing a Text packet has been
* received from device
*
* @event onLogRecord
*/

@@ -184,3 +200,4 @@ readonly onLogRecord: SubEvent<Protobuf.LogRecord>;

* Fires when the device receives a meshPacket, returns a timestamp
* @event
*
* @event onMeshHeartbeat
*/

@@ -190,2 +207,4 @@ readonly onMeshHeartbeat: SubEvent<Date>;

* Fires when the device receives a Metadata packet
*
* @event onDeviceMetadataPacket
*/

@@ -195,34 +214,52 @@ readonly onDeviceMetadataPacket: SubEvent<Types.DeviceMetadataPacket>;

* Sends a text over the radio
* @param text
* @param destinationNum Node number of the destination node
* @param wantAck Whether or not acknowledgement is wanted
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {string} text Message to send
* @param {number} [destinationNum] Node number of the destination node
* @param {boolean} [wantAck=false] Whether or not acknowledgement is wanted.
* Default is `false`
* @param {Types.channelNumber} [channel=0] Channel number to send to. Default
* is `0`. Default is `0`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @returns {Promise<void>}
*/
sendText(text: string, destinationNum?: number, wantAck?: boolean, channel?: number, callback?: (id: number) => Promise<void>): Promise<void>;
sendText(text: string, destinationNum?: number, wantAck?: boolean, channel?: Types.ChannelNumber, callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Sends a text over the radio
* @param waypoint Desired waypoint to send
* @param destinationNum Node number of the destination node
* @param wantAck Whether or not acknowledgement is wanted
* @param channel channel to send on default of 0
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.Waypoint} waypoint Desired waypoint to send
* @param {number} destinationNum Node number of the destination node
* @param {boolean} wantAck Whether or not acknowledgement is wanted
* @param {Types.ChannelNumber} channel Channel to send on default of 0
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @returns {Promise<void>}
*/
sendWaypoint(waypoint: Protobuf.Waypoint, destinationNum?: number, wantAck?: boolean, channel?: number, callback?: (id: number) => Promise<void>): Promise<void>;
sendWaypoint(waypoint: Protobuf.Waypoint, destinationNum?: number, wantAck?: boolean, channel?: Types.ChannelNumber, callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Sends packet over the radio
* @param byteData
* @param portNum dataType Enum of protobuf data type
* @param destinationNum Node number of the destination node
* @param wantAck Whether or not acknowledgement is wanted
* @param channel channel to send on default of 0
* @param wantResponse Used for testing, requests recpipient to respond in kind with the same type of request
* @param echoResponse Sends event back to client
* @param callback If wantAck is true, callback is called when the ack is received
* @param emoji used for message reactions
* @param replyId used to reply to a message
*
* @param {Uint8Array} byteData Raw bytes to send
* @param {Protobuf.PortNum} portNum DataType Enum of protobuf data type
* @param {number} [destinationNum] Node number of the destination node
* @param {boolean} [wantAck=false] Whether or not acknowledgement is wanted.
* Default is `false`
* @param {Types.ChannelNumber} [channel=0] Channel to send. Default is `0`
* @param {boolean} [wantResponse=false] Used for testing, requests recpipient
* to respond in kind with the same type of request. Default is `false`
* @param {boolean} [echoResponse=false] Sends event back to client. Default
* is `false`. Default is `false`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @param {number} [emoji=0] Used for message reactions. Default is `0`
* @param {number} [replyId=0] Used to reply to a message. Default is `0`
*/
sendPacket(byteData: Uint8Array, portNum: PortNum, destinationNum?: number, wantAck?: boolean, channel?: number, wantResponse?: boolean, echoResponse?: boolean, callback?: (id: number) => Promise<void>, emoji?: number, replyId?: number): Promise<void>;
sendPacket(byteData: Uint8Array, portNum: Protobuf.PortNum, destinationNum?: number, wantAck?: boolean, channel?: Types.ChannelNumber, wantResponse?: boolean, echoResponse?: boolean, callback?: (id: number) => Promise<void>, emoji?: number, replyId?: number): Promise<void>;
/**
* Sends raw packet over the radio
* @param toRadio binary data to send
*
* @param {number} id Unique packet ID
* @param {Uint8Array} toRadio Binary data to send
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/

@@ -232,4 +269,6 @@ sendRaw(id: number, toRadio: Uint8Array, callback?: (id: number) => Promise<void>): Promise<void>;

* Writes config to device
* @param config config object
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.Config} config Config object
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/

@@ -239,9 +278,14 @@ setConfig(config: Protobuf.Config, callback?: (id: number) => Promise<void>): Promise<void>;

* Writes module config to device
* @param config module config object
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.ModuleConfig} config Module config object
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
setModuleConfig(config: Protobuf.ModuleConfig, callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Confirms the currently set config, and prevents changes from reverting after 10 minutes.
* @param callback If wantAck is true, callback is called when the ack is received
* Confirms the currently set config, and prevents changes from reverting
* after 10 minutes.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/

@@ -251,31 +295,38 @@ confirmSetConfig(callback?: (id: number) => Promise<void>): Promise<void>;

* Sets devices owner data
* @param owner Owner data to apply to the device
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.User} owner Owner data to apply to the device
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
setOwner(owner: User, callback?: (id: number) => Promise<void>): Promise<void>;
setOwner(owner: Protobuf.User, callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Sets devices ChannelSettings
* @param channel Channel data to be set
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.Channel} channel Channel data to be set
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
setChannel(channel: Channel, callback?: (id: number) => Promise<void>): Promise<void>;
setChannel(channel: Protobuf.Channel, callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Confirms the currently set channels, and prevents changes from reverting after 10 minutes.
* @param callback If wantAck is true, callback is called when the ack is received
* Confirms the currently set channels, and prevents changes from reverting
* after 10 minutes.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
confirmSetChannel(callback?: (id: number) => Promise<void>): Promise<void>;
/**
* @TODO
* Is this needed?
* Clears specific channel with the designated index
*
* @param {number} index Channel index to be cleared
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
clearChannel(index: number, callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Deletes specific channel via index
* @param index Channel index to be deleted
* @param callback If wantAck is true, callback is called when the ack is received
*/
deleteChannel(index: number, callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Gets specified channel information from the radio
* @param index Channel index to be retrieved
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {number} index Channel index to be retrieved
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/

@@ -285,3 +336,5 @@ getChannel(index: number, callback?: (id: number) => Promise<void>): Promise<void>;

* Gets all of the devices channels
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/

@@ -291,13 +344,23 @@ getAllChannels(callback?: () => Promise<void>): Promise<void>;

* Gets devices config
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.AdminMessage_ConfigType} configType Desired config type to
* request
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
getConfig(configType: Protobuf.AdminMessage_ConfigType, callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Gets devices config
* @param callback If wantAck is true, callback is called when the ack is received
* Gets Module config
*
* @param {Protobuf.AdminMessage_ModuleConfigType} moduleConfigType Desired
* module config type to request
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
getModuleConfig(configType: Protobuf.AdminMessage_ModuleConfigType, callback?: (id: number) => Promise<void>): Promise<void>;
getModuleConfig(moduleConfigType: Protobuf.AdminMessage_ModuleConfigType, callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Gets devices Owner
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/

@@ -307,12 +370,21 @@ getOwner(callback?: (id: number) => Promise<void>): Promise<void>;

* Gets devices metadata
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
getMetadata(callback?: (id: number) => Promise<void>): Promise<void>;
/**
* Triggers the device configure process
* Resets the internal NodeDB of the radio, usefull for removing old nodes
* that no longer exist.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
resetPeers(callback?: (id: number) => Promise<void>): Promise<void>;
/** Triggers the device configure process */
configure(): void;
/**
* Updates the device status eliminating duplicate status events
* @param status
*
* @param {Types.DeviceStatusEnum} status New device status
*/

@@ -322,16 +394,19 @@ updateDeviceStatus(status: Types.DeviceStatusEnum): void;

* Generates random packet identifier
*
* @returns {number} Random packet ID
*/
private generateRandId;
/**
* Gets called whenever a fromRadio message is received from device, returns fromRadio data
* @param fromRadio Uint8Array containing raw radio data
* Gets called whenever a fromRadio message is received from device, returns
* fromRadio data
*
* @param {Uint8Array} fromRadio Uint8Array containing raw radio data
*/
protected handleFromRadio(fromRadio: Uint8Array): Promise<void>;
/**
* Completes all SubEvents
*/
/** Completes all SubEvents */
complete(): void;
/**
* Gets called when a MeshPacket is received from device
* @param meshPacket
*
* @param {Protobuf.MeshPacket} meshPacket Packet to process
*/

@@ -338,0 +413,0 @@ private handleMeshPacket;

import { SubEvent } from "sub-events";
import { BROADCAST_NUM, MIN_FW_VERSION } from "./constants.js";
import { AdminMessage } from "./generated/admin.js";
import { FromRadio, LogRecord_Level, MeshPacket, MyNodeInfo, Position, Routing, ToRadio, User, Waypoint } from "./generated/mesh.js";
import { PortNum } from "./generated/portnums.js";
import { broadCastNum, minFwVer } from "./constants.js";
import { Protobuf, Types } from "./index.js";
import { log } from "./utils/logging.js";
import { Queue } from "./utils/queue.js";
/**
* Base class for connection methods to extend
*/
/** Base class for connection methods to extend */
export class IMeshDevice {
/**
* Logs to the console and the logging event emitter
*/
/** Logs to the console and the logging event emitter */
log;
/**
* Describes the current state of the device
*/
/** Describes the current state of the device */
deviceStatus;
/**
* Describes the current state of the device
*/
/** Describes the current state of the device */
isConfigured;
/**
* Device's node number
*/
/** Device's node number */
myNodeInfo;
/**
* Randomly generated number to ensure confiuration lockstep
*/
/** Randomly generated number to ensure confiuration lockstep */
configId;
/**
* Keeps track of all requests sent to the radio that have callbacks
* TODO: Update description
* Keeps track of all requests sent to the radio that have callbacks TODO:
* Update description
*/

@@ -52,3 +37,3 @@ queue;

this.isConfigured = false;
this.myNodeInfo = MyNodeInfo.create();
this.myNodeInfo = Protobuf.MyNodeInfo.create();
this.configId = configId ?? this.generateRandId();

@@ -69,3 +54,4 @@ this.queue = new Queue();

* Fires when a new FromRadio message has been received from the device
* @event
*
* @event onLogEvent
*/

@@ -75,8 +61,11 @@ onLogEvent = new SubEvent();

* Fires when a new FromRadio message has been received from the device
* @event
*
* @event onFromRadio
*/
onFromRadio = new SubEvent();
/**
* Fires when a new FromRadio message containing a Data packet has been received from the device
* @event
* Fires when a new FromRadio message containing a Data packet has been
* received from the device
*
* @event onMeshPacket
*/

@@ -86,12 +75,18 @@ onMeshPacket = new SubEvent();

* Fires when a new MyNodeInfo message has been received from the device
*
* @event onMyNodeInfo
*/
onMyNodeInfo = new SubEvent();
/**
* Fires when a new MeshPacket message containing a NodeInfo packet has been received from device
* @event
* Fires when a new MeshPacket message containing a NodeInfo packet has been
* received from device
*
* @event onNodeInfoPacket
*/
onNodeInfoPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a User packet has been received from device
* @event
* Fires when a new MeshPacket message containing a User packet has been
* received from device
*
* @event onUserPacket
*/

@@ -101,3 +96,4 @@ onUserPacket = new SubEvent();

* Fires when a new Channel message is recieved
* @event
*
* @event onChannelPacket
*/

@@ -107,3 +103,4 @@ onChannelPacket = new SubEvent();

* Fires when a new Config message is recieved
* @event
*
* @event onConfigPacket
*/

@@ -113,68 +110,95 @@ onConfigPacket = new SubEvent();

* Fires when a new ModuleConfig message is recieved
* @event
*
* @event onModuleConfigPacket
*/
onModuleConfigPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Ping packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Ping packet has been
* received from device
*
* @event onPingPacket
*/
onPingPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a IP Tunnel packet has been received from device
* @event
* Fires when a new MeshPacket message containing a IP Tunnel packet has been
* received from device
*
* @event onIpTunnelPacket
*/
onIpTunnelPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Serial packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Serial packet has been
* received from device
*
* @event onSerialPacket
*/
onSerialPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Store and Forward packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Store and Forward packet
* has been received from device
*
* @event onStoreForwardPacket
*/
onStoreForwardPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Store and Forward packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Store and Forward packet
* has been received from device
*
* @event onRangeTestPacket
*/
onRangeTestPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Telemetry packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Telemetry packet has been
* received from device
*
* @event onTelemetryPacket
*/
onTelemetryPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Private packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Private packet has been
* received from device
*
* @event onPrivatePacket
*/
onPrivatePacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a ATAK packet has been received from device
* @event
* Fires when a new MeshPacket message containing a ATAK packet has been
* received from device
*
* @event onAtakPacket
*/
onAtakPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Routing packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Routing packet has been
* received from device
*
* @event onRoutingPacket
*/
onRoutingPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Position packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Position packet has been
* received from device
*
* @event onPositionPacket
*/
onPositionPacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Text packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Text packet has been
* received from device
*
* @event onMessagePacket
*/
onMessagePacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Remote Hardware packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Remote Hardware packet has
* been received from device
*
* @event onRemoteHardwarePacket
*/
onRemoteHardwarePacket = new SubEvent();
/**
* Fires when a new MeshPacket message containing a Waypoint packet has been received from device
* @event
* Fires when a new MeshPacket message containing a Waypoint packet has been
* received from device
*
* @event onWaypointPacket
*/

@@ -184,8 +208,11 @@ onWaypointPacket = new SubEvent();

* Fires when the devices connection or configuration status changes
* @event
*
* @event onDeviceStatus
*/
onDeviceStatus = new SubEvent();
/**
* Fires when a new FromRadio message containing a Text packet has been received from device
* @event
* Fires when a new FromRadio message containing a Text packet has been
* received from device
*
* @event onLogRecord
*/

@@ -195,3 +222,4 @@ onLogRecord = new SubEvent();

* Fires when the device receives a meshPacket, returns a timestamp
* @event
*
* @event onMeshHeartbeat
*/

@@ -201,2 +229,4 @@ onMeshHeartbeat = new SubEvent();

* Fires when the device receives a Metadata packet
*
* @event onDeviceMetadataPacket
*/

@@ -206,40 +236,54 @@ onDeviceMetadataPacket = new SubEvent();

* Sends a text over the radio
* @param text
* @param destinationNum Node number of the destination node
* @param wantAck Whether or not acknowledgement is wanted
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {string} text Message to send
* @param {number} [destinationNum] Node number of the destination node
* @param {boolean} [wantAck=false] Whether or not acknowledgement is wanted.
* Default is `false`
* @param {Types.channelNumber} [channel=0] Channel number to send to. Default
* is `0`. Default is `0`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @returns {Promise<void>}
*/
sendText(text, destinationNum, wantAck = false, channel = 0, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.sendText, `📤 Sending message to ${destinationNum ?? "broadcast"} on channel ${channel}`, LogRecord_Level.DEBUG);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.sendText, `📤 Sending message to ${destinationNum ?? "broadcast"} on channel ${channel.toString()}`, Protobuf.LogRecord_Level.DEBUG);
const enc = new TextEncoder();
return this.sendPacket(enc.encode(text), PortNum.TEXT_MESSAGE_APP, destinationNum, wantAck, channel, undefined, true, callback);
return this.sendPacket(enc.encode(text), Protobuf.PortNum.TEXT_MESSAGE_APP, destinationNum, wantAck, channel, undefined, true, callback);
}
/**
* Sends a text over the radio
* @param waypoint Desired waypoint to send
* @param destinationNum Node number of the destination node
* @param wantAck Whether or not acknowledgement is wanted
* @param channel channel to send on default of 0
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.Waypoint} waypoint Desired waypoint to send
* @param {number} destinationNum Node number of the destination node
* @param {boolean} wantAck Whether or not acknowledgement is wanted
* @param {Types.ChannelNumber} channel Channel to send on default of 0
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @returns {Promise<void>}
*/
sendWaypoint(waypoint, destinationNum, wantAck = false, channel = 0, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.sendWaypoint, `📤 Sending waypoint to ${destinationNum ?? "broadcast"} on channel ${channel}`, LogRecord_Level.DEBUG);
return this.sendPacket(Waypoint.toBinary(waypoint), PortNum.WAYPOINT_APP, destinationNum, wantAck, channel, undefined, true, callback, undefined);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.sendWaypoint, `📤 Sending waypoint to ${destinationNum ?? "broadcast"} on channel ${channel.toString()}`, Protobuf.LogRecord_Level.DEBUG);
return this.sendPacket(Protobuf.Waypoint.toBinary(waypoint), Protobuf.PortNum.WAYPOINT_APP, destinationNum, wantAck, channel, undefined, true, callback, undefined);
}
/**
* Sends packet over the radio
* @param byteData
* @param portNum dataType Enum of protobuf data type
* @param destinationNum Node number of the destination node
* @param wantAck Whether or not acknowledgement is wanted
* @param channel channel to send on default of 0
* @param wantResponse Used for testing, requests recpipient to respond in kind with the same type of request
* @param echoResponse Sends event back to client
* @param callback If wantAck is true, callback is called when the ack is received
* @param emoji used for message reactions
* @param replyId used to reply to a message
*
* @param {Uint8Array} byteData Raw bytes to send
* @param {Protobuf.PortNum} portNum DataType Enum of protobuf data type
* @param {number} [destinationNum] Node number of the destination node
* @param {boolean} [wantAck=false] Whether or not acknowledgement is wanted.
* Default is `false`
* @param {Types.ChannelNumber} [channel=0] Channel to send. Default is `0`
* @param {boolean} [wantResponse=false] Used for testing, requests recpipient
* to respond in kind with the same type of request. Default is `false`
* @param {boolean} [echoResponse=false] Sends event back to client. Default
* is `false`. Default is `false`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @param {number} [emoji=0] Used for message reactions. Default is `0`
* @param {number} [replyId=0] Used to reply to a message. Default is `0`
*/
async sendPacket(byteData, portNum, destinationNum, wantAck = false, channel = 0, wantResponse = false, echoResponse = false, callback, emoji = 0, replyId = 0) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.sendPacket, `📤 Sending ${Protobuf.PortNum[portNum] ?? "UNK"} to ${destinationNum ?? "broadcast"}`, LogRecord_Level.TRACE);
const meshPacket = MeshPacket.create({
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.sendPacket, `📤 Sending ${Protobuf.PortNum[portNum] ?? "UNK"} to ${destinationNum ?? "broadcast"}`, Protobuf.LogRecord_Level.TRACE);
const meshPacket = Protobuf.MeshPacket.create({
payloadVariant: {

@@ -259,3 +303,3 @@ decoded: {

from: this.myNodeInfo.myNodeNum,
to: destinationNum ? destinationNum : BROADCAST_NUM,
to: destinationNum ? destinationNum : broadCastNum,
id: this.generateRandId(),

@@ -265,3 +309,3 @@ wantAck: wantAck,

});
const toRadio = ToRadio.toBinary(ToRadio.create({
const toRadio = Protobuf.ToRadio.toBinary({
payloadVariant: {

@@ -271,3 +315,3 @@ packet: meshPacket,

}
}));
});
if (echoResponse) {

@@ -280,7 +324,11 @@ await this.handleMeshPacket(meshPacket);

* Sends raw packet over the radio
* @param toRadio binary data to send
*
* @param {number} id Unique packet ID
* @param {Uint8Array} toRadio Binary data to send
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async sendRaw(id, toRadio, callback) {
if (toRadio.length > 512) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.sendRaw, `Message longer than 512 bytes, it will not be sent!`, LogRecord_Level.WARNING);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.sendRaw, `Message longer than 512 bytes, it will not be sent!`, Protobuf.LogRecord_Level.WARNING);
}

@@ -304,7 +352,9 @@ else {

* Writes config to device
* @param config config object
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.Config} config Config object
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async setConfig(config, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.setConfig, `Setting config ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.setConfig, `Setting config ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
let configType;

@@ -334,3 +384,3 @@ switch (config.payloadVariant.oneofKind) {

}
const setRadio = AdminMessage.toBinary(AdminMessage.create({
const setRadio = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -340,6 +390,6 @@ oneofKind: "setConfig",

}
}));
await this.sendPacket(setRadio, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
});
await this.sendPacket(setRadio, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
await this.getConfig(configType);
callback && callback(id);
await callback?.(id);
});

@@ -349,7 +399,9 @@ }

* Writes module config to device
* @param config module config object
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.ModuleConfig} config Module config object
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async setModuleConfig(config, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.setModuleConfig, `Setting module config ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.setModuleConfig, `Setting module config ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
let configType;

@@ -379,3 +431,3 @@ switch (config.payloadVariant.oneofKind) {

}
const setRadio = AdminMessage.toBinary(AdminMessage.create({
const setRadio = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -385,15 +437,18 @@ oneofKind: "setModuleConfig",

}
}));
await this.sendPacket(setRadio, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
});
await this.sendPacket(setRadio, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
await this.getModuleConfig(configType);
callback && callback(id);
await callback?.(id);
});
}
/**
* Confirms the currently set config, and prevents changes from reverting after 10 minutes.
* @param callback If wantAck is true, callback is called when the ack is received
* Confirms the currently set config, and prevents changes from reverting
* after 10 minutes.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async confirmSetConfig(callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.confirmSetConfig, `Confirming config ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
const confirmSetRadio = AdminMessage.toBinary(AdminMessage.create({
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.confirmSetConfig, `Confirming config ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const confirmSetRadio = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -403,13 +458,15 @@ confirmSetRadio: true,

}
}));
await this.sendPacket(confirmSetRadio, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
});
await this.sendPacket(confirmSetRadio, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
}
/**
* Sets devices owner data
* @param owner Owner data to apply to the device
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.User} owner Owner data to apply to the device
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async setOwner(owner, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.setOwner, `Setting owner ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
const setOwner = AdminMessage.toBinary(AdminMessage.create({
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.setOwner, `Setting owner ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const setOwner = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -419,6 +476,6 @@ setOwner: owner,

}
}));
await this.sendPacket(setOwner, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
});
await this.sendPacket(setOwner, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
await this.getOwner();
callback && callback(id);
await callback?.(id);
});

@@ -428,8 +485,10 @@ }

* Sets devices ChannelSettings
* @param channel Channel data to be set
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.Channel} channel Channel data to be set
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async setChannel(channel, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.setChannel, `📻 Setting Channel: ${channel.index} ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
const setChannel = AdminMessage.toBinary(AdminMessage.create({
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.setChannel, `📻 Setting Channel: ${channel.index} ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const setChannel = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -439,15 +498,18 @@ setChannel: channel,

}
}));
await this.sendPacket(setChannel, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
});
await this.sendPacket(setChannel, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
await this.getChannel(channel.index);
callback && callback(id);
await callback?.(id);
});
}
/**
* Confirms the currently set channels, and prevents changes from reverting after 10 minutes.
* @param callback If wantAck is true, callback is called when the ack is received
* Confirms the currently set channels, and prevents changes from reverting
* after 10 minutes.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async confirmSetChannel(callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.confirmSetChannel, `📻 Confirming Channel config ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
const confirmSetChannel = AdminMessage.toBinary(AdminMessage.create({
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.confirmSetChannel, `📻 Confirming Channel config ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const confirmSetChannel = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -457,16 +519,14 @@ confirmSetRadio: true,

}
}));
await this.sendPacket(confirmSetChannel, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
});
await this.sendPacket(confirmSetChannel, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
}
/**
* @TODO
* Is this needed?
* Clears specific channel with the designated index
*
* @param {number} index Channel index to be cleared
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
/**
* Deletes specific channel via index
* @param index Channel index to be deleted
* @param callback If wantAck is true, callback is called when the ack is received
*/
async deleteChannel(index, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.deleteChannel, `📻 Deleting Channel ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
async clearChannel(index, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.clearChannel, `📻 Clearing Channel ${index} ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const channel = Protobuf.Channel.create({

@@ -476,3 +536,3 @@ index,

});
const setChannel = AdminMessage.toBinary(AdminMessage.create({
const setChannel = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -482,6 +542,6 @@ setChannel: channel,

}
}));
await this.sendPacket(setChannel, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
});
await this.sendPacket(setChannel, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
await this.getChannel(channel.index);
callback && callback(id);
await callback?.(id);
});

@@ -491,8 +551,10 @@ }

* Gets specified channel information from the radio
* @param index Channel index to be retrieved
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {number} index Channel index to be retrieved
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getChannel(index, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getChannel, `📻 Requesting Channel: ${index} ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
const getChannelRequest = AdminMessage.toBinary(AdminMessage.create({
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getChannel, `📻 Requesting Channel: ${index} ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const getChannelRequest = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -502,11 +564,13 @@ getChannelRequest: index + 1,

}
}));
await this.sendPacket(getChannelRequest, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
});
await this.sendPacket(getChannelRequest, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
}
/**
* Gets all of the devices channels
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getAllChannels(callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getAllChannels, `📻 Requesting all Channels ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getAllChannels, `📻 Requesting all Channels ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
// TODO: Use device queue now.

@@ -521,11 +585,15 @@ const queue = [];

await Promise.all(queue);
callback && callback();
await callback?.();
}
/**
* Gets devices config
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {Protobuf.AdminMessage_ConfigType} configType Desired config type to
* request
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getConfig(configType, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getConfig, `Requesting config ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
const getRadioRequest = AdminMessage.toBinary(AdminMessage.create({
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getConfig, `Requesting config ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const getRadioRequest = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -535,26 +603,32 @@ oneofKind: "getConfigRequest",

}
}));
await this.sendPacket(getRadioRequest, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
});
await this.sendPacket(getRadioRequest, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
}
/**
* Gets devices config
* @param callback If wantAck is true, callback is called when the ack is received
* Gets Module config
*
* @param {Protobuf.AdminMessage_ModuleConfigType} moduleConfigType Desired
* module config type to request
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getModuleConfig(configType, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getModuleConfig, `Requesting module config ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
const getRadioRequest = AdminMessage.toBinary(AdminMessage.create({
async getModuleConfig(moduleConfigType, callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getModuleConfig, `Requesting module config ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const getRadioRequest = Protobuf.AdminMessage.toBinary({
payloadVariant: {
oneofKind: "getModuleConfigRequest",
getModuleConfigRequest: configType
getModuleConfigRequest: moduleConfigType
}
}));
await this.sendPacket(getRadioRequest, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
});
await this.sendPacket(getRadioRequest, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
}
/**
* Gets devices Owner
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getOwner(callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getOwner, `Requesting owner ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
const getOwnerRequest = AdminMessage.toBinary(AdminMessage.create({
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getOwner, `Requesting owner ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const getOwnerRequest = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -564,12 +638,14 @@ getOwnerRequest: true,

}
}));
await this.sendPacket(getOwnerRequest, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
});
await this.sendPacket(getOwnerRequest, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
}
/**
* Gets devices metadata
* @param callback If wantAck is true, callback is called when the ack is received
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getMetadata(callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getMetadata, `Requesting owner ${callback ? "with" : "without"} callback`, LogRecord_Level.DEBUG);
const getDeviceMetricsRequest = AdminMessage.toBinary(AdminMessage.create({
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.getMetadata, `Requesting owner ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const getDeviceMetricsRequest = Protobuf.AdminMessage.toBinary({
payloadVariant: {

@@ -579,13 +655,30 @@ getDeviceMetadataRequest: 0,

}
}));
await this.sendPacket(getDeviceMetricsRequest, PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
});
await this.sendPacket(getDeviceMetricsRequest, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, callback);
}
/**
* Triggers the device configure process
* Resets the internal NodeDB of the radio, usefull for removing old nodes
* that no longer exist.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async resetPeers(callback) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.resetPeers, `📻 Resetting Peers ${callback ? "with" : "without"} callback`, Protobuf.LogRecord_Level.DEBUG);
const resetPeers = Protobuf.AdminMessage.toBinary({
payloadVariant: {
nodedbReset: 1,
oneofKind: "nodedbReset"
}
});
await this.sendPacket(resetPeers, Protobuf.PortNum.ADMIN_APP, this.myNodeInfo.myNodeNum, true, 0, true, false, async (id) => {
callback && (await callback(id));
});
}
/** Triggers the device configure process */
configure() {
// TODO: this not always logged
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.configure, `⚙️ Requesting device configuration`, LogRecord_Level.DEBUG);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.configure, `⚙️ Requesting device configuration`, Protobuf.LogRecord_Level.DEBUG);
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONFIGURING);
const toRadio = ToRadio.toBinary(ToRadio.create({
const toRadio = Protobuf.ToRadio.toBinary({
payloadVariant: {

@@ -595,3 +688,3 @@ wantConfigId: this.configId,

}
}));
});
setTimeout(() => {

@@ -603,3 +696,4 @@ void this.sendRaw(0, toRadio);

* Updates the device status eliminating duplicate status events
* @param status
*
* @param {Types.DeviceStatusEnum} status New device status
*/

@@ -613,2 +707,4 @@ updateDeviceStatus(status) {

* Generates random packet identifier
*
* @returns {number} Random packet ID
*/

@@ -619,11 +715,11 @@ generateRandId() {

/**
* Gets called whenever a fromRadio message is received from device, returns fromRadio data
* @param fromRadio Uint8Array containing raw radio data
* Gets called whenever a fromRadio message is received from device, returns
* fromRadio data
*
* @param {Uint8Array} fromRadio Uint8Array containing raw radio data
*/
async handleFromRadio(fromRadio) {
const decodedMessage = FromRadio.fromBinary(fromRadio);
const decodedMessage = Protobuf.FromRadio.fromBinary(fromRadio);
this.onFromRadio.emit(decodedMessage);
/**
* @todo add map here when `all=true` gets fixed.
*/
/** @todo Add map here when `all=true` gets fixed. */
switch (decodedMessage.payloadVariant.oneofKind) {

@@ -635,12 +731,12 @@ case "packet":

if (parseFloat(decodedMessage.payloadVariant.myInfo.firmwareVersion) <
MIN_FW_VERSION) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, `Device firmware outdated. Min supported: ${MIN_FW_VERSION} got : ${decodedMessage.payloadVariant.myInfo.firmwareVersion}`, LogRecord_Level.CRITICAL);
minFwVer) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, `Device firmware outdated. Min supported: ${minFwVer} got : ${decodedMessage.payloadVariant.myInfo.firmwareVersion}`, Protobuf.LogRecord_Level.CRITICAL);
}
this.onMyNodeInfo.emit(decodedMessage.payloadVariant.myInfo);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, "📱 Received Node info for this device", LogRecord_Level.TRACE);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, "📱 Received Node info for this device", Protobuf.LogRecord_Level.TRACE);
break;
case "nodeInfo":
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, `📱 Received Node Info packet for node: ${decodedMessage.payloadVariant.nodeInfo.num}`, LogRecord_Level.TRACE);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, `📱 Received Node Info packet for node: ${decodedMessage.payloadVariant.nodeInfo.num}`, Protobuf.LogRecord_Level.TRACE);
this.onNodeInfoPacket.emit({
packet: MeshPacket.create({
packet: Protobuf.MeshPacket.create({
id: decodedMessage.id

@@ -652,3 +748,3 @@ }),

this.onPositionPacket.emit({
packet: MeshPacket.create({
packet: Protobuf.MeshPacket.create({
id: decodedMessage.id,

@@ -662,3 +758,3 @@ from: decodedMessage.payloadVariant.nodeInfo.num

this.onUserPacket.emit({
packet: MeshPacket.create({
packet: Protobuf.MeshPacket.create({
id: decodedMessage.id,

@@ -676,6 +772,6 @@ from: decodedMessage.payloadVariant.nodeInfo.num

"UNK"}`, decodedMessage.payloadVariant.config.payloadVariant.oneofKind
? LogRecord_Level.TRACE
: LogRecord_Level.WARNING);
? Protobuf.LogRecord_Level.TRACE
: Protobuf.LogRecord_Level.WARNING);
this.onConfigPacket.emit({
packet: MeshPacket.create({
packet: Protobuf.MeshPacket.create({
id: decodedMessage.id

@@ -687,3 +783,3 @@ }),

case "logRecord":
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, "Received onLogRecord", LogRecord_Level.TRACE);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, "Received onLogRecord", Protobuf.LogRecord_Level.TRACE);
this.onLogRecord.emit(decodedMessage.payloadVariant.logRecord);

@@ -693,9 +789,9 @@ break;

if (decodedMessage.payloadVariant.configCompleteId !== this.configId) {
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, `❌ Invalid config id reveived from device, exptected ${this.configId} but received ${decodedMessage.payloadVariant.configCompleteId}`, LogRecord_Level.ERROR);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, `❌ Invalid config id reveived from device, exptected ${this.configId} but received ${decodedMessage.payloadVariant.configCompleteId}`, Protobuf.LogRecord_Level.ERROR);
}
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, `⚙️ Valid config id reveived from device: ${this.configId}`, LogRecord_Level.INFO);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleFromRadio, `⚙️ Valid config id reveived from device: ${this.configId}`, Protobuf.LogRecord_Level.INFO);
await this.getAllChannels(async () => {
await Promise.resolve();
});
await this.sendRaw(0, ToRadio.toBinary(ToRadio.create({
await this.sendRaw(0, Protobuf.ToRadio.toBinary({
payloadVariant: {

@@ -708,3 +804,3 @@ peerInfo: {

}
})));
}));
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONFIGURED);

@@ -720,6 +816,6 @@ break;

.oneofKind ?? "UNK"}`, decodedMessage.payloadVariant.moduleConfig.payloadVariant.oneofKind
? LogRecord_Level.TRACE
: LogRecord_Level.WARNING);
? Protobuf.LogRecord_Level.TRACE
: Protobuf.LogRecord_Level.WARNING);
this.onModuleConfigPacket.emit({
packet: MeshPacket.create({
packet: Protobuf.MeshPacket.create({
id: decodedMessage.id

@@ -732,5 +828,3 @@ }),

}
/**
* Completes all SubEvents
*/
/** Completes all SubEvents */
complete() {

@@ -765,3 +859,4 @@ this.onLogEvent.cancelAll();

* Gets called when a MeshPacket is received from device
* @param meshPacket
*
* @param {Protobuf.MeshPacket} meshPacket Packet to process
*/

@@ -772,3 +867,4 @@ async handleMeshPacket(meshPacket) {

/**
* @todo, this shouldn't be called unless the device interracts with the mesh, currently it does.
* TODO: this shouldn't be called unless the device interracts with the
* mesh, currently it does.
*/

@@ -783,3 +879,3 @@ this.onMeshHeartbeat.emit(new Date());

case "encrypted":
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "Device received encrypted data packet, ignoring.", LogRecord_Level.DEBUG);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "Device received encrypted data packet, ignoring.", Protobuf.LogRecord_Level.DEBUG);
break;

@@ -791,4 +887,4 @@ }

switch (dataPacket.portnum) {
case PortNum.TEXT_MESSAGE_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received TEXT_MESSAGE_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.TEXT_MESSAGE_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received TEXT_MESSAGE_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onMessagePacket.emit({

@@ -799,4 +895,4 @@ packet: meshPacket,

break;
case PortNum.REMOTE_HARDWARE_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received REMOTE_HARDWARE_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.REMOTE_HARDWARE_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received REMOTE_HARDWARE_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onRemoteHardwarePacket.emit({

@@ -807,31 +903,32 @@ packet: meshPacket,

break;
case PortNum.POSITION_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received POSITION_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.POSITION_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received POSITION_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onPositionPacket.emit({
packet: meshPacket,
data: Position.fromBinary(dataPacket.payload)
data: Protobuf.Position.fromBinary(dataPacket.payload)
});
break;
case PortNum.NODEINFO_APP:
case Protobuf.PortNum.NODEINFO_APP:
/**
* @todo, workaround for NODEINFO_APP plugin sending a User protobuf instead of a NodeInfo protobuf
* TODO: workaround for NODEINFO_APP plugin sending a User protobuf
* instead of a NodeInfo protobuf
*/
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received NODEINFO_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received NODEINFO_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onUserPacket.emit({
packet: meshPacket,
data: User.fromBinary(dataPacket.payload)
data: Protobuf.User.fromBinary(dataPacket.payload)
});
break;
case PortNum.ROUTING_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received ROUTING_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.ROUTING_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received ROUTING_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onRoutingPacket.emit({
packet: meshPacket,
data: Routing.fromBinary(dataPacket.payload)
data: Protobuf.Routing.fromBinary(dataPacket.payload)
});
break;
case PortNum.ADMIN_APP:
adminMessage = AdminMessage.fromBinary(dataPacket.payload);
case Protobuf.PortNum.ADMIN_APP:
adminMessage = Protobuf.AdminMessage.fromBinary(dataPacket.payload);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, `📦 Received ADMIN_APP packet of variant ${
//change
adminMessage.payloadVariant.oneofKind ?? "UNK"}`, LogRecord_Level.TRACE, dataPacket.payload);
adminMessage.payloadVariant.oneofKind ?? "UNK"}`, Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
switch (adminMessage.payloadVariant.oneofKind) {

@@ -869,17 +966,17 @@ case "getChannelResponse":

default:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, `Received unhandled AdminMessage, type ${adminMessage.payloadVariant.oneofKind ?? "undefined"}`, LogRecord_Level.DEBUG, dataPacket.payload);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, `Received unhandled AdminMessage, type ${adminMessage.payloadVariant.oneofKind ?? "undefined"}`, Protobuf.LogRecord_Level.DEBUG, dataPacket.payload);
}
break;
case PortNum.TEXT_MESSAGE_COMPRESSED_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received TEXT_MESSAGE_COMPRESSED_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.TEXT_MESSAGE_COMPRESSED_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received TEXT_MESSAGE_COMPRESSED_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
break;
case PortNum.WAYPOINT_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received WAYPOINT_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.WAYPOINT_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received WAYPOINT_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onWaypointPacket.emit({
packet: meshPacket,
data: Waypoint.fromBinary(dataPacket.payload)
data: Protobuf.Waypoint.fromBinary(dataPacket.payload)
});
break;
case PortNum.REPLY_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received REPLY_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.REPLY_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received REPLY_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onPingPacket.emit({

@@ -890,4 +987,4 @@ packet: meshPacket,

break;
case PortNum.IP_TUNNEL_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received IP_TUNNEL_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.IP_TUNNEL_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received IP_TUNNEL_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onIpTunnelPacket.emit({

@@ -898,4 +995,4 @@ packet: meshPacket,

break;
case PortNum.SERIAL_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received SERIAL_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.SERIAL_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received SERIAL_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onSerialPacket.emit({

@@ -906,4 +1003,4 @@ packet: meshPacket,

break;
case PortNum.STORE_FORWARD_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received STORE_FORWARD_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.STORE_FORWARD_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received STORE_FORWARD_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onStoreForwardPacket.emit({

@@ -914,4 +1011,4 @@ packet: meshPacket,

break;
case PortNum.RANGE_TEST_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received RANGE_TEST_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.RANGE_TEST_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received RANGE_TEST_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onRangeTestPacket.emit({

@@ -922,4 +1019,4 @@ packet: meshPacket,

break;
case PortNum.TELEMETRY_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received TELEMETRY_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.TELEMETRY_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received TELEMETRY_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onTelemetryPacket.emit({

@@ -930,4 +1027,4 @@ packet: meshPacket,

break;
case PortNum.PRIVATE_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received PRIVATE_APP packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.PRIVATE_APP:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received PRIVATE_APP packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onPrivatePacket.emit({

@@ -938,4 +1035,4 @@ packet: meshPacket,

break;
case PortNum.ATAK_FORWARDER:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received ATAK_FORWARDER packet", LogRecord_Level.TRACE, dataPacket.payload);
case Protobuf.PortNum.ATAK_FORWARDER:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, "📦 Received ATAK_FORWARDER packet", Protobuf.LogRecord_Level.TRACE, dataPacket.payload);
this.onAtakPacket.emit({

@@ -947,4 +1044,4 @@ packet: meshPacket,

default:
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, `⚠️ Received unhandled PortNum: ${PortNum[dataPacket.portnum] ?? "UNK"}`, //warn
LogRecord_Level.WARNING, dataPacket.payload);
this.log(Types.EmitterScope.iMeshDevice, Types.Emitter.handleMeshPacket, `⚠️ Received unhandled PortNum: ${Protobuf.PortNum[dataPacket.portnum] ?? "UNK"}`, //warn
Protobuf.LogRecord_Level.WARNING, dataPacket.payload);
break;

@@ -951,0 +1048,0 @@ }

@@ -1,2 +0,2 @@

import { Client, IConnection } from "./client.js";
import { Client } from "./client.js";
import { IMeshDevice } from "./iMeshDevice.js";

@@ -10,2 +10,2 @@ import { IBLEConnection } from "./iBleConnection.js";

import * as Constants from "./constants.js";
export { Client, IMeshDevice, IBLEConnection, IHTTPConnection, ISerialConnection, IConnection, SettingsManager, Types, Constants, Protobuf };
export { Client, IMeshDevice, IBLEConnection, IHTTPConnection, ISerialConnection, SettingsManager, Types, Constants, Protobuf };
import { IMeshDevice } from "./iMeshDevice.js";
/**
* Allows connection to a Meshtastic device over NodeJS SerialPort
*/
/** Allows connection to a Meshtastic device over NodeJS SerialPort */
export declare class INodeSerialConnection extends IMeshDevice {
/**
* Defines the connection type as serial
*/
/** Defines the connection type as serial */
connType: string;
/**
* Serial port used to communicate with device.
*/
/** Serial port used to communicate with device. */
private port;
constructor(path: string, configId?: number);
static getPorts(): Promise<INodeSerialPort[]>;
/**
* Reads packets from transformed serial port steam and processes them.
*/
/** Reads packets from transformed serial port steam and processes them. */
private readFromRadio;
/**
* Initiates the connect process to a Meshtastic device via Web Serial
* @param parameters serial connection parameters
*/
/** Initiates the connect process to a Meshtastic device via Web Serial */
connect(): Promise<void>;
/**
* Disconnects from the serial port
*/
/** Disconnects from the serial port */
disconnect(): Promise<void>;
/**
* Pings device to check if it is avaliable
*/
/** Pings device to check if it is avaliable */
ping(): Promise<boolean>;
/**
* Sends supplied protobuf message to the radio
*
* @param {Uint8Array} data Raw data to send
*/

@@ -36,0 +23,0 @@ protected writeToRadio(data: Uint8Array): Promise<void>;

import { Transform } from "node:stream";
import { SerialPort } from "serialport";
import { Types } from "./index.js";
import { Protobuf, Types } from "./index.js";
import { IMeshDevice } from "./iMeshDevice.js";
import { LogRecord_Level } from "./generated/mesh.js";
import { transformHandler } from "./utils/transformHandler.js";
/**
* Allows connection to a Meshtastic device over NodeJS SerialPort
*/
/** Allows connection to a Meshtastic device over NodeJS SerialPort */
export class INodeSerialConnection extends IMeshDevice {
/**
* Defines the connection type as serial
*/
/** Defines the connection type as serial */
connType;
/**
* Serial port used to communicate with device.
*/
/** Serial port used to communicate with device. */
port;

@@ -28,9 +21,13 @@ constructor(path, configId) {

});
const { log } = this;
const transformer = new Transform({
transform(chunk, _, callback) {
transform(chunk, encoding, callback) {
if (encoding !== "binary") {
log(Types.EmitterScope.iNodeSerialConnection, Types.Emitter.constructor, `❌ Invalid buffer encoding: ${encoding}`, Protobuf.LogRecord_Level.ERROR);
}
transformHandler(new Uint8Array([]), chunk, (buffer) => {
callback(null, buffer);
});
}
// defaultEncoding: 'binary'
},
defaultEncoding: "binary"
});

@@ -41,10 +38,10 @@ this.port.pipe(transformer);

const portInfos = await SerialPort.list();
return portInfos.map((p) => ({
path: p.path,
description: p.manufacturer
}));
return portInfos.map((p) => {
return {
path: p.path,
description: p.manufacturer ?? "Unknown"
};
});
}
/**
* Reads packets from transformed serial port steam and processes them.
*/
/** Reads packets from transformed serial port steam and processes them. */
async readFromRadio() {

@@ -54,3 +51,3 @@ if (this.port?.readable) {

const buffer = (await this.port.read());
if (buffer && buffer.length > 0) {
if (buffer.length > 0) {
void this.handleFromRadio(new Uint8Array(buffer.buffer));

@@ -60,3 +57,3 @@ }

catch (error) {
this.log(Types.EmitterScope.iNodeSerialConnection, Types.Emitter.readFromRadio, `Device errored or disconnected: ${error}`, LogRecord_Level.INFO);
this.log(Types.EmitterScope.iNodeSerialConnection, Types.Emitter.readFromRadio, `Device errored or disconnected: ${error}`, Protobuf.LogRecord_Level.INFO);
await this.disconnect();

@@ -66,10 +63,7 @@ }

}
/**
* Initiates the connect process to a Meshtastic device via Web Serial
* @param parameters serial connection parameters
*/
/** Initiates the connect process to a Meshtastic device via Web Serial */
async connect() {
await Promise.resolve();
this.port?.on("disconnect", () => {
this.log(Types.EmitterScope.iNodeSerialConnection, Types.Emitter.connect, "Device disconnected", LogRecord_Level.INFO);
this.log(Types.EmitterScope.iNodeSerialConnection, Types.Emitter.connect, "Device disconnected", Protobuf.LogRecord_Level.INFO);
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_DISCONNECTED);

@@ -81,17 +75,13 @@ this.complete();

if (e) {
this.log(Types.EmitterScope.iNodeSerialConnection, Types.Emitter.connect, `Conn: ${e.message}`, LogRecord_Level.ERROR);
this.log(Types.EmitterScope.iNodeSerialConnection, Types.Emitter.connect, `❌ ${e.message}`, Protobuf.LogRecord_Level.ERROR);
}
else {
void this.readFromRadio();
/**
* @todo, implement device keep-awake loop
*/
/** TODO: implement device keep-awake loop */
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONNECTED);
void this.configure();
this.configure();
}
});
}
/**
* Disconnects from the serial port
*/
/** Disconnects from the serial port */
async disconnect() {

@@ -103,5 +93,3 @@ await Promise.resolve();

}
/**
* Pings device to check if it is avaliable
*/
/** Pings device to check if it is avaliable */
async ping() {

@@ -112,2 +100,4 @@ return Promise.resolve(true);

* Sends supplied protobuf message to the radio
*
* @param {Uint8Array} data Raw data to send
*/

@@ -120,3 +110,3 @@ async writeToRadio(data) {

if (e) {
this.log(Types.EmitterScope.iNodeSerialConnection, Types.Emitter.writeToRadio, `Conn: ${e.message}`, LogRecord_Level.ERROR);
this.log(Types.EmitterScope.iNodeSerialConnection, Types.Emitter.writeToRadio, `❌ ${e.message}`, Protobuf.LogRecord_Level.ERROR);
}

@@ -123,0 +113,0 @@ });

/// <reference types="w3c-web-serial" />
import { Types } from "./index.js";
import { IMeshDevice } from "./iMeshDevice.js";
import type { SerialConnectionParameters } from "./types.js";
/**
* Allows to connect to a Meshtastic device over WebSerial
*/
/** Allows to connect to a Meshtastic device over WebSerial */
export declare class ISerialConnection extends IMeshDevice {
/**
* Defines the connection type as serial
*/
/** Defines the connection type as serial */
connType: string;
/**
* Serial port used to communicate with device.
*/
/** Serial port used to communicate with device. */
private port;
/**
* Readable stream from serial port.
*/
/** Readable stream from serial port. */
private reader;
/**
* Writable stream to serial port.
*/
/** Writable stream to serial port. */
private writer;
constructor(configId?: number);
/**
* Reads packets from transformed serial port steam and processes them.
*/
/** Reads packets from transformed serial port steam and processes them. */
private readFromRadio;
/**
* Gets list of serial ports that can be passed to `connect`
*/
/** Gets list of serial ports that can be passed to `connect` */
getPorts(): Promise<SerialPort[]>;
/**
* Opens browsers connection dialogue to select a serial port
*
* @param {SerialPortRequestOptions} [filter] Filter to use when requesting
* serial port
* @returns {Promise<SerialPort>} Returned SerialPort
*/

@@ -39,17 +29,21 @@ getPort(filter?: SerialPortRequestOptions): Promise<SerialPort>;

* Initiates the connect process to a Meshtastic device via Web Serial
* @param parameters serial connection parameters
*
* @param {Types.SerialConnectionParameters} parameters Serial connection
* parameters
* @param {SerialPort} [parameters.port] Externally sourced serialport to
* connect to
* @param {number} [parameters.baudRate=115200] Baud rate override. Default is
* `115200`. Default is `115200`
*/
connect({ port, baudRate }: SerialConnectionParameters): Promise<void>;
/**
* Disconnects from the serial port
*/
connect({ port, baudRate }: Types.SerialConnectionParameters): Promise<void>;
/** Disconnects from the serial port */
disconnect(): Promise<void>;
/**
* Pings device to check if it is avaliable
*/
/** Pings device to check if it is avaliable */
ping(): Promise<boolean>;
/**
* Sends supplied protobuf message to the radio
*
* @param {Uint8Array} data Raw bytes to send
*/
protected writeToRadio(data: Uint8Array): Promise<void>;
}

@@ -1,23 +0,12 @@

import { Types } from "./index.js";
import { Protobuf, Types } from "./index.js";
import { IMeshDevice } from "./iMeshDevice.js";
import { LogRecord_Level } from "./generated/mesh.js";
/**
* Allows to connect to a Meshtastic device over WebSerial
*/
/** Allows to connect to a Meshtastic device over WebSerial */
export class ISerialConnection extends IMeshDevice {
/**
* Defines the connection type as serial
*/
/** Defines the connection type as serial */
connType;
/**
* Serial port used to communicate with device.
*/
/** Serial port used to communicate with device. */
port;
/**
* Readable stream from serial port.
*/
/** Readable stream from serial port. */
reader;
/**
* Writable stream to serial port.
*/
/** Writable stream to serial port. */
writer;

@@ -31,5 +20,3 @@ constructor(configId) {

}
/**
* Reads packets from transformed serial port steam and processes them.
*/
/** Reads packets from transformed serial port steam and processes them. */
async readFromRadio() {

@@ -51,3 +38,3 @@ while (this.port?.readable) {

catch (error) {
this.log(Types.EmitterScope.iSerialConnection, Types.Emitter.readFromRadio, `Device errored or disconnected: ${error}`, LogRecord_Level.INFO);
this.log(Types.EmitterScope.iSerialConnection, Types.Emitter.readFromRadio, `Device errored or disconnected: ${error}`, Protobuf.LogRecord_Level.INFO);
await this.disconnect();

@@ -57,5 +44,3 @@ }

}
/**
* Gets list of serial ports that can be passed to `connect`
*/
/** Gets list of serial ports that can be passed to `connect` */
async getPorts() {

@@ -66,2 +51,6 @@ return navigator.serial.getPorts();

* Opens browsers connection dialogue to select a serial port
*
* @param {SerialPortRequestOptions} [filter] Filter to use when requesting
* serial port
* @returns {Promise<SerialPort>} Returned SerialPort
*/

@@ -73,32 +62,28 @@ async getPort(filter) {

* Initiates the connect process to a Meshtastic device via Web Serial
* @param parameters serial connection parameters
*
* @param {Types.SerialConnectionParameters} parameters Serial connection
* parameters
* @param {SerialPort} [parameters.port] Externally sourced serialport to
* connect to
* @param {number} [parameters.baudRate=115200] Baud rate override. Default is
* `115200`. Default is `115200`
*/
async connect({ port, baudRate }) {
/**
* Check for API avaliability
*/
async connect({ port, baudRate = 115200 }) {
/** Check for API avaliability */
if (!navigator.serial) {
this.log(Types.EmitterScope.iSerialConnection, Types.Emitter.connect, `This browser doesn't support the WebSerial API`, LogRecord_Level.WARNING);
this.log(Types.EmitterScope.iSerialConnection, Types.Emitter.connect, `This browser doesn't support the WebSerial API`, Protobuf.LogRecord_Level.WARNING);
}
/**
* Set device state to connecting
*/
/** Set device state to connecting */
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONNECTING);
/**
* Set device if specified, else request.
*/
/** Set device if specified, else request. */
this.port = port ?? (await this.getPort());
/**
* Setup event listners
*/
/** Setup event listners */
this.port.addEventListener("disconnect", () => {
this.log(Types.EmitterScope.iSerialConnection, Types.Emitter.connect, "Device disconnected", LogRecord_Level.INFO);
this.log(Types.EmitterScope.iSerialConnection, Types.Emitter.connect, "Device disconnected", Protobuf.LogRecord_Level.INFO);
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_DISCONNECTED);
this.complete();
});
/**
* Connect to device
*/
/** Connect to device */
await this.port.open({
baudRate: baudRate ?? 115200
baudRate
});

@@ -119,3 +104,3 @@ let byteBuffer = new Uint8Array([]);

.subarray(0, framingIndex)
.toString()}`, LogRecord_Level.WARNING);
.toString()}`, Protobuf.LogRecord_Level.WARNING);
byteBuffer = byteBuffer.subarray(framingIndex);

@@ -134,3 +119,3 @@ }

.subarray(0, malformedDetectorIndex - 1)
.toString()}`, LogRecord_Level.WARNING);
.toString()}`, Protobuf.LogRecord_Level.WARNING);
byteBuffer = byteBuffer.subarray(malformedDetectorIndex);

@@ -144,5 +129,3 @@ }

else {
/**
* Only partioal message in buffer, wait for the rest
*/
/** Only partioal message in buffer, wait for the rest */
processingExhausted = true;

@@ -152,5 +135,3 @@ }

else {
/**
* Message not complete, only 1 byte in buffer
*/
/** Message not complete, only 1 byte in buffer */
processingExhausted = true;

@@ -168,11 +149,7 @@ }

void this.readFromRadio();
/**
* @todo, implement device keep-awake loop
*/
/** TODO: implement device keep-awake loop */
this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONNECTED);
await this.configure();
this.configure();
}
/**
* Disconnects from the serial port
*/
/** Disconnects from the serial port */
async disconnect() {

@@ -184,5 +161,3 @@ await this.reader.cancel();

}
/**
* Pings device to check if it is avaliable
*/
/** Pings device to check if it is avaliable */
async ping() {

@@ -193,2 +168,4 @@ return Promise.resolve(true);

* Sends supplied protobuf message to the radio
*
* @param {Uint8Array} data Raw bytes to send
*/

@@ -195,0 +172,0 @@ async writeToRadio(data) {

@@ -1,2 +0,2 @@

import { Client, IConnection } from "../client.js";
import { Client } from "../client.js";
import { IMeshDevice } from "../iMeshDevice.js";

@@ -9,2 +9,2 @@ import { IHTTPConnection } from "../iHttpConnection.js";

import * as Constants from "../constants.js";
export { Client, IMeshDevice, IHTTPConnection, INodeSerialConnection, IConnection, SettingsManager, Types, Constants, Protobuf };
export { Client, IMeshDevice, IHTTPConnection, INodeSerialConnection, SettingsManager, Types, Constants, Protobuf };

@@ -1,15 +0,12 @@

import { LogRecord_Level } from "./generated/mesh.js";
/**
* Handles library-wide settings
*/
import { Protobuf } from "./index.js";
/** Handles library-wide settings */
export declare class SettingsManager {
/** Logging level for the application */
static debugMode: Protobuf.LogRecord_Level;
/**
* Logging level for the application
*/
static debugMode: LogRecord_Level;
/**
* Sets the library-wide logging level
* @param level Desired level of logging
*
* @param {Protobuf.LogRecord_Level} level Desired level of logging
*/
static setDebugMode(level: LogRecord_Level): void;
static setDebugMode(level: Protobuf.LogRecord_Level): void;
}

@@ -1,19 +0,15 @@

import { LogRecord_Level } from "./generated/mesh.js";
import { Types } from "./index.js";
import { Protobuf, Types } from "./index.js";
import { log } from "./utils/logging.js";
/**
* Handles library-wide settings
*/
/** Handles library-wide settings */
export class SettingsManager {
/** Logging level for the application */
static debugMode = Protobuf.LogRecord_Level.WARNING;
/**
* Logging level for the application
*/
static debugMode = LogRecord_Level.WARNING;
/**
* Sets the library-wide logging level
* @param level Desired level of logging
*
* @param {Protobuf.LogRecord_Level} level Desired level of logging
*/
static setDebugMode(level) {
if (!(level in LogRecord_Level)) {
log(Types.EmitterScope.SettingsManager, Types.Emitter.setDebugMode, `Specified log level must be a member of LogRecord_Level.`, LogRecord_Level.WARNING);
if (!(level in Protobuf.LogRecord_Level)) {
log(Types.EmitterScope.SettingsManager, Types.Emitter.setDebugMode, `Specified log level must be a member of LogRecord_Level.`, Protobuf.LogRecord_Level.WARNING);
}

@@ -20,0 +16,0 @@ SettingsManager.debugMode = level;

/// <reference types="web-bluetooth" />
/// <reference types="w3c-web-serial" />
import type { IBLEConnection, IHTTPConnection, ISerialConnection } from "./index.js";
import type { LogRecord_Level, MeshPacket, NodeInfo, Position, Routing, User, Waypoint } from "./generated/mesh.js";
import { DeviceMetadata } from "./generated/device_metadata.js";
import { ModuleConfig } from "./generated/module_config.js";
import { Config } from "./generated/config.js";
import { Channel } from "./generated/channel.js";
import { HardwareMessage } from "./generated/remote_hardware.js";
import { Telemetry } from "./generated/telemetry.js";
import type { IBLEConnection, IHTTPConnection, ISerialConnection, Protobuf } from "./index.js";
export declare enum DeviceStatusEnum {

@@ -20,19 +13,16 @@ DEVICE_RESTARTING = 0,

}
export declare type DeviceInterface = IHTTPConnection | IBLEConnection | ISerialConnection;
export declare type ConnectionParameters = HTTPConnectionParameters | BLEConnectionParameters | SerialConnectionParameters;
export interface HTTPConnectionParameters {
/**
* address The IP Address/Domain to connect to, without protocol
*/
/** Address The IP Address/Domain to connect to, without protocol */
address: string;
/**
* Enables transport layer security. Notes: Slower, devices' certificate must be trusted by the browser
* Enables transport layer security. Notes: Slower, devices' certificate must
* be trusted by the browser
*/
tls?: boolean;
/**
* Enables receiving messages all at once, versus one per request
*/
/** Enables receiving messages all at once, versus one per request */
receiveBatchRequests?: boolean;
/**
* (ms) Sets a fixed interval in that the device is fetched for new messages, defaults to 5 seconds
* (ms) Sets a fixed interval in that the device is fetched for new messages,
* defaults to 5 seconds
*/

@@ -42,9 +32,5 @@ fetchInterval: number;

export interface BLEConnectionParameters {
/**
* Optional filter options for the web bluetooth api requestDevice() method
*/
/** Optional filter options for the web bluetooth api requestDevice() method */
deviceFilter?: RequestDeviceOptions;
/**
* Connect directly to a Bluetooth deivce, obtained from `getDevices()`
*/
/** Connect directly to a Bluetooth deivce, obtained from `getDevices()` */
device?: BluetoothDevice;

@@ -54,5 +40,3 @@ }

baudRate?: number;
/**
* Connect directly to a Serial port, obtained from `getPorts()`
*/
/** Connect directly to a Serial port, obtained from `getPorts()` */
port?: SerialPort;

@@ -64,76 +48,76 @@ }

export interface NodeInfoPacket {
packet: MeshPacket;
data: NodeInfo;
packet: Protobuf.MeshPacket;
data: Protobuf.NodeInfo;
}
export interface UserPacket {
packet: MeshPacket;
data: User;
packet: Protobuf.MeshPacket;
data: Protobuf.User;
}
export interface RoutingPacket {
packet: MeshPacket;
data: Routing;
packet: Protobuf.MeshPacket;
data: Protobuf.Routing;
}
export interface PositionPacket {
packet: MeshPacket;
data: Position;
packet: Protobuf.MeshPacket;
data: Protobuf.Position;
}
export interface MessagePacket {
packet: MeshPacket;
packet: Protobuf.MeshPacket;
text: string;
}
export interface PingPacket {
packet: MeshPacket;
packet: Protobuf.MeshPacket;
data: Uint8Array;
}
export interface IpTunnelPacket {
packet: MeshPacket;
packet: Protobuf.MeshPacket;
data: Uint8Array;
}
export interface SerialPacket {
packet: MeshPacket;
packet: Protobuf.MeshPacket;
data: Uint8Array;
}
export interface StoreForwardPacket {
packet: MeshPacket;
packet: Protobuf.MeshPacket;
data: Uint8Array;
}
export interface RangeTestPacket {
packet: MeshPacket;
packet: Protobuf.MeshPacket;
data: Uint8Array;
}
export interface TelemetryPacket {
packet: MeshPacket;
data: Telemetry;
packet: Protobuf.MeshPacket;
data: Protobuf.Telemetry;
}
export interface PrivatePacket {
packet: MeshPacket;
packet: Protobuf.MeshPacket;
data: Uint8Array;
}
export interface AtakPacket {
packet: MeshPacket;
packet: Protobuf.MeshPacket;
data: Uint8Array;
}
export interface RemoteHardwarePacket {
packet: MeshPacket;
data: HardwareMessage;
packet: Protobuf.MeshPacket;
data: Protobuf.HardwareMessage;
}
export interface ChannelPacket {
packet: MeshPacket;
data: Channel;
packet: Protobuf.MeshPacket;
data: Protobuf.Channel;
}
export interface ConfigPacket {
packet: MeshPacket;
data: Config;
packet: Protobuf.MeshPacket;
data: Protobuf.Config;
}
export interface ModuleConfigPacket {
packet: MeshPacket;
data: ModuleConfig;
packet: Protobuf.MeshPacket;
data: Protobuf.ModuleConfig;
}
export interface DeviceMetadataPacket {
packet: MeshPacket;
data: DeviceMetadata;
packet: Protobuf.MeshPacket;
data: Protobuf.DeviceMetadata;
}
export interface WaypointPacket {
packet: MeshPacket;
data: Waypoint;
packet: Protobuf.MeshPacket;
data: Protobuf.Waypoint;
}

@@ -149,27 +133,29 @@ export declare enum EmitterScope {

export declare enum Emitter {
"sendText" = 0,
"sendWaypoint" = 1,
"sendPacket" = 2,
"sendRaw" = 3,
"setConfig" = 4,
"setModuleConfig" = 5,
"confirmSetConfig" = 6,
"setOwner" = 7,
"setChannel" = 8,
"confirmSetChannel" = 9,
"deleteChannel" = 10,
"getChannel" = 11,
"getAllChannels" = 12,
"getConfig" = 13,
"getModuleConfig" = 14,
"getOwner" = 15,
"configure" = 16,
"handleFromRadio" = 17,
"handleMeshPacket" = 18,
"connect" = 19,
"ping" = 20,
"readFromRadio" = 21,
"writeToRadio" = 22,
"setDebugMode" = 23,
"getMetadata" = 24
"constructor" = 0,
"sendText" = 1,
"sendWaypoint" = 2,
"sendPacket" = 3,
"sendRaw" = 4,
"setConfig" = 5,
"setModuleConfig" = 6,
"confirmSetConfig" = 7,
"setOwner" = 8,
"setChannel" = 9,
"confirmSetChannel" = 10,
"clearChannel" = 11,
"getChannel" = 12,
"getAllChannels" = 13,
"getConfig" = 14,
"getModuleConfig" = 15,
"getOwner" = 16,
"configure" = 17,
"handleFromRadio" = 18,
"handleMeshPacket" = 19,
"connect" = 20,
"ping" = 21,
"readFromRadio" = 22,
"writeToRadio" = 23,
"setDebugMode" = 24,
"getMetadata" = 25,
"resetPeers" = 26
}

@@ -180,4 +166,6 @@ export interface LogEvent {

message: string;
level: LogRecord_Level;
level: Protobuf.LogRecord_Level;
packet?: Uint8Array;
}
export declare type ChannelNumber = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
export declare type ConnectionType = IBLEConnection | IHTTPConnection | ISerialConnection;

@@ -22,28 +22,30 @@ export var DeviceStatusEnum;

(function (Emitter) {
Emitter[Emitter["sendText"] = 0] = "sendText";
Emitter[Emitter["sendWaypoint"] = 1] = "sendWaypoint";
Emitter[Emitter["sendPacket"] = 2] = "sendPacket";
Emitter[Emitter["sendRaw"] = 3] = "sendRaw";
Emitter[Emitter["setConfig"] = 4] = "setConfig";
Emitter[Emitter["setModuleConfig"] = 5] = "setModuleConfig";
Emitter[Emitter["confirmSetConfig"] = 6] = "confirmSetConfig";
Emitter[Emitter["setOwner"] = 7] = "setOwner";
Emitter[Emitter["setChannel"] = 8] = "setChannel";
Emitter[Emitter["confirmSetChannel"] = 9] = "confirmSetChannel";
Emitter[Emitter["deleteChannel"] = 10] = "deleteChannel";
Emitter[Emitter["getChannel"] = 11] = "getChannel";
Emitter[Emitter["getAllChannels"] = 12] = "getAllChannels";
Emitter[Emitter["getConfig"] = 13] = "getConfig";
Emitter[Emitter["getModuleConfig"] = 14] = "getModuleConfig";
Emitter[Emitter["getOwner"] = 15] = "getOwner";
Emitter[Emitter["configure"] = 16] = "configure";
Emitter[Emitter["handleFromRadio"] = 17] = "handleFromRadio";
Emitter[Emitter["handleMeshPacket"] = 18] = "handleMeshPacket";
Emitter[Emitter["connect"] = 19] = "connect";
Emitter[Emitter["ping"] = 20] = "ping";
Emitter[Emitter["readFromRadio"] = 21] = "readFromRadio";
Emitter[Emitter["writeToRadio"] = 22] = "writeToRadio";
Emitter[Emitter["setDebugMode"] = 23] = "setDebugMode";
Emitter[Emitter["getMetadata"] = 24] = "getMetadata";
Emitter[Emitter["constructor"] = 0] = "constructor";
Emitter[Emitter["sendText"] = 1] = "sendText";
Emitter[Emitter["sendWaypoint"] = 2] = "sendWaypoint";
Emitter[Emitter["sendPacket"] = 3] = "sendPacket";
Emitter[Emitter["sendRaw"] = 4] = "sendRaw";
Emitter[Emitter["setConfig"] = 5] = "setConfig";
Emitter[Emitter["setModuleConfig"] = 6] = "setModuleConfig";
Emitter[Emitter["confirmSetConfig"] = 7] = "confirmSetConfig";
Emitter[Emitter["setOwner"] = 8] = "setOwner";
Emitter[Emitter["setChannel"] = 9] = "setChannel";
Emitter[Emitter["confirmSetChannel"] = 10] = "confirmSetChannel";
Emitter[Emitter["clearChannel"] = 11] = "clearChannel";
Emitter[Emitter["getChannel"] = 12] = "getChannel";
Emitter[Emitter["getAllChannels"] = 13] = "getAllChannels";
Emitter[Emitter["getConfig"] = 14] = "getConfig";
Emitter[Emitter["getModuleConfig"] = 15] = "getModuleConfig";
Emitter[Emitter["getOwner"] = 16] = "getOwner";
Emitter[Emitter["configure"] = 17] = "configure";
Emitter[Emitter["handleFromRadio"] = 18] = "handleFromRadio";
Emitter[Emitter["handleMeshPacket"] = 19] = "handleMeshPacket";
Emitter[Emitter["connect"] = 20] = "connect";
Emitter[Emitter["ping"] = 21] = "ping";
Emitter[Emitter["readFromRadio"] = 22] = "readFromRadio";
Emitter[Emitter["writeToRadio"] = 23] = "writeToRadio";
Emitter[Emitter["setDebugMode"] = 24] = "setDebugMode";
Emitter[Emitter["getMetadata"] = 25] = "getMetadata";
Emitter[Emitter["resetPeers"] = 26] = "resetPeers";
})(Emitter || (Emitter = {}));
//# sourceMappingURL=types.js.map
/**
* Converts a `ArrayBuffer` to a hex string
*
* @param arrayBuffer Input `ArrayBuffer` to be converted

@@ -8,4 +9,5 @@ */

* Converts a `Uint8Array` to an `ArrayBuffer`
*
* @param array Input `Uint8Array` to be converted
*/
export declare const typedArrayToBuffer: (array: Uint8Array) => ArrayBuffer;
/**
* Converts a `ArrayBuffer` to a hex string
*
* @param arrayBuffer Input `ArrayBuffer` to be converted

@@ -12,2 +13,3 @@ */

* Converts a `Uint8Array` to an `ArrayBuffer`
*
* @param array Input `Uint8Array` to be converted

@@ -14,0 +16,0 @@ */

@@ -1,9 +0,10 @@

import { LogRecord_Level } from "../generated/index.js";
import { Types } from "../index.js";
import { Protobuf, Types } from "../index.js";
/**
* Global event logger
* @param emitter Name of calling function
* @param message Informative message
* @param level Desired logging level
*
* @param {Types.EmitterScope} scope Debug statement's wrapper class
* @param {Types.Emitter} emitter Name of calling function
* @param {string} message Informative message
* @param {Protobuf.LogRecord_Level} level Desired logging level
*/
export declare const log: (scope: Types.EmitterScope, emitter: Types.Emitter, message: string, level: LogRecord_Level) => void;
export declare const log: (scope: Types.EmitterScope, emitter: Types.Emitter, message: string, level: Protobuf.LogRecord_Level) => void;

@@ -1,9 +0,10 @@

import { LogRecord_Level } from "../generated/index.js";
import { Types } from "../index.js";
import { Protobuf, Types } from "../index.js";
import { SettingsManager } from "../settingsManager.js";
/**
* Global event logger
* @param emitter Name of calling function
* @param message Informative message
* @param level Desired logging level
*
* @param {Types.EmitterScope} scope Debug statement's wrapper class
* @param {Types.Emitter} emitter Name of calling function
* @param {string} message Informative message
* @param {Protobuf.LogRecord_Level} level Desired logging level
*/

@@ -13,18 +14,18 @@ export const log = (scope, emitter, message, level) => {

switch (level) {
case LogRecord_Level.TRACE:
case Protobuf.LogRecord_Level.TRACE:
console.info(`%c[TRACE]%c ${Types.EmitterScope[scope] ?? "UNK"}.${Types.Emitter[emitter] ?? "UNK"}\n%c${message}`, "color:grey", "color:darkgrey", "color:white");
break;
case LogRecord_Level.DEBUG:
case Protobuf.LogRecord_Level.DEBUG:
console.info(`%c[DEBUG]%c ${Types.EmitterScope[scope] ?? "UNK"}.${Types.Emitter[emitter] ?? "UNK"}\n%c${message}`, "color:lightcyan", "color:darkgrey", "color:white");
break;
case LogRecord_Level.INFO:
case Protobuf.LogRecord_Level.INFO:
console.info(`%c[INFO]%c ${Types.EmitterScope[scope] ?? "UNK"}.${Types.Emitter[emitter] ?? "UNK"}\n%c${message}`, "color:darkgrey", "color:cyan", "color:white");
break;
case LogRecord_Level.WARNING:
case Protobuf.LogRecord_Level.WARNING:
console.warn(`%c[WARNING]%c ${Types.EmitterScope[scope] ?? "UNK"}.${Types.Emitter[emitter] ?? "UNK"}\n%c${message}`, "color:yellow", "color:darkgrey", "color:white");
break;
case LogRecord_Level.ERROR:
case Protobuf.LogRecord_Level.ERROR:
console.error(`%c[ERROR]%c ${Types.EmitterScope[scope] ?? "UNK"}.${Types.Emitter[emitter] ?? "UNK"}\n%c${message}`, "color:orangered", "color:darkgrey", "color:white");
break;
case LogRecord_Level.CRITICAL:
case Protobuf.LogRecord_Level.CRITICAL:
console.error(`%c[CRITICAL]%c ${Types.EmitterScope[scope] ?? "UNK"}.${Types.Emitter[emitter] ?? "UNK"}\n%c${message}`, "color:red", "color:darkgrey", "color:white");

@@ -31,0 +32,0 @@ break;

{
"name": "@meshtastic/meshtasticjs",
"version": "0.6.101",
"version": "0.6.102",
"description": "Browser library for interfacing with meshtastic devices",

@@ -31,8 +31,6 @@ "license": "GPL-3.0-only",

"dependencies": {
"@meshtastic/eslint-config": "^1.0.8",
"@protobuf-ts/runtime": "^2.8.1",
"@serialport/stream": "^10.3.0",
"prettier": "^2.7.1",
"serialport": "^10.4.0",
"sub-events": "^1.8.9"
"sub-events": "^1.9.0"
},

@@ -43,5 +41,14 @@ "devDependencies": {

"@types/web-bluetooth": "^0.0.15",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.6",
"node-protoc": "^1.0.3",
"prettier": "^2.7.1",
"prettier-plugin-jsdoc": "^0.4.2",
"typedoc": "^0.23.15",
"typescript": "^4.8.3"
"typescript": "^4.8.4"
},

@@ -53,3 +60,4 @@ "scripts": {

"update:protobufs": "cd protobufs && git pull origin master",
"format": "prettier --check . && eslint src/*.ts"
"format:check": "prettier --check . && eslint src/*.ts",
"format:fix": "prettier --write . && eslint --fix src/*.ts"
},

@@ -56,0 +64,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc