aboutsummaryrefslogtreecommitdiffstats
path: root/Dummy_Streaming.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Dummy_Streaming.cpp')
-rw-r--r--Dummy_Streaming.cpp83
1 files changed, 45 insertions, 38 deletions
diff --git a/Dummy_Streaming.cpp b/Dummy_Streaming.cpp
index 1ef1c72..a85986b 100644
--- a/Dummy_Streaming.cpp
+++ b/Dummy_Streaming.cpp
@@ -33,10 +33,7 @@ std::vector<std::string> SoapyDummy::getStreamFormats(const int direction, 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;
}
@@ -69,40 +66,27 @@ SoapySDR::Stream* SoapyDummy::setupStream(
const std::vector<size_t> &channels,
const SoapySDR::Kwargs &args )
{
- if ( channels.size() > 1 or( channels.size() > 0 and channels.at( 0 ) != 0 ) ) {
+ 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 (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 )
- {
+ 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 );
+ }
+ 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 )
- {
+ }
+ else if (direction==SOAPY_SDR_TX) {
+
+ 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 );
+ }
+ else
+ throw std::runtime_error( "setupStream invalid format " + format );
return TX_STREAM;
}
@@ -114,18 +98,21 @@ SoapySDR::Stream* SoapyDummy::setupStream(
void SoapyDummy::closeStream( SoapySDR::Stream *stream )
{
if (stream == RX_STREAM) {
- } else if (stream == TX_STREAM) {
+ }
+ else if (stream == TX_STREAM) {
}
}
size_t SoapyDummy::getStreamMTU( SoapySDR::Stream *stream ) const
{
- if(stream == RX_STREAM){
+ if (stream == RX_STREAM) {
return m_rxstream.mtu;
- } else if(stream == TX_STREAM){
+ }
+ else if (stream == TX_STREAM) {
return m_txstream.mtu;
- } else {
+ }
+ else {
throw std::runtime_error("Invalid stream");
}
}
@@ -138,9 +125,11 @@ int SoapyDummy::activateStream(
{
if (stream == RX_STREAM) {
SoapySDR_logf(SOAPY_SDR_DEBUG, "Start RX");
+ m_rxstream.active = true;
}
else if (stream == TX_STREAM) {
SoapySDR_logf(SOAPY_SDR_DEBUG, "Start TX");
+ m_txstream.active = true;
}
return 0;
@@ -152,10 +141,11 @@ int SoapyDummy::deactivateStream(
const int flags,
const long long timeNs )
{
-
if (stream == RX_STREAM) {
+ m_rxstream.active = false;
}
else if (stream == TX_STREAM) {
+ m_rxstream.active = false;
}
return 0;
}
@@ -173,8 +163,17 @@ int SoapyDummy::readStream(
return SOAPY_SDR_NOT_SUPPORTED;
}
- size_t returnedElems = std::min(numElems,this->getStreamMTU(stream));
- return returnedElems;
+ if (not m_rxstream.active) {
+ using namespace std;
+ this_thread::sleep_for(chrono::microseconds(timeoutUs));
+ return SOAPY_SDR_TIMEOUT;
+ }
+
+ std::complex<float> * const buf = static_cast<std::complex<float> * const>(buffs[0]);
+
+ size_t numToRead = std::min(numElems, this->getStreamMTU(stream));
+ const size_t numRead = m_circ_buffer.read(buf, numToRead);
+ return numRead;
}
int SoapyDummy::writeStream(
@@ -189,9 +188,17 @@ int SoapyDummy::writeStream(
return SOAPY_SDR_NOT_SUPPORTED;
}
- size_t returnedElems = std::min(numElems,this->getStreamMTU(stream));
+ if (not m_txstream.active) {
+ using namespace std;
+ this_thread::sleep_for(chrono::microseconds(timeoutUs));
+ return SOAPY_SDR_TIMEOUT;
+ }
+
+ const std::complex<float> * const buf = static_cast<const std::complex<float> * const>(buffs[0]);
- return returnedElems;
+ size_t numWritten = std::min(numElems, this->getStreamMTU(stream));
+ m_circ_buffer.write(buf, numWritten, timeNs);
+ return numWritten;
}