diff options
| author | Christoph Berg <myon@debian.org> | 2018-12-19 23:01:50 +0100 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2018-12-19 23:01:50 +0100 |
| commit | 5c60c77adff9a54fd5f94f9915b22ccd8c4c5a3b (patch) | |
| tree | 410fa358a5f73260a579b4d669730f319a4d2609 /MessageClient.cpp | |
| parent | 6c82050de806dcdafaed0077400a6c3396a4a159 (diff) | |
| parent | e0737c56c1e384e05064a0c6e1ac46979371041b (diff) | |
Update upstream source from tag 'upstream/2.0.0+repack'
Update to upstream version '2.0.0+repack'
with Debian dir 55dbb3a6a7eb189e187dd79f732623ca0b56116d
Diffstat (limited to 'MessageClient.cpp')
| -rw-r--r-- | MessageClient.cpp | 92 |
1 files changed, 79 insertions, 13 deletions
diff --git a/MessageClient.cpp b/MessageClient.cpp index 4c031a7d..6ceca2dc 100644 --- a/MessageClient.cpp +++ b/MessageClient.cpp @@ -1,6 +1,8 @@ #include "MessageClient.hpp" #include <stdexcept> +#include <vector> +#include <algorithm> #include <QUdpSocket> #include <QHostInfo> @@ -8,6 +10,7 @@ #include <QQueue> #include <QByteArray> #include <QHostAddress> +#include <QColor> #include "NetworkMessage.hpp" @@ -76,6 +79,7 @@ public: QHostAddress server_; quint32 schema_; QTimer * heartbeat_timer_; + std::vector<QHostAddress> blocked_addresses_; // hold messages sent before host lookup completes asynchronously QQueue<QByteArray> pending_messages_; @@ -93,15 +97,24 @@ void MessageClient::impl::host_info_results (QHostInfo host_info) } else if (host_info.addresses ().size ()) { - server_ = host_info.addresses ()[0]; + auto server = host_info.addresses ()[0]; + if (blocked_addresses_.end () == std::find (blocked_addresses_.begin (), blocked_addresses_.end (), server)) + { + server_ = server; - // send initial heartbeat which allows schema negotiation - heartbeat (); + // send initial heartbeat which allows schema negotiation + heartbeat (); - // clear any backlog - while (pending_messages_.size ()) + // clear any backlog + while (pending_messages_.size ()) + { + send_message (pending_messages_.dequeue ()); + } + } + else { - send_message (pending_messages_.dequeue ()); + Q_EMIT self_->error ("UDP server blocked, please try another"); + pending_messages_.clear (); // discard } } } @@ -195,6 +208,31 @@ void MessageClient::impl::parse_message (QByteArray const& msg) } break; + case NetworkMessage::Location: + { + QByteArray location; + in >> location; + if (check_status (in) != Fail) + { + Q_EMIT self_->location (QString::fromUtf8 (location)); + } + } + break; + + case NetworkMessage::HighlightCallsign: + { + QByteArray call; + QColor bg; // default invalid color + QColor fg; // default invalid color + bool last_only {false}; + in >> call >> bg >> fg >> last_only; + if (check_status (in) != Fail && call.size ()) + { + Q_EMIT self_->highlight_callsign (QString::fromUtf8 (call), bg, fg, last_only); + } + } + break; + default: // Ignore // @@ -296,7 +334,7 @@ MessageClient::MessageClient (QString const& id, QString const& version, QString connect (&*m_, static_cast<void (impl::*) (impl::SocketError)> (&impl::error) , [this] (impl::SocketError e) { -#if defined (Q_OS_WIN) && QT_VERSION >= 0x050500 +#if defined (Q_OS_WIN) if (e != impl::NetworkError // take this out when Qt 5.5 // stops doing this // spuriously @@ -340,12 +378,24 @@ void MessageClient::set_server_port (port_type server_port) m_->server_port_ = server_port; } -void MessageClient::send_raw_datagram (QByteArray const& message, QHostAddress const& dest_address +qint64 MessageClient::send_raw_datagram (QByteArray const& message, QHostAddress const& dest_address , port_type dest_port) { if (dest_port && !dest_address.isNull ()) { - m_->writeDatagram (message, dest_address, dest_port); + return m_->writeDatagram (message, dest_address, dest_port); + } + return 0; +} + +void MessageClient::add_blocked_destination (QHostAddress const& a) +{ + m_->blocked_addresses_.push_back (a); + if (a == m_->server_) + { + m_->server_.clear (); + Q_EMIT error ("UDP server blocked, please try another"); + m_->pending_messages_.clear (); // discard } } @@ -355,7 +405,7 @@ void MessageClient::status_update (Frequency f, QString const& mode, QString con , qint32 rx_df, qint32 tx_df, QString const& de_call , QString const& de_grid, QString const& dx_grid , bool watchdog_timeout, QString const& sub_mode - , bool fast_mode) + , bool fast_mode, quint8 special_op_mode) { if (m_->server_port_ && !m_->server_string_.isEmpty ()) { @@ -364,7 +414,7 @@ void MessageClient::status_update (Frequency f, QString const& mode, QString con out << f << mode.toUtf8 () << dx_call.toUtf8 () << report.toUtf8 () << tx_mode.toUtf8 () << tx_enabled << transmitting << decoding << rx_df << tx_df << de_call.toUtf8 () << de_grid.toUtf8 () << dx_grid.toUtf8 () << watchdog_timeout << sub_mode.toUtf8 () - << fast_mode; + << fast_mode << special_op_mode; m_->send_message (out, message); } } @@ -410,7 +460,10 @@ void MessageClient::clear_decodes () void MessageClient::qso_logged (QDateTime time_off, QString const& dx_call, QString const& dx_grid , Frequency dial_frequency, QString const& mode, QString const& report_sent , QString const& report_received, QString const& tx_power - , QString const& comments, QString const& name, QDateTime time_on) + , QString const& comments, QString const& name, QDateTime time_on + , QString const& operator_call, QString const& my_call + , QString const& my_grid, QString const& exchange_sent + , QString const& exchange_rcvd) { if (m_->server_port_ && !m_->server_string_.isEmpty ()) { @@ -418,7 +471,20 @@ void MessageClient::qso_logged (QDateTime time_off, QString const& dx_call, QStr NetworkMessage::Builder out {&message, NetworkMessage::QSOLogged, m_->id_, m_->schema_}; out << time_off << dx_call.toUtf8 () << dx_grid.toUtf8 () << dial_frequency << mode.toUtf8 () << report_sent.toUtf8 () << report_received.toUtf8 () << tx_power.toUtf8 () << comments.toUtf8 () - << name.toUtf8 () << time_on; + << name.toUtf8 () << time_on << operator_call.toUtf8 () << my_call.toUtf8 () << my_grid.toUtf8 () + << exchange_sent.toUtf8 () << exchange_rcvd.toUtf8 (); + m_->send_message (out, message); + } +} + +void MessageClient::logged_ADIF (QByteArray const& ADIF_record) +{ + if (m_->server_port_ && !m_->server_string_.isEmpty ()) + { + QByteArray message; + NetworkMessage::Builder out {&message, NetworkMessage::LoggedADIF, m_->id_, m_->schema_}; + QByteArray ADIF {"\n<adif_ver:5>3.0.7\n<programid:6>WSJT-X\n<EOH>\n" + ADIF_record + " <EOR>"}; + out << ADIF; m_->send_message (out, message); } } |
