sdi->conn = serial;
devc = g_malloc0(sizeof(struct dev_context));
+ sr_sw_limits_init(&devc->limits);
devc->model = &models[modelid];
- devc->limit_samples = 0;
- devc->limit_msec = 0;
- devc->num_samples = 0;
- devc->elapsed_msec = g_timer_new();
sdi->priv = devc;
/* Free channel_status.info (list only, data owned by sdi). */
for (ch_idx = 0; ch_idx < devc->model->num_channels; ch_idx++)
g_slist_free(devc->channel_status[ch_idx].info);
-
- g_timer_destroy(devc->elapsed_msec);
}
static int dev_clear_lps301(const struct sr_dev_driver *di)
/* No channel group: global options. */
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_CHANNEL_CONFIG:
*data = g_variant_new_string(channel_modes[devc->tracking_mode]);
break;
/* No channel group: global options. */
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;
+ return sr_sw_limits_config_set(&devc->limits, key, data);
case SR_CONF_CHANNEL_CONFIG:
sval = g_variant_get_string(data, NULL);
found = FALSE;
motech_lps_30x_receive_data, (void *)sdi);
std_session_send_df_header(sdi, LOG_PREFIX);
- /* Start timer, if required. */
- if (devc->limit_msec)
- g_timer_start(devc->elapsed_msec);
+ sr_sw_limits_acquisition_start(&devc->limits);
devc->acq_req = AQ_NONE;
/* Do not start polling device here, the read function will do it in 50 ms. */
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, std_serial_dev_close,
sdi->conn, LOG_PREFIX);
}
analog.data[i] = devc->channel_status[i].output_current_last; /* Value always 0 for channel 3, if present! */
sr_session_send(sdi, &packet);
- devc->num_samples++;
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
}
/** Process a complete line (without CR/LF) in buf. */
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
int len;
- gdouble elapsed_s;
(void)fd;
}
}
- /* If number of samples or time limit reached, stop acquisition. */
- if (devc->limit_samples && (devc->num_samples >= devc->limit_samples))
+ if (sr_sw_limits_check(&devc->limits))
sdi->driver->dev_acquisition_stop(sdi);
- 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);
- }
-
/* Only request the next packet if required. */
if (!((sdi->status == SR_ST_ACTIVE) && (devc->acq_running)))
return TRUE;
/* Acquisition status */
gboolean acq_running; /**< Acquisition is running. */
- uint64_t limit_samples; /**< Target number of samples */
- uint64_t limit_msec; /**< Target sampling time */
+ struct sr_sw_limits limits;
acquisition_req acq_req; /**< Current request. */
uint8_t acq_req_pending; /**< Request pending. 0=none, 1=reply, 2=OK */
/* Temporary state across callbacks */
int64_t req_sent_at; /**< Request sent. */
- uint64_t num_samples; /**< Current #samples for limit_samples */
- GTimer *elapsed_msec; /**< Used for sampling with limit_msec */
gchar buf[LINELEN_MAX]; /**< Buffer for read callback */
int buflen; /**< Data len in buf */
};