Remove local event loops from Omni-Rig interface

Using a local event loop to wait for Omni-Rig to initialize has caused
issues elsewhere, reverted to simple waits in teh hope that Omni-Rig
initializes promptly.
This commit is contained in:
Bill Somerville 2021-07-30 20:21:57 +01:00
parent 25cb82b14d
commit aa1225ff96
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
10 changed files with 227 additions and 178 deletions

View File

@ -26,7 +26,7 @@ if (WIN32)
add_custom_command ( add_custom_command (
OUTPUT ${outfile}.h ${outfile}.cpp OUTPUT ${outfile}.h ${outfile}.cpp
COMMAND ${DUMPCPP_Executable} COMMAND ${DUMPCPP_Executable}
ARGS ${AX_SERVER_options} -o "${outfile}" "${infile}" ARGS ${ax_server_options} -o "${outfile}" "${infile}"
MAIN_DEPENDENCY ${infile} VERBATIM) MAIN_DEPENDENCY ${infile} VERBATIM)
list (APPEND ${outfiles} ${outfile}.cpp) list (APPEND ${outfiles} ${outfile}.cpp)
endforeach() endforeach()

View File

@ -2735,6 +2735,7 @@ bool Configuration::impl::open_rig (bool force)
ui_->test_CAT_push_button->setStyleSheet ({}); ui_->test_CAT_push_button->setStyleSheet ({});
rig_active_ = true; rig_active_ = true;
LOG_TRACE ("emitting startup_transceiver");
Q_EMIT start_transceiver (++transceiver_command_number_); // start rig on its thread Q_EMIT start_transceiver (++transceiver_command_number_); // start rig on its thread
result = true; result = true;
} }
@ -2782,6 +2783,7 @@ void Configuration::impl::transceiver_frequency (Frequency f)
cached_rig_state_.frequency (apply_calibration (f + current_offset_)); cached_rig_state_.frequency (apply_calibration (f + current_offset_));
// qDebug () << "Configuration::impl::transceiver_frequency: n:" << transceiver_command_number_ + 1 << "f:" << f; // qDebug () << "Configuration::impl::transceiver_frequency: n:" << transceiver_command_number_ + 1 << "f:" << f;
LOG_TRACE ("emitting set_transceiver: requested state:" << cached_rig_state_);
Q_EMIT set_transceiver (cached_rig_state_, ++transceiver_command_number_); Q_EMIT set_transceiver (cached_rig_state_, ++transceiver_command_number_);
} }
@ -2808,6 +2810,7 @@ void Configuration::impl::transceiver_tx_frequency (Frequency f)
} }
// qDebug () << "Configuration::impl::transceiver_tx_frequency: n:" << transceiver_command_number_ + 1 << "f:" << f; // qDebug () << "Configuration::impl::transceiver_tx_frequency: n:" << transceiver_command_number_ + 1 << "f:" << f;
LOG_TRACE ("emitting set_transceiver: requested state:" << cached_rig_state_);
Q_EMIT set_transceiver (cached_rig_state_, ++transceiver_command_number_); Q_EMIT set_transceiver (cached_rig_state_, ++transceiver_command_number_);
} }
} }
@ -2817,6 +2820,7 @@ void Configuration::impl::transceiver_mode (MODE m)
cached_rig_state_.online (true); // we want the rig online cached_rig_state_.online (true); // we want the rig online
cached_rig_state_.mode (m); cached_rig_state_.mode (m);
// qDebug () << "Configuration::impl::transceiver_mode: n:" << transceiver_command_number_ + 1 << "m:" << m; // qDebug () << "Configuration::impl::transceiver_mode: n:" << transceiver_command_number_ + 1 << "m:" << m;
LOG_TRACE ("emitting set_transceiver: requested state:" << cached_rig_state_);
Q_EMIT set_transceiver (cached_rig_state_, ++transceiver_command_number_); Q_EMIT set_transceiver (cached_rig_state_, ++transceiver_command_number_);
} }
@ -2826,6 +2830,7 @@ void Configuration::impl::transceiver_ptt (bool on)
set_cached_mode (); set_cached_mode ();
cached_rig_state_.ptt (on); cached_rig_state_.ptt (on);
// qDebug () << "Configuration::impl::transceiver_ptt: n:" << transceiver_command_number_ + 1 << "on:" << on; // qDebug () << "Configuration::impl::transceiver_ptt: n:" << transceiver_command_number_ + 1 << "on:" << on;
LOG_TRACE ("emitting set_transceiver: requested state:" << cached_rig_state_);
Q_EMIT set_transceiver (cached_rig_state_, ++transceiver_command_number_); Q_EMIT set_transceiver (cached_rig_state_, ++transceiver_command_number_);
} }
@ -2909,6 +2914,7 @@ void Configuration::impl::close_rig ()
if (rig_active_) if (rig_active_)
{ {
ui_->test_CAT_push_button->setStyleSheet ("QPushButton {background-color: red;}"); ui_->test_CAT_push_button->setStyleSheet ("QPushButton {background-color: red;}");
LOG_TRACE ("emitting stop_transceiver");
Q_EMIT stop_transceiver (); Q_EMIT stop_transceiver ();
for (auto const& connection: rig_connections_) for (auto const& connection: rig_connections_)
{ {

View File

@ -42,6 +42,15 @@ namespace Radio
value = v.toDouble (); value = v.toDouble ();
if (ok) *ok = true; if (ok) *ok = true;
} }
if (ok && !*ok)
{
return value;
}
return frequency (value, scale, ok);
}
Frequency frequency (double value, int scale, bool * ok)
{
value *= std::pow (10., scale); value *= std::pow (10., scale);
if (ok) if (ok)
{ {
@ -50,6 +59,10 @@ namespace Radio
value = 0.; value = 0.;
*ok = false; *ok = false;
} }
else
{
*ok = true;
}
} }
return std::llround (value); return std::llround (value);
} }
@ -66,6 +79,15 @@ namespace Radio
value = v.toDouble (); value = v.toDouble ();
if (ok) *ok = true; if (ok) *ok = true;
} }
if (ok && !*ok)
{
return value;
}
return frequency_delta (value, scale, ok);
}
FrequencyDelta frequency_delta (double value, int scale, bool * ok)
{
value *= std::pow (10., scale); value *= std::pow (10., scale);
if (ok) if (ok)
{ {
@ -75,6 +97,10 @@ namespace Radio
value = 0.; value = 0.;
*ok = false; *ok = false;
} }
else
{
*ok = true;
}
} }
return std::llround (value); return std::llround (value);
} }

