serial-dmm: Handle time-limited acquisition
Implement SR_HWCAP_LIMIT_MSEC capability, to allow acquisition to automatically stop after a specified amount of time. Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
This commit is contained in:
parent
47eda193b2
commit
f9b9bd632f
|
@ -38,6 +38,7 @@ static const int hwopts[] = {
|
||||||
static const int hwcaps[] = {
|
static const int hwcaps[] = {
|
||||||
SR_HWCAP_MULTIMETER,
|
SR_HWCAP_MULTIMETER,
|
||||||
SR_HWCAP_LIMIT_SAMPLES,
|
SR_HWCAP_LIMIT_SAMPLES,
|
||||||
|
SR_HWCAP_LIMIT_MSEC,
|
||||||
SR_HWCAP_CONTINUOUS,
|
SR_HWCAP_CONTINUOUS,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
@ -411,6 +412,11 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
sr_dbg("Setting sample limit to %" PRIu64 ".",
|
||||||
devc->limit_samples);
|
devc->limit_samples);
|
||||||
break;
|
break;
|
||||||
|
case SR_HWCAP_LIMIT_MSEC:
|
||||||
|
devc->limit_msec = *(const uint64_t *)value;
|
||||||
|
sr_dbg("Setting time limit to %" PRIu64 "ms.",
|
||||||
|
devc->limit_msec);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
sr_err("Unknown capability: %d.", hwcap);
|
sr_err("Unknown capability: %d.", hwcap);
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
@ -443,6 +449,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
* quit without acquiring any new samples.
|
* quit without acquiring any new samples.
|
||||||
*/
|
*/
|
||||||
devc->num_samples = 0;
|
devc->num_samples = 0;
|
||||||
|
devc->starttime = g_get_monotonic_time();
|
||||||
|
|
||||||
/* Send header packet to the session bus. */
|
/* Send header packet to the session bus. */
|
||||||
sr_dbg("Sending SR_DF_HEADER.");
|
sr_dbg("Sending SR_DF_HEADER.");
|
||||||
|
|
|
@ -153,6 +153,7 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
int64_t time;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
|
@ -183,6 +184,15 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data)
|
||||||
return TRUE;
|
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, stopping.");
|
||||||
|
sdi->driver->dev_acquisition_stop(sdi, cb_data);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,12 +72,17 @@ struct dev_context {
|
||||||
/** The current sampling limit (in number of samples). */
|
/** The current sampling limit (in number of samples). */
|
||||||
uint64_t limit_samples;
|
uint64_t limit_samples;
|
||||||
|
|
||||||
|
/** The time limit (in milliseconds). */
|
||||||
|
uint64_t limit_msec;
|
||||||
|
|
||||||
/** Opaque pointer passed in by the frontend. */
|
/** Opaque pointer passed in by the frontend. */
|
||||||
void *cb_data;
|
void *cb_data;
|
||||||
|
|
||||||
/** The current number of already received samples. */
|
/** The current number of already received samples. */
|
||||||
uint64_t num_samples;
|
uint64_t num_samples;
|
||||||
|
|
||||||
|
int64_t starttime;
|
||||||
|
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
uint8_t buf[DMM_BUFSIZE];
|
uint8_t buf[DMM_BUFSIZE];
|
||||||
|
|
Loading…
Reference in New Issue