]> sigrok.org Git - libsigrokdecode.git/commitdiff
Pass multiple samples to the protocol decoder and adapt transitioncounter.py to work...
authorKristoffer Sjöberg <redacted>
Sun, 13 Nov 2011 02:11:40 +0000 (03:11 +0100)
committerGareth McMullin <redacted>
Sun, 20 Nov 2011 03:31:47 +0000 (16:31 +1300)
decode.c
decoders/transitioncounter.py

index 5ff6415bdf6df8fcb7cae442c9c7b043a1a9b787..6ed7e8209c71918eb951bc5bd4d076d7258929df 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -342,8 +342,11 @@ int srd_run_decoder(struct srd_decoder *dec,
                             uint8_t **outbuf, uint64_t *outbuflen)
 {
        PyObject *py_mod, *py_func, *py_args, *py_value, *py_res;
                             uint8_t **outbuf, uint64_t *outbuflen)
 {
        PyObject *py_mod, *py_func, *py_args, *py_value, *py_res;
-       uint64_t inbuf_pos = 0;
        int r, ret;
        int r, ret;
+       
+       /* FIXME: Don't have a timebase available here. Make one up. */
+       static int _timehack = 0;
+       _timehack += inbuflen;
 
        /* TODO: Use #defines for the return codes. */
 
 
        /* TODO: Use #defines for the return codes. */
 
@@ -371,33 +374,31 @@ int srd_run_decoder(struct srd_decoder *dec,
                goto err_run_decref_func;
        }
 
                goto err_run_decref_func;
        }
 
-       while (inbuf_pos < inbuflen) {
-               /* Get the input buffer as Python "string" (byte array). */
-               /* TODO: int vs. uint64_t for 'inbuflen'? */
-
-               py_value = Py_BuildValue("{sisiss#}", 
-                                                 "time", inbuf_pos / _unitsize,
-                                                 "duration", 10,
-                                                 "data", &inbuf[inbuf_pos], _unitsize
-                                                 );
-               
-               /*
-                * IMPORTANT: PyTuple_SetItem() "steals" a reference to py_value!
-                * That means we are no longer responsible for Py_XDECREF()'ing it.
-                * It will automatically be free'd when the 'py_args' tuple is free'd.
-                */
-               if (PyTuple_SetItem(py_args, 0, py_value) != 0) { /* STEAL */
-                       ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
-                       Py_XDECREF(py_value); /* TODO: Ref. stolen upon error? */
-                       goto err_run_decref_args;
-               }
-               
-               if (!(py_res = PyObject_CallObject(py_func, py_args))) { /* NEWREF */
-                       ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
-                       goto err_run_decref_args;
-               }
-               inbuf_pos++;
+       /* Get the input buffer as Python "string" (byte array). */
+       /* TODO: int vs. uint64_t for 'inbuflen'? */
+
+       py_value = Py_BuildValue("{sisiss#}", 
+                                         "time", _timehack,
+                                         "duration", 10,
+                                         "data", inbuf, inbuflen / _unitsize
+                                         );
+       
+       /*
+        * IMPORTANT: PyTuple_SetItem() "steals" a reference to py_value!
+        * That means we are no longer responsible for Py_XDECREF()'ing it.
+        * It will automatically be free'd when the 'py_args' tuple is free'd.
+        */
+       if (PyTuple_SetItem(py_args, 0, py_value) != 0) { /* STEAL */
+               ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
+               Py_XDECREF(py_value); /* TODO: Ref. stolen upon error? */
+               goto err_run_decref_args;
        }
        }
+       
+       if (!(py_res = PyObject_CallObject(py_func, py_args))) { /* NEWREF */
+               ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
+               goto err_run_decref_args;
+       }
+
 
        ret = SRD_OK;
 
 
        ret = SRD_OK;
 
index 23b443e98a86969bf72661dff22019c4b0f9e678..996cf2e0003d487281f7a8b267999c317a0f5e4c 100644 (file)
@@ -36,7 +36,7 @@ def decode(sampledata):
        channels = 8    
 
        # FIXME: Get the data in the correct format in the first place.
        channels = 8    
 
        # FIXME: Get the data in the correct format in the first place.
-       s = ord(sampledata['data'])
+       inbuf = [ord(x) for x in sampledata['data']]
 
        if lastsample == None:
                oldbit = [0] * channels
 
        if lastsample == None:
                oldbit = [0] * channels
@@ -45,30 +45,31 @@ def decode(sampledata):
                falling = [0] * channels
 
                # Initial values.
                falling = [0] * channels
 
                # Initial values.
-               lastsample = s
+               lastsample = inbuf[0]
                for i in range(channels):
                        oldbit[i] = (lastsample & (1 << i)) >> i
                
        # TODO: Handle LAs with more/less than 8 channels.
                for i in range(channels):
                        oldbit[i] = (lastsample & (1 << i)) >> i
                
        # TODO: Handle LAs with more/less than 8 channels.
-       # Optimization: Skip identical bytes (no transitions).
-       if lastsample != s:
-               for i in range(channels):
-                       curbit = (s & (1 << i)) >> i
-                       # Optimization: Skip identical bits (no transitions).
-                       if oldbit[i] == curbit:
-                               continue
-                       elif (oldbit[i] == 0 and curbit == 1):
-                               rising[i] += 1
-                       elif (oldbit[i] == 1 and curbit == 0):
-                               falling[i] += 1
-                       oldbit[i] = curbit
+       for s in inbuf:
+               # Optimization: Skip identical bytes (no transitions).
+               if lastsample != s:
+                       for i in range(channels):
+                               curbit = (s & (1 << i)) >> i
+                               # Optimization: Skip identical bits (no transitions).
+                               if oldbit[i] == curbit:
+                                       continue
+                               elif (oldbit[i] == 0 and curbit == 1):
+                                       rising[i] += 1
+                               elif (oldbit[i] == 1 and curbit == 0):
+                                       falling[i] += 1
+                               oldbit[i] = curbit
 
 
-               # Total number of transitions is the sum of rising and falling edges.
-               for i in range(channels):
-                       transitions[i] = rising[i] + falling[i]
+                       # Total number of transitions is the sum of rising and falling edges.
+                       for i in range(channels):
+                               transitions[i] = rising[i] + falling[i]
                
                
-               lastsample = s
-               print(transitions)
+                       lastsample = s
+                       print(transitions)
 
        sigrok.put(sampledata)
 
 
        sigrok.put(sampledata)