coolchip/luxtronik2

Uncaught exception: The value of "offset" is out of range

UncleSamSwiss opened this issue · 2 comments

Unfortunately I still have cases where we try to read more data than is available. In this case, the problem seems to be that we received 4 bytes of data but already want to read the first 8 bytes:

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 4. Received 8
at boundsError (internal/buffer.js:83:9)
at Buffer.readInt32BE (internal/buffer.js:479:5)
at Luxtronik.<anonymous> (/opt/iobroker/node_modules/luxtronik2/luxtronik.js:480:41)
at Socket.emit (events.js:375:28)at Socket.emit (domain.js:470:12)
at addChunk (internal/streams/readable.js:290:12)
at readableAddChunk (internal/streams/readable.js:265:9)
at Socket.Readable.push (internal/streams/readable.js:204:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)

Notes for analyzing this:
Exception complains about a read at offset 8.

Line 480:
const paramCount = data.readInt32BE(firstReadableDataAddress - 4);

This means firstReadableDataAddress is 12, which is set in line 475 above in handling command 3004 ("Calculated values").

The device should send 12 bytes of headers plus the data for the calculated values, but the buffer only contains 8 bytes at this point. Looks like there's still a hiccup with collecting all the data packets first. :(

In the next release if added some code that trys to check the received data. If something is missing it respond with "parameter count missing".
Hope that will help.