Turn on Hamlib PTT sharing by default and always apply config overrides

This commit is contained in:
Bill Somerville 2021-02-17 15:45:54 +00:00
parent acdef27892
commit 469b9a5ef5
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
2 changed files with 57 additions and 45 deletions

View File

@ -232,7 +232,11 @@ HamlibTransceiver::HamlibTransceiver (logger_type * logger,
{
set_conf ("ptt_type", "RTS");
}
set_conf ("ptt_share", "1");
}
// do this late to allow any configuration option to be overriden
load_user_settings ();
}
HamlibTransceiver::HamlibTransceiver (logger_type * logger,
@ -260,51 +264,6 @@ HamlibTransceiver::HamlibTransceiver (logger_type * logger,
// rig_->state.obj = this;
//
// user defined Hamlib settings
//
auto settings_file_name = QStandardPaths::locate (QStandardPaths::AppConfigLocation
, "hamlib_settings.json");
if (!settings_file_name.isEmpty ())
{
QFile settings_file {settings_file_name};
qDebug () << "Using Hamlib settings file:" << settings_file_name;
if (settings_file.open (QFile::ReadOnly))
{
QJsonParseError status;
auto settings_doc = QJsonDocument::fromJson (settings_file.readAll (), &status);
if (status.error)
{
throw error {tr ("Hamlib settings file error: %1 at character offset %2")
.arg (status.errorString ()).arg (status.offset)};
}
qDebug () << "Hamlib settings JSON:" << settings_doc.toJson ();
if (!settings_doc.isObject ())
{
throw error {tr ("Hamlib settings file error: top level must be a JSON object")};
}
auto const& settings = settings_doc.object ();
//
// configuration settings
//
auto const& config = settings["config"];
if (!config.isUndefined ())
{
if (!config.isObject ())
{
throw error {tr ("Hamlib settings file error: config must be a JSON object")};
}
auto const& config_list = config.toObject ();
for (auto item = config_list.constBegin (); item != config_list.constEnd (); ++item)
{
set_conf (item.key ().toLocal8Bit ().constData ()
, (*item).toVariant ().toString ().toLocal8Bit ().constData ());
}
}
}
}
if (!is_dummy_)
{
switch (rig_->caps->port_type)
@ -399,11 +358,15 @@ HamlibTransceiver::HamlibTransceiver (logger_type * logger,
{
set_conf ("ptt_type", "RTS");
}
set_conf ("ptt_share", "1");
}
// Make Icom CAT split commands less glitchy
set_conf ("no_xchg", "1");
// do this late to allow any configuration option to be overriden
load_user_settings ();
// would be nice to get events but not supported on Windows and also not on a lot of rigs
// rig_set_freq_callback (rig_.data (), &frequency_change_callback, this);
}
@ -417,6 +380,54 @@ void HamlibTransceiver::error_check (int ret_code, QString const& doing) const
}
}
void HamlibTransceiver::load_user_settings ()
{
//
// user defined Hamlib settings
//
auto settings_file_name = QStandardPaths::locate (QStandardPaths::AppConfigLocation
, "hamlib_settings.json");
if (!settings_file_name.isEmpty ())
{
QFile settings_file {settings_file_name};
qDebug () << "Using Hamlib settings file:" << settings_file_name;
if (settings_file.open (QFile::ReadOnly))
{
QJsonParseError status;
auto settings_doc = QJsonDocument::fromJson (settings_file.readAll (), &status);
if (status.error)
{
throw error {tr ("Hamlib settings file error: %1 at character offset %2")
.arg (status.errorString ()).arg (status.offset)};
}
qDebug () << "Hamlib settings JSON:" << settings_doc.toJson ();
if (!settings_doc.isObject ())
{
throw error {tr ("Hamlib settings file error: top level must be a JSON object")};
}
auto const& settings = settings_doc.object ();
//
// configuration settings
//
auto const& config = settings["config"];
if (!config.isUndefined ())
{
if (!config.isObject ())
{
throw error {tr ("Hamlib settings file error: config must be a JSON object")};
}
auto const& config_list = config.toObject ();
for (auto item = config_list.constBegin (); item != config_list.constEnd (); ++item)
{
set_conf (item.key ().toLocal8Bit ().constData ()
, (*item).toVariant ().toString ().toLocal8Bit ().constData ());
}
}
}
}
}
int HamlibTransceiver::do_start ()
{
CAT_TRACE ("starting: " << rig_->caps->mfg_name

View File

@ -26,6 +26,7 @@ public:
QObject * parent = nullptr);
private:
void load_user_settings ();
int do_start () override;
void do_stop () override;
void do_frequency (Frequency, MODE, bool no_ignore) override;