diff options
| author | Christoph Berg <christoph.berg@credativ.de> | 2022-08-23 10:23:31 +0200 |
|---|---|---|
| committer | Christoph Berg <christoph.berg@credativ.de> | 2022-08-23 10:23:31 +0200 |
| commit | 0e579a45e2e5823f90e2632073749583cd15fa0d (patch) | |
| tree | 5e709e13d41c8ea0da0968fb6c4566057b4b7909 /UDPExamples | |
| parent | 28d1767618141cd6481de2e93e36e3dfa555d4b4 (diff) | |
| parent | 2d1068e60bce7ae1fff11623454900e8cee956b1 (diff) | |
Update upstream source from tag 'upstream/2.6.0_rc3+repack'
Update to upstream version '2.6.0~rc3+repack'
with Debian dir 9ee8bc3a4b60bb88f4d57c7d1f2d37dbc1632144
Diffstat (limited to 'UDPExamples')
| -rwxr-xr-x | UDPExamples/BeaconsModel.cpp | 276 | ||||
| -rwxr-xr-x | UDPExamples/BeaconsModel.hpp | 80 | ||||
| -rwxr-xr-x | UDPExamples/ClientWidget.cpp | 972 | ||||
| -rwxr-xr-x | UDPExamples/ClientWidget.hpp | 302 | ||||
| -rwxr-xr-x | UDPExamples/DecodesModel.cpp | 314 | ||||
| -rwxr-xr-x | UDPExamples/DecodesModel.hpp | 88 | ||||
| -rwxr-xr-x | UDPExamples/MessageAggregator.cpp | 208 | ||||
| -rwxr-xr-x | UDPExamples/MessageAggregatorMainWindow.cpp | 806 | ||||
| -rwxr-xr-x | UDPExamples/MessageAggregatorMainWindow.hpp | 148 | ||||
| -rwxr-xr-x | UDPExamples/MessageServer.cpp | 1190 | ||||
| -rwxr-xr-x | UDPExamples/MessageServer.hpp | 254 | ||||
| -rwxr-xr-x | UDPExamples/UDPDaemon.cpp | 660 | ||||
| -rwxr-xr-x | UDPExamples/message_aggregator.qrc.in | 10 | ||||
| -rwxr-xr-x | UDPExamples/qss/default.qss | 24 |
14 files changed, 2666 insertions, 2666 deletions
diff --git a/UDPExamples/BeaconsModel.cpp b/UDPExamples/BeaconsModel.cpp index 8a6cdd27..04d89b41 100755 --- a/UDPExamples/BeaconsModel.cpp +++ b/UDPExamples/BeaconsModel.cpp @@ -1,138 +1,138 @@ -#include "BeaconsModel.hpp" - -#include <QStandardItem> -#include <QFont> - -namespace -{ - char const * const headings[] = { - QT_TRANSLATE_NOOP ("BeaconsModel", "Client"), - QT_TRANSLATE_NOOP ("BeaconsModel", "Time"), - QT_TRANSLATE_NOOP ("BeaconsModel", "Snr"), - QT_TRANSLATE_NOOP ("BeaconsModel", "DT"), - QT_TRANSLATE_NOOP ("BeaconsModel", "Frequency"), - QT_TRANSLATE_NOOP ("BeaconsModel", "Drift"), - QT_TRANSLATE_NOOP ("BeaconsModel", "Grid"), - QT_TRANSLATE_NOOP ("BeaconsModel", "Power"), - QT_TRANSLATE_NOOP ("BeaconsModel", "Live"), - QT_TRANSLATE_NOOP ("BeaconsModel", "Callsign"), - }; - - QString live_string (bool off_air) - { - return off_air ? QT_TRANSLATE_NOOP ("BeaconsModel", "no") : QT_TRANSLATE_NOOP ("BeaconsModel", "yes"); - } - - QFont text_font {"Courier", 10}; - - QList<QStandardItem *> make_row (MessageServer::ClientKey const& key, QTime time, qint32 snr, float delta_time - , Frequency frequency, qint32 drift, QString const& callsign - , QString const& grid, qint32 power, bool off_air) - { - auto client_item = new QStandardItem {QString {"%1(%2)"}.arg (key.second).arg (key.first.toString ())}; - client_item->setData (QVariant::fromValue (key)); - - auto time_item = new QStandardItem {time.toString ("hh:mm")}; - time_item->setData (time); - time_item->setTextAlignment (Qt::AlignRight); - - auto snr_item = new QStandardItem {QString::number (snr)}; - snr_item->setData (snr); - snr_item->setTextAlignment (Qt::AlignRight); - - auto dt = new QStandardItem {QString::number (delta_time)}; - dt->setData (delta_time); - dt->setTextAlignment (Qt::AlignRight); - - auto freq = new QStandardItem {Radio::pretty_frequency_MHz_string (frequency)}; - freq->setData (frequency); - freq->setTextAlignment (Qt::AlignRight); - - auto dri = new QStandardItem {QString::number (drift)}; - dri->setData (drift); - dri->setTextAlignment (Qt::AlignRight); - - auto gd = new QStandardItem {grid}; - gd->setTextAlignment (Qt::AlignRight); - - auto pwr = new QStandardItem {QString::number (power)}; - pwr->setData (power); - pwr->setTextAlignment (Qt::AlignRight); - - auto live = new QStandardItem {live_string (off_air)}; - live->setTextAlignment (Qt::AlignHCenter); - - QList<QStandardItem *> row { - client_item, time_item, snr_item, dt, freq, dri, gd, pwr, live, new QStandardItem {callsign}}; - Q_FOREACH (auto& item, row) - { - item->setEditable (false); - item->setFont (text_font); - item->setTextAlignment (item->textAlignment () | Qt::AlignVCenter); - } - return row; - } -} - -BeaconsModel::BeaconsModel (QObject * parent) - : QStandardItemModel {0, sizeof headings / sizeof headings[0], parent} -{ - int column {0}; - for (auto const& heading : headings) - { - setHeaderData (column++, Qt::Horizontal, tr (heading)); - } -} - -void BeaconsModel::add_beacon_spot (bool is_new, ClientKey const& key, QTime time, qint32 snr, float delta_time - , Frequency frequency, qint32 drift, QString const& callsign - , QString const& grid, qint32 power, bool off_air) -{ - if (!is_new) - { - int target_row {-1}; - for (auto row = 0; row < rowCount (); ++row) - { - if (item (row, 0)->data ().value<ClientKey> () == key) - { - auto row_time = item (row, 1)->data ().toTime (); - if (row_time == time - && item (row, 2)->data ().toInt () == snr - && item (row, 3)->data ().toFloat () == delta_time - && item (row, 4)->data ().value<Frequency> () == frequency - && data (index (row, 5)).toInt () == drift - && data (index (row, 7)).toString () == grid - && data (index (row, 8)).toInt () == power - && data (index (row, 6)).toString () == live_string (off_air) - && data (index (row, 9)).toString () == callsign) - { - return; - } - if (time <= row_time) - { - target_row = row; // last row with same time - } - } - } - if (target_row >= 0) - { - insertRow (target_row + 1, make_row (key, time, snr, delta_time, frequency, drift, callsign, grid, power, off_air)); - return; - } - } - - appendRow (make_row (key, time, snr, delta_time, frequency, drift, callsign, grid, power, off_air)); -} - -void BeaconsModel::decodes_cleared (ClientKey const& key) -{ - for (auto row = rowCount () - 1; row >= 0; --row) - { - if (item (row, 0)->data ().value<ClientKey> () == key) - { - removeRow (row); - } - } -} - -#include "moc_BeaconsModel.cpp" +#include "BeaconsModel.hpp"
+
+#include <QStandardItem>
+#include <QFont>
+
+namespace
+{
+ char const * const headings[] = {
+ QT_TRANSLATE_NOOP ("BeaconsModel", "Client"),
+ QT_TRANSLATE_NOOP ("BeaconsModel", "Time"),
+ QT_TRANSLATE_NOOP ("BeaconsModel", "Snr"),
+ QT_TRANSLATE_NOOP ("BeaconsModel", "DT"),
+ QT_TRANSLATE_NOOP ("BeaconsModel", "Frequency"),
+ QT_TRANSLATE_NOOP ("BeaconsModel", "Drift"),
+ QT_TRANSLATE_NOOP ("BeaconsModel", "Grid"),
+ QT_TRANSLATE_NOOP ("BeaconsModel", "Power"),
+ QT_TRANSLATE_NOOP ("BeaconsModel", "Live"),
+ QT_TRANSLATE_NOOP ("BeaconsModel", "Callsign"),
+ };
+
+ QString live_string (bool off_air)
+ {
+ return off_air ? QT_TRANSLATE_NOOP ("BeaconsModel", "no") : QT_TRANSLATE_NOOP ("BeaconsModel", "yes");
+ }
+
+ QFont text_font {"Courier", 10};
+
+ QList<QStandardItem *> make_row (MessageServer::ClientKey const& key, QTime time, qint32 snr, float delta_time
+ , Frequency frequency, qint32 drift, QString const& callsign
+ , QString const& grid, qint32 power, bool off_air)
+ {
+ auto client_item = new QStandardItem {QString {"%1(%2)"}.arg (key.second).arg (key.first.toString ())};
+ client_item->setData (QVariant::fromValue (key));
+
+ auto time_item = new QStandardItem {time.toString ("hh:mm")};
+ time_item->setData (time);
+ time_item->setTextAlignment (Qt::AlignRight);
+
+ auto snr_item = new QStandardItem {QString::number (snr)};
+ snr_item->setData (snr);
+ snr_item->setTextAlignment (Qt::AlignRight);
+
+ auto dt = new QStandardItem {QString::number (delta_time)};
+ dt->setData (delta_time);
+ dt->setTextAlignment (Qt::AlignRight);
+
+ auto freq = new QStandardItem {Radio::pretty_frequency_MHz_string (frequency)};
+ freq->setData (frequency);
+ freq->setTextAlignment (Qt::AlignRight);
+
+ auto dri = new QStandardItem {QString::number (drift)};
+ dri->setData (drift);
+ dri->setTextAlignment (Qt::AlignRight);
+
+ auto gd = new QStandardItem {grid};
+ gd->setTextAlignment (Qt::AlignRight);
+
+ auto pwr = new QStandardItem {QString::number (power)};
+ pwr->setData (power);
+ pwr->setTextAlignment (Qt::AlignRight);
+
+ auto live = new QStandardItem {live_string (off_air)};
+ live->setTextAlignment (Qt::AlignHCenter);
+
+ QList<QStandardItem *> row {
+ client_item, time_item, snr_item, dt, freq, dri, gd, pwr, live, new QStandardItem {callsign}};
+ Q_FOREACH (auto& item, row)
+ {
+ item->setEditable (false);
+ item->setFont (text_font);
+ item->setTextAlignment (item->textAlignment () | Qt::AlignVCenter);
+ }
+ return row;
+ }
+}
+
+BeaconsModel::BeaconsModel (QObject * parent)
+ : QStandardItemModel {0, sizeof headings / sizeof headings[0], parent}
+{
+ int column {0};
+ for (auto const& heading : headings)
+ {
+ setHeaderData (column++, Qt::Horizontal, tr (heading));
+ }
+}
+
+void BeaconsModel::add_beacon_spot (bool is_new, ClientKey const& key, QTime time, qint32 snr, float delta_time
+ , Frequency frequency, qint32 drift, QString const& callsign
+ , QString const& grid, qint32 power, bool off_air)
+{
+ if (!is_new)
+ {
+ int target_row {-1};
+ for (auto row = 0; row < rowCount (); ++row)
+ {
+ if (item (row, 0)->data ().value<ClientKey> () == key)
+ {
+ auto row_time = item (row, 1)->data ().toTime ();
+ if (row_time == time
+ && item (row, 2)->data ().toInt () == snr
+ && item (row, 3)->data ().toFloat () == delta_time
+ && item (row, 4)->data ().value<Frequency> () == frequency
+ && data (index (row, 5)).toInt () == drift
+ && data (index (row, 7)).toString () == grid
+ && data (index (row, 8)).toInt () == power
+ && data (index (row, 6)).toString () == live_string (off_air)
+ && data (index (row, 9)).toString () == callsign)
+ {
+ return;
+ }
+ if (time <= row_time)
+ {
+ target_row = row; // last row with same time
+ }
+ }
+ }
+ if (target_row >= 0)
+ {
+ insertRow (target_row + 1, make_row (key, time, snr, delta_time, frequency, drift, callsign, grid, power, off_air));
+ return;
+ }
+ }
+
+ appendRow (make_row (key, time, snr, delta_time, frequency, drift, callsign, grid, power, off_air));
+}
+
+void BeaconsModel::decodes_cleared (ClientKey const& key)
+{
+ for (auto row = rowCount () - 1; row >= 0; --row)
+ {
+ if (item (row, 0)->data ().value<ClientKey> () == key)
+ {
+ removeRow (row);
+ }
+ }
+}
+
+#include "moc_BeaconsModel.cpp"
diff --git a/UDPExamples/BeaconsModel.hpp b/UDPExamples/BeaconsModel.hpp index 2baa99ec..19f0e21e 100755 --- a/UDPExamples/BeaconsModel.hpp +++ b/UDPExamples/BeaconsModel.hpp @@ -1,40 +1,40 @@ -#ifndef WSJTX_UDP_BEACONS_MODEL_HPP__ -#define WSJTX_UDP_BEACONS_MODEL_HPP__ - -#include <QStandardItemModel> - -#include "MessageServer.hpp" - -using Frequency = MessageServer::Frequency; - -class QString; -class QTime; - -// -// Beacons Model - simple data model for all beacon spots -// -// The model is a basic table with uniform row format. Rows consist of -// QStandardItem instances containing the string representation of the -// column data and if the underlying field is not a string then the -// UserRole+1 role contains the underlying data item. -// -// Two slots are provided to add a new decode and remove all spots for -// a client. -// -class BeaconsModel - : public QStandardItemModel -{ - Q_OBJECT; - - using ClientKey = MessageServer::ClientKey; - -public: - explicit BeaconsModel (QObject * parent = nullptr); - - Q_SLOT void add_beacon_spot (bool is_new, ClientKey const&, QTime time, qint32 snr, float delta_time - , Frequency frequency, qint32 drift, QString const& callsign, QString const& grid - , qint32 power, bool off_air); - Q_SLOT void decodes_cleared (ClientKey const&); -}; - -#endif +#ifndef WSJTX_UDP_BEACONS_MODEL_HPP__
+#define WSJTX_UDP_BEACONS_MODEL_HPP__
+
+#include <QStandardItemModel>
+
+#include "MessageServer.hpp"
+
+using Frequency = MessageServer::Frequency;
+
+class QString;
+class QTime;
+
+//
+// Beacons Model - simple data model for all beacon spots
+//
+// The model is a basic table with uniform row format. Rows consist of
+// QStandardItem instances containing the string representation of the
+// column data and if the underlying field is not a string then the
+// UserRole+1 role contains the underlying data item.
+//
+// Two slots are provided to add a new decode and remove all spots for
+// a client.
+//
+class BeaconsModel
+ : public QStandardItemModel
+{
+ Q_OBJECT;
+
+ using ClientKey = MessageServer::ClientKey;
+
+public:
+ explicit BeaconsModel (QObject * parent = nullptr);
+
+ Q_SLOT void add_beacon_spot (bool is_new, ClientKey const&, QTime time, qint32 snr, float delta_time
+ , Frequency frequency, qint32 drift, QString const& callsign, QString const& grid
+ , qint32 power, bool off_air);
+ Q_SLOT void decodes_cleared (ClientKey const&);
+};
+
+#endif
diff --git a/UDPExamples/ClientWidget.cpp b/UDPExamples/ClientWidget.cpp index b82836f0..aa963685 100755 --- a/UDPExamples/ClientWidget.cpp +++ b/UDPExamples/ClientWidget.cpp @@ -1,486 +1,486 @@ -#include "ClientWidget.hpp" - -#include <limits> -#include <QRegExp> -#include <QColor> -#include <QtWidgets> -#include <QAction> - -#include "validators/MaidenheadLocatorValidator.hpp" - -namespace -{ - //QRegExp message_alphabet {"[- A-Za-z0-9+./?]*"}; - QRegExp message_alphabet {"[- @A-Za-z0-9+./?#<>]*"}; - QRegularExpression cq_re {"(CQ|CQDX|QRZ)[^A-Z0-9/]+"}; - QRegExpValidator message_validator {message_alphabet}; - MaidenheadLocatorValidator locator_validator; - quint32 quint32_max {std::numeric_limits<quint32>::max ()}; - - void update_dynamic_property (QWidget * widget, char const * property, QVariant const& value) - { - widget->setProperty (property, value); - widget->style ()->unpolish (widget); - widget->style ()->polish (widget); - widget->update (); - } -} - -ClientWidget::IdFilterModel::IdFilterModel (ClientKey const& key, QObject * parent) - : QSortFilterProxyModel {parent} - , key_ {key} - , rx_df_ (quint32_max) -{ -} - -QVariant ClientWidget::IdFilterModel::data (QModelIndex const& proxy_index, int role) const -{ - if (role == Qt::BackgroundRole) - { - switch (proxy_index.column ()) - { - case 8: // message - { - auto message = QSortFilterProxyModel::data (proxy_index).toString (); - if (base_call_re_.pattern ().size () - && message.contains (base_call_re_)) - { - return QColor {255,200,200}; - } - if (message.contains (cq_re)) - { - return QColor {200, 255, 200}; - } - } - break; - - case 4: // DF - if (qAbs (QSortFilterProxyModel::data (proxy_index).toUInt () - rx_df_) <= 10) - { - return QColor {255, 200, 200}; - } - break; - - default: - break; - } - } - return QSortFilterProxyModel::data (proxy_index, role); -} - -bool ClientWidget::IdFilterModel::filterAcceptsRow (int source_row - , QModelIndex const& source_parent) const -{ - auto source_index_col0 = sourceModel ()->index (source_row, 0, source_parent); - return sourceModel ()->data (source_index_col0, Qt::UserRole + 1).value<ClientKey> () == key_; -} - -void ClientWidget::IdFilterModel::de_call (QString const& call) -{ - if (call != call_) - { - beginResetModel (); - if (call.size ()) - { - base_call_re_.setPattern ("[^A-Z0-9]*" + Radio::base_callsign (call) + "[^A-Z0-9]*"); - } - else - { - base_call_re_.setPattern (QString {}); - } - call_ = call; - endResetModel (); - } -} - -void ClientWidget::IdFilterModel::rx_df (quint32 df) -{ - if (df != rx_df_) - { - beginResetModel (); - rx_df_ = df; - endResetModel (); - } -} - -namespace -{ - QString make_title (MessageServer::ClientKey const& key, QString const& version, QString const& revision) - { - QString title {QString {"%1(%2)"}.arg (key.second).arg (key.first.toString ())}; - if (version.size ()) - { - title += QString {" v%1"}.arg (version); - } - if (revision.size ()) - { - title += QString {" (%1)"}.arg (revision); - } - return title; - } -} - -ClientWidget::ClientWidget (QAbstractItemModel * decodes_model, QAbstractItemModel * beacons_model - , ClientKey const& key, QString const& version, QString const& revision - , QListWidget const * calls_of_interest, QWidget * parent) - : QDockWidget {make_title (key, version, revision), parent} - , key_ {key} - , done_ {false} - , calls_of_interest_ {calls_of_interest} - , decodes_proxy_model_ {key} - , beacons_proxy_model_ {key} - , erase_action_ {new QAction {tr ("&Erase Band Activity"), this}} - , erase_rx_frequency_action_ {new QAction {tr ("Erase &Rx Frequency"), this}} - , erase_both_action_ {new QAction {tr ("Erase &Both"), this}} - , decodes_table_view_ {new QTableView {this}} - , beacons_table_view_ {new QTableView {this}} - , message_line_edit_ {new QLineEdit {this}} - , grid_line_edit_ {new QLineEdit {this}} - , generate_messages_push_button_ {new QPushButton {tr ("&Gen Msgs"), this}} - , auto_off_button_ {nullptr} - , halt_tx_button_ {nullptr} - , de_label_ {new QLabel {this}} - , frequency_label_ {new QLabel {this}} - , tx_df_label_ {new QLabel {this}} - , report_label_ {new QLabel {this}} - , configuration_line_edit_ {new QLineEdit {this}} - , mode_line_edit_ {new QLineEdit {this}} - , frequency_tolerance_spin_box_ {new QSpinBox {this}} - , tx_mode_label_ {new QLabel {this}} - , tx_message_label_ {new QLabel {this}} - , submode_line_edit_ {new QLineEdit {this}} - , fast_mode_check_box_ {new QCheckBox {this}} - , tr_period_spin_box_ {new QSpinBox {this}} - , rx_df_spin_box_ {new QSpinBox {this}} - , dx_call_line_edit_ {new QLineEdit {this}} - , dx_grid_line_edit_ {new QLineEdit {this}} - , decodes_page_ {new QWidget {this}} - , beacons_page_ {new QWidget {this}} - , content_widget_ {new QFrame {this}} - , status_bar_ {new QStatusBar {this}} - , control_button_box_ {new QDialogButtonBox {this}} - , form_layout_ {new QFormLayout} - , horizontal_layout_ {new QHBoxLayout} - , subform1_layout_ {new QFormLayout} - , subform2_layout_ {new QFormLayout} - , subform3_layout_ {new QFormLayout} - , decodes_layout_ {new QVBoxLayout {decodes_page_}} - , beacons_layout_ {new QVBoxLayout {beacons_page_}} - , content_layout_ {new QVBoxLayout {content_widget_}} - , decodes_stack_ {new QStackedLayout} - , columns_resized_ {false} -{ - // set up widgets - decodes_proxy_model_.setSourceModel (decodes_model); - decodes_table_view_->setModel (&decodes_proxy_model_); - decodes_table_view_->verticalHeader ()->hide (); - decodes_table_view_->hideColumn (0); - decodes_table_view_->horizontalHeader ()->setStretchLastSection (true); - decodes_table_view_->setContextMenuPolicy (Qt::ActionsContextMenu); - decodes_table_view_->insertAction (nullptr, erase_action_); - decodes_table_view_->insertAction (nullptr, erase_rx_frequency_action_); - decodes_table_view_->insertAction (nullptr, erase_both_action_); - - message_line_edit_->setValidator (&message_validator); - grid_line_edit_->setValidator (&locator_validator); - dx_grid_line_edit_->setValidator (&locator_validator); - tr_period_spin_box_->setRange (5, 1800); - tr_period_spin_box_->setSuffix (" s"); - rx_df_spin_box_->setRange (200, 5000); - frequency_tolerance_spin_box_->setRange (1, 1000); - frequency_tolerance_spin_box_->setPrefix ("\u00b1"); - frequency_tolerance_spin_box_->setSuffix (" Hz"); - - form_layout_->addRow (tr ("Free text:"), message_line_edit_); - form_layout_->addRow (tr ("Temporary grid:"), grid_line_edit_); - form_layout_->addRow (tr ("Configuration name:"), configuration_line_edit_); - form_layout_->addRow (horizontal_layout_); - subform1_layout_->addRow (tr ("Mode:"), mode_line_edit_); - subform2_layout_->addRow (tr ("Submode:"), submode_line_edit_); - subform3_layout_->addRow (tr ("Fast mode:"), fast_mode_check_box_); - subform1_layout_->addRow (tr ("T/R period:"), tr_period_spin_box_); - subform2_layout_->addRow (tr ("Rx DF:"), rx_df_spin_box_); - subform3_layout_->addRow (tr ("Freq. Tol:"), frequency_tolerance_spin_box_); - subform1_layout_->addRow (tr ("DX call:"), dx_call_line_edit_); - subform2_layout_->addRow (tr ("DX grid:"), dx_grid_line_edit_); - subform3_layout_->addRow (generate_messages_push_button_); - horizontal_layout_->addLayout (subform1_layout_); - horizontal_layout_->addLayout (subform2_layout_); - horizontal_layout_->addLayout (subform3_layout_); - - connect (message_line_edit_, &QLineEdit::textEdited, [this] (QString const& text) { - Q_EMIT do_free_text (key_, text, false); - }); - connect (message_line_edit_, &QLineEdit::editingFinished, [this] () { - Q_EMIT do_free_text (key_, message_line_edit_->text (), true); - }); - connect (grid_line_edit_, &QLineEdit::editingFinished, [this] () { - Q_EMIT location (key_, grid_line_edit_->text ()); - }); - connect (configuration_line_edit_, &QLineEdit::editingFinished, [this] () { - Q_EMIT switch_configuration (key_, configuration_line_edit_->text ()); - }); - connect (mode_line_edit_, &QLineEdit::editingFinished, [this] () { - QString empty; - Q_EMIT configure (key_, mode_line_edit_->text (), quint32_max, empty, fast_mode () - , quint32_max, quint32_max, empty, empty, false); - }); - connect (frequency_tolerance_spin_box_, static_cast<void (QSpinBox::*) (int)> (&QSpinBox::valueChanged), [this] (int i) { - QString empty; - auto f = frequency_tolerance_spin_box_->specialValueText ().size () ? quint32_max : i; - Q_EMIT configure (key_, empty, f, empty, fast_mode () - , quint32_max, quint32_max, empty, empty, false); - }); - connect (submode_line_edit_, &QLineEdit::editingFinished, [this] () { - QString empty; - Q_EMIT configure (key_, empty, quint32_max, submode_line_edit_->text (), fast_mode () - , quint32_max, quint32_max, empty, empty, false); - }); - connect (fast_mode_check_box_, &QCheckBox::stateChanged, [this] (int state) { - QString empty; - Q_EMIT configure (key_, empty, quint32_max, empty, Qt::Checked == state - , quint32_max, quint32_max, empty, empty, false); - }); - connect (tr_period_spin_box_, static_cast<void (QSpinBox::*) (int)> (&QSpinBox::valueChanged), [this] (int i) { - QString empty; - Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode () - , i, quint32_max, empty, empty, false); - }); - connect (rx_df_spin_box_, static_cast<void (QSpinBox::*) (int)> (&QSpinBox::valueChanged), [this] (int i) { - QString empty; - Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode () - , quint32_max, i, empty, empty, false); - }); - connect (dx_call_line_edit_, &QLineEdit::editingFinished, [this] () { - QString empty; - Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode () - , quint32_max, quint32_max, dx_call_line_edit_->text (), empty, false); - }); - connect (dx_grid_line_edit_, &QLineEdit::editingFinished, [this] () { - QString empty; - Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode () - , quint32_max, quint32_max, empty, dx_grid_line_edit_->text (), false); - }); - - decodes_layout_->setContentsMargins (QMargins {2, 2, 2, 2}); - decodes_layout_->addWidget (decodes_table_view_); - decodes_layout_->addLayout (form_layout_); - - beacons_proxy_model_.setSourceModel (beacons_model); - beacons_table_view_->setModel (&beacons_proxy_model_); - beacons_table_view_->verticalHeader ()->hide (); - beacons_table_view_->hideColumn (0); - beacons_table_view_->horizontalHeader ()->setStretchLastSection (true); - beacons_table_view_->setContextMenuPolicy (Qt::ActionsContextMenu); - beacons_table_view_->insertAction (nullptr, erase_action_); - - beacons_layout_->setContentsMargins (QMargins {2, 2, 2, 2}); - beacons_layout_->addWidget (beacons_table_view_); - - decodes_stack_->addWidget (decodes_page_); - decodes_stack_->addWidget (beacons_page_); - - // stack alternative views - content_layout_->setContentsMargins (QMargins {2, 2, 2, 2}); - content_layout_->addLayout (decodes_stack_); - - // set up controls - auto_off_button_ = control_button_box_->addButton (tr ("&Auto Off"), QDialogButtonBox::ActionRole); - halt_tx_button_ = control_button_box_->addButton (tr ("&Halt Tx"), QDialogButtonBox::ActionRole); - connect (generate_messages_push_button_, &QAbstractButton::clicked, [this] (bool /*checked*/) { - QString empty; - Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode () - , quint32_max, quint32_max, empty, empty, true); - }); - connect (auto_off_button_, &QAbstractButton::clicked, [this] (bool /* checked */) { - Q_EMIT do_halt_tx (key_, true); - }); - connect (halt_tx_button_, &QAbstractButton::clicked, [this] (bool /* checked */) { - Q_EMIT do_halt_tx (key_, false); - }); - content_layout_->addWidget (control_button_box_); - - // set up status area - status_bar_->addPermanentWidget (de_label_); - status_bar_->addPermanentWidget (tx_mode_label_); - status_bar_->addPermanentWidget (tx_message_label_); - status_bar_->addPermanentWidget (frequency_label_); - status_bar_->addPermanentWidget (tx_df_label_); - status_bar_->addPermanentWidget (report_label_); - content_layout_->addWidget (status_bar_); - connect (this, &ClientWidget::topLevelChanged, status_bar_, &QStatusBar::setSizeGripEnabled); - - // set up central widget - content_widget_->setFrameStyle (QFrame::StyledPanel | QFrame::Sunken); - setWidget (content_widget_); - // setMinimumSize (QSize {550, 0}); - setAllowedAreas (Qt::BottomDockWidgetArea); - setFloating (true); - - // connect context menu actions - connect (erase_action_, &QAction::triggered, [this] (bool /*checked*/) { - Q_EMIT do_clear_decodes (key_); - }); - connect (erase_rx_frequency_action_, &QAction::triggered, [this] (bool /*checked*/) { - Q_EMIT do_clear_decodes (key_, 1); - }); - connect (erase_both_action_, &QAction::triggered, [this] (bool /*checked*/) { - Q_EMIT do_clear_decodes (key_, 2); - }); - - // connect up table view signals - connect (decodes_table_view_, &QTableView::doubleClicked, [this] (QModelIndex const& index) { - Q_EMIT do_reply (decodes_proxy_model_.mapToSource (index), QApplication::keyboardModifiers () >> 24); - }); - - // tell new client about calls of interest - for (int row = 0; row < calls_of_interest_->count (); ++row) - { - Q_EMIT highlight_callsign (key_, calls_of_interest_->item (row)->text (), QColor {Qt::blue}, QColor {Qt::yellow}); - } -} - -void ClientWidget::dispose () -{ - done_ = true; - close (); -} - -void ClientWidget::closeEvent (QCloseEvent *e) -{ - if (!done_) - { - Q_EMIT do_close (key_); - e->ignore (); // defer closure until client actually closes - } - else - { - QDockWidget::closeEvent (e); - } -} - -ClientWidget::~ClientWidget () -{ - for (int row = 0; row < calls_of_interest_->count (); ++row) - { - // tell client to forget calls of interest - Q_EMIT highlight_callsign (key_, calls_of_interest_->item (row)->text ()); - } -} - -bool ClientWidget::fast_mode () const -{ - return fast_mode_check_box_->isChecked (); -} - -namespace -{ - void update_line_edit (QLineEdit * le, QString const& value, bool allow_empty = true) - { - le->setEnabled (value.size () || allow_empty); - if (!(le->hasFocus () && le->isModified ())) - { - le->setText (value); - } - } - - void update_spin_box (QSpinBox * sb, int value, QString const& special_value = QString {}) - { - sb->setSpecialValueText (special_value); - bool enable {0 == special_value.size ()}; - sb->setEnabled (enable); - if (!sb->hasFocus () && enable) - { - sb->setValue (value); - } - } -} - -void ClientWidget::update_status (ClientKey const& key, Frequency f, QString const& mode, QString const& dx_call - , QString const& report, QString const& tx_mode, bool tx_enabled - , bool transmitting, bool decoding, quint32 rx_df, quint32 tx_df - , QString const& de_call, QString const& de_grid, QString const& dx_grid - , bool watchdog_timeout, QString const& submode, bool fast_mode - , quint8 special_op_mode, quint32 frequency_tolerance, quint32 tr_period - , QString const& configuration_name, QString const& tx_message) -{ - if (key == key_) - { - fast_mode_check_box_->setChecked (fast_mode); - decodes_proxy_model_.de_call (de_call); - decodes_proxy_model_.rx_df (rx_df); - QString special; - switch (special_op_mode) - { - case 1: special = "[NA VHF]"; break; - case 2: special = "[EU VHF]"; break; - case 3: special = "[FD]"; break; - case 4: special = "[RTTY RU]"; break; - case 5: special = "[WW DIGI]"; break; - case 6: special = "[Fox]"; break; - case 7: special = "[Hound]"; break; - default: break; - } - de_label_->setText (de_call.size () >= 0 ? QString {"DE: %1%2%3"}.arg (de_call) - .arg (de_grid.size () ? '(' + de_grid + ')' : QString {}) - .arg (special) - : QString {}); - update_line_edit (mode_line_edit_, mode); - update_spin_box (frequency_tolerance_spin_box_, frequency_tolerance - , quint32_max == frequency_tolerance ? QString {"n/a"} : QString {}); - update_line_edit (submode_line_edit_, submode, false); - tx_mode_label_->setText (tx_mode.isEmpty () || tx_mode == mode ? "" : "Tx Mode: (" + tx_mode + ')'); - tx_message_label_->setText (tx_message.isEmpty () ? "" : "Tx Msg: " + tx_message.trimmed ()); - frequency_label_->setText ("QRG: " + Radio::pretty_frequency_MHz_string (f)); - update_line_edit (dx_call_line_edit_, dx_call); - update_line_edit (dx_grid_line_edit_, dx_grid); - if (rx_df != quint32_max) update_spin_box (rx_df_spin_box_, rx_df); - update_spin_box (tr_period_spin_box_, tr_period - , quint32_max == tr_period ? QString {"n/a"} : QString {}); - tx_df_label_->setText (QString {"Tx: %1"}.arg (tx_df)); - report_label_->setText ("SNR: " + report); - update_dynamic_property (frequency_label_, "transmitting", transmitting); - auto_off_button_->setEnabled (tx_enabled); - halt_tx_button_->setEnabled (transmitting); - update_line_edit (configuration_line_edit_, configuration_name); - update_dynamic_property (mode_line_edit_, "decoding", decoding); - update_dynamic_property (tx_df_label_, "watchdog_timeout", watchdog_timeout); - } -} - -void ClientWidget::decode_added (bool /*is_new*/, ClientKey const& key, QTime /*time*/, qint32 /*snr*/ - , float /*delta_time*/, quint32 /*delta_frequency*/, QString const& /*mode*/ - , QString const& /*message*/, bool /*low_confidence*/, bool /*off_air*/) -{ - if (key == key_ && !columns_resized_) - { - decodes_stack_->setCurrentIndex (0); - decodes_table_view_->resizeColumnsToContents (); - columns_resized_ = true; - } - decodes_table_view_->scrollToBottom (); -} - -void ClientWidget::beacon_spot_added (bool /*is_new*/, ClientKey const& key, QTime /*time*/, qint32 /*snr*/ - , float /*delta_time*/, Frequency /*delta_frequency*/, qint32 /*drift*/ - , QString const& /*callsign*/, QString const& /*grid*/, qint32 /*power*/ - , bool /*off_air*/) -{ - if (key == key_ && !columns_resized_) - { - decodes_stack_->setCurrentIndex (1); - beacons_table_view_->resizeColumnsToContents (); - columns_resized_ = true; - } - beacons_table_view_->scrollToBottom (); -} - -void ClientWidget::decodes_cleared (ClientKey const& key) -{ - if (key == key_) - { - columns_resized_ = false; - } -} - -#include "moc_ClientWidget.cpp" +#include "ClientWidget.hpp"
+
+#include <limits>
+#include <QRegExp>
+#include <QColor>
+#include <QtWidgets>
+#include <QAction>
+
+#include "validators/MaidenheadLocatorValidator.hpp"
+
+namespace
+{
+ //QRegExp message_alphabet {"[- A-Za-z0-9+./?]*"};
+ QRegExp message_alphabet {"[- @A-Za-z0-9+./?#<>]*"};
+ QRegularExpression cq_re {"(CQ|CQDX|QRZ)[^A-Z0-9/]+"};
+ QRegExpValidator message_validator {message_alphabet};
+ MaidenheadLocatorValidator locator_validator;
+ quint32 quint32_max {std::numeric_limits<quint32>::max ()};
+
+ void update_dynamic_property (QWidget * widget, char const * property, QVariant const& value)
+ {
+ widget->setProperty (property, value);
+ widget->style ()->unpolish (widget);
+ widget->style ()->polish (widget);
+ widget->update ();
+ }
+}
+
+ClientWidget::IdFilterModel::IdFilterModel (ClientKey const& key, QObject * parent)
+ : QSortFilterProxyModel {parent}
+ , key_ {key}
+ , rx_df_ (quint32_max)
+{
+}
+
+QVariant ClientWidget::IdFilterModel::data (QModelIndex const& proxy_index, int role) const
+{
+ if (role == Qt::BackgroundRole)
+ {
+ switch (proxy_index.column ())
+ {
+ case 8: // message
+ {
+ auto message = QSortFilterProxyModel::data (proxy_index).toString ();
+ if (base_call_re_.pattern ().size ()
+ && message.contains (base_call_re_))
+ {
+ return QColor {255,200,200};
+ }
+ if (message.contains (cq_re))
+ {
+ return QColor {200, 255, 200};
+ }
+ }
+ break;
+
+ case 4: // DF
+ if (qAbs (QSortFilterProxyModel::data (proxy_index).toUInt () - rx_df_) <= 10)
+ {
+ return QColor {255, 200, 200};
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ return QSortFilterProxyModel::data (proxy_index, role);
+}
+
+bool ClientWidget::IdFilterModel::filterAcceptsRow (int source_row
+ , QModelIndex const& source_parent) const
+{
+ auto source_index_col0 = sourceModel ()->index (source_row, 0, source_parent);
+ return sourceModel ()->data (source_index_col0, Qt::UserRole + 1).value<ClientKey> () == key_;
+}
+
+void ClientWidget::IdFilterModel::de_call (QString const& call)
+{
+ if (call != call_)
+ {
+ beginResetModel ();
+ if (call.size ())
+ {
+ base_call_re_.setPattern ("[^A-Z0-9]*" + Radio::base_callsign (call) + "[^A-Z0-9]*");
+ }
+ else
+ {
+ base_call_re_.setPattern (QString {});
+ }
+ call_ = call;
+ endResetModel ();
+ }
+}
+
+void ClientWidget::IdFilterModel::rx_df (quint32 df)
+{
+ if (df != rx_df_)
+ {
+ beginResetModel ();
+ rx_df_ = df;
+ endResetModel ();
+ }
+}
+
+namespace
+{
+ QString make_title (MessageServer::ClientKey const& key, QString const& version, QString const& revision)
+ {
+ QString title {QString {"%1(%2)"}.arg (key.second).arg (key.first.toString ())};
+ if (version.size ())
+ {
+ title += QString {" v%1"}.arg (version);
+ }
+ if (revision.size ())
+ {
+ title += QString {" (%1)"}.arg (revision);
+ }
+ return title;
+ }
+}
+
+ClientWidget::ClientWidget (QAbstractItemModel * decodes_model, QAbstractItemModel * beacons_model
+ , ClientKey const& key, QString const& version, QString const& revision
+ , QListWidget const * calls_of_interest, QWidget * parent)
+ : QDockWidget {make_title (key, version, revision), parent}
+ , key_ {key}
+ , done_ {false}
+ , calls_of_interest_ {calls_of_interest}
+ , decodes_proxy_model_ {key}
+ , beacons_proxy_model_ {key}
+ , erase_action_ {new QAction {tr ("&Erase Band Activity"), this}}
+ , erase_rx_frequency_action_ {new QAction {tr ("Erase &Rx Frequency"), this}}
+ , erase_both_action_ {new QAction {tr ("Erase &Both"), this}}
+ , decodes_table_view_ {new QTableView {this}}
+ , beacons_table_view_ {new QTableView {this}}
+ , message_line_edit_ {new QLineEdit {this}}
+ , grid_line_edit_ {new QLineEdit {this}}
+ , generate_messages_push_button_ {new QPushButton {tr ("&Gen Msgs"), this}}
+ , auto_off_button_ {nullptr}
+ , halt_tx_button_ {nullptr}
+ , de_label_ {new QLabel {this}}
+ , frequency_label_ {new QLabel {this}}
+ , tx_df_label_ {new QLabel {this}}
+ , report_label_ {new QLabel {this}}
+ , configuration_line_edit_ {new QLineEdit {this}}
+ , mode_line_edit_ {new QLineEdit {this}}
+ , frequency_tolerance_spin_box_ {new QSpinBox {this}}
+ , tx_mode_label_ {new QLabel {this}}
+ , tx_message_label_ {new QLabel {this}}
+ , submode_line_edit_ {new QLineEdit {this}}
+ , fast_mode_check_box_ {new QCheckBox {this}}
+ , tr_period_spin_box_ {new QSpinBox {this}}
+ , rx_df_spin_box_ {new QSpinBox {this}}
+ , dx_call_line_edit_ {new QLineEdit {this}}
+ , dx_grid_line_edit_ {new QLineEdit {this}}
+ , decodes_page_ {new QWidget {this}}
+ , beacons_page_ {new QWidget {this}}
+ , content_widget_ {new QFrame {this}}
+ , status_bar_ {new QStatusBar {this}}
+ , control_button_box_ {new QDialogButtonBox {this}}
+ , form_layout_ {new QFormLayout}
+ , horizontal_layout_ {new QHBoxLayout}
+ , subform1_layout_ {new QFormLayout}
+ , subform2_layout_ {new QFormLayout}
+ , subform3_layout_ {new QFormLayout}
+ , decodes_layout_ {new QVBoxLayout {decodes_page_}}
+ , beacons_layout_ {new QVBoxLayout {beacons_page_}}
+ , content_layout_ {new QVBoxLayout {content_widget_}}
+ , decodes_stack_ {new QStackedLayout}
+ , columns_resized_ {false}
+{
+ // set up widgets
+ decodes_proxy_model_.setSourceModel (decodes_model);
+ decodes_table_view_->setModel (&decodes_proxy_model_);
+ decodes_table_view_->verticalHeader ()->hide ();
+ decodes_table_view_->hideColumn (0);
+ decodes_table_view_->horizontalHeader ()->setStretchLastSection (true);
+ decodes_table_view_->setContextMenuPolicy (Qt::ActionsContextMenu);
+ decodes_table_view_->insertAction (nullptr, erase_action_);
+ decodes_table_view_->insertAction (nullptr, erase_rx_frequency_action_);
+ decodes_table_view_->insertAction (nullptr, erase_both_action_);
+
+ message_line_edit_->setValidator (&message_validator);
+ grid_line_edit_->setValidator (&locator_validator);
+ dx_grid_line_edit_->setValidator (&locator_validator);
+ tr_period_spin_box_->setRange (5, 1800);
+ tr_period_spin_box_->setSuffix (" s");
+ rx_df_spin_box_->setRange (200, 5000);
+ frequency_tolerance_spin_box_->setRange (1, 1000);
+ frequency_tolerance_spin_box_->setPrefix ("\u00b1");
+ frequency_tolerance_spin_box_->setSuffix (" Hz");
+
+ form_layout_->addRow (tr ("Free text:"), message_line_edit_);
+ form_layout_->addRow (tr ("Temporary grid:"), grid_line_edit_);
+ form_layout_->addRow (tr ("Configuration name:"), configuration_line_edit_);
+ form_layout_->addRow (horizontal_layout_);
+ subform1_layout_->addRow (tr ("Mode:"), mode_line_edit_);
+ subform2_layout_->addRow (tr ("Submode:"), submode_line_edit_);
+ subform3_layout_->addRow (tr ("Fast mode:"), fast_mode_check_box_);
+ subform1_layout_->addRow (tr ("T/R period:"), tr_period_spin_box_);
+ subform2_layout_->addRow (tr ("Rx DF:"), rx_df_spin_box_);
+ subform3_layout_->addRow (tr ("Freq. Tol:"), frequency_tolerance_spin_box_);
+ subform1_layout_->addRow (tr ("DX call:"), dx_call_line_edit_);
+ subform2_layout_->addRow (tr ("DX grid:"), dx_grid_line_edit_);
+ subform3_layout_->addRow (generate_messages_push_button_);
+ horizontal_layout_->addLayout (subform1_layout_);
+ horizontal_layout_->addLayout (subform2_layout_);
+ horizontal_layout_->addLayout (subform3_layout_);
+
+ connect (message_line_edit_, &QLineEdit::textEdited, [this] (QString const& text) {
+ Q_EMIT do_free_text (key_, text, false);
+ });
+ connect (message_line_edit_, &QLineEdit::editingFinished, [this] () {
+ Q_EMIT do_free_text (key_, message_line_edit_->text (), true);
+ });
+ connect (grid_line_edit_, &QLineEdit::editingFinished, [this] () {
+ Q_EMIT location (key_, grid_line_edit_->text ());
+ });
+ connect (configuration_line_edit_, &QLineEdit::editingFinished, [this] () {
+ Q_EMIT switch_configuration (key_, configuration_line_edit_->text ());
+ });
+ connect (mode_line_edit_, &QLineEdit::editingFinished, [this] () {
+ QString empty;
+ Q_EMIT configure (key_, mode_line_edit_->text (), quint32_max, empty, fast_mode ()
+ , quint32_max, quint32_max, empty, empty, false);
+ });
+ connect (frequency_tolerance_spin_box_, static_cast<void (QSpinBox::*) (int)> (&QSpinBox::valueChanged), [this] (int i) {
+ QString empty;
+ auto f = frequency_tolerance_spin_box_->specialValueText ().size () ? quint32_max : i;
+ Q_EMIT configure (key_, empty, f, empty, fast_mode ()
+ , quint32_max, quint32_max, empty, empty, false);
+ });
+ connect (submode_line_edit_, &QLineEdit::editingFinished, [this] () {
+ QString empty;
+ Q_EMIT configure (key_, empty, quint32_max, submode_line_edit_->text (), fast_mode ()
+ , quint32_max, quint32_max, empty, empty, false);
+ });
+ connect (fast_mode_check_box_, &QCheckBox::stateChanged, [this] (int state) {
+ QString empty;
+ Q_EMIT configure (key_, empty, quint32_max, empty, Qt::Checked == state
+ , quint32_max, quint32_max, empty, empty, false);
+ });
+ connect (tr_period_spin_box_, static_cast<void (QSpinBox::*) (int)> (&QSpinBox::valueChanged), [this] (int i) {
+ QString empty;
+ Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode ()
+ , i, quint32_max, empty, empty, false);
+ });
+ connect (rx_df_spin_box_, static_cast<void (QSpinBox::*) (int)> (&QSpinBox::valueChanged), [this] (int i) {
+ QString empty;
+ Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode ()
+ , quint32_max, i, empty, empty, false);
+ });
+ connect (dx_call_line_edit_, &QLineEdit::editingFinished, [this] () {
+ QString empty;
+ Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode ()
+ , quint32_max, quint32_max, dx_call_line_edit_->text (), empty, false);
+ });
+ connect (dx_grid_line_edit_, &QLineEdit::editingFinished, [this] () {
+ QString empty;
+ Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode ()
+ , quint32_max, quint32_max, empty, dx_grid_line_edit_->text (), false);
+ });
+
+ decodes_layout_->setContentsMargins (QMargins {2, 2, 2, 2});
+ decodes_layout_->addWidget (decodes_table_view_);
+ decodes_layout_->addLayout (form_layout_);
+
+ beacons_proxy_model_.setSourceModel (beacons_model);
+ beacons_table_view_->setModel (&beacons_proxy_model_);
+ beacons_table_view_->verticalHeader ()->hide ();
+ beacons_table_view_->hideColumn (0);
+ beacons_table_view_->horizontalHeader ()->setStretchLastSection (true);
+ beacons_table_view_->setContextMenuPolicy (Qt::ActionsContextMenu);
+ beacons_table_view_->insertAction (nullptr, erase_action_);
+
+ beacons_layout_->setContentsMargins (QMargins {2, 2, 2, 2});
+ beacons_layout_->addWidget (beacons_table_view_);
+
+ decodes_stack_->addWidget (decodes_page_);
+ decodes_stack_->addWidget (beacons_page_);
+
+ // stack alternative views
+ content_layout_->setContentsMargins (QMargins {2, 2, 2, 2});
+ content_layout_->addLayout (decodes_stack_);
+
+ // set up controls
+ auto_off_button_ = control_button_box_->addButton (tr ("&Auto Off"), QDialogButtonBox::ActionRole);
+ halt_tx_button_ = control_button_box_->addButton (tr ("&Halt Tx"), QDialogButtonBox::ActionRole);
+ connect (generate_messages_push_button_, &QAbstractButton::clicked, [this] (bool /*checked*/) {
+ QString empty;
+ Q_EMIT configure (key_, empty, quint32_max, empty, fast_mode ()
+ , quint32_max, quint32_max, empty, empty, true);
+ });
+ connect (auto_off_button_, &QAbstractButton::clicked, [this] (bool /* checked */) {
+ Q_EMIT do_halt_tx (key_, true);
+ });
+ connect (halt_tx_button_, &QAbstractButton::clicked, [this] (bool /* checked */) {
+ Q_EMIT do_halt_tx (key_, false);
+ });
+ content_layout_->addWidget (control_button_box_);
+
+ // set up status area
+ status_bar_->addPermanentWidget (de_label_);
+ status_bar_->addPermanentWidget (tx_mode_label_);
+ status_bar_->addPermanentWidget (tx_message_label_);
+ status_bar_->addPermanentWidget (frequency_label_);
+ status_bar_->addPermanentWidget (tx_df_label_);
+ status_bar_->addPermanentWidget (report_label_);
+ content_layout_->addWidget (status_bar_);
+ connect (this, &ClientWidget::topLevelChanged, status_bar_, &QStatusBar::setSizeGripEnabled);
+
+ // set up central widget
+ content_widget_->setFrameStyle (QFrame::StyledPanel | QFrame::Sunken);
+ setWidget (content_widget_);
+ // setMinimumSize (QSize {550, 0});
+ setAllowedAreas (Qt::BottomDockWidgetArea);
+ setFloating (true);
+
+ // connect context menu actions
+ connect (erase_action_, &QAction::triggered, [this] (bool /*checked*/) {
+ Q_EMIT do_clear_decodes (key_);
+ });
+ connect (erase_rx_frequency_action_, &QAction::triggered, [this] (bool /*checked*/) {
+ Q_EMIT do_clear_decodes (key_, 1);
+ });
+ connect (erase_both_action_, &QAction::triggered, [this] (bool /*checked*/) {
+ Q_EMIT do_clear_decodes (key_, 2);
+ });
+
+ // connect up table view signals
+ connect (decodes_table_view_, &QTableView::doubleClicked, [this] (QModelIndex const& index) {
+ Q_EMIT do_reply (decodes_proxy_model_.mapToSource (index), QApplication::keyboardModifiers () >> 24);
+ });
+
+ // tell new client about calls of interest
+ for (int row = 0; row < calls_of_interest_->count (); ++row)
+ {
+ Q_EMIT highlight_callsign (key_, calls_of_interest_->item (row)->text (), QColor {Qt::blue}, QColor {Qt::yellow});
+ }
+}
+
+void ClientWidget::dispose ()
+{
+ done_ = true;
+ close ();
+}
+
+void ClientWidget::closeEvent (QCloseEvent *e)
+{
+ if (!done_)
+ {
+ Q_EMIT do_close (key_);
+ e->ignore (); // defer closure until client actually closes
+ }
+ else
+ {
+ QDockWidget::closeEvent (e);
+ }
+}
+
+ClientWidget::~ClientWidget ()
+{
+ for (int row = 0; row < calls_of_interest_->count (); ++row)
+ {
+ // tell client to forget calls of interest
+ Q_EMIT highlight_callsign (key_, calls_of_interest_->item (row)->text ());
+ }
+}
+
+bool ClientWidget::fast_mode () const
+{
+ return fast_mode_check_box_->isChecked ();
+}
+
+namespace
+{
+ void update_line_edit (QLineEdit * le, QString const& value, bool allow_empty = true)
+ {
+ le->setEnabled (value.size () || allow_empty);
+ if (!(le->hasFocus () && le->isModified ()))
+ {
+ le->setText (value);
+ }
+ }
+
+ void update_spin_box (QSpinBox * sb, int value, QString const& special_value = QString {})
+ {
+ sb->setSpecialValueText (special_value);
+ bool enable {0 == special_value.size ()};
+ sb->setEnabled (enable);
+ if (!sb->hasFocus () && enable)
+ {
+ sb->setValue (value);
+ }
+ }
+}
+
+void ClientWidget::update_status (ClientKey const& key, Frequency f, QString const& mode, QString const& dx_call
+ , QString const& report, QString const& tx_mode, bool tx_enabled
+ , bool transmitting, bool decoding, quint32 rx_df, quint32 tx_df
+ , QString const& de_call, QString const& de_grid, QString const& dx_grid
+ , bool watchdog_timeout, QString const& submode, bool fast_mode
+ , quint8 special_op_mode, quint32 frequency_tolerance, quint32 tr_period
+ , QString const& configuration_name, QString const& tx_message)
+{
+ if (key == key_)
+ {
+ fast_mode_check_box_->setChecked (fast_mode);
+ decodes_proxy_model_.de_call (de_call);
+ decodes_proxy_model_.rx_df (rx_df);
+ QString special;
+ switch (special_op_mode)
+ {
+ case 1: special = "[NA VHF]"; break;
+ case 2: special = "[EU VHF]"; break;
+ case 3: special = "[FD]"; break;
+ case 4: special = "[RTTY RU]"; break;
+ case 5: special = "[WW DIGI]"; break;
+ case 6: special = "[Fox]"; break;
+ case 7: special = "[Hound]"; break;
+ default: break;
+ }
+ de_label_->setText (de_call.size () >= 0 ? QString {"DE: %1%2%3"}.arg (de_call)
+ .arg (de_grid.size () ? '(' + de_grid + ')' : QString {})
+ .arg (special)
+ : QString {});
+ update_line_edit (mode_line_edit_, mode);
+ update_spin_box (frequency_tolerance_spin_box_, frequency_tolerance
+ , quint32_max == frequency_tolerance ? QString {"n/a"} : QString {});
+ update_line_edit (submode_line_edit_, submode, false);
+ tx_mode_label_->setText (tx_mode.isEmpty () || tx_mode == mode ? "" : "Tx Mode: (" + tx_mode + ')');
+ tx_message_label_->setText (tx_message.isEmpty () ? "" : "Tx Msg: " + tx_message.trimmed ());
+ frequency_label_->setText ("QRG: " + Radio::pretty_frequency_MHz_string (f));
+ update_line_edit (dx_call_line_edit_, dx_call);
+ update_line_edit (dx_grid_line_edit_, dx_grid);
+ if (rx_df != quint32_max) update_spin_box (rx_df_spin_box_, rx_df);
+ update_spin_box (tr_period_spin_box_, tr_period
+ , quint32_max == tr_period ? QString {"n/a"} : QString {});
+ tx_df_label_->setText (QString {"Tx: %1"}.arg (tx_df));
+ report_label_->setText ("SNR: " + report);
+ update_dynamic_property (frequency_label_, "transmitting", transmitting);
+ auto_off_button_->setEnabled (tx_enabled);
+ halt_tx_button_->setEnabled (transmitting);
+ update_line_edit (configuration_line_edit_, configuration_name);
+ update_dynamic_property (mode_line_edit_, "decoding", decoding);
+ update_dynamic_property (tx_df_label_, "watchdog_timeout", watchdog_timeout);
+ }
+}
+
+void ClientWidget::decode_added (bool /*is_new*/, ClientKey const& key, QTime /*time*/, qint32 /*snr*/
+ , float /*delta_time*/, quint32 /*delta_frequency*/, QString const& /*mode*/
+ , QString const& /*message*/, bool /*low_confidence*/, bool /*off_air*/)
+{
+ if (key == key_ && !columns_resized_)
+ {
+ decodes_stack_->setCurrentIndex (0);
+ decodes_table_view_->resizeColumnsToContents ();
+ columns_resized_ = true;
+ }
+ decodes_table_view_->scrollToBottom ();
+}
+
+void ClientWidget::beacon_spot_added (bool /*is_new*/, ClientKey const& key, QTime /*time*/, qint32 /*snr*/
+ , float /*delta_time*/, Frequency /*delta_frequency*/, qint32 /*drift*/
+ , QString const& /*callsign*/, QString const& /*grid*/, qint32 /*power*/
+ , bool /*off_air*/)
+{
+ if (key == key_ && !columns_resized_)
+ {
+ decodes_stack_->setCurrentIndex (1);
+ beacons_table_view_->resizeColumnsToContents ();
+ columns_resized_ = true;
+ }
+ beacons_table_view_->scrollToBottom ();
+}
+
+void ClientWidget::decodes_cleared (ClientKey const& key)
+{
+ if (key == key_)
+ {
+ columns_resized_ = false;
+ }
+}
+
+#include "moc_ClientWidget.cpp"
diff --git a/UDPExamples/ClientWidget.hpp b/UDPExamples/ClientWidget.hpp index fb0ef47f..5fbc2953 100755 --- a/UDPExamples/ClientWidget.hpp +++ b/UDPExamples/ClientWidget.hpp @@ -1,151 +1,151 @@ -#ifndef WSJTX_UDP_CLIENT_WIDGET_MODEL_HPP__ -#define WSJTX_UDP_CLIENT_WIDGET_MODEL_HPP__ - -#include <QDockWidget> -#include <QObject> -#include <QSortFilterProxyModel> -#include <QString> -#include <QRegularExpression> - -#include "MessageServer.hpp" - -class QAbstractItemModel; -class QModelIndex; -class QColor; -class QAction; -class QListWidget; -class QFormLayout; -class QVBoxLayout; -class QHBoxLayout; -class QStackedLayout; -class QTableView; -class QLineEdit; -class QAbstractButton; -class QLabel; -class QCheckBox; -class QSpinBox; -class QFrame; -class QStatusBar; -class QDialogButtonBox; - -using Frequency = MessageServer::Frequency; - -class ClientWidget - : public QDockWidget -{ - Q_OBJECT; - - using ClientKey = MessageServer::ClientKey; - -public: - explicit ClientWidget (QAbstractItemModel * decodes_model, QAbstractItemModel * beacons_model - , ClientKey const& key, QString const& version, QString const& revision - , QListWidget const * calls_of_interest, QWidget * parent = nullptr); - void dispose (); - ~ClientWidget (); - - bool fast_mode () const; - - Q_SLOT void update_status (ClientKey const& key, Frequency f, QString const& mode, QString const& dx_call - , QString const& report, QString const& tx_mode, bool tx_enabled - , bool transmitting, bool decoding, quint32 rx_df, quint32 tx_df - , QString const& de_call, QString const& de_grid, QString const& dx_grid - , bool watchdog_timeout, QString const& sub_mode, bool fast_mode - , quint8 special_op_mode, quint32 frequency_tolerance, quint32 tr_period - , QString const& configuration_name, QString const& tx_message); - Q_SLOT void decode_added (bool is_new, ClientKey const& key, QTime, qint32 snr - , float delta_time, quint32 delta_frequency, QString const& mode - , QString const& message, bool low_confidence, bool off_air); - Q_SLOT void beacon_spot_added (bool is_new, ClientKey const& key, QTime, qint32 snr - , float delta_time, Frequency delta_frequency, qint32 drift - , QString const& callsign, QString const& grid, qint32 power - , bool off_air); - Q_SLOT void decodes_cleared (ClientKey const& key); - - Q_SIGNAL void do_clear_decodes (ClientKey const& key, quint8 window = 0); - Q_SIGNAL void do_close (ClientKey const& key); - Q_SIGNAL void do_reply (QModelIndex const&, quint8 modifier); - Q_SIGNAL void do_halt_tx (ClientKey const& key, bool auto_only); - Q_SIGNAL void do_free_text (ClientKey const& key, QString const& text, bool); - Q_SIGNAL void location (ClientKey const& key, QString const& text); - Q_SIGNAL void highlight_callsign (ClientKey const& key, QString const& call - , QColor const& bg = QColor {}, QColor const& fg = QColor {} - , bool last_only = false); - Q_SIGNAL void switch_configuration (ClientKey const& key, QString const& configuration_name); - Q_SIGNAL void configure (ClientKey const& key, QString const& mode, quint32 frequency_tolerance - , QString const& submode, bool fast_mode, quint32 tr_period, quint32 rx_df - , QString const& dx_call, QString const& dx_grid, bool generate_messages); - -private: - class IdFilterModel final - : public QSortFilterProxyModel - { - public: - IdFilterModel (ClientKey const& key, QObject * = nullptr); - - void de_call (QString const&); - void rx_df (quint32); - - QVariant data (QModelIndex const& proxy_index, int role = Qt::DisplayRole) const override; - private: - bool filterAcceptsRow (int source_row, QModelIndex const& source_parent) const override; - - ClientKey key_; - QString call_; - QRegularExpression base_call_re_; - quint32 rx_df_; - }; - - void closeEvent (QCloseEvent *) override; - - ClientKey key_; - bool done_; - QListWidget const * calls_of_interest_; - IdFilterModel decodes_proxy_model_; - IdFilterModel beacons_proxy_model_; - - QAction * erase_action_; - QAction * erase_rx_frequency_action_; - QAction * erase_both_action_; - QTableView * decodes_table_view_; - QTableView * beacons_table_view_; - QLineEdit * message_line_edit_; - QLineEdit * grid_line_edit_; - QAbstractButton * generate_messages_push_button_; - QAbstractButton * auto_off_button_; - QAbstractButton * halt_tx_button_; - QLabel * de_label_; - QLabel * frequency_label_; - QLabel * tx_df_label_; - QLabel * report_label_; - QLineEdit * configuration_line_edit_; - QLineEdit * mode_line_edit_; - QSpinBox * frequency_tolerance_spin_box_; - QLabel * tx_mode_label_; - QLabel * tx_message_label_; - QLineEdit * submode_line_edit_; - QCheckBox * fast_mode_check_box_; - QSpinBox * tr_period_spin_box_; - QSpinBox * rx_df_spin_box_; - QLineEdit * dx_call_line_edit_; - QLineEdit * dx_grid_line_edit_; - QWidget * decodes_page_; - QWidget * beacons_page_; - QFrame * content_widget_; - QStatusBar * status_bar_; - QDialogButtonBox * control_button_box_; - - QFormLayout * form_layout_; - QHBoxLayout * horizontal_layout_; - QFormLayout * subform1_layout_; - QFormLayout * subform2_layout_; - QFormLayout * subform3_layout_; - QVBoxLayout * decodes_layout_; - QVBoxLayout * beacons_layout_; - QVBoxLayout * content_layout_; - QStackedLayout * decodes_stack_; - - bool columns_resized_; -}; - -#endif +#ifndef WSJTX_UDP_CLIENT_WIDGET_MODEL_HPP__
+#define WSJTX_UDP_CLIENT_WIDGET_MODEL_HPP__
+
+#include <QDockWidget>
+#include <QObject>
+#include <QSortFilterProxyModel>
+#include <QString>
+#include <QRegularExpression>
+
+#include "MessageServer.hpp"
+
+class QAbstractItemModel;
+class QModelIndex;
+class QColor;
+class QAction;
+class QListWidget;
+class QFormLayout;
+class QVBoxLayout;
+class QHBoxLayout;
+class QStackedLayout;
+class QTableView;
+class QLineEdit;
+class QAbstractButton;
+class QLabel;
+class QCheckBox;
+class QSpinBox;
+class QFrame;
+class QStatusBar;
+class QDialogButtonBox;
+
+using Frequency = MessageServer::Frequency;
+
+class ClientWidget
+ : public QDockWidget
+{
+ Q_OBJECT;
+
+ using ClientKey = MessageServer::ClientKey;
+
+public:
+ explicit ClientWidget (QAbstractItemModel * decodes_model, QAbstractItemModel * beacons_model
+ , ClientKey const& key, QString const& version, QString const& revision
+ , QListWidget const * calls_of_interest, QWidget * parent = nullptr);
+ void dispose ();
+ ~ClientWidget ();
+
+ bool fast_mode () const;
+
+ Q_SLOT void update_status (ClientKey const& key, Frequency f, QString const& mode, QString const& dx_call
+ , QString const& report, QString const& tx_mode, bool tx_enabled
+ , bool transmitting, bool decoding, quint32 rx_df, quint32 tx_df
+ , QString const& de_call, QString const& de_grid, QString const& dx_grid
+ , bool watchdog_timeout, QString const& sub_mode, bool fast_mode
+ , quint8 special_op_mode, quint32 frequency_tolerance, quint32 tr_period
+ , QString const& configuration_name, QString const& tx_message);
+ Q_SLOT void decode_added (bool is_new, ClientKey const& key, QTime, qint32 snr
+ , float delta_time, quint32 delta_frequency, QString const& mode
+ , QString const& message, bool low_confidence, bool off_air);
+ Q_SLOT void beacon_spot_added (bool is_new, ClientKey const& key, QTime, qint32 snr
+ , float delta_time, Frequency delta_frequency, qint32 drift
+ , QString const& callsign, QString const& grid, qint32 power
+ , bool off_air);
+ Q_SLOT void decodes_cleared (ClientKey const& key);
+
+ Q_SIGNAL void do_clear_decodes (ClientKey const& key, quint8 window = 0);
+ Q_SIGNAL void do_close (ClientKey const& key);
+ Q_SIGNAL void do_reply (QModelIndex const&, quint8 modifier);
+ Q_SIGNAL void do_halt_tx (ClientKey const& key, bool auto_only);
+ Q_SIGNAL void do_free_text (ClientKey const& key, QString const& text, bool);
+ Q_SIGNAL void location (ClientKey const& key, QString const& text);
+ Q_SIGNAL void highlight_callsign (ClientKey const& key, QString const& call
+ , QColor const& bg = QColor {}, QColor const& fg = QColor {}
+ , bool last_only = false);
+ Q_SIGNAL void switch_configuration (ClientKey const& key, QString const& configuration_name);
+ Q_SIGNAL void configure (ClientKey const& key, QString const& mode, quint32 frequency_tolerance
+ , QString const& submode, bool fast_mode, quint32 tr_period, quint32 rx_df
+ , QString const& dx_call, QString const& dx_grid, bool generate_messages);
+
+private:
+ class IdFilterModel final
+ : public QSortFilterProxyModel
+ {
+ public:
+ IdFilterModel (ClientKey const& key, QObject * = nullptr);
+
+ void de_call (QString const&);
+ void rx_df (quint32);
+
+ QVariant data (QModelIndex const& proxy_index, int role = Qt::DisplayRole) const override;
+ private:
+ bool filterAcceptsRow (int source_row, QModelIndex const& source_parent) const override;
+
+ ClientKey key_;
+ QString call_;
+ QRegularExpression base_call_re_;
+ quint32 rx_df_;
+ };
+
+ void closeEvent (QCloseEvent *) override;
+
+ ClientKey key_;
+ bool done_;
+ QListWidget const * calls_of_interest_;
+ IdFilterModel decodes_proxy_model_;
+ IdFilterModel beacons_proxy_model_;
+
+ QAction * erase_action_;
+ QAction * erase_rx_frequency_action_;
+ QAction * erase_both_action_;
+ QTableView * decodes_table_view_;
+ QTableView * beacons_table_view_;
+ QLineEdit * message_line_edit_;
+ QLineEdit * grid_line_edit_;
+ QAbstractButton * generate_messages_push_button_;
+ QAbstractButton * auto_off_button_;
+ QAbstractButton * halt_tx_button_;
+ QLabel * de_label_;
+ QLabel * frequency_label_;
+ QLabel * tx_df_label_;
+ QLabel * report_label_;
+ QLineEdit * configuration_line_edit_;
+ QLineEdit * mode_line_edit_;
+ QSpinBox * frequency_tolerance_spin_box_;
+ QLabel * tx_mode_label_;
+ QLabel * tx_message_label_;
+ QLineEdit * submode_line_edit_;
+ QCheckBox * fast_mode_check_box_;
+ QSpinBox * tr_period_spin_box_;
+ QSpinBox * rx_df_spin_box_;
+ QLineEdit * dx_call_line_edit_;
+ QLineEdit * dx_grid_line_edit_;
+ QWidget * decodes_page_;
+ QWidget * beacons_page_;
+ QFrame * content_widget_;
+ QStatusBar * status_bar_;
+ QDialogButtonBox * control_button_box_;
+
+ QFormLayout * form_layout_;
+ QHBoxLayout * horizontal_layout_;
+ QFormLayout * subform1_layout_;
+ QFormLayout * subform2_layout_;
+ QFormLayout * subform3_layout_;
+ QVBoxLayout * decodes_layout_;
+ QVBoxLayout * beacons_layout_;
+ QVBoxLayout * content_layout_;
+ QStackedLayout * decodes_stack_;
+
+ bool columns_resized_;
+};
+
+#endif
diff --git a/UDPExamples/DecodesModel.cpp b/UDPExamples/DecodesModel.cpp index 7b8d87c5..2e3cc921 100755 --- a/UDPExamples/DecodesModel.cpp +++ b/UDPExamples/DecodesModel.cpp @@ -1,157 +1,157 @@ -#include "DecodesModel.hpp" - -#include <QStandardItem> -#include <QModelIndex> -#include <QVariant> -#include <QTime> -#include <QString> -#include <QFont> -#include <QList> - -namespace -{ - char const * const headings[] = { - QT_TRANSLATE_NOOP ("DecodesModel", "Client"), - QT_TRANSLATE_NOOP ("DecodesModel", "Time"), - QT_TRANSLATE_NOOP ("DecodesModel", "Snr"), - QT_TRANSLATE_NOOP ("DecodesModel", "DT"), - QT_TRANSLATE_NOOP ("DecodesModel", "DF"), - QT_TRANSLATE_NOOP ("DecodesModel", "Md"), - QT_TRANSLATE_NOOP ("DecodesModel", "Confidence"), - QT_TRANSLATE_NOOP ("DecodesModel", "Live"), - QT_TRANSLATE_NOOP ("DecodesModel", "Message"), - }; - - QString confidence_string (bool low_confidence) - { - return low_confidence ? QT_TRANSLATE_NOOP ("DecodesModel", "low") : QT_TRANSLATE_NOOP ("DecodesModel", "high"); - } - - QString live_string (bool off_air) - { - return off_air ? QT_TRANSLATE_NOOP ("DecodesModel", "no") : QT_TRANSLATE_NOOP ("DecodesModel", "yes"); - } - - QFont text_font {"Courier", 10}; - - QList<QStandardItem *> make_row (MessageServer::ClientKey const& key, QTime time, qint32 snr - , float delta_time, quint32 delta_frequency, QString const& mode - , QString const& message, bool low_confidence, bool off_air, bool is_fast) - { - auto client_item = new QStandardItem {QString {"%1(%2)"}.arg (key.second).arg (key.first.toString ())}; - client_item->setData (QVariant::fromValue (key)); - - auto time_item = new QStandardItem {time.toString (is_fast || "~" == mode ? "hh:mm:ss" : "hh:mm")}; - time_item->setData (time); - time_item->setTextAlignment (Qt::AlignRight); - - auto snr_item = new QStandardItem {QString::number (snr)}; - snr_item->setData (snr); - snr_item->setTextAlignment (Qt::AlignRight); - - auto dt = new QStandardItem {QString::number (delta_time)}; - dt->setData (delta_time); - dt->setTextAlignment (Qt::AlignRight); - - auto df = new QStandardItem {QString::number (delta_frequency)}; - df->setData (delta_frequency); - df->setTextAlignment (Qt::AlignRight); - - auto md = new QStandardItem {mode}; - md->setTextAlignment (Qt::AlignHCenter); - - auto confidence = new QStandardItem {confidence_string (low_confidence)}; - confidence->setTextAlignment (Qt::AlignHCenter); - - auto live = new QStandardItem {live_string (off_air)}; - live->setTextAlignment (Qt::AlignHCenter); - - QList<QStandardItem *> row { - client_item, time_item, snr_item, dt, df, md, confidence, live, new QStandardItem {message}}; - Q_FOREACH (auto& item, row) - { - item->setEditable (false); - item->setFont (text_font); - item->setTextAlignment (item->textAlignment () | Qt::AlignVCenter); - } - return row; - } -} - -DecodesModel::DecodesModel (QObject * parent) - : QStandardItemModel {0, sizeof headings / sizeof headings[0], parent} -{ - int column {0}; - for (auto const& heading : headings) - { - setHeaderData (column++, Qt::Horizontal, tr (heading)); - } -} - -void DecodesModel::add_decode (bool is_new, ClientKey const& key, QTime time, qint32 snr, float delta_time - , quint32 delta_frequency, QString const& mode, QString const& message - , bool low_confidence, bool off_air, bool is_fast) -{ - if (!is_new) - { - int target_row {-1}; - for (auto row = 0; row < rowCount (); ++row) - { - if (item (row, 0)->data ().value<ClientKey> () == key) - { - auto row_time = item (row, 1)->data ().toTime (); - if (row_time == time - && item (row, 2)->data ().toInt () == snr - && item (row, 3)->data ().toFloat () == delta_time - && item (row, 4)->data ().toUInt () == delta_frequency - && data (index (row, 5)).toString () == mode - && data (index (row, 7)).toString () == confidence_string (low_confidence) - && data (index (row, 6)).toString () == live_string (off_air) - && data (index (row, 8)).toString () == message) - { - return; - } - if (time <= row_time) - { - target_row = row; // last row with same time - } - } - } - if (target_row >= 0) - { - insertRow (target_row + 1, make_row (key, time, snr, delta_time, delta_frequency, mode - , message, low_confidence, off_air, is_fast)); - return; - } - } - - appendRow (make_row (key, time, snr, delta_time, delta_frequency, mode, message, low_confidence - , off_air, is_fast)); -} - -void DecodesModel::decodes_cleared (ClientKey const& key) -{ - for (auto row = rowCount () - 1; row >= 0; --row) - { - if (item (row, 0)->data ().value<ClientKey> () == key) - { - removeRow (row); - } - } -} - -void DecodesModel::do_reply (QModelIndex const& source, quint8 modifiers) -{ - auto row = source.row (); - Q_EMIT reply (item (row, 0)->data ().value<ClientKey> () - , item (row, 1)->data ().toTime () - , item (row, 2)->data ().toInt () - , item (row, 3)->data ().toFloat () - , item (row, 4)->data ().toInt () - , data (index (row, 5)).toString () - , data (index (row, 8)).toString () - , confidence_string (true) == data (index (row, 7)).toString () - , modifiers); -} - -#include "moc_DecodesModel.cpp" +#include "DecodesModel.hpp"
+
+#include <QStandardItem>
+#include <QModelIndex>
+#include <QVariant>
+#include <QTime>
+#include <QString>
+#include <QFont>
+#include <QList>
+
+namespace
+{
+ char const * const headings[] = {
+ QT_TRANSLATE_NOOP ("DecodesModel", "Client"),
+ QT_TRANSLATE_NOOP ("DecodesModel", "Time"),
+ QT_TRANSLATE_NOOP ("DecodesModel", "Snr"),
+ QT_TRANSLATE_NOOP ("DecodesModel", "DT"),
+ QT_TRANSLATE_NOOP ("DecodesModel", "DF"),
+ QT_TRANSLATE_NOOP ("DecodesModel", "Md"),
+ QT_TRANSLATE_NOOP ("DecodesModel", "Confidence"),
+ QT_TRANSLATE_NOOP ("DecodesModel", "Live"),
+ QT_TRANSLATE_NOOP ("DecodesModel", "Message"),
+ };
+
+ QString confidence_string (bool low_confidence)
+ {
+ return low_confidence ? QT_TRANSLATE_NOOP ("DecodesModel", "low") : QT_TRANSLATE_NOOP ("DecodesModel", "high");
+ }
+
+ QString live_string (bool off_air)
+ {
+ return off_air ? QT_TRANSLATE_NOOP ("DecodesModel", "no") : QT_TRANSLATE_NOOP ("DecodesModel", "yes");
+ }
+
+ QFont text_font {"Courier", 10};
+
+ QList<QStandardItem *> make_row (MessageServer::ClientKey const& key, QTime time, qint32 snr
+ , float delta_time, quint32 delta_frequency, QString const& mode
+ , QString const& message, bool low_confidence, bool off_air, bool is_fast)
+ {
+ auto client_item = new QStandardItem {QString {"%1(%2)"}.arg (key.second).arg (key.first.toString ())};
+ client_item->setData (QVariant::fromValue (key));
+
+ auto time_item = new QStandardItem {time.toString (is_fast || "~" == mode ? "hh:mm:ss" : "hh:mm")};
+ time_item->setData (time);
+ time_item->setTextAlignment (Qt::AlignRight);
+
+ auto snr_item = new QStandardItem {QString::number (snr)};
+ snr_item->setData (snr);
+ snr_item->setTextAlignment (Qt::AlignRight);
+
+ auto dt = new QStandardItem {QString::number (delta_time)};
+ dt->setData (delta_time);
+ dt->setTextAlignment (Qt::AlignRight);
+
+ auto df = new QStandardItem {QString::number (delta_frequency)};
+ df->setData (delta_frequency);
+ df->setTextAlignment (Qt::AlignRight);
+
+ auto md = new QStandardItem {mode};
+ md->setTextAlignment (Qt::AlignHCenter);
+
+ auto confidence = new QStandardItem {confidence_string (low_confidence)};
+ confidence->setTextAlignment (Qt::AlignHCenter);
+
+ auto live = new QStandardItem {live_string (off_air)};
+ live->setTextAlignment (Qt::AlignHCenter);
+
+ QList<QStandardItem *> row {
+ client_item, time_item, snr_item, dt, df, md, confidence, live, new QStandardItem {message}};
+ Q_FOREACH (auto& item, row)
+ {
+ item->setEditable (false);
+ item->setFont (text_font);
+ item->setTextAlignment (item->textAlignment () | Qt::AlignVCenter);
+ }
+ return row;
+ }
+}
+
+DecodesModel::DecodesModel (QObject * parent)
+ : QStandardItemModel {0, sizeof headings / sizeof headings[0], parent}
+{
+ int column {0};
+ for (auto const& heading : headings)
+ {
+ setHeaderData (column++, Qt::Horizontal, tr (heading));
+ }
+}
+
+void DecodesModel::add_decode (bool is_new, ClientKey const& key, QTime time, qint32 snr, float delta_time
+ , quint32 delta_frequency, QString const& mode, QString const& message
+ , bool low_confidence, bool off_air, bool is_fast)
+{
+ if (!is_new)
+ {
+ int target_row {-1};
+ for (auto row = 0; row < rowCount (); ++row)
+ {
+ if (item (row, 0)->data ().value<ClientKey> () == key)
+ {
+ auto row_time = item (row, 1)->data ().toTime ();
+ if (row_time == time
+ && item (row, 2)->data ().toInt () == snr
+ && item (row, 3)->data ().toFloat () == delta_time
+ && item (row, 4)->data ().toUInt () == delta_frequency
+ && data (index (row, 5)).toString () == mode
+ && data (index (row, 7)).toString () == confidence_string (low_confidence)
+ && data (index (row, 6)).toString () == live_string (off_air)
+ && data (index (row, 8)).toString () == message)
+ {
+ return;
+ }
+ if (time <= row_time)
+ {
+ target_row = row; // last row with same time
+ }
+ }
+ }
+ if (target_row >= 0)
+ {
+ insertRow (target_row + 1, make_row (key, time, snr, delta_time, delta_frequency, mode
+ , message, low_confidence, off_air, is_fast));
+ return;
+ }
+ }
+
+ appendRow (make_row (key, time, snr, delta_time, delta_frequency, mode, message, low_confidence
+ , off_air, is_fast));
+}
+
+void DecodesModel::decodes_cleared (ClientKey const& key)
+{
+ for (auto row = rowCount () - 1; row >= 0; --row)
+ {
+ if (item (row, 0)->data ().value<ClientKey> () == key)
+ {
+ removeRow (row);
+ }
+ }
+}
+
+void DecodesModel::do_reply (QModelIndex const& source, quint8 modifiers)
+{
+ auto row = source.row ();
+ Q_EMIT reply (item (row, 0)->data ().value<ClientKey> ()
+ , item (row, 1)->data ().toTime ()
+ , item (row, 2)->data ().toInt ()
+ , item (row, 3)->data ().toFloat ()
+ , item (row, 4)->data ().toInt ()
+ , data (index (row, 5)).toString ()
+ , data (index (row, 8)).toString ()
+ , confidence_string (true) == data (index (row, 7)).toString ()
+ , modifiers);
+}
+
+#include "moc_DecodesModel.cpp"
diff --git a/UDPExamples/DecodesModel.hpp b/UDPExamples/DecodesModel.hpp index 27a168c8..6eef96aa 100755 --- a/UDPExamples/DecodesModel.hpp +++ b/UDPExamples/DecodesModel.hpp @@ -1,44 +1,44 @@ -#ifndef WSJTX_UDP_DECODES_MODEL_HPP__ -#define WSJTX_UDP_DECODES_MODEL_HPP__ - -#include <QStandardItemModel> - -#include "MessageServer.hpp" - -class QTime; -class QString; -class QModelIndex; - -// -// Decodes Model - simple data model for all decodes -// -// The model is a basic table with uniform row format. Rows consist of -// QStandardItem instances containing the string representation of the -// column data and if the underlying field is not a string then the -// UserRole+1 role contains the underlying data item. -// -// Three slots are provided to add a new decode, remove all decodes -// for a client and, to build a reply to CQ message for a given row -// which is emitted as a signal respectively. -// -class DecodesModel - : public QStandardItemModel -{ - Q_OBJECT; - - using ClientKey = MessageServer::ClientKey; - -public: - explicit DecodesModel (QObject * parent = nullptr); - - Q_SLOT void add_decode (bool is_new, ClientKey const&, QTime, qint32 snr, float delta_time - , quint32 delta_frequency, QString const& mode, QString const& message - , bool low_confidence, bool off_air, bool is_fast); - Q_SLOT void decodes_cleared (ClientKey const&); - Q_SLOT void do_reply (QModelIndex const& source, quint8 modifiers); - - Q_SIGNAL void reply (ClientKey const&, QTime, qint32 snr, float delta_time, quint32 delta_frequency - , QString const& mode, QString const& message, bool low_confidence, quint8 modifiers); -}; - -#endif +#ifndef WSJTX_UDP_DECODES_MODEL_HPP__
+#define WSJTX_UDP_DECODES_MODEL_HPP__
+
+#include <QStandardItemModel>
+
+#include "MessageServer.hpp"
+
+class QTime;
+class QString;
+class QModelIndex;
+
+//
+// Decodes Model - simple data model for all decodes
+//
+// The model is a basic table with uniform row format. Rows consist of
+// QStandardItem instances containing the string representation of the
+// column data and if the underlying field is not a string then the
+// UserRole+1 role contains the underlying data item.
+//
+// Three slots are provided to add a new decode, remove all decodes
+// for a client and, to build a reply to CQ message for a given row
+// which is emitted as a signal respectively.
+//
+class DecodesModel
+ : public QStandardItemModel
+{
+ Q_OBJECT;
+
+ using ClientKey = MessageServer::ClientKey;
+
+public:
+ explicit DecodesModel (QObject * parent = nullptr);
+
+ Q_SLOT void add_decode (bool is_new, ClientKey const&, QTime, qint32 snr, float delta_time
+ , quint32 delta_frequency, QString const& mode, QString const& message
+ , bool low_confidence, bool off_air, bool is_fast);
+ Q_SLOT void decodes_cleared (ClientKey const&);
+ Q_SLOT void do_reply (QModelIndex const& source, quint8 modifiers);
+
+ Q_SIGNAL void reply (ClientKey const&, QTime, qint32 snr, float delta_time, quint32 delta_frequency
+ , QString const& mode, QString const& message, bool low_confidence, quint8 modifiers);
+};
+
+#endif
diff --git a/UDPExamples/MessageAggregator.cpp b/UDPExamples/MessageAggregator.cpp index f44c036b..b18a89b3 100755 --- a/UDPExamples/MessageAggregator.cpp +++ b/UDPExamples/MessageAggregator.cpp @@ -1,104 +1,104 @@ -// -// MessageAggregator - an example application that utilizes the WSJT-X -// messaging facility -// -// This application is only provided as a simple GUI application -// example to demonstrate the WSJT-X messaging facility. It allows the -// user to set the server details either as a unicast UDP server or, -// if a multicast group address is provided, as a multicast server. -// The benefit of the multicast server is that multiple servers can be -// active at once each receiving all WSJT-X broadcast messages and -// each able to respond to individual WSJT_X clients. To utilize the -// multicast group features each WSJT-X client must set the same -// multicast group address as the UDP server address for example -// 239.255.0.0 for a site local multicast group. -// -// The UI is a small panel to input the service port number and -// optionally the multicast group address. Below that a table -// representing the log entries where any QSO logged messages -// broadcast from WSJT-X clients are displayed. The bottom of the -// application main window is a dock area where a dock window will -// appear for each WSJT-X client, this window contains a table of the -// current decode messages broadcast from that WSJT-X client and a -// status line showing the status update messages broadcast from the -// WSJT-X client. The dock windows may be arranged in a tab bar, side -// by side, below each other or, completely detached from the dock -// area as floating windows. Double clicking the dock window title bar -// or dragging and dropping with the mouse allows these different -// arrangements. -// -// The application also provides a simple menu bar including a view -// menu that allows each dock window to be hidden or revealed. -// - -#include <locale> -#include <iostream> -#include <exception> - -#include <QFile> -#include <QApplication> -#include <QMessageBox> -#include <QObject> - -#include "MessageAggregatorMainWindow.hpp" - -// deduce the size of an array -template<class T, size_t N> -inline -size_t size (T (&)[N]) {return N;} - -int main (int argc, char * argv[]) -{ - QApplication app {argc, argv}; - try - { - // ensure number forms are in consistent format, do this after - // instantiating QApplication so that GUI has correct l18n - std::locale::global (std::locale::classic ()); - - app.setApplicationName ("WSJT-X Reference UDP Message Aggregator Server"); - app.setApplicationVersion ("1.0"); - - QObject::connect (&app, SIGNAL (lastWindowClosed ()), &app, SLOT (quit ())); - - { - QString ss; - auto sf = qApp->styleSheet (); - if (sf.size ()) - { - sf.remove ("file:///"); - QFile file {sf}; - if (!file.open (QFile::ReadOnly)) - { - throw std::runtime_error { - QString {"failed to open \"" + file.fileName () + "\": " + file.errorString ()}.toStdString ()}; - } - ss += file.readAll (); - } - { - QFile file {":/qss/default.qss"}; - if (!file.open (QFile::ReadOnly)) - { - throw std::runtime_error { - QString {"failed to open \"" + file.fileName () + "\": " + file.errorString ()}.toStdString ()}; - } - ss += file.readAll (); - } - app.setStyleSheet (ss); - } - - MessageAggregatorMainWindow window; - return app.exec (); - } - catch (std::exception const & e) - { - QMessageBox::critical (nullptr, app.applicationName (), e.what ()); - std::cerr << "Error: " << e.what () << '\n'; - } - catch (...) - { - QMessageBox::critical (nullptr, app.applicationName (), QObject::tr ("Unexpected error")); - std::cerr << "Unexpected error\n"; - } - return -1; -} +//
+// MessageAggregator - an example application that utilizes the WSJT-X
+// messaging facility
+//
+// This application is only provided as a simple GUI application
+// example to demonstrate the WSJT-X messaging facility. It allows the
+// user to set the server details either as a unicast UDP server or,
+// if a multicast group address is provided, as a multicast server.
+// The benefit of the multicast server is that multiple servers can be
+// active at once each receiving all WSJT-X broadcast messages and
+// each able to respond to individual WSJT_X clients. To utilize the
+// multicast group features each WSJT-X client must set the same
+// multicast group address as the UDP server address for example
+// 239.255.0.0 for a site local multicast group.
+//
+// The UI is a small panel to input the service port number and
+// optionally the multicast group address. Below that a table
+// representing the log entries where any QSO logged messages
+// broadcast from WSJT-X clients are displayed. The bottom of the
+// application main window is a dock area where a dock window will
+// appear for each WSJT-X client, this window contains a table of the
+// current decode messages broadcast from that WSJT-X client and a
+// status line showing the status update messages broadcast from the
+// WSJT-X client. The dock windows may be arranged in a tab bar, side
+// by side, below each other or, completely detached from the dock
+// area as floating windows. Double clicking the dock window title bar
+// or dragging and dropping with the mouse allows these different
+// arrangements.
+//
+// The application also provides a simple menu bar including a view
+// menu that allows each dock window to be hidden or revealed.
+//
+
+#include <locale>
+#include <iostream>
+#include <exception>
+
+#include <QFile>
+#include <QApplication>
+#include <QMessageBox>
+#include <QObject>
+
+#include "MessageAggregatorMainWindow.hpp"
+
+// deduce the size of an array
+template<class T, size_t N>
+inline
+size_t size (T (&)[N]) {return N;}
+
+int main (int argc, char * argv[])
+{
+ QApplication app {argc, argv};
+ try
+ {
+ // ensure number forms are in consistent format, do this after
+ // instantiating QApplication so that GUI has correct l18n
+ std::locale::global (std::locale::classic ());
+
+ app.setApplicationName ("WSJT-X Reference UDP Message Aggregator Server");
+ app.setApplicationVersion ("1.0");
+
+ QObject::connect (&app, SIGNAL (lastWindowClosed ()), &app, SLOT (quit ()));
+
+ {
+ QString ss;
+ auto sf = qApp->styleSheet ();
+ if (sf.size ())
+ {
+ sf.remove ("file:///");
+ QFile file {sf};
+ if (!file.open (QFile::ReadOnly))
+ {
+ throw std::runtime_error {
+ QString {"failed to open \"" + file.fileName () + "\": " + file.errorString ()}.toStdString ()};
+ }
+ ss += file.readAll ();
+ }
+ {
+ QFile file {":/qss/default.qss"};
+ if (!file.open (QFile::ReadOnly))
+ {
+ throw std::runtime_error {
+ QString {"failed to open \"" + file.fileName () + "\": " + file.errorString ()}.toStdString ()};
+ }
+ ss += file.readAll ();
+ }
+ app.setStyleSheet (ss);
+ }
+
+ MessageAggregatorMainWindow window;
+ return app.exec ();
+ }
+ catch (std::exception const & e)
+ {
+ QMessageBox::critical (nullptr, app.applicationName (), e.what ());
+ std::cerr << "Error: " << e.what () << '\n';
+ }
+ catch (...)
+ {
+ QMessageBox::critical (nullptr, app.applicationName (), QObject::tr ("Unexpected error"));
+ std::cerr << "Unexpected error\n";
+ }
+ return -1;
+}
diff --git a/UDPExamples/MessageAggregatorMainWindow.cpp b/UDPExamples/MessageAggregatorMainWindow.cpp index 63b1e45b..2f40299e 100755 --- a/UDPExamples/MessageAggregatorMainWindow.cpp +++ b/UDPExamples/MessageAggregatorMainWindow.cpp @@ -1,403 +1,403 @@ -#include "MessageAggregatorMainWindow.hpp" - -#include <QtWidgets> -#include <QDateTime> -#include <QNetworkInterface> -#include <QSet> - -#include "DecodesModel.hpp" -#include "BeaconsModel.hpp" -#include "ClientWidget.hpp" - -using port_type = MessageServer::port_type; - -namespace -{ - char const * const headings[] = { - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Time On"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Time Off"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Callsign"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Grid"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Name"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Frequency"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Mode"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Sent"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Rec'd"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Power"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Operator"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "My Call"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "My Grid"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Exch Sent"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Exch Rcvd"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Prop"), - QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Comments"), - }; -} - -MessageAggregatorMainWindow::MessageAggregatorMainWindow () - : log_ {new QStandardItemModel {0, sizeof headings / sizeof headings[0], this}} - , decodes_model_ {new DecodesModel {this}} - , beacons_model_ {new BeaconsModel {this}} - , server_ {new MessageServer {this}} - , port_spin_box_ {new QSpinBox {this}} - , multicast_group_line_edit_ {new QLineEdit {this}} - , network_interfaces_combo_box_ {new CheckableItemComboBox {this}} - , log_table_view_ {new QTableView {this}} - , add_call_of_interest_action_ {new QAction {tr ("&Add callsign"), this}} - , delete_call_of_interest_action_ {new QAction {tr ("&Delete callsign"), this}} - , last_call_of_interest_action_ {new QAction {tr ("&Highlight last only"), this}} - , call_of_interest_bg_colour_action_ {new QAction {tr ("&Background colour"), this}} - , call_of_interest_fg_colour_action_ {new QAction {tr ("&Foreground colour"), this}} -{ - // logbook - int column {0}; - for (auto const& heading : headings) - { - log_->setHeaderData (column++, Qt::Horizontal, tr (heading)); - } - connect (server_, &MessageServer::qso_logged, this, &MessageAggregatorMainWindow::log_qso); - - // menu bar - auto file_menu = menuBar ()->addMenu (tr ("&File")); - - auto exit_action = new QAction {tr ("E&xit"), this}; - exit_action->setShortcuts (QKeySequence::Quit); - exit_action->setToolTip (tr ("Exit the application")); - file_menu->addAction (exit_action); - connect (exit_action, &QAction::triggered, this, &MessageAggregatorMainWindow::close); - - view_menu_ = menuBar ()->addMenu (tr ("&View")); - - // central layout - auto central_layout = new QVBoxLayout; - - // server details - port_spin_box_->setMinimum (1); - port_spin_box_->setMaximum (std::numeric_limits<port_type>::max ()); - auto group_box_layout = new QFormLayout; - group_box_layout->addRow (tr ("Port number:"), port_spin_box_); - group_box_layout->addRow (tr ("Multicast Group (blank for unicast server):"), multicast_group_line_edit_); - group_box_layout->addRow (tr ("Network interfaces:"), network_interfaces_combo_box_); - int row; - QFormLayout::ItemRole role; - group_box_layout->getWidgetPosition (network_interfaces_combo_box_, &row, &role); - Q_ASSERT (row >= 0); - network_interfaces_form_label_widget_ = static_cast<QLabel *> (group_box_layout->itemAt (row, QFormLayout::LabelRole)->widget ()); - network_interfaces_form_label_widget_->hide (); - network_interfaces_form_label_widget_->buddy ()->hide (); - connect (multicast_group_line_edit_, &QLineEdit::editingFinished, [this] { - if (multicast_group_line_edit_->text ().size ()) - { - network_interfaces_form_label_widget_->show (); - network_interfaces_form_label_widget_->buddy ()->show (); - } - else - { - network_interfaces_form_label_widget_->hide (); - network_interfaces_form_label_widget_->buddy ()->hide (); - } - }); - auto group_box = new QGroupBox {tr ("Server Details")}; - group_box->setLayout (group_box_layout); - central_layout->addWidget (group_box); - - // populate network interface list - for (auto const& net_if : QNetworkInterface::allInterfaces ()) - { - auto flags = QNetworkInterface::IsRunning | QNetworkInterface::CanMulticast; - if ((net_if.flags () & flags) == flags) - { - if (net_if.flags () & QNetworkInterface::IsLoopBack) - { - loopback_interface_name_ = net_if.name (); - } - auto item = network_interfaces_combo_box_->addCheckItem (net_if.humanReadableName () - , net_if.name () - , Qt::Unchecked); - auto tip = QString {"name(index): %1(%2) - %3"} - .arg (net_if.name ()).arg (net_if.index ()) - .arg (net_if.flags () & QNetworkInterface::IsUp ? "Up" : "Down"); - auto hw_addr = net_if.hardwareAddress (); - if (hw_addr.size ()) - { - tip += QString {"\nhw: %1"}.arg (net_if.hardwareAddress ()); - } - auto aes = net_if.addressEntries (); - if (aes.size ()) - { - tip += "\naddresses:"; - for (auto const& ae : aes) - { - tip += QString {"\n ip: %1/%2"}.arg (ae.ip ().toString ()).arg (ae.prefixLength ()); - } - } - item->setToolTip (tip); - } - } - connect (network_interfaces_combo_box_, &QComboBox::currentTextChanged, this, &MessageAggregatorMainWindow::validate_network_interfaces); - validate_network_interfaces (QString {}); - - log_table_view_->setModel (log_); - log_table_view_->verticalHeader ()->hide (); - central_layout->addWidget (log_table_view_); - - // central widget - auto central_widget = new QWidget; - central_widget->setLayout (central_layout); - - // main window setup - setCentralWidget (central_widget); - setDockOptions (AnimatedDocks | AllowNestedDocks | AllowTabbedDocks); - setTabPosition (Qt::BottomDockWidgetArea, QTabWidget::North); - - QDockWidget * calls_dock {new QDockWidget {tr ("Calls of Interest"), this}}; - calls_dock->setAllowedAreas (Qt::RightDockWidgetArea); - calls_of_interest_ = new QListWidget {calls_dock}; - calls_of_interest_->setContextMenuPolicy (Qt::ActionsContextMenu); - calls_of_interest_->insertAction (nullptr, add_call_of_interest_action_); - connect (add_call_of_interest_action_, &QAction::triggered, [this] () { - auto item = new QListWidgetItem {}; - item->setFlags (item->flags () | Qt::ItemIsEditable); - item->setData (Qt::UserRole, QString {}); - calls_of_interest_->addItem (item); - calls_of_interest_->editItem (item); - }); - calls_of_interest_->insertAction (nullptr, delete_call_of_interest_action_); - connect (delete_call_of_interest_action_, &QAction::triggered, [this] () { - for (auto item : calls_of_interest_->selectedItems ()) - { - auto old_call = item->data (Qt::UserRole); - if (old_call.isValid ()) change_highlighting (old_call.toString ()); - delete item; - } - }); - calls_of_interest_->insertAction (nullptr, last_call_of_interest_action_); - connect (last_call_of_interest_action_, &QAction::triggered, [this] () { - for (auto item : calls_of_interest_->selectedItems ()) - { - auto old_call = item->data (Qt::UserRole); - change_highlighting (old_call.toString ()); - change_highlighting (old_call.toString () - , item->background ().color (), item->foreground ().color (), true); - delete item; - } - }); - calls_of_interest_->insertAction (nullptr, call_of_interest_bg_colour_action_); - connect (call_of_interest_bg_colour_action_, &QAction::triggered, [this] () { - for (auto item : calls_of_interest_->selectedItems ()) - { - auto old_call = item->data (Qt::UserRole); - auto new_colour = QColorDialog::getColor (item->background ().color () - , this, tr ("Select background color")); - if (new_colour.isValid ()) - { - change_highlighting (old_call.toString (), new_colour, item->foreground ().color ()); - item->setBackground (new_colour); - } - } - }); - calls_of_interest_->insertAction (nullptr, call_of_interest_fg_colour_action_); - connect (call_of_interest_fg_colour_action_, &QAction::triggered, [this] () { - for (auto item : calls_of_interest_->selectedItems ()) - { - auto old_call = item->data (Qt::UserRole); - auto new_colour = QColorDialog::getColor (item->foreground ().color () - , this, tr ("Select foreground color")); - if (new_colour.isValid ()) - { - change_highlighting (old_call.toString (), item->background ().color (), new_colour); - item->setForeground (new_colour); - } - } - }); - connect (calls_of_interest_, &QListWidget::itemChanged, [this] (QListWidgetItem * item) { - auto old_call = item->data (Qt::UserRole); - auto new_call = item->text ().toUpper (); - if (new_call != old_call) - { - // tell all clients - if (old_call.isValid ()) - { - change_highlighting (old_call.toString ()); - } - item->setData (Qt::UserRole, new_call); - item->setText (new_call); - auto bg = item->listWidget ()->palette ().text ().color (); - auto fg = item->listWidget ()->palette ().base ().color (); - item->setBackground (bg); - item->setForeground (fg); - change_highlighting (new_call, bg, fg); - } - }); - - calls_dock->setWidget (calls_of_interest_); - addDockWidget (Qt::RightDockWidgetArea, calls_dock); - view_menu_->addAction (calls_dock->toggleViewAction ()); - view_menu_->addSeparator (); - - // connect up server - connect (server_, &MessageServer::error, [this] (QString const& message) { - QMessageBox::warning (this, QApplication::applicationName (), tr ("Network Error"), message); - }); - connect (server_, &MessageServer::client_opened, this, &MessageAggregatorMainWindow::add_client); - connect (server_, &MessageServer::client_closed, this, &MessageAggregatorMainWindow::remove_client); - connect (server_, &MessageServer::client_closed, decodes_model_, &DecodesModel::decodes_cleared); - connect (server_, &MessageServer::client_closed, beacons_model_, &BeaconsModel::decodes_cleared); - connect (server_, &MessageServer::decode, [this] (bool is_new, ClientKey const& key, QTime time - , qint32 snr, float delta_time - , quint32 delta_frequency, QString const& mode - , QString const& message, bool low_confidence - , bool off_air) { - decodes_model_->add_decode (is_new, key, time, snr, delta_time - , delta_frequency, mode, message - , low_confidence, off_air - , dock_widgets_[key]->fast_mode ()); - }); - connect (server_, &MessageServer::WSPR_decode, beacons_model_, &BeaconsModel::add_beacon_spot); - connect (server_, &MessageServer::decodes_cleared, decodes_model_, &DecodesModel::decodes_cleared); - connect (server_, &MessageServer::decodes_cleared, beacons_model_, &BeaconsModel::decodes_cleared); - connect (decodes_model_, &DecodesModel::reply, server_, &MessageServer::reply); - - // UI behaviour - connect (port_spin_box_, static_cast<void (QSpinBox::*)(int)> (&QSpinBox::valueChanged) - , [this] (int /*port*/) {restart_server ();}); - connect (multicast_group_line_edit_, &QLineEdit::editingFinished, [this] () {restart_server ();}); - connect (network_interfaces_combo_box_, &QComboBox::currentTextChanged, [this] () {restart_server ();}); - - port_spin_box_->setValue (2237); // start up in unicast mode - show (); -} - -void MessageAggregatorMainWindow::restart_server () -{ - QSet<QString> net_ifs; - if (network_interfaces_combo_box_->isVisible ()) - { - auto model = static_cast<QStandardItemModel *> (network_interfaces_combo_box_->model ()); - for (int row = 0; row < model->rowCount (); ++row) - { - if (Qt::Checked == model->item (row)->checkState ()) - { - net_ifs << model->item (row)->data ().toString (); - } - } - } - server_->start (port_spin_box_->value () - , QHostAddress {multicast_group_line_edit_->text ()} - , net_ifs); -} - -void MessageAggregatorMainWindow::log_qso (ClientKey const& /*key*/, 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& operator_call - , QString const& my_call, QString const& my_grid - , QString const& exchange_sent, QString const& exchange_rcvd - , QString const& prop_mode) -{ - QList<QStandardItem *> row; - row << new QStandardItem {time_on.toString ("dd-MMM-yyyy hh:mm:ss")} - << new QStandardItem {time_off.toString ("dd-MMM-yyyy hh:mm:ss")} - << new QStandardItem {dx_call} - << new QStandardItem {dx_grid} - << new QStandardItem {name} - << new QStandardItem {Radio::frequency_MHz_string (dial_frequency)} - << new QStandardItem {mode} - << new QStandardItem {report_sent} - << new QStandardItem {report_received} - << new QStandardItem {tx_power} - << new QStandardItem {operator_call} - << new QStandardItem {my_call} - << new QStandardItem {my_grid} - << new QStandardItem {exchange_sent} - << new QStandardItem {exchange_rcvd} - << new QStandardItem {prop_mode} - << new QStandardItem {comments}; - log_->appendRow (row); - log_table_view_->resizeColumnsToContents (); - log_table_view_->horizontalHeader ()->setStretchLastSection (true); - log_table_view_->scrollToBottom (); -} - -void MessageAggregatorMainWindow::add_client (ClientKey const& key, QString const& version, QString const& revision) -{ - auto dock = new ClientWidget {decodes_model_, beacons_model_, key, version, revision, calls_of_interest_, this}; - dock->setAttribute (Qt::WA_DeleteOnClose); - auto view_action = dock->toggleViewAction (); - view_action->setEnabled (true); - view_menu_->addAction (view_action); - addDockWidget (Qt::BottomDockWidgetArea, dock); - connect (server_, &MessageServer::status_update, dock, &ClientWidget::update_status); - connect (server_, &MessageServer::decode, dock, &ClientWidget::decode_added); - connect (server_, &MessageServer::WSPR_decode, dock, &ClientWidget::beacon_spot_added); - connect (server_, &MessageServer::decodes_cleared, dock, &ClientWidget::decodes_cleared); - connect (dock, &ClientWidget::do_clear_decodes, server_, &MessageServer::clear_decodes); - connect (dock, &ClientWidget::do_close, server_, &MessageServer::close); - connect (dock, &ClientWidget::do_reply, decodes_model_, &DecodesModel::do_reply); - connect (dock, &ClientWidget::do_halt_tx, server_, &MessageServer::halt_tx); - connect (dock, &ClientWidget::do_free_text, server_, &MessageServer::free_text); - connect (dock, &ClientWidget::location, server_, &MessageServer::location); - connect (view_action, &QAction::toggled, dock, &ClientWidget::setVisible); - connect (dock, &ClientWidget::highlight_callsign, server_, &MessageServer::highlight_callsign); - connect (dock, &ClientWidget::switch_configuration, server_, &MessageServer::switch_configuration); - connect (dock, &ClientWidget::configure, server_, &MessageServer::configure); - dock_widgets_[key] = dock; - server_->replay (key); // request decodes and status -} - -void MessageAggregatorMainWindow::remove_client (ClientKey const& key) -{ - auto iter = dock_widgets_.find (key); - if (iter != std::end (dock_widgets_)) - { - (*iter)->dispose (); - dock_widgets_.erase (iter); - } -} - -MessageAggregatorMainWindow::~MessageAggregatorMainWindow () -{ - for (auto client : dock_widgets_) - { - delete client; - } -} - -void MessageAggregatorMainWindow::change_highlighting (QString const& call, QColor const& bg, QColor const& fg - , bool last_only) -{ - for (auto key : dock_widgets_.keys ()) - { - server_->highlight_callsign (key, call, bg, fg, last_only); - } -} - -void MessageAggregatorMainWindow::validate_network_interfaces (QString const& /*text*/) -{ - auto model = static_cast<QStandardItemModel *> (network_interfaces_combo_box_->model ()); - bool has_checked {false}; - int loopback_row {-1}; - for (int row = 0; row < model->rowCount (); ++row) - { - if (model->item (row)->data ().toString () == loopback_interface_name_) - { - loopback_row = row; - } - else if (Qt::Checked == model->item (row)->checkState ()) - { - has_checked = true; - } - } - if (loopback_row >= 0) - { - if (!has_checked) - { - model->item (loopback_row)->setCheckState (Qt::Checked); - } - model->item (loopback_row)->setEnabled (has_checked); - } -} - -#include "moc_MessageAggregatorMainWindow.cpp" +#include "MessageAggregatorMainWindow.hpp"
+
+#include <QtWidgets>
+#include <QDateTime>
+#include <QNetworkInterface>
+#include <QSet>
+
+#include "DecodesModel.hpp"
+#include "BeaconsModel.hpp"
+#include "ClientWidget.hpp"
+
+using port_type = MessageServer::port_type;
+
+namespace
+{
+ char const * const headings[] = {
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Time On"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Time Off"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Callsign"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Grid"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Name"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Frequency"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Mode"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Sent"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Rec'd"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Power"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Operator"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "My Call"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "My Grid"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Exch Sent"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Exch Rcvd"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Prop"),
+ QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Comments"),
+ };
+}
+
+MessageAggregatorMainWindow::MessageAggregatorMainWindow ()
+ : log_ {new QStandardItemModel {0, sizeof headings / sizeof headings[0], this}}
+ , decodes_model_ {new DecodesModel {this}}
+ , beacons_model_ {new BeaconsModel {this}}
+ , server_ {new MessageServer {this}}
+ , port_spin_box_ {new QSpinBox {this}}
+ , multicast_group_line_edit_ {new QLineEdit {this}}
+ , network_interfaces_combo_box_ {new CheckableItemComboBox {this}}
+ , log_table_view_ {new QTableView {this}}
+ , add_call_of_interest_action_ {new QAction {tr ("&Add callsign"), this}}
+ , delete_call_of_interest_action_ {new QAction {tr ("&Delete callsign"), this}}
+ , last_call_of_interest_action_ {new QAction {tr ("&Highlight last only"), this}}
+ , call_of_interest_bg_colour_action_ {new QAction {tr ("&Background colour"), this}}
+ , call_of_interest_fg_colour_action_ {new QAction {tr ("&Foreground colour"), this}}
+{
+ // logbook
+ int column {0};
+ for (auto const& heading : headings)
+ {
+ log_->setHeaderData (column++, Qt::Horizontal, tr (heading));
+ }
+ connect (server_, &MessageServer::qso_logged, this, &MessageAggregatorMainWindow::log_qso);
+
+ // menu bar
+ auto file_menu = menuBar ()->addMenu (tr ("&File"));
+
+ auto exit_action = new QAction {tr ("E&xit"), this};
+ exit_action->setShortcuts (QKeySequence::Quit);
+ exit_action->setToolTip (tr ("Exit the application"));
+ file_menu->addAction (exit_action);
+ connect (exit_action, &QAction::triggered, this, &MessageAggregatorMainWindow::close);
+
+ view_menu_ = menuBar ()->addMenu (tr ("&View"));
+
+ // central layout
+ auto central_layout = new QVBoxLayout;
+
+ // server details
+ port_spin_box_->setMinimum (1);
+ port_spin_box_->setMaximum (std::numeric_limits<port_type>::max ());
+ auto group_box_layout = new QFormLayout;
+ group_box_layout->addRow (tr ("Port number:"), port_spin_box_);
+ group_box_layout->addRow (tr ("Multicast Group (blank for unicast server):"), multicast_group_line_edit_);
+ group_box_layout->addRow (tr ("Network interfaces:"), network_interfaces_combo_box_);
+ int row;
+ QFormLayout::ItemRole role;
+ group_box_layout->getWidgetPosition (network_interfaces_combo_box_, &row, &role);
+ Q_ASSERT (row >= 0);
+ network_interfaces_form_label_widget_ = static_cast<QLabel *> (group_box_layout->itemAt (row, QFormLayout::LabelRole)->widget ());
+ network_interfaces_form_label_widget_->hide ();
+ network_interfaces_form_label_widget_->buddy ()->hide ();
+ connect (multicast_group_line_edit_, &QLineEdit::editingFinished, [this] {
+ if (multicast_group_line_edit_->text ().size ())
+ {
+ network_interfaces_form_label_widget_->show ();
+ network_interfaces_form_label_widget_->buddy ()->show ();
+ }
+ else
+ {
+ network_interfaces_form_label_widget_->hide ();
+ network_interfaces_form_label_widget_->buddy ()->hide ();
+ }
+ });
+ auto group_box = new QGroupBox {tr ("Server Details")};
+ group_box->setLayout (group_box_layout);
+ central_layout->addWidget (group_box);
+
+ // populate network interface list
+ for (auto const& net_if : QNetworkInterface::allInterfaces ())
+ {
+ auto flags = QNetworkInterface::IsRunning | QNetworkInterface::CanMulticast;
+ if ((net_if.flags () & flags) == flags)
+ {
+ if (net_if.flags () & QNetworkInterface::IsLoopBack)
+ {
+ loopback_interface_name_ = net_if.name ();
+ }
+ auto item = network_interfaces_combo_box_->addCheckItem (net_if.humanReadableName ()
+ , net_if.name ()
+ , Qt::Unchecked);
+ auto tip = QString {"name(index): %1(%2) - %3"}
+ .arg (net_if.name ()).arg (net_if.index ())
+ .arg (net_if.flags () & QNetworkInterface::IsUp ? "Up" : "Down");
+ auto hw_addr = net_if.hardwareAddress ();
+ if (hw_addr.size ())
+ {
+ tip += QString {"\nhw: %1"}.arg (net_if.hardwareAddress ());
+ }
+ auto aes = net_if.addressEntries ();
+ if (aes.size ())
+ {
+ tip += "\naddresses:";
+ for (auto const& ae : aes)
+ {
+ tip += QString {"\n ip: %1/%2"}.arg (ae.ip ().toString ()).arg (ae.prefixLength ());
+ }
+ }
+ item->setToolTip (tip);
+ }
+ }
+ connect (network_interfaces_combo_box_, &QComboBox::currentTextChanged, this, &MessageAggregatorMainWindow::validate_network_interfaces);
+ validate_network_interfaces (QString {});
+
+ log_table_view_->setModel (log_);
+ log_table_view_->verticalHeader ()->hide ();
+ central_layout->addWidget (log_table_view_);
+
+ // central widget
+ auto central_widget = new QWidget;
+ central_widget->setLayout (central_layout);
+
+ // main window setup
+ setCentralWidget (central_widget);
+ setDockOptions (AnimatedDocks | AllowNestedDocks | AllowTabbedDocks);
+ setTabPosition (Qt::BottomDockWidgetArea, QTabWidget::North);
+
+ QDockWidget * calls_dock {new QDockWidget {tr ("Calls of Interest"), this}};
+ calls_dock->setAllowedAreas (Qt::RightDockWidgetArea);
+ calls_of_interest_ = new QListWidget {calls_dock};
+ calls_of_interest_->setContextMenuPolicy (Qt::ActionsContextMenu);
+ calls_of_interest_->insertAction (nullptr, add_call_of_interest_action_);
+ connect (add_call_of_interest_action_, &QAction::triggered, [this] () {
+ auto item = new QListWidgetItem {};
+ item->setFlags (item->flags () | Qt::ItemIsEditable);
+ item->setData (Qt::UserRole, QString {});
+ calls_of_interest_->addItem (item);
+ calls_of_interest_->editItem (item);
+ });
+ calls_of_interest_->insertAction (nullptr, delete_call_of_interest_action_);
+ connect (delete_call_of_interest_action_, &QAction::triggered, [this] () {
+ for (auto item : calls_of_interest_->selectedItems ())
+ {
+ auto old_call = item->data (Qt::UserRole);
+ if (old_call.isValid ()) change_highlighting (old_call.toString ());
+ delete item;
+ }
+ });
+ calls_of_interest_->insertAction (nullptr, last_call_of_interest_action_);
+ connect (last_call_of_interest_action_, &QAction::triggered, [this] () {
+ for (auto item : calls_of_interest_->selectedItems ())
+ {
+ auto old_call = item->data (Qt::UserRole);
+ change_highlighting (old_call.toString ());
+ change_highlighting (old_call.toString ()
+ , item->background ().color (), item->foreground ().color (), true);
+ delete item;
+ }
+ });
+ calls_of_interest_->insertAction (nullptr, call_of_interest_bg_colour_action_);
+ connect (call_of_interest_bg_colour_action_, &QAction::triggered, [this] () {
+ for (auto item : calls_of_interest_->selectedItems ())
+ {
+ auto old_call = item->data (Qt::UserRole);
+ auto new_colour = QColorDialog::getColor (item->background ().color ()
+ , this, tr ("Select background color"));
+ if (new_colour.isValid ())
+ {
+ change_highlighting (old_call.toString (), new_colour, item->foreground ().color ());
+ item->setBackground (new_colour);
+ }
+ }
+ });
+ calls_of_interest_->insertAction (nullptr, call_of_interest_fg_colour_action_);
+ connect (call_of_interest_fg_colour_action_, &QAction::triggered, [this] () {
+ for (auto item : calls_of_interest_->selectedItems ())
+ {
+ auto old_call = item->data (Qt::UserRole);
+ auto new_colour = QColorDialog::getColor (item->foreground ().color ()
+ , this, tr ("Select foreground color"));
+ if (new_colour.isValid ())
+ {
+ change_highlighting (old_call.toString (), item->background ().color (), new_colour);
+ item->setForeground (new_colour);
+ }
+ }
+ });
+ connect (calls_of_interest_, &QListWidget::itemChanged, [this] (QListWidgetItem * item) {
+ auto old_call = item->data (Qt::UserRole);
+ auto new_call = item->text ().toUpper ();
+ if (new_call != old_call)
+ {
+ // tell all clients
+ if (old_call.isValid ())
+ {
+ change_highlighting (old_call.toString ());
+ }
+ item->setData (Qt::UserRole, new_call);
+ item->setText (new_call);
+ auto bg = item->listWidget ()->palette ().text ().color ();
+ auto fg = item->listWidget ()->palette ().base ().color ();
+ item->setBackground (bg);
+ item->setForeground (fg);
+ change_highlighting (new_call, bg, fg);
+ }
+ });
+
+ calls_dock->setWidget (calls_of_interest_);
+ addDockWidget (Qt::RightDockWidgetArea, calls_dock);
+ view_menu_->addAction (calls_dock->toggleViewAction ());
+ view_menu_->addSeparator ();
+
+ // connect up server
+ connect (server_, &MessageServer::error, [this] (QString const& message) {
+ QMessageBox::warning (this, QApplication::applicationName (), tr ("Network Error"), message);
+ });
+ connect (server_, &MessageServer::client_opened, this, &MessageAggregatorMainWindow::add_client);
+ connect (server_, &MessageServer::client_closed, this, &MessageAggregatorMainWindow::remove_client);
+ connect (server_, &MessageServer::client_closed, decodes_model_, &DecodesModel::decodes_cleared);
+ connect (server_, &MessageServer::client_closed, beacons_model_, &BeaconsModel::decodes_cleared);
+ connect (server_, &MessageServer::decode, [this] (bool is_new, ClientKey const& key, QTime time
+ , qint32 snr, float delta_time
+ , quint32 delta_frequency, QString const& mode
+ , QString const& message, bool low_confidence
+ , bool off_air) {
+ decodes_model_->add_decode (is_new, key, time, snr, delta_time
+ , delta_frequency, mode, message
+ , low_confidence, off_air
+ , dock_widgets_[key]->fast_mode ());
+ });
+ connect (server_, &MessageServer::WSPR_decode, beacons_model_, &BeaconsModel::add_beacon_spot);
+ connect (server_, &MessageServer::decodes_cleared, decodes_model_, &DecodesModel::decodes_cleared);
+ connect (server_, &MessageServer::decodes_cleared, beacons_model_, &BeaconsModel::decodes_cleared);
+ connect (decodes_model_, &DecodesModel::reply, server_, &MessageServer::reply);
+
+ // UI behaviour
+ connect (port_spin_box_, static_cast<void (QSpinBox::*)(int)> (&QSpinBox::valueChanged)
+ , [this] (int /*port*/) {restart_server ();});
+ connect (multicast_group_line_edit_, &QLineEdit::editingFinished, [this] () {restart_server ();});
+ connect (network_interfaces_combo_box_, &QComboBox::currentTextChanged, [this] () {restart_server ();});
+
+ port_spin_box_->setValue (2237); // start up in unicast mode
+ show ();
+}
+
+void MessageAggregatorMainWindow::restart_server ()
+{
+ QSet<QString> net_ifs;
+ if (network_interfaces_combo_box_->isVisible ())
+ {
+ auto model = static_cast<QStandardItemModel *> (network_interfaces_combo_box_->model ());
+ for (int row = 0; row < model->rowCount (); ++row)
+ {
+ if (Qt::Checked == model->item (row)->checkState ())
+ {
+ net_ifs << model->item (row)->data ().toString ();
+ }
+ }
+ }
+ server_->start (port_spin_box_->value ()
+ , QHostAddress {multicast_group_line_edit_->text ()}
+ , net_ifs);
+}
+
+void MessageAggregatorMainWindow::log_qso (ClientKey const& /*key*/, 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& operator_call
+ , QString const& my_call, QString const& my_grid
+ , QString const& exchange_sent, QString const& exchange_rcvd
+ , QString const& prop_mode)
+{
+ QList<QStandardItem *> row;
+ row << new QStandardItem {time_on.toString ("dd-MMM-yyyy hh:mm:ss")}
+ << new QStandardItem {time_off.toString ("dd-MMM-yyyy hh:mm:ss")}
+ << new QStandardItem {dx_call}
+ << new QStandardItem {dx_grid}
+ << new QStandardItem {name}
+ << new QStandardItem {Radio::frequency_MHz_string (dial_frequency)}
+ << new QStandardItem {mode}
+ << new QStandardItem {report_sent}
+ << new QStandardItem {report_received}
+ << new QStandardItem {tx_power}
+ << new QStandardItem {operator_call}
+ << new QStandardItem {my_call}
+ << new QStandardItem {my_grid}
+ << new QStandardItem {exchange_sent}
+ << new QStandardItem {exchange_rcvd}
+ << new QStandardItem {prop_mode}
+ << new QStandardItem {comments};
+ log_->appendRow (row);
+ log_table_view_->resizeColumnsToContents ();
+ log_table_view_->horizontalHeader ()->setStretchLastSection (true);
+ log_table_view_->scrollToBottom ();
+}
+
+void MessageAggregatorMainWindow::add_client (ClientKey const& key, QString const& version, QString const& revision)
+{
+ auto dock = new ClientWidget {decodes_model_, beacons_model_, key, version, revision, calls_of_interest_, this};
+ dock->setAttribute (Qt::WA_DeleteOnClose);
+ auto view_action = dock->toggleViewAction ();
+ view_action->setEnabled (true);
+ view_menu_->addAction (view_action);
+ addDockWidget (Qt::BottomDockWidgetArea, dock);
+ connect (server_, &MessageServer::status_update, dock, &ClientWidget::update_status);
+ connect (server_, &MessageServer::decode, dock, &ClientWidget::decode_added);
+ connect (server_, &MessageServer::WSPR_decode, dock, &ClientWidget::beacon_spot_added);
+ connect (server_, &MessageServer::decodes_cleared, dock, &ClientWidget::decodes_cleared);
+ connect (dock, &ClientWidget::do_clear_decodes, server_, &MessageServer::clear_decodes);
+ connect (dock, &ClientWidget::do_close, server_, &MessageServer::close);
+ connect (dock, &ClientWidget::do_reply, decodes_model_, &DecodesModel::do_reply);
+ connect (dock, &ClientWidget::do_halt_tx, server_, &MessageServer::halt_tx);
+ connect (dock, &ClientWidget::do_free_text, server_, &MessageServer::free_text);
+ connect (dock, &ClientWidget::location, server_, &MessageServer::location);
+ connect (view_action, &QAction::toggled, dock, &ClientWidget::setVisible);
+ connect (dock, &ClientWidget::highlight_callsign, server_, &MessageServer::highlight_callsign);
+ connect (dock, &ClientWidget::switch_configuration, server_, &MessageServer::switch_configuration);
+ connect (dock, &ClientWidget::configure, server_, &MessageServer::configure);
+ dock_widgets_[key] = dock;
+ server_->replay (key); // request decodes and status
+}
+
+void MessageAggregatorMainWindow::remove_client (ClientKey const& key)
+{
+ auto iter = dock_widgets_.find (key);
+ if (iter != std::end (dock_widgets_))
+ {
+ (*iter)->dispose ();
+ dock_widgets_.erase (iter);
+ }
+}
+
+MessageAggregatorMainWindow::~MessageAggregatorMainWindow ()
+{
+ for (auto client : dock_widgets_)
+ {
+ delete client;
+ }
+}
+
+void MessageAggregatorMainWindow::change_highlighting (QString const& call, QColor const& bg, QColor const& fg
+ , bool last_only)
+{
+ for (auto key : dock_widgets_.keys ())
+ {
+ server_->highlight_callsign (key, call, bg, fg, last_only);
+ }
+}
+
+void MessageAggregatorMainWindow::validate_network_interfaces (QString const& /*text*/)
+{
+ auto model = static_cast<QStandardItemModel *> (network_interfaces_combo_box_->model ());
+ bool has_checked {false};
+ int loopback_row {-1};
+ for (int row = 0; row < model->rowCount (); ++row)
+ {
+ if (model->item (row)->data ().toString () == loopback_interface_name_)
+ {
+ loopback_row = row;
+ }
+ else if (Qt::Checked == model->item (row)->checkState ())
+ {
+ has_checked = true;
+ }
+ }
+ if (loopback_row >= 0)
+ {
+ if (!has_checked)
+ {
+ model->item (loopback_row)->setCheckState (Qt::Checked);
+ }
+ model->item (loopback_row)->setEnabled (has_checked);
+ }
+}
+
+#include "moc_MessageAggregatorMainWindow.cpp"
diff --git a/UDPExamples/MessageAggregatorMainWindow.hpp b/UDPExamples/MessageAggregatorMainWindow.hpp index 71ab89ff..1f1d9ce6 100755 --- a/UDPExamples/MessageAggregatorMainWindow.hpp +++ b/UDPExamples/MessageAggregatorMainWindow.hpp @@ -1,74 +1,74 @@ -#ifndef WSJTX_MESSAGE_AGGREGATOR_MAIN_WINDOW_MODEL_HPP__ -#define WSJTX_MESSAGE_AGGREGATOR_MAIN_WINDOW_MODEL_HPP__ - -#include <QMainWindow> -#include <QHash> -#include <QString> - -#include "MessageServer.hpp" -#include "widgets/CheckableItemComboBox.hpp" - -class QDateTime; -class QStandardItemModel; -class QMenu; -class DecodesModel; -class BeaconsModel; -class QLineEdit; -class QTableView; -class ClientWidget; -class QListWidget; -class QLabel; -class QSpinBox; - -using Frequency = MessageServer::Frequency; - -class MessageAggregatorMainWindow - : public QMainWindow -{ - Q_OBJECT; - - using ClientKey = MessageServer::ClientKey; - -public: - MessageAggregatorMainWindow (); - ~MessageAggregatorMainWindow (); - - Q_SLOT void log_qso (ClientKey const&, 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& operator_call - , QString const& my_call, QString const& my_grid - , QString const& exchange_sent, QString const& exchange_rcvd, QString const& prop_mode); - -private: - void restart_server (); - void add_client (ClientKey const&, QString const& version, QString const& revision); - void remove_client (ClientKey const&); - void change_highlighting (QString const& call, QColor const& bg = QColor {}, QColor const& fg = QColor {}, - bool last_only = false); - Q_SLOT void validate_network_interfaces (QString const&); - - // maps client id to widgets - using ClientsDictionary = QHash<ClientKey, ClientWidget *>; - ClientsDictionary dock_widgets_; - - QStandardItemModel * log_; - QMenu * view_menu_; - DecodesModel * decodes_model_; - BeaconsModel * beacons_model_; - MessageServer * server_; - QSpinBox * port_spin_box_; - QLineEdit * multicast_group_line_edit_; - CheckableItemComboBox * network_interfaces_combo_box_; - QString loopback_interface_name_; - QLabel * network_interfaces_form_label_widget_; - QTableView * log_table_view_; - QListWidget * calls_of_interest_; - QAction * add_call_of_interest_action_; - QAction * delete_call_of_interest_action_; - QAction * last_call_of_interest_action_; - QAction * call_of_interest_bg_colour_action_; - QAction * call_of_interest_fg_colour_action_; -}; - -#endif +#ifndef WSJTX_MESSAGE_AGGREGATOR_MAIN_WINDOW_MODEL_HPP__
+#define WSJTX_MESSAGE_AGGREGATOR_MAIN_WINDOW_MODEL_HPP__
+
+#include <QMainWindow>
+#include <QHash>
+#include <QString>
+
+#include "MessageServer.hpp"
+#include "widgets/CheckableItemComboBox.hpp"
+
+class QDateTime;
+class QStandardItemModel;
+class QMenu;
+class DecodesModel;
+class BeaconsModel;
+class QLineEdit;
+class QTableView;
+class ClientWidget;
+class QListWidget;
+class QLabel;
+class QSpinBox;
+
+using Frequency = MessageServer::Frequency;
+
+class MessageAggregatorMainWindow
+ : public QMainWindow
+{
+ Q_OBJECT;
+
+ using ClientKey = MessageServer::ClientKey;
+
+public:
+ MessageAggregatorMainWindow ();
+ ~MessageAggregatorMainWindow ();
+
+ Q_SLOT void log_qso (ClientKey const&, 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& operator_call
+ , QString const& my_call, QString const& my_grid
+ , QString const& exchange_sent, QString const& exchange_rcvd, QString const& prop_mode);
+
+private:
+ void restart_server ();
+ void add_client (ClientKey const&, QString const& version, QString const& revision);
+ void remove_client (ClientKey const&);
+ void change_highlighting (QString const& call, QColor const& bg = QColor {}, QColor const& fg = QColor {},
+ bool last_only = false);
+ Q_SLOT void validate_network_interfaces (QString const&);
+
+ // maps client id to widgets
+ using ClientsDictionary = QHash<ClientKey, ClientWidget *>;
+ ClientsDictionary dock_widgets_;
+
+ QStandardItemModel * log_;
+ QMenu * view_menu_;
+ DecodesModel * decodes_model_;
+ BeaconsModel * beacons_model_;
+ MessageServer * server_;
+ QSpinBox * port_spin_box_;
+ QLineEdit * multicast_group_line_edit_;
+ CheckableItemComboBox * network_interfaces_combo_box_;
+ QString loopback_interface_name_;
+ QLabel * network_interfaces_form_label_widget_;
+ QTableView * log_table_view_;
+ QListWidget * calls_of_interest_;
+ QAction * add_call_of_interest_action_;
+ QAction * delete_call_of_interest_action_;
+ QAction * last_call_of_interest_action_;
+ QAction * call_of_interest_bg_colour_action_;
+ QAction * call_of_interest_fg_colour_action_;
+};
+
+#endif
diff --git a/UDPExamples/MessageServer.cpp b/UDPExamples/MessageServer.cpp index 74090395..3394db08 100755 --- a/UDPExamples/MessageServer.cpp +++ b/UDPExamples/MessageServer.cpp @@ -1,595 +1,595 @@ -#include "MessageServer.hpp" - -#include <stdexcept> -#include <limits> - -#include <QNetworkInterface> -#include <QUdpSocket> -#include <QTimer> -#include <QHash> - -#include "Radio.hpp" -#include "Network/NetworkMessage.hpp" -#include "qt_helpers.hpp" - -#include "pimpl_impl.hpp" - -#include "moc_MessageServer.cpp" - -namespace -{ - auto quint32_max = std::numeric_limits<quint32>::max (); -} - -class MessageServer::impl - : public QUdpSocket -{ - Q_OBJECT; - -public: - impl (MessageServer * self, QString const& version, QString const& revision) - : self_ {self} - , version_ {version} - , revision_ {revision} - , clock_ {new QTimer {this}} - { - // register the required types with Qt - Radio::register_types (); - - connect (this, &QIODevice::readyRead, this, &MessageServer::impl::pending_datagrams); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) - connect (this, static_cast<void (impl::*) (SocketError)> (&impl::error) - , [this] (SocketError /* e */) - { - Q_EMIT self_->error (errorString ()); - }); -#else - connect (this, &impl::errorOccurred, [this] (SocketError /* e */) - { - Q_EMIT self_->error (errorString ()); - }); -#endif - connect (clock_, &QTimer::timeout, this, &impl::tick); - clock_->start (NetworkMessage::pulse * 1000); - } - - enum StreamStatus {Fail, Short, OK}; - - void leave_multicast_group (); - void join_multicast_group (); - void parse_message (QHostAddress const& sender, port_type sender_port, QByteArray const& msg); - void tick (); - void pending_datagrams (); - StreamStatus check_status (QDataStream const&) const; - void send_message (QDataStream const& out, QByteArray const& message, QHostAddress const& address, port_type port) - { - if (OK == check_status (out)) - { - writeDatagram (message, address, port); - } - else - { - Q_EMIT self_->error ("Error creating UDP message"); - } - } - - MessageServer * self_; - QString version_; - QString revision_; - QHostAddress multicast_group_address_; - QSet<QString> network_interfaces_; - static BindMode constexpr bind_mode_ = ShareAddress | ReuseAddressHint; - struct Client - { - Client () = default; - Client (port_type const& sender_port) - : sender_port_ {sender_port} - , negotiated_schema_number_ {2} // not 1 because it's broken - , last_activity_ {QDateTime::currentDateTime ()} - { - } - Client (Client const&) = default; - Client& operator= (Client const&) = default; - - port_type sender_port_; - quint32 negotiated_schema_number_; - QDateTime last_activity_; - }; - QHash<ClientKey, Client> clients_; // maps id to Client - QTimer * clock_; -}; - -MessageServer::impl::BindMode constexpr MessageServer::impl::bind_mode_; - -#include "MessageServer.moc" - -void MessageServer::impl::leave_multicast_group () -{ - if (BoundState == state () && is_multicast_address (multicast_group_address_)) - { - for (auto const& if_name : network_interfaces_) - { - leaveMulticastGroup (multicast_group_address_, QNetworkInterface::interfaceFromName (if_name)); - } - } -} - -void MessageServer::impl::join_multicast_group () -{ - if (BoundState == state () && is_multicast_address (multicast_group_address_)) - { - if (network_interfaces_.size ()) - { - for (auto const& if_name : network_interfaces_) - { - joinMulticastGroup (multicast_group_address_, QNetworkInterface::interfaceFromName (if_name)); - } - } - else - { - // find the loop-back interface and join on that - for (auto const& net_if : QNetworkInterface::allInterfaces ()) - { - auto flags = QNetworkInterface::IsUp | QNetworkInterface::IsLoopBack | QNetworkInterface::CanMulticast; - if ((net_if.flags () & flags) == flags) - { - joinMulticastGroup (multicast_group_address_, net_if); - break; - } - } - } - } -} - -void MessageServer::impl::pending_datagrams () -{ - while (hasPendingDatagrams ()) - { - QByteArray datagram; - datagram.resize (pendingDatagramSize ()); - QHostAddress sender_address; - port_type sender_port; - if (0 <= readDatagram (datagram.data (), datagram.size (), &sender_address, &sender_port)) - { - parse_message (sender_address, sender_port, datagram); - } - } -} - -void MessageServer::impl::parse_message (QHostAddress const& sender, port_type sender_port, QByteArray const& msg) -{ - try - { - // - // message format is described in NetworkMessage.hpp - // - NetworkMessage::Reader in {msg}; - - auto id = in.id (); - if (OK == check_status (in)) - { - auto client_key = ClientKey {sender, id}; - if (!clients_.contains (client_key)) - { - auto& client = (clients_[client_key] = {sender_port}); - QByteArray client_version; - QByteArray client_revision; - - if (NetworkMessage::Heartbeat == in.type ()) - { - // negotiate a working schema number - in >> client.negotiated_schema_number_; - if (OK == check_status (in)) - { - auto sn = NetworkMessage::Builder::schema_number; - client.negotiated_schema_number_ = std::min (sn, client.negotiated_schema_number_); - - // reply to the new client informing it of the - // negotiated schema number - QByteArray message; - NetworkMessage::Builder hb {&message, NetworkMessage::Heartbeat, id, client.negotiated_schema_number_}; - hb << NetworkMessage::Builder::schema_number // maximum schema number accepted - << version_.toUtf8 () << revision_.toUtf8 (); - if (impl::OK == check_status (hb)) - { - writeDatagram (message, client_key.first, sender_port); - } - else - { - Q_EMIT self_->error ("Error creating UDP message"); - } - } - // we don't care if this fails to read - in >> client_version >> client_revision; - } - Q_EMIT self_->client_opened (client_key, QString::fromUtf8 (client_version), - QString::fromUtf8 (client_revision)); - } - clients_[client_key].last_activity_ = QDateTime::currentDateTime (); - - // - // message format is described in NetworkMessage.hpp - // - switch (in.type ()) - { - case NetworkMessage::Heartbeat: - //nothing to do here as time out handling deals with lifetime - break; - - case NetworkMessage::Clear: - Q_EMIT self_->decodes_cleared (client_key); - break; - - case NetworkMessage::Status: - { - // unpack message - Frequency f; - QByteArray mode; - QByteArray dx_call; - QByteArray report; - QByteArray tx_mode; - bool tx_enabled {false}; - bool transmitting {false}; - bool decoding {false}; - quint32 rx_df {quint32_max}; - quint32 tx_df {quint32_max}; - QByteArray de_call; - QByteArray de_grid; - QByteArray dx_grid; - bool watchdog_timeout {false}; - QByteArray sub_mode; - bool fast_mode {false}; - quint8 special_op_mode {0}; - quint32 frequency_tolerance {quint32_max}; - quint32 tr_period {quint32_max}; - QByteArray configuration_name; - QByteArray tx_message; - in >> f >> mode >> dx_call >> report >> tx_mode >> tx_enabled >> transmitting >> decoding - >> rx_df >> tx_df >> de_call >> de_grid >> dx_grid >> watchdog_timeout >> sub_mode - >> fast_mode >> special_op_mode >> frequency_tolerance >> tr_period >> configuration_name - >> tx_message; - if (check_status (in) != Fail) - { - Q_EMIT self_->status_update (client_key, f, QString::fromUtf8 (mode) - , QString::fromUtf8 (dx_call) - , QString::fromUtf8 (report), QString::fromUtf8 (tx_mode) - , tx_enabled, transmitting, decoding, rx_df, tx_df - , QString::fromUtf8 (de_call), QString::fromUtf8 (de_grid) - , QString::fromUtf8 (dx_grid), watchdog_timeout - , QString::fromUtf8 (sub_mode), fast_mode - , special_op_mode, frequency_tolerance, tr_period - , QString::fromUtf8 (configuration_name) - , QString::fromUtf8 (tx_message)); - } - } - break; - - case NetworkMessage::Decode: - { - // unpack message - bool is_new {true}; - QTime time; - qint32 snr; - float delta_time; - quint32 delta_frequency; - QByteArray mode; - QByteArray message; - bool low_confidence {false}; - bool off_air {false}; - in >> is_new >> time >> snr >> delta_time >> delta_frequency >> mode - >> message >> low_confidence >> off_air; - if (check_status (in) != Fail) - { - Q_EMIT self_->decode (is_new, client_key, time, snr, delta_time, delta_frequency - , QString::fromUtf8 (mode), QString::fromUtf8 (message) - , low_confidence, off_air); - } - } - break; - - case NetworkMessage::WSPRDecode: - { - // unpack message - bool is_new {true}; - QTime time; - qint32 snr; - float delta_time; - Frequency frequency; - qint32 drift; - QByteArray callsign; - QByteArray grid; - qint32 power; - bool off_air {false}; - in >> is_new >> time >> snr >> delta_time >> frequency >> drift >> callsign >> grid >> power - >> off_air; - if (check_status (in) != Fail) - { - Q_EMIT self_->WSPR_decode (is_new, client_key, time, snr, delta_time, frequency, drift - , QString::fromUtf8 (callsign), QString::fromUtf8 (grid) - , power, off_air); - } - } - break; - - case NetworkMessage::QSOLogged: - { - QDateTime time_off; - QByteArray dx_call; - QByteArray dx_grid; - Frequency dial_frequency; - QByteArray mode; - QByteArray report_sent; - QByteArray report_received; - QByteArray tx_power; - QByteArray comments; - QByteArray name; - QDateTime time_on; // Note: LOTW uses TIME_ON for their +/- 30-minute time window - QByteArray operator_call; - QByteArray my_call; - QByteArray my_grid; - QByteArray exchange_sent; - QByteArray exchange_rcvd; - QByteArray prop_mode; - in >> time_off >> dx_call >> dx_grid >> dial_frequency >> mode >> report_sent >> report_received - >> tx_power >> comments >> name >> time_on >> operator_call >> my_call >> my_grid - >> exchange_sent >> exchange_rcvd >> prop_mode; - if (check_status (in) != Fail) - { - Q_EMIT self_->qso_logged (client_key, time_off, QString::fromUtf8 (dx_call) - , QString::fromUtf8 (dx_grid) - , dial_frequency, QString::fromUtf8 (mode) - , QString::fromUtf8 (report_sent) - , QString::fromUtf8 (report_received), QString::fromUtf8 (tx_power) - , QString::fromUtf8 (comments), QString::fromUtf8 (name), time_on - , QString::fromUtf8 (operator_call), QString::fromUtf8 (my_call) - , QString::fromUtf8 (my_grid), QString::fromUtf8 (exchange_sent) - , QString::fromUtf8 (exchange_rcvd), QString::fromUtf8 (prop_mode)); - } - } - break; - - case NetworkMessage::Close: - Q_EMIT self_->client_closed (client_key); - clients_.remove (client_key); - break; - - case NetworkMessage::LoggedADIF: - { - QByteArray ADIF; - in >> ADIF; - if (check_status (in) != Fail) - { - Q_EMIT self_->logged_ADIF (client_key, ADIF); - } - } - break; - - default: - // Ignore - break; - } - } - else - { - Q_EMIT self_->error ("MessageServer warning: invalid UDP message received"); - } - } - catch (std::exception const& e) - { - Q_EMIT self_->error (QString {"MessageServer exception: %1"}.arg (e.what ())); - } - catch (...) - { - Q_EMIT self_->error ("Unexpected exception in MessageServer"); - } -} - -void MessageServer::impl::tick () -{ - auto now = QDateTime::currentDateTime (); - auto iter = std::begin (clients_); - while (iter != std::end (clients_)) - { - if (now > (*iter).last_activity_.addSecs (NetworkMessage::pulse)) - { - Q_EMIT self_->decodes_cleared (iter.key ()); - Q_EMIT self_->client_closed (iter.key ()); - iter = clients_.erase (iter); // safe while iterating as doesn't rehash - } - else - { - ++iter; - } - } -} - -auto MessageServer::impl::check_status (QDataStream const& stream) const -> StreamStatus -{ - auto stat = stream.status (); - StreamStatus result {Fail}; - switch (stat) - { - case QDataStream::ReadPastEnd: - result = Short; - break; - - case QDataStream::ReadCorruptData: - Q_EMIT self_->error ("Message serialization error: read corrupt data"); - break; - - case QDataStream::WriteFailed: - Q_EMIT self_->error ("Message serialization error: write error"); - break; - - default: - result = OK; - break; - } - return result; -} - -MessageServer::MessageServer (QObject * parent, QString const& version, QString const& revision) - : QObject {parent} - , m_ {this, version, revision} -{ -} - -void MessageServer::start (port_type port, QHostAddress const& multicast_group_address - , QSet<QString> const& network_interface_names) -{ - // qDebug () << "MessageServer::start port:" << port << "multicast addr:" << multicast_group_address.toString () << "network interfaces:" << network_interface_names; - if (port != m_->localPort () - || multicast_group_address != m_->multicast_group_address_ - || network_interface_names != m_->network_interfaces_) - { - m_->leave_multicast_group (); - if (impl::UnconnectedState != m_->state ()) - { - m_->close (); - } - if (!(multicast_group_address.isNull () || is_multicast_address (multicast_group_address))) - { - Q_EMIT error ("Invalid multicast group address"); - } - else if (is_MAC_ambiguous_multicast_address (multicast_group_address)) - { - Q_EMIT error ("MAC-ambiguous IPv4 multicast group address not supported"); - } - else - { - m_->multicast_group_address_ = multicast_group_address; - m_->network_interfaces_ = network_interface_names; - QHostAddress local_addr {is_multicast_address (multicast_group_address) - && impl::IPv4Protocol == multicast_group_address.protocol () ? QHostAddress::AnyIPv4 : QHostAddress::Any}; - if (port && m_->bind (local_addr, port, m_->bind_mode_)) - { - m_->join_multicast_group (); - } - } - } -} - -void MessageServer::clear_decodes (ClientKey const& key, quint8 window) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::Clear, key.second, (*iter).negotiated_schema_number_}; - out << window; - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} - -void MessageServer::reply (ClientKey const& key, QTime time, qint32 snr, float delta_time - , quint32 delta_frequency, QString const& mode - , QString const& message_text, bool low_confidence, quint8 modifiers) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::Reply, key.second, (*iter).negotiated_schema_number_}; - out << time << snr << delta_time << delta_frequency << mode.toUtf8 () - << message_text.toUtf8 () << low_confidence << modifiers; - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} - -void MessageServer::replay (ClientKey const& key) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::Replay, key.second, (*iter).negotiated_schema_number_}; - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} - -void MessageServer::close (ClientKey const& key) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::Close, key.second, (*iter).negotiated_schema_number_}; - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} - -void MessageServer::halt_tx (ClientKey const& key, bool auto_only) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::HaltTx, key.second, (*iter).negotiated_schema_number_}; - out << auto_only; - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} - -void MessageServer::free_text (ClientKey const& key, QString const& text, bool send) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::FreeText, key.second, (*iter).negotiated_schema_number_}; - out << text.toUtf8 () << send; - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} - -void MessageServer::location (ClientKey const& key, QString const& loc) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::Location, key.second, (*iter).negotiated_schema_number_}; - out << loc.toUtf8 (); - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} - -void MessageServer::highlight_callsign (ClientKey const& key, QString const& callsign - , QColor const& bg, QColor const& fg, bool last_only) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::HighlightCallsign, key.second, (*iter).negotiated_schema_number_}; - out << callsign.toUtf8 () << bg << fg << last_only; - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} - -void MessageServer::switch_configuration (ClientKey const& key, QString const& configuration_name) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::SwitchConfiguration, key.second, (*iter).negotiated_schema_number_}; - out << configuration_name.toUtf8 (); - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} - -void MessageServer::configure (ClientKey const& key, QString const& mode, quint32 frequency_tolerance - , QString const& submode, bool fast_mode, quint32 tr_period, quint32 rx_df - , QString const& dx_call, QString const& dx_grid, bool generate_messages) -{ - auto iter = m_->clients_.find (key); - if (iter != std::end (m_->clients_)) - { - QByteArray message; - NetworkMessage::Builder out {&message, NetworkMessage::Configure, key.second, (*iter).negotiated_schema_number_}; - out << mode.toUtf8 () << frequency_tolerance << submode.toUtf8 () << fast_mode << tr_period << rx_df - << dx_call.toUtf8 () << dx_grid.toUtf8 () << generate_messages; - m_->send_message (out, message, key.first, (*iter).sender_port_); - } -} +#include "MessageServer.hpp"
+
+#include <stdexcept>
+#include <limits>
+
+#include <QNetworkInterface>
+#include <QUdpSocket>
+#include <QTimer>
+#include <QHash>
+
+#include "Radio.hpp"
+#include "Network/NetworkMessage.hpp"
+#include "qt_helpers.hpp"
+
+#include "pimpl_impl.hpp"
+
+#include "moc_MessageServer.cpp"
+
+namespace
+{
+ auto quint32_max = std::numeric_limits<quint32>::max ();
+}
+
+class MessageServer::impl
+ : public QUdpSocket
+{
+ Q_OBJECT;
+
+public:
+ impl (MessageServer * self, QString const& version, QString const& revision)
+ : self_ {self}
+ , version_ {version}
+ , revision_ {revision}
+ , clock_ {new QTimer {this}}
+ {
+ // register the required types with Qt
+ Radio::register_types ();
+
+ connect (this, &QIODevice::readyRead, this, &MessageServer::impl::pending_datagrams);
+#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
+ connect (this, static_cast<void (impl::*) (SocketError)> (&impl::error)
+ , [this] (SocketError /* e */)
+ {
+ Q_EMIT self_->error (errorString ());
+ });
+#else
+ connect (this, &impl::errorOccurred, [this] (SocketError /* e */)
+ {
+ Q_EMIT self_->error (errorString ());
+ });
+#endif
+ connect (clock_, &QTimer::timeout, this, &impl::tick);
+ clock_->start (NetworkMessage::pulse * 1000);
+ }
+
+ enum StreamStatus {Fail, Short, OK};
+
+ void leave_multicast_group ();
+ void join_multicast_group ();
+ void parse_message (QHostAddress const& sender, port_type sender_port, QByteArray const& msg);
+ void tick ();
+ void pending_datagrams ();
+ StreamStatus check_status (QDataStream const&) const;
+ void send_message (QDataStream const& out, QByteArray const& message, QHostAddress const& address, port_type port)
+ {
+ if (OK == check_status (out))
+ {
+ writeDatagram (message, address, port);
+ }
+ else
+ {
+ Q_EMIT self_->error ("Error creating UDP message");
+ }
+ }
+
+ MessageServer * self_;
+ QString version_;
+ QString revision_;
+ QHostAddress multicast_group_address_;
+ QSet<QString> network_interfaces_;
+ static BindMode constexpr bind_mode_ = ShareAddress | ReuseAddressHint;
+ struct Client
+ {
+ Client () = default;
+ Client (port_type const& sender_port)
+ : sender_port_ {sender_port}
+ , negotiated_schema_number_ {2} // not 1 because it's broken
+ , last_activity_ {QDateTime::currentDateTime ()}
+ {
+ }
+ Client (Client const&) = default;
+ Client& operator= (Client const&) = default;
+
+ port_type sender_port_;
+ quint32 negotiated_schema_number_;
+ QDateTime last_activity_;
+ };
+ QHash<ClientKey, Client> clients_; // maps id to Client
+ QTimer * clock_;
+};
+
+MessageServer::impl::BindMode constexpr MessageServer::impl::bind_mode_;
+
+#include "MessageServer.moc"
+
+void MessageServer::impl::leave_multicast_group ()
+{
+ if (BoundState == state () && is_multicast_address (multicast_group_address_))
+ {
+ for (auto const& if_name : network_interfaces_)
+ {
+ leaveMulticastGroup (multicast_group_address_, QNetworkInterface::interfaceFromName (if_name));
+ }
+ }
+}
+
+void MessageServer::impl::join_multicast_group ()
+{
+ if (BoundState == state () && is_multicast_address (multicast_group_address_))
+ {
+ if (network_interfaces_.size ())
+ {
+ for (auto const& if_name : network_interfaces_)
+ {
+ joinMulticastGroup (multicast_group_address_, QNetworkInterface::interfaceFromName (if_name));
+ }
+ }
+ else
+ {
+ // find the loop-back interface and join on that
+ for (auto const& net_if : QNetworkInterface::allInterfaces ())
+ {
+ auto flags = QNetworkInterface::IsUp | QNetworkInterface::IsLoopBack | QNetworkInterface::CanMulticast;
+ if ((net_if.flags () & flags) == flags)
+ {
+ joinMulticastGroup (multicast_group_address_, net_if);
+ break;
+ }
+ }
+ }
+ }
+}
+
+void MessageServer::impl::pending_datagrams ()
+{
+ while (hasPendingDatagrams ())
+ {
+ QByteArray datagram;
+ datagram.resize (pendingDatagramSize ());
+ QHostAddress sender_address;
+ port_type sender_port;
+ if (0 <= readDatagram (datagram.data (), datagram.size (), &sender_address, &sender_port))
+ {
+ parse_message (sender_address, sender_port, datagram);
+ }
+ }
+}
+
+void MessageServer::impl::parse_message (QHostAddress const& sender, port_type sender_port, QByteArray const& msg)
+{
+ try
+ {
+ //
+ // message format is described in NetworkMessage.hpp
+ //
+ NetworkMessage::Reader in {msg};
+
+ auto id = in.id ();
+ if (OK == check_status (in))
+ {
+ auto client_key = ClientKey {sender, id};
+ if (!clients_.contains (client_key))
+ {
+ auto& client = (clients_[client_key] = {sender_port});
+ QByteArray client_version;
+ QByteArray client_revision;
+
+ if (NetworkMessage::Heartbeat == in.type ())
+ {
+ // negotiate a working schema number
+ in >> client.negotiated_schema_number_;
+ if (OK == check_status (in))
+ {
+ auto sn = NetworkMessage::Builder::schema_number;
+ client.negotiated_schema_number_ = std::min (sn, client.negotiated_schema_number_);
+
+ // reply to the new client informing it of the
+ // negotiated schema number
+ QByteArray message;
+ NetworkMessage::Builder hb {&message, NetworkMessage::Heartbeat, id, client.negotiated_schema_number_};
+ hb << NetworkMessage::Builder::schema_number // maximum schema number accepted
+ << version_.toUtf8 () << revision_.toUtf8 ();
+ if (impl::OK == check_status (hb))
+ {
+ writeDatagram (message, client_key.first, sender_port);
+ }
+ else
+ {
+ Q_EMIT self_->error ("Error creating UDP message");
+ }
+ }
+ // we don't care if this fails to read
+ in >> client_version >> client_revision;
+ }
+ Q_EMIT self_->client_opened (client_key, QString::fromUtf8 (client_version),
+ QString::fromUtf8 (client_revision));
+ }
+ clients_[client_key].last_activity_ = QDateTime::currentDateTime ();
+
+ //
+ // message format is described in NetworkMessage.hpp
+ //
+ switch (in.type ())
+ {
+ case NetworkMessage::Heartbeat:
+ //nothing to do here as time out handling deals with lifetime
+ break;
+
+ case NetworkMessage::Clear:
+ Q_EMIT self_->decodes_cleared (client_key);
+ break;
+
+ case NetworkMessage::Status:
+ {
+ // unpack message
+ Frequency f;
+ QByteArray mode;
+ QByteArray dx_call;
+ QByteArray report;
+ QByteArray tx_mode;
+ bool tx_enabled {false};
+ bool transmitting {false};
+ bool decoding {false};
+ quint32 rx_df {quint32_max};
+ quint32 tx_df {quint32_max};
+ QByteArray de_call;
+ QByteArray de_grid;
+ QByteArray dx_grid;
+ bool watchdog_timeout {false};
+ QByteArray sub_mode;
+ bool fast_mode {false};
+ quint8 special_op_mode {0};
+ quint32 frequency_tolerance {quint32_max};
+ quint32 tr_period {quint32_max};
+ QByteArray configuration_name;
+ QByteArray tx_message;
+ in >> f >> mode >> dx_call >> report >> tx_mode >> tx_enabled >> transmitting >> decoding
+ >> rx_df >> tx_df >> de_call >> de_grid >> dx_grid >> watchdog_timeout >> sub_mode
+ >> fast_mode >> special_op_mode >> frequency_tolerance >> tr_period >> configuration_name
+ >> tx_message;
+ if (check_status (in) != Fail)
+ {
+ Q_EMIT self_->status_update (client_key, f, QString::fromUtf8 (mode)
+ , QString::fromUtf8 (dx_call)
+ , QString::fromUtf8 (report), QString::fromUtf8 (tx_mode)
+ , tx_enabled, transmitting, decoding, rx_df, tx_df
+ , QString::fromUtf8 (de_call), QString::fromUtf8 (de_grid)
+ , QString::fromUtf8 (dx_grid), watchdog_timeout
+ , QString::fromUtf8 (sub_mode), fast_mode
+ , special_op_mode, frequency_tolerance, tr_period
+ , QString::fromUtf8 (configuration_name)
+ , QString::fromUtf8 (tx_message));
+ }
+ }
+ break;
+
+ case NetworkMessage::Decode:
+ {
+ // unpack message
+ bool is_new {true};
+ QTime time;
+ qint32 snr;
+ float delta_time;
+ quint32 delta_frequency;
+ QByteArray mode;
+ QByteArray message;
+ bool low_confidence {false};
+ bool off_air {false};
+ in >> is_new >> time >> snr >> delta_time >> delta_frequency >> mode
+ >> message >> low_confidence >> off_air;
+ if (check_status (in) != Fail)
+ {
+ Q_EMIT self_->decode (is_new, client_key, time, snr, delta_time, delta_frequency
+ , QString::fromUtf8 (mode), QString::fromUtf8 (message)
+ , low_confidence, off_air);
+ }
+ }
+ break;
+
+ case NetworkMessage::WSPRDecode:
+ {
+ // unpack message
+ bool is_new {true};
+ QTime time;
+ qint32 snr;
+ float delta_time;
+ Frequency frequency;
+ qint32 drift;
+ QByteArray callsign;
+ QByteArray grid;
+ qint32 power;
+ bool off_air {false};
+ in >> is_new >> time >> snr >> delta_time >> frequency >> drift >> callsign >> grid >> power
+ >> off_air;
+ if (check_status (in) != Fail)
+ {
+ Q_EMIT self_->WSPR_decode (is_new, client_key, time, snr, delta_time, frequency, drift
+ , QString::fromUtf8 (callsign), QString::fromUtf8 (grid)
+ , power, off_air);
+ }
+ }
+ break;
+
+ case NetworkMessage::QSOLogged:
+ {
+ QDateTime time_off;
+ QByteArray dx_call;
+ QByteArray dx_grid;
+ Frequency dial_frequency;
+ QByteArray mode;
+ QByteArray report_sent;
+ QByteArray report_received;
+ QByteArray tx_power;
+ QByteArray comments;
+ QByteArray name;
+ QDateTime time_on; // Note: LOTW uses TIME_ON for their +/- 30-minute time window
+ QByteArray operator_call;
+ QByteArray my_call;
+ QByteArray my_grid;
+ QByteArray exchange_sent;
+ QByteArray exchange_rcvd;
+ QByteArray prop_mode;
+ in >> time_off >> dx_call >> dx_grid >> dial_frequency >> mode >> report_sent >> report_received
+ >> tx_power >> comments >> name >> time_on >> operator_call >> my_call >> my_grid
+ >> exchange_sent >> exchange_rcvd >> prop_mode;
+ if (check_status (in) != Fail)
+ {
+ Q_EMIT self_->qso_logged (client_key, time_off, QString::fromUtf8 (dx_call)
+ , QString::fromUtf8 (dx_grid)
+ , dial_frequency, QString::fromUtf8 (mode)
+ , QString::fromUtf8 (report_sent)
+ , QString::fromUtf8 (report_received), QString::fromUtf8 (tx_power)
+ , QString::fromUtf8 (comments), QString::fromUtf8 (name), time_on
+ , QString::fromUtf8 (operator_call), QString::fromUtf8 (my_call)
+ , QString::fromUtf8 (my_grid), QString::fromUtf8 (exchange_sent)
+ , QString::fromUtf8 (exchange_rcvd), QString::fromUtf8 (prop_mode));
+ }
+ }
+ break;
+
+ case NetworkMessage::Close:
+ Q_EMIT self_->client_closed (client_key);
+ clients_.remove (client_key);
+ break;
+
+ case NetworkMessage::LoggedADIF:
+ {
+ QByteArray ADIF;
+ in >> ADIF;
+ if (check_status (in) != Fail)
+ {
+ Q_EMIT self_->logged_ADIF (client_key, ADIF);
+ }
+ }
+ break;
+
+ default:
+ // Ignore
+ break;
+ }
+ }
+ else
+ {
+ Q_EMIT self_->error ("MessageServer warning: invalid UDP message received");
+ }
+ }
+ catch (std::exception const& e)
+ {
+ Q_EMIT self_->error (QString {"MessageServer exception: %1"}.arg (e.what ()));
+ }
+ catch (...)
+ {
+ Q_EMIT self_->error ("Unexpected exception in MessageServer");
+ }
+}
+
+void MessageServer::impl::tick ()
+{
+ auto now = QDateTime::currentDateTime ();
+ auto iter = std::begin (clients_);
+ while (iter != std::end (clients_))
+ {
+ if (now > (*iter).last_activity_.addSecs (NetworkMessage::pulse))
+ {
+ Q_EMIT self_->decodes_cleared (iter.key ());
+ Q_EMIT self_->client_closed (iter.key ());
+ iter = clients_.erase (iter); // safe while iterating as doesn't rehash
+ }
+ else
+ {
+ ++iter;
+ }
+ }
+}
+
+auto MessageServer::impl::check_status (QDataStream const& stream) const -> StreamStatus
+{
+ auto stat = stream.status ();
+ StreamStatus result {Fail};
+ switch (stat)
+ {
+ case QDataStream::ReadPastEnd:
+ result = Short;
+ break;
+
+ case QDataStream::ReadCorruptData:
+ Q_EMIT self_->error ("Message serialization error: read corrupt data");
+ break;
+
+ case QDataStream::WriteFailed:
+ Q_EMIT self_->error ("Message serialization error: write error");
+ break;
+
+ default:
+ result = OK;
+ break;
+ }
+ return result;
+}
+
+MessageServer::MessageServer (QObject * parent, QString const& version, QString const& revision)
+ : QObject {parent}
+ , m_ {this, version, revision}
+{
+}
+
+void MessageServer::start (port_type port, QHostAddress const& multicast_group_address
+ , QSet<QString> const& network_interface_names)
+{
+ // qDebug () << "MessageServer::start port:" << port << "multicast addr:" << multicast_group_address.toString () << "network interfaces:" << network_interface_names;
+ if (port != m_->localPort ()
+ || multicast_group_address != m_->multicast_group_address_
+ || network_interface_names != m_->network_interfaces_)
+ {
+ m_->leave_multicast_group ();
+ if (impl::UnconnectedState != m_->state ())
+ {
+ m_->close ();
+ }
+ if (!(multicast_group_address.isNull () || is_multicast_address (multicast_group_address)))
+ {
+ Q_EMIT error ("Invalid multicast group address");
+ }
+ else if (is_MAC_ambiguous_multicast_address (multicast_group_address))
+ {
+ Q_EMIT error ("MAC-ambiguous IPv4 multicast group address not supported");
+ }
+ else
+ {
+ m_->multicast_group_address_ = multicast_group_address;
+ m_->network_interfaces_ = network_interface_names;
+ QHostAddress local_addr {is_multicast_address (multicast_group_address)
+ && impl::IPv4Protocol == multicast_group_address.protocol () ? QHostAddress::AnyIPv4 : QHostAddress::Any};
+ if (port && m_->bind (local_addr, port, m_->bind_mode_))
+ {
+ m_->join_multicast_group ();
+ }
+ }
+ }
+}
+
+void MessageServer::clear_decodes (ClientKey const& key, quint8 window)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::Clear, key.second, (*iter).negotiated_schema_number_};
+ out << window;
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
+
+void MessageServer::reply (ClientKey const& key, QTime time, qint32 snr, float delta_time
+ , quint32 delta_frequency, QString const& mode
+ , QString const& message_text, bool low_confidence, quint8 modifiers)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::Reply, key.second, (*iter).negotiated_schema_number_};
+ out << time << snr << delta_time << delta_frequency << mode.toUtf8 ()
+ << message_text.toUtf8 () << low_confidence << modifiers;
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
+
+void MessageServer::replay (ClientKey const& key)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::Replay, key.second, (*iter).negotiated_schema_number_};
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
+
+void MessageServer::close (ClientKey const& key)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::Close, key.second, (*iter).negotiated_schema_number_};
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
+
+void MessageServer::halt_tx (ClientKey const& key, bool auto_only)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::HaltTx, key.second, (*iter).negotiated_schema_number_};
+ out << auto_only;
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
+
+void MessageServer::free_text (ClientKey const& key, QString const& text, bool send)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::FreeText, key.second, (*iter).negotiated_schema_number_};
+ out << text.toUtf8 () << send;
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
+
+void MessageServer::location (ClientKey const& key, QString const& loc)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::Location, key.second, (*iter).negotiated_schema_number_};
+ out << loc.toUtf8 ();
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
+
+void MessageServer::highlight_callsign (ClientKey const& key, QString const& callsign
+ , QColor const& bg, QColor const& fg, bool last_only)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::HighlightCallsign, key.second, (*iter).negotiated_schema_number_};
+ out << callsign.toUtf8 () << bg << fg << last_only;
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
+
+void MessageServer::switch_configuration (ClientKey const& key, QString const& configuration_name)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::SwitchConfiguration, key.second, (*iter).negotiated_schema_number_};
+ out << configuration_name.toUtf8 ();
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
+
+void MessageServer::configure (ClientKey const& key, QString const& mode, quint32 frequency_tolerance
+ , QString const& submode, bool fast_mode, quint32 tr_period, quint32 rx_df
+ , QString const& dx_call, QString const& dx_grid, bool generate_messages)
+{
+ auto iter = m_->clients_.find (key);
+ if (iter != std::end (m_->clients_))
+ {
+ QByteArray message;
+ NetworkMessage::Builder out {&message, NetworkMessage::Configure, key.second, (*iter).negotiated_schema_number_};
+ out << mode.toUtf8 () << frequency_tolerance << submode.toUtf8 () << fast_mode << tr_period << rx_df
+ << dx_call.toUtf8 () << dx_grid.toUtf8 () << generate_messages;
+ m_->send_message (out, message, key.first, (*iter).sender_port_);
+ }
+}
diff --git a/UDPExamples/MessageServer.hpp b/UDPExamples/MessageServer.hpp index c18cc95f..6369992f 100755 --- a/UDPExamples/MessageServer.hpp +++ b/UDPExamples/MessageServer.hpp @@ -1,127 +1,127 @@ -#ifndef MESSAGE_SERVER_HPP__ -#define MESSAGE_SERVER_HPP__ - -#include <QObject> -#include <QPair> -#include <QString> -#include <QSet> -#include <QTime> -#include <QDateTime> -#include <QHostAddress> -#include <QColor> - -#include "udp_export.h" -#include "Radio.hpp" - -#include "pimpl_h.hpp" - -class QString; - -// -// MessageServer - a reference implementation of a message server -// matching the MessageClient class at the other end -// of the wire -// -// This class is fully functioning and suitable for use in C++ -// applications that use the Qt framework. Other applications should -// use this classes' implementation as a reference implementation. -// -class UDP_EXPORT MessageServer - : public QObject -{ - Q_OBJECT; - -public: - using port_type = quint16; - using Frequency = Radio::Frequency; - using ClientKey = QPair<QHostAddress, QString>; - - MessageServer (QObject * parent = nullptr, - QString const& version = QString {}, QString const& revision = QString {}); - - // start or restart the server, if the multicast_group_address - // argument is given it is assumed to be a multicast group address - // which the server will join - Q_SLOT void start (port_type port - , QHostAddress const& multicast_group_address = QHostAddress {} - , QSet<QString> const& network_interface_names = QSet<QString> {}); - - // ask the client to clear one or both of the decode windows - Q_SLOT void clear_decodes (ClientKey const&, quint8 window = 0); - - // ask the client with identification 'id' to make the same action - // as a double click on the decode would - // - // note that the client is not obliged to take any action and only - // takes any action if the decode is present and is a CQ or QRZ message - Q_SLOT void reply (ClientKey const&, QTime time, qint32 snr, float delta_time, quint32 delta_frequency - , QString const& mode, QString const& message, bool low_confidence, quint8 modifiers); - - // ask the client to close down gracefully - Q_SLOT void close (ClientKey const&); - - // ask the client to replay all decodes - Q_SLOT void replay (ClientKey const&); - - // ask the client to halt transmitting auto_only just disables auto - // Tx, otherwise halt is immediate - Q_SLOT void halt_tx (ClientKey const&, bool auto_only); - - // ask the client to set the free text message and optionally send - // it ASAP - Q_SLOT void free_text (ClientKey const&, QString const& text, bool send); - - // ask the client to set the location provided - Q_SLOT void location (ClientKey const&, QString const& location); - - // ask the client to highlight the callsign specified with the given - // colors - Q_SLOT void highlight_callsign (ClientKey const&, QString const& callsign - , QColor const& bg = QColor {}, QColor const& fg = QColor {} - , bool last_only = false); - - // ask the client to switch to configuration 'configuration_name' - Q_SLOT void switch_configuration (ClientKey const&, QString const& configuration_name); - - // ask the client to change configuration - Q_SLOT void configure (ClientKey const&, QString const& mode, quint32 frequency_tolerance - , QString const& submode, bool fast_mode, quint32 tr_period, quint32 rx_df - , QString const& dx_call, QString const& dx_grid, bool generate_messages); - - // the following signals are emitted when a client broadcasts the - // matching message - Q_SIGNAL void client_opened (ClientKey const&, QString const& version, QString const& revision); - Q_SIGNAL void status_update (ClientKey const&, Frequency, QString const& mode, QString const& dx_call - , QString const& report, QString const& tx_mode, bool tx_enabled - , bool transmitting, bool decoding, quint32 rx_df, quint32 tx_df - , QString const& de_call, QString const& de_grid, QString const& dx_grid - , bool watchdog_timeout, QString const& sub_mode, bool fast_mode - , quint8 special_op_mode, quint32 frequency_tolerance, quint32 tr_period - , QString const& configuration_name, QString const& tx_message); - Q_SIGNAL void client_closed (ClientKey const&); - Q_SIGNAL void decode (bool is_new, ClientKey const&, QTime time, qint32 snr, float delta_time - , quint32 delta_frequency, QString const& mode, QString const& message - , bool low_confidence, bool off_air); - Q_SIGNAL void WSPR_decode (bool is_new, ClientKey const&, QTime time, qint32 snr, float delta_time, Frequency - , qint32 drift, QString const& callsign, QString const& grid, qint32 power - , bool off_air); - Q_SIGNAL void qso_logged (ClientKey const&, 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& operator_call - , QString const& my_call, QString const& my_grid - , QString const& exchange_sent, QString const& exchange_rcvd, QString const& prop_mode); - Q_SIGNAL void decodes_cleared (ClientKey const&); - Q_SIGNAL void logged_ADIF (ClientKey const&, QByteArray const& ADIF); - - // this signal is emitted when a network error occurs - Q_SIGNAL void error (QString const&) const; - -private: - class UDP_NO_EXPORT impl; - pimpl<impl> m_; -}; - -Q_DECLARE_METATYPE (MessageServer::ClientKey); - -#endif +#ifndef MESSAGE_SERVER_HPP__
+#define MESSAGE_SERVER_HPP__
+
+#include <QObject>
+#include <QPair>
+#include <QString>
+#include <QSet>
+#include <QTime>
+#include <QDateTime>
+#include <QHostAddress>
+#include <QColor>
+
+#include "udp_export.h"
+#include "Radio.hpp"
+
+#include "pimpl_h.hpp"
+
+class QString;
+
+//
+// MessageServer - a reference implementation of a message server
+// matching the MessageClient class at the other end
+// of the wire
+//
+// This class is fully functioning and suitable for use in C++
+// applications that use the Qt framework. Other applications should
+// use this classes' implementation as a reference implementation.
+//
+class UDP_EXPORT MessageServer
+ : public QObject
+{
+ Q_OBJECT;
+
+public:
+ using port_type = quint16;
+ using Frequency = Radio::Frequency;
+ using ClientKey = QPair<QHostAddress, QString>;
+
+ MessageServer (QObject * parent = nullptr,
+ QString const& version = QString {}, QString const& revision = QString {});
+
+ // start or restart the server, if the multicast_group_address
+ // argument is given it is assumed to be a multicast group address
+ // which the server will join
+ Q_SLOT void start (port_type port
+ , QHostAddress const& multicast_group_address = QHostAddress {}
+ , QSet<QString> const& network_interface_names = QSet<QString> {});
+
+ // ask the client to clear one or both of the decode windows
+ Q_SLOT void clear_decodes (ClientKey const&, quint8 window = 0);
+
+ // ask the client with identification 'id' to make the same action
+ // as a double click on the decode would
+ //
+ // note that the client is not obliged to take any action and only
+ // takes any action if the decode is present and is a CQ or QRZ message
+ Q_SLOT void reply (ClientKey const&, QTime time, qint32 snr, float delta_time, quint32 delta_frequency
+ , QString const& mode, QString const& message, bool low_confidence, quint8 modifiers);
+
+ // ask the client to close down gracefully
+ Q_SLOT void close (ClientKey const&);
+
+ // ask the client to replay all decodes
+ Q_SLOT void replay (ClientKey const&);
+
+ // ask the client to halt transmitting auto_only just disables auto
+ // Tx, otherwise halt is immediate
+ Q_SLOT void halt_tx (ClientKey const&, bool auto_only);
+
+ // ask the client to set the free text message and optionally send
+ // it ASAP
+ Q_SLOT void free_text (ClientKey const&, QString const& text, bool send);
+
+ // ask the client to set the location provided
+ Q_SLOT void location (ClientKey const&, QString const& location);
+
+ // ask the client to highlight the callsign specified with the given
+ // colors
+ Q_SLOT void highlight_callsign (ClientKey const&, QString const& callsign
+ , QColor const& bg = QColor {}, QColor const& fg = QColor {}
+ , bool last_only = false);
+
+ // ask the client to switch to configuration 'configuration_name'
+ Q_SLOT void switch_configuration (ClientKey const&, QString const& configuration_name);
+
+ // ask the client to change configuration
+ Q_SLOT void configure (ClientKey const&, QString const& mode, quint32 frequency_tolerance
+ , QString const& submode, bool fast_mode, quint32 tr_period, quint32 rx_df
+ , QString const& dx_call, QString const& dx_grid, bool generate_messages);
+
+ // the following signals are emitted when a client broadcasts the
+ // matching message
+ Q_SIGNAL void client_opened (ClientKey const&, QString const& version, QString const& revision);
+ Q_SIGNAL void status_update (ClientKey const&, Frequency, QString const& mode, QString const& dx_call
+ , QString const& report, QString const& tx_mode, bool tx_enabled
+ , bool transmitting, bool decoding, quint32 rx_df, quint32 tx_df
+ , QString const& de_call, QString const& de_grid, QString const& dx_grid
+ , bool watchdog_timeout, QString const& sub_mode, bool fast_mode
+ , quint8 special_op_mode, quint32 frequency_tolerance, quint32 tr_period
+ , QString const& configuration_name, QString const& tx_message);
+ Q_SIGNAL void client_closed (ClientKey const&);
+ Q_SIGNAL void decode (bool is_new, ClientKey const&, QTime time, qint32 snr, float delta_time
+ , quint32 delta_frequency, QString const& mode, QString const& message
+ , bool low_confidence, bool off_air);
+ Q_SIGNAL void WSPR_decode (bool is_new, ClientKey const&, QTime time, qint32 snr, float delta_time, Frequency
+ , qint32 drift, QString const& callsign, QString const& grid, qint32 power
+ , bool off_air);
+ Q_SIGNAL void qso_logged (ClientKey const&, 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& operator_call
+ , QString const& my_call, QString const& my_grid
+ , QString const& exchange_sent, QString const& exchange_rcvd, QString const& prop_mode);
+ Q_SIGNAL void decodes_cleared (ClientKey const&);
+ Q_SIGNAL void logged_ADIF (ClientKey const&, QByteArray const& ADIF);
+
+ // this signal is emitted when a network error occurs
+ Q_SIGNAL void error (QString const&) const;
+
+private:
+ class UDP_NO_EXPORT impl;
+ pimpl<impl> m_;
+};
+
+Q_DECLARE_METATYPE (MessageServer::ClientKey);
+
+#endif
diff --git a/UDPExamples/UDPDaemon.cpp b/UDPExamples/UDPDaemon.cpp index 4dc04af8..3faa99d4 100755 --- a/UDPExamples/UDPDaemon.cpp +++ b/UDPExamples/UDPDaemon.cpp @@ -1,330 +1,330 @@ -// -// UDPDaemon - an example console application that utilizes the WSJT-X -// messaging facility -// -// This application is only provided as a simple console application -// example to demonstrate the WSJT-X messaging facility. It allows -// the user to set the server details either as a unicast UDP server -// or, if a multicast group address is provided, as a multicast -// server. The benefit of the multicast server is that multiple -// servers can be active at once each receiving all WSJT-X broadcast -// messages and each able to respond to individual WSJT_X clients. To -// utilize the multicast group features each WSJT-X client must set -// the same multicast group address as the UDP server address for -// example 239.255.0.0 for a site local multicast group. -// -// - -#include <iostream> -#include <exception> -#include <locale> -#include <cstdlib> - -#include <QCoreApplication> -#include <QCommandLineParser> -#include <QCommandLineOption> -#include <QString> -#include <QStringList> -#include <QNetworkInterface> -#include <QDateTime> -#include <QTime> -#include <QHash> -#include <QDebug> - -#include "MessageServer.hpp" -#include "Radio.hpp" - -#include "qt_helpers.hpp" - -using port_type = MessageServer::port_type; -using Frequency = MessageServer::Frequency; - -class Client - : public QObject -{ - Q_OBJECT - - using ClientKey = MessageServer::ClientKey; - -public: - explicit Client (ClientKey const& key, QObject * parent = nullptr) - : QObject {parent} - , key_ {key} - , dial_frequency_ {0u} - { - } - - Q_SLOT void update_status (ClientKey const& key, Frequency f, QString const& mode, QString const& /*dx_call*/ - , QString const& /*report*/, QString const& /*tx_mode*/, bool /*tx_enabled*/ - , bool /*transmitting*/, bool /*decoding*/, 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*/ - , quint8 /*special_op_mode*/, quint32 /*frequency_tolerance*/, quint32 /*tr_period*/ - , QString const& /*configuration_name*/, QString const& /*tx_message*/) - { - if (key == key_) - { - if (f != dial_frequency_) - { - std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString () - << QString {"Dial frequency changed to %1"}.arg (f).toStdString () << std::endl; - dial_frequency_ = f; - } - if (mode + sub_mode != mode_) - { - std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString () - << QString {"Mode changed to %1"}.arg (mode + sub_mode).toStdString () << std::endl; - mode_ = mode + sub_mode; - } - } - } - - Q_SLOT void decode_added (bool is_new, ClientKey const& key, QTime time, qint32 snr - , float delta_time, quint32 delta_frequency, QString const& mode - , QString const& message, bool low_confidence, bool off_air) - { - if (key == key_) - { - qDebug () << "new:" << is_new << "t:" << time << "snr:" << snr - << "Dt:" << delta_time << "Df:" << delta_frequency - << "mode:" << mode << "Confidence:" << (low_confidence ? "low" : "high") - << "On air:" << !off_air; - std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString () - << QString {"Decoded %1"}.arg (message).toStdString () << std::endl; - } - } - - Q_SLOT void beacon_spot_added (bool is_new, ClientKey const& key, QTime time, qint32 snr - , float delta_time, Frequency delta_frequency, qint32 drift, QString const& callsign - , QString const& grid, qint32 power, bool off_air) - { - if (key == key_) - { - qDebug () << "new:" << is_new << "t:" << time << "snr:" << snr - << "Dt:" << delta_time << "Df:" << delta_frequency - << "drift:" << drift; - std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString () - << QString {"WSPR decode %1 grid %2 power: %3"} - .arg (callsign).arg (grid).arg (power).toStdString () - << "On air:" << !off_air << std::endl; - } - } - - Q_SLOT void qso_logged (ClientKey const& key, 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& operator_call, QString const& my_call, QString const& my_grid - , QString const& exchange_sent, QString const& exchange_rcvd, QString const& prop_mode) - { - if (key == key_) - { - qDebug () << "time_on:" << time_on << "time_off:" << time_off << "dx_call:" - << dx_call << "grid:" << dx_grid - << "freq:" << dial_frequency << "mode:" << mode << "rpt_sent:" << report_sent - << "rpt_rcvd:" << report_received << "Tx_pwr:" << tx_power << "comments:" << comments - << "name:" << name << "operator_call:" << operator_call << "my_call:" << my_call - << "my_grid:" << my_grid << "exchange_sent:" << exchange_sent - << "exchange_rcvd:" << exchange_rcvd << "prop_mode:" << prop_mode; - std::cout << QByteArray {80, '-'}.data () << '\n'; - std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString () - << QString {"Logged %1 grid: %2 power: %3 sent: %4 recd: %5 freq: %6 time_off: %7 op: %8 my_call: %9 my_grid: %10 exchange_sent: %11 exchange_rcvd: %12 comments: %13 prop_mode: %14"} - .arg (dx_call).arg (dx_grid).arg (tx_power) - .arg (report_sent).arg (report_received) - .arg (dial_frequency).arg (time_off.toString("yyyy-MM-dd hh:mm:ss.z")).arg (operator_call) - .arg (my_call).arg (my_grid).arg (exchange_sent).arg (exchange_rcvd) - .arg (comments).arg (prop_mode).toStdString () - << std::endl; - } - } - - Q_SLOT void logged_ADIF (ClientKey const& key, QByteArray const& ADIF) - { - if (key == key_) - { - qDebug () << "ADIF:" << ADIF; - std::cout << QByteArray {80, '-'}.data () << '\n'; - std::cout << ADIF.data () << std::endl; - } - } - -private: - ClientKey key_; - Frequency dial_frequency_; - QString mode_; -}; - -class Server - : public QObject -{ - Q_OBJECT - - using ClientKey = MessageServer::ClientKey; - -public: - Server (port_type port, QHostAddress const& multicast_group, QStringList const& network_interface_names) - : server_ {new MessageServer {this}} - { - // connect up server - connect (server_, &MessageServer::error, [] (QString const& message) { - std::cerr << tr ("Network Error: %1").arg ( message).toStdString () << std::endl; - }); - connect (server_, &MessageServer::client_opened, this, &Server::add_client); - connect (server_, &MessageServer::client_closed, this, &Server::remove_client); - -#if QT_VERSION >= QT_VERSION_CHECK (5, 14, 0) - server_->start (port, multicast_group, QSet<QString> {network_interface_names.begin (), network_interface_names.end ()}); -#else - server_->start (port, multicast_group, network_interface_names.toSet ()); -#endif - } - -private: - void add_client (ClientKey const& key, QString const& version, QString const& revision) - { - auto client = new Client {key}; - connect (server_, &MessageServer::status_update, client, &Client::update_status); - connect (server_, &MessageServer::decode, client, &Client::decode_added); - connect (server_, &MessageServer::WSPR_decode, client, &Client::beacon_spot_added); - connect (server_, &MessageServer::qso_logged, client, &Client::qso_logged); - connect (server_, &MessageServer::logged_ADIF, client, &Client::logged_ADIF); - clients_[key] = client; - server_->replay (key); - std::cout << "Discovered WSJT-X instance: " << key.second.toStdString () - << '(' << key.first.toString ().toStdString () << ')'; - if (version.size ()) - { - std::cout << " v" << version.toStdString (); - } - if (revision.size ()) - { - std::cout << " (" << revision.toStdString () << ")"; - } - std::cout << std::endl; - } - - void remove_client (ClientKey const& key) - { - auto iter = clients_.find (key); - if (iter != std::end (clients_)) - { - clients_.erase (iter); - (*iter)->deleteLater (); - } - std::cout << "Removed WSJT-X instance: " << key.second.toStdString () - << '(' << key.first.toString ().toStdString () << ')' << std::endl; - } - - MessageServer * server_; - - // maps client key to clients - QHash<ClientKey, Client *> clients_; -}; - -void list_interfaces () -{ - for (auto const& net_if : QNetworkInterface::allInterfaces ()) - { - if (net_if.flags () & QNetworkInterface::IsUp) - { - std::cout << net_if.humanReadableName ().toStdString () << ":\n" - " id: " << net_if.name ().toStdString () << " (" << net_if.index () << ")\n" - " addr: " << net_if.hardwareAddress ().toStdString () << "\n" - " flags: "; - if (net_if.flags () & QNetworkInterface::IsRunning) - { - std::cout << "Running "; - } - if (net_if.flags () & QNetworkInterface::CanBroadcast) - { - std::cout << "Broadcast "; - } - if (net_if.flags () & QNetworkInterface::CanMulticast) - { - std::cout << "Multicast "; - } - if (net_if.flags () & QNetworkInterface::IsLoopBack) - { - std::cout << "Loop-back "; - } - std::cout << "\n addresses:\n"; - for (auto const& ae : net_if.addressEntries ()) - { - std::cout << " " << ae.ip ().toString ().toStdString () << '\n'; - } - std::cout << '\n'; - } - } -} - -#include "UDPDaemon.moc" - -int main (int argc, char * argv[]) -{ - QCoreApplication app {argc, argv}; - try - { - // ensure number forms are in consistent format, do this after - // instantiating QApplication so that GUI has correct l18n - std::locale::global (std::locale::classic ()); - - app.setApplicationName ("WSJT-X UDP Message Server Daemon"); - app.setApplicationVersion ("1.0"); - - QCommandLineParser parser; - parser.setApplicationDescription ("\nWSJT-X UDP Message Server Daemon."); - auto help_option = parser.addHelpOption (); - auto version_option = parser.addVersionOption (); - - QCommandLineOption list_option (QStringList {"l", "list-interfaces"}, - app.translate ("UDPDaemon", - "Print the available network interfaces.")); - parser.addOption (list_option); - - QCommandLineOption port_option (QStringList {"p", "port"}, - app.translate ("UDPDaemon", - "Where <PORT> is the UDP service port number to listen on.\n" - "The default service port is 2237."), - app.translate ("UDPDaemon", "PORT"), - "2237"); - parser.addOption (port_option); - - QCommandLineOption multicast_addr_option (QStringList {"g", "multicast-group"}, - app.translate ("UDPDaemon", - "Where <GROUP> is the multicast group to join.\n" - "The default is a unicast server listening on all interfaces."), - app.translate ("UDPDaemon", "GROUP")); - parser.addOption (multicast_addr_option); - - QCommandLineOption network_interface_option (QStringList {"i", "network-interface"}, - app.translate ("UDPDaemon", - "Where <INTERFACE> is the network interface name to join on.\n" - "This option can be passed more than once to specify multiple network interfaces\n" - "The default is use just the loop back interface."), - app.translate ("UDPDaemon", "INTERFACE")); - parser.addOption (network_interface_option); - - parser.process (app); - - if (parser.isSet (list_option)) - { - list_interfaces (); - return EXIT_SUCCESS; - } - - Server server {static_cast<port_type> (parser.value (port_option).toUInt ()) - , QHostAddress {parser.value (multicast_addr_option).trimmed ()} - , parser.values (network_interface_option)}; - - return app.exec (); - } - catch (std::exception const & e) - { - std::cerr << "Error: " << e.what () << '\n'; - } - catch (...) - { - std::cerr << "Unexpected error\n"; - } - return -1; -} +//
+// UDPDaemon - an example console application that utilizes the WSJT-X
+// messaging facility
+//
+// This application is only provided as a simple console application
+// example to demonstrate the WSJT-X messaging facility. It allows
+// the user to set the server details either as a unicast UDP server
+// or, if a multicast group address is provided, as a multicast
+// server. The benefit of the multicast server is that multiple
+// servers can be active at once each receiving all WSJT-X broadcast
+// messages and each able to respond to individual WSJT_X clients. To
+// utilize the multicast group features each WSJT-X client must set
+// the same multicast group address as the UDP server address for
+// example 239.255.0.0 for a site local multicast group.
+//
+//
+
+#include <iostream>
+#include <exception>
+#include <locale>
+#include <cstdlib>
+
+#include <QCoreApplication>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
+#include <QString>
+#include <QStringList>
+#include <QNetworkInterface>
+#include <QDateTime>
+#include <QTime>
+#include <QHash>
+#include <QDebug>
+
+#include "MessageServer.hpp"
+#include "Radio.hpp"
+
+#include "qt_helpers.hpp"
+
+using port_type = MessageServer::port_type;
+using Frequency = MessageServer::Frequency;
+
+class Client
+ : public QObject
+{
+ Q_OBJECT
+
+ using ClientKey = MessageServer::ClientKey;
+
+public:
+ explicit Client (ClientKey const& key, QObject * parent = nullptr)
+ : QObject {parent}
+ , key_ {key}
+ , dial_frequency_ {0u}
+ {
+ }
+
+ Q_SLOT void update_status (ClientKey const& key, Frequency f, QString const& mode, QString const& /*dx_call*/
+ , QString const& /*report*/, QString const& /*tx_mode*/, bool /*tx_enabled*/
+ , bool /*transmitting*/, bool /*decoding*/, 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*/
+ , quint8 /*special_op_mode*/, quint32 /*frequency_tolerance*/, quint32 /*tr_period*/
+ , QString const& /*configuration_name*/, QString const& /*tx_message*/)
+ {
+ if (key == key_)
+ {
+ if (f != dial_frequency_)
+ {
+ std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString ()
+ << QString {"Dial frequency changed to %1"}.arg (f).toStdString () << std::endl;
+ dial_frequency_ = f;
+ }
+ if (mode + sub_mode != mode_)
+ {
+ std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString ()
+ << QString {"Mode changed to %1"}.arg (mode + sub_mode).toStdString () << std::endl;
+ mode_ = mode + sub_mode;
+ }
+ }
+ }
+
+ Q_SLOT void decode_added (bool is_new, ClientKey const& key, QTime time, qint32 snr
+ , float delta_time, quint32 delta_frequency, QString const& mode
+ , QString const& message, bool low_confidence, bool off_air)
+ {
+ if (key == key_)
+ {
+ qDebug () << "new:" << is_new << "t:" << time << "snr:" << snr
+ << "Dt:" << delta_time << "Df:" << delta_frequency
+ << "mode:" << mode << "Confidence:" << (low_confidence ? "low" : "high")
+ << "On air:" << !off_air;
+ std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString ()
+ << QString {"Decoded %1"}.arg (message).toStdString () << std::endl;
+ }
+ }
+
+ Q_SLOT void beacon_spot_added (bool is_new, ClientKey const& key, QTime time, qint32 snr
+ , float delta_time, Frequency delta_frequency, qint32 drift, QString const& callsign
+ , QString const& grid, qint32 power, bool off_air)
+ {
+ if (key == key_)
+ {
+ qDebug () << "new:" << is_new << "t:" << time << "snr:" << snr
+ << "Dt:" << delta_time << "Df:" << delta_frequency
+ << "drift:" << drift;
+ std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString ()
+ << QString {"WSPR decode %1 grid %2 power: %3"}
+ .arg (callsign).arg (grid).arg (power).toStdString ()
+ << "On air:" << !off_air << std::endl;
+ }
+ }
+
+ Q_SLOT void qso_logged (ClientKey const& key, 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& operator_call, QString const& my_call, QString const& my_grid
+ , QString const& exchange_sent, QString const& exchange_rcvd, QString const& prop_mode)
+ {
+ if (key == key_)
+ {
+ qDebug () << "time_on:" << time_on << "time_off:" << time_off << "dx_call:"
+ << dx_call << "grid:" << dx_grid
+ << "freq:" << dial_frequency << "mode:" << mode << "rpt_sent:" << report_sent
+ << "rpt_rcvd:" << report_received << "Tx_pwr:" << tx_power << "comments:" << comments
+ << "name:" << name << "operator_call:" << operator_call << "my_call:" << my_call
+ << "my_grid:" << my_grid << "exchange_sent:" << exchange_sent
+ << "exchange_rcvd:" << exchange_rcvd << "prop_mode:" << prop_mode;
+ std::cout << QByteArray {80, '-'}.data () << '\n';
+ std::cout << QString {"%1(%2): "}.arg (key_.second).arg (key_.first.toString ()).toStdString ()
+ << QString {"Logged %1 grid: %2 power: %3 sent: %4 recd: %5 freq: %6 time_off: %7 op: %8 my_call: %9 my_grid: %10 exchange_sent: %11 exchange_rcvd: %12 comments: %13 prop_mode: %14"}
+ .arg (dx_call).arg (dx_grid).arg (tx_power)
+ .arg (report_sent).arg (report_received)
+ .arg (dial_frequency).arg (time_off.toString("yyyy-MM-dd hh:mm:ss.z")).arg (operator_call)
+ .arg (my_call).arg (my_grid).arg (exchange_sent).arg (exchange_rcvd)
+ .arg (comments).arg (prop_mode).toStdString ()
+ << std::endl;
+ }
+ }
+
+ Q_SLOT void logged_ADIF (ClientKey const& key, QByteArray const& ADIF)
+ {
+ if (key == key_)
+ {
+ qDebug () << "ADIF:" << ADIF;
+ std::cout << QByteArray {80, '-'}.data () << '\n';
+ std::cout << ADIF.data () << std::endl;
+ }
+ }
+
+private:
+ ClientKey key_;
+ Frequency dial_frequency_;
+ QString mode_;
+};
+
+class Server
+ : public QObject
+{
+ Q_OBJECT
+
+ using ClientKey = MessageServer::ClientKey;
+
+public:
+ Server (port_type port, QHostAddress const& multicast_group, QStringList const& network_interface_names)
+ : server_ {new MessageServer {this}}
+ {
+ // connect up server
+ connect (server_, &MessageServer::error, [] (QString const& message) {
+ std::cerr << tr ("Network Error: %1").arg ( message).toStdString () << std::endl;
+ });
+ connect (server_, &MessageServer::client_opened, this, &Server::add_client);
+ connect (server_, &MessageServer::client_closed, this, &Server::remove_client);
+
+#if QT_VERSION >= QT_VERSION_CHECK (5, 14, 0)
+ server_->start (port, multicast_group, QSet<QString> {network_interface_names.begin (), network_interface_names.end ()});
+#else
+ server_->start (port, multicast_group, network_interface_names.toSet ());
+#endif
+ }
+
+private:
+ void add_client (ClientKey const& key, QString const& version, QString const& revision)
+ {
+ auto client = new Client {key};
+ connect (server_, &MessageServer::status_update, client, &Client::update_status);
+ connect (server_, &MessageServer::decode, client, &Client::decode_added);
+ connect (server_, &MessageServer::WSPR_decode, client, &Client::beacon_spot_added);
+ connect (server_, &MessageServer::qso_logged, client, &Client::qso_logged);
+ connect (server_, &MessageServer::logged_ADIF, client, &Client::logged_ADIF);
+ clients_[key] = client;
+ server_->replay (key);
+ std::cout << "Discovered WSJT-X instance: " << key.second.toStdString ()
+ << '(' << key.first.toString ().toStdString () << ')';
+ if (version.size ())
+ {
+ std::cout << " v" << version.toStdString ();
+ }
+ if (revision.size ())
+ {
+ std::cout << " (" << revision.toStdString () << ")";
+ }
+ std::cout << std::endl;
+ }
+
+ void remove_client (ClientKey const& key)
+ {
+ auto iter = clients_.find (key);
+ if (iter != std::end (clients_))
+ {
+ clients_.erase (iter);
+ (*iter)->deleteLater ();
+ }
+ std::cout << "Removed WSJT-X instance: " << key.second.toStdString ()
+ << '(' << key.first.toString ().toStdString () << ')' << std::endl;
+ }
+
+ MessageServer * server_;
+
+ // maps client key to clients
+ QHash<ClientKey, Client *> clients_;
+};
+
+void list_interfaces ()
+{
+ for (auto const& net_if : QNetworkInterface::allInterfaces ())
+ {
+ if (net_if.flags () & QNetworkInterface::IsUp)
+ {
+ std::cout << net_if.humanReadableName ().toStdString () << ":\n"
+ " id: " << net_if.name ().toStdString () << " (" << net_if.index () << ")\n"
+ " addr: " << net_if.hardwareAddress ().toStdString () << "\n"
+ " flags: ";
+ if (net_if.flags () & QNetworkInterface::IsRunning)
+ {
+ std::cout << "Running ";
+ }
+ if (net_if.flags () & QNetworkInterface::CanBroadcast)
+ {
+ std::cout << "Broadcast ";
+ }
+ if (net_if.flags () & QNetworkInterface::CanMulticast)
+ {
+ std::cout << "Multicast ";
+ }
+ if (net_if.flags () & QNetworkInterface::IsLoopBack)
+ {
+ std::cout << "Loop-back ";
+ }
+ std::cout << "\n addresses:\n";
+ for (auto const& ae : net_if.addressEntries ())
+ {
+ std::cout << " " << ae.ip ().toString ().toStdString () << '\n';
+ }
+ std::cout << '\n';
+ }
+ }
+}
+
+#include "UDPDaemon.moc"
+
+int main (int argc, char * argv[])
+{
+ QCoreApplication app {argc, argv};
+ try
+ {
+ // ensure number forms are in consistent format, do this after
+ // instantiating QApplication so that GUI has correct l18n
+ std::locale::global (std::locale::classic ());
+
+ app.setApplicationName ("WSJT-X UDP Message Server Daemon");
+ app.setApplicationVersion ("1.0");
+
+ QCommandLineParser parser;
+ parser.setApplicationDescription ("\nWSJT-X UDP Message Server Daemon.");
+ auto help_option = parser.addHelpOption ();
+ auto version_option = parser.addVersionOption ();
+
+ QCommandLineOption list_option (QStringList {"l", "list-interfaces"},
+ app.translate ("UDPDaemon",
+ "Print the available network interfaces."));
+ parser.addOption (list_option);
+
+ QCommandLineOption port_option (QStringList {"p", "port"},
+ app.translate ("UDPDaemon",
+ "Where <PORT> is the UDP service port number to listen on.\n"
+ "The default service port is 2237."),
+ app.translate ("UDPDaemon", "PORT"),
+ "2237");
+ parser.addOption (port_option);
+
+ QCommandLineOption multicast_addr_option (QStringList {"g", "multicast-group"},
+ app.translate ("UDPDaemon",
+ "Where <GROUP> is the multicast group to join.\n"
+ "The default is a unicast server listening on all interfaces."),
+ app.translate ("UDPDaemon", "GROUP"));
+ parser.addOption (multicast_addr_option);
+
+ QCommandLineOption network_interface_option (QStringList {"i", "network-interface"},
+ app.translate ("UDPDaemon",
+ "Where <INTERFACE> is the network interface name to join on.\n"
+ "This option can be passed more than once to specify multiple network interfaces\n"
+ "The default is use just the loop back interface."),
+ app.translate ("UDPDaemon", "INTERFACE"));
+ parser.addOption (network_interface_option);
+
+ parser.process (app);
+
+ if (parser.isSet (list_option))
+ {
+ list_interfaces ();
+ return EXIT_SUCCESS;
+ }
+
+ Server server {static_cast<port_type> (parser.value (port_option).toUInt ())
+ , QHostAddress {parser.value (multicast_addr_option).trimmed ()}
+ , parser.values (network_interface_option)};
+
+ return app.exec ();
+ }
+ catch (std::exception const & e)
+ {
+ std::cerr << "Error: " << e.what () << '\n';
+ }
+ catch (...)
+ {
+ std::cerr << "Unexpected error\n";
+ }
+ return -1;
+}
diff --git a/UDPExamples/message_aggregator.qrc.in b/UDPExamples/message_aggregator.qrc.in index 792aa446..c988f361 100755 --- a/UDPExamples/message_aggregator.qrc.in +++ b/UDPExamples/message_aggregator.qrc.in @@ -1,5 +1,5 @@ -<!DOCTYPE RCC> -<RCC version="1.0"> - <qresource>@message_aggregator_RESOURCES@ - </qresource> -</RCC> +<!DOCTYPE RCC>
+<RCC version="1.0">
+ <qresource>@message_aggregator_RESOURCES@
+ </qresource>
+</RCC>
diff --git a/UDPExamples/qss/default.qss b/UDPExamples/qss/default.qss index 4f4bdf4f..3c6d3a8c 100755 --- a/UDPExamples/qss/default.qss +++ b/UDPExamples/qss/default.qss @@ -1,13 +1,13 @@ -/* default stylesheet for the message aggregator application */ - -[transmitting="true"] { - background-color: yellow -} - -[decoding="true"] { - background-color: cyan -} - -[watchdog_timeout="true"] { - background-color: red +/* default stylesheet for the message aggregator application */
+
+[transmitting="true"] {
+ background-color: yellow
+}
+
+[decoding="true"] {
+ background-color: cyan
+}
+
+[watchdog_timeout="true"] {
+ background-color: red
}
\ No newline at end of file |
