var payload = msg.data.toString();
var type = parseInt(payload.slice(0, 2), 16);
var msgNew = {};
msg.type = type;
switch (type) {
default:
msg.error = 'Unknown type: ' + type
break;
case 0x57:
var status = parseInt(payload.slice(2,4), 16) & 0x1f
var len = (payload.length - 4)/4
msg.lowbat = status & 0x2;
msg.numSensors = ((status >> 4) & 0x1) + 1
msg.msg = "Periodic data frame"
for(var i=0; i<len; i++) {
var temperature = parseInt(payload.slice(4*i+4,4*i+8), 16);
// check, if negative temperature
if ((temperature & 0x8000) > 0) {
temperature = temperature - 0x10000;
}
msgNew["temp"+(i+1)] = temperature/10
}
break;
}
var flowTemperature = msgNew.temp1;
var returnFlowTemperature = msgNew.temp2;
var lowbat = msg.lowbat;
var deltaT = flowTemperature - returnFlowTemperature;
var numSensors = msg.numSensors;
var metadata = {numSensors: numSensors, lowbat: lowbat};
var msg = {flowTemperature: flowTemperature, returnFlowTemperature: returnFlowTemperature, deltaT: deltaT};
return {msg: msg, metadata: metadata, msgType: msgType};