Skip to content

Commit 5a806e4

Browse files
Add more decoders
1 parent 95e1796 commit 5a806e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+3012
-1069
lines changed

libsigrokdecode4DSL/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/libtool
3030
/version.h
3131
__pycache__/
32+
*.pyc
3233
stamp-h?
3334

3435
# Files generated by the testsuite

libsigrokdecode4DSL/Makefile.am

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ AM_LIBTOOLFLAGS = --silent
2323
GNUMAKEFLAGS = --no-print-directory
2424

2525
DECODERS_DIR = $(pkgdatadir)/decoders
26+
# Do not hard-code the decoders location on Windows.
27+
if WIN32
28+
AM_CPPFLAGS =
29+
else
2630
AM_CPPFLAGS = -DDECODERS_DIR='"$(DECODERS_DIR)"'
31+
endif
2732

2833
# The tests CFLAGS are a superset of the libsigrokdecode CFLAGS.
2934
AM_CFLAGS = $(SRD_EXTRA_CFLAGS) $(SRD_WFLAGS) $(TESTS_CFLAGS)
@@ -70,7 +75,7 @@ tests_main_SOURCES = \
7075
tests/inst.c \
7176
tests/session.c
7277

73-
tests_main_CPPFLAGS = -DDECODERS_DIR='"$(abs_top_srcdir)/decoders"'
78+
tests_main_CPPFLAGS = -DDECODERS_TESTDIR='"$(abs_top_srcdir)/decoders"'
7479
tests_main_LDADD = libsigrokdecode4DSL.la $(SRD_EXTRA_LIBS) $(TESTS_LIBS)
7580

7681
MAINTAINERCLEANFILES = ChangeLog

libsigrokdecode4DSL/configure.ac

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
AC_PREREQ([2.63])
2222

