]>
Commit | Line | Data |
---|---|---|
bc5f5a43 | 1 | /* |
50bd5d25 | 2 | * This file is part of the libsigrokdecode project. |
bc5f5a43 BV |
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 | ||
c1f86f02 | 20 | #include "libsigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */ |
bc5f5a43 BV |
21 | #include "config.h" |
22 | #include <inttypes.h> | |
23 | #include <string.h> | |
24 | ||
55c3c5f4 | 25 | static PyObject *srd_logic_iter(PyObject *self) |
bc5f5a43 | 26 | { |
bc5f5a43 BV |
27 | return self; |
28 | } | |
29 | ||
55c3c5f4 | 30 | static PyObject *srd_logic_iternext(PyObject *self) |
bc5f5a43 | 31 | { |
c9bfccc6 | 32 | int i; |
bc5f5a43 BV |
33 | PyObject *py_samplenum, *py_samples; |
34 | srd_logic *logic; | |
35 | uint64_t sample; | |
63b1026d | 36 | uint8_t probe_samples[SRD_MAX_NUM_PROBES + 1]; |
bc5f5a43 | 37 | |
c9bfccc6 | 38 | logic = (srd_logic *)self; |
f38ec285 | 39 | if (logic->itercnt >= logic->inbuflen / logic->di->data_unitsize) { |
bc5f5a43 BV |
40 | /* End iteration loop. */ |
41 | return NULL; | |
42 | } | |
43 | ||
c9bfccc6 UH |
44 | /* |
45 | * Convert the bit-packed sample to an array of bytes, with only 0x01 | |
bc5f5a43 BV |
46 | * and 0x00 values, so the PD doesn't need to do any bitshifting. |
47 | */ | |
38ff5046 UH |
48 | |
49 | /* Get probe bits into the 'sample' variable. */ | |
c9bfccc6 UH |
50 | memcpy(&sample, |
51 | logic->inbuf + logic->itercnt * logic->di->data_unitsize, | |
52 | logic->di->data_unitsize); | |
38ff5046 UH |
53 | |
54 | /* All probe values (required + optional) are pre-set to 42. */ | |
55 | memset(probe_samples, 42, logic->di->dec_num_probes); | |
56 | /* TODO: None or -1 in Python would be better. */ | |
57 | ||
58 | /* | |
59 | * Set probe values of specified/used probes to their resp. values. | |
60 | * Unused probe values (those not specified by the user) remain at 42. | |
61 | */ | |
62 | for (i = 0; i < logic->di->dec_num_probes; i++) { | |
63 | /* A probemap value of -1 means "unused optional probe". */ | |
64 | if (logic->di->dec_probemap[i] == -1) | |
65 | continue; | |
582c8473 | 66 | probe_samples[i] = sample & (1 << logic->di->dec_probemap[i]) ? 1 : 0; |
38ff5046 | 67 | } |
bc5f5a43 | 68 | |
bc5f5a43 | 69 | /* Prepare the next samplenum/sample list in this iteration. */ |
c9bfccc6 UH |
70 | py_samplenum = |
71 | PyLong_FromUnsignedLongLong(logic->start_samplenum + | |
72 | logic->itercnt); | |
bc5f5a43 BV |
73 | PyList_SetItem(logic->sample, 0, py_samplenum); |
74 | py_samples = PyBytes_FromStringAndSize((const char *)probe_samples, | |
c9bfccc6 | 75 | logic->di->dec_num_probes); |
bc5f5a43 BV |
76 | PyList_SetItem(logic->sample, 1, py_samples); |
77 | Py_INCREF(logic->sample); | |
86528298 | 78 | logic->itercnt++; |
bc5f5a43 BV |
79 | |
80 | return logic->sample; | |
81 | } | |
82 | ||
57790bc8 | 83 | /** @cond PRIVATE */ |
55c3c5f4 | 84 | SRD_PRIV PyTypeObject srd_logic_type = { |
bc5f5a43 BV |
85 | PyVarObject_HEAD_INIT(NULL, 0) |
86 | .tp_name = "srd_logic", | |
87 | .tp_basicsize = sizeof(srd_logic), | |
88 | .tp_flags = Py_TPFLAGS_DEFAULT, | |
89 | .tp_doc = "Sigrokdecode logic sample object", | |
90 | .tp_iter = srd_logic_iter, | |
91 | .tp_iternext = srd_logic_iternext, | |
92 | }; | |
57790bc8 | 93 | /** @endcond */ |