Skip to content

Improve RSCP frame reception handling to ensure complete frames are processed - #145

Closed
torbennehmer wants to merge 2 commits into
fsantini:masterfrom
torbennehmer:fix-rcv-loop
Closed

Improve RSCP frame reception handling to ensure complete frames are processed#145
torbennehmer wants to merge 2 commits into
fsantini:masterfrom
torbennehmer:fix-rcv-loop

Conversation

@torbennehmer

Copy link
Copy Markdown
Contributor

Tag EH_REQ_GET_SAVED_ERRORS returns a large amount of data (approx 4k on my end), which gets split by TCP in multiple chunks.

Sample code:

print("query EH_REQ_GET_SAVED_ERRORS")
result = e3dc.sendRequest((RscpTag.EH_REQ_GET_SAVED_ERRORS, RscpType.NoneType, None))
print(json.dumps(result, indent=2, default=str))

This yields:

Traceback (most recent call last):
  File "/home/torben/src/python-e3dc/e3dc/_e3dc_rscp_local.py", line 97, in sendRequest
    receive = self._receive()
  File "/home/torben/src/python-e3dc/e3dc/_e3dc_rscp_local.py", line 75, in _receive
    decData = rscpDecode(self.encdec.decrypt(data))[0]
              ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/torben/src/python-e3dc/e3dc/_rscpLib.py", line 262, in rscpDecode
    return rscpDecode(rscpFrameDecode(data)[0])
                      ~~~~~~~~~~~~~~~^^^^^^
  File "/home/torben/src/python-e3dc/e3dc/_rscpLib.py", line 223, in rscpFrameDecode
    data, crc = struct.unpack(
                ~~~~~~~~~~~~~^
        "<" + str(length) + "s" + crcFmt,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        frameData[struct.calcsize(headerFmt) : totalLen],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
struct.error: unpack requires a buffer of 4216 bytes

Altering the receive call to a loop fixes the problem, it assembles the frame appropriately. Tested various other calls to ensure correct functionality.

Prerequisite for hacs-e3dc PR torbennehmer/hacs-e3dc#373

@torbennehmer

Copy link
Copy Markdown
Contributor Author

#146 looks like the more stable solution to me. closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant