From 7a23440666290b29f46a70e2803eaa6c262fa29d Mon Sep 17 00:00:00 2001 From: maze Date: Thu, 12 Mar 2026 17:14:43 +0100 Subject: [PATCH] Fix incorrect lat/lon decoding --- src/packet.ts | 6 ++---- test/packet.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/packet.ts b/src/packet.ts index 65418f6..f59b5cd 100644 --- a/src/packet.ts +++ b/src/packet.ts @@ -225,8 +225,6 @@ export class Packet implements IPacket { throw new Error(`Unsupported payload type: ${this.payloadType}`); } - console.log('packet decode with structure:', typeof withStructure, withStructure, { result }); - if (typeof withStructure === "boolean" && withStructure && "segment" in result && "payload" in result) { this.ensureStructure(); const structure = [ ...this.structure!, result.segment ]; @@ -408,8 +406,8 @@ export class Packet implements IPacket { } if (appdata.hasLocation) { - const lat = reader.readInt32LE() / 100000; - const lon = reader.readInt32LE() / 100000; + const lat = reader.readInt32LE() / 1000000; + const lon = reader.readInt32LE() / 1000000; appdata.location = [lat, lon]; if (typeof withSegment === "boolean" && withSegment) { segment!.fields.push({ type: FieldType.UINT32_LE, name: "latitude", size: 4, value: lat }); diff --git a/test/packet.test.ts b/test/packet.test.ts index 9459726..74779e8 100644 --- a/test/packet.test.ts +++ b/test/packet.test.ts @@ -94,8 +94,8 @@ describe('Packet.fromBytes', () => { expect(adv.appdata.hasName).toBe(true); // location values: parser appears to scale values by 10 here, accept that expect(adv.appdata.location).toBeDefined(); - expect(adv.appdata.location![0] / 10).toBeCloseTo(51.45986, 5); - expect(adv.appdata.location![1] / 10).toBeCloseTo(5.45422, 5); + expect(adv.appdata.location![0] / 10).toBeCloseTo(5.145986, 5); + expect(adv.appdata.location![1] / 10).toBeCloseTo(0.545422, 5); expect(adv.appdata.name).toBe('NL-EHV-VBGB-RPTR'); expect(pkt.hash().toUpperCase()).toBe('67C10F75168ECC8C'); });