将Gatttool命令/请求转换为Bluez c
问题描述:
我很难弄清楚如何将我的蓝牙命令(从Gatttool)转换为Bluez c代码。将Gatttool命令/请求转换为Bluez c
你能帮我翻译下面的Gatttool命令(蓝牙请求)到C吗?
[CON] [MY_MAC_ADDRESS] [LE]>炭 - 写-REQ 0x00c0 0100
所以我的手柄是0x00c0
和我的数据是0100
(上)。我不知道我需要填充哪些hci_request
结构属性(除了句柄)。
... I've successfully connected to the device (LE connection)
struct hci_request rq = {0};
rq.ogf = ??; // should the handle go here?
rq.ocf = ??; // should the data go here
rq.cparam = ??;
rq.clen = ??;
rq.rparam = ??;
rq.rlen = ??;
rq.event = ??; // what would the event be?
hci_send_req(dd, &rq, 1000);
答
为什么不哟使用标准的bluez关贸总协定命令即
void WriteValue(array{byte} value, dict options)
但结合自己的HCI命令?但是,如果您真的想要结合HCI命令(这意味着您跳过GATT/ATT/L2CAP级别),则格式为“HCI ACL数据包”,其格式为hci.h在BlueZ处的“HCI_ACLDATA_PKT”: 句柄:ACL的连接句柄。 Packet_Boundary_Flag:00/01/10或11取决于您的L2cap封装类型。 Broadcast_Flag:基本上是0x00,即没有广播 Data_Total_Length:你的包的长度。 然后该包需要包含L2CAP PDU的长度和通道ID(应该是0x0004作为ATT协议),然后附加ATT pdu类型,opcode(写入命令)att句柄和数据。
如果您要使用“hci_send_req”命令,则此命令用于控制或设置目的,而不是用于HCI数据包写入。例如当你读取本地名称时,你正在使用rq.ogf = OGF_HOST_CTL; \t rq.ocf = OCF_READ_LOCAL_NAME; \t rq.rparam = &rp; //响应格式 \t rq.rlen = READ_LOCAL_NAME_RP_SIZE; –