appa-55ii: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
aea4e45848
commit
e2492a3374
|
@ -130,11 +130,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
|||
|
||||
switch (key) {
|
||||
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;
|
||||
return sr_sw_limits_config_get(&devc->limits, key, data);
|
||||
case SR_CONF_DATA_SOURCE:
|
||||
*data = g_variant_new_string(data_sources[devc->data_source]);
|
||||
break;
|
||||
|
@ -164,11 +161,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
|
||||
switch (key) {
|
||||
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;
|
||||
return sr_sw_limits_config_set(&devc->limits, key, data);
|
||||
case SR_CONF_DATA_SOURCE: {
|
||||
tmp_str = g_variant_get_string(data, NULL);
|
||||
for (i = 0; i < ARRAY_SIZE(data_sources); i++)
|
||||
|
@ -226,13 +219,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
|
||||
devc = sdi->priv;
|
||||
|
||||
/*
|
||||
* Reset the number of samples to take. If we've already collected our
|
||||
* quota, but we start a new session, and don't reset this, we'll just
|
||||
* quit without acquiring any new samples.
|
||||
*/
|
||||
devc->num_samples = 0;
|
||||
devc->start_time = g_get_monotonic_time();
|
||||
sr_sw_limits_acquisition_start(&devc->limits);
|
||||
|
||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ static void appa_55ii_live_data(struct sr_dev_inst *sdi, const uint8_t *buf)
|
|||
sr_session_send(sdi, &packet);
|
||||
g_slist_free(analog.channels);
|
||||
|
||||
devc->num_samples++;
|
||||
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
||||
}
|
||||
|
||||
static void appa_55ii_log_metadata(struct sr_dev_inst *sdi, const uint8_t *buf)
|
||||
|
@ -175,7 +175,7 @@ static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi)
|
|||
sr_session_send(sdi, &packet);
|
||||
g_slist_free(analog.channels);
|
||||
|
||||
devc->num_samples++;
|
||||
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
||||
devc->log_buf_len -= 20;
|
||||
offset += 20;
|
||||
devc->num_log_records--;
|
||||
|
@ -266,7 +266,6 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data)
|
|||
struct sr_dev_inst *sdi;
|
||||
struct dev_context *devc;
|
||||
struct sr_serial_dev_inst *serial;
|
||||
int64_t time;
|
||||
const uint8_t *ptr, *next_ptr, *end_ptr;
|
||||
int len;
|
||||
|
||||
|
@ -301,20 +300,10 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
|
||||
sr_info("Requested number of samples reached.");
|
||||
if (sr_sw_limits_check(&devc->limits)) {
|
||||
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.");
|
||||
sdi->driver->dev_acquisition_stop(sdi);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -39,14 +39,9 @@ enum {
|
|||
/** Private, per-device-instance driver context. */
|
||||
struct dev_context {
|
||||
/* Acquisition settings */
|
||||
uint64_t limit_samples; /**< The sampling limit (in number of samples). */
|
||||
uint64_t limit_msec; /**< The time limit (in milliseconds). */
|
||||
struct sr_sw_limits limits;
|
||||
gboolean data_source; /**< Whether to read live samples or memory */
|
||||
|
||||
/* Operational state */
|
||||
uint64_t num_samples; /**< The number of already received samples. */
|
||||
int64_t start_time; /**< The time at which sampling started. */
|
||||
|
||||
/* Temporary state across callbacks */
|
||||
uint8_t buf[APPA_55II_BUF_SIZE];
|
||||
unsigned int buf_len;
|
||||
|
|
Loading…
Reference in New Issue