Fix non-END 0x16 leading to early frame termination#3
Open
Fix non-END 0x16 leading to early frame termination#3
0x16 leading to early frame termination#3Conversation
0x16 leading to early frame termination0x16 leading to early frame termination
Contributor
|
Only just saw this PR, my apologies for the delay. Could you merge both your commits as the second one seems to rewrite the first one anyway. |
Author
|
@hrbonz Hi! It's great to be able to help! I've reviewed the branch and am merging the two commits you mentioned. I totally get it - reading the documentation takes a lot of effort. Thanks so much for all your hard work! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 asENDto terminate the frame. Later checksum verification fails since theframedata[-2]is mistaken as CS.Another potential problem could be that there is
0x16inaddrsection. 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->0x16format.8 states are provided:
0xFEb_start)ctl_codectl_codereceived, next byte islengthlengthbyte received, set counter to findCSCSbyte received, waiting forb_endb_endreceivedVerification
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! ☕️