首页 > 解决方案 > 如何理解蓝牙循环功能 32 位响应

问题描述

我正在尝试确定 Cycle Power Measurement 支持哪些功能。显然,循环电源功能具有 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>

标签: bluetoothbluetooth-lowenergy

解决方案


您收到了 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 从右到左开始。


推荐阅读