summaryrefslogtreecommitdiff
path: root/DXLabSuiteCommanderTransceiver.cpp
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
committerhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
commit37f727ac0746fd85504aa46c1f023c09b3eff33a (patch)
treec8a7ce04545040a8f161ba279528730bd9a3e6ab /DXLabSuiteCommanderTransceiver.cpp
parentd63dd8d081a6fcd0715cd13f26df59fb831769d2 (diff)
New upstream version 1.8.0+repackupstream/1.8.0+repack
Diffstat (limited to 'DXLabSuiteCommanderTransceiver.cpp')
-rw-r--r--DXLabSuiteCommanderTransceiver.cpp192
1 files changed, 150 insertions, 42 deletions
diff --git a/DXLabSuiteCommanderTransceiver.cpp b/DXLabSuiteCommanderTransceiver.cpp
index 7ef7bb4c..4e9270cf 100644
--- a/DXLabSuiteCommanderTransceiver.cpp
+++ b/DXLabSuiteCommanderTransceiver.cpp
@@ -3,6 +3,8 @@
#include <QTcpSocket>
#include <QRegularExpression>
#include <QLocale>
+#include <QThread>
+#include <QDateTime>
#include "NetworkServerLookup.hpp"
@@ -39,8 +41,10 @@ void DXLabSuiteCommanderTransceiver::register_transceivers (TransceiverFactory::
(*registry)[commander_transceiver_name] = TransceiverFactory::Capabilities {id, TransceiverFactory::Capabilities::network, true};
}
-DXLabSuiteCommanderTransceiver::DXLabSuiteCommanderTransceiver (std::unique_ptr<TransceiverBase> wrapped, QString const& address, bool use_for_ptt, int poll_interval)
- : PollingTransceiver {poll_interval}
+DXLabSuiteCommanderTransceiver::DXLabSuiteCommanderTransceiver (std::unique_ptr<TransceiverBase> wrapped,
+ QString const& address, bool use_for_ptt,
+ int poll_interval, QObject * parent)
+ : PollingTransceiver {poll_interval, parent}
, wrapped_ {std::move (wrapped)}
, use_for_ptt_ {use_for_ptt}
, server_ {address}
@@ -48,14 +52,10 @@ DXLabSuiteCommanderTransceiver::DXLabSuiteCommanderTransceiver (std::unique_ptr<
{
}
-DXLabSuiteCommanderTransceiver::~DXLabSuiteCommanderTransceiver ()
+int DXLabSuiteCommanderTransceiver::do_start ()
{
-}
-
-void DXLabSuiteCommanderTransceiver::do_start ()
-{
- TRACE_CAT ("starting");
- wrapped_->start ();
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", "starting");
+ if (wrapped_) wrapped_->start (0);
auto server_details = network_server_lookup (server_, 52002u, QHostAddress::LocalHost, QAbstractSocket::IPv4Protocol);
@@ -67,11 +67,68 @@ void DXLabSuiteCommanderTransceiver::do_start ()
commander_->connectToHost (std::get<0> (server_details), std::get<1> (server_details));
if (!commander_->waitForConnected ())
{
- TRACE_CAT ("failed to connect" << commander_->errorString ());
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", "failed to connect" << commander_->errorString ());
throw error {tr ("Failed to connect to DX Lab Suite Commander\n") + commander_->errorString ()};
}
-
+
+ // sleeps here are to ensure Commander has actually queried the rig
+ // rather than returning cached data which maybe stale or simply
+ // read backs of not yet committed values, the 2s delays are
+ // arbitrary but hopefully enough as the actual time required is rig
+ // and Commander setting dependent
+ int resolution {0};
+ QThread::msleep (2000);
+ 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));
+ if (f && !(f % 10))
+ {
+ auto test_frequency = f - f % 100 + 55;
+ auto f_string = frequency_to_string (test_frequency);
+ auto params = ("<xcvrfreq:%1>" + f_string).arg (f_string.size ());
+ simple_command (("<command:10>CmdSetFreq<parameters:%1>" + params).arg (params.size ()));
+ QThread::msleep (2000);
+ reply = command_with_reply ("<command:10>CmdGetFreq<parameters:0>");
+ if (0 == reply.indexOf ("<CmdFreq:"))
+ {
+ auto new_frequency = string_to_frequency (reply.mid (reply.indexOf ('>') + 1));
+ switch (static_cast<Radio::FrequencyDelta> (new_frequency - test_frequency))
+ {
+ case -5: resolution = -1; break; // 10Hz truncated
+ case 5: resolution = 1; break; // 10Hz rounded
+ case -15: resolution = -2; break; // 20Hz truncated
+ case -55: resolution = -2; break; // 100Hz truncated
+ case 45: resolution = 2; break; // 100Hz rounded
+ }
+ if (1 == resolution) // may be 20Hz rounded
+ {
+ test_frequency = f - f % 100 + 51;
+ f_string = frequency_to_string (test_frequency);
+ params = ("<xcvrfreq:%1>" + f_string).arg (f_string.size ());
+ simple_command (("<command:10>CmdSetFreq<parameters:%1>" + params).arg (params.size ()));
+ QThread::msleep (2000);
+ reply = command_with_reply ("<command:10>CmdGetFreq<parameters:0>");
+ new_frequency = string_to_frequency (reply.mid (reply.indexOf ('>') + 1));
+ if (9 == static_cast<Radio::FrequencyDelta> (new_frequency - test_frequency))
+ {
+ resolution = 2; // 20Hz rounded
+ }
+ }
+ f_string = frequency_to_string (f);
+ params = ("<xcvrfreq:%1>" + f_string).arg (f_string.size ());
+ simple_command (("<command:10>CmdSetFreq<parameters:%1>" + params).arg (params.size ()));
+ }
+ }
+ }
+ else
+ {
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", "get frequency unexpected response" << reply);
+ throw error {tr ("DX Lab Suite Commander didn't respond correctly reading frequency: ") + reply};
+ }
+
poll ();
+ return resolution;
}
void DXLabSuiteCommanderTransceiver::do_stop ()
@@ -82,29 +139,70 @@ void DXLabSuiteCommanderTransceiver::do_stop ()
delete commander_, commander_ = nullptr;
}
- wrapped_->stop ();
- TRACE_CAT ("stopped");
+ if (wrapped_) wrapped_->stop ();
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", "stopped");
}
void DXLabSuiteCommanderTransceiver::do_ptt (bool on)
{
- TRACE_CAT (on << state ());
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", on << state ());
if (use_for_ptt_)
{
simple_command (on ? "<command:5>CmdTX<parameters:0>" : "<command:5>CmdRX<parameters:0>");
+
+ bool tx {!on};
+ auto start = QDateTime::currentMSecsSinceEpoch ();
+ // we must now wait for Tx on the rig, we will wait a short while
+ // before bailing out
+ while (tx != on && QDateTime::currentMSecsSinceEpoch () - start < 1000)
+ {
+ auto reply = command_with_reply ("<command:9>CmdSendTx<parameters:0>");
+ if (0 == reply.indexOf ("<CmdTX:"))
+ {
+ auto state = reply.mid (reply.indexOf ('>') + 1);
+ if ("ON" == state)
+ {
+ tx = true;
+ }
+ else if ("OFF" == state)
+ {
+ tx = false;
+ }
+ else
+ {
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", "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);
+ 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
+ }
+ update_PTT (tx);
+ if (tx != on)
+ {
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", "rig failed to respond to PTT: " << on);
+ throw error {tr ("DX Lab Suite Commander rig did not respond to PTT: ") + (on ? "ON" : "OFF")};
+ }
}
else
{
- wrapped_->ptt (on);
+ Q_ASSERT (wrapped_);
+ TransceiverState new_state {wrapped_->state ()};
+ new_state.ptt (on);
+ wrapped_->set (new_state, 0);
+ update_PTT (on);
}
- update_PTT (on);
}
-void DXLabSuiteCommanderTransceiver::do_frequency (Frequency f, MODE m)
+void DXLabSuiteCommanderTransceiver::do_frequency (Frequency f, MODE m, bool /*no_ignore*/)
{
- TRACE_CAT (f << state ());
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", f << state ());
auto f_string = frequency_to_string (f);
- if (UNK != m)
+ if (UNK != m && m != get_mode ())
{
auto m_string = map_mode (m);
auto params = ("<xcvrfreq:%1>" + f_string + "<xcvrmode:%2>" + m_string + "<preservesplitanddual:1>Y").arg (f_string.size ()).arg (m_string.size ());
@@ -119,13 +217,17 @@ void DXLabSuiteCommanderTransceiver::do_frequency (Frequency f, MODE m)
update_rx_frequency (f);
}
-void DXLabSuiteCommanderTransceiver::do_tx_frequency (Frequency tx, bool /* rationalise_mode */)
+void DXLabSuiteCommanderTransceiver::do_tx_frequency (Frequency tx, MODE mode, bool /*no_ignore*/)
{
- TRACE_CAT (tx << state ());
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", tx << state ());
if (tx)
{
auto f_string = frequency_to_string (tx);
auto params = ("<xcvrfreq:%1>" + f_string + "<SuppressDual:1>Y").arg (f_string.size ());
+ if (UNK == mode)
+ {
+ params += "<SuppressModeChange:1>Y";
+ }
simple_command (("<command:11>CmdQSXSplit<parameters:%1>" + params).arg (params.size ()));
}
else
@@ -136,9 +238,9 @@ void DXLabSuiteCommanderTransceiver::do_tx_frequency (Frequency tx, bool /* rati
update_other_frequency (tx);
}
-void DXLabSuiteCommanderTransceiver::do_mode (MODE m, bool /* rationalise */)
+void DXLabSuiteCommanderTransceiver::do_mode (MODE m)
{
- TRACE_CAT (m << state ());
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", 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 ()));
@@ -168,8 +270,8 @@ void DXLabSuiteCommanderTransceiver::poll ()
}
else
{
- TRACE_CAT_POLL ("get frequency unexpected response");
- throw error {tr ("DX Lab Suite Commander didn't respond correctly polling frequency")};
+ TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "get frequency unexpected response" << reply);
+ throw error {tr ("DX Lab Suite Commander didn't respond correctly polling frequency: ") + reply};
}
if (state ().split ())
@@ -189,8 +291,8 @@ void DXLabSuiteCommanderTransceiver::poll ()
}
else
{
- TRACE_CAT_POLL ("get tx frequency unexpected response");
- throw error {tr ("DX Lab Suite Commander didn't respond correctly polling TX frequency")};
+ TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "get tx frequency unexpected response" << reply);
+ throw error {tr ("DX Lab Suite Commander didn't respond correctly polling TX frequency: ") + reply};
}
}
@@ -208,21 +310,26 @@ void DXLabSuiteCommanderTransceiver::poll ()
}
else
{
- TRACE_CAT_POLL ("unexpected split state" << split);
+ TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "unexpected split state" << split);
throw error {tr ("DX Lab Suite Commander sent an unrecognised split state: ") + split};
}
}
else
{
- TRACE_CAT_POLL ("get split mode unexpected response");
- throw error {tr ("DX Lab Suite Commander didn't respond correctly polling split status")};
+ TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "get split mode unexpected response" << reply);
+ throw error {tr ("DX Lab Suite Commander didn't respond correctly polling split status: ") + reply};
}
- reply = command_with_reply ("<command:11>CmdSendMode<parameters:0>", quiet);
+ get_mode (quiet);
+}
+
+auto DXLabSuiteCommanderTransceiver::get_mode (bool no_debug) -> MODE
+{
+ MODE m {UNK};
+ auto reply = command_with_reply ("<command:11>CmdSendMode<parameters:0>", no_debug);
if (0 == reply.indexOf ("<CmdMode:"))
{
auto mode = reply.mid (reply.indexOf ('>') + 1);
- MODE m {UNK};
if ("AM" == mode)
{
m = AM;
@@ -265,16 +372,17 @@ void DXLabSuiteCommanderTransceiver::poll ()
}
else
{
- TRACE_CAT_POLL ("unexpected mode name" << mode);
+ TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "unexpected mode name" << mode);
throw error {tr ("DX Lab Suite Commander sent an unrecognised mode: \"") + mode + '"'};
}
update_mode (m);
}
else
{
- TRACE_CAT_POLL ("unexpected response");
- throw error {tr ("DX Lab Suite Commander didn't respond correctly polling mode")};
+ TRACE_CAT_POLL ("DXLabSuiteCommanderTransceiver", "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)
@@ -283,12 +391,12 @@ void DXLabSuiteCommanderTransceiver::simple_command (QString const& cmd, bool no
if (!no_debug)
{
- TRACE_CAT (cmd);
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", cmd);
}
if (!write_to_port (cmd))
{
- TRACE_CAT ("failed:" << commander_->errorString ());
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", "failed:" << commander_->errorString ());
throw error {tr ("DX Lab Suite Commander send command failed\n") + commander_->errorString ()};
}
}
@@ -299,7 +407,7 @@ QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd,
if (!write_to_port (cmd))
{
- TRACE_CAT ("failed to send command:" << commander_->errorString ());
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", "failed to send command:" << commander_->errorString ());
throw error {
tr ("DX Lab Suite Commander failed to send command \"%1\": %2\n")
.arg (cmd)
@@ -316,7 +424,7 @@ QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd,
replied = commander_->waitForReadyRead ();
if (!replied && commander_->error () != commander_->SocketTimeoutError)
{
- TRACE_CAT (cmd << "failed to read reply:" << commander_->errorString ());
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", cmd << "failed to read reply:" << commander_->errorString ());
throw error {
tr ("DX Lab Suite Commander send command \"%1\" read reply failed: %2\n")
.arg (cmd)
@@ -327,7 +435,7 @@ QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd,
if (!replied)
{
- TRACE_CAT (cmd << "retries exhausted");
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", cmd << "retries exhausted");
throw error {
tr ("DX Lab Suite Commander retries exhausted sending command \"%1\"")
.arg (cmd)
@@ -343,7 +451,7 @@ QString DXLabSuiteCommanderTransceiver::command_with_reply (QString const& cmd,
if (!no_debug)
{
- TRACE_CAT (cmd << "->" << result);
+ TRACE_CAT ("DXLabSuiteCommanderTransceiver", cmd << "->" << result);
}
return result; // converting raw UTF-8 bytes to QString
@@ -385,7 +493,7 @@ auto DXLabSuiteCommanderTransceiver::string_to_frequency (QString s) const -> Fr
// conversion to Hz
bool ok;
- // auto f = locale_.toDouble (s, &ok); // use when CmdSendFreq and
+ // auto f = locale_.toDouble (s, &ok); // use when CmdSendFreq and
// CmdSendTxFreq reinstated
auto f = QLocale::c ().toDouble (s, &ok); // temporary fix