From: Lars-Peter Clausen Date: Sun, 1 May 2016 11:54:02 +0000 (+0200) Subject: norma-dmm: Use software limit helpers X-Git-Tag: libsigrok-0.5.0~446 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=37dbffd15d37ee101d93fcfcf31cdefa1cacb8d6;p=libsigrok.git norma-dmm: Use software limit helpers Signed-off-by: Lars-Peter Clausen --- diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index a48ef6a2..91fc5a1b 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -139,9 +139,9 @@ static GSList *scan(struct sr_dev_driver *drv, GSList *options) sdi->model = g_strdup(get_typestr(auxtype, drv)); sdi->version = g_strdup(buf + 9); devc = g_malloc0(sizeof(struct dev_context)); + sr_sw_limits_init(&devc->limits); devc->type = auxtype; devc->version = g_strdup(&buf[9]); - devc->elapsed_msec = g_timer_new(); sdi->conn = serial; sdi->priv = devc; sdi->driver = drv; @@ -182,7 +182,6 @@ static int dev_close(struct sr_dev_inst *sdi) if ((devc = sdi->priv) && devc->version) { g_free(devc->version); devc->version = NULL; - g_timer_destroy(devc->elapsed_msec); } return SR_OK; @@ -203,18 +202,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return SR_ERR_BUG; } - switch (key) { - case SR_CONF_LIMIT_MSEC: - devc->limit_msec = g_variant_get_uint64(data); - break; - case SR_CONF_LIMIT_SAMPLES: - devc->limit_samples = g_variant_get_uint64(data); - break; - default: - return SR_ERR_NA; - } - - return SR_OK; + return sr_sw_limits_config_set(&devc->limits, key, data); } static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -249,12 +237,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc = sdi->priv; + sr_sw_limits_acquisition_start(&devc->limits); std_session_send_df_header(sdi, LOG_PREFIX); - /* Start timer, if required. */ - if (devc->limit_msec) - g_timer_start(devc->elapsed_msec); - /* Poll every 100ms, or whenever some data comes in. */ serial = sdi->conn; serial_source_add(sdi->session, serial, G_IO_IN, 100, @@ -265,12 +250,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - struct dev_context *devc; - - /* Stop timer, if required. */ - if (sdi && (devc = sdi->priv) && devc->limit_msec) - g_timer_stop(devc->elapsed_msec); - return std_serial_dev_acquisition_stop(sdi, dev_close, sdi->conn, LOG_PREFIX); } diff --git a/src/hardware/norma-dmm/protocol.c b/src/hardware/norma-dmm/protocol.c index 60bae0b3..7e0f2a10 100644 --- a/src/hardware/norma-dmm/protocol.c +++ b/src/hardware/norma-dmm/protocol.c @@ -369,7 +369,7 @@ static void nma_process_line(const struct sr_dev_inst *sdi) sr_session_send(sdi, &packet); /* Finish processing. */ - devc->num_samples++; + sr_sw_limits_update_samples_read(&devc->limits, 1); devc->buflen = 0; } @@ -379,8 +379,6 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data) struct dev_context *devc; struct sr_serial_dev_inst *serial; int len; - gboolean terminating; - gdouble elapsed_s; (void)fd; @@ -411,23 +409,10 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data) } } - /* If number of samples or time limit reached, stop acquisition. */ - terminating = FALSE; - if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) { + if (sr_sw_limits_check(&devc->limits)) { sdi->driver->dev_acquisition_stop(sdi); - terminating = TRUE; - } - - if (devc->limit_msec) { - elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL); - if ((elapsed_s * 1000) >= devc->limit_msec) { - sdi->driver->dev_acquisition_stop(sdi); - terminating = TRUE; - } - } - - /* Request next package. */ - if (!terminating) { + } else { + /* Request next package. */ if (devc->last_req_pending) { gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at; if (elapsed_us > NMADMM_TIMEOUT_MS * 1000) {/* Timeout! */ diff --git a/src/hardware/norma-dmm/protocol.h b/src/hardware/norma-dmm/protocol.h index 082e736a..9a43dca2 100644 --- a/src/hardware/norma-dmm/protocol.h +++ b/src/hardware/norma-dmm/protocol.h @@ -61,8 +61,7 @@ struct dev_context { int type; /**< DM9x0, e.g. 5 = DM950 */ /* Acquisition settings */ - uint64_t limit_samples; /**< Target number of samples */ - uint64_t limit_msec; /**< Target sampling time */ + struct sr_sw_limits limits; /* Operational state */ int last_req; /**< Last request. */ @@ -71,8 +70,6 @@ struct dev_context { int lowbatt; /**< Low battery. 1=low, 2=critical. */ /* Temporary state across callbacks */ - uint64_t num_samples; /**< Current #samples. */ - GTimer *elapsed_msec; /**< Used for limit_msec */ uint8_t buf[NMADMM_BUFSIZE]; /**< Buffer for read callback */ int buflen; /**< Data len in buf */ };