diff --git a/src/core/constants.js b/src/core/constants.js index 948a4fa..62cb2c8 100644 --- a/src/core/constants.js +++ b/src/core/constants.js @@ -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) diff --git a/src/core/reader.js b/src/core/reader.js index 69c2b7c..5ee4565 100644 --- a/src/core/reader.js +++ b/src/core/reader.js @@ -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;