Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.