From: Gerhard Sittig Date: Thu, 16 Mar 2023 02:18:14 +0000 (+0100) Subject: rdtech-tc: move assignments out of declarations X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c1f9428a6c95e639e3d613738b6a2b08c8496ee0;p=libsigrok.git rdtech-tc: move assignments out of declarations Separate the declaration of variables from their manipulation. Keep initial assignments and subsequent updates and evaluation of results in closer proximity. Group related instructions while we are here, avoid scatter. Break long lines, and add braces around complex multi-line statements. --- diff --git a/src/hardware/rdtech-tc/api.c b/src/hardware/rdtech-tc/api.c index 962e8f24..2bb2cab5 100644 --- a/src/hardware/rdtech-tc/api.c +++ b/src/hardware/rdtech-tc/api.c @@ -50,9 +50,10 @@ static GSList *rdtech_tc_scan(struct sr_dev_driver *di, const char *conn, const char *serialcomm) { struct sr_serial_dev_inst *serial; - GSList *devices = NULL; - struct dev_context *devc = NULL; - struct sr_dev_inst *sdi = NULL; + GSList *devices; + struct dev_context *devc; + struct sr_dev_inst *sdi; + size_t i; serial = sr_serial_dev_inst_new(conn, serialcomm); if (serial_open(serial, SERIAL_RDWR) != SR_OK) @@ -76,10 +77,12 @@ static GSList *rdtech_tc_scan(struct sr_dev_driver *di, sdi->conn = serial; sdi->priv = devc; - for (int i = 0; devc->channels[i].name; i++) - sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, devc->channels[i].name); + for (i = 0; devc->channels[i].name; i++) { + sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, + devc->channels[i].name); + } - devices = g_slist_append(devices, sdi); + devices = g_slist_append(NULL, sdi); serial_close(serial); if (!devices) sr_serial_dev_inst_free(serial); @@ -98,9 +101,11 @@ err_out: static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_config *src; - const char *conn = NULL; - const char *serialcomm = RDTECH_TC_SERIALCOMM; + const char *conn; + const char *serialcomm; + conn = NULL; + serialcomm = RDTECH_TC_SERIALCOMM; for (GSList *l = options; l; l = l->next) { src = l->data; switch (src->key) { @@ -138,12 +143,14 @@ static int config_list(uint32_t key, GVariant **data, static int dev_acquisition_start(const struct sr_dev_inst *sdi) { - struct dev_context *devc = sdi->priv; - struct sr_serial_dev_inst *serial = sdi->conn; + struct dev_context *devc; + struct sr_serial_dev_inst *serial; + devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->limits); std_session_send_df_header(sdi); + serial = sdi->conn; serial_source_add(sdi->session, serial, G_IO_IN, 50, rdtech_tc_receive_data, (void *)sdi); diff --git a/src/hardware/rdtech-tc/protocol.c b/src/hardware/rdtech-tc/protocol.c index c6b7ce77..f4e02a67 100644 --- a/src/hardware/rdtech-tc/protocol.c +++ b/src/hardware/rdtech-tc/protocol.c @@ -158,15 +158,17 @@ SR_PRIV int rdtech_tc_probe(struct sr_serial_dev_inst *serial, struct dev_contex SR_PRIV int rdtech_tc_poll(const struct sr_dev_inst *sdi) { - struct dev_context *devc = sdi->priv; - struct sr_serial_dev_inst *serial = sdi->conn; + struct dev_context *devc; + struct sr_serial_dev_inst *serial; + 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; return SR_OK; @@ -174,11 +176,12 @@ SR_PRIV int rdtech_tc_poll(const struct sr_dev_inst *sdi) static void handle_poll_data(const struct sr_dev_inst *sdi) { - struct dev_context *devc = sdi->priv; + struct dev_context *devc; uint8_t poll_pkt[TC_POLL_LEN]; int i; GSList *ch; + devc = sdi->priv; sr_spew("Received poll packet (len: %d).", devc->buflen); if (devc->buflen != TC_POLL_LEN) { sr_err("Unexpected poll packet length: %i", devc->buflen); @@ -200,10 +203,11 @@ static void handle_poll_data(const struct sr_dev_inst *sdi) static void recv_poll_data(struct sr_dev_inst *sdi, struct sr_serial_dev_inst *serial) { - struct dev_context *devc = sdi->priv; + struct dev_context *devc; int len; /* Serial data arrived. */ + devc = sdi->priv; while (devc->buflen < TC_POLL_LEN) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) @@ -229,7 +233,6 @@ SR_PRIV int rdtech_tc_receive_data(int fd, int revents, void *cb_data) if (!(sdi = cb_data)) return TRUE; - if (!(devc = sdi->priv)) return TRUE; @@ -244,7 +247,6 @@ SR_PRIV int rdtech_tc_receive_data(int fd, int revents, void *cb_data) now = g_get_monotonic_time() / 1000; elapsed = now - devc->cmd_sent_at; - if (elapsed > TC_POLL_PERIOD_MS) rdtech_tc_poll(sdi);