Fix non-END 0x16
leading to early frame termination
#3
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.
Hi,
I'm submitting this PR to solve a bug that leads to occasional checksum failures.
Issue Description
The 2nd-last byte of a frame is CS (Checksum), and the last byte (
END
) is a fixed0x16
. When CS happens to be0x16
, it is taken asEND
to terminate the frame. Later checksum verification fails since theframedata[-2]
is mistaken as CS.Another potential problem could be that there is
0x16
inaddr
section. However, it could be circumvented by using the broadcast address.Solution
A state machine is written to recognize the
0xFE
->0x68
->addr
->0x68
->ctl_code
->data
->CS
->0x16
format.8 states are provided:
0xFE
b_start
)ctl_code
ctl_code
received, next byte islength
length
byte received, set counter to findCS
CS
byte received, waiting forb_end
b_end
receivedVerification
The fixed code is applied to read from a real meter. Before this fix, occasional frame checksum errors can be observed. After implementing the proposed modification, no more checksum errors are encountered.
Thank you for your great effort to provide this library! ☕️