bluetooth - 了解循环功率测量的 BLE 特征值 0x2A63

标签 bluetooth dart flutter bluetooth-lowenergy

我目前正在使用 Dart/Flutter BLE 插件来更好地了解 BLE 设备。

插件:

https://pub.dartlang.org/packages/flutter_blue

当我连接到我的虚拟自行车教练时,我选择了 0x1818 服务,然后我订阅了 0x2A63 特性以进行循环功率测量。

我正在努力将我获得的响应列表与以下此服务/特性的 GATT 文档保持一致。此列表中有 18 个值,但 GATTS 列表中只有 17 个。此外,这些值似乎没有任何意义。

我还尝试将前两个值 '52','24' 转换为 16 位二进制,以查看它是否与第一个字段的标志对齐,但结果是下面的,这再次没有意义。

0x3418 = 11010000011000

https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.cycling_power_measurement.xml

这是我第一次连接到训练器时的屏幕截图。

enter image description here

这个截图是我在自行车上轻轻骑自行车时

enter image description here

此屏幕截图是当我停止骑自行车但踏板和车轮仍在转动时。

enter image description here

自行车训练器是 Cycleops Magnus,它没有 Cycle Speed Cadence 服务 1816,但可以提供基于功率的虚拟速度。

My Question is this:

Which of the values in the list corresponding with the GATTS characteristics and bonus question is, how would I infer speed or cadence from the values in this service?

最佳答案

基于蓝牙 GATT 规范的第 3.55 节:

DEC - [52,24,40,0,58,29,59,0,0,0,107,136,23, 0,214, 81, 1,0]
BIT -   0  1  2 3  4  5  6 7 8 9  10  11 12 13  14  15 16 17 
Flag field = 24,52 (bit0 and bit1)

2452 = 00001001 10010100
第 3.55.2.1 节
相应的 (1) 等于
- bit2  = Accumulated Torque Present 
- bit4  = Wheel Revolution Data Present
- bit7  = Extreme Torque Magnitudes Present
- bit8  = Extreme Angles Present
- bit11 = Accumulated Energy Present
然后从第 3.55.2 节开始,您可以根据标志向下查看位列表:
Instant Power 是位 2 (40) 和位 3 (0)
(Dec) 0040 == 00000000 00101000 == 40w
为了破译其余的位,我们必须引用标志字段,因为标志字段和即时功率之后的剩余位必须取决于标志字段所说的训练器支持的内容。
基于标志字段的第 2 位表示“存在累计扭矩”(
如果 Flags 字段的第 2 位设置为 1,则存在)因此接下来的 2 位代表累积扭矩
Dec (2958)
下一个数据将基于标志字段的第 4 位 - 车轮转速数据存在(如果标志字段的第 4 位设置为 1,则存在)。这是车轮速度,一旦您将车轮周长考虑在内,它就会转化为速度。对于 Wheel Rev Data,这由接下来的 6 位表示。
Cumulative Wheel Revolutions - 4 bits
Last Wheel Event Time - 2 bits
就像您提到的那样,此培训师不提供节奏服务,因此您看不到标志字段(位 5)为 1。因此您无法从该数据集中推断节奏。
对于车轮速度,您将根据 Cum Wheel Rev 和 Last Wheel Event Time 对来自 6 位的数据进行解码。当您使用 flutter 时,我无法为您提供有关如何解码 6 位的代码,而且我没有 flutter 语言的经验。 (我使用 Swift)但可能可以查看 GoldenCheetah 的这段代码并进行相应的转换。
BT40Device::getWheelRpm(QDataStream& ds)
{
    quint32 wheelrevs;
    quint16 wheeltime;
    ds >> wheelrevs;
    ds >> wheeltime;

    double rpm = 0.0;

    if(!prevWheelStaleness) {
        quint16 time = wheeltime - prevWheelTime;
        quint32 revs = wheelrevs - prevWheelRevs;
        // Power sensor uses 1/2048 second time base and CSC sensor 1/1024
        if (time) rpm = (has_power ? 2048 : 1024)*60*revs / double(time);
    }
    else prevWheelStaleness = false;

    prevWheelRevs = wheelrevs;
    prevWheelTime = wheeltime;
    dynamic_cast<BT40Controller*>(parent)->setWheelRpm(rpm);
}

关于bluetooth - 了解循环功率测量的 BLE 特征值 0x2A63,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54427537/

相关文章:

ios - 在 iOS 中通过蓝牙在两个设备之间传输 NSString

android - 蓝牙设备的循环问题

flutter - 如何知道应用程序何时加载到 Flutter 中?

string - 如何在Dart中映射字符串中的每个字符?

flutter - 除非我打印它,否则不在 .map() 中执行 setState

android - flutter:geolocator 不工作,确保 list 中至少定义了 ACCESS_FINE_LOCATION 或 ACCESS_COARSE_LOCATION

java - 配对蓝牙设备时出现 NullPointerException

c - BlueZ 4.99 中的蓝牙健康设备配置文件 (HDP) 接收器实现?

flutter - 避免在生产代码中调用 `print`。 (文档)

dart - 断言失败 : line 3927 pos 14: '_dependents.isEmpty' : is not true