From 469b9a5ef5ded581859ef4eb9398f9ec6095249e Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Wed, 17 Feb 2021 15:45:54 +0000 Subject: [PATCH] Turn on Hamlib PTT sharing by default and always apply config overrides --- Transceiver/HamlibTransceiver.cpp | 101 +++++++++++++++++------------- Transceiver/HamlibTransceiver.hpp | 1 + 2 files changed, 57 insertions(+), 45 deletions(-) diff --git a/Transceiver/HamlibTransceiver.cpp b/Transceiver/HamlibTransceiver.cpp index 0ae5cd65c..8ebfc8b37 100644 --- a/Transceiver/HamlibTransceiver.cpp +++ b/Transceiver/HamlibTransceiver.cpp @@ -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 diff --git a/Transceiver/HamlibTransceiver.hpp b/Transceiver/HamlibTransceiver.hpp index e1b5dece4..4621896b2 100644 --- a/Transceiver/HamlibTransceiver.hpp +++ b/Transceiver/HamlibTransceiver.hpp @@ -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;