]> sigrok.org Git - libsigrok.git/commitdiff
serial-dmm: Handle time-limited acquisition
authorAlexandru Gagniuc <redacted>
Sun, 23 Dec 2012 18:48:48 +0000 (12:48 -0600)
committerUwe Hermann <redacted>
Tue, 25 Dec 2012 22:55:42 +0000 (23:55 +0100)
Implement SR_HWCAP_LIMIT_MSEC capability, to allow acquisition to automatically
stop after a specified amount of time.

Signed-off-by: Alexandru Gagniuc <redacted>
hardware/serial-dmm/api.c
hardware/serial-dmm/protocol.c
hardware/serial-dmm/protocol.h

index b132ee4224a323fe535bc7d0e1e9116fe65c39fb..1af637d107d31033222d96edb94fef88192af060 100644 (file)
@@ -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.");
index 09f74dd4c56cfb6e750615fddfabf3b40ac9d7c3..9524f2bd92dbfee13a591584f67bd36d9956b994 100644 (file)
@@ -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;
 }
 
index d03a391b3ead26c20da27642897cd8ef0c28a87d..e719efd81e15f2783d9650153dde629e11cddf6a 100644 (file)
@@ -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];