aboutsummaryrefslogtreecommitdiffstats
path: root/src/output/Dexter.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2023-06-06 12:10:39 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2023-06-06 12:10:39 +0200
commit150b75b244602c789934f1a5094f33aa7da3c09a (patch)
tree3b276fab085883d5513ceff4b973b8923632daf0 /src/output/Dexter.cpp
parent1d07999d373b0fb0b67de576aa4d7b10308b4150 (diff)
downloaddabmod-150b75b244602c789934f1a5094f33aa7da3c09a.tar.gz
dabmod-150b75b244602c789934f1a5094f33aa7da3c09a.tar.bz2
dabmod-150b75b244602c789934f1a5094f33aa7da3c09a.zip
DEXTER: Add pacontrol interface
Diffstat (limited to 'src/output/Dexter.cpp')
-rw-r--r--src/output/Dexter.cpp71
1 files changed, 70 insertions, 1 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()