Added context information to Hamlib interface exception messages.

Enhanced TransceiverBase  error exception  type to allow  for language
translatable messages.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@4033 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2014-04-16 14:59:00 +00:00
parent 51c5f5a84f
commit 2d640afe7b
10 changed files with 112 additions and 100 deletions

View File

@ -72,7 +72,7 @@ void DXLabSuiteCommanderTransceiver::do_start ()
qDebug () << "DXLabSuiteCommanderTransceiver::start failed to connect" << commander_->errorString ();
#endif
throw error {"Failed to connect to DX Lab Suite Commander\n" + commander_->errorString ().toLocal8Bit ()};
throw error {tr ("Failed to connect to DX Lab Suite Commander\n") + commander_->errorString ()};
}
poll ();
@ -202,7 +202,7 @@ void DXLabSuiteCommanderTransceiver::poll ()
qDebug () << "DXLabSuiteCommanderTransceiver::poll: get frequency unexpected response";
#endif
throw error {"DX Lab Suite Commander didn't respond correctly polling frequency"};
throw error {tr ("DX Lab Suite Commander didn't respond correctly polling frequency")};
}
reply = command_with_reply ("<command:13>CmdSendTXFreq<parameters:0>", quiet);
@ -221,7 +221,7 @@ void DXLabSuiteCommanderTransceiver::poll ()
qDebug () << "DXLabSuiteCommanderTransceiver::poll: get tx frequency unexpected response";
#endif
throw error {"DX Lab Suite Commander didn't respond correctly polling TX frequency"};
throw error {tr ("DX Lab Suite Commander didn't respond correctly polling TX frequency")};
}
reply = command_with_reply ("<command:12>CmdSendSplit<parameters:0>", quiet);
@ -242,7 +242,7 @@ void DXLabSuiteCommanderTransceiver::poll ()
qDebug () << "DXLabSuiteCommanderTransceiver::poll: unexpected split state" << split;
#endif
throw error {"DX Lab Suite Commander sent an unrecognised split state: " + split};
throw error {tr ("DX Lab Suite Commander sent an unrecognised split state: ") + split};
}
}
else
@ -251,7 +251,7 @@ void DXLabSuiteCommanderTransceiver::poll ()
qDebug () << "DXLabSuiteCommanderTransceiver::poll: get split mode unexpected response";
#endif
throw error {"DX Lab Suite Commander didn't respond correctly polling split status"};
throw error {tr ("DX Lab Suite Commander didn't respond correctly polling split status")};
}
reply = command_with_reply ("<command:11>CmdSendMode<parameters:0>", quiet);
@ -305,7 +305,7 @@ void DXLabSuiteCommanderTransceiver::poll ()
qDebug () << "DXLabSuiteCommanderTransceiver::poll: unexpected mode name" << mode;
#endif
throw error {"DX Lab Suite Commander sent an unrecognised mode: " + mode};
throw error {tr ("DX Lab Suite Commander sent an unrecognised mode: ") + mode};
}
update_mode (m);
}
@ -315,7 +315,7 @@ void DXLabSuiteCommanderTransceiver::poll ()
qDebug () << "DXLabSuiteCommanderTransceiver::poll: unexpected response";
#endif
throw error {"DX Lab Suite Commander didn't respond correctly polling mode"};
throw error {tr ("DX Lab Suite Commander didn't respond correctly polling mode")};
}
}
@ -336,7 +336,7 @@ void DXLabSuiteCommanderTransceiver::simple_command (QByteArray const& cmd, bool
qDebug () << "DXLabSuiteCommanderTransceiver::simple_command failed:" << commander_->errorString ();
#endif
throw error {"DX Lab Suite Commander send command failed\n" + commander_->errorString ().toLocal8Bit ()};
throw error {tr ("DX Lab Suite Commander send command failed\n") + commander_->errorString ()};
}
commander_->write (cmd);
@ -346,7 +346,7 @@ void DXLabSuiteCommanderTransceiver::simple_command (QByteArray const& cmd, bool
qDebug () << "DXLabSuiteCommanderTransceiver::simple_command failed:" << commander_->errorString ();
#endif
throw error {"DX Lab Suite Commander send command failed\n" + commander_->errorString ().toLocal8Bit ()};
throw error {tr ("DX Lab Suite Commander send command failed\n") + commander_->errorString ()};
}
}
@ -360,7 +360,7 @@ QByteArray DXLabSuiteCommanderTransceiver::command_with_reply (QByteArray const&
qDebug () << "DXLabSuiteCommanderTransceiver::command_with_reply failed:" << commander_->errorString ();
#endif
throw error {"DX Lab Suite Commander read reply failed\n" + commander_->errorString ().toLocal8Bit ()};
throw error {tr ("DX Lab Suite Commander read reply failed\n") + commander_->errorString ()};
}
commander_->write (cmd);
@ -370,7 +370,7 @@ QByteArray DXLabSuiteCommanderTransceiver::command_with_reply (QByteArray const&
qDebug () << "DXLabSuiteCommanderTransceiver::simple_command failed:" << commander_->errorString ();
#endif
throw error {"DX Lab Suite Commander send command failed\n" + commander_->errorString ().toLocal8Bit ()};
throw error {tr ("DX Lab Suite Commander send command failed\n") + commander_->errorString ()};
}
if (!commander_->waitForReadyRead (socket_wait_time))
@ -379,7 +379,7 @@ QByteArray DXLabSuiteCommanderTransceiver::command_with_reply (QByteArray const&
qDebug () << "DXLabSuiteCommanderTransceiver::command_with_reply failed:" << commander_->errorString ();
#endif
throw error {"DX Lab Suite Commander read reply failed\n" + commander_->errorString ().toLocal8Bit ()};
throw error {tr ("DX Lab Suite Commander read reply failed\n") + commander_->errorString ()};
}
auto result = commander_->readAll ();

