rscada / libmbus

Meter-bus library and utility programs
http://www.rscada.se/libmbus
BSD 3-Clause "New" or "Revised" License
217 stars 137 forks source link

Improve BCD decoding #167

Closed lategoodbye closed 4 years ago

lategoodbye commented 4 years ago

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.

lategoodbye commented 4 years ago

@fredrik-sk are you fine with this compromise?

fredrik-sk commented 4 years ago

@fredrik-sk are you fine with this compromise?

I'm glad that something happends. And that you have found and corrected some issue.

lategoodbye commented 4 years ago

Thanks for the review

fredrik-sk commented 4 years ago

I had one more comment. I see the change has been merged. Should we return both the raw value and the decoded?

lategoodbye commented 4 years ago

Should we return both the raw value and the decoded?

Not sure that i understand your question. Do you mean decimal + hex?

fredrik-sk commented 4 years ago

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. My first approach was calling it "raw value", and "decoded value".

lategoodbye commented 4 years ago

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:

   <DataRecord id="6">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>Temperature Difference (1e-2  deg C)</Unit>
        <Value>F00018</Value>
    </DataRecord>

normalized output:

<DataRecord id="6">
        <Function>Instantaneous value</Function>
        <StorageNumber>0</StorageNumber>
        <Unit>K</Unit>
        <Quantity>Temperature difference</Quantity>
        <Value>-0.180000</Value>
    </DataRecord>