]>
Commit | Line | Data |
---|---|---|
bc5f5a43 BV |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Bert Vermeulen <bert@biot.com> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include "sigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */ | |
21 | #include "config.h" | |
22 | #include <inttypes.h> | |
23 | #include <string.h> | |
24 | ||
25 | ||
26 | PyObject *srd_logic_iter(PyObject *self) | |
27 | { | |
28 | ||
29 | return self; | |
30 | } | |
31 | ||
32 | PyObject *srd_logic_iternext(PyObject *self) | |
33 | { | |
34 | PyObject *py_samplenum, *py_samples; | |
35 | srd_logic *logic; | |
36 | uint64_t sample; | |
37 | int i; | |
38 | unsigned char probe_samples[SRD_MAX_NUM_PROBES]; | |
39 | ||
40 | logic = (srd_logic *) self; | |
f38ec285 | 41 | if (logic->itercnt >= logic->inbuflen / logic->di->data_unitsize) { |
bc5f5a43 BV |
42 | /* End iteration loop. */ |
43 | return NULL; | |
44 | } | |
45 | ||
bc5f5a43 BV |
46 | /* Convert the bit-packed sample to an array of bytes, with only 0x01 |
47 | * and 0x00 values, so the PD doesn't need to do any bitshifting. | |
48 | */ | |
f38ec285 BV |
49 | memcpy(&sample, logic->inbuf + logic->itercnt * logic->di->data_unitsize, |
50 | logic->di->data_unitsize); | |
51 | for (i = 0; i < logic->di->dec_num_probes; i++) { | |
52 | probe_samples[logic->di->dec_probemap[i]] = sample & 0x01; | |
bc5f5a43 BV |
53 | sample >>= 1; |
54 | } | |
55 | ||
bc5f5a43 | 56 | /* Prepare the next samplenum/sample list in this iteration. */ |
86528298 | 57 | py_samplenum = PyLong_FromUnsignedLongLong(logic->start_samplenum + logic->itercnt); |
bc5f5a43 BV |
58 | PyList_SetItem(logic->sample, 0, py_samplenum); |
59 | py_samples = PyBytes_FromStringAndSize((const char *)probe_samples, | |
f38ec285 | 60 | logic->di->dec_num_probes); |
bc5f5a43 BV |
61 | PyList_SetItem(logic->sample, 1, py_samples); |
62 | Py_INCREF(logic->sample); | |
86528298 | 63 | logic->itercnt++; |
bc5f5a43 BV |
64 | |
65 | return logic->sample; | |
66 | } | |
67 | ||
68 | PyTypeObject srd_logic_type = { | |
69 | PyVarObject_HEAD_INIT(NULL, 0) | |
70 | .tp_name = "srd_logic", | |
71 | .tp_basicsize = sizeof(srd_logic), | |
72 | .tp_flags = Py_TPFLAGS_DEFAULT, | |
73 | .tp_doc = "Sigrokdecode logic sample object", | |
74 | .tp_iter = srd_logic_iter, | |
75 | .tp_iternext = srd_logic_iternext, | |
76 | }; | |
77 |