diff options
author | Bert Vermeulen <bert@biot.com> | 2012-01-08 03:20:12 +0100 |
---|---|---|
committer | Bert Vermeulen <bert@biot.com> | 2012-01-08 03:20:12 +0100 |
commit | 983cb0f5b49167328864d0878148a7407becd1c0 (patch) | |
tree | 543592c8d5c1286fcd2ded8c5348a04a7aadd509 /module_sigrokdecode.c | |
parent | 61132abd40fb2a69beb1873fa079f1a93a4d6534 (diff) | |
download | libsigrokdecode-983cb0f5b49167328864d0878148a7407becd1c0.tar.gz libsigrokdecode-983cb0f5b49167328864d0878148a7407becd1c0.zip |
pass PD output to the calling frontend, simple annotation viewer in CLI.
Diffstat (limited to 'module_sigrokdecode.c')
-rw-r--r-- | module_sigrokdecode.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/module_sigrokdecode.c b/module_sigrokdecode.c index 9c8c72e..e92c9e7 100644 --- a/module_sigrokdecode.c +++ b/module_sigrokdecode.c @@ -95,14 +95,15 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) PyObject *data; struct srd_decoder_instance *di; struct srd_pd_output *pdo; - uint64_t timeoffset, duration; - int output_id, annotation_format, i; - char **annotation, **ann_info; + struct srd_protocol_data *pdata; + uint64_t start_sample, end_sample; + int output_id; + void (*cb)(); if (!(di = get_di_by_decobject(self))) return NULL; - if (!PyArg_ParseTuple(args, "KKiO", &timeoffset, &duration, &output_id, &data)) + if (!PyArg_ParseTuple(args, "KKiO", &start_sample, &end_sample, &output_id, &data)) return NULL; if (!(l = g_slist_nth(di->pd_output, output_id))) { @@ -114,31 +115,35 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) switch (pdo->output_type) { case SRD_OUTPUT_ANNOTATION: - if (convert_pyobj(di, data, &annotation_format, &annotation) != SRD_OK) - return NULL; - - /* TODO: SRD_OUTPUT_ANNOTATION should go back up to the caller */ - ann_info = g_slist_nth_data(pdo->decoder->annotation, annotation_format); - printf("annotation format %d (%s): ", annotation_format, ann_info[0]); - for (i = 0; annotation[i]; i++) - printf("\"%s\" ", annotation[i]); - printf("\n"); - break; - case SRD_OUTPUT_PROTOCOL: - - /* TODO: SRD_OUTPUT_PROTOCOL should go up the PD stack. */ - printf("%s protocol data: ", pdo->protocol_id); - PyObject_Print(data, stdout, Py_PRINT_RAW); - puts(""); + case SRD_OUTPUT_BINARY: break; - default: srd_err("Protocol decoder %s submitted invalid output type %d", di->decoder->name, pdo->output_type); + return NULL; break; } + if ((cb = srd_find_callback(pdo->output_type))) { + /* Something registered an interest in this output type. */ + if (!(pdata = g_try_malloc0(sizeof(struct srd_protocol_data)))) + return NULL; + pdata->start_sample = start_sample; + pdata->end_sample = end_sample; + pdata->pdo = pdo; + if (pdo->output_type == SRD_OUTPUT_ANNOTATION) { + /* annotations need converting from PyObject */ + if (convert_pyobj(di, data, &pdata->annotation_format, + (char ***)&pdata->data) != SRD_OK) + return NULL; + } else { + /* annotation_format is unused, data is an opaque blob. */ + pdata->data = data; + } + cb(pdata); + } + Py_RETURN_NONE; } |