summaryrefslogtreecommitdiff
path: root/decoder.c
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2012-05-10 09:34:13 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2012-05-10 09:34:13 +0200
commitdd93276bf6b7537b65cab270f66666bf23fbc585 (patch)
treed0aa8d6b59fcb742e07d293833bac3e3fd822320 /decoder.c
parent29590b14fc508a0b951ea0b87e98f7741808bab0 (diff)
downloadlibsigrokdecode-dd93276bf6b7537b65cab270f66666bf23fbc585.tar.gz
libsigrokdecode-dd93276bf6b7537b65cab270f66666bf23fbc585.zip
srd: Support for one or more optional probes.
In the protocol decoder you always get all required probes, then _all_ optional probes in the list of probes in the decode() call. Example: (r1, r2, r3, o1, o2, o3, o4) = pins In this case r1-r3 are required probes, o1-o4 are optional probes. However, the value of valid/used/specified probes will be 0 or 1, whereas the value of probes that were not specified/assigned by the user will be (at the moment) 42. The PD can check for a valid probe like this: if p in (0, 1): ... Or check for an invalid probe: if (p > 1): ... The value of 42 could change to be -1 or None later.
Diffstat (limited to 'decoder.c')
-rw-r--r--decoder.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/decoder.c b/decoder.c
index 4cf4197..6dfeeca 100644
--- a/decoder.c
+++ b/decoder.c
@@ -134,6 +134,8 @@ SRD_API int srd_decoder_load(const char *module_name)
struct srd_decoder *d;
int alen, ret, i;
char **ann;
+ struct srd_probe *p;
+ GSList *l;
srd_dbg("Loading protocol decoder '%s'.", module_name);
@@ -222,6 +224,19 @@ SRD_API int srd_decoder_load(const char *module_name)
if (get_probes(d, "optional_probes", &d->opt_probes) != SRD_OK)
goto err_out;
+ /*
+ * Fix order numbers for the optional probes.
+ *
+ * Example:
+ * Required probes: r1, r2, r3. Optional: o1, o2, o3, o4.
+ * 'order' fields in the d->probes list = 0, 1, 2.
+ * 'order' fields in the d->opt_probes list = 3, 4, 5, 6.
+ */
+ for (l = d->opt_probes; l; l = l->next) {
+ p = l->data;
+ p->order += g_slist_length(d->probes);
+ }
+
/* Store required fields in newly allocated strings. */
if (py_attr_as_str(d->py_dec, "id", &(d->id)) != SRD_OK)
goto err_out;