diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | Dummy_Clock.cpp | 66 | ||||
-rw-r--r-- | Dummy_Settings.cpp | 5 | ||||
-rw-r--r-- | SoapyDummy.hpp | 15 |
4 files changed, 87 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6010eb7..b2117ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,4 +24,5 @@ SOAPY_SDR_MODULE_UTIL( Dummy_Settings.cpp Dummy_Streaming.cpp Dummy_Session.cpp + Dummy_Clock.cpp ) diff --git a/Dummy_Clock.cpp b/Dummy_Clock.cpp new file mode 100644 index 0000000..ce7f767 --- /dev/null +++ b/Dummy_Clock.cpp @@ -0,0 +1,66 @@ +/* + * 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> + +std::vector<std::string> SoapyDummy::listTimeSources(void) const +{ + return {"internal"}; +} + +void SoapyDummy::setTimeSource(const std::string &source) +{ +} + +std::string SoapyDummy::getTimeSource(void) const +{ + return "internal"; +} + +bool SoapyDummy::hasHardwareTime(const std::string &what) const +{ + return true; +} + +long long SoapyDummy::getHardwareTime(const std::string &what) const +{ + using namespace std::chrono; + const auto now = steady_clock::now(); + return duration_cast<nanoseconds>(now.time_since_epoch()).count() - m_time_epoch; +} + +void SoapyDummy::setHardwareTime(const long long timeNs, const std::string &what) +{ + // From getHardwareTime() we have: + // timeNs = now - epoch + // we derive + // epoch = now - timeNs + using namespace std::chrono; + const auto now = steady_clock::now(); + m_time_epoch = + duration_cast<nanoseconds>(now.time_since_epoch()).count() - timeNs; +} diff --git a/Dummy_Settings.cpp b/Dummy_Settings.cpp index acf8614..85dc056 100644 --- a/Dummy_Settings.cpp +++ b/Dummy_Settings.cpp @@ -27,6 +27,11 @@ SoapyDummy::SoapyDummy( const SoapySDR::Kwargs &args ) { + // On startup, initialise our epoch to current time, so that + // it appears the counter just started counting + using namespace std::chrono; + const auto now = steady_clock::now(); + m_time_epoch = duration_cast<nanoseconds>(now.time_since_epoch()).count(); } SoapyDummy::~SoapyDummy( void ) diff --git a/SoapyDummy.hpp b/SoapyDummy.hpp index e1ca79a..e89932d 100644 --- a/SoapyDummy.hpp +++ b/SoapyDummy.hpp @@ -25,6 +25,7 @@ #pragma once #include <string.h> #include <mutex> +#include <chrono> #include <condition_variable> #include <SoapySDR/Device.hpp> #include <SoapySDR/Logger.hpp> @@ -184,6 +185,18 @@ class SoapyDummy : public SoapySDR::Device std::vector<double> listBandwidths( const int direction, const size_t channel ) const; /******************************************************************* + * Time API + ******************************************************************/ + + virtual std::vector<std::string> listTimeSources(void) const; + virtual void setTimeSource(const std::string &source); + virtual std::string getTimeSource(void) const; + + virtual bool hasHardwareTime(const std::string &what = "") const; + virtual long long getHardwareTime(const std::string &what = "") const; + virtual void setHardwareTime(const long long timeNs, const std::string &what = ""); + + /******************************************************************* * Dummy callback ******************************************************************/ int dummy_tx_callback( int8_t *buffer, int32_t length ); @@ -204,4 +217,6 @@ class SoapyDummy : public SoapySDR::Device SoapyDummySession m_session; double m_samplerate = 0; double m_frequency = 0; + + long long m_time_epoch; }; |