-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve BCD decoding #167
Improve BCD decoding #167
Conversation
@fredrik-sk are you fine with this compromise? |
@@ -4015,7 +4040,7 @@ mbus_data_variable_header_xml(mbus_data_variable_header *header) | |||
{ | |||
len += snprintf(&buff[len], sizeof(buff) - len, " <SlaveInformation>\n"); | |||
|
|||
len += snprintf(&buff[len], sizeof(buff) - len, " <Id>%lld</Id>\n", mbus_data_bcd_decode(header->id_bcd, 4)); | |||
len += snprintf(&buff[len], sizeof(buff) - len, " <Id>%llX</Id>\n", mbus_data_bcd_decode_hex(header->id_bcd, 4)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and above this line you use "%llX", (upper case hexdecimal). But lines 4221 and below use "%llx" (lower case hexadecimal).
Is this intentional, or is there a correct way that should be used all through the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, thanks for noticing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now
9614634
to
280fc80
Compare
@@ -48,14 +48,14 @@ | |||
<Function>Value during error state</Function> | |||
<StorageNumber>0</StorageNumber> | |||
<Unit>Power (W)</Unit> | |||
<Value>144445223</Value> | |||
<Value>DDDDEBBD</Value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a hexadecimal number. Should this be using some other encoding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the intention of this patch. Since this is a error value (look at the function), it's better to signalize this with a hex value than a unrealistic decimal.
I'm glad that something happends. And that you have found and corrected some issue. |
The convert function mbus_data_bcd_decode (BCD to decimal) suffers from information loss in case of hexacimal digits. So introduce a new function mbus_data_bcd_decode_hex (BCD to hexadecimal), which isn't affected and use this for default XML output. But keep mbus_data_bcd_decode for normalized output.
This updates the XML reference output after recent decoding changes.
280fc80
to
3d41518
Compare
Thanks for the review |
I had one more comment. I see the change has been merged. |
Not sure that i understand your question. Do you mean decimal + hex? |
Yes. Since in the case with negative BCD, seing a minus makes more sense then an F, and having to apply the algorithm by yourself. |
I like to avoid such a structure change in the XML structure. Maybe you prefer the normalized output. Let's stay at this example (SLB_CF-Compact-Integral-MK-MaXX). default output:
normalized output:
|
* Introduce mbus_data_bcd_decode_hex The convert function mbus_data_bcd_decode (BCD to decimal) suffers from information loss in case of hexacimal digits. So introduce a new function mbus_data_bcd_decode_hex (BCD to hexadecimal), which isn't affected and use this for default XML output. But keep mbus_data_bcd_decode for normalized output. (cherry picked from commit 17a7328)
* Introduce mbus_data_bcd_decode_hex The convert function mbus_data_bcd_decode (BCD to decimal) suffers from information loss in case of hexacimal digits. So introduce a new function mbus_data_bcd_decode_hex (BCD to hexadecimal), which isn't affected and use this for default XML output. But keep mbus_data_bcd_decode for normalized output.
This pull request tries to solve the issue #163
At the end the whole BCD decoding is depending on the context. So add a new function which preserve all the BCD information.