demo: make frame generation (and maximum frame count) a runtime option
The previous implementation supported the generation of frames as a compile time option. This change lets users adjust the feature at runtime. In the absence of a frame count limit no frame begin/end markers get sent (the default behaviour of the previous implementation). When a frame count limit is specified, the respective number of frames gets sent and acquisition stops. The fixed amount of 1000 samples per frame is an arbitrary choice. This compile time option is easily adjusted in the source code.
This commit is contained in:
parent
0373343046
commit
fb193945b6
|
@ -62,6 +62,7 @@ static const uint32_t devopts[] = {
|
|||
SR_CONF_CONTINUOUS,
|
||||
SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
|
||||
SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
|
||||
SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
|
||||
SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
|
||||
SR_CONF_AVERAGING | SR_CONF_GET | SR_CONF_SET,
|
||||
SR_CONF_AVG_SAMPLES | SR_CONF_GET | SR_CONF_SET,
|
||||
|
@ -223,6 +224,9 @@ static int config_get(uint32_t key, GVariant **data,
|
|||
case SR_CONF_LIMIT_MSEC:
|
||||
*data = g_variant_new_uint64(devc->limit_msec);
|
||||
break;
|
||||
case SR_CONF_LIMIT_FRAMES:
|
||||
*data = g_variant_new_uint64(devc->limit_frames);
|
||||
break;
|
||||
case SR_CONF_AVERAGING:
|
||||
*data = g_variant_new_boolean(devc->avg);
|
||||
break;
|
||||
|
@ -284,6 +288,9 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
devc->limit_samples = 0;
|
||||
break;
|
||||
case SR_CONF_LIMIT_FRAMES:
|
||||
devc->limit_frames = g_variant_get_uint64(data);
|
||||
break;
|
||||
case SR_CONF_AVERAGING:
|
||||
devc->avg = g_variant_get_boolean(data);
|
||||
sr_dbg("%s averaging", devc->avg ? "Enabling" : "Disabling");
|
||||
|
@ -458,7 +465,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
|
||||
std_session_send_df_header(sdi);
|
||||
|
||||
if (SAMPLES_PER_FRAME > 0)
|
||||
if (devc->limit_frames > 0)
|
||||
std_session_send_frame_begin(sdi);
|
||||
|
||||
/* We use this timestamp to decide how many more samples to send. */
|
||||
|
@ -471,9 +478,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
|
||||
static int dev_acquisition_stop(struct sr_dev_inst *sdi)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
|
||||
sr_session_source_remove(sdi->session, -1);
|
||||
|
||||
if (SAMPLES_PER_FRAME > 0)
|
||||
devc = sdi->priv;
|
||||
if (devc->limit_frames > 0)
|
||||
std_session_send_frame_end(sdi);
|
||||
|
||||
std_session_send_df_end(sdi);
|
||||
|
|
|
@ -493,12 +493,13 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
|
|||
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
|
||||
if (devc->limit_frames) {
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Calculate the actual time covered by this run back from the sample
|
||||
* count, rounded towards zero. This avoids getting stuck on a too-low
|
||||
|
@ -553,12 +554,15 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
|
|||
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) {
|
||||
if (devc->limit_frames && devc->sent_frame_samples >= SAMPLES_PER_FRAME) {
|
||||
std_session_send_frame_end(sdi);
|
||||
devc->sent_frame_samples = 0;
|
||||
devc->limit_frames--;
|
||||
if (!devc->limit_frames) {
|
||||
sr_dbg("Requested number of frames reached.");
|
||||
sr_dev_acquisition_stop(sdi);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((devc->limit_samples > 0 && devc->sent_samples >= devc->limit_samples)
|
||||
|| (limit_us > 0 && devc->spent_us >= limit_us)) {
|
||||
|
@ -577,11 +581,9 @@ 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)
|
||||
} else if (devc->limit_frames) {
|
||||
if (devc->sent_frame_samples == 0)
|
||||
std_session_send_frame_begin(sdi);
|
||||
#endif
|
||||
}
|
||||
|
||||
return G_SOURCE_CONTINUE;
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
/* 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
|
||||
#define SAMPLES_PER_FRAME 1000UL
|
||||
|
||||
/* Logic patterns we can generate. */
|
||||
enum logic_pattern_type {
|
||||
|
@ -94,6 +94,7 @@ struct dev_context {
|
|||
uint64_t cur_samplerate;
|
||||
uint64_t limit_samples;
|
||||
uint64_t limit_msec;
|
||||
uint64_t limit_frames;
|
||||
uint64_t sent_samples;
|
||||
uint64_t sent_frame_samples; /* Number of samples that were sent for current frame. */
|
||||
int64_t start_us;
|
||||
|
|
Loading…
Reference in New Issue