From 50da40413f29e5122f921f81b4f84c2fa0906db3 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sun, 16 Aug 2020 00:38:19 +0100 Subject: [PATCH] PSK Reporter connection opened & closed at the correct times --- Network/PSKReporter.cpp | 22 ++++++++++++++++++++-- Network/PSKReporter.hpp | 2 +- widgets/mainwindow.cpp | 11 ++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Network/PSKReporter.cpp b/Network/PSKReporter.cpp index 1776d8143..59c5f2f0a 100644 --- a/Network/PSKReporter.cpp +++ b/Network/PSKReporter.cpp @@ -165,6 +165,16 @@ public: } } + void stop () + { + if (socket_) + { + socket_->disconnectFromHost (); + } + descriptor_timer_.stop (); + report_timer_.stop (); + } + void send_report (bool send_residue = false); void build_preamble (QDataStream&); @@ -484,6 +494,7 @@ void PSKReporter::reconnect () void PSKReporter::setLocalStation (QString const& call, QString const& gridSquare, QString const& antenna) { + m_->check_connection (); if (call != m_->rx_call_ || gridSquare != m_->rx_grid_ || antenna != m_->rx_ant_) { m_->send_receiver_data_ = m_->socket_ @@ -510,7 +521,14 @@ bool PSKReporter::addRemoteStation (QString const& call, QString const& grid, Ra return false; } -void PSKReporter::sendReport () +void PSKReporter::sendReport (bool last) { - m_->send_report (true); + if (m_->socket_ && QAbstractSocket::ConnectedState == m_->socket_->state ()) + { + m_->send_report (true); + } + if (last) + { + m_->stop (); + } } diff --git a/Network/PSKReporter.hpp b/Network/PSKReporter.hpp index 3582b5850..1757e63af 100644 --- a/Network/PSKReporter.hpp +++ b/Network/PSKReporter.hpp @@ -29,7 +29,7 @@ public: // // Flush any pending spots to PSK Reporter // - void sendReport (); + void sendReport (bool last = false); Q_SIGNAL void errorOccurred (QString const& reason); diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index 3f0ded867..829fdf1c6 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -1801,6 +1801,7 @@ void MainWindow::on_actionSettings_triggered() //Setup Dialog auto callsign = m_config.my_callsign (); auto my_grid = m_config.my_grid (); SpecOp nContest0=m_config.special_op_id(); + auto psk_on = m_config.spot_to_psk_reporter (); if (QDialog::Accepted == m_config.exec ()) { checkMSK144ContestType(); if (m_config.my_callsign () != callsign) { @@ -1815,6 +1816,12 @@ void MainWindow::on_actionSettings_triggered() //Setup Dialog enable_DXCC_entity (m_config.DXCC ()); // sets text window proportions and (re)inits the logbook pskSetLocal (); + // this will close the connection to PSKReporter if it has been + // disabled + if (psk_on && !m_config.spot_to_psk_reporter ()) + { + m_psk_Reporter.sendReport (true); + } if(m_config.restart_audio_input ()) { Q_EMIT startAudioInputStream (m_config.audio_input_device () @@ -7238,9 +7245,7 @@ void MainWindow::handle_transceiver_update (Transceiver::TransceiverState const& || !(ui->cbCQTx->isEnabled () && ui->cbCQTx->isVisible () && ui->cbCQTx->isChecked()))) { m_lastDialFreq = m_freqNominal; m_secBandChanged=QDateTime::currentMSecsSinceEpoch()/1000; - if (m_config.spot_to_psk_reporter ()) { - pskSetLocal (); - } + pskSetLocal (); statusChanged(); m_wideGraph->setDialFreq(m_freqNominal / 1.e6); }