motech-lps-30x: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
301090aa58
commit
8aafc5e64d
|
@ -460,11 +460,8 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
|
|||
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;
|
||||
|
||||
|
@ -524,8 +521,6 @@ static void dev_clear_private(struct dev_context *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)
|
||||
|
@ -549,11 +544,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
|||
/* 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;
|
||||
|
@ -614,11 +606,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
/* 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;
|
||||
|
@ -803,9 +792,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
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. */
|
||||
|
@ -815,12 +802,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ static void send_data(struct sr_dev_inst *sdi)
|
|||
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. */
|
||||
|
@ -140,7 +140,6 @@ SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data)
|
|||
struct dev_context *devc;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
int len;
|
||||
gdouble elapsed_s;
|
||||
|
||||
(void)fd;
|
||||
|
||||
|
@ -179,16 +178,9 @@ SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data)
|
|||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
|
|
@ -97,8 +97,7 @@ struct dev_context {
|
|||
|
||||
/* 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 */
|
||||
|
||||
|
@ -108,8 +107,6 @@ struct dev_context {
|
|||
|
||||
/* 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 */
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue