首页 技术 正文
技术 2022年11月15日
0 收藏 791 点赞 4,003 浏览 2349 个字

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
:
try
FBluetoothManagerLE := TBluetoothLEManager.Current;
FAdapter := FBluetoothManagerLE.CurrentAdapter;
if ManagerConnected then
begin
FBluetoothManagerLE.OnDiscoveryEnd := BluetoothLE1EndDiscoverDevices;
FBluetoothManagerLE.StartDiscovery(, ADeviceUUIDList);
end;
except
on E: Exception do ShowMessage('step1'+E.Message);
end;
:
try
CurrDevice.OnServicesDiscovered := ServicesDiscovered; if (FServiceDiscovered = false) then CurrDevice.DiscoverServices;
except
on E: Exception do ShowMessage('step2'+E.Message);
end;
:
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:=;
end else Memo1.Lines.Add('aaa');
except
on E: Exception do ShowMessage('step3'+E.Message);
end;
:
;
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,问题解决。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,905
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,430
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,727