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);
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);
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) {
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;
}
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;
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.");
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
+
+ if (sr_sw_limits_check(&devc->limits)) {
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;
-
- 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;
- }
}
devc->last_sample_fin = g_get_monotonic_time();
/** 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;