iOS   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了将心率测量服务添加到iPhone作为外围设备大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我正在使用 Apple BLTE Transfer模拟iPhone作为外围设备. 我的目标是模拟使用心率测量配置文件的心率监测器. (我知道如何生成数据但需要在外围端定义服务) 我已经在另一侧有一个代码来收集BLE心率监测器的数据. 我需要一些指导如何定义心率服务及其特征(在外围侧). 我还看到了使用特定服务UUID(180D)和UUID的一些特性(例如2A37用于心率测量,2A29用于制造商名称
我正在使用 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];

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

大佬总结

以上是大佬教程为你收集整理的将心率测量服务添加到iPhone作为外围设备全部内容,希望文章能够帮你解决将心率测量服务添加到iPhone作为外围设备所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。