From ef1085cd66e347cfbd6ff689f5e0c9a940ca781c Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 18 Jan 2018 08:01:45 +0100 Subject: Add initial dummy driver code --- SoapyDummy.hpp | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 SoapyDummy.hpp (limited to 'SoapyDummy.hpp') diff --git a/SoapyDummy.hpp b/SoapyDummy.hpp new file mode 100644 index 0000000..e1ca79a --- /dev/null +++ b/SoapyDummy.hpp @@ -0,0 +1,207 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Matthias P. Braendli + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once +#include +#include +#include +#include +#include + +class SoapyDummySession +{ + public: + SoapyDummySession(void); + ~SoapyDummySession(void); +}; + +class SoapyDummy : public SoapySDR::Device +{ + public: + SoapyDummy( const SoapySDR::Kwargs & args ); + SoapyDummy(const SoapyDummy& other) = delete; + SoapyDummy& operator=(const SoapyDummy& other) = delete; + ~SoapyDummy( void ); + + /******************************************************************* + * Identification API + ******************************************************************/ + std::string getDriverKey( void ) const; + std::string getHardwareKey( void ) const; + SoapySDR::Kwargs getHardwareInfo( void ) const; + + /******************************************************************* + * Channels API + ******************************************************************/ + size_t getNumChannels( const int ) const; + bool getFullDuplex( const int direction, const size_t channel ) const; + + /******************************************************************* + * Stream API + ******************************************************************/ + 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() ); + + void closeStream( SoapySDR::Stream *stream ); + size_t getStreamMTU( SoapySDR::Stream *stream ) const; + int activateStream( + SoapySDR::Stream *stream, + const int flags = 0, + const long long timeNs = 0, + const size_t numElems = 0 ); + + int deactivateStream( + SoapySDR::Stream *stream, + const int flags = 0, + const long long timeNs = 0 ); + + 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); + + int readStreamStatus( + SoapySDR::Stream *stream, + size_t &chanMask, + int &flags, + long long &timeNs, + const long timeoutUs + ); + + int acquireReadBuffer( + SoapySDR::Stream *stream, + size_t &handle, + const void **buffs, + int &flags, + long long &timeNs, + const long timeoutUs = 100000); + + void releaseReadBuffer( + SoapySDR::Stream *stream, + const size_t handle); + + int acquireWriteBuffer( + SoapySDR::Stream *stream, + size_t &handle, + void **buffs, + const long timeoutUs = 100000); + + void releaseWriteBuffer( + SoapySDR::Stream *stream, + const size_t handle, + const size_t numElems, + int &flags, + const long long timeNs = 0); + + size_t getNumDirectAccessBuffers(SoapySDR::Stream *stream); + int getDirectAccessBufferAddrs(SoapySDR::Stream *stream, const size_t handle, void **buffs); + + /******************************************************************* + * Settings API + ******************************************************************/ + SoapySDR::ArgInfoList getSettingInfo(void) const; + void writeSetting(const std::string &key, const std::string &value); + std::string readSetting(const std::string &key) const; + + /******************************************************************* + * Antenna API + ******************************************************************/ + std::vector listAntennas( const int direction, const size_t channel ) const; + void setAntenna( const int direction, const size_t channel, const std::string &name ); + std::string getAntenna( const int direction, const size_t channel ) const; + + /******************************************************************* + * Frontend corrections API + ******************************************************************/ + bool hasDCOffsetMode( const int direction, const size_t channel ) const; + + /******************************************************************* + * Gain API + ******************************************************************/ + std::vector listGains( const int direction, const size_t channel ) const; + void setGainMode( const int direction, const size_t channel, const bool automatic ); + bool getGainMode( const int direction, const size_t channel ) const; + void setGain( const int direction, const size_t channel, const double value ); + void setGain( const int direction, const size_t channel, const std::string &name, const double value ); + double getGain( const int direction, const size_t channel, const std::string &name ) const; + SoapySDR::Range getGainRange( const int direction, const size_t channel, const std::string &name ) const; + + /******************************************************************* + * Frequency API + ******************************************************************/ + void setFrequency( const int direction, const size_t channel, const std::string &name, const double frequency, const SoapySDR::Kwargs &args = SoapySDR::Kwargs() ); + double getFrequency( const int direction, const size_t channel, const std::string &name ) const; + SoapySDR::ArgInfoList getFrequencyArgsInfo(const int direction, const size_t channel) const; + std::vector listFrequencies( const int direction, const size_t channel ) const; + SoapySDR::RangeList getFrequencyRange( const int direction, const size_t channel, const std::string &name ) const; + + /******************************************************************* + * Sample Rate API + ******************************************************************/ + void setSampleRate( const int direction, const size_t channel, const double rate ); + double getSampleRate( const int direction, const size_t channel ) const; + std::vector listSampleRates( const int direction, const size_t channel ) const; + void setBandwidth( const int direction, const size_t channel, const double bw ); + double getBandwidth( const int direction, const size_t channel ) const; + std::vector listBandwidths( const int direction, const size_t channel ) const; + + /******************************************************************* + * Dummy callback + ******************************************************************/ + int dummy_tx_callback( int8_t *buffer, int32_t length ); + int dummy_rx_callback( int8_t *buffer, int32_t length ); + + private: + struct DummyStream { + size_t mtu = 1024; + size_t buf_num = 1; + std::complex buf[1024]; + }; + + DummyStream m_rxstream; + DummyStream m_txstream; + SoapySDR::Stream* const TX_STREAM = (SoapySDR::Stream*) 0x1; + SoapySDR::Stream* const RX_STREAM = (SoapySDR::Stream*) 0x2; + + SoapyDummySession m_session; + double m_samplerate = 0; + double m_frequency = 0; +}; -- cgit v1.2.3