sdi->model = g_strdup(get_typestr(auxtype, drv));
sdi->version = g_strdup(buf + 9);
devc = g_malloc0(sizeof(struct dev_context));
+ sr_sw_limits_init(&devc->limits);
devc->type = auxtype;
devc->version = g_strdup(&buf[9]);
- devc->elapsed_msec = g_timer_new();
sdi->conn = serial;
sdi->priv = devc;
sdi->driver = drv;
if ((devc = sdi->priv) && devc->version) {
g_free(devc->version);
devc->version = NULL;
- g_timer_destroy(devc->elapsed_msec);
}
return SR_OK;
return SR_ERR_BUG;
}
- switch (key) {
- 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;
+ 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,
devc = sdi->priv;
+ sr_sw_limits_acquisition_start(&devc->limits);
std_session_send_df_header(sdi, LOG_PREFIX);
- /* Start timer, if required. */
- if (devc->limit_msec)
- g_timer_start(devc->elapsed_msec);
-
/* Poll every 100ms, or whenever some data comes in. */
serial = sdi->conn;
serial_source_add(sdi->session, serial, G_IO_IN, 100,
static int dev_acquisition_stop(struct sr_dev_inst *sdi)
{
- struct dev_context *devc;
-
- /* Stop timer, if required. */
- if (sdi && (devc = sdi->priv) && devc->limit_msec)
- g_timer_stop(devc->elapsed_msec);
-
return std_serial_dev_acquisition_stop(sdi, dev_close,
sdi->conn, LOG_PREFIX);
}
sr_session_send(sdi, &packet);
/* Finish processing. */
- devc->num_samples++;
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
devc->buflen = 0;
}
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
int len;
- gboolean terminating;
- gdouble elapsed_s;
(void)fd;
}
}
- /* If number of samples or time limit reached, stop acquisition. */
- terminating = FALSE;
- if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) {
+ if (sr_sw_limits_check(&devc->limits)) {
sdi->driver->dev_acquisition_stop(sdi);
- terminating = TRUE;
- }
-
- if (devc->limit_msec) {
- elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL);
- if ((elapsed_s * 1000) >= devc->limit_msec) {
- sdi->driver->dev_acquisition_stop(sdi);
- terminating = TRUE;
- }
- }
-
- /* Request next package. */
- if (!terminating) {
+ } else {
+ /* Request next package. */
if (devc->last_req_pending) {
gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at;
if (elapsed_us > NMADMM_TIMEOUT_MS * 1000) {/* Timeout! */
int type; /**< DM9x0, e.g. 5 = DM950 */
/* Acquisition settings */
- uint64_t limit_samples; /**< Target number of samples */
- uint64_t limit_msec; /**< Target sampling time */
+ struct sr_sw_limits limits;
/* Operational state */
int last_req; /**< Last request. */
int lowbatt; /**< Low battery. 1=low, 2=critical. */
/* Temporary state across callbacks */
- uint64_t num_samples; /**< Current #samples. */
- GTimer *elapsed_msec; /**< Used for limit_msec */
uint8_t buf[NMADMM_BUFSIZE]; /**< Buffer for read callback */
int buflen; /**< Data len in buf */
};