]> sigrok.org Git - libsigrok.git/commitdiff
Demo: Implement multi-frame development feature
authorSoeren Apel <redacted>
Sun, 1 Oct 2017 22:25:57 +0000 (00:25 +0200)
committerSoeren Apel <redacted>
Tue, 3 Oct 2017 15:31:48 +0000 (17:31 +0200)
src/hardware/demo/api.c
src/hardware/demo/protocol.c
src/hardware/demo/protocol.h

index 5c1543cb1113229ff7849eaa8d4b1352ef9dff70..f23cb7004f2a5115165bd5f02d5e28fd48c08b29 100644 (file)
@@ -453,6 +453,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
        std_session_send_df_header(sdi);
 
+       if (SAMPLES_PER_FRAME > 0)
+               std_session_send_frame_begin(sdi);
+
        /* We use this timestamp to decide how many more samples to send. */
        devc->start_us = g_get_monotonic_time();
        devc->spent_us = 0;
@@ -464,6 +467,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
        sr_session_source_remove(sdi->session, -1);
+
+       if (SAMPLES_PER_FRAME > 0)
+               std_session_send_frame_end(sdi);
+
        std_session_send_df_end(sdi);
 
        return SR_OK;
index 9969abf90f4171154751d48a4a239529e7507589..37417f734f21e2164a43c9296185a2c4a4879b54 100644 (file)
@@ -459,12 +459,17 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
        /* How many samples are outstanding since the last round? */
        samples_todo = (todo_us * devc->cur_samplerate + G_USEC_PER_SEC - 1)
                        / G_USEC_PER_SEC;
+
+       if (SAMPLES_PER_FRAME > 0)
+               samples_todo = SAMPLES_PER_FRAME;
+
        if (devc->limit_samples > 0) {
                if (devc->limit_samples < devc->sent_samples)
                        samples_todo = 0;
                else if (devc->limit_samples - devc->sent_samples < samples_todo)
                        samples_todo = devc->limit_samples - devc->sent_samples;
        }
+
        /* Calculate the actual time covered by this run back from the sample
         * count, rounded towards zero. This avoids getting stuck on a too-low
         * time delta with no samples being sent due to round-off.
@@ -534,6 +539,11 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
                }
                sr_dbg("Requested number of samples reached.");
                sr_dev_acquisition_stop(sdi);
+       } else {
+               if (SAMPLES_PER_FRAME > 0) {
+                       std_session_send_frame_end(sdi);
+                       std_session_send_frame_begin(sdi);
+               }
        }
 
        return G_SOURCE_CONTINUE;
index 0b13ebfba2ef9b4a217d980bc997eab46ed8b475..53ad043b17845952d35a8bd72fb8b27bf1948d16 100644 (file)
@@ -33,6 +33,8 @@
 #define LOGIC_BUFSIZE                  4096
 /* Size of the analog pattern space per channel. */
 #define ANALOG_BUFSIZE                 4096
+/* This is a development feature: it starts a new frame every n samples. */
+#define SAMPLES_PER_FRAME              0
 
 struct dev_context {
        uint64_t cur_samplerate;