GWF LMB-10-IM-2 Ölzähler
GWF LMB-10-IM-2 Oil meter
Last updated
GWF LMB-10-IM-2 Oil meter
Last updated
//V1.0, 23.08.2021,DS
if (msg.data.substr(14, 2) == "01") {
var decoded = decodeFromHex(msg.data);
decoded.ts = msg.ts;
decoded.rssi = msg.rssi;
decoded.snr = msg.snr;
decoded.toa = msg.toa;
decoded.frequency = msg.frequency;
decoded.dr = msg.dr;
decoded.bat = decodeBattery(msg.bat);
decoded.hex = msg.data;
return {
msg: decoded,
metadata: metadata,
msgType: msgType
};
} else {
return {
msg: msg,
metadata: metadata,
msgType: msgType
};
}
function decodeFromHex(data) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var telemetry = {};
var bytes = parseHexStringToBytes(data);
//Test if medium is oil
var volumeVIF = data.substr(24, 2);
var valueVolume = parseFloat(data.substr(32, 2) + data.substr(30, 2) + data.substr(28, 2) + data.substr(26, 2));
var multiplyFactor = 0;
if (volumeVIF == "12") {
multiplyFactor = 0.0001;
}
if (volumeVIF == "13") {
multiplyFactor = 0.001;
}
if (volumeVIF == "14") {
multiplyFactor = 0.01;
}
if (volumeVIF == "15") {
multiplyFactor = 0.1;
}
if (volumeVIF == "16") {
multiplyFactor = 1;
}
if (volumeVIF == "17") {
multiplyFactor = 10;
}
////////////////////////////////////
//oilMeterVolume
telemetry.oilMeter = valueVolume * multiplyFactor;
///////////////////////////////////
return telemetry;
}
function HexToFloat32(str) {
var int = parseInt(str, 16);
if (int > 0 || int < 0) {
var sign = (int >>> 31) ? -1 : 1;
var exp = (int >>> 23 & 0xff) - 127;
var mantissa = ((int & 0x7fffff) + 0x800000)
.toString(2);
var float32 = 0;
for (i = 0; i < mantissa.length; i += 1) {
float32 += parseInt(mantissa[i]) ? Math.pow(
2, exp) : 0;
exp--;
}
return float32 * sign;
} else return 0;
}
function findRegister(bytes, registersActive) {
var registers = new Array(4);
var start = 3;
for (var i = 0; i < registersActive.length; i++) {
var current = start * (i + 1);
if (registersActive[i] == 1) {
registers[i] = bytes[current] + "." + bytes[
current + 1] + "." + bytes[current + 2];
}
}
return registers;
}
function decodeBattery(byte) {
if (byte == 0) {
return 'External power source';
} else if (byte > 0 && byte < 255) {
return byte / 254 * 100;
} else {
return 'Unknown battery state';
}
}
function calculateBattery(nibbles) {
var result = nibbles[2] * 10;
return result;
}
function parseHexString(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
function parseHexStringToBytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
function parseHexStringToNibbles(hex) {
for (var nibbles = [], c = 0; c < hex.length; c += 1)
nibbles.push(parseInt(hex.substr(c, 1), 16));
return nibbles;
}
function convertToBinary(x) {
var bin = 0;
var rem, i = 1,
step = 1;
while (x != 0) {
rem = x % 2;
x = parseInt(x / 2);
bin = bin + rem * i;
i = i * 10;
}
return bin;
}
function decodeToJson(payload) {
// covert payload to string.
var str = decodeToString(payload);
// parse string to JSON
var data = JSON.parse(str);
return data;
}