From b9949d8eb9fe826b49c150429ea82ab05b1a94b3 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Fri, 27 Dec 2019 12:57:22 +0100 Subject: [PATCH] bugfix in decoders plain & packed --- src/TTN/packed_decoder.js | 8 +++++--- src/TTN/plain_decoder.js | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index 0624d885..291ee8a7 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -4,6 +4,8 @@ function Decoder(bytes, port) { var decoded = {}; + decoded.wifi = 0; + decoded.ble = 0; if (bytes.length === 0) { return {}; @@ -147,7 +149,7 @@ var int8 = function (bytes) { if (bytes.length !== int8.BYTES) { throw new Error('int8 must have exactly 1 byte'); } - var value = +(bytesToInt(bytes)); + var value = +(bytesToInt(bytes)); if (value > 127) { value -= 256; } @@ -159,7 +161,7 @@ var int16 = function (bytes) { if (bytes.length !== int16.BYTES) { throw new Error('int16 must have exactly 2 bytes'); } - var value = +(bytesToInt(bytes)); + var value = +(bytesToInt(bytes)); if (value > 32767) { value -= 65536; } @@ -171,7 +173,7 @@ var int32 = function (bytes) { if (bytes.length !== int32.BYTES) { throw new Error('int32 must have exactly 4 bytes'); } - var value = +(bytesToInt(bytes)); + var value = +(bytesToInt(bytes)); if (value > 2147483647) { value -= 4294967296; } diff --git a/src/TTN/plain_decoder.js b/src/TTN/plain_decoder.js index b7478b9c..4e1a7a17 100644 --- a/src/TTN/plain_decoder.js +++ b/src/TTN/plain_decoder.js @@ -3,6 +3,8 @@ function Decoder(bytes, port) { var decoded = {}; + decoded.wifi = 0; + decoded.ble = 0; if (port === 1) { var i = 0; @@ -10,7 +12,7 @@ function Decoder(bytes, port) { if (bytes.length >= 2) { decoded.wifi = (bytes[i++] << 8) | bytes[i++]; } - + if (bytes.length === 4 || bytes.length > 15) { decoded.ble = (bytes[i++] << 8) | bytes[i++]; }