View File

@ -21,6 +21,8 @@ class QTcpSocket;
class DXLabSuiteCommanderTransceiver final
: public PollingTransceiver
{
Q_OBJECT; // for translation context
public:
static void register_transceivers (TransceiverFactory::Transceivers *, int id);

View File

@ -115,7 +115,7 @@ void HRDTransceiver::do_start ()
qDebug () << "HRDTransceiver::start failed to connect:" << hrd_->errorString ();
#endif
throw error {"Failed to connect to Ham Radio Deluxe\n" + hrd_->errorString ().toLocal8Bit ()};
throw error {tr ("Failed to connect to Ham Radio Deluxe\n") + hrd_->errorString ()};
}
init_radio ();
@ -167,7 +167,7 @@ void HRDTransceiver::init_radio ()
qDebug () << "HRDTransceiver::init_radio failed to connect:" << hrd_->errorString ();
#endif
throw error {"Failed to connect to Ham Radio Deluxe\n" + hrd_->errorString ().toLocal8Bit ()};
throw error {tr ("Failed to connect to Ham Radio Deluxe\n") + hrd_->errorString ()};
}
send_command ("get context", false, false);
@ -185,7 +185,7 @@ void HRDTransceiver::init_radio ()
qDebug () << "HRDTransceiver::init_radio no rig found";
#endif
throw error {"Ham Radio Deluxe: no rig found"};
throw error {tr ("Ham Radio Deluxe: no rig found")};
}
Q_FOREACH (auto const& radio, radios)
@ -208,7 +208,7 @@ void HRDTransceiver::init_radio ()
qDebug () << "HRDTransceiver::init_radio no rig found";
#endif
throw error {"Ham Radio Deluxe: no rig found"};
throw error {tr ("Ham Radio Deluxe: no rig found")};
}
vfo_count_ = send_command ("get vfo-count").toUInt ();
@ -346,7 +346,7 @@ int HRDTransceiver::lookup_mode (MODE mode, ModeMap const& map) const
auto it = std::find_if (map.begin (), map.end (), [mode] (ModeMap::value_type const& item) {return std::get<0> (item) == mode;});
if (map.end () == it)
{
throw error {"Ham Radio Deluxe: rig doesn't support mode"};
throw error {tr ("Ham Radio Deluxe: rig doesn't support mode")};
}
return std::get<1> (*it);
}
@ -356,7 +356,7 @@ auto HRDTransceiver::lookup_mode (int mode, ModeMap const& map) const -> MODE
auto it = std::find_if (map.begin (), map.end (), [mode] (ModeMap::value_type const& item) {return std::get<1> (item) == mode;});
if (map.end () == it)
{
throw error {"Ham Radio Deluxe: sent an unrecognised mode"};
throw error {tr ("Ham Radio Deluxe: sent an unrecognised mode")};
}
return std::get<0> (*it);
}
@ -374,7 +374,7 @@ int HRDTransceiver::get_dropdown (int dd, bool no_debug)
qDebug () << "HRDTransceiver::get_dropdown bad response";
#endif
throw error {"Ham Radio Deluxe didn't respond as expected"};
throw error {tr ("Ham Radio Deluxe didn't respond as expected")};
}
Q_ASSERT (reply.left (colon_index).trimmed () == dd_name);
@ -394,7 +394,7 @@ void HRDTransceiver::set_dropdown (int dd, int value)
qDebug () << "HRDTransceiver::set_dropdown item" << value << "not found in" << dd_name;
#endif
throw error {("Ham Radio Deluxe: item not found in " + dd_name + " dropdown list").toLocal8Bit ()};
throw error {tr ("Ham Radio Deluxe: item not found in %1 dropdown list").arg (dd_name)};
}
}
@ -427,7 +427,7 @@ void HRDTransceiver::set_button (int button_index, bool checked)
qDebug () << "HRDTransceiver::set_button invalid button";
#endif
throw error {"Ham Radio Deluxe: button not available"};
throw error {tr ("Ham Radio Deluxe: button not available")};
}
}
@ -559,7 +559,7 @@ bool HRDTransceiver::is_button_checked (int button_index, bool no_debug)
qDebug () << "HRDTransceiver::is_button_checked bad response";
#endif
throw error {"Ham Radio Deluxe didn't respond as expected"};
throw error {tr ("Ham Radio Deluxe didn't respond as expected")};
}
return "1" == reply;
}
@ -638,7 +638,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
qDebug () << "HRDTransceiver::send_command connection failed:" << hrd_->errorString ();
#endif
throw error {"Ham Radio Deluxe connection failed\n" + hrd_->errorString ().toLocal8Bit ()};
throw error {tr ("Ham Radio Deluxe connection failed\n") + hrd_->errorString ()};
}
if (!recurse && prepend_context)
@ -654,7 +654,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
qDebug () << "HRDTransceiver::send_command rig disappeared or changed";
#endif
throw error {"Ham Radio Deluxe: rig has disappeared or changed"};
throw error {tr ("Ham Radio Deluxe: rig has disappeared or changed")};
}
if (0u == current_radio_ || std::get<0> (*radio_iter) != current_radio_)
@ -696,7 +696,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
qDebug () << "HRDTransceiver::send_command failed" << hrd_->errorString ();
#endif
throw error {"Ham Radio Deluxe send command failed\n" + hrd_->errorString ().toLocal8Bit ()};
throw error {tr ("Ham Radio Deluxe send command failed\n") + hrd_->errorString ()};
}
if (!hrd_->waitForReadyRead (socket_wait_time))
@ -705,7 +705,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
qDebug () << "HRDTransceiver::send_command failed to reply" << hrd_->errorString ();
#endif
throw error {"Ham Radio Deluxe failed to reply to command\n" + hrd_->errorString ().toLocal8Bit ()};
throw error {tr ("Ham Radio Deluxe failed to reply to command\n") + hrd_->errorString ()};
}
QByteArray buffer (hrd_->readAll ());
if (!no_debug)
@ -729,7 +729,7 @@ QString HRDTransceiver::send_command (QString const& cmd, bool no_debug, bool pr
qDebug () << "HRDTransceiver::send_command invalid reply";
#endif
throw error {"Ham Radio Deluxe sent an invalid reply to our command"};
throw error {tr ("Ham Radio Deluxe sent an invalid reply to our command")};
}
result = QString {reply->payload_}; // this is not a memory leak (honest!)
@ -753,6 +753,6 @@ void HRDTransceiver::send_simple_command (QString const& command, bool no_debug)
qDebug () << "HRDTransceiver::send_simple_command unexpected response";
#endif
throw error {"Ham Radio Deluxe didn't respond as expected"};
throw error {tr ("Ham Radio Deluxe didn't respond as expected")};
}
}

