]> sigrok.org Git - libsigrok.git/commitdiff
serial-dmm: Use software limit helpers
authorLars-Peter Clausen <redacted>
Sun, 1 May 2016 11:54:14 +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/serial-dmm/api.c
src/hardware/serial-dmm/protocol.c
src/hardware/serial-dmm/protocol.h

index a9de067467011ed8a492f1e467e4a9e9ae64b0c6..b66274c5d7730c985e3d9d10387e3e1a62c86098 100644 (file)
@@ -131,6 +131,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        sdi->vendor = g_strdup(dmm->vendor);
        sdi->model = g_strdup(dmm->device);
        devc = g_malloc0(sizeof(struct dev_context));
+       sr_sw_limits_init(&devc->limits);
        sdi->inst_type = SR_INST_SERIAL;
        sdi->conn = serial;
        sdi->priv = devc;
@@ -160,18 +161,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_SAMPLES:
-               devc->limit_samples = g_variant_get_uint64(data);
-               break;
-       case SR_CONF_LIMIT_MSEC:
-               devc->limit_msec = 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,
@@ -206,14 +196,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
 
-       /*
-        * Reset the number of samples to take. If we've already collected our
-        * quota, but we start a new session, and don't reset this, we'll just
-        * quit without acquiring any new samples.
-        */
-       devc->num_samples = 0;
-       devc->starttime = g_get_monotonic_time();
-
+       sr_sw_limits_acquisition_start(&devc->limits);
        std_session_send_df_header(sdi, LOG_PREFIX);
 
        /* Poll every 50ms, or whenever some data comes in. */
index 1e343a2f3f89254923965dc77a352888069a5aaf..3ea85be5461bc014938c4c37955fd72990ea3792 100644 (file)
@@ -70,7 +70,7 @@ static void handle_packet(const uint8_t *buf, 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);
        }
 }
 
@@ -160,7 +160,6 @@ int receive_data(int fd, int revents, void *cb_data)
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
        struct dmm_info *dmm;
-       int64_t time;
        void *info;
 
        (void)fd;
@@ -184,20 +183,8 @@ int receive_data(int fd, int revents, void *cb_data)
                        return FALSE;
        }
 
-       if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
-               sr_info("Requested number of samples reached.");
+       if (sr_sw_limits_check(&devc->limits))
                sdi->driver->dev_acquisition_stop(sdi);
-               return TRUE;
-       }
-
-       if (devc->limit_msec) {
-               time = (g_get_monotonic_time() - devc->starttime) / 1000;
-               if (time > (int64_t)devc->limit_msec) {
-                       sr_info("Requested time limit reached.");
-                       sdi->driver->dev_acquisition_stop(sdi);
-                       return TRUE;
-               }
-       }
 
        return TRUE;
 }
index da6742c35b6732f776eea17a66b5ca4e6b872f1c..8c21f9d975847dcce16cde3eb5866cef45b70edb 100644 (file)
@@ -58,17 +58,7 @@ struct dmm_info {
 
 /** Private, per-device-instance driver context. */
 struct dev_context {
-       /** The current sampling limit (in number of samples). */
-       uint64_t limit_samples;
-
-       /** The time limit (in milliseconds). */
-       uint64_t limit_msec;
-
-       /** The current number of already received samples. */
-       uint64_t num_samples;
-
-       /** The starting time of current sampling run. */
-       int64_t starttime;
+       struct sr_sw_limits limits;
 
        uint8_t buf[DMM_BUFSIZE];
        int bufoffset;