TTN decoders updated

This commit is contained in:
Klaus K Wilting 2018-09-17 21:57:01 +02:00
parent 836572eeb2
commit 52efcb7b01
2 changed files with 14 additions and 3 deletions

View File

@ -18,12 +18,12 @@ function Decoder(bytes, port) {
if (port === 2) { if (port === 2) {
// device status data // device status data
return decode(bytes, [uint16, uptime, uint8, uint32], ['voltage', 'uptime', 'cputemp', 'memory']); return decode(bytes, [uint16, uptime, uint8, uint32, uint8, uint8], ['voltage', 'uptime', 'cputemp', 'memory', 'reset0', 'reset1']);
} }
if (port === 3) { if (port === 3) {
// device config data // device config data
return decode(bytes, [uint8, uint8, uint16, uint8, uint8, uint8, uint8, bitmap], ['lorasf', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags']); return decode(bytes, [uint8, uint8, uint16, uint8, uint8, uint8, uint8, bitmap, version], ['lorasf', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags', 'version']);
} }
if (port === 4) { if (port === 4) {
@ -55,6 +55,14 @@ var bytesToInt = function (bytes) {
return i; return i;
}; };
var version = function (bytes) {
if (bytes.length !== version.BYTES) {
throw new Error('version must have exactly 10 bytes');
}
return String.fromCharCode.apply(null, bytes).split('\u0000')[0];
};
version.BYTES = 10;
var uint8 = function (bytes) { var uint8 = function (bytes) {
if (bytes.length !== uint8.BYTES) { if (bytes.length !== uint8.BYTES) {
throw new Error('uint8 must have exactly 1 byte'); throw new Error('uint8 must have exactly 1 byte');
@ -180,12 +188,12 @@ if (typeof module === 'object' && typeof module.exports !== 'undefined') {
uint16: uint16, uint16: uint16,
uint32: uint32, uint32: uint32,
uptime: uptime, uptime: uptime,
reset: reset,
temperature: temperature, temperature: temperature,
humidity: humidity, humidity: humidity,
latLng: latLng, latLng: latLng,
hdop: hdop, hdop: hdop,
bitmap: bitmap, bitmap: bitmap,
version: version,
decode: decode decode: decode
}; };
} }

View File

@ -25,6 +25,9 @@ function Decoder(bytes, port) {
decoded.uptime = ((bytes[i++] << 56) | (bytes[i++] << 48) | (bytes[i++] << 40) | (bytes[i++] << 32) | decoded.uptime = ((bytes[i++] << 56) | (bytes[i++] << 48) | (bytes[i++] << 40) | (bytes[i++] << 32) |
(bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); (bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]);
decoded.temp = bytes[i++]; decoded.temp = bytes[i++];
decoded.memory = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]);
decoded.reset0 = bytes[i++];
decoded.reset1 = bytes[i++];
} }
if (port === 5) { if (port === 5) {