aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-01-17 11:30:17 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-01-17 11:30:44 +0100
commit7ca7edbc5a80b3869fb0772946c00c76c264da8d (patch)
treef9b8fabd56fe422d637475b882e50982027d524d /src/output
parent4f7636694a752fa8c652c684a3c9ebf1488ceaa4 (diff)
downloaddabmod-7ca7edbc5a80b3869fb0772946c00c76c264da8d.tar.gz
dabmod-7ca7edbc5a80b3869fb0772946c00c76c264da8d.tar.bz2
dabmod-7ca7edbc5a80b3869fb0772946c00c76c264da8d.zip
Don't use CLOCK_GETTIME in SDR
Diffstat (limited to 'src/output')
-rw-r--r--src/output/SDR.cpp43
-rw-r--r--src/output/SDR.h8
-rw-r--r--src/output/USRPTime.cpp2
3 files changed, 17 insertions, 36 deletions
diff --git a/src/output/SDR.cpp b/src/output/SDR.cpp
index e478de5..8906ef6 100644
--- a/src/output/SDR.cpp
+++ b/src/output/SDR.cpp
@@ -59,15 +59,11 @@ static constexpr double TIMESTAMP_MARGIN_FUTURE = 0.5;
SDR::SDR(SDRDeviceConfig& config, std::shared_ptr<SDRDevice> device) :
ModOutput(), ModMetadata(), RemoteControllable("sdr"),
m_config(config),
- m_running(false),
m_device(device)
{
// muting is remote-controllable
m_config.muting = false;
- time_last_frame.tv_sec = 0;
- time_last_frame.tv_nsec = 0;
-
m_device_thread = std::thread(&SDR::process_thread_entry, this);
m_dpd_feedback_server = make_shared<DPDFeedbackServer>(
@@ -78,15 +74,10 @@ SDR::SDR(SDRDeviceConfig& config, std::shared_ptr<SDRDevice> device) :
SDR::~SDR()
{
- stop();
-}
-
-void SDR::stop()
-{
m_running.store(false);
FrameData end_marker;
- end_marker.buf.resize(0);
+ end_marker.buf.clear();
m_queue.push(end_marker);
if (m_device_thread.joinable()) {
@@ -218,33 +209,23 @@ const char* SDR::name()
void SDR::sleep_through_frame()
{
- struct timespec now;
- if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) {
- stringstream ss;
- ss << "clock_gettime failure: " << strerror(errno);
- throw runtime_error(ss.str());
- }
+ using namespace std::chrono;
- if (time_last_frame.tv_sec == 0) {
- if (clock_gettime(CLOCK_MONOTONIC, &time_last_frame) != 0) {
- stringstream ss;
- ss << "clock_gettime failure: " << strerror(errno);
- throw runtime_error(ss.str());
- }
+ const auto now = steady_clock::now();
+
+ if (not t_last_frame_initialised) {
+ t_last_frame = now;
+ t_last_frame_initialised = true;
}
- long delta_us = timespecdiff_us(time_last_frame, now);
- long wait_time_us = transmission_frame_duration_ms(m_config.dabMode);
+ const auto delta = now - t_last_frame;
+ const auto wait_time = transmission_frame_duration(m_config.dabMode);
- if (wait_time_us - delta_us > 0) {
- usleep(wait_time_us - delta_us);
+ if (wait_time > delta) {
+ this_thread::sleep_for(wait_time - delta);
}
- time_last_frame.tv_nsec += wait_time_us * 1000;
- while (time_last_frame.tv_nsec >= 1000000000L) {
- time_last_frame.tv_nsec -= 1000000000L;
- time_last_frame.tv_sec++;
- }
+ t_last_frame += wait_time;
}
void SDR::handle_frame(struct FrameData& frame)
diff --git a/src/output/SDR.h b/src/output/SDR.h
index 4c7de5a..a55f7c0 100644
--- a/src/output/SDR.h
+++ b/src/output/SDR.h
@@ -34,6 +34,7 @@ DESCRIPTION:
# include <config.h>
#endif
+#include <chrono>
#include "ModPlugin.h"
#include "EtiReader.h"
#include "output/SDRDevice.h"
@@ -66,14 +67,13 @@ class SDR : public ModOutput, public ModMetadata, public RemoteControllable {
const std::string& parameter) const override;
private:
- void stop(void);
void process_thread_entry(void);
void handle_frame(struct FrameData &frame);
void sleep_through_frame(void);
SDRDeviceConfig& m_config;
- std::atomic<bool> m_running;
+ std::atomic<bool> m_running = ATOMIC_VAR_INIT(false);
std::thread m_device_thread;
std::vector<uint8_t> m_frame;
ThreadsafeQueue<FrameData> m_queue;
@@ -87,8 +87,8 @@ class SDR : public ModOutput, public ModMetadata, public RemoteControllable {
uint32_t last_tx_second = 0;
uint32_t last_tx_pps = 0;
- struct timespec time_last_frame;
-
+ bool t_last_frame_initialised = false;
+ std::chrono::steady_clock::time_point t_last_frame;
};
}
diff --git a/src/output/USRPTime.cpp b/src/output/USRPTime.cpp
index dcedeab..9ed398e 100644
--- a/src/output/USRPTime.cpp
+++ b/src/output/USRPTime.cpp
@@ -2,7 +2,7 @@
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Her Majesty the
Queen in Right of Canada (Communications Research Center Canada)
- Copyright (C) 2017
+ Copyright (C) 2018
Matthias P. Braendli, matthias.braendli@mpb.li
http://opendigitalradio.org