iPhone 5C / 5S上的CoreBluetooth:破坏了收到的数据

时间:2013-10-10 14:49:29

标签: iphone ios objective-c core-bluetooth

我在iPhone 5C和Linux上使用CoreBluetooth时遇到了一个奇怪的问题。 iPhone 5S。 根据情况,我将接收83字节的数据,分为20个字节(共5个块)。 iPhone 5S / 5C上的数据不同(请参阅下面的转储):chunk#4在这些设备下替换了#3块。 但是在iPad3上(使用6.1和7.0.2 iOS)一切都还可以

// 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ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ

我的问题是:如何从5S / 5C设备获取正常数据?也许,有一些CBC特性或CBCentralManager的技巧?

感谢。

修改

正如 @allprog 建议的那样,以下是我使用CoreBluetooth的代码片段。

这是非常基本的方法:

// 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
}

1 个答案:

答案 0 :(得分:0)

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

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