【发布时间】:2018-01-29 13:52:52
【问题描述】:
我是低功耗蓝牙的新手,我正在尝试在 Linux 上构建自己的 C 程序,以连接低功耗蓝牙设备并与之交互。为此,我使用的是 Linux 蓝牙协议栈 Bluez。
阅读此博客 (https://www.jaredwolff.com/blog/get-started-with-bluetooth-low-energy/) 后,我可以通过命令行与我的设备进行连接和通信。但现在我坚持用我的代码来做这件事。我查看了 Gatttool 源文件,但我很难理解..
我尝试使用 gatt_connect(const char *src, const char *dst, const char *dst_type, const char *sec_level, int psm, int mtu, BtIOConnect connect_cb, GError **gerr),但我认为我传递给函数的参数有问题。
char dst[] = "XX:XX:XX:XX:XX:XX"; //device address
char dst_type = BDADDR_LE_RANDOM;
char sec_level = BT_IO_SEC_LOW;
GError *gerr;
BtIOConnect connect_cb; //Compiler says it´s uninitialized, but I don´t in what way I have how to initialize it
GIOhannel *chan;
chan = gatt_connect(NULL, dst, &dst_type, &sec_level, 0, 0, connect_cb, &gerr);
函数崩溃。我认为 connect_cb 函数指针有问题。但是在查看 Gattool 源代码后,我不知道如何修复它。
【问题讨论】:
-
你试过使用调试器吗?
-
是的。当使用给定参数调用 bt_io_connect 时,它会在 gatt_connect() 内部崩溃。但是调试器不能更深入地了解它。它说分段错误。
标签: c linux bluetooth-lowenergy gatt