delphiXE开发蓝牙BLE4.0程序时遇到的notification问题

IDE环境delphiXE8

蓝牙硬件ST17H26

service:0xfee7

chareter:0xfec9

 

const u16 my_OEMServiceUUID=0xfee7;
const u16 my_OEMCharaterUUID=0xfec9;

在my_Attributes[]中添加

{4,2,2,(u8*)(&my_primaryServiceUUID), (u8*)(&my_OEMServiceUUID)},
{0,2,1,(u8*)(&my_characterUUID), (u8*)(&PROP_READ_WRITE_NORSP_NOTIFY)},
{0,2,1, (u8*)(&my_OEMCharaterUUID), (u8*)(&my_page)},

 

手机调试软件BLEReader可以正常看到service和charater,点击"开始通知",蓝牙端发送可以正常接收。

delphixe内容:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
case Step of
  1:
    try
    FBluetoothManagerLE := TBluetoothLEManager.Current;
    FAdapter := FBluetoothManagerLE.CurrentAdapter;
    if ManagerConnected then
    begin
      FBluetoothManagerLE.OnDiscoveryEnd := BluetoothLE1EndDiscoverDevices;
      FBluetoothManagerLE.StartDiscovery(1000, ADeviceUUIDList);
    end;
   except
    on E: Exception do  ShowMessage('step1'+E.Message);
  end;
  2:
  try
         CurrDevice.OnServicesDiscovered := ServicesDiscovered;

        if (FServiceDiscovered = false) then  CurrDevice.DiscoverServices;
  except
    on E: Exception do  ShowMessage('step2'+E.Message);
  end;
  3:
  try
    FChar1 := FService.GetCharacteristic(StringToGUID(UUID_CHAR1));
    if FChar1<>nil then
    begin
    CurrDevice.OnCharacteristicRead := OnCharRead;
    CurrDevice.SetCharacteristicNotification(FChar1,true);
    CurrDevice.ReadCharacteristic(FChar1);
    FChar1.GetDescriptor()
    Memo1.Lines.Add('找到键值');
    Step:=4;
    end else Memo1.Lines.Add('aaa');
   except
    on E: Exception do  ShowMessage('step3'+E.Message);
  end;
  4:
  ;
end;
end;
在SetCharacteristicNotification后,无法从server端获得notify,跟踪到源文件中:
function TBluetoothLEDevice.SetCharacteristicNotification(const ACharacteristic: TBluetoothGattCharacteristic;
  Enable: Boolean): Boolean;
const
  Desc_Configuration: TBluetoothUUID = '{00002902-0000-1000-8000-00805F9B34FB}';
var
  LDesc: TBluetoothGattDescriptor;
begin
  Result := False;
  if [TBluetoothProperty.Notify, TBluetoothProperty.Indicate] * ACharacteristic.GetProperties <> [] then
  begin
    // This is to ensure that we have read the descriptors before querying.
    ACharacteristic.Descriptors;
    // We check that we have the Configurarion descriptor, and then we set the notification accordingly.
    LDesc := ACharacteristic.GetDescriptor(Desc_Configuration);
    if LDesc <> nil then
      Result := DoSetCharacteristicNotification(ACharacteristic, Enable);
  end;
end;
可以发现,在真正设置
DoSetCharacteristicNotification(ACharacteristic, Enable);前进行了一些列的判断,注意是要求该charater下要有个
Desc_Configuration的UUID,如果没有就不会实质上地设置notify。于是回过头来修改蓝牙代码:
增加了:

{0,2,2,(u8*)(&clientCharacterCfgUUID), (u8*)(serviceChangeCCC)},

修改mac(不知道为什么,不修改反映不出变化)

重新烧录后,0xfec9下面多了一个0x2902的describe。再次运行delphi端程序,可以得到notify,问题解决。

转载于:https://www.cnblogs.com/csaaa/p/6591065.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值