]> sigrok.org Git - libsigrokdecode.git/commitdiff
Make the data unit size configurable
authorDaniel Elstner <redacted>
Thu, 20 Feb 2014 05:24:23 +0000 (06:24 +0100)
committerBert Vermeulen <redacted>
Mon, 24 Feb 2014 00:09:15 +0000 (01:09 +0100)
instance.c
libsigrokdecode.h
session.c
tests/runtc.c

index 594f144edcabe9dc44ec3a60265e3b5a257ecfa3..0a930bf184ca7a7c7ff6cfc499d2d74762ce81c6 100644 (file)
@@ -224,19 +224,22 @@ static gint compare_probe_id(const struct srd_probe *a, const char *probe_id)
  * @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.
  * @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.
+ * @param unit_size Number of bytes per sample in the data stream to be passed
+ *                  to the decoder. The highest probe index specified in the
+ *                  probe map must lie within a sample unit.
  *
  * @return SRD_OK upon success, a (negative) error code otherwise.
  *
  * @since 0.1.0
  */
 SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
  *
  * @return SRD_OK upon success, a (negative) error code otherwise.
  *
  * @since 0.1.0
  */
 SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
-               GHashTable *new_probes)
+               GHashTable *new_probes, int unit_size)
 {
        GVariant *probe_val;
        GList *l;
        GSList *sl;
        struct srd_probe *p;
 {
        GVariant *probe_val;
        GList *l;
        GSList *sl;
        struct srd_probe *p;
-       int *new_probemap, new_probenum, num_required_probes, num_probes, i;
+       int *new_probemap, new_probenum, num_required_probes, i;
        char *probe_id;
 
        srd_dbg("set probes called for instance %s with list of %d probes",
        char *probe_id;
 
        srd_dbg("set probes called for instance %s with list of %d probes",
@@ -267,7 +270,6 @@ SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
        for (i = 0; i < di->dec_num_probes; i++)
                new_probemap[i] = -1;
 
        for (i = 0; i < di->dec_num_probes; i++)
                new_probemap[i] = -1;
 
-       num_probes = 0;
        for (l = g_hash_table_get_keys(new_probes); l; l = l->next) {
                probe_id = l->data;
                probe_val = g_hash_table_lookup(new_probes, probe_id);
        for (l = g_hash_table_get_keys(new_probes); l; l = l->next) {
                probe_id = l->data;
                probe_val = g_hash_table_lookup(new_probes, probe_id);
@@ -279,6 +281,12 @@ SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
                        return SRD_ERR_ARG;
                }
                new_probenum = g_variant_get_int32(probe_val);
                        return SRD_ERR_ARG;
                }
                new_probenum = g_variant_get_int32(probe_val);
+               if (new_probenum >= 8 * unit_size) {
+                       srd_err("Probe index %d not within data unit (%d bit).",
+                               new_probenum, 8 * unit_size);
+                       g_free(new_probemap);
+                       return SRD_ERR_ARG;
+               }
                if (!(sl = g_slist_find_custom(di->decoder->probes, probe_id,
                                (GCompareFunc)compare_probe_id))) {
                        /* Fall back on optional probes. */
                if (!(sl = g_slist_find_custom(di->decoder->probes, probe_id,
                                (GCompareFunc)compare_probe_id))) {
                        /* Fall back on optional probes. */
@@ -294,9 +302,8 @@ SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
                new_probemap[p->order] = new_probenum;
                srd_dbg("Setting probe mapping: %s (index %d) = probe %d.",
                        p->id, p->order, new_probenum);
                new_probemap[p->order] = new_probenum;
                srd_dbg("Setting probe mapping: %s (index %d) = probe %d.",
                        p->id, p->order, new_probenum);
-               num_probes++;
        }
        }
-       di->data_unitsize = (num_probes + 7) / 8;
+       di->data_unitsize = unit_size;
 
        srd_dbg("Final probe map:");
        num_required_probes = g_slist_length(di->decoder->probes);
 
        srd_dbg("Final probe map:");
        num_required_probes = g_slist_length(di->decoder->probes);
index 1603582a0cc5f80e8c2ce32ad10a32a97743672e..fdf60526657c21bb280f6c5236f90944669942fa 100644 (file)
@@ -312,7 +312,7 @@ SRD_API int srd_decoder_unload_all(void);
 SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
                GHashTable *options);
 SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
 SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
                GHashTable *options);
 SRD_API int srd_inst_probe_set_all(struct srd_decoder_inst *di,
-               GHashTable *probes);
+               GHashTable *probes, int unit_size);
 SRD_API struct srd_decoder_inst *srd_inst_new(struct srd_session *sess,
                const char *id, GHashTable *options);
 SRD_API int srd_inst_stack(struct srd_session *sess,
 SRD_API struct srd_decoder_inst *srd_inst_new(struct srd_session *sess,
                const char *id, GHashTable *options);
 SRD_API int srd_inst_stack(struct srd_session *sess,
index c073c80e653cdac0ecfeea4fff8431a7b46d887a..8df71576600072802be025119984190e3c45798f 100644 (file)
--- a/session.c
+++ b/session.c
@@ -209,12 +209,13 @@ SRD_API int srd_session_metadata_set(struct srd_session *sess, int key,
 /**
  * Send a chunk of logic sample data to a running decoder session.
  *
 /**
  * Send a chunk of logic sample data to a running decoder session.
  *
- * The logic samples must be arranged in probe order, in the least
- * amount of space possible. If no probes were configured, the default
+ * If no probe map has been set up, the logic samples must be arranged
+ * in probe order, in the least amount of space possible. The default
  * probe set consists of all required probes + all optional probes.
  *
  * probe set consists of all required probes + all optional probes.
  *
- * The size of a sample in inbuf is the minimum number of bytes needed
- * to store the configured (or default) probes.
+ * The size of a sample in inbuf is the unit size passed to
+ * srd_inst_probe_set_all(). If no probe map has been configured, it is
+ * the minimum number of bytes needed to store the default probes.
  *
  * @param sess The session to use.
  * @param start_samplenum The sample number of the first sample in this chunk.
  *
  * @param sess The session to use.
  * @param start_samplenum The sample number of the first sample in this chunk.
index ab1f5e9ad1a99ec5199cb327bee2624c1ef709d5..b75e4142c67d079b19035be1b806d2d7501d4041 100644 (file)
@@ -319,6 +319,7 @@ static int run_testcase(char *infile, GSList *pdlist, struct output *op)
        GHashTable *probes, *opts;
        GSList *pdl, *l;
        int idx;
        GHashTable *probes, *opts;
        GSList *pdl, *l;
        int idx;
+       int max_probe;
        char **decoder_class;
 
        if (op->outfile) {
        char **decoder_class;
 
        if (op->outfile) {
@@ -372,13 +373,17 @@ static int run_testcase(char *infile, GSList *pdlist, struct output *op)
                if (pd->probes) {
                        probes = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
                                        (GDestroyNotify)g_variant_unref);
                if (pd->probes) {
                        probes = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
                                        (GDestroyNotify)g_variant_unref);
+                       max_probe = 0;
                        for (l = pd->probes; l; l = l->next) {
                                probe = l->data;
                        for (l = pd->probes; l; l = l->next) {
                                probe = l->data;
+                               if (probe->probe > max_probe)
+                                       max_probe = probe->probe;
                                gvar = g_variant_new_int32(probe->probe);
                                g_variant_ref_sink(gvar);
                                g_hash_table_insert(probes, probe->name, gvar);
                        }
                                gvar = g_variant_new_int32(probe->probe);
                                g_variant_ref_sink(gvar);
                                g_hash_table_insert(probes, probe->name, gvar);
                        }
-                       if (srd_inst_probe_set_all(di, probes) != SRD_OK)
+                       if (srd_inst_probe_set_all(di, probes,
+                                       (max_probe + 8) / 8) != SRD_OK)
                                return FALSE;
                        g_hash_table_destroy(probes);
                }
                                return FALSE;
                        g_hash_table_destroy(probes);
                }