diff options
Diffstat (limited to 'Dummy_Streaming.cpp')
| -rw-r--r-- | Dummy_Streaming.cpp | 296 | 
1 files changed, 296 insertions, 0 deletions
| diff --git a/Dummy_Streaming.cpp b/Dummy_Streaming.cpp new file mode 100644 index 0000000..493800d --- /dev/null +++ b/Dummy_Streaming.cpp @@ -0,0 +1,296 @@ +/* + * 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. + */ + +#include "SoapyDummy.hpp" +#include <SoapySDR/Logger.hpp> +#include <SoapySDR/Formats.hpp> +#include <chrono> +#include <thread> +#include <algorithm> + +std::vector<std::string> SoapyDummy::getStreamFormats(const int direction, const size_t channel) const +{ +    std::vector<std::string> formats; + +    formats.push_back(SOAPY_SDR_CS8); +    formats.push_back(SOAPY_SDR_CS16); +    formats.push_back(SOAPY_SDR_CF32); +    formats.push_back(SOAPY_SDR_CF64); + +    return formats; +} + +std::string SoapyDummy::getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const +{ +    fullScale = 1.0; +    return SOAPY_SDR_CF32; +} + +SoapySDR::ArgInfoList SoapyDummy::getStreamArgsInfo(const int direction, const size_t channel) const +{ +    SoapySDR::ArgInfoList streamArgs; + +    SoapySDR::ArgInfo buffersArg; +    buffersArg.key="buffers"; +    buffersArg.value = std::to_string(1); +    buffersArg.name = "Buffer Count"; +    buffersArg.description = "Number of buffers per read."; +    buffersArg.units = "buffers"; +    buffersArg.type = SoapySDR::ArgInfo::INT; +    streamArgs.push_back(buffersArg); + +    return streamArgs; +} + +SoapySDR::Stream* SoapyDummy::setupStream( +        const int direction, +        const std::string &format, +        const std::vector<size_t> &channels, +        const SoapySDR::Kwargs &args ) +{ +    if ( channels.size() > 1 or( channels.size() > 0 and channels.at( 0 ) != 0 ) ) { +        throw std::runtime_error( "setupStream invalid channel selection" ); +    } + +    if(direction==SOAPY_SDR_RX){ + +        if ( format == SOAPY_SDR_CS8 ) +        { +            SoapySDR_log( SOAPY_SDR_DEBUG, "Using format CS8." ); +        }else if ( format == SOAPY_SDR_CS16 ) +        { +            SoapySDR_log( SOAPY_SDR_DEBUG, "Using format CS16." ); +        }else if ( format == SOAPY_SDR_CF32 ) +        { +            SoapySDR_log( SOAPY_SDR_DEBUG, "Using format CF32." ); +        }else if(format==SOAPY_SDR_CF64){ +            SoapySDR_log( SOAPY_SDR_DEBUG, "Using format CF64." ); +        }else throw std::runtime_error( "setupStream invalid format " + format ); + +        return RX_STREAM; +    } else if(direction==SOAPY_SDR_TX){ + +        if ( format == SOAPY_SDR_CS8 ) +        { +            SoapySDR_log( SOAPY_SDR_DEBUG, "Using format CS8." ); +        }else if ( format == SOAPY_SDR_CS16 ) +        { +            SoapySDR_log( SOAPY_SDR_DEBUG, "Using format CS16." ); +        }else if ( format == SOAPY_SDR_CF32 ) +        { +            SoapySDR_log( SOAPY_SDR_DEBUG, "Using format CF32." ); +        }else if(format==SOAPY_SDR_CF64){ +            SoapySDR_log( SOAPY_SDR_DEBUG, "Using format CF64." ); +        }else throw std::runtime_error( "setupStream invalid format " + format ); + +        return TX_STREAM; +    } +    else { +        throw std::runtime_error("Invalid direction"); +    } +} + +void SoapyDummy::closeStream( SoapySDR::Stream *stream ) +{ +    if (stream == RX_STREAM) { +    } else if (stream == TX_STREAM) { +    } +} + + +size_t SoapyDummy::getStreamMTU( SoapySDR::Stream *stream ) const +{ +    if(stream == RX_STREAM){ +        return m_rxstream.mtu; +    } else if(stream == TX_STREAM){ +        return m_txstream.mtu; +    } else { +        throw std::runtime_error("Invalid stream"); +    } +} + +int SoapyDummy::activateStream( +        SoapySDR::Stream *stream, +        const int flags, +        const long long timeNs, +        const size_t numElems ) +{ +    if (stream == RX_STREAM) { +        SoapySDR_logf(SOAPY_SDR_DEBUG, "Start RX"); +    } +    else if (stream == TX_STREAM) { +        SoapySDR_logf(SOAPY_SDR_DEBUG, "Start TX"); +    } + +    return 0; +} + + +int SoapyDummy::deactivateStream( +        SoapySDR::Stream *stream, +        const int flags, +        const long long timeNs ) +{ + +    if (stream == RX_STREAM) { +    } +    else if (stream == TX_STREAM) { +    } +    return 0; +} + + +int SoapyDummy::readStream( +        SoapySDR::Stream *stream, +        void * const *buffs, +        const size_t numElems, +        int &flags, +        long long &timeNs, +        const long timeoutUs ) +{ +    if (stream != RX_STREAM){ +        return SOAPY_SDR_NOT_SUPPORTED; +    } + +    size_t returnedElems = std::min(numElems,this->getStreamMTU(stream)); +    return returnedElems; +} + +int SoapyDummy::writeStream( +        SoapySDR::Stream *stream, +        const void * const *buffs, +        const size_t numElems, +        int &flags, +        const long long timeNs, +        const long timeoutUs ) +{ +    if (stream != TX_STREAM){ +        return SOAPY_SDR_NOT_SUPPORTED; +    } + +    size_t returnedElems = std::min(numElems,this->getStreamMTU(stream)); + +    return returnedElems; +} + + +int SoapyDummy::readStreamStatus( +        SoapySDR::Stream *stream, +        size_t &chanMask, +        int &flags, +        long long &timeNs, +        const long timeoutUs +        ){ + +    if(stream != TX_STREAM){ +        return SOAPY_SDR_NOT_SUPPORTED; +    } + +    return SOAPY_SDR_TIMEOUT; +} + +int SoapyDummy::acquireReadBuffer( +        SoapySDR::Stream *stream, +        size_t &handle, +        const void **buffs, +        int &flags, +        long long &timeNs, +        const long timeoutUs) +{ +    if (stream != RX_STREAM){ +        return SOAPY_SDR_NOT_SUPPORTED; +    } + +    return this->getStreamMTU(stream); +} + +void SoapyDummy::releaseReadBuffer( +        SoapySDR::Stream *stream, +        const size_t handle) +{ +    if(stream != RX_STREAM){ +        throw std::runtime_error("Invalid stream"); +    } +} + +int SoapyDummy::acquireWriteBuffer( +        SoapySDR::Stream *stream, +        size_t &handle, +        void **buffs, +        const long timeoutUs) +{ + +    if(stream != TX_STREAM){ +        return SOAPY_SDR_NOT_SUPPORTED; +    } + +    return this->getStreamMTU(stream); +} + +void SoapyDummy::releaseWriteBuffer( +        SoapySDR::Stream *stream, +        const size_t handle, +        const size_t numElems, +        int &flags, +        const long long timeNs) +{ +    if (stream == TX_STREAM) { +    } +    else { +        throw std::runtime_error("Invalid stream"); +    } +} + +size_t SoapyDummy::getNumDirectAccessBuffers( +        SoapySDR::Stream *stream) +{ +    if (stream == RX_STREAM) { +        return m_rxstream.buf_num; +    } +    else if(stream == TX_STREAM){ +        return m_rxstream.buf_num; +    } +    else { +        throw std::runtime_error("Invalid stream"); +    } +} + +int SoapyDummy::getDirectAccessBufferAddrs( +        SoapySDR::Stream *stream, +        const size_t handle, +        void **buffs) +{ + +    if (stream == RX_STREAM) { +        buffs[0]=(void *)m_rxstream.buf; +    } +    else if (stream == TX_STREAM) { +        buffs[0]=(void *)m_txstream.buf; +    } +    else { +        throw std::runtime_error("Invalid stream"); +    } + +    return 0; +} | 
