]> sigrok.org Git - libsigrok.git/commitdiff
arachnid-labs-re-load-pro: Use software limit helpers
authorLars-Peter Clausen <redacted>
Wed, 4 May 2016 12:27:05 +0000 (14:27 +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.

Signed-off-by: Lars-Peter Clausen <redacted>
src/hardware/arachnid-labs-re-load-pro/api.c
src/hardware/arachnid-labs-re-load-pro/protocol.c
src/hardware/arachnid-labs-re-load-pro/protocol.h

index cf5f27507be1d895491367b71d5a981f1fdb76ce..45bc7a159f27f39e48c6dccfcba14415388d4845 100644 (file)
@@ -140,6 +140,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        cg->channels = g_slist_append(cg->channels, ch);
 
        devc = g_malloc0(sizeof(struct dev_context));
+       sr_sw_limits_init(&devc->limits);
        sdi->priv = devc;
 
        serial_close(serial);
@@ -226,11 +227,8 @@ static int config_get(uint32_t key, GVariant **data,
        ret = SR_OK;
        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_REGULATION:
                *data = g_variant_new_string("CC"); /* Always CC mode. */
                break;
@@ -289,11 +287,7 @@ static int config_set(uint32_t key, GVariant *data,
        ret = SR_OK;
        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_ENABLED:
                ret = reloadpro_set_on_off(sdi, g_variant_get_boolean(data));
                break;
@@ -332,12 +326,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        serial_source_add(sdi->session, serial, G_IO_IN, 100,
                          reloadpro_receive_data, (void *)sdi);
 
+       sr_sw_limits_acquisition_start(&devc->limits);
        std_session_send_df_header(sdi, LOG_PREFIX);
 
        memset(devc->buf, 0, RELOADPRO_BUFSIZE);
        devc->buflen = 0;
-       devc->num_samples = 0;
-       devc->starttime = g_get_monotonic_time();
 
        return SR_OK;
 }
index 9431ff3f55ed27933e6f8be4aa5b141449c8d905..cbca8e53f38efa9ba6d0dcdce8779ed551faa16e 100644 (file)
@@ -218,7 +218,7 @@ static void handle_packet(const struct sr_dev_inst *sdi)
        packet.payload = NULL;
        sr_session_send(sdi, &packet);
 
-       devc->num_samples++;
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
 }
 
 static void handle_new_data(const struct sr_dev_inst *sdi)
@@ -252,7 +252,6 @@ SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
-       int64_t t;
 
        (void)fd;
 
@@ -264,20 +263,8 @@ SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data)
 
        handle_new_data(sdi);
 
-       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;
-               }
-       }
 
        return TRUE;
 }
index 35a7a5be267012cedde72ee58a6e1331898ac964..40e465577928abbd1350c6d4f70bc766b472f406 100644 (file)
 
 /** Private, per-device-instance driver context. */
 struct dev_context {
-       uint64_t limit_samples;
-       uint64_t limit_msec;
-       uint64_t num_samples;
-       int64_t starttime;
+       struct sr_sw_limits limits;
        uint8_t buf[RELOADPRO_BUFSIZE];
        int buflen;
        gboolean otp_active;