maynuo-m97: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
a655b3fd08
commit
45b75c368f
|
@ -260,10 +260,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
||||||
ret = SR_OK;
|
ret = SR_OK;
|
||||||
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);
|
ret = sr_sw_limits_config_get(&devc->limits, key, data);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_ENABLED:
|
case SR_CONF_ENABLED:
|
||||||
if ((ret = maynuo_m97_get_bit(modbus, ISTATE, &ivalue)) == SR_OK)
|
if ((ret = maynuo_m97_get_bit(modbus, ISTATE, &ivalue)) == SR_OK)
|
||||||
|
@ -347,10 +345,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
ret = SR_OK;
|
ret = SR_OK;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case SR_CONF_LIMIT_SAMPLES:
|
case SR_CONF_LIMIT_SAMPLES:
|
||||||
devc->limit_samples = g_variant_get_uint64(data);
|
|
||||||
break;
|
|
||||||
case SR_CONF_LIMIT_MSEC:
|
case SR_CONF_LIMIT_MSEC:
|
||||||
devc->limit_msec = g_variant_get_uint64(data);
|
ret = sr_sw_limits_config_set(&devc->limits, key, data);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_ENABLED:
|
case SR_CONF_ENABLED:
|
||||||
ret = maynuo_m97_set_input(modbus, g_variant_get_boolean(data));
|
ret = maynuo_m97_set_input(modbus, g_variant_get_boolean(data));
|
||||||
|
@ -453,11 +449,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
maynuo_m97_receive_data, (void *)sdi)) != SR_OK)
|
maynuo_m97_receive_data, (void *)sdi)) != SR_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
sr_sw_limits_acquisition_start(&devc->limits);
|
||||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||||
|
|
||||||
devc->num_samples = 0;
|
|
||||||
devc->starttime = g_get_monotonic_time();
|
|
||||||
|
|
||||||
return maynuo_m97_capture_start(sdi);
|
return maynuo_m97_capture_start(sdi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,6 @@ SR_PRIV int maynuo_m97_receive_data(int fd, int revents, void *cb_data)
|
||||||
struct sr_modbus_dev_inst *modbus;
|
struct sr_modbus_dev_inst *modbus;
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
uint16_t registers[4];
|
uint16_t registers[4];
|
||||||
int64_t t;
|
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
(void)revents;
|
(void)revents;
|
||||||
|
@ -189,24 +188,14 @@ SR_PRIV int maynuo_m97_receive_data(int fd, int revents, void *cb_data)
|
||||||
|
|
||||||
packet.type = SR_DF_FRAME_END;
|
packet.type = SR_DF_FRAME_END;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
devc->num_samples++;
|
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
maynuo_m97_capture_start(sdi);
|
maynuo_m97_capture_start(sdi);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,9 @@ struct dev_context {
|
||||||
const struct maynuo_m97_model *model;
|
const struct maynuo_m97_model *model;
|
||||||
|
|
||||||
/* Acquisition settings */
|
/* Acquisition settings */
|
||||||
uint64_t limit_samples;
|
struct sr_sw_limits limits;
|
||||||
uint64_t limit_msec;
|
|
||||||
|
|
||||||
/* Operational state */
|
/* Operational state */
|
||||||
uint64_t num_samples;
|
|
||||||
int64_t starttime;
|
|
||||||
int expecting_registers;
|
int expecting_registers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue