diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2023-06-06 12:10:39 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2023-06-06 12:10:39 +0200 |
commit | 150b75b244602c789934f1a5094f33aa7da3c09a (patch) | |
tree | 3b276fab085883d5513ceff4b973b8923632daf0 /src/output | |
parent | 1d07999d373b0fb0b67de576aa4d7b10308b4150 (diff) | |
download | dabmod-150b75b244602c789934f1a5094f33aa7da3c09a.tar.gz dabmod-150b75b244602c789934f1a5094f33aa7da3c09a.tar.bz2 dabmod-150b75b244602c789934f1a5094f33aa7da3c09a.zip |
DEXTER: Add pacontrol interface
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/Dexter.cpp | 71 | ||||
-rw-r--r-- | src/output/Dexter.h | 14 | ||||
-rw-r--r-- | src/output/SDRDevice.h | 4 |
3 files changed, 87 insertions, 2 deletions
diff --git a/src/output/Dexter.cpp b/src/output/Dexter.cpp index c1d8d2f..dd51517 100644 --- a/src/output/Dexter.cpp +++ b/src/output/Dexter.cpp @@ -66,9 +66,35 @@ static void fill_time(struct timespec *t) } } +static void pacontrol_set_targetpower(zmq::socket_t& sock, int targetpower_dBm) +{ + stringstream message_builder; + message_builder << "{'PA0' : {'TargetPower': "; + message_builder << targetpower_dBm; + message_builder << "}}"; + const auto message = message_builder.str(); + + try { + const auto r = sock.send(zmq::const_buffer{message.data(), message.size()}); + if (r.has_value()) { + etiLog.level(debug) << "Sent TargetPower=" << targetpower_dBm << " to pacontrol"; + } + else { + // zmq_send returned EAGAIN + etiLog.level(info) << "Send TargetPower=" << targetpower_dBm << " failed"; + } + } + catch (const zmq::error_t& err) { + etiLog.level(warn) << "Failed to send TargetPower=" << targetpower_dBm << ": " << err.what(); + } +} + + Dexter::Dexter(SDRDeviceConfig& config) : SDRDevice(), - m_conf(config) + m_conf(config), + m_zmq_context(1), + m_zmq_sock(m_zmq_context, ZMQ_PUSH) { etiLog.level(info) << "Dexter:Creating the device"; @@ -166,6 +192,41 @@ Dexter::Dexter(SDRDeviceConfig& config) : m_running = true; m_underflow_read_thread = std::thread(&Dexter::underflow_read_process, this); + + m_zmq_sock.setsockopt(ZMQ_SNDTIMEO, 0); + if (not m_conf.pacontrol_config_endpoint.empty()) { + etiLog.level(debug) << "Creating pacontrol connection to " << + m_conf.pacontrol_config_endpoint; + m_zmq_sock.connect(m_conf.pacontrol_config_endpoint.c_str()); + } + + if (m_conf.pacontrol_targetpower.has_value()) { + pacontrol_set_targetpower(m_zmq_sock, *m_conf.pacontrol_targetpower); + } + else { + etiLog.level(warn) << "Config does not defined PA target power"; + } +} + +static void pacontrol_set_mute(zmq::socket_t& sock, bool mute) +{ + string message = "{'PA0' : {'Mute': "; + message += (mute ? "True" : "False"); + message += "}}"; + + try { + const auto r = sock.send(zmq::const_buffer{message.data(), message.size()}); + if (r.has_value()) { + etiLog.level(debug) << "Sent mute=" << mute << " to pacontrol"; + } + else { + // zmq_send returned EAGAIN + etiLog.level(info) << "Send mute=" << mute << " failed"; + } + } + catch (const zmq::error_t& err) { + etiLog.level(warn) << "Failed to send mute=" << mute << ": " << err.what(); + } } void Dexter::channel_up() @@ -178,6 +239,10 @@ void Dexter::channel_up() m_channel_is_up = true; etiLog.level(debug) << "DEXTER CHANNEL_UP"; + + if (m_zmq_sock.connected()) { + pacontrol_set_mute(m_zmq_sock, false); + } } void Dexter::channel_down() @@ -194,6 +259,10 @@ void Dexter::channel_down() m_channel_is_up = false; etiLog.level(debug) << "DEXTER CHANNEL_DOWN"; + + if (m_zmq_sock.connected()) { + pacontrol_set_mute(m_zmq_sock, true); + } } void Dexter::handle_hw_time() diff --git a/src/output/Dexter.h b/src/output/Dexter.h index d4f425f..57b9798 100644 --- a/src/output/Dexter.h +++ b/src/output/Dexter.h @@ -34,8 +34,14 @@ DESCRIPTION: # include <config.h> #endif -#ifdef HAVE_DEXTER +#if defined(HAVE_DEXTER) + +#if !defined(HAVE_ZEROMQ) +#error "ZeroMQ is mandatory for DEXTER" +#endif + #include "iio.h" +#include "zmq.hpp" #include <string> #include <memory> @@ -120,6 +126,12 @@ class Dexter : public Output::SDRDevice size_t num_buffers_pushed = 0; + /* Communication with pacontrol */ + zmq::context_t m_zmq_context; + zmq::socket_t m_zmq_sock; + std::string m_pacontrol_endpoint; + + /* Clock State */ DexterClockState m_clock_state = DexterClockState::Startup; // Only valid when m_clock_state is not Startup diff --git a/src/output/SDRDevice.h b/src/output/SDRDevice.h index 26272be..f84b340 100644 --- a/src/output/SDRDevice.h +++ b/src/output/SDRDevice.h @@ -94,6 +94,10 @@ struct SDRDeviceConfig { // TCP port on which to serve TX and RX samples for the // digital pre distortion learning tool uint16_t dpdFeedbackServerPort = 0; + + // DEXTER-specific + std::string pacontrol_config_endpoint; + std::optional<int> pacontrol_targetpower; // dBm }; // Each frame contains one OFDM frame, and its |