]> sigrok.org Git - libsigrokdecode.git/blobdiff - controller.c
srd: uart: Fix regression.
[libsigrokdecode.git] / controller.c
index 5d19e7a6a142ced06b04349449480fbc0b25739d..995ddd7f13667302a2c7cc271829aafb2148d9cb 100644 (file)
@@ -330,9 +330,9 @@ static gint compare_probe_id(const struct srd_probe *a, const char *probe_id)
  * it overwrites any probes that were already defined (if any).
  *
  * @param di Decoder instance.
- * @param probes A GHashTable of probes to set. Key is probe name, value is
- *               the probe number. Samples passed to this instance will be
- *               arranged in this order.
+ * @param new_probes A GHashTable of probes to set. Key is probe name, value is
+ *                   the probe number. Samples passed to this instance will be
+ *                   arranged in this order.
  *
  * @return SRD_OK upon success, a (negative) error code otherwise.
  */
@@ -344,6 +344,7 @@ SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
        struct srd_probe *p;
        int *new_probemap, new_probenum;
        char *probe_id, *probenum_str;
+       int i, num_required_probes;
 
        srd_dbg("set probes called for instance %s with list of %d probes",
                di->inst_id, g_hash_table_size(new_probes));
@@ -366,6 +367,13 @@ SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
                return SRD_ERR_MALLOC;
        }
 
+       /*
+        * For now, map all indexes to probe -1 (can be overridden later).
+        * This -1 is interpreted as an unspecified probe later.
+        */
+       for (i = 0; i < di->dec_num_probes; i++)
+               new_probemap[i] = -1;
+
        for (l = g_hash_table_get_keys(new_probes); l; l = l->next) {
                probe_id = l->data;
                probenum_str = g_hash_table_lookup(new_probes, probe_id);
@@ -390,9 +398,17 @@ SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
                }
                p = sl->data;
                new_probemap[p->order] = new_probenum;
-               srd_dbg("setting probe mapping for %d = probe %d", p->order,
-                       new_probenum);
+               srd_dbg("Setting probe mapping: %s (index %d) = probe %d.",
+                       p->id, p->order, new_probenum);
        }
+
+       srd_dbg("Final probe map:");
+       num_required_probes = g_slist_length(di->decoder->probes);
+       for (i = 0; i < di->dec_num_probes; i++) {
+               srd_dbg(" - index %d = probe %d (%s)", i, new_probemap[i],
+                       (i < num_required_probes) ? "required" : "optional");
+       }
+
        g_free(di->dec_probemap);
        di->dec_probemap = new_probemap;
 
@@ -402,7 +418,7 @@ SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
 /**
  * Create a new protocol decoder instance.
  *
- * @param id Decoder 'id' field.
+ * @param decoder_id Decoder 'id' field.
  * @param options GHashtable of options which override the defaults set in
  *                the decoder class.
  *
@@ -735,7 +751,7 @@ SRD_API int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
                di->data_num_probes = num_probes;
                di->data_unitsize = unitsize;
                di->data_samplerate = samplerate;
-               if ((ret = srd_inst_start(di, args) != SRD_OK))
+               if ((ret = srd_inst_start(di, args)) != SRD_OK)
                        break;
        }
 
@@ -749,7 +765,7 @@ SRD_API int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
  *
  * @param start_samplenum The sample number of the first sample in this chunk.
  * @param inbuf Pointer to sample data.
- * @param inbuf Length in bytes of the buffer.
+ * @param inbuflen Length in bytes of the buffer.
  *
  * @return SRD_OK upon success, a (negative) error code otherwise.
  */