加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:40:02 所属栏目:百科 来源:网络整理
导读:我正在使用 Apple BLTE Transfer模拟iPhone作为外围设备. 我的目标是模拟使用心率测量配置文件的心率监测器. (我知道如何生成数据但需要在外围端定义服务) 我已经在另一侧有一个代码来收集BLE心率监测器的数据. 我需要一些指导如何定义心率服务及其特征(在外
我正在使用 Apple BLTE Transfer模拟iPhone作为外围设备.
我的目标是模拟使用心率测量配置文件的心率监测器.
(我知道如何生成数据但需要在外围端定义服务)

我已经在另一侧有一个代码来收集BLE心率监测器的数据.

我需要一些指导如何定义心率服务及其特征(在外围侧).
我还看到了使用特定服务UUID(180D)和UUID的一些特性(例如2A37用于心率测量,2A29用于制造商名称等)我从哪里获得这些数字?它们的定义在哪里?

如果需要任何其他信息请告知.

解决方法

心率服务详情请见 bluetooth developer portal.
假设您已经初始化了名为peripheralManager的CBPeripheralManager,并且您已经收到了具有CBPeripheralManagerStatePoweredOn状态的peripheralManagerDidUpdateState:callback.以下是在此之后如何设置服务的方法.

// 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:表示添加成功的回调.您应该同样添加device information service (0x180A)最后,您应该开始做广告:

NSDictionary *data = @{
    CBAdvertisementDataLocalNameKey:@"iDeviceName",CBAdvertisementDataServiceUUIDsKey:@[[CBUUID UUIDWithString:@"180D"]]};

[peripheralManager startAdvertising:data];

注意:心率服务也是我实施的第一个.好的选择.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读