From 53c31e288732cfcee9bb04d3768b6015083e05ce Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 25 Feb 2017 11:52:22 +0100 Subject: Set uhd timestamps log to std::fixed --- src/OutputUHD.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index b4344f5..7f880e0 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -430,6 +430,7 @@ void OutputUHD::set_usrp_time() else { myUsrp->set_time_now(uhd::time_spec_t(now.tv_sec)); etiLog.level(info) << "OutputUHD: Setting USRP time to " << + std::fixed << uhd::time_spec_t(now.tv_sec).get_real_secs(); } } @@ -462,6 +463,7 @@ void OutputUHD::set_usrp_time() usleep(200000); // 200ms, we want the PPS to be later myUsrp->set_time_unknown_pps(uhd::time_spec_t(seconds + 2)); etiLog.level(info) << "OutputUHD: Setting USRP time next pps to " << + std::fixed << uhd::time_spec_t(seconds + 2).get_real_secs(); } @@ -733,6 +735,7 @@ void UHDWorker::handle_frame(const struct UHDWorkerFrameData *frame) if (md.time_spec.get_real_secs() > usrp_time + TIMESTAMP_ABORT_FUTURE) { etiLog.level(error) << "OutputUHD: Timestamp way too far in the future! offset: " << + std::fixed << md.time_spec.get_real_secs() - usrp_time; throw std::runtime_error("Timestamp error. Aborted."); } -- cgit v1.2.3 From 8eb2b6842570af606c797d1bc8da55bb27487b99 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 25 Feb 2017 12:05:34 +0100 Subject: Add ability to set UHD LO offset --- src/DabMod.cpp | 1 + src/OutputUHD.cpp | 26 +++++++++++++++++++++++--- src/OutputUHD.h | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/DabMod.cpp b/src/DabMod.cpp index 37db71a..741ac73 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -503,6 +503,7 @@ int launch_modulator(int argc, char* argv[]) throw std::runtime_error("Configuration error"); } + outputuhd_conf.lo_offset = pt.get("uhdoutput.lo_offset", 0); outputuhd_conf.refclk_src = pt.get("uhdoutput.refclk_source", "internal"); outputuhd_conf.pps_src = pt.get("uhdoutput.pps_source", "none"); diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index 7f880e0..072b63a 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -221,9 +221,29 @@ OutputUHD::OutputUHD( throw std::runtime_error("Cannot set USRP sample rate. Aborted."); } - //set the centre frequency - MDEBUG("OutputUHD:Setting freq to %f...\n", myConf.frequency); - myUsrp->set_tx_freq(myConf.frequency); + if (myConf.lo_offset != 0.0) { + etiLog.log(info, "OutputUHD:Setting freq to %f with LO offset %f...\n", + myConf.frequency, myConf.lo_offset); + const auto tr = uhd::tune_request_t(myConf.frequency, myConf.lo_offset); + uhd::tune_result_t result = myUsrp->set_tx_freq(tr); + + etiLog.level(info) << "OutputUHD: " << std::fixed << + "Target RF: " << result.target_rf_freq << + "Actual RF: " << result.actual_rf_freq << + "Target DSP: " << result.target_dsp_freq << + "Actual DSP: " << result.actual_dsp_freq; + + if (result.clipped_rf_freq != result.target_rf_freq) { + etiLog.level(warn) << + "OutputUHD: clipped RF frequency " << std::fixed << + " different from target"; + } + } + else { + //set the centre frequency + etiLog.log(info, "OutputUHD:Setting freq to %f...\n", myConf.frequency); + myUsrp->set_tx_freq(myConf.frequency); + } myConf.frequency = myUsrp->get_tx_freq(); MDEBUG("OutputUHD:Actual frequency: %f\n", myConf.frequency); diff --git a/src/OutputUHD.h b/src/OutputUHD.h index e477e47..cbf159f 100644 --- a/src/OutputUHD.h +++ b/src/OutputUHD.h @@ -182,6 +182,7 @@ struct OutputUHDConfig { long masterClockRate = 32768000; unsigned sampleRate = 2048000; double frequency = 0.0; + double lo_offset = 0.0; double txgain = 0.0; bool enableSync = false; bool muteNoTimestamps = false; -- cgit v1.2.3 From 1478ff198878db23e8417aecfc936e31e3e9bec9 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 25 Feb 2017 12:13:03 +0100 Subject: Move setenv earlier the glibc manual says in chapter 25.4.1 Environment Access 'Modifications of environment variables are not allowed in multi-threaded programs.' So we do it before we become multi-threaded. --- src/DabMod.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DabMod.cpp b/src/DabMod.cpp index 741ac73..bc3ee30 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -209,10 +209,6 @@ int launch_modulator(int argc, char* argv[]) return EXIT_FAILURE; } - // Set timezone to UTC - setenv("TZ", "", 1); - tzset(); - while (true) { int c = getopt(argc, argv, "a:C:c:f:F:g:G:hlm:o:O:r:T:u:V"); if (c == -1) { @@ -1015,6 +1011,10 @@ run_modulator_state_t run_modulator(modulator_data& m) int main(int argc, char* argv[]) { + // Set timezone to UTC + setenv("TZ", "", 1); + tzset(); + try { return launch_modulator(argc, argv); } -- cgit v1.2.3 From 74504a9af2ef9a34085b0065c7c993ac5346fd27 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 25 Feb 2017 12:26:16 +0100 Subject: Fix UHD LO offset logging --- src/OutputUHD.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index 072b63a..3a4511a 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -222,30 +222,30 @@ OutputUHD::OutputUHD( } if (myConf.lo_offset != 0.0) { - etiLog.log(info, "OutputUHD:Setting freq to %f with LO offset %f...\n", - myConf.frequency, myConf.lo_offset); + etiLog.level(info) << std::fixed << std::setprecision(3) << + "OutputUHD:Setting freq to " << myConf.frequency << + " with LO offset " << myConf.lo_offset << "..."; + const auto tr = uhd::tune_request_t(myConf.frequency, myConf.lo_offset); uhd::tune_result_t result = myUsrp->set_tx_freq(tr); - etiLog.level(info) << "OutputUHD: " << std::fixed << - "Target RF: " << result.target_rf_freq << - "Actual RF: " << result.actual_rf_freq << - "Target DSP: " << result.target_dsp_freq << - "Actual DSP: " << result.actual_dsp_freq; - - if (result.clipped_rf_freq != result.target_rf_freq) { - etiLog.level(warn) << - "OutputUHD: clipped RF frequency " << std::fixed << - " different from target"; - } + etiLog.level(debug) << "OutputUHD:" << + std::fixed << std::setprecision(0) << + " Target RF: " << result.target_rf_freq << + " Actual RF: " << result.actual_rf_freq << + " Target DSP: " << result.target_dsp_freq << + " Actual DSP: " << result.actual_dsp_freq; } else { //set the centre frequency - etiLog.log(info, "OutputUHD:Setting freq to %f...\n", myConf.frequency); + etiLog.level(info) << std::fixed << std::setprecision(3) << + "OutputUHD:Setting freq to " << myConf.frequency << "..."; myUsrp->set_tx_freq(myConf.frequency); } + myConf.frequency = myUsrp->get_tx_freq(); - MDEBUG("OutputUHD:Actual frequency: %f\n", myConf.frequency); + etiLog.level(info) << std::fixed << std::setprecision(3) << + "OutputUHD:Actual frequency: " << myConf.frequency; myUsrp->set_tx_gain(myConf.txgain); MDEBUG("OutputUHD:Actual TX Gain: %f ...\n", myUsrp->get_tx_gain()); -- cgit v1.2.3 From 0bdb1ce8e7753f6617074fb859419a6185d91ad1 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 25 Feb 2017 14:12:05 +0100 Subject: Document lo_offset --- doc/example.ini | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/example.ini b/doc/example.ini index bdb3f00..36a6c2f 100644 --- a/doc/example.ini +++ b/doc/example.ini @@ -201,6 +201,15 @@ txgain=2.0 ;frequency=234208000 channel=13C +; Some USRP boards/frontends support setting an LO offset that has the +; effect of shifting DC out of the signal bandwidth. This should also +; improve IQ imbalance effects, because the mirror will centered on another +; frequency (it should be on frequency + 2*lo_offset) +; +; The value can be negative, and its absolute value must be smaller than +; master_clock_rate/2. +;lo_offset=2048000 + ; The reference clock to use. The gpsdo is the ODR LEA-M8F board, the ; official Ettus GPSDO is selected with gpsdo-ettus ; possible values : internal, external, MIMO, gpsdo, gpsdo-ettus -- cgit v1.2.3