]> sigrok.org Git - libsigrok.git/commitdiff
demo: Skip generating data when all channels in a group are disabled
authorGerhard Sittig <redacted>
Sat, 17 Jun 2017 18:59:18 +0000 (20:59 +0200)
committerUwe Hermann <redacted>
Fri, 23 Jun 2017 17:33:24 +0000 (19:33 +0200)
The generator logic determines how many samples per group (analog and
logic) need to get produced, then keeps iterating until each group has
reached the specified count. Different groups can generate different
numbers of samples per iteration, they have their own stride.

It's essential to check whether all channels in a group are disabled, to
then completely skip the respective half of the generation loop. Without
this check, the group would be expected to generate data but it won't,
which results in an endless loop. This was observed with analog channels.

There was another issue with logic channels. Unexpected logic data was
seen in the output although neither logic channel was selected.

This commit fixes bug #923.

src/hardware/demo/api.c
src/hardware/demo/protocol.c
src/hardware/demo/protocol.h

index 645ef5f2317744a3f019cb033528c5a9306266fe..92b59fe3a32f07751111e5135b82c408c3fc3c3d 100644 (file)
@@ -457,6 +457,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
+       GSList *l;
+       struct sr_channel *ch;
        GHashTableIter iter;
        void *value;
 
@@ -466,6 +468,22 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        devc = sdi->priv;
        devc->sent_samples = 0;
 
+       devc->enabled_logic_channels = 0;
+       devc->enabled_analog_channels = 0;
+       for (l = sdi->channels; l; l = l->next) {
+               ch = l->data;
+               if (!ch->enabled)
+                       continue;
+               if (ch->type == SR_CHANNEL_ANALOG) {
+                       devc->enabled_analog_channels++;
+                       continue;
+               }
+               if (ch->type == SR_CHANNEL_LOGIC) {
+                       devc->enabled_logic_channels++;
+                       continue;
+               }
+       }
+
        g_hash_table_iter_init(&iter, devc->ch_ag);
        while (g_hash_table_iter_next(&iter, NULL, &value))
                demo_generate_analog_pattern(value, devc->cur_samplerate);
index 9c4ada3b66fdc7bc1283476cc062123c0e43071f..1c1ec6074617615d52671d3417970e9402104936 100644 (file)
@@ -448,7 +448,11 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data)
        todo_us = samples_todo * G_USEC_PER_SEC / devc->cur_samplerate;
 
        logic_done  = devc->num_logic_channels  > 0 ? 0 : samples_todo;
+       if (!devc->enabled_logic_channels)
+               logic_done = samples_todo;
        analog_done = devc->num_analog_channels > 0 ? 0 : samples_todo;
+       if (!devc->enabled_analog_channels)
+               analog_done = samples_todo;
 
        while (logic_done < samples_todo || analog_done < samples_todo) {
                /* Logic */
index 8f8868fab07eca45535e57d1f455f1699500e6d3..79e5d886a877149964b8c27133c3c5932b968168 100644 (file)
@@ -54,6 +54,8 @@ struct dev_context {
        GHashTable *ch_ag;
        gboolean avg; /* True if averaging is enabled */
        uint64_t avg_samples;
+       size_t enabled_logic_channels;
+       size_t enabled_analog_channels;
 };
 
 /* Logic patterns we can generate. */