node-red-contrib-victron-ble
Version:
node-red node to parse Instant Readout advertisement data from Victron BLE devices
58 lines (57 loc) • 2.8 kB
JavaScript
;
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.SmartLithium = exports.BalancerStatus = void 0;
const base_1 = require("./base");
var BalancerStatus;
(function (BalancerStatus) {
BalancerStatus[BalancerStatus["UNKNOWN"] = 0] = "UNKNOWN";
BalancerStatus[BalancerStatus["BALANCED"] = 1] = "BALANCED";
BalancerStatus[BalancerStatus["BALANCING"] = 2] = "BALANCING";
BalancerStatus[BalancerStatus["IMBALANCE"] = 3] = "IMBALANCE";
})(BalancerStatus || (exports.BalancerStatus = BalancerStatus = {}));
class SmartLithium extends base_1.Device {
bmsFlags;
errorFlags;
batteryVoltage;
batteryTemperature;
cellVoltages;
balancerStatus;
parseDecrypted(decrypted) {
const reader = new base_1.BitReader(decrypted);
const bms_flags = reader.readUnsignedInt(32);
const error_flags = reader.readUnsignedInt(16);
const cell_voltages = Array.from({ length: 8 }, () => reader.readUnsignedInt(7));
const battery_voltage = reader.readUnsignedInt(12);
const balancer_status = reader.readUnsignedInt(4);
const battery_temperature = reader.readUnsignedInt(7);
this.bmsFlags = bms_flags;
this.errorFlags = error_flags;
this.cellVoltages = cell_voltages.map(v => parseCellVoltage(v));
this.batteryVoltage = battery_voltage !== 0x0FFF ? battery_voltage / 100.0 : undefined;
this.balancerStatus = balancer_status !== 0xF ? balancer_status : undefined;
this.batteryTemperature = battery_temperature !== 0x7F ? (battery_temperature - 40) : undefined;
}
}
exports.SmartLithium = SmartLithium;
__decorate([
(0, base_1.EnumField)(BalancerStatus),
__metadata("design:type", Number)
], SmartLithium.prototype, "balancerStatus", void 0);
function parseCellVoltage(payload) {
if (payload === 0x00)
return Number.NEGATIVE_INFINITY;
if (payload === 0x7E)
return Number.POSITIVE_INFINITY;
if (payload === 0x7F)
return null;
return (260 + payload) / 100.0;
}