From c0c704956c7e52d55b203a825cd0ea84b7299c4f Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Fri, 16 Feb 2024 13:05:27 +0100 Subject: [PATCH] feat(wirepas): record local timestamp --- wirepas-5g-mesh-gateway/decodePayload.spec.ts | 9 +++++++-- wirepas-5g-mesh-gateway/decodePayload.ts | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/wirepas-5g-mesh-gateway/decodePayload.spec.ts b/wirepas-5g-mesh-gateway/decodePayload.spec.ts index 3fd52a5..53548d6 100644 --- a/wirepas-5g-mesh-gateway/decodePayload.spec.ts +++ b/wirepas-5g-mesh-gateway/decodePayload.spec.ts @@ -4,6 +4,8 @@ import assert from 'node:assert/strict' void describe('decodePayload()', () => { void it('should decode a regular payload', () => { + const now = Date.now() + const payload = Buffer.from( [ // [0x01: COUNTER] [0x04] [size_t counter] @@ -52,11 +54,14 @@ void describe('decodePayload()', () => { 'hex', ) - const decoded = decodePayload(payload) + const decoded = decodePayload(payload, undefined, () => now) assert.deepEqual(decoded, { // eslint-disable-next-line @typescript-eslint/no-loss-of-precision - temp: 24.479999542236328, + temp: { + v: 24.479999542236328, + ts: now, + }, }) }) diff --git a/wirepas-5g-mesh-gateway/decodePayload.ts b/wirepas-5g-mesh-gateway/decodePayload.ts index 543ba0b..c67cfc6 100644 --- a/wirepas-5g-mesh-gateway/decodePayload.ts +++ b/wirepas-5g-mesh-gateway/decodePayload.ts @@ -1,6 +1,10 @@ import { ScannableArray } from './ScannableArray.js' export type Wirepas5GMeshNodePayload = { - temp?: number + temp?: { + v: number + // The local timestamp + ts: number + } btn?: { // The ID of the pressed button v: number @@ -166,7 +170,13 @@ export const decodePayload = ( skip() continue case MessageType.TEMPERATURE: - message = { ...message, temp: readFloat(msg, len) } + message = { + ...message, + temp: { + v: readFloat(msg, len), + ts: now(), + }, + } continue default: onUnknown?.(type, msg.pos() - 1)