Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTU: Check CRC in exception ADU #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

acolomb
Copy link
Contributor

@acolomb acolomb commented Mar 10, 2021

The first five response ADU bytes received are checked for a valid
function code, assuming an error if it is unknown. The received ADU
part is then treated as an exception frame. But even those must pass
the CRC validation, otherwise the supposed "wrong" function code
cannot even be trusted at all.

This change adds the CRC check for the first five bytes, falling
through to further processing when it fails. The overall CRC and
function code is checked later in parse_response_adu(), so an invalid
code will be detected again at that point.

This is mainly relevant if the responses are received partially from
the serial input buffer, which will cause many CRC and parsing
failures. In those cases, the reported exception will likely be a
CRCError or ValueError for the whole ADU, instead of an invalid
function code based on only the first 5 bytes.

Note that it works best in conjunction with #117, failing early if the response function code does not match the request.

The first five response ADU bytes received are checked for a valid
function code, assuming an error if it is unknown.  The received ADU
part is then treated as an exception frame.  But even those must pass
the CRC validation, otherwise the supposed "wrong" function code
cannot even be trusted at all.

This change adds the CRC check for the first five bytes, falling
through to further processing when it fails.  The overall CRC and
function code is checked later in parse_response_adu(), so an invalid
code will be detected again at that point.

This is mainly relevant if the responses are received partially from
the serial input buffer, which will cause many CRC and parsing
failures.  In those cases, the reported exception will likely be a
CRCError or ValueError for the whole ADU, instead of an invalid
function code based on only the first 5 bytes.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 95.726% when pulling 964d09f on acolomb:check-crc-in-exception-adu into f1128a7 on AdvancedClimateSystems:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 95.726% when pulling 964d09f on acolomb:check-crc-in-exception-adu into f1128a7 on AdvancedClimateSystems:master.

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.

None yet

2 participants