@meshtastic/meshtasticjs
Advanced tools
Comparing version 0.9.1 to 0.9.2
@@ -137,3 +137,5 @@ import { Types } from "./index.js"; | ||
}); | ||
this.configure(); | ||
void this.configure().catch(() => { | ||
// TODO: FIX, workaround for `wantConfigId` not getting acks. | ||
}); | ||
} | ||
@@ -140,0 +142,0 @@ /** Disconnects from the Meshtastic device */ |
@@ -48,3 +48,5 @@ import { Types } from "./index.js"; | ||
this.log.debug(Types.Emitter[Types.Emitter.connect], `Ping succeeded, starting configuration and request timer.`); | ||
this.configure(); | ||
void this.configure().catch(() => { | ||
// TODO: FIX, workaround for `wantConfigId` not getting acks. | ||
}); | ||
this.readLoop = setInterval(() => { | ||
@@ -124,3 +126,3 @@ this.readFromRadio().catch((e) => { | ||
if (readBuffer.byteLength > 0) { | ||
await this.handleFromRadio({ | ||
this.handleFromRadio({ | ||
fromRadio: new Uint8Array(readBuffer, 0) | ||
@@ -127,0 +129,0 @@ }); |
@@ -173,3 +173,3 @@ import { Logger } from "tslog"; | ||
/** Triggers the device configure process */ | ||
configure(): void; | ||
configure(): Promise<number>; | ||
/** Sends a trace route packet to the designated node */ | ||
@@ -176,0 +176,0 @@ traceRoute({ destination }: traceRouteProps): Promise<number>; |
@@ -27,3 +27,6 @@ import { Logger } from "tslog"; | ||
constructor(configId) { | ||
this.log = new Logger({ name: "iMeshDevice" }); | ||
this.log = new Logger({ | ||
name: "iMeshDevice", | ||
prettyLogTemplate: "{{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t[{{name}}]\t" | ||
}); | ||
this.deviceStatus = Types.DeviceStatusEnum.DEVICE_DISCONNECTED; | ||
@@ -161,4 +164,3 @@ this.isConfigured = false; | ||
id, | ||
data: toRadio, | ||
waitingAck: false | ||
data: toRadio | ||
}); | ||
@@ -178,26 +180,2 @@ await this.queue.processQueue(async (data) => { | ||
this.log.debug(Types.Emitter[Types.Emitter.setConfig], `Setting config`); | ||
let configType; | ||
switch (config.payloadVariant.oneofKind) { | ||
case "device": | ||
configType = Protobuf.AdminMessage_ConfigType.DEVICE_CONFIG; | ||
break; | ||
case "display": | ||
configType = Protobuf.AdminMessage_ConfigType.DISPLAY_CONFIG; | ||
break; | ||
case "lora": | ||
configType = Protobuf.AdminMessage_ConfigType.LORA_CONFIG; | ||
break; | ||
case "position": | ||
configType = Protobuf.AdminMessage_ConfigType.POSITION_CONFIG; | ||
break; | ||
case "power": | ||
configType = Protobuf.AdminMessage_ConfigType.POWER_CONFIG; | ||
break; | ||
case "network": | ||
configType = Protobuf.AdminMessage_ConfigType.NETWORK_CONFIG; | ||
break; | ||
case "bluetooth": | ||
configType = Protobuf.AdminMessage_ConfigType.BLUETOOTH_CONFIG; | ||
break; | ||
} | ||
const setRadio = Protobuf.AdminMessage.toBinary({ | ||
@@ -215,5 +193,2 @@ payloadVariant: { | ||
wantResponse: true | ||
}).then(async (id) => { | ||
await this.getConfig({ configType }); | ||
return id; | ||
}); | ||
@@ -228,31 +203,2 @@ } | ||
this.log.debug(Types.Emitter[Types.Emitter.setModuleConfig], `Setting module config`); | ||
let moduleConfigType; | ||
switch (moduleConfig.payloadVariant.oneofKind) { | ||
case "mqtt": | ||
moduleConfigType = Protobuf.AdminMessage_ModuleConfigType.MQTT_CONFIG; | ||
break; | ||
case "serial": | ||
moduleConfigType = Protobuf.AdminMessage_ModuleConfigType.SERIAL_CONFIG; | ||
break; | ||
case "externalNotification": | ||
moduleConfigType = | ||
Protobuf.AdminMessage_ModuleConfigType.EXTNOTIF_CONFIG; | ||
break; | ||
case "storeForward": | ||
moduleConfigType = | ||
Protobuf.AdminMessage_ModuleConfigType.STOREFORWARD_CONFIG; | ||
break; | ||
case "rangeTest": | ||
moduleConfigType = | ||
Protobuf.AdminMessage_ModuleConfigType.RANGETEST_CONFIG; | ||
break; | ||
case "telemetry": | ||
moduleConfigType = | ||
Protobuf.AdminMessage_ModuleConfigType.TELEMETRY_CONFIG; | ||
break; | ||
case "cannedMessage": | ||
moduleConfigType = | ||
Protobuf.AdminMessage_ModuleConfigType.CANNEDMSG_CONFIG; | ||
break; | ||
} | ||
const setRadio = Protobuf.AdminMessage.toBinary({ | ||
@@ -270,5 +216,2 @@ payloadVariant: { | ||
wantResponse: true | ||
}).then(async (id) => { | ||
await this.getModuleConfig({ moduleConfigType }); | ||
return id; | ||
}); | ||
@@ -295,5 +238,2 @@ } | ||
wantResponse: true | ||
}).then(async (id) => { | ||
await this.getOwner(); | ||
return id; | ||
}); | ||
@@ -320,5 +260,2 @@ } | ||
wantResponse: true | ||
}).then(async (id) => { | ||
await this.getChannel({ index: channel.index }); | ||
return id; | ||
}); | ||
@@ -462,5 +399,2 @@ } | ||
wantResponse: true | ||
}).then(async (id) => { | ||
await this.getChannel({ index: channel.index }); | ||
return id; | ||
}); | ||
@@ -631,5 +565,3 @@ } | ||
/** Triggers the device configure process */ | ||
// TODO: Make more robust and await the sendRaw | ||
configure() { | ||
// TODO: this not always logged | ||
this.log.debug(Types.Emitter[Types.Emitter.configure], `⚙️ Requesting device configuration`); | ||
@@ -645,5 +577,3 @@ this.updateDeviceStatus({ | ||
}); | ||
setTimeout(() => { | ||
void this.sendRaw({ id: 0, toRadio }); | ||
}, 200); | ||
return this.sendRaw({ id: this.generateRandId(), toRadio }); | ||
} | ||
@@ -711,6 +641,6 @@ /** Sends a trace route packet to the designated node */ | ||
this.events.onMyNodeInfo.emit(decodedMessage.payloadVariant.myInfo); | ||
this.log.trace(Types.Emitter[Types.Emitter.handleFromRadio], "📱 Received Node info for this device"); | ||
this.log.info(Types.Emitter[Types.Emitter.handleFromRadio], "📱 Received Node info for this device"); | ||
break; | ||
case "nodeInfo": | ||
this.log.trace(Types.Emitter[Types.Emitter.handleFromRadio], `📱 Received Node Info packet for node: ${decodedMessage.payloadVariant.nodeInfo.num}`); | ||
this.log.info(Types.Emitter[Types.Emitter.handleFromRadio], `📱 Received Node Info packet for node: ${decodedMessage.payloadVariant.nodeInfo.num}`); | ||
this.events.onNodeInfoPacket.emit({ | ||
@@ -769,3 +699,5 @@ packet: Protobuf.MeshPacket.create({ | ||
case "rebooted": | ||
this.configure(); | ||
void this.configure().catch(() => { | ||
// TODO: FIX, workaround for `wantConfigId` not getting acks. | ||
}); | ||
break; | ||
@@ -855,6 +787,2 @@ case "moduleConfig": | ||
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], `📦 Received ${Protobuf.PortNum[dataPacket.portnum]} packet`); | ||
if (dataPacket.requestId !== 0 && | ||
dataPacket.portnum !== Protobuf.PortNum.ROUTING_APP) { | ||
this.queue.processAck(dataPacket.requestId); | ||
} | ||
switch (dataPacket.portnum) { | ||
@@ -893,6 +821,11 @@ case Protobuf.PortNum.TEXT_MESSAGE_APP: | ||
case "errorReason": | ||
this.queue.processError({ | ||
id: dataPacket.requestId, | ||
error: routingPacket.variant.errorReason | ||
}); | ||
if (routingPacket.variant.errorReason === Protobuf.Routing_Error.NONE) { | ||
this.queue.processAck(dataPacket.requestId); | ||
} | ||
else { | ||
this.queue.processError({ | ||
id: dataPacket.requestId, | ||
error: routingPacket.variant.errorReason | ||
}); | ||
} | ||
break; | ||
@@ -899,0 +832,0 @@ case "routeReply": |
@@ -107,3 +107,3 @@ import { SubEvent } from "sub-events"; | ||
}) | ||
.then(() => { | ||
.then(async () => { | ||
if (this.port?.readable && this.port.writable) { | ||
@@ -116,3 +116,5 @@ this.transformer = transformHandler(this.log, this.onReleaseEvent, this.events.onDeviceDebugLog, concurrentLogOutput); | ||
}); | ||
this.configure(); | ||
void this.configure().catch(() => { | ||
// TODO: FIX, workaround for `wantConfigId` not getting acks. | ||
}); | ||
} | ||
@@ -119,0 +121,0 @@ else { |
@@ -5,3 +5,3 @@ import { PacketError } from "../types.js"; | ||
data: Uint8Array; | ||
waitingAck: boolean; | ||
sent: boolean; | ||
promise: Promise<number>; | ||
@@ -15,3 +15,3 @@ } | ||
clear(): void; | ||
push(item: Omit<IQueueItem, "promise">): void; | ||
push(item: Omit<IQueueItem, "promise" | "sent">): void; | ||
remove(id: number): void; | ||
@@ -18,0 +18,0 @@ processAck(id: number): void; |
import { SubEvent } from "sub-events"; | ||
import { Protobuf } from "../index.js"; | ||
export class Queue { | ||
@@ -13,17 +14,26 @@ queue = []; | ||
...item, | ||
sent: false, | ||
promise: new Promise((resolve, reject) => { | ||
this.ackNotifier.subscribe((id) => { | ||
resolve(id); | ||
if (item.id === id) { | ||
this.remove(item.id); | ||
resolve(id); | ||
this.remove(item.id); | ||
} | ||
}); | ||
this.errorNotifier.subscribe((e) => { | ||
reject(e); | ||
if (item.id === e.id) { | ||
this.remove(item.id); | ||
reject(e); | ||
} | ||
}); | ||
setTimeout(() => { | ||
if (this.queue.findIndex((qi) => qi.id === item.id) !== -1) { | ||
this.remove(item.id); | ||
console.warn(`REMOVING PACKET THAT TIMED OUT ${item.id}`); | ||
reject({ | ||
id: item.id, | ||
error: Protobuf.Routing_Error.TIMEOUT | ||
}); | ||
} | ||
}); | ||
}, 60000); | ||
}) | ||
@@ -37,9 +47,5 @@ }; | ||
processAck(id) { | ||
console.warn("PROCESSING ACK", id); | ||
console.log(this.queue); | ||
this.ackNotifier.emit(id); | ||
} | ||
processError(e) { | ||
console.warn("PROCESSING ERROR", e.id); | ||
console.log(this.queue); | ||
this.errorNotifier.emit(e); | ||
@@ -59,8 +65,8 @@ } | ||
this.locked = true; | ||
while (this.queue.filter((p) => !p.waitingAck).length > 0) { | ||
const item = this.queue.filter((p) => !p.waitingAck)[0]; | ||
while (this.queue.filter((p) => !p.sent).length > 0) { | ||
const item = this.queue.filter((p) => !p.sent)[0]; | ||
if (item) { | ||
await new Promise((resolve) => setTimeout(resolve, 200)); | ||
await writeToRadio(item.data); | ||
item.waitingAck = true; | ||
item.sent = true; | ||
} | ||
@@ -67,0 +73,0 @@ } |
{ | ||
"name": "@meshtastic/meshtasticjs", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Browser library for interfacing with meshtastic devices", | ||
@@ -8,2 +8,3 @@ "license": "GPL-3.0-only", | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"generate:protobufs": "protoc --ts_out src/generated/ --ts_opt long_type_string --proto_path protobufs protobufs/*.proto", | ||
@@ -10,0 +11,0 @@ "generate:docs": "typedoc src/index.ts", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
554045
11677