简体   繁体   中英

mainloop_add_fd() in BlueZ

In 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? prompt_read_cb always waits for the cmd window event to happen, How to bypass this ??

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. 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).

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. 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.

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. Note I also made prompt_read_cp() to be a no-op, tho I haven't dug into it yet if that was necessary. HTH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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