baylibre-acme: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
e2492a3374
commit
d54a7c42ac
|
@ -174,10 +174,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);
|
||||
ret = sr_sw_limits_config_get(&devc->limits, key, data);
|
||||
break;
|
||||
case SR_CONF_SAMPLERATE:
|
||||
*data = g_variant_new_uint64(devc->samplerate);
|
||||
|
@ -219,12 +217,8 @@ 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);
|
||||
devc->limit_msec = 0;
|
||||
break;
|
||||
case SR_CONF_LIMIT_MSEC:
|
||||
devc->limit_msec = g_variant_get_uint64(data) * 1000;
|
||||
devc->limit_samples = 0;
|
||||
ret = sr_sw_limits_config_set(&devc->limits, key, data);
|
||||
break;
|
||||
case SR_CONF_SAMPLERATE:
|
||||
samplerate = g_variant_get_uint64(data);
|
||||
|
@ -345,7 +339,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
return SR_ERR;
|
||||
|
||||
devc = sdi->priv;
|
||||
devc->samples_read = 0;
|
||||
devc->samples_missed = 0;
|
||||
devc->timer_fd = timerfd_create(CLOCK_MONOTONIC, 0);
|
||||
if (devc->timer_fd < 0) {
|
||||
|
@ -372,7 +365,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
G_IO_IN | G_IO_ERR, 1000, bl_acme_receive_data, (void *)sdi);
|
||||
|
||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||
devc->start_time = g_get_monotonic_time();
|
||||
sr_sw_limits_acquisition_start(&devc->limits);
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
|
|
@ -697,7 +697,6 @@ SR_PRIV void bl_acme_close_channel(struct sr_channel *ch)
|
|||
|
||||
SR_PRIV int bl_acme_receive_data(int fd, int revents, void *cb_data)
|
||||
{
|
||||
uint32_t cur_time, elapsed_time;
|
||||
uint64_t nrexpiration;
|
||||
struct sr_datafeed_packet packet, framep;
|
||||
struct sr_datafeed_analog_old analog;
|
||||
|
@ -783,23 +782,11 @@ SR_PRIV int bl_acme_receive_data(int fd, int revents, void *cb_data)
|
|||
sr_session_send(sdi, &framep);
|
||||
}
|
||||
|
||||
devc->samples_read++;
|
||||
if (devc->limit_samples > 0 &&
|
||||
devc->samples_read >= devc->limit_samples) {
|
||||
sr_info("Requested number of samples reached.");
|
||||
sdi->driver->dev_acquisition_stop(sdi);
|
||||
devc->last_sample_fin = g_get_monotonic_time();
|
||||
return TRUE;
|
||||
} else if (devc->limit_msec > 0) {
|
||||
cur_time = g_get_monotonic_time();
|
||||
elapsed_time = cur_time - devc->start_time;
|
||||
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
||||
|
||||
if (elapsed_time >= devc->limit_msec) {
|
||||
sr_info("Sampling time limit reached.");
|
||||
sdi->driver->dev_acquisition_stop(sdi);
|
||||
devc->last_sample_fin = g_get_monotonic_time();
|
||||
return TRUE;
|
||||
}
|
||||
if (sr_sw_limits_check(&devc->limits)) {
|
||||
sdi->driver->dev_acquisition_stop(sdi);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
devc->last_sample_fin = g_get_monotonic_time();
|
||||
|
|
|
@ -52,13 +52,10 @@ enum probe_type {
|
|||
/** Private, per-device-instance driver context. */
|
||||
struct dev_context {
|
||||
uint64_t samplerate;
|
||||
uint64_t limit_samples;
|
||||
uint64_t limit_msec;
|
||||
struct sr_sw_limits limits;
|
||||
|
||||
uint32_t num_channels;
|
||||
uint64_t samples_read;
|
||||
uint64_t samples_missed;
|
||||
int64_t start_time;
|
||||
int64_t last_sample_fin;
|
||||
int timer_fd;
|
||||
GIOChannel *channel;
|
||||
|
|
Loading…
Reference in New Issue