View File

@ -34,10 +34,12 @@ namespace Radio
// QVariant argument is convertible to double and is assumed to // QVariant argument is convertible to double and is assumed to
// be scaled by (10 ** -scale). // be scaled by (10 ** -scale).
// //
Frequency UDP_EXPORT frequency (QVariant const&, int scale, Frequency UDP_EXPORT frequency (QVariant const&, int scale = 0,
bool * ok = nullptr, QLocale const& = QLocale ()); bool * ok = nullptr, QLocale const& = QLocale ());
FrequencyDelta UDP_EXPORT frequency_delta (QVariant const&, int scale, FrequencyDelta UDP_EXPORT frequency_delta (QVariant const&, int scale = 0,
bool * ok = nullptr, QLocale const& = QLocale ()); bool * ok = nullptr, QLocale const& = QLocale ());
Frequency UDP_EXPORT frequency (double, int scale = 0, bool * ok = nullptr);
FrequencyDelta UDP_EXPORT frequency_delta (double, int scale = 0, bool * ok = nullptr);
// //
// Frequency type formatting // Frequency type formatting

View File

@ -1128,7 +1128,7 @@ void HamlibTransceiver::do_poll ()
{ {
m_->error_check (rig_get_freq (m_->rig_.data (), RIG_VFO_CURR, &f), tr ("getting current VFO frequency")); m_->error_check (rig_get_freq (m_->rig_.data (), RIG_VFO_CURR, &f), tr ("getting current VFO frequency"));
f = std::round (f); f = std::round (f);
CAT_TRACE ("rig_get_freq frequency=" << f); CAT_TRACE ("rig_get_freq frequency=" << Radio::frequency (f));
update_rx_frequency (f); update_rx_frequency (f);
} }

View File

