mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
fix reading and writing lat lon
This commit is contained in:
parent
feb149ad35
commit
865ca127ac
3 changed files with 17 additions and 4 deletions
|
|
@ -48,6 +48,12 @@ class BufferReader {
|
|||
return view.getUint32(0, true);
|
||||
}
|
||||
|
||||
readInt32LE() {
|
||||
const bytes = this.readBytes(4);
|
||||
const view = new DataView(bytes.buffer);
|
||||
return view.getInt32(0, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default BufferReader;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,13 @@ class BufferWriter {
|
|||
this.writeBytes(bytes);
|
||||
}
|
||||
|
||||
writeInt32LE(num) {
|
||||
const bytes = new Uint8Array(4);
|
||||
const view = new DataView(bytes.buffer);
|
||||
view.setInt32(0, num, true);
|
||||
this.writeBytes(bytes);
|
||||
}
|
||||
|
||||
writeString(string) {
|
||||
this.writeBytes(new TextEncoder().encode(string));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ class Connection extends EventEmitter {
|
|||
async sendCommandSetAdvertLatLon(lat, lon) {
|
||||
const data = new BufferWriter();
|
||||
data.writeByte(Constants.CommandCodes.SetAdvertLatLon);
|
||||
data.writeUInt32LE(lat);
|
||||
data.writeUInt32LE(lon);
|
||||
data.writeInt32LE(lat);
|
||||
data.writeInt32LE(lon);
|
||||
await this.sendToRadioFrame(data.toBytes());
|
||||
}
|
||||
|
||||
|
|
@ -223,8 +223,8 @@ class Connection extends EventEmitter {
|
|||
txPower: bufferReader.readByte(),
|
||||
maxTxPower: bufferReader.readByte(),
|
||||
publicKey: bufferReader.readBytes(32),
|
||||
advLat: bufferReader.readUInt32LE(),
|
||||
advLon: bufferReader.readUInt32LE(),
|
||||
advLat: bufferReader.readInt32LE(),
|
||||
advLon: bufferReader.readInt32LE(),
|
||||
reserved: bufferReader.readBytes(4),
|
||||
radioFreq: bufferReader.readUInt32LE(),
|
||||
radioBw: bufferReader.readUInt32LE(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue