Skip to content

Commit

Permalink
Merge branch 'devel' into gd73
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatuschek committed Oct 9, 2023
2 parents 99516a6 + 2cbfba6 commit bf9a2bd
Show file tree
Hide file tree
Showing 25 changed files with 259 additions and 130 deletions.
2 changes: 0 additions & 2 deletions cli/writecodeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ int writeCodeplug(QCommandLineParser &parser, QCoreApplication &app) {
logDebug() << "Start upload to " << radio->name() << ".";
if (! radio->startUpload(intermediate, true, flags, err)) {
logError() << "Codeplug upload error: " << err.format();
delete intermediate;
return -1;
}
delete intermediate;

if (Radio::StatusError == radio->status()) {
logError() << "Codeplug upload error: " << err.format();
Expand Down
6 changes: 3 additions & 3 deletions lib/anytone_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ AnytoneCodeplug::ChannelElement::linkChannelObj(Channel *c, Context &ctx) const

// Link radio ID
DMRRadioID *rid = ctx.get<DMRRadioID>(radioIDIndex());
if (rid == ctx.config()->radioIDs()->defaultId())
if (rid == ctx.config()->settings()->defaultIdRef()->as<DMRRadioID>())
dc->setRadioIdObj(DefaultRadioID::get());
else
dc->setRadioIdObj(rid);
Expand Down Expand Up @@ -898,11 +898,11 @@ AnytoneCodeplug::ChannelElement::fromChannelObj(const Channel *c, Context &ctx)
setGroupListIndex(ctx.index(dc->groupListObj()));
// Set radio ID
if ((nullptr == dc->radioIdObj()) || (DefaultRadioID::get() == dc->radioIdObj())) {
if (nullptr == ctx.config()->radioIDs()->defaultId()) {
if (nullptr == ctx.config()->settings()->defaultIdRef()->as<DMRRadioID>()) {
logWarn() << "No default radio ID set: using index 0.";
setRadioIDIndex(0);
} else {
setRadioIDIndex(ctx.index(ctx.config()->radioIDs()->defaultId()));
setRadioIDIndex(ctx.index(ctx.config()->settings()->defaultIdRef()->as<DMRRadioID>()));
}
} else {
setRadioIDIndex(ctx.index(dc->radioIdObj()));
Expand Down
6 changes: 6 additions & 0 deletions lib/anytone_radio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ AnytoneRadio::startUpload(Config *config, bool blocking, const Codeplug::Flags &
if (StatusIdle != _task)
return false;

if (_config)
delete _config;

// Cannot upload null-pointer
if (nullptr == (_config = config))
return false;
_config->setParent(this);

_task = StatusUpload;
_codeplugFlags = flags;
Expand All @@ -88,6 +92,8 @@ AnytoneRadio::startUpload(Config *config, bool blocking, const Codeplug::Flags &
// If non-blocking -> move device to this thread
if (_dev && _dev->isOpen())
_dev->moveToThread(this);
_config->moveToThread(this);

start();

return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/anytone_radio.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected:
/** If @c true, the codeplug on the radio gets updated upon upload. If @c false, it gets
* overridden. */
Codeplug::Flags _codeplugFlags;
/** The generic configuration. */
/** Owns the generic configuration. */
Config *_config;
/** A weak reference to the user-database. */
UserDatabase *_userDB;
Expand Down
26 changes: 3 additions & 23 deletions lib/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ Config::populate(YAML::Node &node, const Context &context, const ErrorStack &err
if ((node["settings"]= _settings->serialize(context, err)).IsNull())
return false;

if (_radioIDs->defaultId() && context.contains(_radioIDs->defaultId()))
node["settings"]["defaultID"] = context.getId(_radioIDs->defaultId()).toStdString();

if ((node["radioIDs"] = _radioIDs->serialize(context, err)).IsNull())
return false;

Expand Down Expand Up @@ -409,29 +406,12 @@ bool
Config::link(const YAML::Node &node, const Context &ctx, const ErrorStack &err) {
// radio IDs must be linked before settings, as they may refer to the default DMR ID

if (! _radioIDs->link(node["radioIDs"], ctx, err))
return false;

if (! _settings->link(node["settings"], ctx, err))
if (node["radioIDs"] && (! _radioIDs->link(node["radioIDs"], ctx, err)))
return false;

// Link default radio ID separately as it is not a property of the settings but defined there
if (node["settings"] && node["settings"]["defaultID"] && node["settings"]["defaultID"].IsScalar()) {
YAML::Node defIDNode = node["settings"]["defaultID"];
QString id = QString::fromStdString(defIDNode.as<std::string>());
if (ctx.contains(id) && ctx.getObj(id)->is<DMRRadioID>()) {
DMRRadioID *def = ctx.getObj(id)->as<DMRRadioID>();
radioIDs()->setDefaultId(radioIDs()->indexOf(def));
logDebug() << "Set default radio ID to '" << def->name() << "'.";
} else {
errMsg(err) << defIDNode.Mark().line << ":" << defIDNode.Mark().column
<< "Default radio ID '" << id << " does not refer to a radio ID.";
if (node["settings"])
if (!_settings->link(node["settings"], ctx, err))
return false;
}
} else if (radioIDs()->count()) {
// If no default is set, use first one.
radioIDs()->setDefaultId(0);
}

if (node["contacts"] && (! _contacts->link(node["contacts"], ctx, err)))
return false;
Expand Down
4 changes: 2 additions & 2 deletions lib/csvreader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1766,8 +1766,8 @@ CSVReader::handleRadioName(const QString &name, qint64 line, qint64 column, QStr
Q_UNUSED(column);
Q_UNUSED(errorMessage);

if (_link && _config->radioIDs()->defaultId()) {
_config->radioIDs()->defaultId()->setName(name);
if (_link && (!_config->settings()->defaultIdRef()->isNull())) {
_config->settings()->defaultIdRef()->as<DMRRadioID>()->setName(name);
}
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/opengd77.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ OpenGD77::startUpload(Config *config, bool blocking, const Codeplug::Flags &flag
return false;
}

if (_config)
delete _config;

if (! (_config = config)) {
logError() << "Cannot upload to radio, no config given.";
return false;
}
_config->setParent(this);

_task = StatusUpload;
_errorStack = err;
Expand Down
4 changes: 4 additions & 0 deletions lib/openrtx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ OpenRTX::startUpload(Config *config, bool blocking, const Codeplug::Flags &flags
return false;
}

if (_config)
delete _config;

if (! (_config = config)) {
errMsg(err) << "Cannot upload to radio, no config given.";
return false;
}
_config->setParent(this);

_task = StatusUpload;
if (blocking) {
Expand Down
4 changes: 2 additions & 2 deletions lib/openrtx_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ OpenRTXCodeplug::index(Config *config, Context &ctx, const ErrorStack &err) cons
bool
OpenRTXCodeplug::encode(Config *config, const Flags &flags, const ErrorStack &err) {
// Check if default DMR id is set.
if (nullptr == config->radioIDs()->defaultId()) {
if (nullptr == config->settings()->defaultIdRef()) {
errMsg(err) << "Cannot encode TyT codeplug: No default radio ID specified.";
return false;
}
Expand All @@ -992,7 +992,7 @@ bool
OpenRTXCodeplug::encodeElements(const Flags &flags, Context &ctx, const ErrorStack &err) {
HeaderElement header(data(0));
header.clear();
header.setAuthor(ctx.config()->radioIDs()->defaultId()->name());
header.setAuthor(ctx.config()->settings()->defaultId()->name());
header.setDescription("Encoded by qdmr v" VERSION_STRING);

// Define Contacts
Expand Down
16 changes: 8 additions & 8 deletions lib/radioddity_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1700,9 +1700,9 @@ RadioddityCodeplug::GeneralSettingsElement::clearProgPassword() {

bool
RadioddityCodeplug::GeneralSettingsElement::fromConfig(const Config *conf, Context &ctx) {
if (conf->radioIDs()->defaultId()) {
setName(conf->radioIDs()->defaultId()->name());
setRadioID(conf->radioIDs()->defaultId()->number());
if (! conf->settings()->defaultIdRef()->isNull()) {
setName(conf->settings()->defaultIdRef()->as<DMRRadioID>()->name());
setRadioID(conf->settings()->defaultIdRef()->as<DMRRadioID>()->number());
} else if (conf->radioIDs()->count()) {
setName(conf->radioIDs()->getId(0)->name());
setRadioID(conf->radioIDs()->getId(0)->number());
Expand Down Expand Up @@ -1756,12 +1756,12 @@ RadioddityCodeplug::GeneralSettingsElement::fromConfig(const Config *conf, Conte
bool
RadioddityCodeplug::GeneralSettingsElement::updateConfig(Config *conf, Context &ctx) {
Q_UNUSED(ctx)
if (! conf->radioIDs()->defaultId()) {
if (conf->settings()->defaultIdRef()->isNull()) {
int idx = conf->radioIDs()->add(new DMRRadioID(name(), radioID()));
conf->radioIDs()->setDefaultId(idx);
conf->settings()->defaultIdRef()->set(conf->radioIDs()->getId(idx));
} else {
conf->radioIDs()->defaultId()->setName(name());
conf->radioIDs()->defaultId()->setNumber(radioID());
conf->settings()->defaultIdRef()->as<DMRRadioID>()->setName(name());
conf->settings()->defaultIdRef()->as<DMRRadioID>()->setNumber(radioID());
}
conf->settings()->setVOX(voxSensitivity());
// There is no global squelch settings either, so set it to 1
Expand Down Expand Up @@ -2689,7 +2689,7 @@ RadioddityCodeplug::preprocess(Config *config, const ErrorStack &err) const {
bool
RadioddityCodeplug::encode(Config *config, const Flags &flags, const ErrorStack &err) {
// Check if default DMR id is set.
if (nullptr == config->radioIDs()->defaultId()) {
if (config->settings()->defaultIdRef()->isNull()) {
errMsg(err) << "No default radio ID specified.";
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/radioddity_radio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ RadioddityRadio::startUpload(Config *config, bool blocking, const Codeplug::Flag
if (StatusIdle != _task)
return false;

if (_config)
delete _config;

if (! (_config = config))
return false;
_config->setParent(this);

_task = StatusUpload;
_codeplugFlags = flags;
Expand Down
46 changes: 6 additions & 40 deletions lib/radioid.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "radioid.hh"
#include "logger.hh"
#include "utils.hh"
#include "config.hh"
#include "radiosettings.hh"


/* ********************************************************************************************* *
Expand Down Expand Up @@ -161,14 +163,13 @@ DTMFRadioID::setNumber(const QString &number) {
* Implementation of RadioIDList
* ********************************************************************************************* */
RadioIDList::RadioIDList(QObject *parent)
: ConfigObjectList(DMRRadioID::staticMetaObject, parent), _default(nullptr)
: ConfigObjectList(DMRRadioID::staticMetaObject, parent)
{
// pass...
}

void
RadioIDList::clear() {
setDefaultId(-1);
ConfigObjectList::clear();
}

Expand All @@ -179,11 +180,6 @@ RadioIDList::getId(int idx) const {
return nullptr;
}

DMRRadioID *
RadioIDList::defaultId() const {
return _default;
}

DMRRadioID *
RadioIDList::find(uint32_t id) const {
for (int i=0; i<count(); i++) {
Expand All @@ -198,15 +194,10 @@ RadioIDList::add(ConfigObject *obj, int row, bool unique) {
if ((nullptr == obj) || (! obj->is<DMRRadioID>()))
return -1;

bool was_empty = (0 == count());
int idx = ConfigObjectList::add(obj, row, unique);
if (0 > idx)
return idx;
// automatically select first added ID as default
if (was_empty && (nullptr == _default)) {
logDebug() << "Automatically set default radio id to " << obj->as<DMRRadioID>()->name() << ".";
setDefaultId(idx);
}
if (parent() && obj->is<DMRRadioID>() && qobject_cast<Config*>(parent())->settings()->defaultIdRef()->isNull())
qobject_cast<Config*>(parent())->settings()->setDefaultId(obj->as<DMRRadioID>());

return idx;
}

Expand All @@ -215,27 +206,6 @@ RadioIDList::addId(const QString &name, uint32_t id) {
return add(new DMRRadioID(name, id, this));
}

bool
RadioIDList::setDefaultId(int idx) {
if (_default) {
disconnect(_default, SIGNAL(destroyed(QObject*)), this, SLOT(onDefaultIdDeleted()));
if (0 <= indexOf(_default))
emit elementModified(indexOf(_default));
}

if (0 > idx) {
_default = nullptr;
return true;
}

_default = getId(idx);
if (nullptr == _default)
return false;
connect(_default, SIGNAL(destroyed(QObject*)), this, SLOT(onDefaultIdDeleted()));
emit elementModified(idx);
return true;
}

bool
RadioIDList::delId(uint32_t id) {
return del(find(id));
Expand Down Expand Up @@ -266,7 +236,3 @@ RadioIDList::allocateChild(const YAML::Node &node, ConfigItem::Context &ctx, con
return nullptr;
}

void
RadioIDList::onDefaultIdDeleted() {
_default = nullptr;
}
18 changes: 3 additions & 15 deletions lib/radioid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "configobject.hh"

class DMRRadioIDReference;


/** Abstract base class for all radio IDs.
*
Expand Down Expand Up @@ -118,14 +120,12 @@ protected:


/** Represents the list of configured DMR IDs (radio IDs) within the abstract config.
* There must always be at least one valid DMR ID. The first (index 0) ID is always the default
* DMR ID of the radio.
*
* @ingroup conf */
class RadioIDList: public ConfigObjectList
{
Q_OBJECT


public:
/** Constructor. */
explicit RadioIDList(QObject *parent=nullptr);
Expand All @@ -134,10 +134,6 @@ public:

/** Returns the radio ID at the given index. */
DMRRadioID *getId(int idx) const;
/** Returns the current default ID for the radio. */
DMRRadioID * defaultId() const;
/** Sets the default DMR ID. Pass idx=-1 to clear default ID. */
bool setDefaultId(int idx);
/** Searches the DMR ID object associated with the given DMR ID. */
DMRRadioID *find(uint32_t id) const;

Expand All @@ -150,14 +146,6 @@ public:

public:
ConfigItem *allocateChild(const YAML::Node &node, ConfigItem::Context &ctx, const ErrorStack &err=ErrorStack());

protected slots:
/** Gets call whenever the default DMR ID gets deleted. */
void onDefaultIdDeleted();

protected:
/** Holds a weak reference to the default DMR radio ID. */
DMRRadioID *_default;
};


Expand Down
19 changes: 18 additions & 1 deletion lib/radiosettings.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "radiosettings.hh"
#include "radioid.hh"

RadioSettings::RadioSettings(QObject *parent)
: ConfigItem(parent), _introLine1(""), _introLine2(""), _micLevel(3), _speech(false),
_squelch(1), _power(Channel::Power::High), _vox(0), _transmitTimeOut(0), _tytExtension(nullptr),
_squelch(1), _power(Channel::Power::High), _vox(0), _transmitTimeOut(0),
_defaultId(new DMRRadioIDReference(this)), _tytExtension(nullptr),
_radioddityExtension(nullptr), _anytoneExtension(nullptr)
{
// pass
Expand Down Expand Up @@ -141,6 +143,21 @@ RadioSettings::disableTOT() {
setTOT(0);
}

DMRRadioIDReference *
RadioSettings::defaultIdRef() const {
return _defaultId;
}
DMRRadioID *
RadioSettings::defaultId() const {
if (_defaultId->isNull())
return nullptr;
return _defaultId->as<DMRRadioID>();
}
void
RadioSettings::setDefaultId(DMRRadioID *id) {
_defaultId->set(id);
}

TyTSettingsExtension *
RadioSettings::tytExtension() const {
return _tytExtension;
Expand Down
Loading

0 comments on commit bf9a2bd

Please sign in to comment.