mesh-net-codec
Version:
Decoder for enless LoRaWAN data frames.
64 lines (52 loc) • 2.1 kB
JavaScript
const Device = require("./device/device").default;
const template = require("./../tools/template").default;
const parsers = require("./../tools/parsers");
class D600_039 extends Device {
constructor() {
super("Tx Contact");
this.PAYLOAD_LENGTH = 44;
this.template.addValueField({
"pulse ch1": {
unit: "count",
value: template.templatedValue(12, 8, parsers.hexToUInt),
},
});
this.template.addValueField({
"pulse ch2": {
unit: "count",
value: template.templatedValue(20, 8, parsers.hexToUInt),
},
});
this.template.addValueField({
"pulse oc": {
unit: "count",
value: template.templatedValue(28, 8, parsers.hexToUInt),
},
});
this.template.setField(template.fields.ALARM_STATUS, template.templatedValue(36, 4, this.alarmParser));
this.template.addStateField({
battery: template.templatedValue(40, 4, parsers.hexToBatteryLvl),
});
this.template.addStateField(template.templatedValue(40, 4, this.stateParser));
}
alarmParser(hexValue) {
const defs = [
{ name: "pulse ch1", values: [{ change: false }, { change: true }], bit: 1 },
{ name: "pulse ch2", values: [{ change: false }, { change: true }], bit: 2 },
{ name: "pulse oc", values: [{ change: false }, { change: true }], bit: 3 },
];
return parsers.hexToStatus(hexValue, defs);
}
stateParser(hexValue) {
const defs = [
{ name: "pulse ch1", values: ["open", "closed"], bit: 5 },
{ name: "pulse ch2", values: ["open", "closed"], bit: 6 },
{ name: "pulse oc", values: ["open", "closed"], bit: 7 },
];
return parsers.hexToStatus(hexValue, defs);
}
decode(payload) {
return super.decode(payload, this.PAYLOAD_LENGTH);
}
}
exports.device = D600_039;