View File

@ -169,7 +169,7 @@ HamlibTransceiver::HamlibTransceiver (int model_number
{
if (!rig_)
{
throw error {"Hamlib initialisation error"};
throw error {tr ("Hamlib initialisation error")};
}
// rig_->state.obj = this;
@ -241,6 +241,18 @@ HamlibTransceiver::~HamlibTransceiver ()
{
}
void HamlibTransceiver::error_check (int ret_code, QString const& doing) const
{
if (RIG_OK != ret_code)
{
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
qDebug () << "HamlibTransceiver::error_check: error:" << rigerror (ret_code);
#endif
throw error {tr ("Hamlib error: %1 while %2").arg (rigerror (ret_code)).arg (doing)};
}
}
void HamlibTransceiver::do_start ()
{
#if WSJT_TRACE_CAT
@ -248,7 +260,7 @@ void HamlibTransceiver::do_start ()
+ QString::fromLatin1 (rig_->caps->model_name).trimmed ();
#endif
error_check (rig_open (rig_.data ()));
error_check (rig_open (rig_.data ()), tr ("opening connection to rig"));
init_rig ();
}
@ -281,13 +293,13 @@ void HamlibTransceiver::init_rig ()
// VFO is selected or if SPLIT is selected so we have to simply
// assume it is as when we started by setting at open time right
// here. We also gather/set other initial state.
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f1));
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f1), tr ("getting current frequency"));
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::init_rig rig_get_freq =" << f1;
#endif
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w));
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w), tr ("getting current mode"));
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::init_rig rig_get_mode =" << m << "bw =" << w;
@ -302,11 +314,11 @@ void HamlibTransceiver::init_rig ()
qDebug () << "HamlibTransceiver::init_rig rig_vfo_op TOGGLE";
#endif
error_check (rig_vfo_op (rig_.data (), RIG_VFO_CURR, RIG_OP_TOGGLE));
error_check (rig_vfo_op (rig_.data (), RIG_VFO_CURR, RIG_OP_TOGGLE), tr ("exchanging VFOs"));
}
else
{
throw error {"Hamlib: unable to initialise rig"};
throw error {tr ("Hamlib: unable to initialise rig")};
}
}
else
@ -316,16 +328,16 @@ void HamlibTransceiver::init_rig ()
qDebug () << "HamlibTransceiver::init_rig rig_set_vfo";
#endif
error_check (rig_set_vfo (rig_.data (), rig_->state.vfo_list & RIG_VFO_B ? RIG_VFO_B : RIG_VFO_SUB));
error_check (rig_set_vfo (rig_.data (), rig_->state.vfo_list & RIG_VFO_B ? RIG_VFO_B : RIG_VFO_SUB), tr ("setting current VFO"));
}
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f2));
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f2), tr ("getting other VFO frequency"));
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::init_rig rig_get_freq =" << f2;
#endif
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &mb, &wb));
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &mb, &wb), tr ("getting other VFFO mode"));
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::init_rig rig_get_mode =" << mb << "bw =" << wb;
@ -340,7 +352,7 @@ void HamlibTransceiver::init_rig ()
qDebug () << "HamlibTransceiver::init_rig rig_vfo_op TOGGLE";
#endif
error_check (rig_vfo_op (rig_.data (), RIG_VFO_CURR, RIG_OP_TOGGLE));
error_check (rig_vfo_op (rig_.data (), RIG_VFO_CURR, RIG_OP_TOGGLE), tr ("exchanging VFOs"));
}
else
{
@ -348,7 +360,7 @@ void HamlibTransceiver::init_rig ()
qDebug () << "HamlibTransceiver::init_rig rig_set_vfo";
#endif
error_check (rig_set_vfo (rig_.data (), rig_->state.vfo_list & RIG_VFO_A ? RIG_VFO_A : RIG_VFO_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"));
}
if (f1 != f2 || m != mb || w != wb) // we must have started with MAIN/A
@ -357,13 +369,13 @@ void HamlibTransceiver::init_rig ()
}
else
{
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f1));
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f1), tr ("getting frequency"));
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::init_rig rig_get_freq =" << f1;
#endif
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w));
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w), tr ("getting mode"));
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::init_rig rig_get_mode =" << m << "bw =" << w;
@ -376,13 +388,13 @@ void HamlibTransceiver::init_rig ()
qDebug () << "HamlibTransceiver::init_rig rig_set_split_vfo";
#endif
// error_check (rig_set_split_vfo (rig_.data (), RIG_VFO_CURR, RIG_SPLIT_OFF, RIG_VFO_CURR));
// error_check (rig_set_split_vfo (rig_.data (), RIG_VFO_CURR, RIG_SPLIT_OFF, RIG_VFO_CURR), tr ("setting split off"));
// update_split (false);
}
else
{
vfo_t v;
error_check (rig_get_vfo (rig_.data (), &v)); // has side effect of establishing current VFO inside hamlib
error_check (rig_get_vfo (rig_.data (), &v), tr ("getting current VFO")); // has side effect of establishing current VFO inside hamlib
#if WSJT_TRACE_CAT
qDebug ().nospace () << "HamlibTransceiver::init_rig rig_get_vfo = 0x" << hex << v;
@ -392,7 +404,7 @@ void HamlibTransceiver::init_rig ()
if (!(rig_->caps->targetable_vfo & (RIG_TARGETABLE_MODE | RIG_TARGETABLE_PURE)))
{
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w));
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w), tr ("getting current mode"));
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::init_rig rig_get_mode =" << m << "bw =" << w;
@ -414,7 +426,7 @@ auto HamlibTransceiver::get_vfos () const -> std::tuple<vfo_t, vfo_t>
if (rig_->caps->get_vfo)
{
vfo_t v;
error_check (rig_get_vfo (rig_.data (), &v)); // has side effect of establishing current VFO inside hamlib
error_check (rig_get_vfo (rig_.data (), &v), tr ("getting current VFO")); // has side effect of establishing current VFO inside hamlib
#if WSJT_TRACE_CAT
qDebug ().nospace () << "HamlibTransceiver::get_vfos rig_get_vfo = 0x" << hex << v;
@ -432,7 +444,7 @@ auto HamlibTransceiver::get_vfos () const -> std::tuple<vfo_t, vfo_t>
qDebug () << "HamlibTransceiver::get_vfos rig_set_vfo";
#endif
error_check (rig_set_vfo (rig_.data (), rig_->state.vfo_list & RIG_VFO_A ? RIG_VFO_A : RIG_VFO_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 both VFOs should be substitutable
@ -462,7 +474,7 @@ void HamlibTransceiver::do_frequency (Frequency f)
if (!is_dummy_)
{
error_check (rig_set_freq (rig_.data (), RIG_VFO_CURR, f));
error_check (rig_set_freq (rig_.data (), RIG_VFO_CURR, f), tr ("setting frequency"));
}
update_rx_frequency (f);
@ -487,7 +499,7 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, bool rationalise_mode)
#endif
hamlib_tx_vfo_fixup fixup (rig_.data (), tx_vfo);
error_check (rig_set_split_freq (rig_.data (), RIG_VFO_CURR, tx));
error_check (rig_set_split_freq (rig_.data (), RIG_VFO_CURR, tx), tr ("setting split TX frequency"));
if (rationalise_mode)
{
@ -498,7 +510,7 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, bool rationalise_mode)
qDebug () << "HamlibTransceiver::mode rig_get_split_mode";
#endif
auto new_mode = map_mode (state ().mode ());
error_check (rig_get_split_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width));
error_check (rig_get_split_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width), tr ("getting mode of split TX VFO"));
if (new_mode != current_mode)
{
@ -506,7 +518,7 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, bool rationalise_mode)
qDebug () << "HamlibTransceiver::do_tx_frequency rig_set_split_mode";
#endif
error_check (rig_set_split_mode (rig_.data (), RIG_VFO_CURR, new_mode, rig_passband_wide (rig_.data (), new_mode)));
error_check (rig_set_split_mode (rig_.data (), RIG_VFO_CURR, new_mode, rig_passband_wide (rig_.data (), new_mode)), tr ("setting split TX VFO mode"));
}
}
}
@ -519,7 +531,7 @@ void HamlibTransceiver::do_tx_frequency (Frequency tx, bool rationalise_mode)
qDebug () << "HamlibTransceiver::do_tx_frequency rig_set_split_vfo";
#endif
error_check (rig_set_split_vfo (rig_.data (), RIG_VFO_CURR, tx ? RIG_SPLIT_ON : RIG_SPLIT_OFF, tx_vfo));
error_check (rig_set_split_vfo (rig_.data (), RIG_VFO_CURR, tx ? RIG_SPLIT_ON : RIG_SPLIT_OFF, tx_vfo), tr ("seting split mode"));
}
update_split (tx);
@ -544,7 +556,7 @@ void HamlibTransceiver::do_mode (MODE mode, bool rationalise)
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::mode rig_get_mode";
#endif
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width));
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width), tr ("getting current VFO mode"));
auto new_mode = map_mode (mode);
if (new_mode != current_mode)
@ -552,7 +564,7 @@ void HamlibTransceiver::do_mode (MODE mode, bool rationalise)
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::mode rig_set_mode";
#endif
error_check (rig_set_mode (rig_.data (), RIG_VFO_CURR, new_mode, rig_passband_wide (rig_.data (), new_mode)));
error_check (rig_set_mode (rig_.data (), RIG_VFO_CURR, new_mode, rig_passband_wide (rig_.data (), new_mode)), tr ("setting current VFO mode"));
}
if (state ().split () && rationalise)
@ -560,7 +572,7 @@ void HamlibTransceiver::do_mode (MODE mode, bool rationalise)
#if WSJT_TRACE_CAT
qDebug () << "HamlibTransceiver::mode rig_get_split_mode";
#endif
error_check (rig_get_split_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width));
error_check (rig_get_split_mode (rig_.data (), RIG_VFO_CURR, &current_mode, &current_width), tr ("getting split TX VFO mode"));
if (new_mode != current_mode)
{
@ -568,7 +580,7 @@ void HamlibTransceiver::do_mode (MODE mode, bool rationalise)
qDebug () << "HamlibTransceiver::mode rig_set_split_mode";
#endif
hamlib_tx_vfo_fixup fixup (rig_.data (), tx_vfo);
error_check (rig_set_split_mode (rig_.data (), RIG_VFO_CURR, new_mode, rig_passband_wide (rig_.data (), new_mode)));
error_check (rig_set_split_mode (rig_.data (), RIG_VFO_CURR, new_mode, rig_passband_wide (rig_.data (), new_mode)), tr ("setting split TX VFO mode"));
}
}
}
@ -604,7 +616,7 @@ void HamlibTransceiver::poll ()
if (rig_->caps->get_vfo)
{
vfo_t v;
error_check (rig_get_vfo (rig_.data (), &v)); // has side effect of establishing current VFO inside hamlib
error_check (rig_get_vfo (rig_.data (), &v), tr ("getting current VFO")); // has side effect of establishing current VFO inside hamlib
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
qDebug ().nospace () << "HamlibTransceiver::state rig_get_vfo = 0x" << hex << v;
@ -613,7 +625,7 @@ void HamlibTransceiver::poll ()
reversed_ = RIG_VFO_B == v;
}
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f));
error_check (rig_get_freq (rig_.data (), RIG_VFO_CURR, &f), tr ("getting current VFO frequency"));
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
qDebug () << "HamlibTransceiver::state rig_get_freq =" << f;
@ -628,7 +640,7 @@ void HamlibTransceiver::poll ()
, reversed_
? (rig_->state.vfo_list & RIG_VFO_A ? RIG_VFO_A : RIG_VFO_MAIN)
: (rig_->state.vfo_list & RIG_VFO_B ? RIG_VFO_B : RIG_VFO_SUB)
, &f));
, &f), tr ("getting current VFO frequency"));
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
qDebug () << "HamlibTransceiver::state rig_get_freq other =" << f;
@ -637,7 +649,7 @@ void HamlibTransceiver::poll ()
update_other_frequency (f);
}
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w));
error_check (rig_get_mode (rig_.data (), RIG_VFO_CURR, &m, &w), tr ("getting current VFO mode"));
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
qDebug () << "HamlibTransceiver::state rig_get_mode =" << m << "bw =" << w;
@ -678,13 +690,13 @@ void HamlibTransceiver::poll ()
}
else
{
error_check (rc);
error_check (rc, tr ("getting split TX VFO"));
}
if (RIG_PTT_NONE != rig_->state.pttport.type.ptt && rig_->caps->get_ptt)
{
ptt_t p;
error_check (rig_get_ptt (rig_.data (), RIG_VFO_CURR, &p));
error_check (rig_get_ptt (rig_.data (), RIG_VFO_CURR, &p), tr ("getting PTT state"));
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
qDebug () << "HamlibTransceiver::state rig_get_ptt =" << p;
@ -719,7 +731,7 @@ void HamlibTransceiver::do_ptt (bool on)
qDebug () << "HamlibTransceiver::ptt rig_set_ptt";
#endif
error_check (rig_set_ptt (rig_.data (), RIG_VFO_CURR, back_ptt_port_ ? RIG_PTT_ON_DATA : RIG_PTT_ON));
error_check (rig_set_ptt (rig_.data (), RIG_VFO_CURR, back_ptt_port_ ? RIG_PTT_ON_DATA : RIG_PTT_ON), tr ("setting PTT on"));
}
}
else
@ -730,31 +742,19 @@ void HamlibTransceiver::do_ptt (bool on)
qDebug () << "HamlibTransceiver::ptt rig_set_ptt";
#endif
error_check (rig_set_ptt (rig_.data (), RIG_VFO_CURR, RIG_PTT_OFF));
error_check (rig_set_ptt (rig_.data (), RIG_VFO_CURR, RIG_PTT_OFF), tr ("setting PTT off"));
}
}
update_PTT (on);
}
void HamlibTransceiver::error_check (int ret_code) const
{
if (RIG_OK != ret_code)
{
#if WSJT_TRACE_CAT && WSJT_TRACE_CAT_POLLS
qDebug () << "HamlibTransceiver::error_check: error:" << rigerror (ret_code);
#endif
throw error {QByteArray ("Hamlib error: ") + rigerror (ret_code)};
}
}
void HamlibTransceiver::set_conf (char const * item, char const * value)
{
token_t token = rig_token_lookup (rig_.data (), item);
if (RIG_CONF_END != token) // only set if valid for rig model
{
error_check (rig_set_conf (rig_.data (), token, value));
error_check (rig_set_conf (rig_.data (), token, value), tr ("setting a configuration item"));
}
}
@ -764,7 +764,7 @@ QByteArray HamlibTransceiver::get_conf (char const * item)
QByteArray value {128, '\0'};
if (RIG_CONF_END != token) // only get if valid for rig model
{
error_check (rig_get_conf (rig_.data (), token, value.data ()));
error_check (rig_get_conf (rig_.data (), token, value.data ()), tr ("getting a configuration item"));
}
return value;
}

