X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fdemo%2Fprotocol.c;h=46808fd6cf5622b4cd2ad333906ab9159059ac3d;hb=70cfec9a1419741b5972f10f7bc7aea7c15b700b;hp=9969abf90f4171154751d48a4a239529e7507589;hpb=8ebad343709aad6ef4d5aa83a2633690ef313de5;p=libsigrok.git diff --git a/src/hardware/demo/protocol.c b/src/hardware/demo/protocol.c index 9969abf9..46808fd6 100644 --- a/src/hardware/demo/protocol.c +++ b/src/hardware/demo/protocol.c @@ -459,12 +459,24 @@ 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 (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; } + + if (samples_todo == 0) + return G_SOURCE_CONTINUE; + +#if (SAMPLES_PER_FRAME > 0) /* Avoid "comparison < 0 always false" warning. */ + /* Never send more samples than a frame can fit... */ + samples_todo = MIN(samples_todo, SAMPLES_PER_FRAME); + /* ...or than we need to finish the current frame. */ + samples_todo = MIN(samples_todo, SAMPLES_PER_FRAME - devc->sent_frame_samples); +#endif + /* 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. @@ -515,8 +527,16 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data) return G_SOURCE_REMOVE; } devc->sent_samples += samples_todo; + devc->sent_frame_samples += samples_todo; devc->spent_us += todo_us; +#if (SAMPLES_PER_FRAME > 0) /* Avoid "comparison >= 0 always true" warning. */ + if (devc->sent_frame_samples >= SAMPLES_PER_FRAME) { + std_session_send_frame_end(sdi); + devc->sent_frame_samples = 0; + } +#endif + if ((devc->limit_samples > 0 && devc->sent_samples >= devc->limit_samples) || (limit_us > 0 && devc->spent_us >= limit_us)) { @@ -534,6 +554,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) + if (devc->sent_frame_samples == 0) + std_session_send_frame_begin(sdi); +#endif } return G_SOURCE_CONTINUE;