UNPKG

node-red-contrib-victron-ble

Version:

node-red node to parse Instant Readout advertisement data from Victron BLE devices

69 lines (68 loc) 3.17 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BatteryMonitor = exports.AuxMode = void 0; const base_1 = require("./base"); var AuxMode; (function (AuxMode) { AuxMode[AuxMode["STARTER_VOLTAGE"] = 0] = "STARTER_VOLTAGE"; AuxMode[AuxMode["MIDPOINT_VOLTAGE"] = 1] = "MIDPOINT_VOLTAGE"; AuxMode[AuxMode["TEMPERATURE"] = 2] = "TEMPERATURE"; AuxMode[AuxMode["DISABLED"] = 3] = "DISABLED"; })(AuxMode || (exports.AuxMode = AuxMode = {})); class BatteryMonitor extends base_1.Device { remainingMins; voltage; alarm; auxMode; current; consumedAh; soc; starterVoltage; midpointVoltage; temperature; parseDecrypted(decrypted) { const reader = new base_1.BitReader(decrypted); const remaining_mins = reader.readUnsignedInt(16); const voltage = reader.readSignedInt(16); const alarm = reader.readUnsignedInt(16); const aux = reader.readUnsignedInt(16); const aux_mode = reader.readUnsignedInt(2); const current = reader.readSignedInt(22); const consumed_ah = reader.readUnsignedInt(20); const soc = reader.readUnsignedInt(10); this.remainingMins = remaining_mins !== 0xffff ? remaining_mins : undefined; this.voltage = voltage !== 0x7fff ? voltage / 100 : undefined; this.alarm = alarm in base_1.AlarmReason ? alarm : base_1.AlarmReason.NO_ALARM; this.auxMode = aux_mode in AuxMode ? aux_mode : AuxMode.DISABLED; this.current = current !== 0x3fffff ? current / 1000 : undefined; this.consumedAh = consumed_ah !== 0xfffff ? -consumed_ah / 10 : undefined; this.soc = soc !== 0x3ff ? soc / 10 : undefined; if (this.auxMode === AuxMode.STARTER_VOLTAGE) { this.starterVoltage = base_1.BitReader.toSignedInt(aux, 16) / 100; } else if (this.auxMode === AuxMode.MIDPOINT_VOLTAGE) { this.midpointVoltage = aux / 100; } else if (this.auxMode === AuxMode.TEMPERATURE) { this.temperature = aux / 100; } } } exports.BatteryMonitor = BatteryMonitor; __decorate([ (0, base_1.EnumField)(base_1.AlarmReason), __metadata("design:type", Number) ], BatteryMonitor.prototype, "alarm", void 0); __decorate([ (0, base_1.EnumField)(AuxMode), __metadata("design:type", Number) ], BatteryMonitor.prototype, "auxMode", void 0);