]> sigrok.org Git - libsigrok.git/commitdiff
norma-dmm: Use software limit helpers
authorLars-Peter Clausen <redacted>
Sun, 1 May 2016 11:54:02 +0000 (13:54 +0200)
committerUwe Hermann <redacted>
Mon, 9 May 2016 10:44:41 +0000 (12:44 +0200)
Signed-off-by: Lars-Peter Clausen <redacted>
src/hardware/norma-dmm/api.c
src/hardware/norma-dmm/protocol.c
src/hardware/norma-dmm/protocol.h

index a48ef6a2800dfc2ba9c6cd1ba9ee8e0c950fc122..91fc5a1bd7fe3a47c1b9c4fee5fb735ac8983fb9 100644 (file)
@@ -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);
 }
index 60bae0b3460078f258a43a61de0b138630bb3c03..7e0f2a10834f7fe0fbacc1e0a3026537ede21311 100644 (file)
@@ -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! */
index 082e736a617e0e71911e95dbd338ede9ef76041b..9a43dca27693cc9d9ad0066cacc5e803d2e21abf 100644 (file)
@@ -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 */
 };