Как понять функцию Bluetooth Cycle 32-битный отклик - PullRequest
0 голосов
/ 20 октября 2019

Я пытаюсь определить, какие функции поддерживаются Cycle Power Measurement. Очевидно, функция Cycle Power имеет 32-битный ответ, который определяет, какие функции поддерживаются.

Я предполагаю, что из приведенного ниже документа ответ будет показывать истинный / ложный ответ для каждого.

Однако, затем я получаю ответ обратно, я получаю следующее

[132,0,0,42]

Я предполагаю, что это то, что 32-битный битдо 4 x 8 битов в массиве целых чисел?

Однако я понятия не имею, что делать отсюда, и мне нужна помощь.

Вопрос в том, «Как я могу использовать 4целые числа для определения поддерживаемых функций на основе приведенного ниже XML? "

Документ с характеристиками GATTS.

<?xml version="1.0" encoding="utf-8"?>
<!-- <?xml-stylesheet type="text/xsl" href="FieldBasedDisplay.xslt"?> -->
<!--Copyright 2016 Bluetooth SIG, Inc. All rights reserved.-->
<Characteristic xsi:noNamespaceSchemaLocation="http://schemas.bluetooth.org/Documents/characteristic.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Cycling Power Feature" type="org.bluetooth.characteristic.cycling_power_feature" uuid="2A65" last-modified="2016-05-03" approved="Yes">
  <InformativeText>
    <Summary>The CP Feature characteristic is used to report a list of features supported by the device.</Summary>
  </InformativeText>
  <Value>
    <Field name="Cycling Power Feature">
      <Requirement>Mandatory</Requirement>
      <Format>32bit</Format>
      <BitField>
        <Bit index="0" size="1" name="Pedal Power Balance Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="1" size="1" name="Accumulated Torque Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="2" size="1" name="Wheel Revolution Data Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="3" size="1" name="Crank Revolution Data Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="4" size="1" name="Extreme Magnitudes Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="5" size="1" name="Extreme Angles Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="6" size="1" name="Top and Bottom Dead Spot Angles Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="7" size="1" name="Accumulated Energy Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="8" size="1" name="Offset Compensation Indicator Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="9" size="1" name="Offset Compensation Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="10" size="1" name="Cycling Power Measurement Characteristic Content Masking Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="11" size="1" name="Multiple Sensor Locations Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="12" size="1" name="Crank Length Adjustment Supported ">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="13" size="1" name="Chain Length Adjustment Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="14" size="1" name="Chain Weight Adjustment Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="15" size="1" name="Span Length Adjustment Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="16" size="1" name="Sensor Measurement Context">
          <Enumerations>
            <Enumeration key="0" value="Force based" />
            <Enumeration key="1" value="Torque based" />
          </Enumerations>
        </Bit>
        <Bit index="17" size="1" name="Instantaneous Measurement Direction Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="18" size="1" name="Factory Calibration Date Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="19" size="1" name="Enhanced Offset Compensation Supported">
          <Enumerations>
            <Enumeration key="0" value="False" />
            <Enumeration key="1" value="True" />
          </Enumerations>
        </Bit>
        <Bit index="20" size="2" name="Distribute System Support">
          <Enumerations>
            <Enumeration key="0" value="Unspecified (legacy sensor)" />
            <Enumeration key="1" value="Not for use in a distributed system" />
            <Enumeration key="2" value="Can be used in a distributed system" />
            <Enumeration key="3" value="RFU" />
          </Enumerations>
        </Bit>
        <ReservedForFutureUse index="22" size="10" />
      </BitField>
    </Field>
  </Value>
  <Note>        
        The fields in the above table, reading from top to bottom, are shown in the order of LSO to MSO, where LSO = Least Significant Octet and MSO = Most Significant Octet. 
        The Least Significant Octet represents the eight bits numbered 0 to 7.
    </Note>
</Characteristic>

1 Ответ

1 голос
/ 04 ноября 2019

Вы получили ответ с 32-битным шестнадцатеричным значением, например [2c 00 01 00]. чем нужно преобразовать его в двоичный, например, 2c становится 00101100 00 становится 0000000 и т. д. В конце ваша двоичная строка становится чем-то вроде [00101100 00000000 00000001 0000000], теперь вам нужно прочитать первые 8 бит справа налево [от LSB к MSB]

Для простоты считывания вы можете повернуть эти 8 битов, например, 00101100 становится 00110100. Это показывает, что у вас есть WRDS (данные оборотов колеса поддерживаются) CRDS (данные оборотов коленчатого вала поддерживаются) и EAS (поддерживаются экстремальные величины).

Надеюсь, это поможет вам в чтении флагов.

другой простой способ чтения - преобразовать шестнадцатеричную строку в простой формат, например, 2c 00 01 00, становится 00 01 00 2c, а затем преобразовать ее в двоичный файл и начать чтение справа, например, 00000000 00000001 00000000 00101100, начать справа налево.

...