dub*_*eat 7 macos bluetooth l2cap iobluetooth
我试图打开L2Cap HID通道和中断通道,以便我可以将HID命令发送到蓝牙设备.
我已完成所有服务广告和设备配对并建立了基带连接.
Hid控制通道打开正常.当我尝试创建我的kBluetoothL2CAPPSMHIDInterrupt连接时
l2capChannelQueueSpaceAvailable
委托方法调用(不确定这意味着什么)后跟
l2capChannelOpenComplete
但连接立即关闭
l2capChannelClosed
我该如何正确打开这些连接?
我花了很长时间挖掘IOBlueTooth框架和bluetooth.org HID规范,但几乎没有任何有用的信息(我至少可以找到).
当我追踪我的L2Cap频道时,我看到了一些空值
mIncomingDataListener
和
mEventDataListener
.我不知道如何设置它们或者它们是否与我的问题有关....只是推测.
下面的代码片段是我到目前为止在建立与设备的连接后建立连接的尝试.
-(void)establishL2CappConnections:(IOBluetoothDevice*)device
{
IOReturn r;
IOBluetoothL2CAPChannel *ch1;
r = [device openL2CAPChannelSync:&ch1
withPSM:(BluetoothL2CAPPSM)kBluetoothL2CAPPSMHIDControl
delegate:self];
self.mL2CappChannel=ch1;
NSLog(@"r == %i",r);
IOBluetoothL2CAPChannel *ch2;
r = [device openL2CAPChannelSync:&ch2
withPSM:(BluetoothL2CAPPSM)kBluetoothL2CAPPSMHIDInterrupt
delegate:self];
self.mL2CappInterruptChannel=ch2;
NSLog(@"r == %i",r);
}
Run Code Online (Sandbox Code Playgroud)
编辑:1
我已经附上了我的包日志.这很奇怪,是一个请求
kBluetoothL2CAPPSMSDP 0x0001
没有我请求它,然后一切开始断开连接.
根据您的日志,很明显您的设备处于有限连接模式,其保持活动状态的时间为 30 秒或更短。更改设备设置以使其可被发现。
k蓝牙L2CAPPSMSDP 0x0001
表示位 13 - 有限可发现模式
使用蓝牙设置可以解决您的问题