2323
# libsigrokdecode package version number (NOT the same as shared lib version!).
24-
AC_INIT([libsigrokdecode4DSL], [0.4.0],
24+
AC_INIT([libsigrokdecode4DSL], [0.5.0],
2525
[[email protected]], [libsigrokdecode4DSL],
2626
[http://www.dreamsourcelab.com])
2727
AC_CONFIG_MACRO_DIR([m4])
@@ -62,7 +62,10 @@ SR_PKG_VERSION_SET([SRD_PACKAGE_VERSION], [AC_PACKAGE_VERSION])
6262
# Carefully read the libtool docs before updating these numbers!
6363
# The algorithm for determining which number to change (and how) is nontrivial!
6464
# http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
65-
SR_LIB_VERSION_SET([SRD_LIB_VERSION], [2:0:0])
65+
# Format: current:revision:age.
66+
SR_LIB_VERSION_SET([SRD_LIB_VERSION], [3:0:0])
67+
68+
AM_CONDITIONAL([WIN32], [test -z "${host_os##mingw*}" || test -z "${host_os##cygwin*}"])
6669

6770
############################
6871
## Package dependencies ##
@@ -83,14 +86,14 @@ SR_PKG_CHECK_SUMMARY([srd_pkglibs_summary])
8386

8487
# Python 3 is always needed.
8588
SR_PKG_CHECK([python3], [SRD_PKGLIBS],
86-
[python3 >= 3.2], [python-3.4 >= 3.4], [python-3.3 >= 3.3], [python-3.2 >= 3.2])
89+
[python3 >= 3.2], [python-3.5 >= 3.5], [python-3.4 >= 3.4], [python-3.3 >= 3.3], [python-3.2 >= 3.2])
8790
AS_IF([test "x$sr_have_python3" = xno],
8891
[AC_MSG_ERROR([Cannot find Python 3 development headers.])])
8992

9093
# We also need to find the name of the python3 executable (for 'make install').
9194
# Some OSes call this python3, some call it python3.2, etc. etc.
9295
AC_ARG_VAR([PYTHON3], [Python 3 interpreter])
93-
AC_CHECK_PROGS([PYTHON3], [python3.4 python3.3 python3.2 python3])
96+
AC_CHECK_PROGS([PYTHON3], [python3.5 python3.4 python3.3 python3.2 python3])
9497
AS_IF([test "x$PYTHON3" = x],
9598
[AC_MSG_ERROR([Cannot find Python 3 interpreter.])])
9699

@@ -128,7 +131,7 @@ AC_SUBST([SRD_PKGLIBS])
128131

129132
# Retrieve the compile and link flags for all modules combined.
130133
# Also, bail out at this point if any module dependency is not met.
131-
PKG_CHECK_MODULES([LIBSIGROKDECODE], [glib-2.0 >= 2.24.0 $SRD_PKGLIBS])
134+
PKG_CHECK_MODULES([LIBSIGROKDECODE], [glib-2.0 >= 2.28.0 $SRD_PKGLIBS])
132135
PKG_CHECK_MODULES([TESTS], [$SRD_PKGLIBS_TESTS glib-2.0 $SRD_PKGLIBS])
133136

134137
srd_glib_version=`$PKG_CONFIG --modversion glib-2.0 2>&AS_MESSAGE_LOG_FD`
@@ -154,7 +157,7 @@ Compile configuration:
154157
- C compiler warnings............. $SRD_WFLAGS
155158

156159
Detected libraries (required):
157-
- glib-2.0 >= 2.24.0.............. $srd_glib_version
160+
- glib-2.0 >= 2.28.0.............. $srd_glib_version
158161
$srd_pkglibs_summary
159162
Detected libraries (optional):
160163
$srd_pkglibs_opt_summary

libsigrokdecode4DSL/decoder.c

+46-46
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,21 @@ static void decoder_free(struct srd_decoder *dec)
156156
if (!dec)
157157
return;
158158

159-
Py_XDECREF(dec->py_dec);
160-
Py_XDECREF(dec->py_mod);
161-
162-
g_slist_free_full(dec->options, &decoder_option_free);
163-
g_slist_free_full(dec->binary, (GDestroyNotify)&g_strfreev);
164-
g_slist_free_full(dec->annotation_rows, &annotation_row_free);
165-
g_slist_free_full(dec->annotations, (GDestroyNotify)&g_strfreev);
166-
g_slist_free_full(dec->opt_channels, &channel_free);
167-
g_slist_free_full(dec->channels, &channel_free);
168-
169-
g_free(dec->license);
170-
g_free(dec->desc);
171-
g_free(dec->longname);
172-
g_free(dec->name);
173-
g_free(dec->id);
159+
Py_XDECREF(dec->py_dec);
160+
Py_XDECREF(dec->py_mod);
161+
162+
g_slist_free_full(dec->options, &decoder_option_free);
163+
g_slist_free_full(dec->binary, (GDestroyNotify)&g_strfreev);
164+
g_slist_free_full(dec->annotation_rows, &annotation_row_free);
165+
g_slist_free_full(dec->annotations, (GDestroyNotify)&g_strfreev);
166+
g_slist_free_full(dec->opt_channels, &channel_free);
167+
g_slist_free_full(dec->channels, &channel_free);
168+
169+
g_free(dec->license);
170+
g_free(dec->desc);
171+
g_free(dec->longname);
172+
g_free(dec->name);
173+
g_free(dec->id);
174174

175175
g_free(dec);
176176
}
@@ -215,14 +215,14 @@ static int get_channels(const struct srd_decoder *d, const char *attr,
215215

216216
if (py_dictitem_as_str(py_entry, "id", &pdch->id) != SRD_OK)
217217
goto err_out;
218-
if (py_dictitem_as_str(py_entry, "name", &pdch->name) != SRD_OK)
218+
if (py_dictitem_as_str(py_entry, "name", &pdch->name) != SRD_OK)
219219
goto err_out;
220220
if (py_dictitem_as_str(py_entry, "desc", &pdch->desc) != SRD_OK)
221221
goto err_out;
222222

223-
pdch->type = py_dictitem_to_int(py_entry, "type");
224-
if (pdch->type < 0)
225-
pdch->type = SRD_CHANNEL_COMMON;
223+
pdch->type = py_dictitem_to_int(py_entry, "type");
224+
if (pdch->type < 0)
225+
pdch->type = SRD_CHANNEL_COMMON;
226226
pdch->order = offset + i;
227227
}
228228

@@ -232,7 +232,7 @@ static int get_channels(const struct srd_decoder *d, const char *attr,
232232
return SRD_OK;
233233

234234
except_out:
235-
srd_exception_catch(NULL, "Failed to get %s list of %s decoder",
235+
srd_exception_catch(NULL, "Failed to get %s list of %s decoder",
236236
attr, d->name);
237237
err_out:
238238
g_slist_free_full(pdchl, &channel_free);
@@ -348,7 +348,7 @@ static int get_options(struct srd_decoder *d)
348348
return SRD_OK;
349349

350350
except_out:
351-
srd_exception_catch(NULL, "Failed to get %s decoder options", d->name);
351+
srd_exception_catch(NULL, "Failed to get %s decoder options", d->name);
352352
err_out:
353353
g_slist_free_full(options, &decoder_option_free);
354354
Py_XDECREF(py_opts);
@@ -364,8 +364,8 @@ static int get_annotations(struct srd_decoder *dec)
364364
GSList *annotations;
365365
char **annpair;
366366
ssize_t i;
367-
int ann_type = 7;
368-
unsigned int j;
367+
int ann_type = 7;
368+
unsigned int j;
369369

370370
if (!PyObject_HasAttrString(dec->py_dec, "annotations"))
371371
return SRD_OK;
@@ -382,15 +382,15 @@ static int get_annotations(struct srd_decoder *dec)
382382
goto err_out;
383383
}
384384

385-
for (i = 0; i < PyTuple_Size(py_annlist); i++) {
385+
for (i = 0; i < PyTuple_Size(py_annlist); i++) {
386386
py_ann = PyTuple_GetItem(py_annlist, i);
387387
if (!py_ann)
388388
goto except_out;
389389

390390
if (!PyTuple_Check(py_ann) || (PyTuple_Size(py_ann) != 3 && PyTuple_Size(py_ann) != 2)) {
391391
srd_err("Protocol decoder %s annotation %zd should "
392392
"be a tuple with two or three elements.",
393-
dec->name, i);
393+
dec->name, i + 1);
394394
goto err_out;
395395
}
396396
if (py_strseq_to_char(py_ann, &annpair) != SRD_OK)
@@ -399,22 +399,22 @@ static int get_annotations(struct srd_decoder *dec)
399399
annotations = g_slist_prepend(annotations, annpair);
400400

401401
if (PyTuple_Size(py_ann) == 3) {
402-
ann_type = 0;
403-
for (j = 0; j < strlen(annpair[0]); j++)
404-
ann_type = ann_type * 10 + (annpair[0][j] - '0');
405-
dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
406-
} else if (PyTuple_Size(py_ann) == 2) {
407-
dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
408-
ann_type++;
409-
}
402+
ann_type = 0;
403+
for (j = 0; j < strlen(annpair[0]); j++)
404+
ann_type = ann_type * 10 + (annpair[0][j] - '0');
405+
dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
406+
} else if (PyTuple_Size(py_ann) == 2) {
407+
dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
408+
ann_type++;
409+
}
410410
}
411411
dec->annotations = annotations;
412412
Py_DECREF(py_annlist);
413413

414414
return SRD_OK;
415415

416416
except_out:
417-
srd_exception_catch(NULL, "Failed to get %s decoder annotations", dec->name);
417+
srd_exception_catch(NULL, "Failed to get %s decoder annotations", dec->name);
418418
err_out:
419419
g_slist_free_full(annotations, (GDestroyNotify)&g_strfreev);
420420
Py_XDECREF(py_annlist);
@@ -510,7 +510,7 @@ static int get_annotation_rows(struct srd_decoder *dec)
510510
return SRD_OK;
511511

512512
except_out:
513-
srd_exception_catch(NULL, "Failed to get %s decoder annotation rows",
513+
srd_exception_catch(NULL, "Failed to get %s decoder annotation rows",
514514
dec->name);
515515
err_out:
516516
g_slist_free_full(annotation_rows, &annotation_row_free);
@@ -566,7 +566,7 @@ static int get_binary_classes(struct srd_decoder *dec)
566566
return SRD_OK;
567567

568568
except_out:
569-
srd_exception_catch(NULL, "Failed to get %s decoder binary classes",
569+
srd_exception_catch(NULL, "Failed to get %s decoder binary classes",
570570
dec->name);
571571
err_out:
572572
g_slist_free_full(bin_classes, (GDestroyNotify)&g_strfreev);
@@ -585,8 +585,8 @@ static int check_method(PyObject *py_dec, const char *mod_name,
585585

586586
py_method = PyObject_GetAttrString(py_dec, method_name);
587587
if (!py_method) {
588-
srd_exception_catch(NULL, "Protocol decoder %s Decoder class "
589-
"has no %s() method", mod_name, method_name);
588+
srd_exception_catch(NULL, "Protocol decoder %s Decoder class "
589+
"has no %s() method", mod_name, method_name);
590590
return SRD_ERR_PYTHON;
591591
}
592592

@@ -636,12 +636,12 @@ SRD_PRIV long srd_decoder_apiver(const struct srd_decoder *d)
636636
*/
637637
SRD_API int srd_decoder_load(const char *module_name)
638638
{
639-
PyObject *py_basedec;
639+
PyObject *py_basedec;
640640
struct srd_decoder *d;
641641
long apiver;
642642
int is_subclass;
643643
const char *fail_txt;
644-
644+
645645
if (!srd_check_init())
646646
return SRD_ERR;
647647

@@ -699,8 +699,8 @@ SRD_API int srd_decoder_load(const char *module_name)
699699
*/
700700
apiver = srd_decoder_apiver(d);
701701
if (apiver != 2) {
702-
srd_exception_catch(NULL, "Only PD API version 2 is supported, "
703-
"decoder %s has version %ld", module_name, apiver);
702+
srd_exception_catch(NULL, "Only PD API version 2 is supported, "
703+
"decoder %s has version %ld", module_name, apiver);
704704
fail_txt = "API version mismatch";
705705
goto err_out;
706706
}
@@ -776,19 +776,19 @@ SRD_API int srd_decoder_load(const char *module_name)
776776
fail_txt = "cannot get binary classes";
777777
goto err_out;
778778
}
779-
779+
780780
/* Append it to the list of loaded decoders. */
781781
pd_list = g_slist_append(pd_list, d);
782782

783783
return SRD_OK;
784784

785785
except_out:
786786
if (fail_txt) {
787-
srd_exception_catch(NULL, "Failed to load decoder %s: %s",
787+
srd_exception_catch(NULL, "Failed to load decoder %s: %s",
788788
module_name, fail_txt);
789789
fail_txt = NULL;
790790
} else {
791-
srd_exception_catch(NULL, "Failed to load decoder %s", module_name);
791+
srd_exception_catch(NULL, "Failed to load decoder %s", module_name);
792792
}
793793
err_out:
794794
if (fail_txt)
@@ -823,7 +823,7 @@ SRD_API char *srd_decoder_doc_get(const struct srd_decoder *dec)
823823
return NULL;
824824

825825
if (!(py_str = PyObject_GetAttrString(dec->py_mod, "__doc__"))) {
826-
srd_exception_catch(NULL, "Failed to get docstring");
826+
srd_exception_catch(NULL, "Failed to get docstring");
827827
return NULL;
828828
}
829829

libsigrokdecode4DSL/decoders/0-spi/pd.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def decode(self, ss, es, logic):
250250
if not (self.have_miso or self.have_mosi):
251251
raise ChannelError('Either MISO or MOSI (or both) pins required.')
252252
if (self.mode == 0 or self.mode == 3):
253-
self.exp_oldclk = 0
253+
self.exp_oldclk = 0
254254
self.exp_clk = 1
255255
else:
256256
self.exp_oldclk = 1
@@ -272,7 +272,7 @@ def decode(self, ss, es, logic):
272272
#if not self.no_cs_notification and not self.have_cs:
273273
# self.put(0, 0, self.out_python, ['CS-CHANGE', None, None])
274274
# self.no_cs_notification = True
275-
275+
276276
if (self.oldcs, cs) == (self.asserted_oldcs, self.asserted_cs):
277277
#self.ss_transfer = self.samplenum
278278
#self.misobytes = []
@@ -288,6 +288,6 @@ def decode(self, ss, es, logic):
288288
elif not self.have_cs or cs == self.asserted_cs:
289289
if (self.oldclk, clk) == (self.exp_oldclk, self.exp_clk):
290290
#Sample on rising/falling clock edge
291-
self.handle_bit(miso, mosi, clk, cs)
291+
self.handle_bit(miso, mosi, clk, cs)
292292

293293
self.oldclk, self.oldcs = clk, cs

libsigrokdecode4DSL/decoders/0-uart/pd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def decode(self, ss, es, logic):
281281
(signal,) = pins
282282

283283
if self.options['invert'] == 'yes':
284-
signal = not signal
284+
signal = not signal
285285

286286
# State machine.
287287
if self.state == 'FIND START':

libsigrokdecode4DSL/decoders/1-i2c/pd.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def found_address(self, scl, sda):
179179
self.bits[1][2] = self.samplenum
180180
if self.bitcount == 7:
181181
self.bitwidth = self.bits[1][2] - self.bits[2][2]
182-
self.bits[0][2] += self.bitwidth
182+
self.bits[0][2] += self.bitwidth
183183

184184
# Return if we haven't collected all 8 + 1 bits, yet.
185185
if self.bitcount < 7:
@@ -233,7 +233,7 @@ def found_data(self, scl, sda):
233233
self.bits[1][2] = self.samplenum
234234
if self.bitcount == 7:
235235
self.bitwidth = self.bits[1][2] - self.bits[2][2]
236-
self.bits[0][2] += self.bitwidth
236+
self.bits[0][2] += self.bitwidth
237237

238238
# Return if we haven't collected all 8 + 1 bits, yet.
239239
if self.bitcount < 7:

libsigrokdecode4DSL/decoders/1-spi/pd.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def decode(self, ss, es, logic):
252252
if not (self.have_miso or self.have_mosi):
253253
raise ChannelError('Either MISO or MOSI (or both) pins required.')
254254
if (self.mode == 0 or self.mode == 3):
255-
self.exp_oldclk = 0
255+
self.exp_oldclk = 0
256256
self.exp_clk = 1
257257
else:
258258
self.exp_oldclk = 1
@@ -273,7 +273,7 @@ def decode(self, ss, es, logic):
273273
if not self.no_cs_notification and not self.have_cs:
274274
self.put(0, 0, self.out_python, ['CS-CHANGE', None, None])
275275
self.no_cs_notification = True
276-
276+
277277
if (self.oldcs, cs) == (self.asserted_oldcs, self.asserted_cs):
278278
self.ss_transfer = self.samplenum
279279
self.misobytes = []
@@ -289,6 +289,6 @@ def decode(self, ss, es, logic):
289289
elif not self.have_cs or cs == self.asserted_cs:
290290
if (self.oldclk, clk) == (self.exp_oldclk, self.exp_clk):
291291
#Sample on rising/falling clock edge
292-
self.handle_bit(miso, mosi, clk, cs)
292+
self.handle_bit(miso, mosi, clk, cs)
293293

294294
self.oldclk, self.oldcs = clk, cs

libsigrokdecode4DSL/decoders/1-uart/pd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def decode(self, ss, es, logic):
281281
(signal,) = pins
282282

283283
if self.options['invert'] == 'yes':
284-
signal = not signal
284+
signal = not signal
285285

286286
# State machine.
287287
if self.state == 'FIND START':

0 commit comments

Comments
 (0)