summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controller.c20
-rw-r--r--decoder.c15
-rw-r--r--type_logic.c17
3 files changed, 49 insertions, 3 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;
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;
diff --git a/type_logic.c b/type_logic.c
index b284ebf..098e34d 100644
--- a/type_logic.c
+++ b/type_logic.c
@@ -45,11 +45,26 @@ static PyObject *srd_logic_iternext(PyObject *self)
* Convert the bit-packed sample to an array of bytes, with only 0x01
* and 0x00 values, so the PD doesn't need to do any bitshifting.
*/
+
+ /* Get probe bits into the 'sample' variable. */
memcpy(&sample,
logic->inbuf + logic->itercnt * logic->di->data_unitsize,
logic->di->data_unitsize);
- for (i = 0; i < logic->di->dec_num_probes; i++)
+
+ /* All probe values (required + optional) are pre-set to 42. */
+ memset(probe_samples, 42, logic->di->dec_num_probes);
+ /* TODO: None or -1 in Python would be better. */
+
+ /*
+ * Set probe values of specified/used probes to their resp. values.
+ * Unused probe values (those not specified by the user) remain at 42.
+ */
+ for (i = 0; i < logic->di->dec_num_probes; i++) {
+ /* A probemap value of -1 means "unused optional probe". */
+ if (logic->di->dec_probemap[i] == -1)
+ continue;
probe_samples[i] = sample & (1 << logic->di->dec_probemap[i]) ? 1 : 0;
+ }
/* Prepare the next samplenum/sample list in this iteration. */
py_samplenum =