2 * This file is part of the sigrok project.
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
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.
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.
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/>.
20 #include "sigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
26 PyObject *srd_logic_iter(PyObject *self)
32 PyObject *srd_logic_iternext(PyObject *self)
34 PyObject *py_samplenum, *py_samples;
38 unsigned char probe_samples[SRD_MAX_NUM_PROBES];
40 logic = (srd_logic *) self;
41 if (logic->itercnt >= logic->inbuflen / logic->di->unitsize) {
42 /* End iteration loop. */
46 /* TODO: use number of probes defined in the PD, in the order the PD
47 * defined them -- not whatever came in from the driver.
49 /* Convert the bit-packed sample to an array of bytes, with only 0x01
50 * and 0x00 values, so the PD doesn't need to do any bitshifting.
52 memcpy(&sample, logic->inbuf + logic->itercnt * logic->di->unitsize,
54 for (i = 0; i < logic->di->num_probes; i++) {
55 probe_samples[i] = sample & 0x01;
59 /* TODO: samplenum should be in the inbuf feed, instead of time/duration.
62 /* Prepare the next samplenum/sample list in this iteration. */
63 py_samplenum = PyLong_FromUnsignedLongLong(logic->itercnt++);
64 PyList_SetItem(logic->sample, 0, py_samplenum);
65 py_samples = PyBytes_FromStringAndSize((const char *)probe_samples,
66 logic->di->num_probes);
67 PyList_SetItem(logic->sample, 1, py_samples);
68 Py_INCREF(logic->sample);
73 PyTypeObject srd_logic_type = {
74 PyVarObject_HEAD_INIT(NULL, 0)
75 .tp_name = "srd_logic",
76 .tp_basicsize = sizeof(srd_logic),
77 .tp_flags = Py_TPFLAGS_DEFAULT,
78 .tp_doc = "Sigrokdecode logic sample object",
79 .tp_iter = srd_logic_iter,
80 .tp_iternext = srd_logic_iternext,