]> sigrok.org Git - libsigrokdecode.git/commitdiff
srd: PDs now get a logic feed with sample numbers, not time/duration
authorBert Vermeulen <redacted>
Sun, 15 Jan 2012 22:20:39 +0000 (23:20 +0100)
committerBert Vermeulen <redacted>
Sun, 15 Jan 2012 22:25:58 +0000 (23:25 +0100)
controller.c
sigrokdecode.h
type_decoder.c
type_logic.c

index 963345c637c1b09ce550ecf623f1778ed48faf3c..9a663ff8d01b125b048347048a8d730dcea03da9 100644 (file)
@@ -283,11 +283,12 @@ int srd_instance_start(struct srd_decoder_instance *di, PyObject *args)
  *
  * @return SRD_OK upon success, a (negative) error code otherwise.
  */
-int srd_instance_decode(uint64_t timeoffset, uint64_t duration,
+int srd_instance_decode(uint64_t start_samplenum,
                struct srd_decoder_instance *di, uint8_t *inbuf, uint64_t inbuflen)
 {
        PyObject *py_instance, *py_res;
        srd_logic *logic;
+       uint64_t end_samplenum;
 
        /* Return an error upon unusable input. */
        if (di == NULL)
@@ -304,14 +305,16 @@ int srd_instance_decode(uint64_t timeoffset, uint64_t duration,
        logic = PyObject_New(srd_logic, &srd_logic_type);
        Py_INCREF(logic);
        logic->di = di;
+       logic->start_samplenum = start_samplenum;
        logic->itercnt = 0;
        logic->inbuf = inbuf;
        logic->inbuflen = inbuflen;
        logic->sample = PyList_New(2);
        Py_INCREF(logic->sample);
 
+       end_samplenum = start_samplenum + inbuflen / di->unitsize;
        if (!(py_res = PyObject_CallMethod(py_instance, "decode",
-                       "KKO", timeoffset, duration, logic))) {
+                       "KKO", logic->start_samplenum, end_samplenum, logic))) {
                if (PyErr_Occurred())
                        PyErr_Print(); /* Returns void. */
 
@@ -360,14 +363,13 @@ int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
 }
 
 /* Feed logic samples to decoder session. */
-int srd_session_feed(uint64_t timeoffset, uint64_t duration, uint8_t *inbuf,
-               uint64_t inbuflen)
+int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf, uint64_t inbuflen)
 {
        GSList *d;
        int ret;
 
        for (d = di_list; d; d = d->next) {
-               if ((ret = srd_instance_decode(timeoffset, duration, d->data, inbuf,
+               if ((ret = srd_instance_decode(start_samplenum, d->data, inbuf,
                                inbuflen)) != SRD_OK)
                        return ret;
        }
index 863608b90e0dd742d773b928afc1f11465ce2fa2..1d8a79b78a760a1627368729090b9574d3e9ea88 100644 (file)
@@ -151,6 +151,7 @@ typedef struct {
 typedef struct {
        PyObject_HEAD
        struct srd_decoder_instance *di;
+       uint64_t start_samplenum;
        unsigned int itercnt;
        uint8_t *inbuf;
        uint64_t inbuflen;
@@ -170,13 +171,11 @@ int srd_instance_set_probe(struct srd_decoder_instance *di,
                                const char *probename, int num);
 struct srd_decoder_instance *srd_instance_find(char *instance_id);
 int srd_instance_start(struct srd_decoder_instance *di, PyObject *args);
-int srd_instance_decode(uint64_t timeoffset, uint64_t duration,
+int srd_instance_decode(uint64_t start_samplenum,
                struct srd_decoder_instance *dec, uint8_t *inbuf, uint64_t inbuflen);
 int srd_session_start(int num_probes, int unitsize, uint64_t samplerate);
-int srd_session_feed(uint64_t timeoffset, uint64_t duration, uint8_t *inbuf,
-               uint64_t inbuflen);
-int pd_add(struct srd_decoder_instance *di, int output_type,
-               char *output_id);
+int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf, uint64_t inbuflen);
+int pd_add(struct srd_decoder_instance *di, int output_type, char *output_id);
 struct srd_decoder_instance *get_di_by_decobject(void *decobject);
 int srd_register_callback(int output_type, void *cb);
 void *srd_find_callback(int output_type);
index 34b414e6c3b31a96644529245ea504d9dd665227..e1e67967c6b79c6b6de8feb06333342a7ef88920 100644 (file)
@@ -177,7 +177,7 @@ static PyObject *Decoder_add(PyObject *self, PyObject *args)
 
 static PyMethodDef Decoder_methods[] = {
        {"put", Decoder_put, METH_VARARGS,
-        "Accepts a dictionary with the following keys: time, duration, data"},
+        "Accepts a dictionary with the following keys: startsample, endsample, data"},
        {"add", Decoder_add, METH_VARARGS, "Create a new output stream"},
        {NULL, NULL, 0, NULL}
 };
index 2f7923425b08bae786db5e106bdc153864ae1584..851a42ead51070334db360985b698962165df6be 100644 (file)
@@ -56,16 +56,14 @@ PyObject *srd_logic_iternext(PyObject *self)
                sample >>= 1;
        }
 
-       /* TODO: samplenum should be in the inbuf feed, instead of time/duration.
-        * fake it for now...
-        */
        /* Prepare the next samplenum/sample list in this iteration. */
-       py_samplenum = PyLong_FromUnsignedLongLong(logic->itercnt++);
+       py_samplenum = PyLong_FromUnsignedLongLong(logic->start_samplenum + logic->itercnt);
        PyList_SetItem(logic->sample, 0, py_samplenum);
        py_samples = PyBytes_FromStringAndSize((const char *)probe_samples,
                        logic->di->num_probes);
        PyList_SetItem(logic->sample, 1, py_samples);
        Py_INCREF(logic->sample);
+       logic->itercnt++;
 
        return logic->sample;
 }