diff --git a/.gitignore b/.gitignore index 73f43452..2bb0aa9d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,11 @@ nmux ddcd *.o *.so +*.so.* tags dumpvect.*.vect grc_tests/top_block.py *.swp +csdrpy.i +csdrpy.py* +csdrpy_wrap.* diff --git a/Makefile b/Makefile index 047630c8..0e5c3019 100644 --- a/Makefile +++ b/Makefile @@ -43,9 +43,10 @@ PARAMS_MISC = -Wno-unused-result #PARAMS_DEBUG = $(if $(DEBUG_ON),-g,) FFTW_PACKAGE = fftw-3.3.3 PREFIX ?= /usr +PYVERSION ?= 2.7 SOVERSION = 0.15 -.PHONY: clean-vect clean +.PHONY: clean-vect clean-python clean all: csdr nmux 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 @echo NOTE: you may have to manually edit Makefile to optimize for your CPU \(especially if you compile on ARM, please edit PARAMS_NEON\). @@ -66,7 +67,7 @@ arm-cross: clean-vect 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 clean-vect: rm -f dumpvect*.vect -clean: clean-vect +clean: clean-vect clean-python rm -f libcsdr.so.$(SOVERSION) csdr ddcd nmux *.o *.so install: all install -m 0755 libcsdr.so.$(SOVERSION) $(PREFIX)/lib @@ -99,3 +100,23 @@ emcc: cat sdr.js/sdrjs-header.js sdr.js/sdrjs-compiled.js sdr.js/sdrjs-footer.js > sdr.js/sdr.js emcc-beautify: 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' + +python: libcsdr.so clean-python + @echo "/* This file is autogenerated. Any changes should be made to csdrpy.i.in */" > csdrpy.i + @echo 'generating "csdrpy.i"' + @cat csdrpy.i.in >> csdrpy.i + @cat fastddc.h >> csdrpy.i + @cat fft_fftw.h >> csdrpy.i + @cat fft_rpi.h >> csdrpy.i + @cat ima_adpcm.h >> csdrpy.i + @cat libcsdr_gpl.h >> csdrpy.i + @cat libcsdr.h >> csdrpy.i + swig -python csdrpy.i + gcc -c -fPIC csdrpy_wrap.c -I/usr/include/python$(PYVERSION) -I. + gcc -shared csdrpy_wrap.o -L. -lcsdr -lfftw3f -lm -o _csdrpy.so + +clean-python: + rm -f csdrpy_wrap.c csdrpy_wrap.o _csdrpy.so csdrpy.py* csdrpy.i + +python-install: libcsdr.so + install -m 0755 csdrpy.py _csdrpy.so $(PREFIX)/lib/python$(PYVERSION)/ diff --git a/csdrpy.i.in b/csdrpy.i.in new file mode 100644 index 00000000..f2a09231 --- /dev/null +++ b/csdrpy.i.in @@ -0,0 +1,21 @@ +%module csdrpy + +%{ +#define SWIG_FILE_WITH_INIT +#define LIBCSDR_GPL +#define USE_FFTW +#define USE_IMA_ADPCM + +#include "predefined.h" +#include "fastddc.h" +#include "libcsdr.h" +#include "libcsdr_gpl.h" +#include "fft_fftw.h" +#include "fft_rpi.h" +#include "ima_adpcm.h" +%} + +%feature("autodoc", "2"); + +/* contents of libcsdr.h will be appended below for processing by swig */ + diff --git a/csdrpy_test.py b/csdrpy_test.py new file mode 100644 index 00000000..88828b85 --- /dev/null +++ b/csdrpy_test.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +import csdrpy + +csdrpy_syms = filter(lambda x: x.startswith('_') == False, dir(csdrpy)) +csdrpy_syms = set(csdrpy_syms) + +assert( csdrpy.is_nan(1.0) == False) +assert( csdrpy.is_nan(float('NaN')) == True) +assert( csdrpy.log2n(1) == 0 ) +assert( csdrpy.log2n(256) == 8) + +print 'Loaded {0} symbols'.format(len(csdrpy_syms)) +print 'csdr python binding works! :)'