Refactoring e correzione degli indirizzi

This commit is contained in:
Giuseppe Raffa
2026-05-13 13:11:59 +02:00
parent 9a299586f4
commit cc006a8791

View File

@@ -1,7 +1,7 @@
const { SerialPort } = require('serialport'); const { SerialPort } = require('serialport');
const errors = require('./errors'); const errors = require('./errors');
const address = 0x04; const address = 0x40;
const frameLength = 13; const frameLength = 13;
const timeoutMS = 700; const timeoutMS = 700;
const retryDelayMS = 200; const retryDelayMS = 200;
@@ -12,7 +12,7 @@ const r3 = v => Math.round(v * 1000) / 1000; // 0.001 — tensioni cella
const r2 = v => Math.round(v * 100) / 100; // 0.01 — temperature in kelvin (SignalK) const r2 = v => Math.round(v * 100) / 100; // 0.01 — temperature in kelvin (SignalK)
class BMS { class BMS {
constructor({ device, retries = 5, log = () => {} } = {}) { constructor({ device, retries = 5, log = () => { } } = {}) {
this.device = device; this.device = device;
this.retries = retries; this.retries = retries;
this.log = log; this.log = log;
@@ -75,7 +75,7 @@ class BMS {
throw lastErr || new Error(`cmd ${cmd} failed after ${this.retries} retries`); throw lastErr || new Error(`cmd ${cmd} failed after ${this.retries} retries`);
}; };
const next = this._queue.then(run, run); const next = this._queue.then(run, run);
this._queue = next.catch(() => {}); // non rompere la coda al primo errore this._queue = next.catch(() => { }); // non rompere la coda al primo errore
return next; return next;
} }
@@ -180,7 +180,7 @@ class BMS {
const d = await this._sendBatch('94'); const d = await this._sendBatch('94');
if (!d) return null; if (!d) return null;
const stateByte = d.readInt8(4); const stateByte = d.readInt8(4);
const stateNames = ['DI1','DI2','DI3','DI4','DO1','DO2','DO3','DO4']; const stateNames = ['DI1', 'DI2', 'DI3', 'DI4', 'DO1', 'DO2', 'DO3', 'DO4'];
const states = {}; const states = {};
for (let i = 0; i < 8; i++) states[stateNames[i]] = !!((stateByte >> i) & 1); for (let i = 0; i < 8; i++) states[stateNames[i]] = !!((stateByte >> i) & 1);
const data = { const data = {