diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2012-05-10 09:34:13 +0200 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2012-05-10 09:34:13 +0200 |
commit | dd93276bf6b7537b65cab270f66666bf23fbc585 (patch) | |
tree | d0aa8d6b59fcb742e07d293833bac3e3fd822320 /controller.c | |
parent | 29590b14fc508a0b951ea0b87e98f7741808bab0 (diff) | |
download | libsigrokdecode-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 'controller.c')
-rw-r--r-- | controller.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/controller.c b/controller.c index 0d914c9..995ddd7 100644 --- a/controller.c +++ b/controller.c @@ -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; |