Restructuring message client for external api with a python example
This commit is contained in:
parent
edf85a1e5f
commit
80ed587514
@ -138,6 +138,10 @@ void MessageClient::impl::parse_message (QByteArray const& msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
qDebug() << "incoming udp message" << msg;
|
||||
|
||||
|
||||
#if 0
|
||||
//
|
||||
// message format is described in NetworkMessage.hpp
|
||||
//
|
||||
@ -157,6 +161,7 @@ void MessageClient::impl::parse_message (QByteArray const& msg)
|
||||
{
|
||||
case NetworkMessage::Reply:
|
||||
{
|
||||
#if 0
|
||||
// unpack message
|
||||
QTime time;
|
||||
qint32 snr;
|
||||
@ -174,30 +179,38 @@ void MessageClient::impl::parse_message (QByteArray const& msg)
|
||||
, QString::fromUtf8 (mode), QString::fromUtf8 (message)
|
||||
, low_confidence, modifiers);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkMessage::Replay:
|
||||
{
|
||||
#if 0
|
||||
if (check_status (in) != Fail)
|
||||
{
|
||||
last_message_.clear ();
|
||||
Q_EMIT self_->replay ();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkMessage::HaltTx:
|
||||
{
|
||||
#if 0
|
||||
bool auto_only {false};
|
||||
in >> auto_only;
|
||||
if (check_status (in) != Fail)
|
||||
{
|
||||
Q_EMIT self_->halt_tx (auto_only);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkMessage::FreeText:
|
||||
{
|
||||
#if 0
|
||||
QByteArray message;
|
||||
bool send {true};
|
||||
in >> message >> send;
|
||||
@ -205,22 +218,26 @@ void MessageClient::impl::parse_message (QByteArray const& msg)
|
||||
{
|
||||
Q_EMIT self_->free_text (QString::fromUtf8 (message), send);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkMessage::Location:
|
||||
{
|
||||
#if 0
|
||||
QByteArray location;
|
||||
in >> location;
|
||||
if (check_status (in) != Fail)
|
||||
{
|
||||
Q_EMIT self_->location (QString::fromUtf8 (location));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkMessage::HighlightCallsign:
|
||||
{
|
||||
#if 0
|
||||
QByteArray call;
|
||||
QColor bg; // default invalid color
|
||||
QColor fg; // default invalid color
|
||||
@ -230,6 +247,7 @@ void MessageClient::impl::parse_message (QByteArray const& msg)
|
||||
{
|
||||
Q_EMIT self_->highlight_callsign (QString::fromUtf8 (call), bg, fg, last_only);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
@ -243,6 +261,7 @@ void MessageClient::impl::parse_message (QByteArray const& msg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
@ -264,6 +283,7 @@ void MessageClient::impl::heartbeat ()
|
||||
<< version_.toUtf8 () << revision_.toUtf8 ();
|
||||
if (OK == check_status (hb))
|
||||
{
|
||||
qDebug() << "outgoing udp heartbeat message" << message;
|
||||
writeDatagram (message, server_, server_port_);
|
||||
}
|
||||
}
|
||||
@ -277,6 +297,7 @@ void MessageClient::impl::closedown ()
|
||||
NetworkMessage::Builder out {&message, NetworkMessage::Close, id_, schema_};
|
||||
if (OK == check_status (out))
|
||||
{
|
||||
qDebug() << "outgoing udp closedown message" << message;
|
||||
writeDatagram (message, server_, server_port_);
|
||||
}
|
||||
}
|
||||
@ -290,6 +311,7 @@ void MessageClient::impl::send_message (QByteArray const& message)
|
||||
{
|
||||
if (message != last_message_) // avoid duplicates
|
||||
{
|
||||
qDebug() << "outgoing udp message" << message;
|
||||
writeDatagram (message, server_, server_port_);
|
||||
last_message_ = message;
|
||||
}
|
||||
@ -398,6 +420,7 @@ void MessageClient::add_blocked_destination (QHostAddress const& a)
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
void MessageClient::status_update (Frequency f, QString const& mode, QString const& dx_call
|
||||
, QString const& report, QString const& tx_mode
|
||||
, bool tx_enabled, bool transmitting, bool decoding
|
||||
@ -485,3 +508,4 @@ void MessageClient::logged_ADIF (QByteArray const& ADIF_record)
|
||||
m_->send_message (out, message);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
Q_SLOT void set_server_port (port_type server_port = 0u);
|
||||
|
||||
// outgoing messages
|
||||
#if 0
|
||||
Q_SLOT void status_update (Frequency, 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
|
||||
@ -69,6 +70,7 @@ public:
|
||||
// ADIF_record argument should be valid ADIF excluding any <EOR> end
|
||||
// of record marker
|
||||
Q_SLOT void logged_ADIF (QByteArray const& ADIF_record);
|
||||
#endif
|
||||
|
||||
// this slot may be used to send arbitrary UDP datagrams to and
|
||||
// destination allowing the underlying socket to be used for general
|
||||
@ -79,6 +81,7 @@ public:
|
||||
// with send_raw_datagram() above)
|
||||
Q_SLOT void add_blocked_destination (QHostAddress const&);
|
||||
|
||||
#if 0
|
||||
// this signal is emitted if the server sends us a reply, the only
|
||||
// reply supported is reply to a prior CQ or QRZ message
|
||||
Q_SIGNAL void reply (QTime, qint32 snr, float delta_time, quint32 delta_frequency, QString const& mode
|
||||
@ -99,15 +102,18 @@ public:
|
||||
// this signal is emitted if the server has sent a highlight
|
||||
// callsign request for the specified call
|
||||
Q_SIGNAL void highlight_callsign (QString const& callsign, QColor const& bg, QColor const& fg, bool last_only);
|
||||
#endif
|
||||
|
||||
// this signal is emitted when network errors occur or if a host
|
||||
// lookup fails
|
||||
Q_SIGNAL void error (QString const&) const;
|
||||
|
||||
#if 0
|
||||
// this signal is emitted if the message obtains a location from a
|
||||
// server. (It doesn't have to be new, could be a periodic location
|
||||
// update)
|
||||
Q_SIGNAL void location (QString const&);
|
||||
#endif
|
||||
|
||||
private:
|
||||
class impl;
|
||||
|
@ -544,7 +544,11 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
|
||||
connect (m_logDlg.data (), &LogQSO::acceptQSO, this, &MainWindow::acceptQSO);
|
||||
connect (this, &MainWindow::finished, m_logDlg.data (), &LogQSO::close);
|
||||
|
||||
|
||||
// Network message handlers
|
||||
connect (m_messageClient, &MessageClient::error, this, &MainWindow::networkError);
|
||||
|
||||
#if 0
|
||||
connect (m_messageClient, &MessageClient::reply, this, &MainWindow::replyToCQ);
|
||||
connect (m_messageClient, &MessageClient::replay, this, &MainWindow::replayDecodes);
|
||||
connect (m_messageClient, &MessageClient::location, this, &MainWindow::locationChange);
|
||||
@ -559,7 +563,6 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
|
||||
}
|
||||
}
|
||||
});
|
||||
connect (m_messageClient, &MessageClient::error, this, &MainWindow::networkError);
|
||||
connect (m_messageClient, &MessageClient::free_text, [this] (QString const& text, bool send) {
|
||||
if (m_config.accept_udp_requests ()) {
|
||||
tx_watchdog (false);
|
||||
@ -598,6 +601,8 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
|
||||
, &m_WSPR_band_hopping, &WSPRBandHopping::show_dialog);
|
||||
connect (ui->sbTxPercent, static_cast<void (QSpinBox::*) (int)> (&QSpinBox::valueChanged)
|
||||
, &m_WSPR_band_hopping, &WSPRBandHopping::set_tx_percent);
|
||||
#endif
|
||||
|
||||
|
||||
on_EraseButton_clicked ();
|
||||
|
||||
@ -3745,7 +3750,9 @@ void MainWindow::on_EraseButton_clicked ()
|
||||
|
||||
void MainWindow::band_activity_cleared ()
|
||||
{
|
||||
#if 0
|
||||
m_messageClient->clear_decodes ();
|
||||
#endif
|
||||
QFile f(m_config.temp_dir ().absoluteFilePath ("decoded.txt"));
|
||||
if(f.exists()) f.remove();
|
||||
}
|
||||
@ -6333,8 +6340,10 @@ void MainWindow::acceptQSO (QDateTime const& QSO_date_off, QString const& call,
|
||||
QString date = QSO_date_on.toString("yyyyMMdd");
|
||||
m_logBook.addAsWorked (m_hisCall, m_config.bands ()->find (m_freqNominal), m_modeTx, date);
|
||||
|
||||
#if 0
|
||||
m_messageClient->qso_logged (QSO_date_off, call, grid, dial_freq, mode, rpt_sent, rpt_received, tx_power, comments, name, QSO_date_on, operator_call, my_call, my_grid);
|
||||
m_messageClient->logged_ADIF (ADIF);
|
||||
#endif
|
||||
if (m_config.clear_DX () and !m_config.bHound()) clearDX ();
|
||||
m_dateTimeQSOOn = QDateTime {};
|
||||
}
|
||||
@ -8158,6 +8167,7 @@ void MainWindow::replayDecodes ()
|
||||
|
||||
void MainWindow::postDecode (bool is_new, QString const& message)
|
||||
{
|
||||
#if 0
|
||||
auto const& decode = message.trimmed ();
|
||||
auto const& parts = decode.left (22).split (' ', QString::SkipEmptyParts);
|
||||
if (parts.size () >= 5)
|
||||
@ -8171,6 +8181,7 @@ void MainWindow::postDecode (bool is_new, QString const& message)
|
||||
, QChar {'?'} == decode.mid (has_seconds ? 24 + 21 : 22 + 21, 1)
|
||||
, m_diskData);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(is_new){
|
||||
m_rxDirty = true;
|
||||
@ -8963,10 +8974,12 @@ void MainWindow::postWSPRDecode (bool is_new, QStringList parts)
|
||||
{
|
||||
parts.insert (6, "");
|
||||
}
|
||||
#if 0
|
||||
m_messageClient->WSPR_decode (is_new, QTime::fromString (parts[0], "hhmm"), parts[1].toInt ()
|
||||
, parts[2].toFloat (), Radio::frequency (parts[3].toFloat (), 6)
|
||||
, parts[4].toInt (), parts[5], parts[6], parts[7].toInt ()
|
||||
, m_diskData);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::networkError (QString const& e)
|
||||
@ -9398,6 +9411,7 @@ void MainWindow::statusUpdate () const
|
||||
{
|
||||
if (!ui) return;
|
||||
auto submode = current_submode ();
|
||||
#if 0
|
||||
m_messageClient->status_update (m_freqNominal, m_mode, m_hisCall,
|
||||
QString::number (ui->rptSpinBox->value ()),
|
||||
m_modeTx, ui->autoButton->isChecked (),
|
||||
@ -9406,6 +9420,7 @@ void MainWindow::statusUpdate () const
|
||||
m_config.my_callsign (), m_config.my_grid (),
|
||||
m_hisGrid, m_tx_watchdog,
|
||||
submode != QChar::Null ? QString {submode} : QString {}, m_bFastMode);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::childEvent (QChildEvent * e)
|
||||
|
23
udp.py
Normal file
23
udp.py
Normal file
@ -0,0 +1,23 @@
|
||||
from __future__ import print_function
|
||||
from socket import socket, AF_INET, SOCK_DGRAM
|
||||
|
||||
listen = ('127.0.0.1', 2237)
|
||||
|
||||
def main():
|
||||
sock = socket(AF_INET, SOCK_DGRAM)
|
||||
print("listening on", ':'.join(map(str, listen)))
|
||||
sock.bind(listen)
|
||||
try:
|
||||
while True:
|
||||
content, addr = sock.recvfrom(1024)
|
||||
print("from:", ":".join(map(str, addr)))
|
||||
print("->", repr(content))
|
||||
print("sending test reply...", end="")
|
||||
sock.sendto("test", addr)
|
||||
print("done")
|
||||
finally:
|
||||
sock.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -68,7 +68,9 @@ SOURCES += \
|
||||
WSPRBandHopping.cpp MessageAggregator.cpp SampleDownloader.cpp qt_helpers.cpp\
|
||||
MultiSettings.cpp PhaseEqualizationDialog.cpp IARURegions.cpp MessageBox.cpp \
|
||||
EqualizationToolsDialog.cpp \
|
||||
varicode.cpp
|
||||
varicode.cpp \
|
||||
NetworkMessage.cpp \
|
||||
MessageClient.cpp
|
||||
|
||||
HEADERS += qt_helpers.hpp \
|
||||
pimpl_h.hpp pimpl_impl.hpp \
|
||||
@ -88,7 +90,9 @@ HEADERS += qt_helpers.hpp \
|
||||
qorderedmap.h \
|
||||
varicode.h \
|
||||
qpriorityqueue.h \
|
||||
crc.h
|
||||
crc.h \
|
||||
NetworkMessage.hpp \
|
||||
MessageClient.hpp
|
||||
|
||||
|
||||
INCLUDEPATH += qmake_only
|
||||
|
Loading…
Reference in New Issue
Block a user