@ -96,11 +96,11 @@ void OmniRigTransceiver::register_transceivers (logger_type *,
}; };
} }
OmniRigTransceiver::OmniRigTransceiver (logger_type * logger, OmniRigTransceiver::OmniRigTransceiver (logger_type * the_logger,
std::unique_ptr<TransceiverBase> wrapped, std::unique_ptr<TransceiverBase> wrapped,
RigNumber n, TransceiverFactory::PTTMethod ptt_type, RigNumber n, TransceiverFactory::PTTMethod ptt_type,
QString const& ptt_port, QObject * parent) QString const& ptt_port, QObject * parent)
: TransceiverBase {logger, parent} : TransceiverBase {the_logger, parent}
, wrapped_ {std::move (wrapped)} , wrapped_ {std::move (wrapped)}
, use_for_ptt_ {TransceiverFactory::PTT_method_CAT == ptt_type || ("CAT" == ptt_port && (TransceiverFactory::PTT_method_RTS == ptt_type || TransceiverFactory::PTT_method_DTR == ptt_type))} , use_for_ptt_ {TransceiverFactory::PTT_method_CAT == ptt_type || ("CAT" == ptt_port && (TransceiverFactory::PTT_method_RTS == ptt_type || TransceiverFactory::PTT_method_DTR == ptt_type))}
, ptt_type_ {ptt_type} , ptt_type_ {ptt_type}
@ -111,173 +111,131 @@ OmniRigTransceiver::OmniRigTransceiver (logger_type * logger,
, reversed_ {false} , reversed_ {false}
{ {
CoInitializeEx (nullptr, 0 /*COINIT_APARTMENTTHREADED*/); // required because Qt only does this for GUI thread CoInitializeEx (nullptr, 0 /*COINIT_APARTMENTTHREADED*/); // required because Qt only does this for GUI thread
CAT_TRACE ("constructed");
} }
OmniRigTransceiver::~OmniRigTransceiver () OmniRigTransceiver::~OmniRigTransceiver ()
{ {
CAT_TRACE ("destroying");
CoUninitialize (); CoUninitialize ();
} }
// returns false on time out
bool OmniRigTransceiver::await_notification_with_timeout (int timeout)
{
QEventLoop el;
connect (this, &OmniRigTransceiver::notified, &el, [&el] () {el.exit (1);});
QTimer::singleShot (timeout, Qt::CoarseTimer, &el, [&el] () {el.exit (0);});
return 1 == el.exec (); // wait for notify or timer
}
int OmniRigTransceiver::do_start () int OmniRigTransceiver::do_start ()
{ {
CAT_TRACE ("starting"); CAT_TRACE ("starting");
try
if (wrapped_) wrapped_->start (0);
omni_rig_.reset (new OmniRig::OmniRigX {this});
if (omni_rig_->isNull ())
{ {
CAT_ERROR ("failed to start COM server"); if (wrapped_) wrapped_->start (0);
throw_qstring (tr ("Failed to start OmniRig COM server"));
}
// COM/OLE exceptions get signaled omni_rig_.reset (new OmniRig::OmniRigX {this});
connect (&*omni_rig_, SIGNAL (exception (int, QString, QString, QString)), this, SLOT (handle_COM_exception (int, QString, QString, QString))); if (omni_rig_->isNull ())
{
// IOmniRigXEvent interface signals CAT_ERROR ("failed to start COM server");
connect (&*omni_rig_, SIGNAL (VisibleChange ()), this, SLOT (handle_visible_change ())); throw_qstring (tr ("Failed to start OmniRig COM server"));
connect (&*omni_rig_, SIGNAL (RigTypeChange (int)), this, SLOT (handle_rig_type_change (int))); }
connect (&*omni_rig_, SIGNAL (StatusChange (int)), this, SLOT (handle_status_change (int)));
connect (&*omni_rig_, SIGNAL (ParamsChange (int, int)), this, SLOT (handle_params_change (int, int)));
connect (&*omni_rig_
, SIGNAL (CustomReply (int, QVariant const&, QVariant const&))
, this, SLOT (handle_custom_reply (int, QVariant const&, QVariant const&)));
CAT_INFO ("OmniRig s/w version: " << omni_rig_->SoftwareVersion ()
<< "i/f version: " << omni_rig_->InterfaceVersion ());
// fetch the interface of the RigX CoClass and instantiate a proxy object
switch (rig_number_)
{
case One: rig_.reset (new OmniRig::RigX (omni_rig_->Rig1 ())); break;
case Two: rig_.reset (new OmniRig::RigX (omni_rig_->Rig2 ())); break;
}
Q_ASSERT (rig_);
Q_ASSERT (!rig_->isNull ());
// COM/OLE exceptions get signaled
connect (&*rig_, SIGNAL (exception (int, QString, QString, QString)), this, SLOT (handle_COM_exception (int, QString, QString, QString)));
offline_timer_.reset (new QTimer); // instantiate here as
// constructor runs in wrong
// thread
offline_timer_->setSingleShot (true);
connect (offline_timer_.data (), &QTimer::timeout, [this] () {offline ("Rig went offline");});
if (use_for_ptt_ && (TransceiverFactory::PTT_method_DTR == ptt_type_ || TransceiverFactory::PTT_method_RTS == ptt_type_))
{
// fetch the interface for the serial port if we need it for PTT
port_.reset (new OmniRig::PortBits (rig_->PortBits ()));
Q_ASSERT (port_);
Q_ASSERT (!port_->isNull ());
// COM/OLE exceptions get signaled // COM/OLE exceptions get signaled
connect (&*port_, SIGNAL (exception (int, QString, QString, QString)), this, SLOT (handle_COM_exception (int, QString, QString, QString))); connect (&*omni_rig_, SIGNAL (exception (int, QString, QString, QString)), this, SLOT (handle_COM_exception (int, QString, QString, QString)));
CAT_TRACE ("OmniRig RTS state: " << port_->Rts ()); // IOmniRigXEvent interface signals
connect (&*omni_rig_, SIGNAL (VisibleChange ()), this, SLOT (handle_visible_change ()));
connect (&*omni_rig_, SIGNAL (RigTypeChange (int)), this, SLOT (handle_rig_type_change (int)));
connect (&*omni_rig_, SIGNAL (StatusChange (int)), this, SLOT (handle_status_change (int)));
connect (&*omni_rig_, SIGNAL (ParamsChange (int, int)), this, SLOT (handle_params_change (int, int)));
connect (&*omni_rig_
, SIGNAL (CustomReply (int, QVariant const&, QVariant const&))
, this, SLOT (handle_custom_reply (int, QVariant const&, QVariant const&)));
// remove locking because it doesn't seem to work properly CAT_INFO ("OmniRig s/w version: " << static_cast<quint16> (omni_rig_->SoftwareVersion () >> 16)
// if (!port_->Lock ()) // try to take exclusive use of the OmniRig serial port for PTT << '.' << static_cast<quint16> (omni_rig_->SoftwareVersion () & 0xffff)
// { << " i/f version: " << static_cast<int> (omni_rig_->InterfaceVersion () >> 8 & 0xff)
// CAT_WARNING ("Failed to get exclusive use of serial port for PTT from OmniRig"); << '.' << static_cast<int> (omni_rig_->InterfaceVersion () && 0xff));
// }
// start off so we don't accidentally key the radio // fetch the interface of the RigX CoClass and instantiate a proxy object
if (TransceiverFactory::PTT_method_DTR == ptt_type_) switch (rig_number_)
{ {
port_->SetDtr (false); case One: rig_.reset (new OmniRig::RigX (omni_rig_->Rig1 ())); break;
case Two: rig_.reset (new OmniRig::RigX (omni_rig_->Rig2 ())); break;
} }
else // RTS
{
port_->SetRts (false);
}
}
rig_type_ = rig_->RigType (); Q_ASSERT (rig_);
readable_params_ = rig_->ReadableParams (); Q_ASSERT (!rig_->isNull ());
writable_params_ = rig_->WriteableParams ();
CAT_INFO (QString {"OmniRig initial rig type: %1 readable params=0x%2 writable params=0x%3 for rig %4"} // COM/OLE exceptions get signaled
.arg (rig_type_) connect (&*rig_, SIGNAL (exception (int, QString, QString, QString)), this, SLOT (handle_COM_exception (int, QString, QString, QString)));
.arg (readable_params_, 8, 16, QChar ('0'))
.arg (writable_params_, 8, 16, QChar ('0')) offline_timer_.reset (new QTimer); // instantiate here as constructor runs in wrong thread
.arg (rig_number_)); offline_timer_->setSingleShot (true);
for (int i = 0; i < 5; ++i) connect (offline_timer_.data (), &QTimer::timeout, [this] () {offline ("Rig went offline");});
{
if (OmniRig::ST_ONLINE == rig_->Status ()) for (int i = 0; i < 5; ++i)
{ {
break; // leave some time for Omni-Rig to do its first poll
QThread::msleep (250);
if (OmniRig::ST_ONLINE == rig_->Status ())
{
break;
}
} }
await_notification_with_timeout (1000);
} if (OmniRig::ST_ONLINE != rig_->Status ())
if (OmniRig::ST_ONLINE != rig_->Status ()) {
{ CAT_ERROR ("rig not online");
throw_qstring ("OmniRig: " + rig_->StatusStr ()); throw_qstring ("OmniRig: " + rig_->StatusStr ());
} }
QThread::msleep (500); // leave some time for Omni-Rig to get
// the rig status for the 1st. time if (use_for_ptt_ && (TransceiverFactory::PTT_method_DTR == ptt_type_ || TransceiverFactory::PTT_method_RTS == ptt_type_))
auto f = rig_->GetRxFrequency (); {
for (int i = 0; (f == 0) && (i < 5); ++i) // fetch the interface for the serial port if we need it for PTT
{ port_.reset (new OmniRig::PortBits (rig_->PortBits ()));
await_notification_with_timeout (1000);
f = rig_->GetRxFrequency (); Q_ASSERT (port_);
} Q_ASSERT (!port_->isNull ());
update_rx_frequency (f);
int resolution {0}; // COM/OLE exceptions get signaled
if (OmniRig::PM_UNKNOWN == rig_->Vfo () connect (&*port_, SIGNAL (exception (int, QString, QString, QString)), this, SLOT (handle_COM_exception (int, QString, QString, QString)));
&& (writable_params_ & (OmniRig::PM_VFOA | OmniRig::PM_VFOB))
== (OmniRig::PM_VFOA | OmniRig::PM_VFOB)) CAT_TRACE ("OmniRig RTS state: " << port_->Rts ());
{
// start with VFO A (probably MAIN) on rigs that we // remove locking because it doesn't seem to work properly
// can't query VFO but can set explicitly // if (!port_->Lock ()) // try to take exclusive use of the OmniRig serial port for PTT
rig_->SetVfo (OmniRig::PM_VFOA); // {
} // CAT_WARNING ("Failed to get exclusive use of serial port for PTT from OmniRig");
f = state ().frequency (); // }
if (f % 10) return resolution; // 1Hz resolution
auto test_frequency = f - f % 100 + 55; // start off so we don't accidentally key the radio
if (OmniRig::PM_FREQ & writable_params_) if (TransceiverFactory::PTT_method_DTR == ptt_type_)
{ {
rig_->SetFreq (test_frequency); port_->SetDtr (false);
} }
else if (reversed_ && (OmniRig::PM_FREQB & writable_params_)) else // RTS
{ {
rig_->SetFreqB (test_frequency); port_->SetRts (false);
} }
else if (!reversed_ && (OmniRig::PM_FREQA & writable_params_)) }
{
rig_->SetFreqA (test_frequency); rig_type_ = rig_->RigType ();
} readable_params_ = rig_->ReadableParams ();
else writable_params_ = rig_->WriteableParams ();
{
throw_qstring (tr ("OmniRig: don't know how to set rig frequency")); CAT_INFO (QString {"OmniRig initial rig type: %1 readable params=0x%2 writable params=0x%3 for rig %4"}
} .arg (rig_type_)
if (!await_notification_with_timeout (1000)) .arg (readable_params_, 8, 16, QChar ('0'))
{ .arg (writable_params_, 8, 16, QChar ('0'))
CAT_ERROR ("do_start 1: wait timed out"); .arg (rig_number_));
throw_qstring (tr ("OmniRig: timeout waiting for update from rig")); update_rx_frequency (rig_->GetRxFrequency ());
} int resolution {0};
switch (rig_->GetRxFrequency () - test_frequency) if (OmniRig::PM_UNKNOWN == rig_->Vfo ()
{ && (writable_params_ & (OmniRig::PM_VFOA | OmniRig::PM_VFOB))
case -5: resolution = -1; break; // 10Hz truncated == (OmniRig::PM_VFOA | OmniRig::PM_VFOB))
case 5: resolution = 1; break; // 10Hz rounded {
case -15: resolution = -2; break; // 20Hz truncated // start with VFO A (probably MAIN) on rigs that we
case -55: resolution = -2; break; // 100Hz truncated // can't query VFO but can set explicitly
case 45: resolution = 2; break; // 100Hz rounded rig_->SetVfo (OmniRig::PM_VFOA);
} }
if (1 == resolution) // may be 20Hz rounded auto f = state ().frequency ();
{ if (f % 10) return resolution; // 1Hz resolution
test_frequency = f - f % 100 + 51; auto test_frequency = f - f % 100 + 55;
if (OmniRig::PM_FREQ & writable_params_) if (OmniRig::PM_FREQ & writable_params_)
{ {
rig_->SetFreq (test_frequency); rig_->SetFreq (test_frequency);
@ -290,34 +248,65 @@ int OmniRigTransceiver::do_start ()
{ {
rig_->SetFreqA (test_frequency); rig_->SetFreqA (test_frequency);
} }
if (!await_notification_with_timeout (2000)) else
{ {
CAT_ERROR ("do_start 2: wait timed out"); throw_qstring (tr ("OmniRig: don't know how to set rig frequency"));
throw_qstring (tr ("OmniRig: timeout waiting for update from rig"));
} }
if (9 == rig_->GetRxFrequency () - test_frequency) switch (rig_->GetRxFrequency () - test_frequency)
{ {
resolution = 2; // 20Hz rounded case -5: resolution = -1; break; // 10Hz truncated
case 5: resolution = 1; break; // 10Hz rounded
case -15: resolution = -2; break; // 20Hz truncated
case -55: resolution = -2; break; // 100Hz truncated
case 45: resolution = 2; break; // 100Hz rounded
} }
if (1 == resolution) // may be 20Hz rounded
{
test_frequency = f - f % 100 + 51;
if (OmniRig::PM_FREQ & writable_params_)
{
rig_->SetFreq (test_frequency);
}
else if (reversed_ && (OmniRig::PM_FREQB & writable_params_))
{
rig_->SetFreqB (test_frequency);
}
else if (!reversed_ && (OmniRig::PM_FREQA & writable_params_))
{
rig_->SetFreqA (test_frequency);
}
if (9 == rig_->GetRxFrequency () - test_frequency)
{
resolution = 2; // 20Hz rounded
}
}
if (OmniRig::PM_FREQ & writable_params_)
{
rig_->SetFreq (f);
}
else if (reversed_ && (OmniRig::PM_FREQB & writable_params_))
{
rig_->SetFreqB (f);
}
else if (!reversed_ && (OmniRig::PM_FREQA & writable_params_))
{
rig_->SetFreqA (f);
}
update_rx_frequency (f);
CAT_TRACE ("started");
return resolution;
} }
if (OmniRig::PM_FREQ & writable_params_) catch (...)
{ {
rig_->SetFreq (f); CAT_TRACE ("start threw exception");
throw;
} }
else if (reversed_ && (OmniRig::PM_FREQB & writable_params_))
{
rig_->SetFreqB (f);
}
else if (!reversed_ && (OmniRig::PM_FREQA & writable_params_))
{
rig_->SetFreqA (f);
}
update_rx_frequency (f);
return resolution;
} }
void OmniRigTransceiver::do_stop () void OmniRigTransceiver::do_stop ()
{ {
CAT_TRACE ("stopping");
QThread::msleep (200); // leave some time for pending QThread::msleep (200); // leave some time for pending
// commands at the server end // commands at the server end
@ -337,6 +326,7 @@ void OmniRigTransceiver::do_stop ()
{ {
rig_->clear (); rig_->clear ();
rig_.reset (); rig_.reset ();
CAT_TRACE ("rig_ reset");
} }
omni_rig_->clear (); omni_rig_->clear ();
omni_rig_.reset (); omni_rig_.reset ();
@ -396,7 +386,6 @@ void OmniRigTransceiver::handle_status_change (int rig_number)
else else
{ {
offline_timer_->stop (); // good to go again offline_timer_->stop (); // good to go again
Q_EMIT notified ();
} }
// else // else
// { // {
@ -467,7 +456,6 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
if (params & OmniRig::PM_FREQ) if (params & OmniRig::PM_FREQ)
{ {
CAT_TRACE ("FREQ");
need_frequency = true; need_frequency = true;
} }
if (params & OmniRig::PM_FREQA) if (params & OmniRig::PM_FREQA)
@ -653,7 +641,6 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
} }
CAT_TRACE ("OmniRig params change: state after:" << state ()); CAT_TRACE ("OmniRig params change: state after:" << state ());
} }
Q_EMIT notified ();
} }
void OmniRigTransceiver::handle_custom_reply (int rig_number, QVariant const& command, QVariant const& reply) void OmniRigTransceiver::handle_custom_reply (int rig_number, QVariant const& command, QVariant const& reply)
@ -710,7 +697,7 @@ void OmniRigTransceiver::do_ptt (bool on)
void OmniRigTransceiver::do_frequency (Frequency f, MODE m, bool /*no_ignore*/) void OmniRigTransceiver::do_frequency (Frequency f, MODE m, bool /*no_ignore*/)
{ {
CAT_TRACE (f << state ()); CAT_TRACE (f << ' ' << state ());
if (!rig_ || rig_->isNull ()) return; if (!rig_ || rig_->isNull ()) return;
if (UNK != m) if (UNK != m)
{ {
@ -739,7 +726,7 @@ void OmniRigTransceiver::do_frequency (Frequency f, MODE m, bool /*no_ignore*/)
void OmniRigTransceiver::do_tx_frequency (Frequency tx, MODE m, bool /*no_ignore*/) void OmniRigTransceiver::do_tx_frequency (Frequency tx, MODE m, bool /*no_ignore*/)
{ {
CAT_TRACE (tx << state ()); CAT_TRACE (tx << ' ' << state ());
if (!rig_ || rig_->isNull ()) return; if (!rig_ || rig_->isNull ()) return;
bool split {tx != 0}; bool split {tx != 0};
if (split) if (split)
@ -804,7 +791,7 @@ void OmniRigTransceiver::do_tx_frequency (Frequency tx, MODE m, bool /*no_ignore
void OmniRigTransceiver::do_mode (MODE mode) void OmniRigTransceiver::do_mode (MODE mode)
{ {
CAT_TRACE (mode << state ()); CAT_TRACE (mode << ' ' << state ());
if (!rig_ || rig_->isNull ()) return; if (!rig_ || rig_->isNull ()) return;
// TODO: G4WJS OmniRig doesn't seem to have any capability of tracking/setting VFO B mode // TODO: G4WJS OmniRig doesn't seem to have any capability of tracking/setting VFO B mode
auto mapped = map_mode (mode); auto mapped = map_mode (mode);

View File

@ -44,9 +44,6 @@ public:
void do_ptt (bool on) override; void do_ptt (bool on) override;
private: private:
bool await_notification_with_timeout (int timeout);
Q_SIGNAL void notified () const;
// Q_SLOT void timeout_check ();
Q_SLOT void handle_COM_exception (int, QString, QString, QString); Q_SLOT void handle_COM_exception (int, QString, QString, QString);
Q_SLOT void handle_visible_change (); Q_SLOT void handle_visible_change ();
Q_SLOT void handle_rig_type_change (int rig_number); Q_SLOT void handle_rig_type_change (int rig_number);

View File

@ -23,6 +23,12 @@ QDebug operator << (QDebug d, Transceiver::TransceiverState const& s)
} }
#endif #endif
std::ostream& operator << (std::ostream& os, Transceiver::MODE m)
{
auto const& mo = Transceiver::staticMetaObject; \
return os << mo.enumerator (mo.indexOfEnumerator ("MODE")).valueToKey (static_cast<int> (m)); \
}
std::ostream& operator << (std::ostream& os, Transceiver::TransceiverState const& s) std::ostream& operator << (std::ostream& os, Transceiver::TransceiverState const& s)
{ {
return os return os

View File

@ -169,6 +169,7 @@ Q_DECLARE_METATYPE (Transceiver::TransceiverState);
QDebug operator << (QDebug, Transceiver::TransceiverState const&); QDebug operator << (QDebug, Transceiver::TransceiverState const&);
#endif #endif
std::ostream& operator << (std::ostream&, Transceiver::MODE);
std::ostream& operator << (std::ostream&, Transceiver::TransceiverState const&); std::ostream& operator << (std::ostream&, Transceiver::TransceiverState const&);
ENUM_QDATASTREAM_OPS_DECL (Transceiver, MODE); ENUM_QDATASTREAM_OPS_DECL (Transceiver, MODE);

View File

@ -16,6 +16,8 @@ namespace
void TransceiverBase::start (unsigned sequence_number) noexcept void TransceiverBase::start (unsigned sequence_number) noexcept
{ {
CAT_TRACE ("#: " << sequence_number);
QString message; QString message;
try try
{ {
@ -26,10 +28,12 @@ void TransceiverBase::start (unsigned sequence_number) noexcept
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
CAT_TRACE ("#: " << sequence_number << " what: " << e.what ());
message = e.what (); message = e.what ();
} }
catch (...) catch (...)
{ {
CAT_TRACE ("#: " << sequence_number);
message = unexpected; message = unexpected;
} }
if (!message.isEmpty ()) if (!message.isEmpty ())
@ -41,7 +45,7 @@ void TransceiverBase::start (unsigned sequence_number) noexcept
void TransceiverBase::set (TransceiverState const& s, void TransceiverBase::set (TransceiverState const& s,
unsigned sequence_number) noexcept unsigned sequence_number) noexcept
{ {
CAT_TRACE ("#: " << sequence_number << " " << s); CAT_TRACE ("#: " << s);
QString message; QString message;
try try
@ -119,10 +123,12 @@ void TransceiverBase::set (TransceiverState const& s,
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
CAT_TRACE ("#: " << sequence_number << " what: " << e.what ());
message = e.what (); message = e.what ();
} }
catch (...) catch (...)
{ {
CAT_TRACE ("#: " << sequence_number << " " << sequence_number);
message = unexpected; message = unexpected;
} }
if (!message.isEmpty ()) if (!message.isEmpty ())
@ -133,6 +139,7 @@ void TransceiverBase::set (TransceiverState const& s,
void TransceiverBase::startup () void TransceiverBase::startup ()
{ {
CAT_TRACE ("startup");
QString message; QString message;
try try
{ {
@ -144,10 +151,12 @@ void TransceiverBase::startup ()
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
CAT_TRACE ("startup" << " what: " << e.what ());
message = e.what (); message = e.what ();
} }
catch (...) catch (...)
{ {
CAT_TRACE ("startup");
message = unexpected; message = unexpected;
} }
if (!message.isEmpty ()) if (!message.isEmpty ())
@ -158,6 +167,7 @@ void TransceiverBase::startup ()
void TransceiverBase::shutdown () void TransceiverBase::shutdown ()
{ {
CAT_TRACE ("shutdown");
may_update u {this}; may_update u {this};
if (requested_.online ()) if (requested_.online ())
{ {
@ -177,6 +187,7 @@ void TransceiverBase::shutdown ()
} }
catch (...) catch (...)
{ {
CAT_TRACE ("shutdown");
// don't care about exceptions // don't care about exceptions
} }
} }
@ -186,6 +197,7 @@ void TransceiverBase::shutdown ()
void TransceiverBase::stop () noexcept void TransceiverBase::stop () noexcept
{ {
CAT_TRACE ("stop");
QString message; QString message;
try try
{ {
@ -193,10 +205,12 @@ void TransceiverBase::stop () noexcept
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
CAT_TRACE ("stop" << " what: " << e.what ());
message = e.what (); message = e.what ();
} }
catch (...) catch (...)
{ {
CAT_TRACE ("stop");
message = unexpected; message = unexpected;
} }
if (!message.isEmpty ()) if (!message.isEmpty ())
@ -211,6 +225,7 @@ void TransceiverBase::stop () noexcept
void TransceiverBase::update_rx_frequency (Frequency rx) void TransceiverBase::update_rx_frequency (Frequency rx)
{ {
CAT_TRACE ("frequency: " << rx);
if (rx) if (rx)
{ {
actual_.frequency (rx); actual_.frequency (rx);
@ -220,28 +235,35 @@ void TransceiverBase::update_rx_frequency (Frequency rx)
void TransceiverBase::update_other_frequency (Frequency tx) void TransceiverBase::update_other_frequency (Frequency tx)
{ {
CAT_TRACE ("frequency: " << tx);
actual_.tx_frequency (tx); actual_.tx_frequency (tx);
} }
void TransceiverBase::update_split (bool state) void TransceiverBase::update_split (bool state)
{ {
CAT_TRACE ("state: " << state);
actual_.split (state); actual_.split (state);
} }
void TransceiverBase::update_mode (MODE m) void TransceiverBase::update_mode (MODE m)
{ {
CAT_TRACE ("mode: " << m);
actual_.mode (m); actual_.mode (m);
requested_.mode (m); // track rig changes requested_.mode (m); // track rig changes
} }
void TransceiverBase::update_PTT (bool state) void TransceiverBase::update_PTT (bool state)
{ {
CAT_TRACE ("state: " << state);
actual_.ptt (state); actual_.ptt (state);
} }
void TransceiverBase::update_complete (bool force_signal) void TransceiverBase::update_complete (bool force_signal)
{ {
if ((do_pre_update () && actual_ != last_) || force_signal) CAT_TRACE ("force signal: " << force_signal);
if ((do_pre_update ()
&& actual_ != last_)
|| force_signal)
{ {
Q_EMIT update (actual_, last_sequence_number_); Q_EMIT update (actual_, last_sequence_number_);
last_ = actual_; last_ = actual_;
@ -250,6 +272,7 @@ void TransceiverBase::update_complete (bool force_signal)
void TransceiverBase::offline (QString const& reason) void TransceiverBase::offline (QString const& reason)
{ {
CAT_TRACE ("reason: " << reason);
Q_EMIT failure (reason); Q_EMIT failure (reason);
try try
{ {
@ -257,6 +280,7 @@ void TransceiverBase::offline (QString const& reason)
} }
catch (...) catch (...)
{ {
CAT_TRACE ("reason: " << reason);
// don't care // don't care
} }
} }