victor-dmm: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
8a63a4064e
commit
cf9e86bc74
|
@ -86,6 +86,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
||||||
sdi->driver = di;
|
sdi->driver = di;
|
||||||
sdi->connection_id = g_strdup(connection_id);
|
sdi->connection_id = g_strdup(connection_id);
|
||||||
devc = g_malloc0(sizeof(struct dev_context));
|
devc = g_malloc0(sizeof(struct dev_context));
|
||||||
|
sr_sw_limits_init(&devc->limits);
|
||||||
sdi->priv = devc;
|
sdi->priv = devc;
|
||||||
|
|
||||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
|
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
|
||||||
|
@ -170,6 +171,7 @@ static int dev_close(struct sr_dev_inst *sdi)
|
||||||
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
||||||
const struct sr_channel_group *cg)
|
const struct sr_channel_group *cg)
|
||||||
{
|
{
|
||||||
|
struct dev_context *devc = sdi->priv;
|
||||||
struct sr_usb_dev_inst *usb;
|
struct sr_usb_dev_inst *usb;
|
||||||
char str[128];
|
char str[128];
|
||||||
|
|
||||||
|
@ -183,6 +185,9 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
||||||
snprintf(str, 128, "%d.%d", usb->bus, usb->address);
|
snprintf(str, 128, "%d.%d", usb->bus, usb->address);
|
||||||
*data = g_variant_new_string(str);
|
*data = g_variant_new_string(str);
|
||||||
break;
|
break;
|
||||||
|
case SR_CONF_LIMIT_SAMPLES:
|
||||||
|
case SR_CONF_LIMIT_MSEC:
|
||||||
|
return sr_sw_limits_config_get(&devc->limits, key, data);
|
||||||
default:
|
default:
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +199,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
const struct sr_channel_group *cg)
|
const struct sr_channel_group *cg)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
gint64 now;
|
|
||||||
|
|
||||||
(void)cg;
|
(void)cg;
|
||||||
|
|
||||||
|
@ -203,20 +207,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:
|
|
||||||
devc->limit_msec = g_variant_get_uint64(data);
|
|
||||||
now = g_get_monotonic_time() / 1000;
|
|
||||||
devc->end_time = now + devc->limit_msec;
|
|
||||||
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,
|
||||||
|
@ -260,10 +251,8 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
|
||||||
sr_dbg("Got %d-byte packet.", transfer->actual_length);
|
sr_dbg("Got %d-byte packet.", transfer->actual_length);
|
||||||
if (transfer->actual_length == DMM_DATA_SIZE) {
|
if (transfer->actual_length == DMM_DATA_SIZE) {
|
||||||
victor_dmm_receive_data(sdi, transfer->buffer);
|
victor_dmm_receive_data(sdi, transfer->buffer);
|
||||||
if (devc->limit_samples) {
|
if (sr_sw_limits_check(&devc->limits))
|
||||||
if (devc->num_samples >= devc->limit_samples)
|
dev_acquisition_stop(sdi);
|
||||||
dev_acquisition_stop(sdi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Anything else is either an error or a timeout, which is fine:
|
/* Anything else is either an error or a timeout, which is fine:
|
||||||
|
@ -293,7 +282,6 @@ static int handle_events(int fd, int revents, void *cb_data)
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct sr_dev_driver *di;
|
struct sr_dev_driver *di;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gint64 now;
|
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
(void)revents;
|
(void)revents;
|
||||||
|
@ -303,11 +291,8 @@ static int handle_events(int fd, int revents, void *cb_data)
|
||||||
di = sdi->driver;
|
di = sdi->driver;
|
||||||
drvc = di->context;
|
drvc = di->context;
|
||||||
|
|
||||||
if (devc->limit_msec) {
|
if (sr_sw_limits_check(&devc->limits))
|
||||||
now = g_get_monotonic_time() / 1000;
|
dev_acquisition_stop(sdi);
|
||||||
if (now > devc->end_time)
|
|
||||||
dev_acquisition_stop(sdi);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sdi->status == SR_ST_STOPPING) {
|
if (sdi->status == SR_ST_STOPPING) {
|
||||||
usb_source_remove(sdi->session, drvc->sr_ctx);
|
usb_source_remove(sdi->session, drvc->sr_ctx);
|
||||||
|
|
|
@ -264,7 +264,7 @@ static void decode_buf(struct sr_dev_inst *sdi, unsigned char *data)
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf)
|
SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf)
|
||||||
|
|
|
@ -30,15 +30,7 @@
|
||||||
|
|
||||||
/** Private, per-device-instance driver context. */
|
/** Private, per-device-instance driver context. */
|
||||||
struct dev_context {
|
struct dev_context {
|
||||||
/** The current sampling limit (in number of samples). */
|
struct sr_sw_limits limits;
|
||||||
uint64_t limit_samples;
|
|
||||||
|
|
||||||
/** The current sampling limit (in ms). */
|
|
||||||
uint64_t limit_msec;
|
|
||||||
|
|
||||||
/** The current number of already received samples. */
|
|
||||||
uint64_t num_samples;
|
|
||||||
gint64 end_time;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf);
|
SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf);
|
||||||
|
|
Loading…
Reference in New Issue