brymen-bm86x: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
d54a7c42ac
commit
ab939ebba6
|
@ -85,6 +85,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
||||||
sdi->inst_type = SR_INST_USB;
|
sdi->inst_type = SR_INST_USB;
|
||||||
sdi->conn = usb;
|
sdi->conn = usb;
|
||||||
|
|
||||||
|
sr_sw_limits_init(&devc->sw_limits);
|
||||||
|
|
||||||
drvc->instances = g_slist_append(drvc->instances, sdi);
|
drvc->instances = g_slist_append(drvc->instances, sdi);
|
||||||
devices = g_slist_append(devices, sdi);
|
devices = g_slist_append(devices, sdi);
|
||||||
}
|
}
|
||||||
|
@ -174,18 +176,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
||||||
|
|
||||||
(void)cg;
|
(void)cg;
|
||||||
|
|
||||||
switch (key) {
|
return sr_sw_limits_config_get(&devc->sw_limits, key, data);
|
||||||
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;
|
|
||||||
default:
|
|
||||||
return SR_ERR_NA;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
|
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
|
||||||
|
@ -203,18 +194,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
return SR_ERR_BUG;
|
return SR_ERR_BUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (key) {
|
return sr_sw_limits_config_set(&devc->sw_limits, key, data);
|
||||||
case SR_CONF_LIMIT_SAMPLES:
|
|
||||||
devc->limit_samples = g_variant_get_uint64(data);
|
|
||||||
break;
|
|
||||||
case SR_CONF_LIMIT_MSEC:
|
|
||||||
devc->limit_msec = 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,
|
||||||
|
@ -247,7 +227,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
return SR_ERR_DEV_CLOSED;
|
return SR_ERR_DEV_CLOSED;
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
devc->start_time = g_get_monotonic_time();
|
|
||||||
|
sr_sw_limits_acquisition_start(&devc->sw_limits);
|
||||||
|
|
||||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,7 @@ static void brymen_bm86x_handle_packet(const struct sr_dev_inst *sdi,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (analog[0].mq != -1 || analog[1].mq != -1)
|
if (analog[0].mq != -1 || analog[1].mq != -1)
|
||||||
devc->num_samples++;
|
sr_sw_limits_update_samples_read(&devc->sw_limits, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int brymen_bm86x_send_command(const struct sr_dev_inst *sdi)
|
static int brymen_bm86x_send_command(const struct sr_dev_inst *sdi)
|
||||||
|
@ -308,7 +308,6 @@ SR_PRIV int brymen_bm86x_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;
|
||||||
int64_t time;
|
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
(void)revents;
|
(void)revents;
|
||||||
|
@ -328,20 +327,8 @@ SR_PRIV int brymen_bm86x_receive_data(int fd, int revents, void *cb_data)
|
||||||
if (brymen_bm86x_read_interrupt(sdi))
|
if (brymen_bm86x_read_interrupt(sdi))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
|
if (sr_sw_limits_check(&devc->sw_limits))
|
||||||
sr_info("Requested number of samples reached, stopping.");
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
sdi->driver->dev_acquisition_stop(sdi);
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (devc->limit_msec) {
|
|
||||||
time = (g_get_monotonic_time() - devc->start_time) / 1000;
|
|
||||||
if (time > (int64_t)devc->limit_msec) {
|
|
||||||
sr_info("Requested time limit reached, stopping.");
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,10 @@
|
||||||
/** Private, per-device-instance driver context. */
|
/** Private, per-device-instance driver context. */
|
||||||
struct dev_context {
|
struct dev_context {
|
||||||
/* Acquisition settings */
|
/* Acquisition settings */
|
||||||
uint64_t limit_samples; /**< The sampling limit (in number of samples).*/
|
struct sr_sw_limits sw_limits;
|
||||||
uint64_t limit_msec; /**< The time limit (in milliseconds). */
|
|
||||||
|
|
||||||
/* Operational state */
|
/* Operational state */
|
||||||
int detached_kernel_driver;/**< Whether kernel driver was detached or not */
|
int detached_kernel_driver;/**< Whether kernel driver was detached or not */
|
||||||
uint64_t num_samples; /**< The number of already received samples. */
|
|
||||||
int64_t start_time; /**< The time at which sampling started. */
|
|
||||||
|
|
||||||
/* Temporary state across callbacks */
|
/* Temporary state across callbacks */
|
||||||
int interrupt_pending;
|
int interrupt_pending;
|
||||||
|
|
Loading…
Reference in New Issue