Skip to content

Commit 969de8a

Browse files
committed
python bindings
1 parent d1c5628 commit 969de8a

4 files changed

Lines changed: 61 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ tags
77
dumpvect.*.vect
88
grc_tests/top_block.py
99
*.swp
10+
csdrpy.i
11+
csdrpy.py*
12+
csdrpy_wrap.*

Makefile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ PARAMS_MISC = -Wno-unused-result
4343
#PARAMS_DEBUG = $(if $(DEBUG_ON),-g,)
4444
FFTW_PACKAGE = fftw-3.3.3
4545
PREFIX ?= /usr
46+
PYVERSION ?= 2.7
4647
SOVERSION = 0.15
4748

48-
.PHONY: clean-vect clean
49+
.PHONY: clean-vect clean-python clean
4950
all: csdr nmux
5051
libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c fastddc.c fastddc.h fft_fftw.h fft_rpi.h ima_adpcm.h libcsdr_gpl.h libcsdr.h predefined.h
5152
@echo NOTE: you may have to manually edit Makefile to optimize for your CPU \(especially if you compile on ARM, please edit PARAMS_NEON\).
@@ -65,7 +66,7 @@ arm-cross: clean-vect
6566
arm-linux-gnueabihf-gcc -std=gnu99 -O3 -fshort-double -ffast-math -dumpbase dumpvect-arm -fdump-tree-vect-details -mfloat-abi=softfp -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mvectorize-with-neon-quad -Wno-unused-result -Wformat=0 $(SOURCES) -lm -o ./csdr
6667
clean-vect:
6768
rm -f dumpvect*.vect
68-
clean: clean-vect
69+
clean: clean-vect clean-python
6970
rm -f libcsdr.so csdr ddcd nmux
7071
install: all
7172
install -m 0755 libcsdr.so $(PREFIX)/lib
@@ -98,3 +99,23 @@ emcc:
9899
cat sdr.js/sdrjs-header.js sdr.js/sdrjs-compiled.js sdr.js/sdrjs-footer.js > sdr.js/sdr.js
99100
emcc-beautify:
100101
bash -c 'type js-beautify >/dev/null 2>&1; if [ $$? -eq 0 ]; then js-beautify sdr.js/sdr.js >sdr.js/sdr.js.beautiful; mv sdr.js/sdr.js.beautiful sdr.js/sdr.js; fi'
102+
103+
python: libcsdr.so clean-python
104+
@echo "/* This file is autogenerated. Any changes should be made to csdrpy.i.in */" > csdrpy.i
105+
@echo 'generating "csdrpy.i"'
106+
@cat csdrpy.i.in >> csdrpy.i
107+
@cat fastddc.h >> csdrpy.i
108+
@cat fft_fftw.h >> csdrpy.i
109+
@cat fft_rpi.h >> csdrpy.i
110+
@cat ima_adpcm.h >> csdrpy.i
111+
@cat libcsdr_gpl.h >> csdrpy.i
112+
@cat libcsdr.h >> csdrpy.i
113+
swig -python csdrpy.i
114+
gcc -c -fPIC csdrpy_wrap.c -I/usr/include/python$(PYVERSION) -I.
115+
gcc -shared csdrpy_wrap.o -lcsdr -lfftw3f -lm -o _csdrpy.so
116+
117+
clean-python:
118+
rm -f csdrpy_wrap.c csdrpy_wrap.o _csdrpy.so csdrpy.py* csdrpy.i
119+
120+
python-install: libcsdr.so
121+
install -m 0755 csdrpy.py _csdrpy.so $(PREFIX)/lib/python$(PYVERSION)/

csdrpy.i.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
%module csdrpy
2+
3+
%{
4+
#define SWIG_FILE_WITH_INIT
5+
#define LIBCSDR_GPL
6+
#define USE_FFTW
7+
#define USE_IMA_ADPCM
8+
9+
#include "predefined.h"
10+
#include "fastddc.h"
11+
#include "libcsdr.h"
12+
#include "libcsdr_gpl.h"
13+
#include "fft_fftw.h"
14+
#include "fft_rpi.h"
15+
#include "ima_adpcm.h"
16+
%}
17+
18+
%feature("autodoc", "2");
19+
20+
/* contents of libcsdr.h will be appended below for processing by swig */
21+

csdrpy_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
3+
import csdrpy
4+
5+
csdrpy_syms = filter(lambda x: x.startswith('_') == False, dir(csdrpy))
6+
csdrpy_syms = set(csdrpy_syms)
7+
8+
assert( csdrpy.is_nan(1.0) == False)
9+
assert( csdrpy.is_nan(float('NaN')) == True)
10+
assert( csdrpy.log2n(1) == 0 )
11+
assert( csdrpy.log2n(256) == 8)
12+
13+
print 'Loaded {0} symbols'.format(len(csdrpy_syms))
14+
print 'csdr python binding works! :)'

0 commit comments

Comments
 (0)