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

index 997d1405b1b6d8d93ec88b73c4aba4dc8ef56bc1..27fcad531186731013c5e1d74f9cbcf73eac77d8 100644 (file)
@@ -146,22 +146,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_SAMPLES:
-               if (g_variant_get_uint64(data) == 0)
-                       return SR_ERR_ARG;
-               devc->limit_samples = g_variant_get_uint64(data);
-               break;
-       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;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return sr_sw_limits_config_set(&devc->sw_limits, key, data);
 }
 
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
@@ -198,8 +183,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx)
                return SR_ERR_DEV_CLOSED;
 
        devc = sdi->priv;
-       devc->num_samples = 0;
-       devc->starttime = g_get_monotonic_time();
+
+       sr_sw_limits_acquisition_start(&devc->sw_limits);
 
        std_session_send_df_header(sdi, LOG_PREFIX);
 
index 0c491723d4a8d18858d573b2a3210fd0022491f1..a67a884f97a7a31c7ffeb4a7b95af7234f93b1e6 100644 (file)
@@ -157,7 +157,7 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
                g_slist_free(l);
        }
 
-       devc->num_samples++;
+       sr_sw_limits_update_samples_read(&devc->sw_limits, 1);
 
        return SR_OK;
 }
@@ -205,7 +205,6 @@ static int receive_data(int fd, int revents, int idx, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
-       int64_t t;
        static gboolean request_new_packet = TRUE;
        struct sr_serial_dev_inst *serial;
 
@@ -233,20 +232,8 @@ static int receive_data(int fd, int revents, int idx, 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->sw_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;
-               }
-       }
 
        return TRUE;
 }
index f6564491752c1bd259b01497e77f96367650720c..a5a3df43a7da407047cf0a282baad2685ee1fe04 100644 (file)
@@ -54,16 +54,7 @@ extern SR_PRIV const struct center_dev_info center_devs[];
 
 /** Private, per-device-instance driver context. */
 struct dev_context {
-       /** The current sampling limit (in number of samples). */
-       uint64_t limit_samples;
-
-       /** The current sampling limit (in ms). */
-       uint64_t limit_msec;
-
-       /** The current number of already received samples. */
-       uint64_t num_samples;
-
-       int64_t starttime;
+       struct sr_sw_limits sw_limits;
 
        uint8_t buf[SERIAL_BUFSIZE];
        int bufoffset;