// J.G : 07-08-2024 V 1.1 GF Mobile Ultraschall HM version
var decodedMsg = {};
if (msg && msg.data && msg.data.length >= 32) {
var filterCorruptData = msg.data.slice(-18);
if (filterCorruptData != "ffffffffffffffffff") {
decodedMsg = main(msg.data);
}
}
return {
msg: decodedMsg,
metadata: metadata,
msgType: msgType
};
function main(data) {
var decodedData = {};
var gemessenesGesamtVolumeData = data.slice(-8); // volume
//var gemessenerTemperaturunterschied = data.slice(-16, -8); // deltaT ...doens't work
var gemesseneTemperaturKalt = data.slice(-24, -16); // returnFlowTemperature
var gemesseneTemperaturWarm = data.slice(-32, -24); // flowTemperature
var gemesseneEnergie = data.slice(-40, -32); // heatMeterEnergy
var gemesseneLeistung = data.slice(-48, -40); // power
var gemessenerDurchfluss = data.slice(-56, -48); // flowRate
var gemesseneGeschwindigkeit = data.slice(-64, -56); // flowSpeed
decodedData.waterMeter = HexToFloat32(gemessenesGesamtVolumeData); // m3
//decodedData.deltaT = HexToFloat32(gemessenerTemperaturunterschied); // °C ... doesn't work, doing it manually below
decodedData.returnFlowTemperature = HexToFloat32(gemesseneTemperaturKalt); // °C
decodedData.flowTemperature = HexToFloat32(gemesseneTemperaturWarm); // °C
decodedData.heatMeterEnergy = HexToFloat32(gemesseneEnergie); // kWh
decodedData.power = HexToFloat32(gemesseneLeistung); // kW
decodedData.flowRate = HexToFloat32(gemessenerDurchfluss); // m3/std
decodedData.flowSpeed = HexToFloat32(gemesseneGeschwindigkeit); // m/s
decodedData.deltaT = decodedData.flowTemperature - decodedData.returnFlowTemperature;
decodedData.data = msg.data;
return decodedData;
}
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 (var i = 0; i < mantissa.length; i += 1) {
float32 += parseInt(mantissa[i]) ? Math.pow(2, exp) : 0;
exp--;
}
return float32 * sign;
} else return 0;
}