0

I've got a strange problem using CoreBluetooth on iPhone 5C & iPhone 5S. By scenario, I'm going to receive 83 bytes of data, chunked by 20 bytes (5 chunks in common). And data are differs on iPhone 5S/5C (please see the dump below): chunk #4 substitutes chunk #3 under these devices. But on iPad3 (with the 6.1 & 7.0.2 iOS) all is OK

// iPhone 5C, iOS 7.0.2
nRF UART[237:60b] Received data on a characteristic. 0x01=001,0x02=5B2226
nRF UART[237:60b] Received data on a characteristic. 400192,0x05=1.0.0,0x
nRF UART[237:60b] Received data on a characteristic. ,0x09=2,0x0a=0,0x0b=
nRF UART[237:60b] Received data on a characteristic. ,0x09=2,0x0a=0,0x0b=
nRF UART[237:60b] Received data on a characteristic. 100ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ

// iPad 3, iOS 6.1.3 && iPad 3, iOS 7.0.2
nRF UART[221:60b] Received data on a characteristic. 0x01=001,0x02=5B2226
nRF UART[221:60b] Received data on a characteristic. 400192,0x05=1.0.0,0x
nRF UART[221:60b] Received data on a characteristic. 07=2013.010,0x08=001
nRF UART[221:60b] Received data on a characteristic. ,0x09=2,0x0a=0,0x0b=
nRF UART[221:60b] Received data on a characteristic. 100ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ

// iPhone 4S, iOS 6.1.3
nRF UART[241:60b] Received data on a characteristic. 0x01=001,0x02=5B2226
nRF UART[241:60b] Received data on a characteristic. 400192,0x05=1.0.0,0x
nRF UART[241:60b] Received data on a characteristic. 07=2013.010,0x08=001
nRF UART[241:60b] Received data on a characteristic. ,0x09=2,0x0a=0,0x0b=
nRF UART[241:60b] Received data on a characteristic. 100ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ

My question is: how to get a normal data from 5S/5C devices? Perhaps, there are some tricks with CBCharacteristic or CBCentralManager?

Thanks.

EDIT

As @allprog suggested, here is the fragments of the code how I'm using CoreBluetooth.

This is the pretty basic approach:

// CBCentralManager init
self.cm = [[CBCentralManager alloc] initWithDelegate:self queue:nil];

// Getting data chunks from CBCharacteristic in CBPeripheral's Delegate
- (void) peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
    {
        if (error)
        {
            NSLog(@"Error receiving notification for characteristic %@: %@", characteristic, error);
    return;
        }

        NSLog(@"Received data on a characteristic. %s", [[characteristic value] bytes]);
        // ... the rest of code
}
4

1 回答 1

0

如果您要传输大量数据并且必须将其拆分为多个数据包,我建议您为每个数据包添加某种 ID。这将为您提供接收方所需的附加信息,以确定数据包是否被丢弃、接收两次等。如果您检测到数据包被丢弃,您可能需要一种通过 ID 重新请求数据包的方法外围设备。

编辑:另外,如评论中所述,您可以切换到指示,让蓝牙堆栈满足您对保证和非重复交付的需求。

于 2013-10-17T23:57:11.683 回答