mesh-net-codec
Version:
Decoder for enless LoRaWAN data frames.
70 lines (58 loc) • 2.59 kB
JavaScript
const Device = require("./device/device").default;
const template = require("./../tools/template").default;
const parsers = require("./../tools/parsers");
class D600_036 extends Device {
constructor() {
super("Tx pulse");
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 flow", values: [{ high: false }, { high: true }], bit: 1 },
{ name: "pulse ch2 flow", values: [{ high: false }, { high: true }], bit: 2 },
{ name: "pulse oc flow", values: [{ high: false }, { high: true }], bit: 3 },
{ name: "pulse ch1 flow", values: [{ low: false }, { low: true }], bit: 5 },
{ name: "pulse ch2 flow", values: [{ low: false }, { low: true }], bit: 6 },
{ name: "pulse oc flow", values: [{ low: false }, { low: true }], bit: 7 },
{ name: "pulse ch1 leak", values: [false, true], bit: 9 },
{ name: "pulse ch2 leak", values: [false, true], bit: 10 },
{ name: "pulse oc leak", values: [false, true], bit: 11 },
];
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_036;