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

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

概述我正在使用 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 serviceCBMutableService *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作为外围设备所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1013220.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存