1

I'm trying to implement this Bluetooth mesh characteristic:

<!--
  Copyright 2017 Bluetooth SIG, Inc. All rights reserved.
-->
<Characteristic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schemas.bluetooth.org/Documents/characteristic.xsd" name="Illuminance" type="org.bluetooth.characteristic.illuminance" uuid="2AFB" last-modified="2017-07-11" approved="Yes">
  <InformativeText>
    <Abstract>
    The Illuminance characteristic is used to represent a measure of illuminance in units of lux.
    </Abstract>
  </InformativeText>
  <Value>
    <Field name="Illuminance">
      <InformativeText>Unit is lux with a resolution of 0.01.</InformativeText>
      <Format>uint24</Format>
      <Unit>org.bluetooth.unit.lux</Unit>
      <Minimum>0</Minimum>
      <Maximum>167772.14</Maximum>
      <DecimalExponent>-2</DecimalExponent>
      <BinaryExponent>0</BinaryExponent>
      <Multipler>1</Multipler>
      <Description>
        A value of 0xFFFFFF represents 'value is not known'. All other values are Prohibited.
      </Description>
    </Field>
  </Value>
</Characteristic>

https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Specifications/Mesh/Xml/Characteristics/org.bluetooth.characteristic.illuminance.xml. This characteristic represents a lux value in 3 bytes.

But I don't know how I would be able to convert a value like 0x123456 to the real floating-point number. It doesn't seem that the standard IEEE 754 standard is used. I also don't know what they mean with DecimalExponent and BinaryExponent.

Could anyone help me out? Kind regards, Daan

Daan Pape
  • 1,100
  • 1
  • 13
  • 25
  • The text of the page you link to is short and should be included in your question. External links change or vanish, which then cause Stack Overflow questions to become wrong or useless. Always include all information relevant to your question in the question itself. – Eric Postpischil Dec 31 '19 at 12:47

1 Answers1

2

There is no floating point in the page you link to. It uses -2 with DecimalExponent merely to specify that a 24-bit integer value that in plain binary would be some number x from 0 to 16,777,214 (with 16,777,215 reserved for “not known”) represents a value of x•10−2 lux, ranging from 0.00 lux to 167,772.14 lux. This is fixed point, not floating point; the point is fixed at the position two digits to the left of where it would be in the plain binary integer representation.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312