manson-hcs-3xxx: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
597deef91e
commit
a655b3fd08
|
@ -159,6 +159,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
||||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
|
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
|
||||||
|
|
||||||
devc = g_malloc0(sizeof(struct dev_context));
|
devc = g_malloc0(sizeof(struct dev_context));
|
||||||
|
sr_sw_limits_init(&devc->limits);
|
||||||
devc->model = &models[model_id];
|
devc->model = &models[model_id];
|
||||||
|
|
||||||
sdi->priv = devc;
|
sdi->priv = devc;
|
||||||
|
@ -214,11 +215,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case SR_CONF_LIMIT_SAMPLES:
|
case SR_CONF_LIMIT_SAMPLES:
|
||||||
*data = g_variant_new_uint64(devc->limit_samples);
|
|
||||||
break;
|
|
||||||
case SR_CONF_LIMIT_MSEC:
|
case SR_CONF_LIMIT_MSEC:
|
||||||
*data = g_variant_new_uint64(devc->limit_msec);
|
return sr_sw_limits_config_get(&devc->limits, key, data);
|
||||||
break;
|
|
||||||
case SR_CONF_VOLTAGE:
|
case SR_CONF_VOLTAGE:
|
||||||
*data = g_variant_new_double(devc->voltage);
|
*data = g_variant_new_double(devc->voltage);
|
||||||
break;
|
break;
|
||||||
|
@ -257,15 +255,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case SR_CONF_LIMIT_MSEC:
|
case SR_CONF_LIMIT_MSEC:
|
||||||
if (g_variant_get_uint64(data) == 0)
|
return sr_sw_limits_config_set(&devc->limits, key, data);
|
||||||
return SR_ERR_ARG;
|
|
||||||
devc->limit_msec = g_variant_get_uint64(data);
|
|
||||||
break;
|
|
||||||
case SR_CONF_LIMIT_SAMPLES:
|
|
||||||
if (g_variant_get_uint64(data) == 0)
|
|
||||||
return SR_ERR_ARG;
|
|
||||||
devc->limit_samples = g_variant_get_uint64(data);
|
|
||||||
break;
|
|
||||||
case SR_CONF_VOLTAGE_TARGET:
|
case SR_CONF_VOLTAGE_TARGET:
|
||||||
dval = g_variant_get_double(data);
|
dval = g_variant_get_double(data);
|
||||||
if (dval < devc->model->voltage[0] || dval > devc->voltage_max_device)
|
if (dval < devc->model->voltage[0] || dval > devc->voltage_max_device)
|
||||||
|
@ -382,10 +372,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
|
sr_sw_limits_acquisition_start(&devc->limits);
|
||||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||||
|
|
||||||
devc->starttime = g_get_monotonic_time();
|
|
||||||
devc->num_samples = 0;
|
|
||||||
devc->reply_pending = FALSE;
|
devc->reply_pending = FALSE;
|
||||||
devc->req_sent_at = 0;
|
devc->req_sent_at = 0;
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,8 @@ static void send_sample(struct sr_dev_inst *sdi)
|
||||||
analog.data = &devc->current;
|
analog.data = &devc->current;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
|
|
||||||
devc->num_samples++;
|
|
||||||
|
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_reply(struct sr_dev_inst *sdi)
|
static int parse_reply(struct sr_dev_inst *sdi)
|
||||||
|
@ -206,7 +207,7 @@ SR_PRIV int hcs_receive_data(int fd, int revents, void *cb_data)
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
int64_t t, elapsed_us;
|
uint64_t elapsed_us;
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
|
|
||||||
|
@ -225,21 +226,11 @@ SR_PRIV int hcs_receive_data(int fd, int revents, void *cb_data)
|
||||||
/* Timeout. */
|
/* Timeout. */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) {
|
if (sr_sw_limits_check(&devc->limits)) {
|
||||||
sr_info("Requested number of samples reached.");
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
sdi->driver->dev_acquisition_stop(sdi);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devc->limit_msec) {
|
|
||||||
t = (g_get_monotonic_time() - devc->starttime) / 1000;
|
|
||||||
if (t > (int64_t)devc->limit_msec) {
|
|
||||||
sr_info("Requested time limit reached.");
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Request next packet, if required. */
|
/* Request next packet, if required. */
|
||||||
if (sdi->status == SR_ST_ACTIVE) {
|
if (sdi->status == SR_ST_ACTIVE) {
|
||||||
if (devc->reply_pending) {
|
if (devc->reply_pending) {
|
||||||
|
|
|
@ -68,10 +68,7 @@ struct hcs_model {
|
||||||
struct dev_context {
|
struct dev_context {
|
||||||
const struct hcs_model *model; /**< Model information. */
|
const struct hcs_model *model; /**< Model information. */
|
||||||
|
|
||||||
uint64_t limit_samples;
|
struct sr_sw_limits limits;
|
||||||
uint64_t limit_msec;
|
|
||||||
uint64_t num_samples;
|
|
||||||
int64_t starttime;
|
|
||||||
int64_t req_sent_at;
|
int64_t req_sent_at;
|
||||||
gboolean reply_pending;
|
gboolean reply_pending;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue