2nd iteration for fixes

This commit is contained in:
Giuseppe Raffa
2026-06-06 14:20:27 +02:00
parent 2385152887
commit 03b572642f
2 changed files with 7 additions and 2 deletions

View File

@@ -103,6 +103,7 @@ const serialProtocol = {
sourceHost: 0xFF, // SRC host/GUI
endOfFrame: 0x0D, // EOF
addressAny: 0x00, // DST = qualsiasi dispositivo (usato per discovery)
defaultDestinationAddress: 0x00, // DST UART usato da DataCOM: l'Addr del registro 1 e' il CAN Rx ID
headerLength: 5, // SOF + DST + SRC + 0x00 + DLEN
tailLength: 3, // CHK_HI + CHK_LO + EOF
// Comandi (scritti nel registro 2)

View File

@@ -74,6 +74,9 @@ class MPPTReader extends EventEmitter {
// Buffer di ricezione e transazione pendente (protocollo sincrono: 1 alla volta)
this.rxBuffer = Buffer.alloc(0);
this.pendingTransaction = null;
// Indirizzo DST usato sul protocollo UART. Il registro Addr identifica il CAN Rx ID;
// DataCOM e il test Python interrogano l'MPPT con DST=0x00.
this.uartDestinationAddress = serialProtocol.defaultDestinationAddress;
// Istanzia gli MPPT configurati (indicizzati per nome logico)
this.mppts = new Map();
@@ -93,7 +96,8 @@ class MPPTReader extends EventEmitter {
this.log(
`[reader] configurazione: device=${this.device}, baudRate=${this.baudRate}, ` +
`pollIntervalMs=${this.pollIntervalMs}, timeoutMs=${this.timeoutMs}, retries=${this.retries}, ` +
`dtr=${this.dtr}, rts=${this.rts}, mppts=${JSON.stringify(Array.from(this.mppts.values()).map((mppt) => ({
`dtr=${this.dtr}, rts=${this.rts}, uartDestinationAddress=${this.uartDestinationAddress}, ` +
`mppts=${JSON.stringify(Array.from(this.mppts.values()).map((mppt) => ({
name: mppt.name,
address: mppt.address,
})))}`
@@ -263,7 +267,7 @@ class MPPTReader extends EventEmitter {
for (const regAddr of pollRegisters) {
try {
this.log(`[reader] leggo MPPT ${mppt.name} address=${mppt.address} registro=${regAddr}`);
const rawValue = await this._readRegister(mppt.address, regAddr);
const rawValue = await this._readRegister(this.uartDestinationAddress, regAddr);
this.log(`[reader] letto MPPT ${mppt.name} address=${mppt.address} registro=${regAddr} raw=${rawValue}`);
mppt.updateRegister(regAddr, rawValue);
updated = true;