我正在开发 BLE 应用程序(与 Heath 相关),我有一个选项可以从 BLE 设备获取 ECG 值。我需要启用 8 个波形才能在我的应用程序中获取 ECG 数据。
我的问题是如何使用 CBDescriptor 启用所有波形。我需要将如下数据传递给 CBDescriptor。 波形 ID 格式 0:8bit,1:16bit,2:32bit,3:64bit,4:128bit,5:8bit*3,6:16bit*3,7:32bit*3
uint8_t waveArray[8] = {0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00};
NSData *waveData = [NSData dataWithBytes:waveArray length:sizeof(waveArray)/sizeof(uint8_t)];
[peripheral writeValue:waveData forDescriptor:descript];
但我没有得到设备的任何响应。请帮帮我。
最后我得到了我的问题的解决方案。首先我们需要调用 CBDescriptor 的 discover 方法。
[peripheral discoverDescriptorsForCharacteristic:characteristic];
-(void)peripheralCBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristicCBCharacteristic *)characteristic errorNSError *)error {
NSArray *Descroptors = [characteristic descriptors];
CBDescriptor *descript;
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
for (descript in Descroptors)
{
if ([descript.UUID isEqual:[CBUUID UUIDWithString:KT_WP_WC_CHARACTERISTIC]])
{
uint8_t waveArray[9] = {0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00};//Your data which you need to send to BLE device
NSData *waveData = [NSData dataWithBytes:waveArray length:sizeof(waveArray)/sizeof(uint8_t)];
[peripheral writeValue:waveData forDescriptor:descript];
NSLog(@"waveData ==%@",waveData);
CBUUID * sCBUUID = [CBUUID UUIDWithString:KT_WP_SERVICE];
CBUUID * cCBUUID = [CBUUID UUIDWithString:KT_WP_WF_CHARACTERISTIC];
[self CBUUIDwriteValue:sCBUUID characteristicUUID:cCBUUID p:peripheral data:waveData];
}else
{
const unsigned char bytes[] = { 0x28, 0x00 };//Your data which you need to send BLE device
NSData *descriptorData = [NSData dataWithBytes:bytes length:2];
CBUUID * sCBUUID = [CBUUID UUIDWithString:KT_WP_SERVICE];
CBUUID * cCBUUID = [CBUUID UUIDWithString:KT_WP_WF_CHARACTERISTIC];
[self CBUUIDwriteValue:sCBUUID characteristicUUID:cCBUUID p:peripheral data:descriptorData];
}
}
}
关于ios - 如何启用自定义 CBDescriptor 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46617943/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |