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

index f60d0d69354ab1101e05fd76008a04f181b3a07a..5361908a374b79149e20d2f9ecf958e41f1ab196 100644 (file)
@@ -153,6 +153,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
 
        devc = g_malloc0(sizeof(struct dev_context));
+       sr_sw_limits_init(&devc->limits);
        devc->model = &models[model_id];
        devc->reply[5] = 0;
        devc->req_sent_at = 0;
@@ -191,12 +192,7 @@ static int config_get(uint32_t key, GVariant **data,
        devc = sdi->priv;
 
        switch (key) {
-       case SR_CONF_LIMIT_SAMPLES:
-               *data = g_variant_new_uint64(devc->limit_samples);
-               break;
-       case SR_CONF_LIMIT_MSEC:
-               *data = g_variant_new_uint64(devc->limit_msec);
-               break;
+               return sr_sw_limits_config_get(&devc->limits, key, data);
        case SR_CONF_VOLTAGE:
                *data = g_variant_new_double(devc->voltage);
                break;
@@ -245,15 +241,8 @@ static int config_set(uint32_t key, GVariant *data,
 
        switch (key) {
        case SR_CONF_LIMIT_MSEC:
-               if (g_variant_get_uint64(data) == 0)
-                       return SR_ERR_ARG;
-               devc->limit_msec = g_variant_get_uint64(data);
-               break;
        case SR_CONF_LIMIT_SAMPLES:
-               if (g_variant_get_uint64(data) == 0)
-                       return SR_ERR_ARG;
-               devc->limit_samples = g_variant_get_uint64(data);
-               break;
+               return sr_sw_limits_config_set(&devc->limits, key, data);
        case SR_CONF_VOLTAGE_TARGET:
                dval = g_variant_get_double(data);
                if (dval < devc->model->voltage[0] || dval > devc->model->voltage[1])
@@ -375,10 +364,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);
 
-       devc->starttime = g_get_monotonic_time();
-       devc->num_samples = 0;
        devc->reply_pending = FALSE;
        devc->req_sent_at = 0;
        serial = sdi->conn;
index 709805a93cc2588eb65673e750aed4d006c192f6..5151e1fa251b6b1a1b27e6b7f92eee03084f1a02 100644 (file)
@@ -329,7 +329,7 @@ SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data)
        struct sr_serial_dev_inst *serial;
        struct sr_datafeed_packet packet;
        struct sr_datafeed_analog_old analog;
-       int64_t t, elapsed_us;
+       uint64_t elapsed_us;
 
        (void)fd;
 
@@ -363,7 +363,7 @@ SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data)
                        analog.mqflags = SR_MQFLAG_DC;
                        analog.data = &devc->voltage;
                        sr_session_send(sdi, &packet);
-                       devc->num_samples++;
+                       sr_sw_limits_update_samples_read(&devc->limits, 1);
                }
                next_measurement(devc);
        } else {
@@ -376,21 +376,11 @@ SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data)
                }
        }
 
-       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) {
-               t = (g_get_monotonic_time() - devc->starttime) / 1000;
-               if (t > (int64_t)devc->limit_msec) {
-                       sr_info("Requested time limit reached.");
-                       sdi->driver->dev_acquisition_stop(sdi);
-                       return TRUE;
-               }
-       }
-
        /* Request next packet, if required. */
        if (sdi->status == SR_ST_ACTIVE) {
                if (devc->reply_pending) {
index 307424a0200f1e27605aba18b9dbd221e94c5738..e88360e7edcf0f10b0dc734746e766fac6a1114b 100644 (file)
@@ -76,10 +76,7 @@ struct dev_context {
        const struct korad_kaxxxxp_model *model; /**< Model information. */
 
        /* Acquisition settings */
-       uint64_t limit_samples;
-       uint64_t limit_msec;
-       uint64_t num_samples;
-       int64_t starttime;
+       struct sr_sw_limits limits;
        int64_t req_sent_at;
        gboolean reply_pending;