Skip to content

Commit

Permalink
Renamed RadioID -> DMRRadioID, added DTMFRadioID.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatuschek committed Jan 20, 2022
1 parent 76bc9dd commit ab231d2
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 71 deletions.
8 changes: 4 additions & 4 deletions lib/anytone_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ AnytoneCodeplug::ChannelElement::linkChannelObj(Channel *c, Context &ctx) const
dc->setAPRSObj(ctx.get<GPSSystem>(digitalAPRSSystemIndex()));

// Link radio ID
RadioID *rid = ctx.get<RadioID>(radioIDIndex());
DMRRadioID *rid = ctx.get<DMRRadioID>(radioIDIndex());
if (rid == ctx.config()->radioIDs()->defaultId())
dc->setRadioIdObj(DefaultRadioID::get());
else
Expand Down Expand Up @@ -1352,12 +1352,12 @@ AnytoneCodeplug::RadioIDElement::setName(const QString &name) {
writeASCII(0x0005, name, 16, 0x00);
}

RadioID *
DMRRadioID *
AnytoneCodeplug::RadioIDElement::toRadioID() const {
return new RadioID(name(), number());
return new DMRRadioID(name(), number());
}
bool
AnytoneCodeplug::RadioIDElement::fromRadioID(RadioID *id) {
AnytoneCodeplug::RadioIDElement::fromRadioID(DMRRadioID *id) {
setName(id->name());
setNumber(id->number());
return true;
Expand Down
4 changes: 2 additions & 2 deletions lib/anytone_codeplug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,9 @@ public:
virtual void setName(const QString &name);

/** Encodes the given RadioID. */
virtual bool fromRadioID(RadioID *id);
virtual bool fromRadioID(DMRRadioID *id);
/** Constructs a new radio id. */
virtual RadioID *toRadioID() const;
virtual DMRRadioID *toRadioID() const;
};

/** Represents the base class for the settings element in all AnyTone codeplugs.
Expand Down
6 changes: 3 additions & 3 deletions lib/channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -808,13 +808,13 @@ DigitalChannel::setRadioId(RadioIDReference *ref) {
_radioId.copy(ref);
}

RadioID *
DMRRadioID *
DigitalChannel::radioIdObj() const {
return _radioId.as<RadioID>();
return _radioId.as<DMRRadioID>();
}

bool
DigitalChannel::setRadioIdObj(RadioID *id) {
DigitalChannel::setRadioIdObj(DMRRadioID *id) {
if (! _radioId.set(id))
return false;
emit modified(this);
Expand Down
6 changes: 3 additions & 3 deletions lib/channel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ScanList;
class APRSSystem;
class PositioningSystem;
class RoamingZone;
class RadioID;
class DMRRadioID;


/** The base class of all channels (analog and digital) of a codeplug configuration.
Expand Down Expand Up @@ -407,9 +407,9 @@ public:
/** Sets the reference to the radio ID. */
void setRadioId(RadioIDReference *ref);
/** Returns the radio ID associated with this channel or @c nullptr if the default ID is used. */
RadioID *radioIdObj() const;
DMRRadioID *radioIdObj() const;
/** Associates the given radio ID with this channel. Pass nullptr to set to default ID. */
bool setRadioIdObj(RadioID *id);
bool setRadioIdObj(DMRRadioID *id);

public:
YAML::Node serialize(const Context &context);
Expand Down
2 changes: 1 addition & 1 deletion lib/codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Codeplug::Context::Context(Config *config)
: _config(config), _tables()
{
// Add tables for common elements
addTable(&RadioID::staticMetaObject);
addTable(&DMRRadioID::staticMetaObject);
addTable(&DigitalContact::staticMetaObject);
addTable(&DTMFContact::staticMetaObject);
addTable(&RXGroupList::staticMetaObject);
Expand Down
2 changes: 1 addition & 1 deletion lib/codeplugcontext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CodeplugContext::addRadioId(uint32_t id, int index, const QString &name) {
return true;
}

RadioID *
DMRRadioID *
CodeplugContext::getRadioId(int idx) const {
if (! _radioIDTable.contains(idx))
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion lib/codeplugcontext.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public:
/** Adds the given radio ID at the given index to the list. */
bool addRadioId(uint32_t id, int index, const QString &name="");
/** Maps the given index to the associated radio ID. */
RadioID *getRadioId(int idx) const;
DMRRadioID *getRadioId(int idx) const;

/** Returns @c true, if the given channel index has been defined before. */
bool hasChannel(int index) const;
Expand Down
4 changes: 2 additions & 2 deletions lib/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ Config::link(const YAML::Node &node, const Context &ctx, const ErrorStack &err)
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<RadioID>()) {
RadioID *def = ctx.getObj(id)->as<RadioID>();
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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/configreference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ GPSSystemReference::GPSSystemReference(QObject *parent)
* Implementation of RadioIDReference
* ********************************************************************************************* */
RadioIDReference::RadioIDReference(QObject *parent)
: ConfigObjectReference(RadioID::staticMetaObject, parent)
: ConfigObjectReference(DMRRadioID::staticMetaObject, parent)
{
// pass...
}
Expand Down
2 changes: 1 addition & 1 deletion lib/csvreader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ CSVReader::handleRadioId(const QList<qint64> &ids, qint64 line, qint64 column, Q
return true;
logDebug() << "Got " << ids.count() << " IDs...";
for (int i=0; i<ids.count(); i++) {
RadioID *id = new RadioID("", ids.at(i));
DMRRadioID *id = new DMRRadioID("", ids.at(i));
_config->radioIDs()->add(id);
_radioIDs[i+1] = id;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/csvreader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ protected:
/** Index <-> RoamingZone map */
QMap<int, RoamingZone *> _roamingZones;
/** Index <-> radio ID map */
QMap<int, RadioID *> _radioIDs;
QMap<int, DMRRadioID *> _radioIDs;
};

#endif // CSVREADER_HH
2 changes: 1 addition & 1 deletion lib/d868uv_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ D868UVCodeplug::setRadioID(Context &ctx, const ErrorStack &err) {
continue;
RadioIDElement id(data(ADDR_RADIOIDS + i*RADIOID_SIZE));
logDebug() << "Store id " << id.number() << " at idx " << i << ".";
if (RadioID *rid = id.toRadioID()) {
if (DMRRadioID *rid = id.toRadioID()) {
ctx.config()->radioIDs()->add(rid); ctx.add(rid, i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/radioddity_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ bool
RadioddityCodeplug::GeneralSettingsElement::updateConfig(Config *conf, Context &ctx) {
Q_UNUSED(ctx)
if (! conf->radioIDs()->defaultId()) {
int idx = conf->radioIDs()->add(new RadioID(name(), radioID()));
int idx = conf->radioIDs()->add(new DMRRadioID(name(), radioID()));
conf->radioIDs()->setDefaultId(idx);
} else {
conf->radioIDs()->defaultId()->setName(name());
Expand Down
102 changes: 79 additions & 23 deletions lib/radioid.cc
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
#include "radioid.hh"
#include "logger.hh"
#include "utils.hh"


/* ********************************************************************************************* *
* Implementation of RadioID
* ********************************************************************************************* */
RadioID::RadioID(QObject *parent)
: ConfigObject("id", parent), _number(0)
RadioID::RadioID(const QString &idBase, QObject *parent)
: ConfigObject(idBase, parent)
{
// pass...
}

RadioID::RadioID(const QString &name, uint32_t id, QObject *parent)
: ConfigObject(name, "id", parent), _number(id)
RadioID::RadioID(const QString &name, const QString &idBase, QObject *parent)
: ConfigObject(name, idBase, parent)
{
// pass...
}


/* ********************************************************************************************* *
* Implementation of DMRRadioID
* ********************************************************************************************* */
DMRRadioID::DMRRadioID(QObject *parent)
: RadioID("id", parent), _number(0)
{
// pass...
}

DMRRadioID::DMRRadioID(const QString &name, uint32_t id, QObject *parent)
: RadioID(name, "id", parent), _number(id)
{
// pass...
}

ConfigItem *
RadioID::clone() const {
RadioID *id = new RadioID();
DMRRadioID::clone() const {
DMRRadioID *id = new DMRRadioID();
if (! id->copy(*this)) {
id->deleteLater();
return nullptr;
Expand All @@ -28,21 +45,21 @@ RadioID::clone() const {
}

uint32_t
RadioID::number() const {
DMRRadioID::number() const {
return _number;
}

void
RadioID::setNumber(uint32_t id) {
DMRRadioID::setNumber(uint32_t id) {
if (id == _number)
return;
_number = id;
emit modified();
emit modified(this);
}

YAML::Node
RadioID::serialize(const Context &context) {
YAML::Node node = ConfigObject::serialize(context);
DMRRadioID::serialize(const Context &context) {
YAML::Node node = RadioID::serialize(context);
if (node.IsNull())
return node;
YAML::Node type;
Expand All @@ -52,7 +69,7 @@ RadioID::serialize(const Context &context) {
}

bool
RadioID::parse(const YAML::Node &node, ConfigItem::Context &ctx, const ErrorStack &err) {
DMRRadioID::parse(const YAML::Node &node, ConfigItem::Context &ctx, const ErrorStack &err) {
if (! node)
return false;

Expand All @@ -66,7 +83,7 @@ RadioID::parse(const YAML::Node &node, ConfigItem::Context &ctx, const ErrorStac
}

bool
RadioID::link(const YAML::Node &node, const ConfigItem::Context &ctx, const ErrorStack &err) {
DMRRadioID::link(const YAML::Node &node, const ConfigItem::Context &ctx, const ErrorStack &err) {
if (! node)
return false;

Expand All @@ -86,7 +103,7 @@ RadioID::link(const YAML::Node &node, const ConfigItem::Context &ctx, const Erro
DefaultRadioID *DefaultRadioID::_instance = nullptr;

DefaultRadioID::DefaultRadioID(QObject *parent)
: RadioID(tr("[Default]"),0,parent)
: DMRRadioID(tr("[Default]"),0,parent)
{
// pass...
}
Expand All @@ -99,11 +116,50 @@ DefaultRadioID::get() {
}


/* ********************************************************************************************* *
* Implementation of DTMFRadioID
* ********************************************************************************************* */
DTMFRadioID::DTMFRadioID(QObject *parent)
: RadioID("id", parent)
{
// pass...
}

DTMFRadioID::DTMFRadioID(const QString &name, const QString &number, QObject *parent)
: RadioID(name, "id", parent), _number()
{
setNumber(number.simplified());
}

ConfigItem *
DTMFRadioID::clone() const {
DTMFRadioID *newId = new DTMFRadioID();
if (! newId->copy(*this)) {
newId->deleteLater();
return nullptr;
}
return newId;
}

const QString &
DTMFRadioID::number() const {
return _number;
}
void
DTMFRadioID::setNumber(const QString &number) {
if (! validDTMFNumber(number))
return;
_number = number.simplified();
emit modified(this);
return;
}


/* ********************************************************************************************* *
* Implementation of RadioIDList
* ********************************************************************************************* */
RadioIDList::RadioIDList(QObject *parent)
: ConfigObjectList(RadioID::staticMetaObject, parent), _default(nullptr)
: ConfigObjectList(DMRRadioID::staticMetaObject, parent), _default(nullptr)
{
// pass...
}
Expand All @@ -114,19 +170,19 @@ RadioIDList::clear() {
ConfigObjectList::clear();
}

RadioID *
DMRRadioID *
RadioIDList::getId(int idx) const {
if (ConfigItem *obj = get(idx))
return obj->as<RadioID>();
return obj->as<DMRRadioID>();
return nullptr;
}

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

RadioID *
DMRRadioID *
RadioIDList::find(uint32_t id) const {
for (int i=0; i<count(); i++) {
if (id == getId(i)->number())
Expand All @@ -137,7 +193,7 @@ RadioIDList::find(uint32_t id) const {

int
RadioIDList::add(ConfigObject *obj, int row) {
if ((nullptr == obj) || (! obj->is<RadioID>()))
if ((nullptr == obj) || (! obj->is<DMRRadioID>()))
return -1;

bool was_empty = (0 == count());
Expand All @@ -146,15 +202,15 @@ RadioIDList::add(ConfigObject *obj, int row) {
return idx;
// automatically select first added ID as default
if (was_empty && (nullptr == _default)) {
logDebug() << "Automatically set default radio id to " << obj->as<RadioID>()->name() << ".";
logDebug() << "Automatically set default radio id to " << obj->as<DMRRadioID>()->name() << ".";
setDefaultId(idx);
}
return idx;
}

int
RadioIDList::addId(const QString &name, uint32_t id) {
return add(new RadioID(name, id, this));
return add(new DMRRadioID(name, id, this));
}

bool
Expand Down Expand Up @@ -199,7 +255,7 @@ RadioIDList::allocateChild(const YAML::Node &node, ConfigItem::Context &ctx, con

QString type = QString::fromStdString(node.begin()->first.as<std::string>());
if ("dmr" == type) {
return new RadioID();
return new DMRRadioID();
}

errMsg(err) << node.Mark().line << ":" << node.Mark().column
Expand Down
Loading

0 comments on commit ab231d2

Please sign in to comment.