fix(unit): use correct byte length for enum resolution in procGetUnit #148
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.
This pull request fixes a bug in
procGetUnitwhere the result ofexecIExpression(stored in a 4-byteint) was passed tobytes2Enumusing only the first byte, but an incorrect length parameter (recvLen) was still being used. This led to enum resolution failing or succeeding by coincidence, depending on the content of unrelated bytes.We now explicitly pass
1as the byte length tobytes2Enum, as only a single byte (res) is intended to be used for the lookup.Example log from
vcontroldbefore the fixThe
getBedarfWarmwasseris a command that reads in 10 bytes and extracts byte 2 to map it onto an enum.Command
vito.xml:unit in
vcontrold.xmlAfter initiating the connection to vcontrold and sending the command, the response is initially parsed correctly:
vcontrold log - correctly parsed (click to show)
After some time, the response is the exact same, but the conversion to enum fails:
vcontrold log - parse error (click to show)
Reason
The enum lookup sometimes fails due to
recvLenbeing passed as10, causingbytes2Enumto look at 10 bytes instead of 1 in:Fix
The fix changes:
to:
Now the lookup works consistently as expected.