From 0270c742931ff23eeae00560102b48a6a0bf54a5 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 9 Mar 2025 20:59:43 +1300 Subject: [PATCH] log raw lora bytes received --- index.html | 5 +++++ src/connection/connection.js | 10 ++++++++++ src/constants.js | 1 + src/packet.js | 13 ++++--------- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 363d3e4..d5a6e88 100644 --- a/index.html +++ b/index.html @@ -249,6 +249,11 @@ console.log("ExportContact", event); }); + this.connection.on(Constants.PushCodes.LogRxData, async (event) => { + console.log("LogRxData", event) + console.log(this.bytesToHex(event.raw)); + }); + }, onDisconnected() { console.log("disconnected"); diff --git a/src/connection/connection.js b/src/connection/connection.js index fce058f..4d9ce8d 100644 --- a/src/connection/connection.js +++ b/src/connection/connection.js @@ -273,6 +273,8 @@ class Connection extends EventEmitter { this.onLoginSuccessPush(bufferReader); } else if(responseCode === Constants.PushCodes.StatusResponse){ this.onStatusResponsePush(bufferReader); + } else if(responseCode === Constants.PushCodes.LogRxData){ + this.onLogRxDataPush(bufferReader); } else { console.log("unhandled frame", frame); } @@ -319,6 +321,14 @@ class Connection extends EventEmitter { }); } + onLogRxDataPush(bufferReader) { + this.emit(Constants.PushCodes.LogRxData, { + lastSnr: bufferReader.readInt8() / 4, + lastRssi: bufferReader.readInt8(), + raw: bufferReader.readRemainingBytes(), + }); + } + onOkResponse(bufferReader) { this.emit(Constants.ResponseCodes.Ok, { diff --git a/src/constants.js b/src/constants.js index 3583a52..d715f81 100644 --- a/src/constants.js +++ b/src/constants.js @@ -68,6 +68,7 @@ class Constants { LoginSuccess: 0x85, LoginFail: 0x86, // not usable yet StatusResponse: 0x87, + LogRxData: 0x88, } static AdvType = { diff --git a/src/packet.js b/src/packet.js index d7f6753..914e094 100644 --- a/src/packet.js +++ b/src/packet.js @@ -121,22 +121,17 @@ class Packet { const src = bufferReader.readByte(); const encrypted = bufferReader.readRemainingBytes(); - // convert to hex - const destHex = dest.toString(16); - const srcHex = src.toString(16); - const encryptedHex = Buffer.from(encrypted).toString("hex"); - return { - src: srcHex, - dest: destHex, - encrypted: encryptedHex, + src: src, + dest: dest, + encrypted: encrypted, }; } parsePayloadTypeAck() { return { - ack_code: Buffer.from(this.payload).toString("hex"), + ack_code: this.payload, }; }