View File

@ -21,6 +21,8 @@ extern "C"
class HamlibTransceiver final
: public PollingTransceiver
{
Q_OBJECT; // for translation context
public:
static void register_transceivers (TransceiverFactory::Transceivers *);
@ -48,7 +50,7 @@ class HamlibTransceiver final
void poll () override;
void error_check (int ret_code) const;
void error_check (int ret_code, QString const& doing) const;
void set_conf (char const * item, char const * value);
QByteArray get_conf (char const * item);
Transceiver::MODE map_mode (rmode_t) const;

View File

@ -52,7 +52,7 @@ auto OmniRigTransceiver::map_mode (OmniRig::RigParamX param) -> MODE
qDebug () << "OmniRig map_mode unrecognized mode";
#endif
throw error {"OmniRig: unrecognized mode"};
throw error {tr ("OmniRig: unrecognized mode")};
}
OmniRig::RigParamX OmniRigTransceiver::map_mode (MODE mode)
@ -130,7 +130,7 @@ void OmniRigTransceiver::do_start ()
qDebug () << "OmniRigTransceiver::do_start: failed to start COM server";
#endif
throw error {"Failed to start OmniRig COM server"};
throw error {tr ("Failed to start OmniRig COM server")};
}
// COM/OLE exceptions get signalled
@ -172,7 +172,7 @@ void OmniRigTransceiver::do_start ()
// if (!port_->Lock ()) // try to take exclusive use of the OmniRig serial port for PTT
// {
// throw error {("Failed to get exclusive use of " + ptt_type + " from OmniRig").toLocal8Bit ()};
// throw error {tr ("Failed to get exclusive use of %1" from OmniRig").arg (ptt_type)};
// }
// start off so we don't accidentally key the radio
@ -289,7 +289,7 @@ void OmniRigTransceiver::handle_COM_exception (int code, QString source, QString
qDebug () << "OmniRigTransceiver::handle_COM_exception:" << QString::number (code) + " at " + source + ": " + desc + " (" + help + ')';
#endif
throw error {("OmniRig COM/OLE error: " + QString::number (code) + " at " + source + ": " + desc + " (" + help + ')').toLocal8Bit ()};
throw error {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 ()
@ -659,7 +659,7 @@ void OmniRigTransceiver::do_frequency (Frequency f)
}
else
{
throw error {"OmniRig: don't know how to set rig frequency"};
throw error {tr ("OmniRig: don't know how to set rig frequency")};
}
}

View File

@ -200,7 +200,7 @@ void PollingTransceiver::impl::handle_timeout ()
}
catch (...)
{
message = "Unexpected rig error";
message = tr ("Unexpected rig error");
}
if (!message.isEmpty ())
{

View File

@ -32,6 +32,8 @@
class PollingTransceiver
: public TransceiverBase
{
Q_OBJECT; // for translation context
protected:
explicit PollingTransceiver (int poll_interval); // in milliseconds

View File

@ -6,6 +6,11 @@
#include "pimpl_impl.hpp"
namespace
{
auto const unexpected = TransceiverBase::tr ("Unexpected rig error");
}
class TransceiverBase::impl final
{
public:
@ -53,7 +58,7 @@ void TransceiverBase::start () noexcept
}
catch (...)
{
message = "Unexpected rig error";
message = unexpected;
}
if (!message.isEmpty ())
{
@ -83,7 +88,7 @@ void TransceiverBase::stop () noexcept
}
catch (...)
{
message = "Unexpected rig error";
message = unexpected;
}
if (!message.isEmpty ())
{
@ -112,7 +117,7 @@ void TransceiverBase::frequency (Frequency f) noexcept
}
catch (...)
{
message = "Unexpected rig error";
message = unexpected;
}
if (!message.isEmpty ())
{
@ -137,7 +142,7 @@ void TransceiverBase::tx_frequency (Frequency tx, bool rationalise_mode) noexcep
}
catch (...)
{
message = "Unexpected rig error";
message = unexpected;
}
if (!message.isEmpty ())
{
@ -162,7 +167,7 @@ void TransceiverBase::mode (MODE m, bool rationalise) noexcept
}
catch (...)
{
message = "Unexpected rig error";
message = unexpected;
}
if (!message.isEmpty ())
{
@ -187,7 +192,7 @@ void TransceiverBase::ptt (bool on) noexcept
}
catch (...)
{
message = "Unexpected rig error";
message = unexpected;
}
if (!message.isEmpty ())
{
@ -211,7 +216,7 @@ void TransceiverBase::sync (bool force_signal) noexcept
}
catch (...)
{
message = "Unexpected rig error";
message = unexpected;
}
if (!message.isEmpty ())
{
@ -269,7 +274,7 @@ void TransceiverBase::offline (QString const& reason)
}
catch (...)
{
message = "Unexpected rig error";
message = unexpected;
}
Q_EMIT failure (reason + '\n' + message);
}

View File

@ -3,12 +3,12 @@
#include <stdexcept>
#include <QString>
#include "Transceiver.hpp"
#include "pimpl_h.hpp"
class QString;
//
// Base Transceiver Implementation
//
@ -84,7 +84,8 @@ protected:
struct error
: public std::runtime_error
{
error (char const * msg) : std::runtime_error (msg) {}
error (char const * const msg) : std::runtime_error (msg) {}
error (QString const& msg) : std::runtime_error (msg.toStdString ()) {}
};
// Template methods that sub classes implement to do what they need to do.