Fix off-by-one error when checking for last fragment #18
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.
I discovered this bug when trying to update my inovelli LZW30 switches to firmware 1.22. The firmware updater worked fine for other firmware files, but not this one.
The reason is that there's a bug in the logic for checking for whether this is the last fragment, which falsely sets to true when this is the next-to-last fragment and the actual last fragment will only have 1 byte in it.
This only causes an actual problem when the firmware size is 1 more than a multiple of the fragment size, which is the case with the LZW30 firmware version 1.22 (93601 bytes).
Once I applied this change locally, I was able to successfully update my switches. I successfully flashed multiple firmware files with a variety of sizes, resulting in last-fragment sizes of 40 bytes, 1 byte, and something in between.
For more context, see https://community.inovelli.com/t/unable-to-update-black-switch-firmware-using-hubitat/9413/2