From dd93276bf6b7537b65cab270f66666bf23fbc585 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Thu, 10 May 2012 09:34:13 +0200 Subject: 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. --- decoder.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'decoder.c') 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; -- cgit v1.2.3-70-g09d2