susutex’s blog

自転車、電子工作、プログラミングとかについて書くかもしれないブログ

BLEのCycling Power Serviceについて調べる

susutex.hatenablog.com

の続き。

速度とパワーを表示するにはCSC ServiceとCycling Power Serviceを別々に実装しなければならないのかと思っていたが、Cycling Power ServiceにもSpeed関連の値を入れられるので別々にServiceを実装する必要が無いことがわかった

 

Cycling Power

https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.cycling_power.xml

 MandetoryのCharacteristicsはCycling Power Measurement, Cycling Power Feature, Sensor Locationの3つ。

 

Cycling Power Measurement

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

非常に項目が多いが速度とパワーをサポートするなら以下。

  • Flags(16bit)

速度とパワーのみをサポートするならばWheel Revolution Data Presentのみ1とするので0x0010でよいだろう。

  • Instantaneous Power(sint16)

パワーの測定値そのもの。単位W。なぜか負の値が入れられる。

  • Wheel Revolution Data - Cumulative Wheel Revolutions(32bit)
  • Wheel Revolution Data - Last Wheel Event Time(16bit)

スピードセンサーのときと同じかと思いきや、Last Wheel Event Timeの単位は1/2048[s]でスピードセンサの際の1/1024[s]の半分なので、同じ値を入れると速度が倍に出る。

 

Cycling Power Feature

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

  • Cycling Power Feature(32bit)

かなりいろいろある。
Distribute System SupportとSensor Measurement Contextの意味が不明だが、Wheel Revolution Data Supportedのみ1として0x00000004でよいだろう。

Sensor Location

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

  • Sensor Location(8bit)

とりあえず

13: Rear Hub

あたりにしておけばよいだろう

 

f:id:susutex:20170906211743p:plain

以上を実装し、CSC Serviceの時と同様に送信のたびにCumulative Wheel Revolutionsを5、Last Wheel Event Timeを1024ずつ増やしながら送信しているが、Last Wheel Event Timeのunitが1/2担っているので表示される速度は二倍になっている。


ある程度できたらchibi:bitではなくSWITCH SCIENCEでRedBearLab BLE Nanoあたりを買ってユニバーサル基板を使って組もうと思っていたが、気づいたら販売終了になっていた。代わりのnRF51822モジュールを捜すが、BGAのモジュール単品かデバッガが一体になったものしかない。消費電力とサイズを考えるとできればBLEモジュール単品で工作がしやすいものが欲しいが。

nRF51822以外だとKoshianが安い。Serviceを追加するとなるとおそらくファーム書き換えが必須になる。mbedでは使えないが、面白そう。