kern-scale: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
9edb98982a
commit
7fc9dc31ac
|
@ -105,6 +105,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
||||||
sdi->vendor = g_strdup(scale->vendor);
|
sdi->vendor = g_strdup(scale->vendor);
|
||||||
sdi->model = g_strdup(scale->device);
|
sdi->model = g_strdup(scale->device);
|
||||||
devc = g_malloc0(sizeof(struct dev_context));
|
devc = g_malloc0(sizeof(struct dev_context));
|
||||||
|
sr_sw_limits_init(&devc->limits);
|
||||||
sdi->inst_type = SR_INST_SERIAL;
|
sdi->inst_type = SR_INST_SERIAL;
|
||||||
sdi->conn = serial;
|
sdi->conn = serial;
|
||||||
sdi->priv = devc;
|
sdi->priv = devc;
|
||||||
|
@ -132,18 +133,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
if (!(devc = sdi->priv))
|
if (!(devc = sdi->priv))
|
||||||
return SR_ERR_BUG;
|
return SR_ERR_BUG;
|
||||||
|
|
||||||
switch (key) {
|
return sr_sw_limits_config_set(&devc->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,
|
||||||
|
@ -184,9 +174,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
/* Device replies with "A00\r\n" (OK) or "E01\r\n" (Error). Ignore. */
|
/* Device replies with "A00\r\n" (OK) or "E01\r\n" (Error). Ignore. */
|
||||||
|
|
||||||
devc->num_samples = 0;
|
sr_sw_limits_acquisition_start(&devc->limits);
|
||||||
devc->starttime = g_get_monotonic_time();
|
|
||||||
|
|
||||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||||
|
|
||||||
/* Poll every 50ms, or whenever some data comes in. */
|
/* Poll every 50ms, or whenever some data comes in. */
|
||||||
|
|
|
@ -54,7 +54,7 @@ static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi,
|
||||||
packet.type = SR_DF_ANALOG_OLD;
|
packet.type = SR_DF_ANALOG_OLD;
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,6 @@ SR_PRIV int kern_scale_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 scale_info *scale;
|
struct scale_info *scale;
|
||||||
int64_t time;
|
|
||||||
void *info;
|
void *info;
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
|
@ -122,20 +121,8 @@ SR_PRIV int kern_scale_receive_data(int fd, int revents, void *cb_data)
|
||||||
g_free(info);
|
g_free(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (devc->limit_msec) {
|
|
||||||
time = (g_get_monotonic_time() - devc->starttime) / 1000;
|
|
||||||
if (time > (int64_t)devc->limit_msec) {
|
|
||||||
sr_info("Requested time limit reached.");
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,17 +49,7 @@ struct scale_info {
|
||||||
|
|
||||||
/** 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 time limit (in milliseconds). */
|
|
||||||
uint64_t limit_msec;
|
|
||||||
|
|
||||||
/** The current number of already received samples. */
|
|
||||||
uint64_t num_samples;
|
|
||||||
|
|
||||||
/** The starting time of current sampling run. */
|
|
||||||
int64_t starttime;
|
|
||||||
|
|
||||||
uint8_t buf[SCALE_BUFSIZE];
|
uint8_t buf[SCALE_BUFSIZE];
|
||||||
int bufoffset;
|
int bufoffset;
|
||||||
|
|
Loading…
Reference in New Issue