From: Alexandru Gagniuc Date: Sun, 23 Dec 2012 18:48:48 +0000 (-0600) Subject: serial-dmm: Handle time-limited acquisition X-Git-Tag: dsupstream~408 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f9b9bd632faf4d5651c31a51026f6cbd219256e4;p=libsigrok.git 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 --- diff --git a/hardware/serial-dmm/api.c b/hardware/serial-dmm/api.c index b132ee42..1af637d1 100644 --- a/hardware/serial-dmm/api.c +++ b/hardware/serial-dmm/api.c @@ -38,6 +38,7 @@ static const int hwopts[] = { static const int hwcaps[] = { SR_HWCAP_MULTIMETER, SR_HWCAP_LIMIT_SAMPLES, + SR_HWCAP_LIMIT_MSEC, SR_HWCAP_CONTINUOUS, 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 ".", devc->limit_samples); 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: sr_err("Unknown capability: %d.", hwcap); 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. */ devc->num_samples = 0; + devc->starttime = g_get_monotonic_time(); /* Send header packet to the session bus. */ sr_dbg("Sending SR_DF_HEADER."); diff --git a/hardware/serial-dmm/protocol.c b/hardware/serial-dmm/protocol.c index 09f74dd4..9524f2bd 100644 --- a/hardware/serial-dmm/protocol.c +++ b/hardware/serial-dmm/protocol.c @@ -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 dev_context *devc; + int64_t time; int ret; (void)fd; @@ -183,6 +184,15 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data) 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; } diff --git a/hardware/serial-dmm/protocol.h b/hardware/serial-dmm/protocol.h index d03a391b..e719efd8 100644 --- a/hardware/serial-dmm/protocol.h +++ b/hardware/serial-dmm/protocol.h @@ -72,12 +72,17 @@ struct dev_context { /** The current sampling limit (in number of samples). */ uint64_t limit_samples; + /** The time limit (in milliseconds). */ + uint64_t limit_msec; + /** Opaque pointer passed in by the frontend. */ void *cb_data; /** The current number of already received samples. */ uint64_t num_samples; + int64_t starttime; + struct sr_serial_dev_inst *serial; uint8_t buf[DMM_BUFSIZE];