Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RTU: Check CRC before signalling an exception response.
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.
- Loading branch information