From b0087c0236501d8124fb58cab21563b861fab26a Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 25 May 2022 20:09:11 +0200 Subject: [PATCH] Remove bandwidth, not supported by radioberry --- SoapyRadioberry.hpp | 156 +++++++++++++++++++---------------- SoapyRadioberrySettings.cpp | 22 ++--- SoapyRadioberryStreaming.cpp | 22 ++++- 3 files changed, 110 insertions(+), 90 deletions(-) diff --git a/SoapyRadioberry.hpp b/SoapyRadioberry.hpp index 29f9ee8..564ff2c 100644 --- a/SoapyRadioberry.hpp +++ b/SoapyRadioberry.hpp @@ -22,112 +22,121 @@ typedef enum radioberrysdrStreamFormat { RADIOBERRY_SDR_CS16 } radioberrysdrStreamFormat; -class SoapyRadioberry : public SoapySDR::Device{ +class sdr_stream +{ + public: + sdr_stream(int dir) + { + direction = dir; + } + int get_direction() { return direction; } + + private: + int direction; +}; - public: - - SoapyRadioberry( const SoapySDR::Kwargs & args ); - ~SoapyRadioberry(); - /******************************************************************* + +class SoapyRadioberry : public SoapySDR::Device +{ + + public: + SoapyRadioberry(const SoapySDR::Kwargs &args); + ~SoapyRadioberry(); + + /******************************************************************* * Identification API ******************************************************************/ - std::string getDriverKey( void ) const; + std::string getDriverKey(void) const; - std::string getHardwareKey( void ) const; - - SoapySDR::Kwargs getHardwareInfo( void ) const; - - /******************************************************************* + std::string getHardwareKey(void) const; + + SoapySDR::Kwargs getHardwareInfo(void) const; + + /******************************************************************* * Channels API ******************************************************************/ - size_t getNumChannels( const int direction ) const; + size_t getNumChannels(const int direction) const; - bool getFullDuplex( const int direction, const size_t channel ) const; - - /******************************************************************* + bool getFullDuplex(const int direction, const size_t channel) const; + + /******************************************************************* * Stream API ******************************************************************/ - SoapySDR::RangeList getSampleRateRange(const int direction, const size_t channel) const; - - std::vector getStreamFormats(const int direction, const size_t channel) const; - - std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const; - - SoapySDR::ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const; - - - SoapySDR::Stream *setupStream( - const int direction, - const std::string &format, - const std::vector &channels = std::vector(), - const SoapySDR::Kwargs &args = SoapySDR::Kwargs() ); - - int readStream( - SoapySDR::Stream *stream, - void * const *buffs, - const size_t numElems, - int &flags, - long long &timeNs, - const long timeoutUs = 100000 ); - - int writeStream( - SoapySDR::Stream *stream, - const void * const *buffs, - const size_t numElems, - int &flags, - const long long timeNs = 0, - const long timeoutUs = 100000); - - - /******************************************************************* + SoapySDR::RangeList getSampleRateRange(const int direction, const size_t channel) const; + + std::vector getStreamFormats(const int direction, const size_t channel) const; + + std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const; + + SoapySDR::ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const; + + void closeStream(SoapySDR::Stream *stream); + + SoapySDR::Stream *setupStream( + const int direction, + const std::string &format, + const std::vector &channels = std::vector(), + const SoapySDR::Kwargs &args = SoapySDR::Kwargs()); + + int readStream( + SoapySDR::Stream *stream, + void *const *buffs, + const size_t numElems, + int &flags, + long long &timeNs, + const long timeoutUs = 100000); + + int writeStream( + SoapySDR::Stream *stream, + const void *const *buffs, + const size_t numElems, + int &flags, + const long long timeNs = 0, + const long timeoutUs = 100000); + + /******************************************************************* * Sample Rate API ******************************************************************/ - void setSampleRate( const int direction, const size_t channel, const double rate ); + void setSampleRate(const int direction, const size_t channel, const double rate); - double getBandwidth( const int direction, const size_t channel ) const; + double getBandwidth(const int direction, const size_t channel) const; + std::vector listBandwidths(const int direction, const size_t channel) const; + std::vector listSampleRates(const int direction, const size_t channel) const; - std::vector listBandwidths( const int direction, const size_t channel ) const; - std::vector listSampleRates( const int direction, const size_t channel ) const; - - - /******************************************************************* + /******************************************************************* * Frequency API ******************************************************************/ - - void setFrequency( - const int direction, - const size_t channel, - const double frequency, - const SoapySDR::Kwargs &args = SoapySDR::Kwargs()); + void setFrequency( + const int direction, + const size_t channel, + const double frequency, + const SoapySDR::Kwargs &args = SoapySDR::Kwargs()); - SoapySDR::RangeList getFrequencyRange( const int direction, const size_t channel) const; - + SoapySDR::RangeList getFrequencyRange(const int direction, const size_t channel) const; - /******************************************************************* + /******************************************************************* * Antenna API ******************************************************************/ - std::vector listAntennas( const int direction, const size_t channel ) const; + std::vector listAntennas(const int direction, const size_t channel) const; - - /******************************************************************* + /******************************************************************* * Gain API ******************************************************************/ - std::vector listGains( const int direction, const size_t channel ) const; - - void setGain( const int direction, const size_t channel, const double value ); + std::vector listGains(const int direction, const size_t channel) const; - SoapySDR::Range getGainRange( const int direction, const size_t channel ) const; + void setGain(const int direction, const size_t channel, const double value); + SoapySDR::Range getGainRange(const int direction, const size_t channel) const; - void controlRadioberry(uint32_t command, uint32_t command_data); + void controlRadioberry(uint32_t command, uint32_t command_data); /******************************************************************* * I2C API @@ -147,4 +156,5 @@ class SoapyRadioberry : public SoapySDR::Device{ bool i2c_available = false; radioberrysdrStreamFormat streamFormat; std::mutex send_command; + std::vector streams; }; diff --git a/SoapyRadioberrySettings.cpp b/SoapyRadioberrySettings.cpp index fd1581b..a4a0f56 100644 --- a/SoapyRadioberrySettings.cpp +++ b/SoapyRadioberrySettings.cpp @@ -28,10 +28,11 @@ SoapyRadioberry::SoapyRadioberry( const SoapySDR::Kwargs &args ){ } } -SoapyRadioberry::~SoapyRadioberry(void){ - +SoapyRadioberry::~SoapyRadioberry(void) +{ SoapySDR_log(SOAPY_SDR_INFO, "SoapyRadioberry::SoapyRadioberry destructor called"); - + for (auto con : streams) + delete (con); if (fd_rb != 0) close(fd_rb); } @@ -130,21 +131,10 @@ bool SoapyRadioberry::getFullDuplex( const int direction, const size_t channel ) std::vector SoapyRadioberry::listBandwidths( const int direction, const size_t channel ) const { - + // radioberry does nor support bandwidth SoapySDR_log(SOAPY_SDR_INFO, "SoapyRadioberry::listBandwidths called"); - - + std::vector options; - - if (direction == SOAPY_SDR_RX) { - options.push_back(0.048e6); - options.push_back(0.096e6); - options.push_back(0.192e6); - options.push_back(0.384e6); - } - if (direction == SOAPY_SDR_TX) { - options.push_back(0.048e6); - } return(options); } diff --git a/SoapyRadioberryStreaming.cpp b/SoapyRadioberryStreaming.cpp index e4ba427..6e46a2b 100644 --- a/SoapyRadioberryStreaming.cpp +++ b/SoapyRadioberryStreaming.cpp @@ -114,8 +114,28 @@ SoapySDR::Stream *SoapyRadioberry::setupStream( "setupStream invalid format '" + format + "' -- Only CF32 is supported by SoapyRadioberrySDR module."); } - return (SoapySDR::Stream *) this; + sdr_stream *ptr; + ptr = new sdr_stream(direction); + streams.push_back(ptr); + return (SoapySDR::Stream *)ptr; +} +void SoapyRadioberry::closeStream(SoapySDR::Stream *stream) +{ + int i = 0; + for (auto con : streams) + { + if ((sdr_stream *)stream == con) + { + if (((sdr_stream *)stream)->get_direction() == SOAPY_SDR_TX) + { // switch off TX stream + setSampleRate(SOAPY_SDR_RX, 0, sample_rate); + } + delete ((sdr_stream *)stream); + streams.erase(streams.begin() + i); + } + i++; + } } int SoapyRadioberry::readStream(