简体   繁体   English

BlueZ中的mainloop_add_fd()

[英]mainloop_add_fd() in BlueZ

In BlueZ tools/btgatt-client.c 在BlueZ tools / btgatt-client.c中
I am using this file to connect to a device and read data and I want to disable the interactive command prompt. 我正在使用此文件连接到设备并读取数据,我想禁用交互式命令提示符。

I am able to connect but to get data register-notify 0x00xx I have to enter via cmd window, then prompt_read_cb gets called, How can i automate this? 我能够连接但是要获取数据寄存器 - 通知0x00xx我必须通过cmd窗口进入,然后调用prompt_read_cb ,我该如何自动执行此操作? prompt_read_cb always waits for the cmd window event to happen, How to bypass this ?? prompt_read_cb总是等待cmd窗口事件发生,如何绕过这个?

if (mainloop_add_fd(fileno(stdin),EPOLLIN | EPOLLRDHUP | EPOLLHUP | 
EPOLLERR,prompt_read_cb, cli, NULL) < 0)`
{
    fprintf(stderr, "Failed to initialize console\n");
    return EXIT_FAILURE;
}

I am trying to do the same thing, for a headless HRM receiver. 对于无头HRM接收器,我正在尝试做同样的事情。 I uncoded much of btgatt-client.c such that I simply, in the ready_cb() function, request a connection to the device & registered the notification with the device and then modified the notify_cb() to do exactly what I wanted to with the data (push into shared memory, essentially). 我没有编写很多btgatt-client.c,因此我只是在ready_cb()函数中请求与设备的连接并向设备注册通知,然后修改notify_cb()以完全按照我想要的方式执行数据(基本上是推入共享内存)。

This works fine without any stdin requests running from the shell, however when you run it from systemd the call to mainloop_add_fd() returns an error and the program exits. 这没有任何stdin请求从shell运行时工作正常,但是当你从systemd运行它时,对mainloop_add_fd()的调用会返回一个错误并退出程序。 I tried commenting out the call, sending a file that I opened but was null, or sending a null file descriptor and all caused the mainloop to exit. 我试着注释掉这个调用,发送一个我打开但是为null的文件,或发送一个空文件描述符,所有这些都导致mainloop退出。

However, if I simply called mainloop_add_fd() with stdin and ignore the error it returns when run from systemd the process continues and appears to work. 但是,如果我只是用stdin调用mainloop_add_fd()并忽略它从systemd运行时返回的错误,则该过程继续并且似乎正常工作。 Note I also made prompt_read_cp() to be a no-op, tho I haven't dug into it yet if that was necessary. 注意我也将prompt_read_cp()设置为无操作,如果有必要,我还没有挖到它。 HTH. HTH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM