From 1a9858e02884a28d4c9e694d3f75e766fcdfd70d Mon Sep 17 00:00:00 2001 From: "Vanya A. Sergeev" Date: Tue, 25 Feb 2020 00:55:57 -0600 Subject: [PATCH] blocks/sources/soapysdr: add support for abi version 0.8 --- radio/blocks/sources/soapysdr.lua | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/radio/blocks/sources/soapysdr.lua b/radio/blocks/sources/soapysdr.lua index 3ea66fef8..5a7891265 100644 --- a/radio/blocks/sources/soapysdr.lua +++ b/radio/blocks/sources/soapysdr.lua @@ -159,8 +159,7 @@ if not package.loaded['radio.blocks.sinks.soapysdr'] then char *SoapySDRDevice_readSetting(const SoapySDRDevice *device, const char *key); /* Stream setup/close */ - int SoapySDRDevice_setupStream(SoapySDRDevice *device, SoapySDRStream **stream, const int direction, const char *format, const size_t *channels, const size_t numChans, const SoapySDRKwargs *args); - void SoapySDRDevice_closeStream(SoapySDRDevice *device, SoapySDRStream *stream); + /* See initialize() for SoapySDRDevice_setupStream() and SoapySDRDevice_closeStream() */ size_t SoapySDRDevice_getStreamMTU(const SoapySDRDevice *device, SoapySDRStream *stream); /* Stream activate/deactivate */ @@ -180,6 +179,20 @@ function SoapySDRSource:initialize() if not libsoapysdr_available then error("SoapySDRSource: libSoapySDR not found. Is SoapySDR installed?") end + + -- Check ABI version and load correct definitions of setupStream and closeStream + self.abi_version = ffi.string(libsoapysdr.SoapySDR_getABIVersion()) + if self.abi_version >= "0.8" then + ffi.cdef[[ + SoapySDRStream *SoapySDRDevice_setupStream(SoapySDRDevice *device, const int direction, const char *format, const size_t *channels, const size_t numChans, const SoapySDRKwargs *args); + int SoapySDRDevice_closeStream(SoapySDRDevice *device, SoapySDRStream *stream); + ]] + else + ffi.cdef[[ + int SoapySDRDevice_setupStream(SoapySDRDevice *device, SoapySDRStream **stream, const int direction, const char *format, const size_t *channels, const size_t numChans, const SoapySDRKwargs *args); + void SoapySDRDevice_closeStream(SoapySDRDevice *device, SoapySDRStream *stream); + ]] + end end local function table2kwargs(t) @@ -476,9 +489,16 @@ function SoapySDRSource:initialize_soapysdr() -- Setup the stream self.stream = ffi.new("SoapySDRStream*[1]") local channels = ffi.new("size_t[1]", {self.channel}) - ret = libsoapysdr.SoapySDRDevice_setupStream(self.dev, self.stream, ffi.C.SOAPY_SDR_RX, "CF32", channels, 1, nil) - if ret < 0 then - error("SoapySDRDevice_setupStream(): " .. ffi.string(libsoapysdr.SoapySDR_errToStr(ret))) + if self.abi_version >= "0.8" then + self.stream[0] = libsoapysdr.SoapySDRDevice_setupStream(self.dev, ffi.C.SOAPY_SDR_RX, "CF32", channels, 1, nil) + if self.stream[0] == nil then + error("SoapySDRDevice_setupStream(): " .. ffi.string(libsoapysdr.SoapySDR_errToStr(ret))) + end + else + ret = libsoapysdr.SoapySDRDevice_setupStream(self.dev, self.stream, ffi.C.SOAPY_SDR_RX, "CF32", channels, 1, nil) + if ret < 0 then + error("SoapySDRDevice_setupStream(): " .. ffi.string(libsoapysdr.SoapySDR_errToStr(ret))) + end end -- Create output vector