首页 > 解决方案 > 通知和指示 - BLE、葡萄糖服务

问题描述

我正在尝试使用 Delphi 中的 TBluetoothLE 组件从带有蓝牙 LE 的葡萄糖设备(Contour One Plus)获取葡萄糖测量值。我可以: - 连接到设备 - 发现 GATT 服务 - 发现 GATT 特性,现在我尝试设置葡萄糖测量特性的通知和记录访问控制点特性的指示。

我写了两个启用程序:

procedure TForm6.enableGlucoseMeasurementNotification(
  const ACharacteristic: TBluetoothGattCharacteristic);
  var
    ADescriptor: TBluetoothGattDescriptor;
    AValues : TBytes;
begin
   BluetoothLE1.DiscoveredDevices[0].SetCharacteristicNotification(FGlucoseMeasurementGattCharact, true);
   ADescriptor := FGlucoseMeasurementGattCharact.Descriptors[0];  // czy aby na pewno [0]... ?

   SetLength(AValues, 2);
   AValues[0] := $01;
   AValues[1] := $00;

   ADescriptor.SetValue(AValues);
   BluetoothLE1.DiscoveredDevices[0].WriteDescriptor(ADescriptor);
end;
procedure TForm6.enableRecordAccessControlPointIndication(
  const ACharacteristic: TBluetoothGattCharacteristic);
  var
  ADescriptor: TBluetoothGattDescriptor;
  AValues: TBytes;
begin
  BluetoothLE1.DiscoveredDevices[0].SetCharacteristicNotification(FRecordAccessControlPoint, true);
  ADescriptor := FRecordAccessControlPoint.Descriptors[0];

  SetLength(AValues, 2);
  AValues[0] := $02;
  AValues[1] := $00;

  ADescriptor.SetValue(AValues);
  BluetoothLE1.DiscoveredDevices[0].WriteDescriptor(ADescriptor);
end;

我基于 nRF Connect,但我不明白一些事情。我的问题是,我应该在哪里运行这两个程序?在 OnServicesDiscovered 中?我的程序正确吗?从 RACP 获取价值的下一步是什么?我应该只将字节值(例如 0x01)写入 RACP 吗?

标签: notificationsbluetooth-lowenergygattbluetooth-gatt

解决方案


推荐阅读