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);
- break;
+ return sr_sw_limits_config_get(&devc->limits, key, data);
case SR_CONF_DATA_SOURCE:
*data = g_variant_new_string(data_sources[devc->data_source]);
break;
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;
+ return sr_sw_limits_config_set(&devc->limits, key, data);
case SR_CONF_DATA_SOURCE: {
tmp_str = g_variant_get_string(data, NULL);
for (i = 0; i < ARRAY_SIZE(data_sources); i++)
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->start_time = g_get_monotonic_time();
+ sr_sw_limits_acquisition_start(&devc->limits);
std_session_send_df_header(sdi, LOG_PREFIX);
sr_session_send(sdi, &packet);
g_slist_free(analog.channels);
- devc->num_samples++;
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
}
static void appa_55ii_log_metadata(struct sr_dev_inst *sdi, const uint8_t *buf)
sr_session_send(sdi, &packet);
g_slist_free(analog.channels);
- devc->num_samples++;
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
devc->log_buf_len -= 20;
offset += 20;
devc->num_log_records--;
struct sr_dev_inst *sdi;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
- int64_t time;
const uint8_t *ptr, *next_ptr, *end_ptr;
int len;
return FALSE;
}
- if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
- sr_info("Requested number of samples reached.");
+ if (sr_sw_limits_check(&devc->limits)) {
sdi->driver->dev_acquisition_stop(sdi);
return TRUE;
}
- if (devc->limit_msec) {
- time = (g_get_monotonic_time() - devc->start_time) / 1000;
- if (time > (int64_t)devc->limit_msec) {
- sr_info("Requested time limit reached.");
- sdi->driver->dev_acquisition_stop(sdi);
- return TRUE;
- }
- }
-
return TRUE;
}
/** Private, per-device-instance driver context. */
struct dev_context {
/* Acquisition settings */
- uint64_t limit_samples; /**< The sampling limit (in number of samples). */
- uint64_t limit_msec; /**< The time limit (in milliseconds). */
+ struct sr_sw_limits limits;
gboolean data_source; /**< Whether to read live samples or memory */
- /* Operational state */
- uint64_t num_samples; /**< The number of already received samples. */
- int64_t start_time; /**< The time at which sampling started. */
-
/* Temporary state across callbacks */
uint8_t buf[APPA_55II_BUF_SIZE];
unsigned int buf_len;