From: Lars-Peter Clausen Date: Sun, 1 May 2016 11:52:09 +0000 (+0200) Subject: brymen-dmm: Use software limit helpers X-Git-Tag: libsigrok-0.5.0~455 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=dcba0c41f5345a4c5316128aac44732625faff6e;p=libsigrok.git brymen-dmm: Use software limit helpers Signed-off-by: Lars-Peter Clausen --- diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index a4f96a44..ffc0e9c6 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -79,6 +79,7 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm) sdi->vendor = g_strdup("Brymen"); sdi->model = g_strdup("BM85x"); devc = g_malloc0(sizeof(struct dev_context)); + sr_sw_limits_init(&devc->sw_limits); sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; drvc = di->context; @@ -135,7 +136,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; - int ret; (void)cg; @@ -147,19 +147,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return SR_ERR_BUG; } - 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; - default: - ret = SR_ERR_NA; - } - - return ret; + 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, @@ -194,14 +182,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->starttime = g_get_monotonic_time(); - + sr_sw_limits_acquisition_start(&devc->sw_limits); std_session_send_df_header(sdi, LOG_PREFIX); /* Poll every 50ms, or whenever some data comes in. */ diff --git a/src/hardware/brymen-dmm/protocol.c b/src/hardware/brymen-dmm/protocol.c index 1667bef6..3e1b84c4 100644 --- a/src/hardware/brymen-dmm/protocol.c +++ b/src/hardware/brymen-dmm/protocol.c @@ -43,7 +43,7 @@ static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi) packet.type = SR_DF_ANALOG_OLD; packet.payload = &analog; sr_session_send(sdi, &packet); - devc->num_samples++; + sr_sw_limits_update_samples_read(&devc->sw_limits, 1); } } @@ -114,7 +114,6 @@ SR_PRIV int brymen_dmm_receive_data(int fd, int revents, void *cb_data) struct dev_context *devc; struct sr_serial_dev_inst *serial; int ret; - int64_t time; (void)fd; @@ -137,20 +136,8 @@ SR_PRIV int brymen_dmm_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, stopping."); + if (sr_sw_limits_check(&devc->sw_limits)) sdi->driver->dev_acquisition_stop(sdi); - return TRUE; - } - - if (devc->limit_msec) { - time = (g_get_monotonic_time() - devc->starttime) / 1000; - if (time > (int64_t)devc->limit_msec) { - sr_info("Requested time limit reached, stopping."); - sdi->driver->dev_acquisition_stop(sdi); - return TRUE; - } - } return TRUE; } diff --git a/src/hardware/brymen-dmm/protocol.h b/src/hardware/brymen-dmm/protocol.h index 6f59206a..be26cb96 100644 --- a/src/hardware/brymen-dmm/protocol.h +++ b/src/hardware/brymen-dmm/protocol.h @@ -40,17 +40,7 @@ enum packet_len_status { /** 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; - - /** Start time of acquisition session */ - int64_t starttime; + struct sr_sw_limits sw_limits; uint8_t buf[DMM_BUFSIZE]; int bufoffset;