首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将心率测量服务添加到iPhone作为外围设备

将心率测量服务添加到iPhone作为外围设备
EN

Stack Overflow用户
提问于 2013-08-07 09:02:47
回答 2查看 3.2K关注 0票数 4

我正在使用苹果BLTE传输作为外围设备来模拟iPhone。我的目标是模拟一个使用心率测量剖面的心率监测器。(我知道如何生成数据,但需要在外围端定义服务)

我已经有一个代码在另一边收集数据从BLE心率监测器。

我需要一些指导,如何定义心率服务和它的特点(在外围)。我还看到了特定服务UUID (180 D)的使用,以及UUID的一些特性(例如,2A37用于心率测量,2A29用于制造商名称等)。我从哪弄到这些号码的?它们是在哪里定义的?

如有任何其他资料需要,请告知。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-08-07 20:46:48

心率服务在蓝牙开发者门户上有详细的介绍。假设您已经初始化了一个名为CBPeripheralManagerperipheralManager,并且已经收到了带有CBPeripheralManagerStatePoweredOn状态的peripheralManagerDidUpdateState:回调。下面是如何在此之后设置服务本身。

代码语言:javascript
运行
复制
// 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),最后,您应该使用以下内容开始广告:

代码语言:javascript
运行
复制
NSDictionary *data = @{
    CBAdvertisementDataLocalNameKey:@"iDeviceName", 
    CBAdvertisementDataServiceUUIDsKey:@[[CBUUID UUIDWithString:@"180D"]]};

[peripheralManager startAdvertising:data];

注意:心率服务也是我第一个实现的。不错的选择。;)

票数 3
EN

Stack Overflow用户

发布于 2013-08-07 17:24:07

有关关贸总协定规范的所有内容都可以在蓝牙开发者站点上找到。你需要做的基本上是:

1.设置您的CBPeripheralManager

2.启动后,创建与心率服务相匹配的CBMutableServiceCBMutableCharacteristics。做广告,你就可以走了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18099081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档