agilent-dmm: Use software limits helpers
Use the new software limit helper functions rather than open-coding their functionality. This also fixes the issue that the driver does not reset the limit statistics in acquisition_start(). It also makes the time limit work, which previously was only a stub implementation. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
d8f9609790
commit
5b6829eafe
|
@ -52,11 +52,9 @@ struct agdmm_profile {
|
||||||
/* Private, per-device-instance driver context. */
|
/* Private, per-device-instance driver context. */
|
||||||
struct dev_context {
|
struct dev_context {
|
||||||
const struct agdmm_profile *profile;
|
const struct agdmm_profile *profile;
|
||||||
uint64_t limit_samples;
|
struct sr_sw_limits limits;
|
||||||
uint64_t limit_msec;
|
|
||||||
|
|
||||||
/* Runtime. */
|
/* Runtime. */
|
||||||
uint64_t num_samples;
|
|
||||||
int64_t jobqueue[8];
|
int64_t jobqueue[8];
|
||||||
unsigned char buf[AGDMM_BUFSIZE];
|
unsigned char buf[AGDMM_BUFSIZE];
|
||||||
int buflen;
|
int buflen;
|
||||||
|
|
|
@ -128,6 +128,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
||||||
sdi->model = g_strdup(tokens[1]);
|
sdi->model = g_strdup(tokens[1]);
|
||||||
sdi->version = g_strdup(tokens[3]);
|
sdi->version = g_strdup(tokens[3]);
|
||||||
devc = g_malloc0(sizeof(struct dev_context));
|
devc = g_malloc0(sizeof(struct dev_context));
|
||||||
|
sr_sw_limits_init(&devc->limits);
|
||||||
devc->profile = &supported_agdmm[i];
|
devc->profile = &supported_agdmm[i];
|
||||||
devc->cur_mq = -1;
|
devc->cur_mq = -1;
|
||||||
sdi->inst_type = SR_INST_SERIAL;
|
sdi->inst_type = SR_INST_SERIAL;
|
||||||
|
@ -160,19 +161,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
switch (key) {
|
return sr_sw_limits_config_set(&devc->limits, key, data);
|
||||||
case SR_CONF_LIMIT_MSEC:
|
|
||||||
/* TODO: not yet implemented */
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
||||||
|
@ -202,11 +191,13 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
||||||
|
|
||||||
static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
|
struct dev_context *devc = sdi->priv;
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
if (sdi->status != SR_ST_ACTIVE)
|
if (sdi->status != SR_ST_ACTIVE)
|
||||||
return SR_ERR_DEV_CLOSED;
|
return SR_ERR_DEV_CLOSED;
|
||||||
|
|
||||||
|
sr_sw_limits_acquisition_start(&devc->limits);
|
||||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||||
|
|
||||||
/* Poll every 100ms, or whenever some data comes in. */
|
/* Poll every 100ms, or whenever some data comes in. */
|
||||||
|
|
|
@ -121,7 +121,7 @@ SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data)
|
||||||
|
|
||||||
dispatch(sdi);
|
dispatch(sdi);
|
||||||
|
|
||||||
if (devc->limit_samples && devc->num_samples >= devc->limit_samples)
|
if (sr_sw_limits_check(&devc->limits))
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
sdi->driver->dev_acquisition_stop(sdi);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -307,7 +307,7 @@ static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match)
|
||||||
packet.payload = &analog;
|
packet.payload = &analog;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
|
|
||||||
devc->num_samples++;
|
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue