]> average.org Git - pulsecounter.git/blobdiff - linux/pulsecounter.c
mark possible place that is losing events
[pulsecounter.git] / linux / pulsecounter.c
index 77c77bb9d102eb7207441523fc00cb9fb06a6437..cc05da904ce1f3d3acb6f09a881a7dc2615ff43a 100644 (file)
@@ -33,6 +33,7 @@ static int opt_mtu = 0;
 static int opt_psm = 0;
 static char *opt_sec_level = NULL;
 static char *opt_dbconffile = NULL;
+static gboolean opt_daemon = FALSE;
 
 static GMainLoop *event_loop;
 
@@ -49,7 +50,9 @@ static GOptionEntry options[] = {
                "Specify the PSM for GATT/ATT over BR/EDR", "PSM" },
        { "sec-level", 'l', 0, G_OPTION_ARG_STRING, &opt_sec_level,
                "Set security level. Default: low", "[low | medium | high]"},
-       { "dbconfig", 'c', 0, G_OPTION_ARG_STRING, &opt_dbconffile,
+       { "dbconfig", 'c', 0, G_OPTION_ARG_FILENAME, &opt_dbconffile,
+               "Specify file name with database configuration", "cfile"},
+       { "daemon", 'd', 0, G_OPTION_ARG_NONE, &opt_daemon,
                "Specify file name with database configuration", "cfile"},
        { NULL },
 };
@@ -93,12 +96,17 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
 
        handle = bt_get_le16(&pdu[1]);
        which = pdu[3];
-       if ((pdu[0] == 0x1b) && (handle == 0x0012) && (len == 9) &&
-           ((which == 1) || (which == 2))) {
+       if ((pdu[0] == 0x1b) && (handle == 0x0012) && (len == 9)) {
                uint32_t val = bt_get_le32(&pdu[5]);
-               g_debug("store: \"%hhu,%u\"\n", which, val);
-               if (dbstore(which, val))
-                       g_warning("error storing \"%hhu,%u\"\n", which, val);
+
+               if ((which == 1) || (which == 2)) {
+                       g_debug("store: \"%hhu,%u\"\n", which, val);
+                       if (dbstore(which, val))
+                               g_warning("error storing \"%hhu,%u\"\n",
+                                               which, val);
+               } else {
+                       g_debug("jitter: \"%hhu,%u\"\n", which, val);
+               }
        } else {
                time_t t;
                int i;
@@ -175,6 +183,7 @@ int main(int argc, char *argv[])
                got_error = TRUE;
                goto done;
        }
+       if (opt_daemon) daemon(0, 0);
        while (1) {
                chan = gatt_connect(opt_src, opt_dst, opt_dst_type,
                        opt_sec_level, opt_psm, opt_mtu, connect_cb, &gerr);