Add a log channel for rig control

RIGCTRL is defined as a log channel for rig control messages and the
appropriate logger is made available to children of the Transceiver
class. Use Transceiver::logger() to access the logger.

Switched existing rig control QDebug messages to Boost logging.
This commit is contained in:
Bill Somerville 2020-09-25 02:37:41 +01:00
parent bd529c0ce5
commit cbd4f109a8
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
19 changed files with 361 additions and 403 deletions

View File

@ -166,6 +166,7 @@
#include <QDebug>
#include "pimpl_impl.hpp"
#include "Logger.hpp"
#include "qt_helpers.hpp"
#include "MetaDataRegistry.hpp"
#include "SettingsGroup.hpp"
@ -792,10 +793,7 @@ bool Configuration::is_dummy_rig () const
bool Configuration::transceiver_online ()
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_online: " << m_->cached_rig_state_;
#endif
LOG_TRACE ("transceiver_online: " << m_->cached_rig_state_);
return m_->have_rig ();
}
@ -806,54 +804,37 @@ int Configuration::transceiver_resolution () const
void Configuration::transceiver_offline ()
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_offline:" << m_->cached_rig_state_;
#endif
LOG_TRACE ("transceiver_offline: " << m_->cached_rig_state_);
m_->close_rig ();
}
void Configuration::transceiver_frequency (Frequency f)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_frequency:" << f << m_->cached_rig_state_;
#endif
LOG_TRACE ("transceiver_frequency: " << f << m_->cached_rig_state_);
m_->transceiver_frequency (f);
}
void Configuration::transceiver_tx_frequency (Frequency f)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_tx_frequency:" << f << m_->cached_rig_state_;
#endif
LOG_TRACE ("transceiver_tx_frequency: " << f << m_->cached_rig_state_);
m_->transceiver_tx_frequency (f);
}
void Configuration::transceiver_mode (MODE mode)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_mode:" << mode << m_->cached_rig_state_;
#endif
LOG_TRACE ("transceiver_mode: " << mode << " " << m_->cached_rig_state_);
m_->transceiver_mode (mode);
}
void Configuration::transceiver_ptt (bool on)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_ptt:" << on << m_->cached_rig_state_;
#endif
LOG_TRACE ("transceiver_ptt: " << on << " " << m_->cached_rig_state_);
m_->transceiver_ptt (on);
}
void Configuration::sync_transceiver (bool force_signal, bool enforce_mode_and_split)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::sync_transceiver: force signal:" << force_signal << "enforce_mode_and_split:" << enforce_mode_and_split << m_->cached_rig_state_;
#endif
LOG_TRACE ("sync_transceiver: force signal: " << force_signal << " enforce_mode_and_split: " << enforce_mode_and_split << " " << m_->cached_rig_state_);
m_->sync_transceiver (force_signal);
if (!enforce_mode_and_split)
{
@ -2723,9 +2704,7 @@ void Configuration::impl::sync_transceiver (bool /*force_signal*/)
void Configuration::impl::handle_transceiver_update (TransceiverState const& state,
unsigned sequence_number)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::handle_transceiver_update: Transceiver State #:" << sequence_number << state;
#endif
LOG_TRACE ("handle_transceiver_update: Transceiver State #: " << sequence_number << " " << state);
// only follow rig on some information, ignore other stuff
cached_rig_state_.online (state.online ());
@ -2773,10 +2752,7 @@ void Configuration::impl::handle_transceiver_update (TransceiverState const& sta
void Configuration::impl::handle_transceiver_failure (QString const& reason)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::handle_transceiver_failure: reason:" << reason;
#endif
LOG_TRACE ("handle_transceiver_failure: reason: " << reason);
close_rig ();
ui_->test_PTT_push_button->setChecked (false);

View File

@ -6,6 +6,7 @@
#include <QThread>
#include <QDateTime>
#include "qt_helpers.hpp"
#include "Network/NetworkServerLookup.hpp"
#include "moc_DXLabSuiteCommanderTransceiver.cpp"
@ -36,15 +37,18 @@ namespace
}
}
void DXLabSuiteCommanderTransceiver::register_transceivers (TransceiverFactory::Transceivers * registry, int id)
void DXLabSuiteCommanderTransceiver::register_transceivers (logger_type * /*logger*/,
TransceiverFactory::Transceivers * registry,
int id)
{
(*registry)[commander_transceiver_name] = TransceiverFactory::Capabilities {id, TransceiverFactory::Capabilities::network, true};
}
DXLabSuiteCommanderTransceiver::DXLabSuiteCommanderTransceiver (std::unique_ptr<TransceiverBase> wrapped,
DXLabSuiteCommanderTransceiver::DXLabSuiteCommanderTransceiver (logger_type * logger,
std::unique_ptr<TransceiverBase> wrapped,
QString const& address, bool use_for_ptt,
int poll_interval, QObject * parent)
: PollingTransceiver {poll_interval, parent}
: PollingTransceiver {logger, poll_interval, parent}
, wrapped_ {std::move (wrapped)}
, use_for_ptt_ {use_for_ptt}
, server_ {address}
@ -54,7 +58,7 @@ DXLabSuiteCommanderTransceiver::DXLabSuiteCommanderTransceiver (std::unique_ptr<
int DXLabSuiteCommanderTransceiver::do_start ()
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", "starting");
TRACE_CAT ("starting");
if (wrapped_) wrapped_->start (0);
auto server_details = network_server_lookup (server_, 52002u, QHostAddress::LocalHost, QAbstractSocket::IPv4Protocol);
@ -67,7 +71,7 @@ int DXLabSuiteCommanderTransceiver::do_start ()
commander_->connectToHost (std::get<0> (server_details), std::get<1> (server_details));
if (!commander_->waitForConnected ())
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", "failed to connect" << commander_->errorString ());
TRACE_CAT ("failed to connect" << commander_->errorString ());
throw error {tr ("Failed to connect to DX Lab Suite Commander\n") + commander_->errorString ()};
}
@ -123,7 +127,7 @@ int DXLabSuiteCommanderTransceiver::do_start ()
}
else
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", "get frequency unexpected response" << reply);
TRACE_CAT ("get frequency unexpected response" << reply);
throw error {tr ("DX Lab Suite Commander didn't respond correctly reading frequency: ") + reply};
}
@ -140,12 +144,12 @@ void DXLabSuiteCommanderTransceiver::do_stop ()
}
if (wrapped_) wrapped_->stop ();
TRACE_CAT ("DXLabSuiteCommanderTransceiver", "stopped");
TRACE_CAT ("stopped");
}
void DXLabSuiteCommanderTransceiver::do_ptt (bool on)
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", on << state ());
TRACE_CAT (on << state ());
if (use_for_ptt_)
{
simple_command (on ? "<command:5>CmdTX<parameters:0>" : "<command:5>CmdRX<parameters:0>");
@ -170,13 +174,13 @@ void DXLabSuiteCommanderTransceiver::do_ptt (bool on)
}
else
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", "unexpected TX state" << state);
TRACE_CAT ("unexpected TX state" << state);
throw error {tr ("DX Lab Suite Commander sent an unrecognised TX state: ") + state};
}
}
else
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", "get TX unexpected response" << reply);
TRACE_CAT ("get TX unexpected response" << reply);
throw error {tr ("DX Lab Suite Commander didn't respond correctly polling TX status: ") + reply};
}
if (tx != on) QThread::msleep (10); // don't thrash Commander
@ -184,7 +188,7 @@ void DXLabSuiteCommanderTransceiver::do_ptt (bool on)
update_PTT (tx);
if (tx != on)
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", "rig failed to respond to PTT: " << on);
TRACE_CAT ("rig failed to respond to PTT: " << on);
throw error {tr ("DX Lab Suite Commander rig did not respond to PTT: ") + (on ? "ON" : "OFF")};
}
}
@ -200,7 +204,7 @@ void DXLabSuiteCommanderTransceiver::do_ptt (bool on)
void DXLabSuiteCommanderTransceiver::do_frequency (Frequency f, MODE m, bool /*no_ignore*/)
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", f << state ());
TRACE_CAT (f << state ());
auto f_string = frequency_to_string (f);
if (UNK != m && m != get_mode ())
{
@ -219,7 +223,7 @@ void DXLabSuiteCommanderTransceiver::do_frequency (Frequency f, MODE m, bool /*n
void DXLabSuiteCommanderTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool /*no_ignore*/)
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", tx << state ());
TRACE_CAT (tx << state ());
if (tx)
{
auto f_string = frequency_to_string (tx);
@ -240,7 +244,7 @@ void DXLabSuiteCommanderTransceiver::do_tx_frequency (Frequency tx, MODE mode, b
void DXLabSuiteCommanderTransceiver::do_mode (MODE m)
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", m << state ());
TRACE_CAT (m << state ());
auto m_string = map_mode (m);
auto params = ("<1:%1>" + m_string).arg (m_string.size ());
simple_command (("<command:10>CmdSetMode<parameters:%1>" + params).arg (params.size ()));
@ -249,13 +253,7 @@ void DXLabSuiteCommanderTransceiver::do_mode (MODE m)
void DXLabSuiteCommanderTransceiver::do_poll ()
{
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
bool quiet {false};
#else
bool quiet {true};
#endif
auto reply = command_with_reply ("<command:10>CmdGetFreq<parameters:0>", quiet);
auto reply = command_with_reply ("<command:10>CmdGetFreq<parameters:0>");
if (0 == reply.indexOf ("<CmdFreq:"))
{
auto f = string_to_frequency (reply.mid (reply.indexOf ('>') + 1));
@ -270,13 +268,13 @@ void DXLabSuiteCommanderTransceiver::do_poll ()
}
else
{
TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "get frequency unexpected response" << reply);
TRACE_CAT_POLL ("get frequency unexpected response" << reply);
throw error {tr ("DX Lab Suite Commander didn't respond correctly polling frequency: ") + reply};
}
if (state ().split ())
{
reply = command_with_reply ("<command:12>CmdGetTXFreq<parameters:0>", quiet);
reply = command_with_reply ("<command:12>CmdGetTXFreq<parameters:0>");
if (0 == reply.indexOf ("<CmdTXFreq:"))
{
auto f = string_to_frequency (reply.mid (reply.indexOf ('>') + 1));
@ -291,12 +289,12 @@ void DXLabSuiteCommanderTransceiver::do_poll ()
}
else
{
TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "get tx frequency unexpected response" << reply);
TRACE_CAT_POLL ("get tx frequency unexpected response" << reply);
throw error {tr ("DX Lab Suite Commander didn't respond correctly polling TX frequency: ") + reply};
}
}
reply = command_with_reply ("<command:12>CmdSendSplit<parameters:0>", quiet);
reply = command_with_reply ("<command:12>CmdSendSplit<parameters:0>");
if (0 == reply.indexOf ("<CmdSplit:"))
{
auto split = reply.mid (reply.indexOf ('>') + 1);
@ -310,23 +308,23 @@ void DXLabSuiteCommanderTransceiver::do_poll ()
}
else
{
TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "unexpected split state" << split);
TRACE_CAT_POLL ("unexpected split state" << split);
throw error {tr ("DX Lab Suite Commander sent an unrecognised split state: ") + split};
}
}
else
{
TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "get split mode unexpected response" << reply);
TRACE_CAT_POLL ("get split mode unexpected response" << reply);
throw error {tr ("DX Lab Suite Commander didn't respond correctly polling split status: ") + reply};
}
get_mode (quiet);
get_mode ();
}
auto DXLabSuiteCommanderTransceiver::get_mode (bool no_debug) -> MODE
auto DXLabSuiteCommanderTransceiver::get_mode () -> MODE
{
MODE m {UNK};
auto reply = command_with_reply ("<command:11>CmdSendMode<parameters:0>", no_debug);
auto reply = command_with_reply ("<command:11>CmdSendMode<parameters:0>");
if (0 == reply.indexOf ("<CmdMode:"))
{
auto mode = reply.mid (reply.indexOf ('>') + 1);
@ -372,42 +370,39 @@ auto DXLabSuiteCommanderTransceiver::get_mode (bool no_debug) -> MODE
}
else
{
TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "unexpected mode name" << mode);
TRACE_CAT_POLL ("unexpected mode name" << mode);
throw error {tr ("DX Lab Suite Commander sent an unrecognised mode: \"") + mode + '"'};
}
update_mode (m);
}
else
{
TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "unexpected response" << reply);
TRACE_CAT_POLL ("unexpected response" << reply);
throw error {tr ("DX Lab Suite Commander didn't respond correctly polling mode: ") + reply};
}
return m;
}
void DXLabSuiteCommanderTransceiver::simple_command (QString const& cmd, bool no_debug)
void DXLabSuiteCommanderTransceiver::simple_command (QString const& cmd)
{
Q_ASSERT (commander_);
if (!no_debug)
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", cmd);
}
TRACE_CAT (cmd);
if (!write_to_port (cmd))
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", "failed:" << commander_->errorString ());
TRACE_CAT ("failed:" << commander_->errorString ());
throw error {tr ("DX Lab Suite Commander send command failed\n") + commander_->errorString ()};
}
}
QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd, bool no_debug)
QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd)
{
Q_ASSERT (commander_);
if (!write_to_port (cmd))
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", "failed to send command:" << commander_->errorString ());
TRACE_CAT ("failed to send command:" << commander_->errorString ());
throw error {
tr ("DX Lab Suite Commander send command failed \"%1\": %2\n")
.arg (cmd)
@ -424,7 +419,7 @@ QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd,
replied = commander_->waitForReadyRead ();
if (!replied && commander_->error () != commander_->SocketTimeoutError)
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", cmd << "failed to read reply:" << commander_->errorString ());
TRACE_CAT (cmd << "failed to read reply:" << commander_->errorString ());
throw error {
tr ("DX Lab Suite Commander send command \"%1\" read reply failed: %2\n")
.arg (cmd)
@ -435,7 +430,7 @@ QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd,
if (!replied)
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", cmd << "retries exhausted");
TRACE_CAT (cmd << "retries exhausted");
throw error {
tr ("DX Lab Suite Commander retries exhausted sending command \"%1\"")
.arg (cmd)
@ -449,11 +444,7 @@ QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd,
// qDebug () << i << ":" << hex << int (result[i]);
// }
if (!no_debug)
{
TRACE_CAT ("DXLabSuiteCommanderTransceiver", cmd << "->" << result);
}
TRACE_CAT (cmd << "->" << result);
return result; // converting raw UTF-8 bytes to QString
}

View File

@ -24,10 +24,10 @@ class DXLabSuiteCommanderTransceiver final
Q_OBJECT; // for translation context
public:
static void register_transceivers (TransceiverFactory::Transceivers *, int id);
static void register_transceivers (logger_type *, TransceiverFactory::Transceivers *, int id);
// takes ownership of wrapped Transceiver
explicit DXLabSuiteCommanderTransceiver (std::unique_ptr<TransceiverBase> wrapped,
explicit DXLabSuiteCommanderTransceiver (logger_type *, std::unique_ptr<TransceiverBase> wrapped,
QString const& address, bool use_for_ptt,
int poll_interval, QObject * parent = nullptr);
@ -42,9 +42,9 @@ protected:
void do_poll () override;
private:
MODE get_mode (bool no_debug = false);
void simple_command (QString const&, bool no_debug = false);
QString command_with_reply (QString const&, bool no_debug = false);
MODE get_mode ();
void simple_command (QString const&);
QString command_with_reply (QString const&);
bool write_to_port (QString const&);
QString frequency_to_string (Frequency) const;
Frequency string_to_frequency (QString) const;

View File

@ -2,8 +2,10 @@
#include "moc_EmulateSplitTransceiver.cpp"
EmulateSplitTransceiver::EmulateSplitTransceiver (std::unique_ptr<Transceiver> wrapped, QObject * parent)
: Transceiver {parent}
EmulateSplitTransceiver::EmulateSplitTransceiver (logger_type * logger,
std::unique_ptr<Transceiver> wrapped,
QObject * parent)
: Transceiver {logger, parent}
, wrapped_ {std::move (wrapped)}
, rx_frequency_ {0}
, tx_frequency_ {0}

View File

@ -31,7 +31,8 @@ class EmulateSplitTransceiver final
public:
// takes ownership of wrapped Transceiver
explicit EmulateSplitTransceiver (std::unique_ptr<Transceiver> wrapped,
explicit EmulateSplitTransceiver (logger_type *,
std::unique_ptr<Transceiver> wrapped,
QObject * parent = nullptr);
void set (TransceiverState const&,

View File

@ -23,7 +23,9 @@ namespace
#include "moc_HRDTransceiver.cpp"
void HRDTransceiver::register_transceivers (TransceiverFactory::Transceivers * registry, int id)
void HRDTransceiver::register_transceivers (logger_type *,
TransceiverFactory::Transceivers * registry,
int id)
{
(*registry)[HRD_transceiver_name] = TransceiverFactory::Capabilities (id, TransceiverFactory::Capabilities::network, true, true /* maybe */);
}
@ -70,13 +72,14 @@ struct HRDMessage
static qint32 constexpr magic_2_value_ = 0xABCD1234;
};
HRDTransceiver::HRDTransceiver (std::unique_ptr<TransceiverBase> wrapped
HRDTransceiver::HRDTransceiver (logger_type * logger
, std::unique_ptr<TransceiverBase> wrapped
, QString const& server
, bool use_for_ptt
, TransceiverFactory::TXAudioSource audio_source
, int poll_interval
, QObject * parent)
: PollingTransceiver {poll_interval, parent}
: PollingTransceiver {logger, poll_interval, parent}
, wrapped_ {std::move (wrapped)}
, use_for_ptt_ {use_for_ptt}
, audio_source_ {audio_source}
@ -111,7 +114,7 @@ HRDTransceiver::HRDTransceiver (std::unique_ptr<TransceiverBase> wrapped
int HRDTransceiver::do_start ()
{
TRACE_CAT ("HRDTransceiver", "starting");
TRACE_CAT ("starting");
if (wrapped_) wrapped_->start (0);
auto server_details = network_server_lookup (server_, 7809u);
@ -122,7 +125,7 @@ int HRDTransceiver::do_start ()
hrd_->connectToHost (std::get<0> (server_details), std::get<1> (server_details));
if (!hrd_->waitForConnected ())
{
TRACE_CAT ("HRDTransceiver", "failed to connect:" << hrd_->errorString ());
TRACE_CAT ("failed to connect:" << hrd_->errorString ());
throw error {tr ("Failed to connect to Ham Radio Deluxe\n") + hrd_->errorString ()};
}
@ -147,7 +150,7 @@ int HRDTransceiver::do_start ()
hrd_->connectToHost (std::get<0> (server_details), std::get<1> (server_details));
if (!hrd_->waitForConnected ())
{
TRACE_CAT ("HRDTransceiver", "failed to connect:" << hrd_->errorString ());
TRACE_CAT ("failed to connect:" << hrd_->errorString ());
throw error {tr ("Failed to connect to Ham Radio Deluxe\n") + hrd_->errorString ()};
}
@ -164,14 +167,14 @@ int HRDTransceiver::do_start ()
auto id = send_command ("get id", false, false);
auto version = send_command ("get version", false, false);
TRACE_CAT ("HRDTransceiver", "Id:" << id << "Version:" << version);
TRACE_CAT ("Id:" << id << "Version:" << version);
HRD_info << "Id: " << id << "\n";
HRD_info << "Version: " << version << "\n";
auto radios = send_command ("get radios", false, false).trimmed ().split (',', SkipEmptyParts);
if (radios.isEmpty ())
{
TRACE_CAT ("HRDTransceiver", "no rig found");
TRACE_CAT ("no rig found");
throw error {tr ("Ham Radio Deluxe: no rig found")};
}
@ -183,48 +186,46 @@ int HRDTransceiver::do_start ()
radios_.push_back (std::forward_as_tuple (entries[0].toUInt (), entries[1]));
}
#if WSJT_TRACE_CAT
TRACE_CAT ("HRDTransceiver", "radios:-");
TRACE_CAT ("radios:-");
Q_FOREACH (auto const& radio, radios_)
{
TRACE_CAT ("HRDTransceiver", "\t[" << std::get<0> (radio) << "] " << std::get<1> (radio));
TRACE_CAT ("\t[" << std::get<0> (radio) << "] " << std::get<1> (radio));
}
#endif
auto current_radio_name = send_command ("get radio", false, false, true);
auto current_radio_name = send_command ("get radio", false, false);
HRD_info << "Current radio: " << current_radio_name << "\n";
if (current_radio_name.isEmpty ())
{
TRACE_CAT ("HRDTransceiver", "no rig found");
TRACE_CAT ("no rig found");
throw error {tr ("Ham Radio Deluxe: no rig found")};
}
vfo_count_ = send_command ("get vfo-count").toUInt ();
HRD_info << "VFO count: " << vfo_count_ << "\n";
TRACE_CAT ("HRDTransceiver", "vfo count:" << vfo_count_);
TRACE_CAT ("vfo count:" << vfo_count_);
buttons_ = send_command ("get buttons").trimmed ().split (',', SkipEmptyParts).replaceInStrings (" ", "~");
TRACE_CAT ("HRDTransceiver", "HRD Buttons: " << buttons_);
TRACE_CAT ("HRD Buttons: " << buttons_.join (", "));
HRD_info << "Buttons: {" << buttons_.join (", ") << "}\n";
dropdown_names_ = send_command ("get dropdowns").trimmed ().split (',', SkipEmptyParts);
TRACE_CAT ("HRDTransceiver", "Dropdowns:");
TRACE_CAT ("Dropdowns:");
HRD_info << "Dropdowns:\n";
Q_FOREACH (auto const& dd, dropdown_names_)
{
auto selections = send_command ("get dropdown-list {" + dd + "}").trimmed ().split (',');
TRACE_CAT ("HRDTransceiver", "\t" << dd << ": {" << selections.join (", ") << "}");
TRACE_CAT ("\t" << dd << ": {" << selections.join (", ") << "}");
HRD_info << "\t" << dd << ": {" << selections.join (", ") << "}\n";
dropdowns_[dd] = selections;
}
slider_names_ = send_command ("get sliders").trimmed ().split (',', SkipEmptyParts).replaceInStrings (" ", "~");
TRACE_CAT ("HRDTransceiver", "Sliders:-");
TRACE_CAT ("Sliders:-");
HRD_info << "Sliders:\n";
Q_FOREACH (auto const& s, slider_names_)
{
auto range = send_command ("get slider-range " + current_radio_name + " " + s).trimmed ().split (',', SkipEmptyParts);
TRACE_CAT ("HRDTransceiver", "\t" << s << ": {" << range.join (", ") << "}");
TRACE_CAT ("\t" << s << ": {" << range.join (", ") << "}");
HRD_info << "\t" << s << ": {" << range.join (", ") << "}\n";
sliders_[s] = range;
}
@ -358,7 +359,7 @@ void HRDTransceiver::do_stop ()
}
if (wrapped_) wrapped_->stop ();
TRACE_CAT ("HRDTransceiver", "stopped" << state () << "reversed" << reversed_);
TRACE_CAT ("stopped" << state () << "reversed" << reversed_);
}
int HRDTransceiver::find_button (QRegExp const& re) const
@ -405,14 +406,12 @@ void HRDTransceiver::map_modes (int dropdown, ModeMap *map)
map->push_back (std::forward_as_tuple (FM, find_dropdown_selection (dropdown, QRegExp ("^(FM|FM\\(N\\)|FM-N|WFM)$"))));
map->push_back (std::forward_as_tuple (DIG_FM, find_dropdown_selection (dropdown, QRegExp ("^(PKT-FM|PKT|DATA\\(FM\\)|FM)$"))));
#if WSJT_TRACE_CAT
TRACE_CAT ("HRDTransceiver", "for dropdown" << dropdown_names_[dropdown]);
TRACE_CAT ("for dropdown" << dropdown_names_[dropdown]);
std::for_each (map->begin (), map->end (), [this, dropdown] (ModeMap::value_type const& item)
{
auto const& rhs = std::get<1> (item);
TRACE_CAT ("HRDTransceiver", '\t' << std::get<0> (item) << "<->" << (rhs.size () ? dropdowns_[dropdown_names_[dropdown]][rhs.front ()] : "None"));
TRACE_CAT ('\t' << std::get<0> (item) << "<->" << (rhs.size () ? dropdowns_[dropdown_names_[dropdown]][rhs.front ()] : "None"));
});
#endif
}
int HRDTransceiver::lookup_mode (MODE mode, ModeMap const& map) const
@ -444,7 +443,7 @@ auto HRDTransceiver::lookup_mode (int mode, ModeMap const& map) const -> MODE
return std::get<0> (*it);
}
int HRDTransceiver::get_dropdown (int dd, bool no_debug)
int HRDTransceiver::get_dropdown (int dd)
{
if (dd < 0)
{
@ -452,7 +451,7 @@ int HRDTransceiver::get_dropdown (int dd, bool no_debug)
}
auto dd_name = dropdown_names_.value (dd);
auto reply = send_command ("get dropdown-text {" + dd_name + "}", no_debug);
auto reply = send_command ("get dropdown-text {" + dd_name + "}");
auto colon_index = reply.indexOf (':');
if (colon_index < 0)
@ -473,14 +472,14 @@ void HRDTransceiver::set_dropdown (int dd, int value)
}
else
{
TRACE_CAT ("HRDTransceiver", "item" << value << "not found in" << dd_name);
TRACE_CAT ("item" << value << "not found in" << dd_name);
throw error {tr ("Ham Radio Deluxe: item not found in %1 dropdown list").arg (dd_name)};
}
}
void HRDTransceiver::do_ptt (bool on)
{
TRACE_CAT ("HRDTransceiver", on);
TRACE_CAT (on);
if (use_for_ptt_)
{
if (alt_ptt_button_ >= 0 && TransceiverFactory::TX_audio_source_rear == audio_source_)
@ -517,7 +516,7 @@ void HRDTransceiver::set_button (int button_index, bool checked)
}
else
{
TRACE_CAT ("HRDTransceiver", "invalid button");
TRACE_CAT ("invalid button");
throw error {tr ("Ham Radio Deluxe: button not available")};
}
}
@ -570,12 +569,12 @@ void HRDTransceiver::set_data_mode (MODE m)
}
}
auto HRDTransceiver::get_data_mode (MODE m, bool quiet) -> MODE
auto HRDTransceiver::get_data_mode (MODE m) -> MODE
{
if (data_mode_dropdown_ >= 0
&& data_mode_dropdown_selection_off_.size ())
{
auto selection = get_dropdown (data_mode_dropdown_, quiet);
auto selection = get_dropdown (data_mode_dropdown_);
// can't check for on here as there may be multiple on values so
// we must rely on the initial parse finding valid on values
if (selection >= 0 && selection != data_mode_dropdown_selection_off_.front ())
@ -594,7 +593,7 @@ auto HRDTransceiver::get_data_mode (MODE m, bool quiet) -> MODE
void HRDTransceiver::do_frequency (Frequency f, MODE m, bool /*no_ignore*/)
{
TRACE_CAT ("HRDTransceiver", f << "reversed" << reversed_);
TRACE_CAT (f << "reversed" << reversed_);
if (UNK != m)
{
do_mode (m);
@ -614,7 +613,7 @@ void HRDTransceiver::do_frequency (Frequency f, MODE m, bool /*no_ignore*/)
void HRDTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool /*no_ignore*/)
{
TRACE_CAT ("HRDTransceiver", tx << "reversed" << reversed_);
TRACE_CAT (tx << "reversed" << reversed_);
// re-check if reversed VFOs
bool rx_A {true};
@ -781,7 +780,7 @@ void HRDTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool /*no_ignore*
void HRDTransceiver::do_mode (MODE mode)
{
TRACE_CAT ("HRDTransceiver", mode);
TRACE_CAT (mode);
if (reversed_ && mode_B_dropdown_ >= 0)
{
set_dropdown (mode_B_dropdown_, lookup_mode (mode, mode_B_map_));
@ -873,17 +872,17 @@ void HRDTransceiver::do_mode (MODE mode)
update_mode (mode);
}
bool HRDTransceiver::is_button_checked (int button_index, bool no_debug)
bool HRDTransceiver::is_button_checked (int button_index)
{
if (button_index < 0)
{
return false;
}
auto reply = send_command ("get button-select " + buttons_.value (button_index), no_debug);
auto reply = send_command ("get button-select " + buttons_.value (button_index));
if ("1" != reply && "0" != reply)
{
TRACE_CAT ("HRDTransceiver", "bad response");
TRACE_CAT ("bad response");
throw error {tr ("Ham Radio Deluxe didn't respond as expected")};
}
return "1" == reply;
@ -891,10 +890,8 @@ bool HRDTransceiver::is_button_checked (int button_index, bool no_debug)
void HRDTransceiver::do_poll ()
{
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
bool quiet {false};
qDebug () << "+++++++ poll dump +++++++";
qDebug () << "reversed:" << reversed_;
TRACE_CAT ("+++++++ poll dump +++++++");
TRACE_CAT ("reversed:" << reversed_);
is_button_checked (vfo_A_button_);
is_button_checked (vfo_B_button_);
is_button_checked (vfo_toggle_button_);
@ -922,10 +919,7 @@ void HRDTransceiver::do_poll ()
{
get_dropdown (split_mode_dropdown_);
}
qDebug () << "------- poll dump -------";
#else
bool quiet {true};
#endif
TRACE_CAT ("------- poll dump -------");
if (split_off_button_ >= 0)
{
@ -933,13 +927,13 @@ void HRDTransceiver::do_poll ()
}
else if (split_mode_button_ >= 0 && !(tx_A_button_ >= 0 && tx_B_button_ >= 0))
{
update_split (is_button_checked (split_mode_button_, quiet));
update_split (is_button_checked (split_mode_button_));
}
else if (split_mode_dropdown_ >= 0)
{
if (!split_mode_dropdown_write_only_)
{
auto selection = get_dropdown (split_mode_dropdown_, quiet);
auto selection = get_dropdown (split_mode_dropdown_);
if (selection >= 0
&& split_mode_dropdown_selection_off_.size ())
{
@ -958,7 +952,7 @@ void HRDTransceiver::do_poll ()
bool rx_A {true}; // no Rx taken as not reversed
bool rx_B {false};
auto tx_A = is_button_checked (tx_A_button_, quiet);
auto tx_A = is_button_checked (tx_A_button_);
// some rigs have dual Rx, we take VFO A/MAIN receiving as
// normal and only say reversed when only VFO B/SUB is active
@ -974,10 +968,10 @@ void HRDTransceiver::do_poll ()
}
else if (vfo_B_button_ >= 0 || rx_B_button_ >= 0)
{
rx_A = is_button_checked (rx_A_button_ >= 0 ? rx_A_button_ : vfo_A_button_, quiet);
rx_A = is_button_checked (rx_A_button_ >= 0 ? rx_A_button_ : vfo_A_button_);
if (!rx_A)
{
rx_B = is_button_checked (rx_B_button_ >= 0 ? rx_B_button_ : vfo_B_button_, quiet);
rx_B = is_button_checked (rx_B_button_ >= 0 ? rx_B_button_ : vfo_B_button_);
}
}
@ -987,7 +981,7 @@ void HRDTransceiver::do_poll ()
if (vfo_count_ > 1)
{
auto frequencies = send_command ("get frequencies", quiet).trimmed ().split ('-', SkipEmptyParts);
auto frequencies = send_command ("get frequencies").trimmed ().split ('-', SkipEmptyParts);
update_rx_frequency (frequencies[reversed_ ? 1 : 0].toUInt ());
update_other_frequency (frequencies[reversed_ ? 0 : 1].toUInt ());
}
@ -997,7 +991,7 @@ void HRDTransceiver::do_poll ()
// while transmitting
if (!state ().ptt ())
{
update_rx_frequency (send_command ("get frequency", quiet).toUInt ());
update_rx_frequency (send_command ("get frequency").toUInt ());
}
}
@ -1005,11 +999,11 @@ void HRDTransceiver::do_poll ()
// transmitting
if (vfo_count_ > 1 || !state ().ptt ())
{
update_mode (get_data_mode (lookup_mode (get_dropdown (mode_A_dropdown_, quiet), mode_A_map_), quiet));
update_mode (get_data_mode (lookup_mode (get_dropdown (mode_A_dropdown_), mode_A_map_)));
}
}
QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool prepend_context, bool recurse)
QString HRDTransceiver::send_command (QString const& cmd, bool prepend_context, bool recurse)
{
Q_ASSERT (hrd_);
@ -1024,7 +1018,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
if (!recurse && prepend_context)
{
auto radio_name = send_command ("get radio", true, current_radio_, true);
auto radio_name = send_command ("get radio", current_radio_, true);
qDebug () << "HRDTransceiver::send_command: radio_name:" << radio_name;
auto radio_iter = std::find_if (radios_.begin (), radios_.end (), [&radio_name] (RadioMap::value_type const& radio)
{
@ -1032,7 +1026,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
});
if (radio_iter == radios_.end ())
{
TRACE_CAT ("HRDTransceiver", "rig disappeared or changed");
TRACE_CAT ("rig disappeared or changed");
throw error {tr ("Ham Radio Deluxe: rig has disappeared or changed")};
}
@ -1046,7 +1040,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
if (QTcpSocket::ConnectedState != hrd_->state ())
{
TRACE_CAT ("HRDTransceiver", cmd << "failed" << hrd_->errorString ());
TRACE_CAT (cmd << "failed" << hrd_->errorString ());
throw error {
tr ("Ham Radio Deluxe send command \"%1\" failed %2\n")
.arg (cmd)
@ -1059,7 +1053,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
auto message = ((prepend_context ? context + cmd : cmd) + "\r").toLocal8Bit ();
if (!write_to_port (message.constData (), message.size ()))
{
TRACE_CAT ("HRDTransceiver", "failed to write command" << cmd << "to HRD");
TRACE_CAT ("failed to write command" << cmd << "to HRD");
throw error {
tr ("Ham Radio Deluxe: failed to write command \"%1\"")
.arg (cmd)
@ -1072,7 +1066,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
QScopedPointer<HRDMessage> message {new (string) HRDMessage};
if (!write_to_port (reinterpret_cast<char const *> (message.data ()), message->size_))
{
TRACE_CAT ("HRDTransceiver", "failed to write command" << cmd << "to HRD");
TRACE_CAT ("failed to write command" << cmd << "to HRD");
throw error {
tr ("Ham Radio Deluxe: failed to write command \"%1\"")
.arg (cmd)
@ -1089,7 +1083,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
HRDMessage const * reply {new (buffer) HRDMessage};
if (reply->magic_1_value_ != reply->magic_1_ && reply->magic_2_value_ != reply->magic_2_)
{
TRACE_CAT ("HRDTransceiver", cmd << "invalid reply");
TRACE_CAT (cmd << "invalid reply");
throw error {
tr ("Ham Radio Deluxe sent an invalid reply to our command \"%1\"")
.arg (cmd)
@ -1099,20 +1093,14 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
// keep reading until expected size arrives
while (buffer.size () - offsetof (HRDMessage, size_) < reply->size_)
{
if (!no_debug)
{
TRACE_CAT ("HRDTransceiver", cmd << "reading more reply data");
}
TRACE_CAT (cmd << "reading more reply data");
buffer += read_reply (cmd);
reply = new (buffer) HRDMessage;
}
result = QString {reply->payload_}; // this is not a memory leak (honest!)
}
if (!no_debug)
{
TRACE_CAT ("HRDTransceiver", cmd << " ->" << result);
}
TRACE_CAT (cmd << " ->" << result);
return result;
}
@ -1143,7 +1131,7 @@ QByteArray HRDTransceiver::read_reply (QString const& cmd)
replied = hrd_->waitForReadyRead ();
if (!replied && hrd_->error () != hrd_->SocketTimeoutError)
{
TRACE_CAT ("HRDTransceiver", cmd << "failed to reply" << hrd_->errorString ());
TRACE_CAT (cmd << "failed to reply" << hrd_->errorString ());
throw error {
tr ("Ham Radio Deluxe failed to reply to command \"%1\" %2\n")
.arg (cmd)
@ -1153,7 +1141,7 @@ QByteArray HRDTransceiver::read_reply (QString const& cmd)
}
if (!replied)
{
TRACE_CAT ("HRDTransceiver", cmd << "retries exhausted");
TRACE_CAT (cmd << "retries exhausted");
throw error {
tr ("Ham Radio Deluxe retries exhausted sending command \"%1\"")
.arg (cmd)
@ -1162,11 +1150,11 @@ QByteArray HRDTransceiver::read_reply (QString const& cmd)
return hrd_->readAll ();
}
void HRDTransceiver::send_simple_command (QString const& command, bool no_debug)
void HRDTransceiver::send_simple_command (QString const& command)
{
if ("OK" != send_command (command, no_debug))
if ("OK" != send_command (command))
{
TRACE_CAT ("HRDTransceiver", command << "unexpected response");
TRACE_CAT (command << "unexpected response");
throw error {
tr ("Ham Radio Deluxe didn't respond to command \"%1\" as expected")
.arg (command)

View File

@ -30,10 +30,11 @@ class HRDTransceiver final
Q_OBJECT
public:
static void register_transceivers (TransceiverFactory::Transceivers *, int id);
static void register_transceivers (logger_type *, TransceiverFactory::Transceivers *, int id);
// takes ownership of wrapped Transceiver
explicit HRDTransceiver (std::unique_ptr<TransceiverBase> wrapped
explicit HRDTransceiver (logger_type *
, std::unique_ptr<TransceiverBase> wrapped
, QString const& server
, bool use_for_ptt
, TransceiverFactory::TXAudioSource
@ -53,17 +54,17 @@ protected:
void do_poll () override;
private:
QString send_command (QString const&, bool no_debug = false, bool prepend_context = true, bool recurse = false);
QString send_command (QString const&, bool prepend_context = true, bool recurse = false);
QByteArray read_reply (QString const& command);
void send_simple_command (QString const&, bool no_debug = false);
void send_simple_command (QString const&);
bool write_to_port (char const *, qint64 length);
int find_button (QRegExp const&) const;
int find_dropdown (QRegExp const&) const;
std::vector<int> find_dropdown_selection (int dropdown, QRegExp const&) const;
int get_dropdown (int, bool no_debug = false);
int get_dropdown (int);
void set_dropdown (int, int);
void set_button (int button_index, bool checked = true);
bool is_button_checked (int button_index, bool no_debug = false);
bool is_button_checked (int button_index);
// This dictionary type maps Transceiver::MODE to a list of mode
// drop down selection indexes that equate to that mode. It is used
@ -75,7 +76,7 @@ private:
int lookup_mode (MODE, ModeMap const&) const;
MODE lookup_mode (int, ModeMap const&) const;
void set_data_mode (MODE);
MODE get_data_mode (MODE, bool no_debug = false);
MODE get_data_mode (MODE);
// An alternate TransceiverBase instance that can be used to drive
// PTT if required.

View File

@ -30,35 +30,6 @@ namespace
// As an ultimate workaround make sure the user always has the
// option to skip mode setting altogether.
// reroute Hamlib diagnostic messages to Qt
int debug_callback (enum rig_debug_level_e level, rig_ptr_t /* arg */, char const * format, va_list ap)
{
QString message;
static char constexpr fmt[] = "Hamlib: %s";
message = message.vasprintf (format, ap).trimmed ();
switch (level)
{
case RIG_DEBUG_BUG:
qFatal (fmt, message.toLocal8Bit ().data ());
break;
case RIG_DEBUG_ERR:
qCritical (fmt, message.toLocal8Bit ().data ());
break;
case RIG_DEBUG_WARN:
qWarning (fmt, message.toLocal8Bit ().data ());
break;
default:
qDebug (fmt, message.toLocal8Bit ().data ());
break;
}
return 0;
}
// callback function that receives transceiver capabilities from the
// hamlib libraries
int register_callback (rig_caps const * caps, void * callback_data)
@ -157,22 +128,35 @@ namespace
freq_t HamlibTransceiver::dummy_frequency_;
rmode_t HamlibTransceiver::dummy_mode_ {RIG_MODE_NONE};
void HamlibTransceiver::register_transceivers (TransceiverFactory::Transceivers * registry)
// reroute Hamlib diagnostic messages to Qt
int HamlibTransceiver::debug_callback (enum rig_debug_level_e level, rig_ptr_t arg, char const * format, va_list ap)
{
rig_set_debug_callback (debug_callback, nullptr);
auto logger = reinterpret_cast<logger_type *> (arg);
auto message = QString::vasprintf (format, ap);
va_end (ap);
auto severity = boost::log::trivial::trace;
switch (level)
{
case RIG_DEBUG_BUG: severity = boost::log::trivial::debug; break;
case RIG_DEBUG_ERR: severity = boost::log::trivial::error; break;
case RIG_DEBUG_WARN: severity = boost::log::trivial::warning; break;
case RIG_DEBUG_TRACE: severity = boost::log::trivial::info; break;
case RIG_DEBUG_VERBOSE: severity = boost::log::trivial::trace; break;
default: break;
};
if (level != RIG_DEBUG_NONE) // no idea what level NONE means so
// ignore it
{
BOOST_LOG_SEV (*logger, severity) << message.trimmed ().toStdString ();
}
return 0;
}
#if WSJT_HAMLIB_TRACE
#if WSJT_HAMLIB_VERBOSE_TRACE
void HamlibTransceiver::register_transceivers (logger_type * logger,
TransceiverFactory::Transceivers * registry)
{
rig_set_debug_callback (debug_callback, logger);
rig_set_debug (RIG_DEBUG_TRACE);
#else
rig_set_debug (RIG_DEBUG_VERBOSE);
#endif
#elif defined (NDEBUG)
rig_set_debug (RIG_DEBUG_ERR);
#else
rig_set_debug (RIG_DEBUG_WARN);
#endif
rig_load_all_backends ();
rig_list_foreach (register_callback, registry);
}
@ -191,9 +175,10 @@ void HamlibTransceiver::RIGDeleter::cleanup (RIG * rig)
}
}
HamlibTransceiver::HamlibTransceiver (TransceiverFactory::PTTMethod ptt_type, QString const& ptt_port,
HamlibTransceiver::HamlibTransceiver (logger_type * logger,
TransceiverFactory::PTTMethod ptt_type, QString const& ptt_port,
QObject * parent)
: PollingTransceiver {0, parent}
: PollingTransceiver {logger, 0, parent}
, rig_ {rig_init (RIG_MODEL_DUMMY)}
, ptt_only_ {true}
, back_ptt_port_ {false}
@ -245,9 +230,11 @@ HamlibTransceiver::HamlibTransceiver (TransceiverFactory::PTTMethod ptt_type, QS
}
}
HamlibTransceiver::HamlibTransceiver (int model_number, TransceiverFactory::ParameterPack const& params,
HamlibTransceiver::HamlibTransceiver (logger_type * logger,
int model_number,
TransceiverFactory::ParameterPack const& params,
QObject * parent)
: PollingTransceiver {params.poll_interval, parent}
: PollingTransceiver {logger, params.poll_interval, parent}
, rig_ {rig_init (model_number)}
, ptt_only_ {false}
, back_ptt_port_ {TransceiverFactory::TX_audio_source_rear == params.audio_source}
@ -420,16 +407,15 @@ void HamlibTransceiver::error_check (int ret_code, QString const& doing) const
{
if (RIG_OK != ret_code)
{
TRACE_CAT_POLL ("HamlibTransceiver", "error:" << rigerror (ret_code));
TRACE_CAT_POLL ("error: " << rigerror (ret_code));
throw error {tr ("Hamlib error: %1 while %2").arg (rigerror (ret_code)).arg (doing)};
}
}
int HamlibTransceiver::do_start ()
{
TRACE_CAT ("HamlibTransceiver",
QString::fromLatin1 (rig_->caps->mfg_name).trimmed ()
<< QString::fromLatin1 (rig_->caps->model_name).trimmed ());
TRACE_CAT ("starting: " << QString::fromLatin1 (rig_->caps->mfg_name).trimmed ()
<< ": " << QString::fromLatin1 (rig_->caps->model_name).trimmed ());
error_check (rig_open (rig_.data ()), tr ("opening connection to rig"));
@ -480,25 +466,25 @@ int HamlibTransceiver::do_start ()
// here. We also gather/set other initial state.
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f1), tr ("getting current frequency"));
f1 = std::round (f1);
TRACE_CAT ("HamlibTransceiver", "current frequency =" << f1);
TRACE_CAT ("current frequency=" << f1);
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w), tr ("getting current mode"));
TRACE_CAT ("HamlibTransceiver", "current mode =" << rig_strrmode (m) << "bw =" << w);
TRACE_CAT ("current mode=" << rig_strrmode (m) << " bw=" << w);
if (!rig_->caps->set_vfo)
{
TRACE_CAT ("HamlibTransceiver", "rig_vfo_op TOGGLE");
TRACE_CAT ("rig_vfo_op TOGGLE");
rc = rig_vfo_op (rig_.data (), RIG_VFO_CURR, RIG_OP_TOGGLE);
}
else
{
TRACE_CAT ("HamlibTransceiver", "rig_set_vfo to other VFO");
TRACE_CAT ("rig_set_vfo to other VFO");
rc = rig_set_vfo (rig_.data (), rig_->state.vfo_list & RIG_VFO_B ? RIG_VFO_B : RIG_VFO_SUB);
if (-RIG_ENAVAIL == rc || -RIG_ENIMPL == rc)
{
// if we are talking to netrigctl then toggle VFO op
// may still work
TRACE_CAT ("HamlibTransceiver", "rig_vfo_op TOGGLE");
TRACE_CAT ("rig_vfo_op TOGGLE");
rc = rig_vfo_op (rig_.data (), RIG_VFO_CURR, RIG_OP_TOGGLE);
}
}
@ -521,21 +507,21 @@ int HamlibTransceiver::do_start ()
// need to execute this block
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f2), tr ("getting other VFO frequency"));
f2 = std::round (f2);
TRACE_CAT ("HamlibTransceiver", "rig_get_freq other frequency =" << f2);
TRACE_CAT ("rig_get_freq other frequency=" << f2);
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &mb, &wb), tr ("getting other VFO mode"));
TRACE_CAT ("HamlibTransceiver", "rig_get_mode other mode =" << rig_strrmode (mb) << "bw =" << wb);
TRACE_CAT ("rig_get_mode other mode=" << rig_strrmode (mb) << " bw=" << wb);
update_other_frequency (f2);
if (!rig_->caps->set_vfo)
{
TRACE_CAT ("HamlibTransceiver", "rig_vfo_op TOGGLE");
TRACE_CAT ("rig_vfo_op TOGGLE");
error_check (rig_vfo_op (rig_.data (), RIG_VFO_CURR, RIG_OP_TOGGLE), tr ("exchanging VFOs"));
}
else
{
TRACE_CAT ("HamlibTransceiver", "rig_set_vfo A/MAIN");
TRACE_CAT ("rig_set_vfo A/MAIN");
error_check (rig_set_vfo (rig_.data (), rig_->state.vfo_list & RIG_VFO_A ? RIG_VFO_A : RIG_VFO_MAIN), tr ("setting current VFO"));
}
@ -547,16 +533,16 @@ int HamlibTransceiver::do_start ()
{
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f1), tr ("getting frequency"));
f1 = std::round (f1);
TRACE_CAT ("HamlibTransceiver", "rig_get_freq frequency =" << f1);
TRACE_CAT ("rig_get_freq frequency=" << f1);
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w), tr ("getting mode"));
TRACE_CAT ("HamlibTransceiver", "rig_get_mode mode =" << rig_strrmode (m) << "bw =" << w);
TRACE_CAT ("rig_get_mode mode=" << rig_strrmode (m) << " bw=" << w);
update_rx_frequency (f1);
}
}
// TRACE_CAT ("HamlibTransceiver", "rig_set_split_vfo split off");
// TRACE_CAT ("rig_set_split_vfo split off");
// error_check (rig_set_split_vfo (rig_.data (), RIG_VFO_CURR, RIG_SPLIT_OFF, RIG_VFO_CURR), tr ("setting split off"));
// update_split (false);
}
@ -567,7 +553,7 @@ int HamlibTransceiver::do_start ()
if (get_vfo_works_ && rig_->caps->get_vfo)
{
error_check (rig_get_vfo (rig_.data (), &v), tr ("getting current VFO")); // has side effect of establishing current VFO inside hamlib
TRACE_CAT ("HamlibTransceiver", "rig_get_vfo current VFO = " << rig_strvfo (v));
TRACE_CAT ("rig_get_vfo current VFO=" << rig_strvfo (v));
}
reversed_ = RIG_VFO_B == v;
@ -576,7 +562,7 @@ int HamlibTransceiver::do_start ()
{
if (RIG_OK == rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w))
{
TRACE_CAT ("HamlibTransceiver", "rig_get_mode current mode =" << rig_strrmode (m) << "bw =" << w);
TRACE_CAT ("rig_get_mode current mode=" << rig_strrmode (m) << " bw=" << w);
}
else
{
@ -584,7 +570,7 @@ int HamlibTransceiver::do_start ()
// Some rigs (HDSDR) don't have a working way of
// reporting MODE so we give up on mode queries -
// sets will still cause an error
TRACE_CAT ("HamlibTransceiver", "rig_get_mode can't do on this rig");
TRACE_CAT ("rig_get_mode can't do on this rig");
}
}
}
@ -660,7 +646,7 @@ int HamlibTransceiver::do_start ()
do_poll ();
TRACE_CAT ("HamlibTransceiver", "exit" << state () << "reversed =" << reversed_ << "resolution = " << resolution);
TRACE_CAT ("finished start " << state () << " reversed=" << reversed_ << " resolution=" << resolution);
return resolution;
}
@ -681,7 +667,7 @@ void HamlibTransceiver::do_stop ()
rig_close (rig_.data ());
}
TRACE_CAT ("HamlibTransceiver", "state:" << state () << "reversed =" << reversed_);
TRACE_CAT ("state: " << state () << " reversed=" << reversed_);
}
std::tuple<vfo_t, vfo_t> HamlibTransceiver::get_vfos (bool for_split) const
@ -690,7 +676,7 @@ std::tuple<vfo_t, vfo_t> HamlibTransceiver::get_vfos (bool for_split) const
{
vfo_t v;
error_check (rig_get_vfo (rig_.data (), &v), tr ("getting current VFO")); // has side effect of establishing current VFO inside hamlib
TRACE_CAT ("HamlibTransceiver", "rig_get_vfo VFO = " << rig_strvfo (v));
TRACE_CAT ("rig_get_vfo VFO=" << rig_strvfo (v));
reversed_ = RIG_VFO_B == v;
}
@ -700,7 +686,7 @@ std::tuple<vfo_t, vfo_t> HamlibTransceiver::get_vfos (bool for_split) const
// frequency if split since these type of radios can only
// support this way around
TRACE_CAT ("HamlibTransceiver", "rig_set_vfo VFO = A/MAIN");
TRACE_CAT ("rig_set_vfo VFO=A/MAIN");
error_check (rig_set_vfo (rig_.data (), rig_->state.vfo_list & RIG_VFO_A ? RIG_VFO_A : RIG_VFO_MAIN), tr ("setting current VFO"));
}
// else only toggle available but VFOs should be substitutable
@ -711,17 +697,17 @@ std::tuple<vfo_t, vfo_t> HamlibTransceiver::get_vfos (bool for_split) const
: rx_vfo;
if (reversed_)
{
TRACE_CAT ("HamlibTransceiver", "reversing VFOs");
TRACE_CAT ("reversing VFOs");
std::swap (rx_vfo, tx_vfo);
}
TRACE_CAT ("HamlibTransceiver", "RX VFO = " << rig_strvfo (rx_vfo) << " TX VFO = " << rig_strvfo (tx_vfo));
TRACE_CAT ("RX VFO=" << rig_strvfo (rx_vfo) << " TX VFO=" << rig_strvfo (tx_vfo));
return std::make_tuple (rx_vfo, tx_vfo);
}
void HamlibTransceiver::do_frequency (Frequency f, MODE m, bool no_ignore)
{
TRACE_CAT ("HamlibTransceiver", f << "mode:" << m << "reversed:" << reversed_);
TRACE_CAT ("f: " << f << " mode: " << m << " reversed: " << reversed_);
// only change when receiving or simplex or direct VFO addressing
// unavailable or forced
@ -738,11 +724,11 @@ void HamlibTransceiver::do_frequency (Frequency f, MODE m, bool no_ignore)
pbwidth_t current_width;
auto new_mode = map_mode (m);
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width), tr ("getting current VFO mode"));
TRACE_CAT ("HamlibTransceiver", "rig_get_mode mode = " << rig_strrmode (current_mode) << "bw =" << current_width);
TRACE_CAT ("rig_get_mode mode=" << rig_strrmode (current_mode) << " bw=" << current_width);
if (new_mode != current_mode)
{
TRACE_CAT ("HamlibTransceiver", "rig_set_mode mode = " << rig_strrmode (new_mode));
TRACE_CAT ("rig_set_mode mode=" << rig_strrmode (new_mode));
error_check (rig_set_mode (rig_.data (), RIG_VFO_CURR, new_mode, RIG_PASSBAND_NOCHANGE), tr ("setting current VFO mode"));
// for the 2nd time because a mode change may have caused a
@ -751,7 +737,7 @@ void HamlibTransceiver::do_frequency (Frequency f, MODE m, bool no_ignore)
// for the second time because some rigs change mode according
// to frequency such as the TS-2000 auto mode setting
TRACE_CAT ("HamlibTransceiver", "rig_set_mode mode = " << rig_strrmode (new_mode));
TRACE_CAT ("rig_set_mode mode=" << rig_strrmode (new_mode));
error_check (rig_set_mode (rig_.data (), RIG_VFO_CURR, new_mode, RIG_PASSBAND_NOCHANGE), tr ("setting current VFO mode"));
}
update_mode (m);
@ -761,7 +747,7 @@ void HamlibTransceiver::do_frequency (Frequency f, MODE m, bool no_ignore)
void HamlibTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool no_ignore)
{
TRACE_CAT ("HamlibTransceiver", tx << "reversed:" << reversed_);
TRACE_CAT ("txf: " << tx << " reversed: " << reversed_);
if (WSJT_RIG_NONE_CAN_SPLIT || !is_dummy_) // split is meaningless if you can't see it
{
@ -785,7 +771,7 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool no_ignore
// much we can do since the Hamlib Library needs this
// call at least once to establish the Tx VFO. Best we
// can do is only do this once per session.
TRACE_CAT ("HamlibTransceiver", "rig_set_split_vfo split =" << split);
TRACE_CAT ("rig_set_split_vfo split=" << split);
auto rc = rig_set_split_vfo (rig_.data (), RIG_VFO_CURR, split, tx_vfo);
if (tx || (-RIG_ENAVAIL != rc && -RIG_ENIMPL != rc))
{
@ -805,7 +791,7 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool no_ignore
// addressing
if (state ().ptt () && one_VFO_)
{
TRACE_CAT ("HamlibTransceiver", "rig_set_split_vfo split =" << split);
TRACE_CAT ("rig_set_split_vfo split=" << split);
error_check (rig_set_split_vfo (rig_.data (), RIG_VFO_CURR, split, tx_vfo), tr ("setting split mode"));
error_check (rig_set_freq (rig_.data (), RIG_VFO_CURR, tx), tr ("setting frequency"));
@ -816,11 +802,11 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool no_ignore
pbwidth_t current_width;
auto new_mode = map_mode (mode);
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width), tr ("getting current VFO mode"));
TRACE_CAT ("HamlibTransceiver", "rig_get_mode mode = " << rig_strrmode (current_mode) << "bw =" << current_width);
TRACE_CAT ("rig_get_mode mode=" << rig_strrmode (current_mode) << " bw=" << current_width);
if (new_mode != current_mode)
{
TRACE_CAT ("HamlibTransceiver", "rig_set_mode mode = " << rig_strrmode (new_mode));
TRACE_CAT ("rig_set_mode mode=" << rig_strrmode (new_mode));
error_check (rig_set_mode (rig_.data (), RIG_VFO_CURR, new_mode, RIG_PASSBAND_NOCHANGE), tr ("setting current VFO mode"));
}
}
@ -832,20 +818,20 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool no_ignore
if (UNK != mode)
{
auto new_mode = map_mode (mode);
TRACE_CAT ("HamlibTransceiver", "rig_set_split_freq_mode freq = " << tx
TRACE_CAT ("rig_set_split_freq_mode freq=" << tx
<< " mode = " << rig_strrmode (new_mode));
error_check (rig_set_split_freq_mode (rig_.data (), RIG_VFO_CURR, tx, new_mode, RIG_PASSBAND_NOCHANGE), tr ("setting split TX frequency and mode"));
}
else
{
TRACE_CAT ("HamlibTransceiver", "rig_set_split_freq freq = " << tx);
TRACE_CAT ("rig_set_split_freq freq=" << tx);
error_check (rig_set_split_freq (rig_.data (), RIG_VFO_CURR, tx), tr ("setting split TX frequency"));
}
// Enable split last since some rigs (Kenwood for one) come out
// of split when you switch RX VFO (to set split mode above for
// example). Also the Elecraft K3 will refuse to go to split
// with certain VFO A/B mode combinations.
TRACE_CAT ("HamlibTransceiver", "rig_set_split_vfo split =" << split);
TRACE_CAT ("rig_set_split_vfo split=" << split);
error_check (rig_set_split_vfo (rig_.data (), RIG_VFO_CURR, split, tx_vfo), tr ("setting split mode"));
update_other_frequency (tx);
update_split (tx);
@ -854,7 +840,7 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool no_ignore
else
{
// Disable split
TRACE_CAT ("HamlibTransceiver", "rig_set_split_vfo split =" << split);
TRACE_CAT ("rig_set_split_vfo split=" << split);
auto rc = rig_set_split_vfo (rig_.data (), RIG_VFO_CURR, split, tx_vfo);
if (tx || (-RIG_ENAVAIL != rc && -RIG_ENIMPL != rc))
{
@ -874,7 +860,7 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool no_ignore
void HamlibTransceiver::do_mode (MODE mode)
{
TRACE_CAT ("HamlibTransceiver", mode);
TRACE_CAT (mode);
auto vfos = get_vfos (state ().split ());
// auto rx_vfo = std::get<0> (vfos);
@ -888,11 +874,11 @@ void HamlibTransceiver::do_mode (MODE mode)
if (!(state ().ptt () && state ().split () && one_VFO_))
{
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width), tr ("getting current VFO mode"));
TRACE_CAT ("HamlibTransceiver", "rig_get_mode mode = " << rig_strrmode (current_mode) << "bw =" << current_width);
TRACE_CAT ("rig_get_mode mode=" << rig_strrmode (current_mode) << " bw=" << current_width);
if (new_mode != current_mode)
{
TRACE_CAT ("HamlibTransceiver", "rig_set_mode mode = " << rig_strrmode (new_mode));
TRACE_CAT ("rig_set_mode mode=" << rig_strrmode (new_mode));
error_check (rig_set_mode (rig_.data (), RIG_VFO_CURR, new_mode, RIG_PASSBAND_NOCHANGE), tr ("setting current VFO mode"));
}
}
@ -901,22 +887,22 @@ void HamlibTransceiver::do_mode (MODE mode)
if (state ().ptt () && state ().split () && one_VFO_)
{
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width), tr ("getting current VFO mode"));
TRACE_CAT ("HamlibTransceiver", "rig_get_mode mode = " << rig_strrmode (current_mode) << "bw =" << current_width);
TRACE_CAT ("rig_get_mode mode=" << rig_strrmode (current_mode) << " bw=" << current_width);
if (new_mode != current_mode)
{
TRACE_CAT ("HamlibTransceiver", "rig_set_mode mode = " << rig_strrmode (new_mode));
TRACE_CAT ("rig_set_mode mode=" << rig_strrmode (new_mode));
error_check (rig_set_mode (rig_.data (), RIG_VFO_CURR, new_mode, RIG_PASSBAND_NOCHANGE), tr ("setting current VFO mode"));
}
}
else if (state ().split () && !one_VFO_)
{
error_check (rig_get_split_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width), tr ("getting split TX VFO mode"));
TRACE_CAT ("HamlibTransceiver", "rig_get_split_mode mode = " << rig_strrmode (current_mode) << "bw =" << current_width);
TRACE_CAT ("rig_get_split_mode mode=" << rig_strrmode (current_mode) << " bw=" << current_width);
if (new_mode != current_mode)
{
TRACE_CAT ("HamlibTransceiver", "rig_set_split_mode mode = " << rig_strrmode (new_mode));
TRACE_CAT ("rig_set_split_mode mode=" << rig_strrmode (new_mode));
hamlib_tx_vfo_fixup fixup (rig_.data (), tx_vfo);
error_check (rig_set_split_mode (rig_.data (), RIG_VFO_CURR, new_mode, RIG_PASSBAND_NOCHANGE), tr ("setting split TX VFO mode"));
}
@ -926,14 +912,6 @@ void HamlibTransceiver::do_mode (MODE mode)
void HamlibTransceiver::do_poll ()
{
#if !WSJT_TRACE_CAT_POLLS
#if defined (NDEBUG)
rig_set_debug (RIG_DEBUG_ERR);
#else
rig_set_debug (RIG_DEBUG_WARN);
#endif
#endif
freq_t f;
rmode_t m;
pbwidth_t w;
@ -943,7 +921,7 @@ void HamlibTransceiver::do_poll ()
{
vfo_t v;
error_check (rig_get_vfo (rig_.data (), &v), tr ("getting current VFO")); // has side effect of establishing current VFO inside hamlib
TRACE_CAT_POLL ("HamlibTransceiver", "VFO =" << rig_strvfo (v));
TRACE_CAT_POLL ("VFO=" << rig_strvfo (v));
reversed_ = RIG_VFO_B == v;
}
@ -954,7 +932,7 @@ void HamlibTransceiver::do_poll ()
auto rc = rig_get_split_vfo (rig_.data (), RIG_VFO_CURR, &s, &v);
if (-RIG_OK == rc && RIG_SPLIT_ON == s)
{
TRACE_CAT_POLL ("HamlibTransceiver", "rig_get_split_vfo split = " << s << " VFO = " << rig_strvfo (v));
TRACE_CAT_POLL ("rig_get_split_vfo split=" << s << " VFO=" << rig_strvfo (v));
update_split (true);
// if (RIG_VFO_A == v)
// {
@ -963,14 +941,14 @@ void HamlibTransceiver::do_poll ()
}
else if (-RIG_OK == rc) // not split
{
TRACE_CAT_POLL ("HamlibTransceiver", "rig_get_split_vfo split = " << s << " VFO = " << rig_strvfo (v));
TRACE_CAT_POLL ("rig_get_split_vfo split=" << s << " VFO=" << rig_strvfo (v));
update_split (false);
}
else
{
// Some rigs (Icom) don't have a way of reporting SPLIT
// mode
TRACE_CAT_POLL ("HamlibTransceiver", "rig_get_split_vfo can't do on this rig");
TRACE_CAT_POLL ("rig_get_split_vfo can't do on this rig");
// just report how we see it based on prior commands
split_query_works_ = false;
}
@ -983,7 +961,7 @@ void HamlibTransceiver::do_poll ()
{
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f), tr ("getting current VFO frequency"));
f = std::round (f);
TRACE_CAT_POLL ("HamlibTransceiver", "rig_get_freq frequency =" << f);
TRACE_CAT_POLL ("rig_get_freq frequency=" << f);
update_rx_frequency (f);
}
@ -1004,7 +982,7 @@ void HamlibTransceiver::do_poll ()
: (rig_->state.vfo_list & RIG_VFO_B ? RIG_VFO_B : RIG_VFO_SUB)
, &f), tr ("getting other VFO frequency"));
f = std::round (f);
TRACE_CAT_POLL ("HamlibTransceiver", "rig_get_freq other VFO =" << f);
TRACE_CAT_POLL ("rig_get_freq other VFO=" << f);
update_other_frequency (f);
}
}
@ -1022,12 +1000,12 @@ void HamlibTransceiver::do_poll ()
auto rc = rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w);
if (RIG_OK == rc)
{
TRACE_CAT_POLL ("HamlibTransceiver", "rig_get_mode mode =" << rig_strrmode (m) << "bw =" << w);
TRACE_CAT_POLL ("rig_get_mode mode=" << rig_strrmode (m) << " bw=" << w);
update_mode (map_mode (m));
}
else
{
TRACE_CAT_POLL ("HamlibTransceiver", "rig_get_mode mode failed with rc:" << rc << "ignoring");
TRACE_CAT_POLL ("rig_get_mode mode failed with rc: " << rc << " ignoring");
}
}
@ -1040,34 +1018,20 @@ void HamlibTransceiver::do_poll ()
// support command
{
error_check (rc, tr ("getting PTT state"));
TRACE_CAT_POLL ("HamlibTransceiver", "rig_get_ptt PTT =" << p);
TRACE_CAT_POLL ("rig_get_ptt PTT=" << p);
update_PTT (!(RIG_PTT_OFF == p));
}
}
#if !WSJT_TRACE_CAT_POLLS
#if WSJT_HAMLIB_TRACE
#if WSJT_HAMLIB_VERBOSE_TRACE
rig_set_debug (RIG_DEBUG_TRACE);
#else
rig_set_debug (RIG_DEBUG_VERBOSE);
#endif
#elif defined (NDEBUG)
rig_set_debug (RIG_DEBUG_ERR);
#else
rig_set_debug (RIG_DEBUG_WARN);
#endif
#endif
}
void HamlibTransceiver::do_ptt (bool on)
{
TRACE_CAT ("HamlibTransceiver", on << state () << "reversed =" << reversed_);
TRACE_CAT ("PTT: " << on << " " << state () << " reversed=" << reversed_);
if (on)
{
if (RIG_PTT_NONE != rig_->state.pttport.type.ptt)
{
TRACE_CAT ("HamlibTransceiver", "rig_set_ptt PTT = true");
TRACE_CAT ("rig_set_ptt PTT=true");
error_check (rig_set_ptt (rig_.data (), RIG_VFO_CURR
, RIG_PTT_RIG_MICDATA == rig_->caps->ptt_type && back_ptt_port_
? RIG_PTT_ON_DATA : RIG_PTT_ON), tr ("setting PTT on"));
@ -1077,7 +1041,7 @@ void HamlibTransceiver::do_ptt (bool on)
{
if (RIG_PTT_NONE != rig_->state.pttport.type.ptt)
{
TRACE_CAT ("HamlibTransceiver", "rig_set_ptt PTT = false");
TRACE_CAT ("rig_set_ptt PTT=false");
error_check (rig_set_ptt (rig_.data (), RIG_VFO_CURR, RIG_PTT_OFF), tr ("setting PTT off"));
}
}

View File

@ -17,15 +17,15 @@ class HamlibTransceiver final
Q_OBJECT // for translation context
public:
static void register_transceivers (TransceiverFactory::Transceivers *);
static void register_transceivers (logger_type *, TransceiverFactory::Transceivers *);
static void unregister_transceivers ();
explicit HamlibTransceiver (int model_number, TransceiverFactory::ParameterPack const&,
explicit HamlibTransceiver (logger_type *, int model_number, TransceiverFactory::ParameterPack const&,
QObject * parent = nullptr);
explicit HamlibTransceiver (TransceiverFactory::PTTMethod ptt_type, QString const& ptt_port,
explicit HamlibTransceiver (logger_type *, TransceiverFactory::PTTMethod ptt_type, QString const& ptt_port,
QObject * parent = nullptr);
private:
private:
int do_start () override;
void do_stop () override;
void do_frequency (Frequency, MODE, bool no_ignore) override;
@ -65,6 +65,8 @@ public:
// establish the Tx VFO
bool get_vfo_works_; // Net rigctl promises what it can't deliver
bool set_vfo_works_; // More rigctl promises which it can't deliver
static int debug_callback (enum rig_debug_level_e level, rig_ptr_t arg, char const * format, va_list ap);
};
#endif

View File

@ -49,7 +49,7 @@ auto OmniRigTransceiver::map_mode (OmniRig::RigParamX param) -> MODE
{
return FM;
}
TRACE_CAT ("OmniRigTransceiver", "unrecognized mode");
TRACE_CAT ("unrecognized mode");
throw_qstring (tr ("OmniRig: unrecognized mode"));
return UNK;
}
@ -74,7 +74,9 @@ OmniRig::RigParamX OmniRigTransceiver::map_mode (MODE mode)
return OmniRig::PM_SSB_U; // quieten compiler grumble
}
void OmniRigTransceiver::register_transceivers (TransceiverFactory::Transceivers * registry, int id1, int id2)
void OmniRigTransceiver::register_transceivers (logger_type *,
TransceiverFactory::Transceivers * registry,
int id1, int id2)
{
(*registry)[OmniRig_transceiver_one_name] = TransceiverFactory::Capabilities {
id1
@ -94,10 +96,11 @@ void OmniRigTransceiver::register_transceivers (TransceiverFactory::Transceivers
};
}
OmniRigTransceiver::OmniRigTransceiver (std::unique_ptr<TransceiverBase> wrapped,
OmniRigTransceiver::OmniRigTransceiver (logger_type * logger,
std::unique_ptr<TransceiverBase> wrapped,
RigNumber n, TransceiverFactory::PTTMethod ptt_type,
QString const& ptt_port, QObject * parent)
: TransceiverBase {parent}
: TransceiverBase {logger, parent}
, 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))}
, ptt_type_ {ptt_type}
@ -126,14 +129,14 @@ bool OmniRigTransceiver::await_notification_with_timeout (int timeout)
int OmniRigTransceiver::do_start ()
{
TRACE_CAT ("OmniRigTransceiver", "starting");
TRACE_CAT ("starting");
if (wrapped_) wrapped_->start (0);
omni_rig_.reset (new OmniRig::OmniRigX {this});
if (omni_rig_->isNull ())
{
TRACE_CAT ("OmniRigTransceiver", "failed to start COM server");
TRACE_CAT ("failed to start COM server");
throw_qstring (tr ("Failed to start OmniRig COM server"));
}
@ -149,7 +152,7 @@ int OmniRigTransceiver::do_start ()
, SIGNAL (CustomReply (int, QVariant const&, QVariant const&))
, this, SLOT (handle_custom_reply (int, QVariant const&, QVariant const&)));
TRACE_CAT ("OmniRigTransceiver", "OmniRig s/w version:" << QString::number (omni_rig_->SoftwareVersion ()).toLocal8Bit ()
TRACE_CAT ("OmniRig s/w version:" << QString::number (omni_rig_->SoftwareVersion ()).toLocal8Bit ()
<< "i/f version:" << QString::number (omni_rig_->InterfaceVersion ()).toLocal8Bit ());
// fetch the interface of the RigX CoClass and instantiate a proxy object
@ -182,12 +185,12 @@ int OmniRigTransceiver::do_start ()
// COM/OLE exceptions get signaled
connect (&*port_, SIGNAL (exception (int, QString, QString, QString)), this, SLOT (handle_COM_exception (int, QString, QString, QString)));
TRACE_CAT ("OmniRigTransceiver", "OmniRig RTS state:" << port_->Rts ());
TRACE_CAT ("OmniRig RTS state:" << port_->Rts ());
// remove locking because it doesn't seem to work properly
// if (!port_->Lock ()) // try to take exclusive use of the OmniRig serial port for PTT
// {
// TRACE_CAT ("OmniRigTransceiver", "Failed to get exclusive use of serial port for PTT from OmniRig");
// TRACE_CAT ("Failed to get exclusive use of serial port for PTT from OmniRig");
// }
// start off so we don't accidentally key the radio
@ -205,7 +208,7 @@ int OmniRigTransceiver::do_start ()
readable_params_ = rig_->ReadableParams ();
writable_params_ = rig_->WriteableParams ();
TRACE_CAT ("OmniRigTransceiver", QString {"OmniRig initial rig type: %1 readable params = 0x%2 writable params = 0x%3 for rig %4"}
TRACE_CAT (QString {"OmniRig initial rig type: %1 readable params = 0x%2 writable params = 0x%3 for rig %4"}
.arg (rig_type_)
.arg (readable_params_, 8, 16, QChar ('0'))
.arg (writable_params_, 8, 16, QChar ('0'))
@ -261,7 +264,7 @@ int OmniRigTransceiver::do_start ()
}
if (!await_notification_with_timeout (1000))
{
TRACE_CAT ("OmniRigTransceiver", "do_start 1: wait timed out");
TRACE_CAT ("do_start 1: wait timed out");
throw_qstring (tr ("OmniRig: timeout waiting for update from rig"));
}
switch (rig_->GetRxFrequency () - test_frequency)
@ -289,7 +292,7 @@ int OmniRigTransceiver::do_start ()
}
if (!await_notification_with_timeout (2000))
{
TRACE_CAT ("OmniRigTransceiver", "do_start 2: wait timed out");
TRACE_CAT ("do_start 2: wait timed out");
throw_qstring (tr ("OmniRig: timeout waiting for update from rig"));
}
if (9 == rig_->GetRxFrequency () - test_frequency)
@ -341,30 +344,30 @@ void OmniRigTransceiver::do_stop ()
if (wrapped_) wrapped_->stop ();
TRACE_CAT ("OmniRigTransceiver", "stopped");
TRACE_CAT ("stopped");
}
void OmniRigTransceiver::handle_COM_exception (int code, QString source, QString desc, QString help)
{
TRACE_CAT ("OmniRigTransceiver", QString::number (code) + " at " + source + ": " + desc + " (" + help + ')');
TRACE_CAT (QString::number (code) + " at " + source + ": " + desc + " (" + help + ')');
throw_qstring (tr ("OmniRig COM/OLE error: %1 at %2: %3 (%4)").arg (QString::number (code)).arg (source). arg (desc). arg (help));
}
void OmniRigTransceiver::handle_visible_change ()
{
if (!omni_rig_ || omni_rig_->isNull ()) return;
TRACE_CAT ("OmniRigTransceiver", "visibility change: visibility =" << omni_rig_->DialogVisible ());
TRACE_CAT ("visibility change: visibility =" << omni_rig_->DialogVisible ());
}
void OmniRigTransceiver::handle_rig_type_change (int rig_number)
{
TRACE_CAT ("OmniRigTransceiver", "rig type change: rig =" << rig_number);
TRACE_CAT ("rig type change: rig =" << rig_number);
if (rig_number_ == rig_number)
{
if (!rig_ || rig_->isNull ()) return;
readable_params_ = rig_->ReadableParams ();
writable_params_ = rig_->WriteableParams ();
TRACE_CAT ("OmniRigTransceiver", QString {"rig type change to: %1 readable params = 0x%2 writable params = 0x%3 for rig %4"}
TRACE_CAT (QString {"rig type change to: %1 readable params = 0x%2 writable params = 0x%3 for rig %4"}
.arg (rig_->RigType ())
.arg (readable_params_, 8, 16, QChar ('0'))
.arg (writable_params_, 8, 16, QChar ('0'))
@ -374,12 +377,12 @@ void OmniRigTransceiver::handle_rig_type_change (int rig_number)
void OmniRigTransceiver::handle_status_change (int rig_number)
{
TRACE_CAT ("OmniRigTransceiver", QString {"status change for rig %1"}.arg (rig_number).toLocal8Bit ());
TRACE_CAT (QString {"status change for rig %1"}.arg (rig_number).toLocal8Bit ());
if (rig_number_ == rig_number)
{
if (!rig_ || rig_->isNull ()) return;
auto const& status = rig_->StatusStr ().toLocal8Bit ();
TRACE_CAT ("OmniRigTransceiver", "OmniRig status change: new status = " << status);
TRACE_CAT ("OmniRig status change: new status = " << status);
if (OmniRig::ST_ONLINE != rig_->Status ())
{
if (!offline_timer_->isActive ())
@ -399,14 +402,14 @@ void OmniRigTransceiver::handle_status_change (int rig_number)
// {
// update_rx_frequency (rig_->GetRxFrequency ());
// update_complete ();
// TRACE_CAT ("OmniRigTransceiver", "frequency:" << state ().frequency ());
// TRACE_CAT ("frequency:" << state ().frequency ());
// }
}
}
void OmniRigTransceiver::handle_params_change (int rig_number, int params)
{
TRACE_CAT ("OmniRigTransceiver", QString {"params change: params = 0x%1 for rig %2"}
TRACE_CAT (QString {"params change: params = 0x%1 for rig %2"}
.arg (params, 8, 16, QChar ('0'))
.arg (rig_number).toLocal8Bit ()
<< "state before:" << state ());
@ -419,7 +422,7 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
if (params & OmniRig::PM_VFOAA)
{
TRACE_CAT ("OmniRigTransceiver", "VFOAA");
TRACE_CAT ("VFOAA");
update_split (false);
reversed_ = false;
update_rx_frequency (rig_->FreqA ());
@ -427,7 +430,7 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
}
if (params & OmniRig::PM_VFOAB)
{
TRACE_CAT ("OmniRigTransceiver", "VFOAB");
TRACE_CAT ("VFOAB");
update_split (true);
reversed_ = false;
update_rx_frequency (rig_->FreqA ());
@ -435,7 +438,7 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
}
if (params & OmniRig::PM_VFOBA)
{
TRACE_CAT ("OmniRigTransceiver", "VFOBA");
TRACE_CAT ("VFOBA");
update_split (true);
reversed_ = true;
update_other_frequency (rig_->FreqA ());
@ -443,7 +446,7 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
}
if (params & OmniRig::PM_VFOBB)
{
TRACE_CAT ("OmniRigTransceiver", "VFOBB");
TRACE_CAT ("VFOBB");
update_split (false);
reversed_ = true;
update_other_frequency (rig_->FreqA ());
@ -451,26 +454,26 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
}
if (params & OmniRig::PM_VFOA)
{
TRACE_CAT ("OmniRigTransceiver", "VFOA");
TRACE_CAT ("VFOA");
reversed_ = false;
need_frequency = true;
}
if (params & OmniRig::PM_VFOB)
{
TRACE_CAT ("OmniRigTransceiver", "VFOB");
TRACE_CAT ("VFOB");
reversed_ = true;
need_frequency = true;
}
if (params & OmniRig::PM_FREQ)
{
TRACE_CAT ("OmniRigTransceiver", "FREQ");
TRACE_CAT ("FREQ");
need_frequency = true;
}
if (params & OmniRig::PM_FREQA)
{
auto f = rig_->FreqA ();
TRACE_CAT ("OmniRigTransceiver", "FREQA = " << f);
TRACE_CAT ("FREQA = " << f);
if (reversed_)
{
update_other_frequency (f);
@ -483,7 +486,7 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
if (params & OmniRig::PM_FREQB)
{
auto f = rig_->FreqB ();
TRACE_CAT ("OmniRigTransceiver", "FREQB = " << f);
TRACE_CAT ("FREQB = " << f);
if (reversed_)
{
update_rx_frequency (f);
@ -500,7 +503,7 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
auto f = rig_->FreqA ();
if (f)
{
TRACE_CAT ("OmniRigTransceiver", "FREQA = " << f);
TRACE_CAT ("FREQA = " << f);
if (reversed_)
{
update_other_frequency (f);
@ -516,7 +519,7 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
auto f = rig_->FreqB ();
if (f)
{
TRACE_CAT ("OmniRigTransceiver", "FREQB = " << f);
TRACE_CAT ("FREQB = " << f);
if (reversed_)
{
update_rx_frequency (f);
@ -532,35 +535,35 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
auto f = rig_->Freq ();
if (f)
{
TRACE_CAT ("OmniRigTransceiver", "FREQ = " << f);
TRACE_CAT ("FREQ = " << f);
update_rx_frequency (f);
}
}
}
if (params & OmniRig::PM_PITCH)
{
TRACE_CAT ("OmniRigTransceiver", "PITCH");
TRACE_CAT ("PITCH");
}
if (params & OmniRig::PM_RITOFFSET)
{
TRACE_CAT ("OmniRigTransceiver", "RITOFFSET");
TRACE_CAT ("RITOFFSET");
}
if (params & OmniRig::PM_RIT0)
{
TRACE_CAT ("OmniRigTransceiver", "RIT0");
TRACE_CAT ("RIT0");
}
if (params & OmniRig::PM_VFOEQUAL)
{
auto f = readable_params_ & OmniRig::PM_FREQA ? rig_->FreqA () : rig_->Freq ();
auto m = map_mode (rig_->Mode ());
TRACE_CAT ("OmniRigTransceiver", QString {"VFOEQUAL f=%1 m=%2"}.arg (f).arg (m));
TRACE_CAT (QString {"VFOEQUAL f=%1 m=%2"}.arg (f).arg (m));
update_rx_frequency (f);
update_other_frequency (f);
update_mode (m);
}
if (params & OmniRig::PM_VFOSWAP)
{
TRACE_CAT ("OmniRigTransceiver", "VFOSWAP");
TRACE_CAT ("VFOSWAP");
auto f = state ().tx_frequency ();
update_other_frequency (state ().frequency ());
update_rx_frequency (f);
@ -568,78 +571,78 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
}
if (params & OmniRig::PM_SPLITON)
{
TRACE_CAT ("OmniRigTransceiver", "SPLITON");
TRACE_CAT ("SPLITON");
update_split (true);
}
if (params & OmniRig::PM_SPLITOFF)
{
TRACE_CAT ("OmniRigTransceiver", "SPLITOFF");
TRACE_CAT ("SPLITOFF");
update_split (false);
}
if (params & OmniRig::PM_RITON)
{
TRACE_CAT ("OmniRigTransceiver", "RITON");
TRACE_CAT ("RITON");
}
if (params & OmniRig::PM_RITOFF)
{
TRACE_CAT ("OmniRigTransceiver", "RITOFF");
TRACE_CAT ("RITOFF");
}
if (params & OmniRig::PM_XITON)
{
TRACE_CAT ("OmniRigTransceiver", "XITON");
TRACE_CAT ("XITON");
}
if (params & OmniRig::PM_XITOFF)
{
TRACE_CAT ("OmniRigTransceiver", "XITOFF");
TRACE_CAT ("XITOFF");
}
if (params & OmniRig::PM_RX)
{
TRACE_CAT ("OmniRigTransceiver", "RX");
TRACE_CAT ("RX");
update_PTT (false);
}
if (params & OmniRig::PM_TX)
{
TRACE_CAT ("OmniRigTransceiver", "TX");
TRACE_CAT ("TX");
update_PTT ();
}
if (params & OmniRig::PM_CW_U)
{
TRACE_CAT ("OmniRigTransceiver", "CW-R");
TRACE_CAT ("CW-R");
update_mode (CW_R);
}
if (params & OmniRig::PM_CW_L)
{
TRACE_CAT ("OmniRigTransceiver", "CW");
TRACE_CAT ("CW");
update_mode (CW);
}
if (params & OmniRig::PM_SSB_U)
{
TRACE_CAT ("OmniRigTransceiver", "USB");
TRACE_CAT ("USB");
update_mode (USB);
}
if (params & OmniRig::PM_SSB_L)
{
TRACE_CAT ("OmniRigTransceiver", "LSB");
TRACE_CAT ("LSB");
update_mode (LSB);
}
if (params & OmniRig::PM_DIG_U)
{
TRACE_CAT ("OmniRigTransceiver", "DATA-U");
TRACE_CAT ("DATA-U");
update_mode (DIG_U);
}
if (params & OmniRig::PM_DIG_L)
{
TRACE_CAT ("OmniRigTransceiver", "DATA-L");
TRACE_CAT ("DATA-L");
update_mode (DIG_L);
}
if (params & OmniRig::PM_AM)
{
TRACE_CAT ("OmniRigTransceiver", "AM");
TRACE_CAT ("AM");
update_mode (AM);
}
if (params & OmniRig::PM_FM)
{
TRACE_CAT ("OmniRigTransceiver", "FM");
TRACE_CAT ("FM");
update_mode (FM);
}
@ -648,7 +651,7 @@ void OmniRigTransceiver::handle_params_change (int rig_number, int params)
update_complete ();
send_update_signal_ = false;
}
TRACE_CAT ("OmniRigTransceiver", "OmniRig params change: state after:" << state ());
TRACE_CAT ("OmniRig params change: state after:" << state ());
}
Q_EMIT notified ();
}
@ -661,19 +664,19 @@ void OmniRigTransceiver::handle_custom_reply (int rig_number, QVariant const& co
if (rig_number_ == rig_number)
{
if (!rig_ || rig_->isNull ()) return;
TRACE_CAT ("OmniRigTransceiver", "custom command" << command.toString ().toLocal8Bit ()
TRACE_CAT ("custom command" << command.toString ().toLocal8Bit ()
<< "with reply" << reply.toString ().toLocal8Bit ()
<< QString ("for rig %1").arg (rig_number).toLocal8Bit ());
TRACE_CAT ("OmniRigTransceiver", "rig number:" << rig_number_ << ':' << state ());
TRACE_CAT ("rig number:" << rig_number_ << ':' << state ());
}
}
void OmniRigTransceiver::do_ptt (bool on)
{
TRACE_CAT ("OmniRigTransceiver", on << state ());
TRACE_CAT (on << state ());
if (use_for_ptt_ && TransceiverFactory::PTT_method_CAT == ptt_type_)
{
TRACE_CAT ("OmniRigTransceiver", "set PTT");
TRACE_CAT ("set PTT");
if (rig_ && !rig_->isNull ())
{
rig_->SetTx (on ? OmniRig::PM_TX : OmniRig::PM_RX);
@ -685,18 +688,18 @@ void OmniRigTransceiver::do_ptt (bool on)
{
if (TransceiverFactory::PTT_method_RTS == ptt_type_)
{
TRACE_CAT ("OmniRigTransceiver", "set RTS");
TRACE_CAT ("set RTS");
port_->SetRts (on);
}
else // "DTR"
{
TRACE_CAT ("OmniRigTransceiver", "set DTR");
TRACE_CAT ("set DTR");
port_->SetDtr (on);
}
}
else if (wrapped_)
{
TRACE_CAT ("OmniRigTransceiver", "set PTT using basic transceiver");
TRACE_CAT ("set PTT using basic transceiver");
TransceiverState new_state {wrapped_->state ()};
new_state.ptt (on);
wrapped_->set (new_state, 0);
@ -707,7 +710,7 @@ void OmniRigTransceiver::do_ptt (bool on)
void OmniRigTransceiver::do_frequency (Frequency f, MODE m, bool /*no_ignore*/)
{
TRACE_CAT ("OmniRigTransceiver", f << state ());
TRACE_CAT (f << state ());
if (!rig_ || rig_->isNull ()) return;
if (UNK != m)
{
@ -736,7 +739,7 @@ void OmniRigTransceiver::do_frequency (Frequency f, MODE m, bool /*no_ignore*/)
void OmniRigTransceiver::do_tx_frequency (Frequency tx, MODE m, bool /*no_ignore*/)
{
TRACE_CAT ("OmniRigTransceiver", tx << state ());
TRACE_CAT (tx << state ());
if (!rig_ || rig_->isNull ()) return;
bool split {tx != 0};
if (split)
@ -766,14 +769,14 @@ void OmniRigTransceiver::do_tx_frequency (Frequency tx, MODE m, bool /*no_ignore
}
}
}
TRACE_CAT ("OmniRigTransceiver", "set SPLIT mode on");
TRACE_CAT ("set SPLIT mode on");
rig_->SetSplitMode (state ().frequency (), tx);
update_other_frequency (tx);
update_split (true);
}
else
{
TRACE_CAT ("OmniRigTransceiver", "set SPLIT mode off");
TRACE_CAT ("set SPLIT mode off");
rig_->SetSimplexMode (state ().frequency ());
update_split (false);
}
@ -788,7 +791,7 @@ void OmniRigTransceiver::do_tx_frequency (Frequency tx, MODE m, bool /*no_ignore
}
if (!((OmniRig::PM_VFOAB | OmniRig::PM_VFOBA | OmniRig::PM_SPLITON) & readable_params_))
{
TRACE_CAT ("OmniRigTransceiver", "setting SPLIT manually");
TRACE_CAT ("setting SPLIT manually");
update_split (split); // we can't read it so just set and
// hope op doesn't change it
notify = true;
@ -801,7 +804,7 @@ void OmniRigTransceiver::do_tx_frequency (Frequency tx, MODE m, bool /*no_ignore
void OmniRigTransceiver::do_mode (MODE mode)
{
TRACE_CAT ("OmniRigTransceiver", mode << state ());
TRACE_CAT (mode << state ());
if (!rig_ || rig_->isNull ()) return;
// TODO: G4WJS OmniRig doesn't seem to have any capability of tracking/setting VFO B mode
auto mapped = map_mode (mode);

View File

@ -26,12 +26,14 @@ class OmniRigTransceiver final
Q_OBJECT;
public:
static void register_transceivers (TransceiverFactory::Transceivers *, int id1, int id2);
static void register_transceivers (logger_type *, TransceiverFactory::Transceivers *, int id1, int id2);
enum RigNumber {One = 1, Two};
// takes ownership of wrapped Transceiver
explicit OmniRigTransceiver (std::unique_ptr<TransceiverBase> wrapped, RigNumber, TransceiverFactory::PTTMethod ptt_type, QString const& ptt_port, QObject * parent = nullptr);
explicit OmniRigTransceiver (logger_type *, std::unique_ptr<TransceiverBase> wrapped,
RigNumber, TransceiverFactory::PTTMethod ptt_type,
QString const& ptt_port, QObject * parent = nullptr);
~OmniRigTransceiver ();
int do_start () override;
@ -52,8 +54,8 @@ private:
Q_SLOT void handle_params_change (int rig_number, int params);
Q_SLOT void handle_custom_reply (int, QVariant const& command, QVariant const& reply);
static MODE map_mode (OmniRig::RigParamX param);
static OmniRig::RigParamX map_mode (MODE mode);
MODE map_mode (OmniRig::RigParamX param);
OmniRig::RigParamX map_mode (MODE mode);
std::unique_ptr<TransceiverBase> wrapped_; // may be null
bool use_for_ptt_;

View File

@ -13,8 +13,8 @@ namespace
unsigned const polls_to_stabilize {3};
}
PollingTransceiver::PollingTransceiver (int poll_interval, QObject * parent)
: TransceiverBase {parent}
PollingTransceiver::PollingTransceiver (logger_type * logger, int poll_interval, QObject * parent)
: TransceiverBase {logger, parent}
, interval_ {poll_interval * 1000}
, poll_timer_ {nullptr}
, retries_ {0}

View File

@ -35,7 +35,7 @@ class PollingTransceiver
Q_OBJECT; // for translation context
protected:
explicit PollingTransceiver (int poll_interval, // in seconds
explicit PollingTransceiver (logger_type *, int poll_interval, // in seconds
QObject * parent);
protected:

View File

@ -1,7 +1,15 @@
#include "Transceiver.hpp"
#include <ostream>
#include "moc_Transceiver.cpp"
Transceiver::Transceiver (logger_type * logger, QObject * parent)
: QObject {parent}
, logger_ {logger}
{
}
#if !defined (QT_NO_DEBUG_STREAM)
QDebug operator << (QDebug d, Transceiver::TransceiverState const& s)
{
@ -15,6 +23,16 @@ QDebug operator << (QDebug d, Transceiver::TransceiverState const& s)
}
#endif
std::ostream& operator << (std::ostream& os, Transceiver::TransceiverState const& s)
{
return os
<< "Transceiver::TransceiverState(online: " << (s.online_ ? "yes" : "no")
<< " Frequency {" << s.rx_frequency_ << "Hz, " << s.tx_frequency_ << "Hz} " << s.mode_
<< "; SPLIT: " << (Transceiver::TransceiverState::Split::on == s.split_ ? "on" : Transceiver::TransceiverState::Split::off == s.split_ ? "off" : "unknown")
<< "; PTT: " << (s.ptt_ ? "on" : "off")
<< ')';
}
ENUM_QDATASTREAM_OPS_IMPL (Transceiver, MODE);
ENUM_CONVERSION_OPS_IMPL (Transceiver, MODE);

View File

@ -1,6 +1,11 @@
#ifndef TRANSCEIVER_HPP__
#define TRANSCEIVER_HPP__
#include <iosfwd>
#include <boost/log/trivial.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <QObject>
#include "qt_helpers.hpp"
@ -55,9 +60,11 @@ class Transceiver
public:
using Frequency = Radio::Frequency;
using logger_type = boost::log::sources::severity_channel_logger_mt<boost::log::trivial::severity_level>;
protected:
Transceiver (QObject * parent) : QObject {parent} {}
Transceiver (logger_type *, QObject * parent);
logger_type& logger () const {return *logger_;}
public:
virtual ~Transceiver () {}
@ -108,6 +115,7 @@ public:
friend QDebug operator << (QDebug, TransceiverState const&);
friend bool operator != (TransceiverState const&, TransceiverState const&);
friend std::ostream& operator << (std::ostream&, Transceiver::TransceiverState const&);
};
//
@ -150,6 +158,9 @@ public:
// Ready to be destroyed.
Q_SIGNAL void finished () const;
private:
logger_type mutable * logger_;
};
Q_DECLARE_METATYPE (Transceiver::TransceiverState);
@ -158,6 +169,8 @@ Q_DECLARE_METATYPE (Transceiver::TransceiverState);
QDebug operator << (QDebug, Transceiver::TransceiverState const&);
#endif
std::ostream& operator << (std::ostream&, Transceiver::TransceiverState const&);
ENUM_QDATASTREAM_OPS_DECL (Transceiver, MODE);
ENUM_CONVERSION_OPS_DECL (Transceiver, MODE);

View File

@ -41,7 +41,7 @@ void TransceiverBase::start (unsigned sequence_number) noexcept
void TransceiverBase::set (TransceiverState const& s,
unsigned sequence_number) noexcept
{
TRACE_CAT ("TransceiverBase", "#:" << sequence_number << s);
TRACE_CAT ("#: " << sequence_number << " " << s);
QString message;
try

View File

@ -5,6 +5,7 @@
#include <QString>
#include "Logger.hpp"
#include "Transceiver.hpp"
//
@ -61,8 +62,8 @@ class TransceiverBase
Q_OBJECT;
protected:
TransceiverBase (QObject * parent)
: Transceiver {parent}
TransceiverBase (logger_type * logger, QObject * parent)
: Transceiver {logger, parent}
, last_sequence_number_ {0}
{}
@ -153,16 +154,7 @@ private:
};
// some trace macros
#if WSJT_TRACE_CAT
#define TRACE_CAT(FAC, MSG) qDebug () << QString {"%1::%2:"}.arg ((FAC)).arg (__func__) << MSG
#else
#define TRACE_CAT(FAC, MSG)
#endif
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
#define TRACE_CAT_POLL(FAC, MSG) qDebug () << QString {"%1::%2:"}.arg ((FAC)).arg (__func__) << MSG
#else
#define TRACE_CAT_POLL(FAC, MSG)
#endif
#define TRACE_CAT(MSG) LOG_LOG_LOCATION (logger (), trace, MSG)
#define TRACE_CAT_POLL(MSG) LOG_LOG_LOCATION (logger (), trace, MSG)
#endif

View File

@ -32,14 +32,15 @@ namespace
}
TransceiverFactory::TransceiverFactory ()
: logger_ (boost::log::keywords::channel = "RIGCTRL")
{
HamlibTransceiver::register_transceivers (&transceivers_);
DXLabSuiteCommanderTransceiver::register_transceivers (&transceivers_, CommanderId);
HRDTransceiver::register_transceivers (&transceivers_, HRDId);
HamlibTransceiver::register_transceivers (&logger_, &transceivers_);
DXLabSuiteCommanderTransceiver::register_transceivers (&logger_, &transceivers_, CommanderId);
HRDTransceiver::register_transceivers (&logger_, &transceivers_, HRDId);
#if defined (WIN32)
// OmniRig is ActiveX/COM server so only on Windows
OmniRigTransceiver::register_transceivers (&transceivers_, OmniRigOneId, OmniRigTwoId);
OmniRigTransceiver::register_transceivers (&logger_, &transceivers_, OmniRigOneId, OmniRigTwoId);
#endif
}
@ -91,7 +92,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
if (PTT_method_CAT != params.ptt_type)
{
// we start with a dummy HamlibTransceiver object instance that can support direct PTT
basic_transceiver.reset (new HamlibTransceiver {params.ptt_type, params.ptt_port});
basic_transceiver.reset (new HamlibTransceiver {&logger_, params.ptt_type, params.ptt_port});
if (target_thread)
{
basic_transceiver.get ()->moveToThread (target_thread);
@ -99,7 +100,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
}
// wrap the basic Transceiver object instance with a decorator object that talks to DX Lab Suite Commander
result.reset (new DXLabSuiteCommanderTransceiver {std::move (basic_transceiver), params.network_port, PTT_method_CAT == params.ptt_type, params.poll_interval});
result.reset (new DXLabSuiteCommanderTransceiver {&logger_, std::move (basic_transceiver), params.network_port, PTT_method_CAT == params.ptt_type, params.poll_interval});
if (target_thread)
{
result->moveToThread (target_thread);
@ -113,7 +114,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
if (PTT_method_CAT != params.ptt_type)
{
// we start with a dummy HamlibTransceiver object instance that can support direct PTT
basic_transceiver.reset (new HamlibTransceiver {params.ptt_type, params.ptt_port});
basic_transceiver.reset (new HamlibTransceiver {&logger_, params.ptt_type, params.ptt_port});
if (target_thread)
{
basic_transceiver.get ()->moveToThread (target_thread);
@ -121,7 +122,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
}
// wrap the basic Transceiver object instance with a decorator object that talks to ham Radio Deluxe
result.reset (new HRDTransceiver {std::move (basic_transceiver), params.network_port, PTT_method_CAT == params.ptt_type, params.audio_source, params.poll_interval});
result.reset (new HRDTransceiver {&logger_, std::move (basic_transceiver), params.network_port, PTT_method_CAT == params.ptt_type, params.audio_source, params.poll_interval});
if (target_thread)
{
result->moveToThread (target_thread);
@ -136,7 +137,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
if (PTT_method_CAT != params.ptt_type && "CAT" != params.ptt_port)
{
// we start with a dummy HamlibTransceiver object instance that can support direct PTT
basic_transceiver.reset (new HamlibTransceiver {params.ptt_type, params.ptt_port});
basic_transceiver.reset (new HamlibTransceiver {&logger_, params.ptt_type, params.ptt_port});
if (target_thread)
{
basic_transceiver.get ()->moveToThread (target_thread);
@ -144,7 +145,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
}
// wrap the basic Transceiver object instance with a decorator object that talks to OmniRig rig one
result.reset (new OmniRigTransceiver {std::move (basic_transceiver), OmniRigTransceiver::One, params.ptt_type, params.ptt_port});
result.reset (new OmniRigTransceiver {&logger_, std::move (basic_transceiver), OmniRigTransceiver::One, params.ptt_type, params.ptt_port});
if (target_thread)
{
result->moveToThread (target_thread);
@ -158,7 +159,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
if (PTT_method_CAT != params.ptt_type && "CAT" != params.ptt_port)
{
// we start with a dummy HamlibTransceiver object instance that can support direct PTT
basic_transceiver.reset (new HamlibTransceiver {params.ptt_type, params.ptt_port});
basic_transceiver.reset (new HamlibTransceiver {&logger_, params.ptt_type, params.ptt_port});
if (target_thread)
{
basic_transceiver.get ()->moveToThread (target_thread);
@ -166,7 +167,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
}
// wrap the basic Transceiver object instance with a decorator object that talks to OmniRig rig two
result.reset (new OmniRigTransceiver {std::move (basic_transceiver), OmniRigTransceiver::Two, params.ptt_type, params.ptt_port});
result.reset (new OmniRigTransceiver {&logger_, std::move (basic_transceiver), OmniRigTransceiver::Two, params.ptt_type, params.ptt_port});
if (target_thread)
{
result->moveToThread (target_thread);
@ -176,7 +177,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
#endif
default:
result.reset (new HamlibTransceiver {supported_transceivers ()[params.rig_name].model_number_, params});
result.reset (new HamlibTransceiver {&logger_, supported_transceivers ()[params.rig_name].model_number_, params});
if (target_thread)
{
result->moveToThread (target_thread);
@ -187,7 +188,7 @@ std::unique_ptr<Transceiver> TransceiverFactory::create (ParameterPack const& pa
if (split_mode_emulate == params.split_mode)
{
// wrap the Transceiver object instance with a decorator that emulates split mode
result.reset (new EmulateSplitTransceiver {std::move (result)});
result.reset (new EmulateSplitTransceiver {&logger_, std::move (result)});
if (target_thread)
{
result->moveToThread (target_thread);

View File

@ -3,6 +3,9 @@
#include <memory>
#include <boost/log/trivial.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <QObject>
#include <QMap>
@ -151,6 +154,7 @@ public:
std::unique_ptr<Transceiver> create (ParameterPack const&, QThread * target_thread = nullptr);
private:
Transceiver::logger_type mutable logger_;
Transceivers transceivers_;
};