From b7a21b5e8e6b09688d90fee428116b4b5d58925d Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 9 Mar 2025 21:19:59 +1300 Subject: [PATCH] send and receive raw data --- src/connection/connection.js | 20 ++++++++++++++++++++ src/constants.js | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/connection/connection.js b/src/connection/connection.js index 4d9ce8d..dbbc75e 100644 --- a/src/connection/connection.js +++ b/src/connection/connection.js @@ -206,6 +206,15 @@ class Connection extends EventEmitter { await this.sendToRadioFrame(data.toBytes()); } + async sendCommandSendRawData(path, rawData) { + const data = new BufferWriter(); + data.writeByte(Constants.CommandCodes.SendRawData); + data.writeByte(path.length); + data.writeBytes(path); + data.writeBytes(rawData); + await this.sendToRadioFrame(data.toBytes()); + } + async sendCommandSendLogin(publicKey, password) { const data = new BufferWriter(); data.writeByte(Constants.CommandCodes.SendLogin); @@ -269,6 +278,8 @@ class Connection extends EventEmitter { this.onSendConfirmedPush(bufferReader); } else if(responseCode === Constants.PushCodes.MsgWaiting){ this.onMsgWaitingPush(bufferReader); + } else if(responseCode === Constants.PushCodes.RawData){ + this.onRawDataPush(bufferReader); } else if(responseCode === Constants.PushCodes.LoginSuccess){ this.onLoginSuccessPush(bufferReader); } else if(responseCode === Constants.PushCodes.StatusResponse){ @@ -306,6 +317,15 @@ class Connection extends EventEmitter { }); } + onRawDataPush(bufferReader) { + this.emit(Constants.PushCodes.RawData, { + lastSnr: bufferReader.readInt8() / 4, + lastRssi: bufferReader.readInt8(), + reserved: bufferReader.readByte(), + payload: bufferReader.readRemainingBytes(), + }); + } + onLoginSuccessPush(bufferReader) { this.emit(Constants.PushCodes.LoginSuccess, { reserved: bufferReader.readByte(), // reserved diff --git a/src/constants.js b/src/constants.js index d715f81..5dbc360 100644 --- a/src/constants.js +++ b/src/constants.js @@ -36,7 +36,7 @@ class Constants { DeviceQuery: 22, ExportPrivateKey: 23, ImportPrivateKey: 24, - SendRawData: 25, // todo + SendRawData: 25, SendLogin: 26, // todo SendStatusReq: 27, // todo } @@ -65,6 +65,7 @@ class Constants { PathUpdated: 0x81, SendConfirmed: 0x82, MsgWaiting: 0x83, + RawData: 0x84, LoginSuccess: 0x85, LoginFail: 0x86, // not usable yet StatusResponse: 0x87,