How to perform a Offset Compensation Procedure for a BLE Cycling Power Meter

Viewed 93

I have an iOS application written in Swift that is able to communicate with a variety of BLE cycling based devices: heart rate monitor, speed and cadence sensor, trainers and of course power meters.

My question is regarding how to perform a Offset Compensation Procedure as described in the Cycling Power Profile document.

I have the following code to perform this operation:

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
    ...
    for characteristic in service.characteristics! as [CBCharacteristic] {
        switch characteristic.uuid.uuidString {
        case POWER_CONTROL:
            var rawArray:[UInt8] = [0x0C];
            let data = NSData(bytes: &rawArray, length: rawArray.count)
            peripheral.writeValue(data as Data, for: characteristic, type:   CBCharacteristicWriteType.withResponse)
            print("POWER CONTROL")

...

What ends up happening is, well, nothing except that the power meter disconnects itself every thirty seconds or so. If I don't issue this command it does not disconnect itself. Thus this command is definitely causing the disconnect.

What is the proper procedure to performing this operation ? Am I to disconnect from the device, reconnect, issue the calibration command when I find a power meter and then disconnect and reconnect again ?

I am confused when this operation can happen and how I will be notified when it's worked or failed.

0 Answers
Related