]> sigrok.org Git - libsigrok.git/commitdiff
rdtech-tc: concentrate request transmit handling in one spot
authorGerhard Sittig <redacted>
Thu, 16 Mar 2023 02:41:17 +0000 (03:41 +0100)
committerGerhard Sittig <redacted>
Thu, 16 Mar 2023 13:29:30 +0000 (14:29 +0100)
Move all "command sent at ..." calculation and update in a single spot
for improved awareness during development. Allow acquisition start to
force the transmission of the measurement request.

src/hardware/rdtech-tc/api.c
src/hardware/rdtech-tc/protocol.c
src/hardware/rdtech-tc/protocol.h

index 1d45d312137ec718eb7e5a2945bdf4563b32965c..5c6bb70ea84277d2140b6078557a58523812ce1f 100644 (file)
@@ -143,7 +143,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        serial_source_add(sdi->session, serial, G_IO_IN, 50,
                rdtech_tc_receive_data, (void *)sdi);
 
-       return rdtech_tc_poll(sdi);
+       return rdtech_tc_poll(sdi, TRUE);
 }
 
 static struct sr_dev_driver rdtech_tc_driver_info = {
index e1cff006770813bfa9b4757c940ce545deebe5b3..36477858876cbaa588db2f15e5f67734dd2d5701 100644 (file)
@@ -156,20 +156,25 @@ SR_PRIV int rdtech_tc_probe(struct sr_serial_dev_inst *serial, struct dev_contex
        return SR_OK;
 }
 
-SR_PRIV int rdtech_tc_poll(const struct sr_dev_inst *sdi)
+SR_PRIV int rdtech_tc_poll(const struct sr_dev_inst *sdi, gboolean force)
 {
        struct dev_context *devc;
+       int64_t now, elapsed;
        struct sr_serial_dev_inst *serial;
 
+       devc = sdi->priv;
+       now = g_get_monotonic_time() / 1000;
+       elapsed = now - devc->cmd_sent_at;
+       if (!force && elapsed < TC_POLL_PERIOD_MS)
+               return SR_OK;
+
        serial = sdi->conn;
        if (serial_write_blocking(serial, poll_cmd, strlen(poll_cmd),
                        SERIAL_WRITE_TIMEOUT_MS) < 0) {
                sr_err("Unable to send poll request.");
                return SR_ERR;
        }
-
-       devc = sdi->priv;
-       devc->cmd_sent_at = g_get_monotonic_time() / 1000;
+       devc->cmd_sent_at = now;
 
        return SR_OK;
 }
@@ -229,7 +234,6 @@ SR_PRIV int rdtech_tc_receive_data(int fd, int revents, void *cb_data)
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
-       int64_t now, elapsed;
 
        (void)fd;
 
@@ -247,10 +251,7 @@ SR_PRIV int rdtech_tc_receive_data(int fd, int revents, void *cb_data)
                return TRUE;
        }
 
-       now = g_get_monotonic_time() / 1000;
-       elapsed = now - devc->cmd_sent_at;
-       if (elapsed > TC_POLL_PERIOD_MS)
-               rdtech_tc_poll(sdi);
+       rdtech_tc_poll(sdi, FALSE);
 
        return TRUE;
 }
index 4692ec4022f004fe223abba239050041ec21c486..d13527df11b0c3c8f9c8cf938912539d7c532aea 100644 (file)
@@ -44,6 +44,6 @@ struct dev_context {
 
 SR_PRIV int rdtech_tc_probe(struct sr_serial_dev_inst *serial, struct dev_context *devc);
 SR_PRIV int rdtech_tc_receive_data(int fd, int revents, void *cb_data);
-SR_PRIV int rdtech_tc_poll(const struct sr_dev_inst *sdi);
+SR_PRIV int rdtech_tc_poll(const struct sr_dev_inst *sdi, gboolean force);
 
 #endif