From: Gerhard Sittig Date: Thu, 16 Mar 2023 02:41:17 +0000 (+0100) Subject: rdtech-tc: concentrate request transmit handling in one spot X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a82490b6f7ea4a65a45d96e1a55c7bd74a4e49c1;p=libsigrok.git rdtech-tc: concentrate request transmit handling in one spot 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. --- diff --git a/src/hardware/rdtech-tc/api.c b/src/hardware/rdtech-tc/api.c index 1d45d312..5c6bb70e 100644 --- a/src/hardware/rdtech-tc/api.c +++ b/src/hardware/rdtech-tc/api.c @@ -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 = { diff --git a/src/hardware/rdtech-tc/protocol.c b/src/hardware/rdtech-tc/protocol.c index e1cff006..36477858 100644 --- a/src/hardware/rdtech-tc/protocol.c +++ b/src/hardware/rdtech-tc/protocol.c @@ -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; } diff --git a/src/hardware/rdtech-tc/protocol.h b/src/hardware/rdtech-tc/protocol.h index 4692ec40..d13527df 100644 --- a/src/hardware/rdtech-tc/protocol.h +++ b/src/hardware/rdtech-tc/protocol.h @@ -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