mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
send and receive raw data
This commit is contained in:
parent
0270c74293
commit
b7a21b5e8e
2 changed files with 22 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue