Merge pull request #215 from cyberman54/development
bugfix payload decoder packed_decoder.js
This commit is contained in:
commit
ee55176e18
@ -23,7 +23,7 @@ function Decoder(bytes, port) {
|
|||||||
|
|
||||||
if (port === 3) {
|
if (port === 3) {
|
||||||
// device config data
|
// device config data
|
||||||
return decode(bytes, [uint8, uint8, uint16, uint8, uint8, uint8, uint8, bitmap, bitmap, version], ['lorasf', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags', 'payloadmask', 'version']);
|
return decode(bytes, [uint8, uint8, uint16, uint8, uint8, uint8, uint8, bitmap1, bitmap2, version], ['lorasf', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags', 'payloadmask', 'version']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port === 4) {
|
if (port === 4) {
|
||||||
@ -161,8 +161,8 @@ var pressure = function (bytes) {
|
|||||||
};
|
};
|
||||||
pressure.BYTES = 2;
|
pressure.BYTES = 2;
|
||||||
|
|
||||||
var bitmap = function (byte) {
|
var bitmap1 = function (byte) {
|
||||||
if (byte.length !== bitmap.BYTES) {
|
if (byte.length !== bitmap1.BYTES) {
|
||||||
throw new Error('Bitmap must have exactly 1 byte');
|
throw new Error('Bitmap must have exactly 1 byte');
|
||||||
}
|
}
|
||||||
var i = bytesToInt(byte);
|
var i = bytesToInt(byte);
|
||||||
@ -173,7 +173,21 @@ var bitmap = function (byte) {
|
|||||||
return obj;
|
return obj;
|
||||||
}, {});
|
}, {});
|
||||||
};
|
};
|
||||||
bitmap.BYTES = 1;
|
bitmap1.BYTES = 1;
|
||||||
|
|
||||||
|
var bitmap2 = function (byte) {
|
||||||
|
if (byte.length !== bitmap2.BYTES) {
|
||||||
|
throw new Error('Bitmap must have exactly 1 byte');
|
||||||
|
}
|
||||||
|
var i = bytesToInt(byte);
|
||||||
|
var bm = ('00000000' + Number(i).toString(2)).substr(-8).split('').map(Number).map(Boolean);
|
||||||
|
return ['gps', 'alarm', 'bme', 'counter', 'sensor1', 'sensor2', 'sensor3', 'battery']
|
||||||
|
.reduce(function (obj, pos, index) {
|
||||||
|
obj[pos] = +bm[index];
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
bitmap2.BYTES = 1;
|
||||||
|
|
||||||
var decode = function (bytes, mask, names) {
|
var decode = function (bytes, mask, names) {
|
||||||
|
|
||||||
@ -208,7 +222,8 @@ if (typeof module === 'object' && typeof module.exports !== 'undefined') {
|
|||||||
pressure: pressure,
|
pressure: pressure,
|
||||||
latLng: latLng,
|
latLng: latLng,
|
||||||
hdop: hdop,
|
hdop: hdop,
|
||||||
bitmap: bitmap,
|
bitmap1: bitmap1,
|
||||||
|
bitmap2: bitmap2,
|
||||||
version: version,
|
version: version,
|
||||||
decode: decode
|
decode: decode
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user