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

index c4e34331a71332d7e911ce9816705c9c0e156bd5..03c1452480974516e3841ec0fb88323cbdb2e925 100644 (file)
@@ -130,11 +130,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
 
        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_DATA_SOURCE:
                *data = g_variant_new_string(data_sources[devc->data_source]);
                break;
@@ -164,11 +161,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 
        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;
+               return sr_sw_limits_config_set(&devc->limits, key, data);
        case SR_CONF_DATA_SOURCE: {
                tmp_str = g_variant_get_string(data, NULL);
                for (i = 0; i < ARRAY_SIZE(data_sources); i++)
@@ -226,13 +219,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->start_time = g_get_monotonic_time();
+       sr_sw_limits_acquisition_start(&devc->limits);
 
        std_session_send_df_header(sdi, LOG_PREFIX);
 
index 257f60577e99c2c443f49e41f9c8bf5914a5a2b8..4720fd4f24d11b5c0e3b660e58229713919cdb21 100644 (file)
@@ -123,7 +123,7 @@ static void appa_55ii_live_data(struct sr_dev_inst *sdi, const uint8_t *buf)
        sr_session_send(sdi, &packet);
        g_slist_free(analog.channels);
 
-       devc->num_samples++;
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
 }
 
 static void appa_55ii_log_metadata(struct sr_dev_inst *sdi, const uint8_t *buf)
@@ -175,7 +175,7 @@ static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi)
                sr_session_send(sdi, &packet);
                g_slist_free(analog.channels);
 
-               devc->num_samples++;
+               sr_sw_limits_update_samples_read(&devc->limits, 1);
                devc->log_buf_len -= 20;
                offset += 20;
                devc->num_log_records--;
@@ -266,7 +266,6 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data)
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
-       int64_t time;
        const uint8_t *ptr, *next_ptr, *end_ptr;
        int len;
 
@@ -301,20 +300,10 @@ SR_PRIV int appa_55ii_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->start_time) / 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 23b59b95733fd466c0bf9c6a8092ff308fcf0ccf..eeae8e1ad4c4ce3e124095a4c68809d6c070cfef 100644 (file)
@@ -39,14 +39,9 @@ enum {
 /** Private, per-device-instance driver context. */
 struct dev_context {
        /* Acquisition settings */
-       uint64_t limit_samples;   /**< The sampling limit (in number of samples). */
-       uint64_t limit_msec;      /**< The time limit (in milliseconds). */
+       struct sr_sw_limits limits;
        gboolean data_source;     /**< Whether to read live samples or memory */
 
-       /* Operational state */
-       uint64_t num_samples;     /**< The number of already received samples. */
-       int64_t start_time;       /**< The time at which sampling started. */
-
        /* Temporary state across callbacks */
        uint8_t buf[APPA_55II_BUF_SIZE];
        unsigned int buf_len;