From: Lars-Peter Clausen Date: Sun, 1 May 2016 11:55:51 +0000 (+0200) Subject: victor-dmm: Use software limit helpers X-Git-Tag: libsigrok-0.5.0~440 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cf9e86bc74ae5bd916b8d1abf27205c36585119f;p=libsigrok.git victor-dmm: Use software limit helpers Signed-off-by: Lars-Peter Clausen --- diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 8f20f599..aefbe8b2 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -86,6 +86,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->driver = di; sdi->connection_id = g_strdup(connection_id); devc = g_malloc0(sizeof(struct dev_context)); + sr_sw_limits_init(&devc->limits); sdi->priv = devc; sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); @@ -170,6 +171,7 @@ static int dev_close(struct sr_dev_inst *sdi) static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + struct dev_context *devc = sdi->priv; struct sr_usb_dev_inst *usb; char str[128]; @@ -183,6 +185,9 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s snprintf(str, 128, "%d.%d", usb->bus, usb->address); *data = g_variant_new_string(str); break; + case SR_CONF_LIMIT_SAMPLES: + case SR_CONF_LIMIT_MSEC: + return sr_sw_limits_config_get(&devc->limits, key, data); default: return SR_ERR_NA; } @@ -194,7 +199,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd const struct sr_channel_group *cg) { struct dev_context *devc; - gint64 now; (void)cg; @@ -203,20 +207,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_MSEC: - devc->limit_msec = g_variant_get_uint64(data); - now = g_get_monotonic_time() / 1000; - devc->end_time = now + devc->limit_msec; - break; - case SR_CONF_LIMIT_SAMPLES: - devc->limit_samples = 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, @@ -260,10 +251,8 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) sr_dbg("Got %d-byte packet.", transfer->actual_length); if (transfer->actual_length == DMM_DATA_SIZE) { victor_dmm_receive_data(sdi, transfer->buffer); - if (devc->limit_samples) { - if (devc->num_samples >= devc->limit_samples) - dev_acquisition_stop(sdi); - } + if (sr_sw_limits_check(&devc->limits)) + dev_acquisition_stop(sdi); } } /* Anything else is either an error or a timeout, which is fine: @@ -293,7 +282,6 @@ static int handle_events(int fd, int revents, void *cb_data) struct sr_dev_inst *sdi; struct sr_dev_driver *di; struct timeval tv; - gint64 now; (void)fd; (void)revents; @@ -303,11 +291,8 @@ static int handle_events(int fd, int revents, void *cb_data) di = sdi->driver; drvc = di->context; - if (devc->limit_msec) { - now = g_get_monotonic_time() / 1000; - if (now > devc->end_time) - dev_acquisition_stop(sdi); - } + if (sr_sw_limits_check(&devc->limits)) + dev_acquisition_stop(sdi); if (sdi->status == SR_ST_STOPPING) { usb_source_remove(sdi->session, drvc->sr_ctx); diff --git a/src/hardware/victor-dmm/protocol.c b/src/hardware/victor-dmm/protocol.c index c25ac52c..13a9befa 100644 --- a/src/hardware/victor-dmm/protocol.c +++ b/src/hardware/victor-dmm/protocol.c @@ -264,7 +264,7 @@ static void decode_buf(struct sr_dev_inst *sdi, unsigned char *data) packet.payload = &analog; sr_session_send(sdi, &packet); - devc->num_samples++; + sr_sw_limits_update_samples_read(&devc->limits, 1); } SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf) diff --git a/src/hardware/victor-dmm/protocol.h b/src/hardware/victor-dmm/protocol.h index 1ee36267..5c07d373 100644 --- a/src/hardware/victor-dmm/protocol.h +++ b/src/hardware/victor-dmm/protocol.h @@ -30,15 +30,7 @@ /** 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; - gint64 end_time; + struct sr_sw_limits limits; }; SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf);