我正在使用苹果BLTE传输作为外围设备来模拟iPhone。我的目标是模拟一个使用心率测量剖面的心率监测器。(我知道如何生成数据,但需要在外围端定义服务)
我已经有一个代码在另一边收集数据从BLE心率监测器。
我需要一些指导,如何定义心率服务和它的特点(在外围)。我还看到了特定服务UUID (180 D)的使用,以及UUID的一些特性(例如,2A37用于心率测量,2A29用于制造商名称等)。我从哪弄到这些号码的?它们是在哪里定义的?
如有任何其他资料需要,请告知。
发布于 2013-08-07 20:46:48
心率服务在蓝牙开发者门户上有详细的介绍。假设您已经初始化了一个名为CBPeripheralManager
的peripheralManager
,并且已经收到了带有CBPeripheralManagerStatePoweredOn
状态的peripheralManagerDidUpdateState:
回调。下面是如何在此之后设置服务本身。
// Define the heart rate service
CBMutableService *heartRateService = [[CBMutableService alloc]
initWithType:[CBUUID UUIDWithString:@"180D"] primary:true];
// Define the sensor location characteristic
char sensorLocation = 5;
CBMutableCharacteristic *heartRateSensorLocationCharacteristic = [[CBMutableCharacteristic alloc]
initWithType:[CBUUID UUIDWithString:@"0x2A38"]
properties:CBCharacteristicPropertyRead
value:[NSData dataWithBytesNoCopy:&sensorLocation length:1]
permissions:CBAttributePermissionsReadable];
// Define the heart rate reading characteristic
char heartRateData[2]; heartRateData[0] = 0; heartRateData[1] = 60;
CBMutableCharacteristic *heartRateSensorHeartRateCharacteristic = [[CBMutableCharacteristic alloc]
initWithType:[CBUUID UUIDWithString:@"2A37"]
properties: CBCharacteristicPropertyNotify
value:[NSData dataWithBytesNoCopy:&heartRateData length:2]
permissions:CBAttributePermissionsReadable];
// Add the characteristics to the service
heartRateService.characteristics =
@[heartRateSensorLocationCharacteristic, heartRateSensorHeartRateCharacteristic];
// Add the service to the peripheral manager
[peripheralManager addService:heartRateService];
在此之后,您应该收到指示成功添加的peripheralManager:didAddService:error:
回调。您应该以类似的方式添加设备信息服务(0x180A),最后,您应该使用以下内容开始广告:
NSDictionary *data = @{
CBAdvertisementDataLocalNameKey:@"iDeviceName",
CBAdvertisementDataServiceUUIDsKey:@[[CBUUID UUIDWithString:@"180D"]]};
[peripheralManager startAdvertising:data];
注意:心率服务也是我第一个实现的。不错的选择。;)
发布于 2013-08-07 17:24:07
有关关贸总协定规范的所有内容都可以在蓝牙开发者站点上找到。你需要做的基本上是:
1.设置您的CBPeripheralManager
2.启动后,创建与心率服务相匹配的CBMutableService
和CBMutableCharacteristics
。做广告,你就可以走了。
https://stackoverflow.com/questions/18099081
复制相似问题