From 498d4af7a90948c06fb68f24f08e06955b07c45e Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Thu, 8 Jan 2015 23:51:56 +0000 Subject: [PATCH] Rig polling not detecting changes against cached values correctly The PollingTransceiver class was not dealing with frequency change commands correctly when the mode was not specified. Improved some diagnostic messages. Only leave transmit mode when PTT is seen to drop. Merged from wsjtx-1.4 branch. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@4886 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- EmulateSplitTransceiver.cpp | 2 +- PollingTransceiver.cpp | 29 +++++++++++++++++++++++------ PollingTransceiver.hpp | 1 + TransceiverBase.cpp | 27 ++++++++++++++++++++++----- TransceiverBase.hpp | 2 +- mainwindow.cpp | 3 +-- 6 files changed, 49 insertions(+), 15 deletions(-) diff --git a/EmulateSplitTransceiver.cpp b/EmulateSplitTransceiver.cpp index 0e47a902c..8b2b9ee6d 100644 --- a/EmulateSplitTransceiver.cpp +++ b/EmulateSplitTransceiver.cpp @@ -100,7 +100,7 @@ void EmulateSplitTransceiver::handle_update (TransceiverState state) if (state.split ()) { - Q_EMIT failure (tr ("Emulated split mode requires rig to in simplex mode")); + Q_EMIT failure (tr ("Emulated split mode requires rig to be in simplex mode")); } else { diff --git a/PollingTransceiver.cpp b/PollingTransceiver.cpp index 8d4acadc8..d00783dcc 100644 --- a/PollingTransceiver.cpp +++ b/PollingTransceiver.cpp @@ -21,9 +21,6 @@ class PollingTransceiver::impl final { Q_OBJECT; -private: - Q_DISABLE_COPY (impl); - public: impl (PollingTransceiver * self, int poll_interval) : QObject {self} @@ -35,6 +32,9 @@ public: } private: + impl (impl const&) = delete; + impl& operator = (impl const&) = delete; + void start_timer () { if (interval_) @@ -108,11 +108,17 @@ void PollingTransceiver::do_post_stop () void PollingTransceiver::do_post_frequency (Frequency f, MODE m) { - if (m_->next_state_.frequency () != f || m_->next_state_.mode () != m) + // take care not to set the expected next mode to unknown since some + // callers use mode == unknown to signify that they do not know the + // mode and don't care + if (m_->next_state_.frequency () != f || (m != UNK && m_->next_state_.mode () != m)) { // update expected state with new frequency and set poll count m_->next_state_.frequency (f); - m_->next_state_.mode (m); + if (m != UNK) + { + m_->next_state_.mode (m); + } m_->retries_ = polls_to_stabilize; } } @@ -131,7 +137,8 @@ void PollingTransceiver::do_post_tx_frequency (Frequency f, bool /* rationalize void PollingTransceiver::do_post_mode (MODE m, bool /*rationalize_mode*/) { - if (m_->next_state_.mode () != m) + // we don't ever expect mode to goto to unknown + if (m != UNK && m_->next_state_.mode () != m) { // update expected state with new mode and set poll count m_->next_state_.mode (m); @@ -139,6 +146,16 @@ void PollingTransceiver::do_post_mode (MODE m, bool /*rationalize_mode*/) } } +void PollingTransceiver::do_post_ptt (bool p) +{ + if (m_->next_state_.ptt () != p) + { + // update expected state with new PTT and set poll count + m_->next_state_.ptt (p); + m_->retries_ = polls_to_stabilize; + } +} + bool PollingTransceiver::do_pre_update () { // if we are holding off a change then withhold the signal diff --git a/PollingTransceiver.hpp b/PollingTransceiver.hpp index 0abec495b..a27b7d031 100644 --- a/PollingTransceiver.hpp +++ b/PollingTransceiver.hpp @@ -52,6 +52,7 @@ protected: void do_post_frequency (Frequency, MODE = UNK) override final; void do_post_tx_frequency (Frequency, bool rationalize = true) override final; void do_post_mode (MODE, bool rationalize = true) override final; + void do_post_ptt (bool = true) override final; bool do_pre_update () override final; private: diff --git a/TransceiverBase.cpp b/TransceiverBase.cpp index 77c7f0e88..0db0bfb74 100644 --- a/TransceiverBase.cpp +++ b/TransceiverBase.cpp @@ -12,20 +12,38 @@ namespace } class TransceiverBase::impl final + : public QObject { + Q_OBJECT; + public: - impl () + impl (TransceiverBase * parent) + : parent_ {parent} { + connect (this, &TransceiverBase::impl::updated, this, &TransceiverBase::impl::update_complete, Qt::QueuedConnection); } impl (impl const&) = delete; impl& operator = (impl const&) = delete; + Q_SIGNAL void updated (); + Q_SLOT void update_complete () + { + if (parent_->do_pre_update ()) + { + Q_EMIT parent_->update (state_); + } + } + + TransceiverBase * parent_; TransceiverState state_; }; +#include "TransceiverBase.moc" + TransceiverBase::TransceiverBase () + : m_ {this} { } @@ -260,10 +278,9 @@ void TransceiverBase::update_PTT (bool state) void TransceiverBase::update_complete () { - if (do_pre_update ()) - { - Q_EMIT update (m_->state_); - } + // Use a signal to ensure that the calling function completes before + // the Transceiver::update signal is triggered. + Q_EMIT m_->updated (); } void TransceiverBase::offline (QString const& reason) diff --git a/TransceiverBase.hpp b/TransceiverBase.hpp index d42df9a0f..2cb06d6ca 100644 --- a/TransceiverBase.hpp +++ b/TransceiverBase.hpp @@ -120,7 +120,7 @@ protected: void update_mode (MODE); void update_PTT (bool = true); - // Calling this triggers the Transceiver::update(State) signal. + // Calling this eventually triggers the Transceiver::update(State) signal. void update_complete (); // sub class may asynchronously take the rig offline by calling this diff --git a/mainwindow.cpp b/mainwindow.cpp index 3a0f0890a..2f44fc6c6 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2883,8 +2883,7 @@ void MainWindow::on_cbPlus2kHz_toggled(bool checked) void MainWindow::handle_transceiver_update (Transceiver::TransceiverState s) { - - transmitDisplay (false); + transmitDisplay (s.ptt ()); if ((s.frequency () - m_dialFreq) || s.split () != m_splitMode) {