From 1678ccf9b9b2dfbbd4f35b425a5ee409b9b9e14f Mon Sep 17 00:00:00 2001 From: Hannes Matuschek Date: Sat, 17 Sep 2022 16:28:50 +0200 Subject: [PATCH] Fixed OpenRTX codeplug generation to handle M17 contacts. Addresses #251. --- lib/openrtx_codeplug.cc | 62 +++++++++++++++++++++++++++-------------- lib/openrtx_codeplug.hh | 2 +- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/lib/openrtx_codeplug.cc b/lib/openrtx_codeplug.cc index d4a85c98..5462b8e2 100644 --- a/lib/openrtx_codeplug.cc +++ b/lib/openrtx_codeplug.cc @@ -805,14 +805,28 @@ OpenRTXCodeplug::ContactElement::toContactObj(Context &ctx, const ErrorStack &er return contact; } -void -OpenRTXCodeplug::ContactElement::fromContactObj(const DMRContact *cont, Context &ctx, const ErrorStack &err) { - Q_UNUSED(ctx); Q_UNUSED(err) - setMode(Mode_DMR); +bool +OpenRTXCodeplug::ContactElement::fromContactObj(const DigitalContact *cont, Context &ctx, const ErrorStack &err) { + Q_UNUSED(ctx); Q_UNUSED(err); + setName(cont->name()); - setDMRId(cont->number()); - setDMRContactType(cont->type()); enableDMRRing(cont->ring()); + + if (cont->is()) { + const DMRContact *dmr = cont->as(); + setMode(Mode_DMR); + setDMRId(dmr->number()); + setDMRContactType(dmr->type()); + } else if (cont->is()) { + const M17Contact *m17 = cont->as(); + setM17Call(m17->call()); + } else { + errMsg(err) << "Cannot encode contact '" << cont->name() << "': Contact type '" + << cont->metaObject()->className() << "' not supported by OpenRTX firmware."; + return false; + } + + return true; } @@ -955,15 +969,22 @@ OpenRTXCodeplug::index(Config *config, Context &ctx, const ErrorStack &err) cons // All indices as 1-based. That is, the first channel gets index 1 etc. // Map DMR contacts - for (int i=0, d=0; icontacts()->count(); i++) { - if (config->contacts()->contact(i)->is()) { - ctx.add(config->contacts()->contact(i)->as(), d+1); d++; + for (int i=0, c=0; icontacts()->count(); i++) { + Contact *contact = config->contacts()->contact(i); + if (contact->is() || contact->is()) { + ctx.add(contact, c+1); c++; + } else { + logInfo() << "Cannot index contact '" << contact->name() + << "'. Contact type '" << contact->metaObject()->className() + << "' not supported by or implemented for OpenRTX devices."; } } // Map channels - for (int i=0; ichannelList()->count(); i++) - ctx.add(config->channelList()->channel(i), i+1); + for (int i=0; ichannelList()->count(); i++) { + Channel *channel = config->channelList()->channel(i); + ctx.add(channel, i+1); + } // Map zones for (int i=0; izones()->count(); i++) @@ -976,7 +997,7 @@ bool OpenRTXCodeplug::encode(Config *config, const Flags &flags, const ErrorStack &err) { // Check if default DMR id is set. if (nullptr == config->radioIDs()->defaultId()) { - errMsg(err) << "Cannot encode TyT codeplug: No default radio ID specified."; + errMsg(err) << "Cannot encode OpenRTX codeplug: No default radio ID specified."; return false; } @@ -1067,20 +1088,19 @@ OpenRTXCodeplug::offsetContact(unsigned int n) { bool OpenRTXCodeplug::encodeContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) { - Q_UNUSED(flags) + Q_UNUSED(config); Q_UNUSED(flags) /// @todo Limit number of contacts. - unsigned int numContacts = ctx.count(); + unsigned int numContacts = ctx.count(); HeaderElement(data(0x0000)).setContactCount(numContacts); image(0).addElement(offsetContact(0), numContacts*ContactSize); - for (int i=0,c=0; icontacts()->count(); i++) { - if (! config->contacts()->contact(i)->is()) - continue; - ContactElement contact(data(offsetContact(c))); - contact.fromContactObj( - config->contacts()->contact(i)->as(), ctx, err); - c++; + for (unsigned int i=0; i(); i++) { + ContactElement contact(data(offsetContact(i))); + if (! contact.fromContactObj(ctx.get(i+1), ctx, err)) { + errMsg(err) << "Cannot encode contact '" << ctx.get(i+1)->name() <<"'."; + return false; + } } return true; diff --git a/lib/openrtx_codeplug.hh b/lib/openrtx_codeplug.hh index 78ef62af..9cdb4d1e 100644 --- a/lib/openrtx_codeplug.hh +++ b/lib/openrtx_codeplug.hh @@ -359,7 +359,7 @@ public: /** Constructs a @c DigitalContact instance from this codeplug contact. */ virtual DMRContact *toContactObj(Context &ctx, const ErrorStack &err=ErrorStack()) const; /** Resets this codeplug contact from the given @c DigitalContact. */ - virtual void fromContactObj(const DMRContact *obj, Context &ctx, const ErrorStack &err=ErrorStack()); + virtual bool fromContactObj(const DigitalContact *obj, Context &ctx, const ErrorStack &err=ErrorStack()); protected: /** Just holds the offsets within the codeplug. */