From: Soeren Apel Date: Sun, 1 Oct 2017 22:25:57 +0000 (+0200) Subject: Demo: Implement multi-frame development feature X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=f55bea7626d8bfa3a3d0bbff1e9f6ac98a6aadc5 Demo: Implement multi-frame development feature --- diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index 5c1543cb..f23cb700 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -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; diff --git a/src/hardware/demo/protocol.c b/src/hardware/demo/protocol.c index 9969abf9..37417f73 100644 --- a/src/hardware/demo/protocol.c +++ b/src/hardware/demo/protocol.c @@ -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; diff --git a/src/hardware/demo/protocol.h b/src/hardware/demo/protocol.h index 0b13ebfb..53ad043b 100644 --- a/src/hardware/demo/protocol.h +++ b/src/hardware/demo/protocol.h @@ -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;