From d8c881b74737b97afc483b6042304e981d5266b1 Mon Sep 17 00:00:00 2001 From: Hannes Matuschek Date: Sat, 17 Sep 2022 15:47:29 +0200 Subject: [PATCH] Fixed encoding of TyT codeplugs to tolerate M17 contacts/channels. Addresses #251. --- lib/dm1701_codeplug.cc | 16 ++++++++-------- lib/md2017_codeplug.cc | 16 ++++++++-------- lib/md390_codeplug.cc | 16 ++++++++-------- lib/tyt_codeplug.cc | 25 +++++++++++++++++++------ lib/uv390_codeplug.cc | 16 ++++++++-------- 5 files changed, 51 insertions(+), 38 deletions(-) diff --git a/lib/dm1701_codeplug.cc b/lib/dm1701_codeplug.cc index 8ca4d5e3..ff199c73 100644 --- a/lib/dm1701_codeplug.cc +++ b/lib/dm1701_codeplug.cc @@ -577,12 +577,12 @@ DM1701Codeplug::clearChannels() { bool DM1701Codeplug::encodeChannels(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) { - Q_UNUSED(flags); Q_UNUSED(err) + Q_UNUSED(config); Q_UNUSED(flags); Q_UNUSED(err) // Define Channels - for (int i=0; ichannelList()->count()) { - chan.fromChannelObj(config->channelList()->channel(i), ctx); + if (i < ctx.count()) { + chan.fromChannelObj(ctx.get(i+1), ctx); } else { chan.clear(); } @@ -629,12 +629,12 @@ DM1701Codeplug::clearContacts() { bool DM1701Codeplug::encodeContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) { - Q_UNUSED(flags); Q_UNUSED(ctx); Q_UNUSED(err) + Q_UNUSED(flags); Q_UNUSED(config); Q_UNUSED(err) // Encode contacts - for (int i=0; icontacts()->digitalCount()) - cont.fromContactObj(config->contacts()->digitalContact(i)); + if (i < ctx.count()) + cont.fromContactObj(ctx.get(i+1)); else cont.clear(); } diff --git a/lib/md2017_codeplug.cc b/lib/md2017_codeplug.cc index f1e46f88..a22d29a1 100644 --- a/lib/md2017_codeplug.cc +++ b/lib/md2017_codeplug.cc @@ -120,12 +120,12 @@ MD2017Codeplug::clearChannels() { bool MD2017Codeplug::encodeChannels(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) { - Q_UNUSED(flags); Q_UNUSED(err) + Q_UNUSED(config); Q_UNUSED(flags); Q_UNUSED(err) // Define Channels - for (int i=0; ichannelList()->count()) { - chan.fromChannelObj(config->channelList()->channel(i), ctx); + if (i < ctx.count()) { + chan.fromChannelObj(ctx.get(i+1), ctx); } else { chan.clear(); } @@ -172,12 +172,12 @@ MD2017Codeplug::clearContacts() { bool MD2017Codeplug::encodeContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) { - Q_UNUSED(flags); Q_UNUSED(ctx); Q_UNUSED(err) + Q_UNUSED(flags); Q_UNUSED(config); Q_UNUSED(err) // Encode contacts - for (int i=0; icontacts()->digitalCount()) - cont.fromContactObj(config->contacts()->digitalContact(i)); + if (i < ctx.count()) + cont.fromContactObj(ctx.get(i+1)); else cont.clear(); } diff --git a/lib/md390_codeplug.cc b/lib/md390_codeplug.cc index 41cab7f8..5670380a 100644 --- a/lib/md390_codeplug.cc +++ b/lib/md390_codeplug.cc @@ -212,12 +212,12 @@ MD390Codeplug::clearChannels() { bool MD390Codeplug::encodeChannels(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) { - Q_UNUSED(flags); Q_UNUSED(err) + Q_UNUSED(config); Q_UNUSED(flags); Q_UNUSED(err) // Define Channels - for (int i=0; ichannelList()->count()) { - chan.fromChannelObj(config->channelList()->channel(i), ctx); + if (i < ctx.count()) { + chan.fromChannelObj(ctx.get(i+1), ctx); } else { chan.clear(); } @@ -264,12 +264,12 @@ MD390Codeplug::clearContacts() { bool MD390Codeplug::encodeContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) { - Q_UNUSED(flags); Q_UNUSED(ctx); Q_UNUSED(err) + Q_UNUSED(flags); Q_UNUSED(config); Q_UNUSED(err) // Encode contacts - for (int i=0; icontacts()->digitalCount()) - cont.fromContactObj(config->contacts()->digitalContact(i)); + if (i < ctx.count()) + cont.fromContactObj(ctx.get(i+1)); else cont.clear(); } diff --git a/lib/tyt_codeplug.cc b/lib/tyt_codeplug.cc index 4be67693..78c172a0 100644 --- a/lib/tyt_codeplug.cc +++ b/lib/tyt_codeplug.cc @@ -2745,10 +2745,15 @@ TyTCodeplug::index(Config *config, Context &ctx, const ErrorStack &err) const { // Map digital and DTMF contacts for (int i=0, d=0, a=0; icontacts()->count(); i++) { - if (config->contacts()->contact(i)->is()) { - ctx.add(config->contacts()->contact(i)->as(), d+1); d++; - } else if (config->contacts()->contact(i)->is()) { - ctx.add(config->contacts()->contact(i)->as(), a+1); a++; + Contact *contact = config->contacts()->contact(i); + if (contact->is()) { + ctx.add(contact->as(), d+1); d++; + } else if (contact->is()) { + ctx.add(contact->as(), a+1); a++; + } else { + logInfo() << "Cannot index contact '" << contact->name() + << "'. Contact type '" << contact->metaObject()->className() + << "' not supported by or implemented for TyT devices."; } } @@ -2757,8 +2762,16 @@ TyTCodeplug::index(Config *config, Context &ctx, const ErrorStack &err) const { ctx.add(config->rxGroupLists()->list(i), i+1); // Map channels - for (int i=0; ichannelList()->count(); i++) - ctx.add(config->channelList()->channel(i), i+1); + for (int i=0, c=0; ichannelList()->count(); i++) { + Channel *channel = config->channelList()->channel(i); + if (channel->is() || channel->is()) { + ctx.add(channel, c+1); + } else { + logInfo() << "Cannot index channel '" << channel->name() + << "'. Channel type '" << channel->metaObject()->className() + << "' not supported by or implemented for TyT devices."; + } + } // Map zones for (int i=0; izones()->count(); i++) diff --git a/lib/uv390_codeplug.cc b/lib/uv390_codeplug.cc index a86d1263..fb29f2de 100644 --- a/lib/uv390_codeplug.cc +++ b/lib/uv390_codeplug.cc @@ -643,12 +643,12 @@ UV390Codeplug::clearChannels() { bool UV390Codeplug::encodeChannels(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) { - Q_UNUSED(flags); Q_UNUSED(err) + Q_UNUSED(config); Q_UNUSED(flags); Q_UNUSED(err) // Define Channels - for (int i=0; ichannelList()->count()) { - chan.fromChannelObj(config->channelList()->channel(i), ctx); + if (i < ctx.count()) { + chan.fromChannelObj(ctx.get(i+1), ctx); } else { chan.clear(); } @@ -695,12 +695,12 @@ UV390Codeplug::clearContacts() { bool UV390Codeplug::encodeContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) { - Q_UNUSED(flags); Q_UNUSED(ctx); Q_UNUSED(err) + Q_UNUSED(flags); Q_UNUSED(config); Q_UNUSED(err) // Encode contacts - for (int i=0; icontacts()->digitalCount()) - cont.fromContactObj(config->contacts()->digitalContact(i)); + if (i < ctx.count()) + cont.fromContactObj(ctx.get(i+1)); else cont.clear(); }