uni-t-dmm: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
2630f97ebb
commit
8a63a4064e
|
@ -34,8 +34,8 @@ static const uint32_t scanopts[] = {
|
||||||
static const uint32_t devopts[] = {
|
static const uint32_t devopts[] = {
|
||||||
SR_CONF_MULTIMETER,
|
SR_CONF_MULTIMETER,
|
||||||
SR_CONF_CONTINUOUS,
|
SR_CONF_CONTINUOUS,
|
||||||
SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
|
SR_CONF_LIMIT_SAMPLES | SR_CONF_SET | SR_CONF_GET,
|
||||||
SR_CONF_LIMIT_MSEC | SR_CONF_SET,
|
SR_CONF_LIMIT_MSEC | SR_CONF_SET | SR_CONF_GET,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -138,18 +138,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
switch (key) {
|
return sr_sw_limits_config_set(&devc->limits, key, data);
|
||||||
case SR_CONF_LIMIT_MSEC:
|
|
||||||
devc->limit_msec = g_variant_get_uint64(data);
|
|
||||||
break;
|
|
||||||
case SR_CONF_LIMIT_SAMPLES:
|
|
||||||
devc->limit_samples = g_variant_get_uint64(data);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return SR_ERR_NA;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
||||||
|
@ -179,7 +168,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
devc->starttime = g_get_monotonic_time();
|
|
||||||
|
sr_sw_limits_acquisition_start(&devc->limits);
|
||||||
|
|
||||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,7 @@ static void decode_packet(struct sr_dev_inst *sdi, const uint8_t *buf)
|
||||||
packet.payload = &analog;
|
packet.payload = &analog;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
|
|
||||||
/* Increase sample count. */
|
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
||||||
devc->num_samples++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hid_chip_init(struct sr_dev_inst *sdi, uint16_t baudrate)
|
static int hid_chip_init(struct sr_dev_inst *sdi, uint16_t baudrate)
|
||||||
|
@ -274,7 +273,6 @@ SR_PRIV int uni_t_dmm_receive_data(int fd, int revents, void *cb_data)
|
||||||
int ret;
|
int ret;
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
int64_t time_ms;
|
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
(void)revents;
|
(void)revents;
|
||||||
|
@ -286,19 +284,8 @@ SR_PRIV int uni_t_dmm_receive_data(int fd, int revents, void *cb_data)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Abort acquisition if we acquired enough samples. */
|
/* Abort acquisition if we acquired enough samples. */
|
||||||
if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
|
if (sr_sw_limits_check(&devc->limits))
|
||||||
sr_info("Requested number of samples reached.");
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
sdi->driver->dev_acquisition_stop(sdi);
|
||||||
}
|
|
||||||
|
|
||||||
if (devc->limit_msec) {
|
|
||||||
time_ms = (g_get_monotonic_time() - devc->starttime) / 1000;
|
|
||||||
if (time_ms > (int64_t)devc->limit_msec) {
|
|
||||||
sr_info("Requested time limit reached.");
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,16 +48,7 @@ struct dmm_info {
|
||||||
|
|
||||||
/** Private, per-device-instance driver context. */
|
/** Private, per-device-instance driver context. */
|
||||||
struct dev_context {
|
struct dev_context {
|
||||||
/** The current sampling limit (in number of samples). */
|
struct sr_sw_limits limits;
|
||||||
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;
|
|
||||||
|
|
||||||
gboolean first_run;
|
gboolean first_run;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue