mesh-net-codec
Version:
Decoder for enless LoRaWAN data frames.
45 lines (36 loc) • 1.41 kB
JavaScript
const Device = require("./device/device").default;
const template = require("./../tools/template").default;
const parsers = require("./../tools/parsers");
class D600_031 extends Device {
constructor() {
super("Temp Ins");
this.PAYLOAD_LENGTH = 28;
this.template.addValueField({
"temperature 1": {
unit: "°C",
value: template.templatedValue(12, 4, (hex) => parsers.hexToInt(hex, 10)),
},
});
this.template.addValueField({
"temperature 2": {
unit: "°C",
value: template.templatedValue(16, 4, (hex) => parsers.hexToUInt(hex, 10)),
},
});
this.template.addStateField({
battery: template.templatedValue(24, 4, parsers.hexToBatteryLvl),
});
this.template.setField(template.fields.ALARM_STATUS, template.templatedValue(20, 4, this.alarmParser));
}
alarmParser(hexValue) {
const defs = [
{ name: "temperature 1", values: [{ high: false }, { high: true }], bit: 1 },
{ name: "temperature 1", values: [{ low: false }, { low: true }], bit: 2 },
];
return parsers.hexToStatus(hexValue, defs);
}
decode(payload) {
return super.decode(payload, this.PAYLOAD_LENGTH);
}
}
exports.device = D600_031;