From 7b0bd2675b7514e2292684bfe2bd647f87330727 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 18 Nov 2018 17:39:22 +0100 Subject: Add SDR temperature to RC --- src/output/SDR.cpp | 13 +++++++++++++ src/output/SDRDevice.h | 2 ++ src/output/Soapy.cpp | 8 ++++++++ src/output/Soapy.h | 2 ++ src/output/UHD.cpp | 9 +++++++++ src/output/UHD.h | 2 ++ 6 files changed, 36 insertions(+) diff --git a/src/output/SDR.cpp b/src/output/SDR.cpp index 9be9aa2..068b5af 100644 --- a/src/output/SDR.cpp +++ b/src/output/SDR.cpp @@ -75,6 +75,7 @@ SDR::SDR(SDRDeviceConfig& config, std::shared_ptr device) : RC_ADD_PARAMETER(rxgain, "RX gain for DPD feedback"); RC_ADD_PARAMETER(freq, "Transmission frequency"); RC_ADD_PARAMETER(muting, "Mute the output by stopping the transmitter"); + RC_ADD_PARAMETER(temp, "Temperature in degrees C of the device"); RC_ADD_PARAMETER(underruns, "Counter of number of underruns"); RC_ADD_PARAMETER(latepackets, "Counter of number of late packets"); RC_ADD_PARAMETER(frames, "Counter of number of frames modulated"); @@ -412,6 +413,18 @@ const string SDR::get_parameter(const string& parameter) const else if (parameter == "muting") { ss << m_config.muting; } + else if (parameter == "temp") { + if (not m_device) { + throw ParameterError("OutputSDR has no device"); + } + const double temp = m_device->get_temperature(); + if (std::isnan(temp)) { + throw ParameterError("Temperature not available"); + } + else { + ss << temp; + } + } else if (parameter == "underruns" or parameter == "latepackets" or parameter == "frames" ) { diff --git a/src/output/SDRDevice.h b/src/output/SDRDevice.h index 9e052b0..90a1123 100644 --- a/src/output/SDRDevice.h +++ b/src/output/SDRDevice.h @@ -130,6 +130,8 @@ class SDRDevice { struct frame_timestamp& ts, double timeout_secs) = 0; + // Returns device temperature in degrees C or NaN if not available + virtual double get_temperature(void) const = 0; // Return true if GPS and reference clock inputs are ok virtual bool is_clk_source_ok(void) const = 0; diff --git a/src/output/Soapy.cpp b/src/output/Soapy.cpp index 36ecaa8..86ed3e0 100644 --- a/src/output/Soapy.cpp +++ b/src/output/Soapy.cpp @@ -35,6 +35,7 @@ DESCRIPTION: #include #include +#include #include #include @@ -239,6 +240,13 @@ const char* Soapy::device_name(void) const return "Soapy"; } +double Soapy::get_temperature(void) const +{ + // TODO Unimplemented + // LimeSDR exports 'lms7_temp' + return std::numeric_limits::quiet_NaN(); +} + void Soapy::transmit_frame(const struct FrameData& frame) { if (not m_device) throw runtime_error("Soapy device not set up"); diff --git a/src/output/Soapy.h b/src/output/Soapy.h index 3045420..9feb0b8 100644 --- a/src/output/Soapy.h +++ b/src/output/Soapy.h @@ -79,6 +79,8 @@ class Soapy : public Output::SDRDevice virtual bool is_clk_source_ok(void) const override; virtual const char* device_name(void) const override; + virtual double get_temperature(void) const override; + private: SDRDeviceConfig& m_conf; SoapySDR::Device *m_device = nullptr; diff --git a/src/output/UHD.cpp b/src/output/UHD.cpp index 1106fe0..9358072 100644 --- a/src/output/UHD.cpp +++ b/src/output/UHD.cpp @@ -451,6 +451,15 @@ const char* UHD::device_name(void) const return "UHD"; } +double UHD::get_temperature(void) const +{ + try { + return std::round(m_usrp->get_tx_sensor("temp", 0).to_real()); + } + catch (uhd::lookup_error &e) { + return std::numeric_limits::quiet_NaN(); + } +} bool UHD::refclk_loss_needs_check() const { diff --git a/src/output/UHD.h b/src/output/UHD.h index 9aec7ce..f42b6e8 100644 --- a/src/output/UHD.h +++ b/src/output/UHD.h @@ -93,6 +93,8 @@ class UHD : public Output::SDRDevice virtual bool is_clk_source_ok(void) const override; virtual const char* device_name(void) const override; + virtual double get_temperature(void) const override; + private: SDRDeviceConfig& m_conf; uhd::usrp::multi_usrp::sptr m_usrp; -- cgit v1.2.3