sdi->vendor = g_strdup(VENDOR_GMC);
sdi->model = g_strdup(gmc_model_str(model));
devc = g_malloc0(sizeof(struct dev_context));
+ sr_sw_limits_init(&devc->limits);
devc->model = model;
- devc->limit_samples = 0;
- devc->limit_msec = 0;
- devc->num_samples = 0;
- devc->elapsed_msec = g_timer_new();
devc->settings_ok = FALSE;
sdi->conn = serial;
sdi->priv = devc;
if (devc->model != METRAHIT_NONE) {
sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(devc->model));
- devc->elapsed_msec = g_timer_new();
+ sr_sw_limits_init(&devc->limits);
sdi->model = g_strdup(gmc_model_str(devc->model));
sdi->version = g_strdup_printf("Firmware %d.%d", devc->fw_ver_maj, devc->fw_ver_min);
sdi->conn = serial;
std_serial_dev_close(sdi);
sdi->status = SR_ST_INACTIVE;
-
- /* Free dynamically allocated resources. */
- if ((devc = sdi->priv) && devc->elapsed_msec) {
- g_timer_destroy(devc->elapsed_msec);
- devc->elapsed_msec = NULL;
+ if ((devc = sdi->priv))
devc->model = METRAHIT_NONE;
- }
return SR_OK;
}
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);
- break;
+ return sr_sw_limits_config_get(&devc->limits, key, data);
case SR_CONF_POWER_OFF:
*data = g_variant_new_boolean(FALSE);
break;
devc->settings_ok = FALSE;
devc->buflen = 0;
+ 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 40ms, or whenever some data comes in. */
serial = sdi->conn;
serial_source_add(sdi->session, serial, G_IO_IN, 40,
devc->settings_ok = FALSE;
devc->buflen = 0;
+ 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 40ms, or whenever some data comes in. */
serial = sdi->conn;
serial_source_add(sdi->session, serial, G_IO_IN, 40,
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);
}
packet.payload = &analog;
sr_session_send(sdi, &packet);
- devc->num_samples++;
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
}
/** Process 6-byte data message, Metrahit 1x/2x send mode. */
struct sr_serial_dev_inst *serial;
uint8_t buf, msgt;
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);
- }
-
return TRUE;
}
struct sr_serial_dev_inst *serial;
uint8_t buf;
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);
- }
-
/* Request next data set, if required */
if (sdi->status == SR_ST_ACTIVE) {
if (devc->response_pending) {
else
g_usleep(2 * 1000 * 1000); /* Wait to ensure transfer before interface switched off. */
break;
- 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;
+ case SR_CONF_LIMIT_MSEC:
+ return sr_sw_limits_config_set(&devc->limits, key, data);
default:
return SR_ERR_NA;
}
enum model model; /**< Model code. */
/* Acquisition settings */
- uint64_t limit_samples; /**< Target number of samples */
- uint64_t limit_msec; /**< Target sampling time */
+ struct sr_sw_limits limits;
/* Operational state */
gboolean settings_ok; /**< Settings msg received yet. */
gboolean response_pending; /**< Request sent, response is pending. */
/* Temporary state across callbacks */
- uint64_t num_samples; /**< Current #samples for limit_samples */
- GTimer *elapsed_msec; /**< Used for sampling with limit_msec */
uint8_t buf[GMC_BUFSIZE]; /**< Buffer for read callback */
int buflen; /**< Data len in buf */
};