]> sigrok.org Git - libsigrok.git/commitdiff
fluke-dmm: Use software limits helpers
authorLars-Peter Clausen <redacted>
Wed, 4 May 2016 12:19:04 +0000 (14:19 +0200)
committerUwe Hermann <redacted>
Tue, 31 May 2016 13:54:52 +0000 (15:54 +0200)
Use the new software limit helper functions rather than open-coding their
functionality.

This also fixes the issue that the driver does not reset the limit
statistics in acquisition_start(). It also makes the time limit work, which
previously was only a stub implementation.

Signed-off-by: Lars-Peter Clausen <redacted>
src/hardware/fluke-dmm/api.c
src/hardware/fluke-dmm/fluke-dmm.h
src/hardware/fluke-dmm/fluke.c

index eba36c549824b5c8b8cc2e7cd6a8d4d275246953..deca6c9e3a441fe7ed2d34dda1fdaba4d5b0072f 100644 (file)
@@ -118,6 +118,7 @@ static GSList *fluke_scan(struct sr_dev_driver *di, const char *conn,
                                sdi->model = g_strdup(tokens[0] + 6);
                                sdi->version = g_strdup(tokens[1] + s);
                                devc = g_malloc0(sizeof(struct dev_context));
+                               sr_sw_limits_init(&devc->limits);
                                devc->profile = &supported_flukedmm[i];
                                sdi->inst_type = SR_INST_SERIAL;
                                sdi->conn = serial;
@@ -190,19 +191,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 
        devc = sdi->priv;
 
-       switch (key) {
-       case SR_CONF_LIMIT_MSEC:
-               /* TODO: not yet implemented */
-               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,
@@ -237,6 +226,7 @@ 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);
 
        /* Poll every 100ms, or whenever some data comes in. */
index 8f1571cefc56ece7c6d6f9799a54df04add5cb4a..e85682fbcf3e271bea982a0a3184ad13212cc06b 100644 (file)
@@ -49,11 +49,9 @@ struct flukedmm_profile {
 /* Private, per-device-instance driver context. */
 struct dev_context {
        const struct flukedmm_profile *profile;
-       uint64_t limit_samples;
-       uint64_t limit_msec;
+       struct sr_sw_limits limits;
 
        /* Runtime. */
-       uint64_t num_samples;
        char buf[FLUKEDMM_BUFSIZE];
        int buflen;
        int64_t cmd_sent_at;
index 3629b5f373e1cbbf8e6cd2908efbaaa5569b7708..3261390deb405d664ece57cfea210e73c0839990 100644 (file)
@@ -400,8 +400,8 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
        packet.type = SR_DF_ANALOG_OLD;
        packet.payload = &analog;
        sr_session_send(sdi, &packet);
-       devc->num_samples++;
 
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
 }
 
 static void handle_line(const struct sr_dev_inst *sdi)
@@ -468,7 +468,7 @@ static void handle_line(const struct sr_dev_inst *sdi)
                packet.type = SR_DF_ANALOG_OLD;
                packet.payload = analog;
                sr_session_send(sdi, &packet);
-               devc->num_samples++;
+               sr_sw_limits_update_samples_read(&devc->limits, 1);
                g_free(analog->data);
                g_free(analog);
        }
@@ -508,7 +508,7 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data)
                }
        }
 
-       if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
+       if (sr_sw_limits_check(&devc->limits)) {
                sdi->driver->dev_acquisition_stop(sdi);
                return TRUE;
        }