Skip to content

Commit

Permalink
Fixed encoding of TyT codeplugs to tolerate M17 contacts/channels. Ad…
Browse files Browse the repository at this point in the history
…dresses hmatuschek#251.
  • Loading branch information
hmatuschek committed Sep 17, 2022
1 parent 408a934 commit d8c881b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 38 deletions.
16 changes: 8 additions & 8 deletions lib/dm1701_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<NUM_CHANNELS; i++) {
for (unsigned int i=0; i<NUM_CHANNELS; i++) {
ChannelElement chan(data(ADDR_CHANNELS+i*CHANNEL_SIZE));
if (i < config->channelList()->count()) {
chan.fromChannelObj(config->channelList()->channel(i), ctx);
if (i < ctx.count<Channel>()) {
chan.fromChannelObj(ctx.get<Channel>(i+1), ctx);
} else {
chan.clear();
}
Expand Down Expand Up @@ -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; i<NUM_CONTACTS; i++) {
for (unsigned int i=0; i<NUM_CONTACTS; i++) {
ContactElement cont(data(ADDR_CONTACTS+i*CONTACT_SIZE));
if (i < config->contacts()->digitalCount())
cont.fromContactObj(config->contacts()->digitalContact(i));
if (i < ctx.count<DMRContact>())
cont.fromContactObj(ctx.get<DMRContact>(i+1));
else
cont.clear();
}
Expand Down
16 changes: 8 additions & 8 deletions lib/md2017_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<NUM_CHANNELS; i++) {
for (unsigned int i=0; i<NUM_CHANNELS; i++) {
ChannelElement chan(data(ADDR_CHANNELS+i*CHANNEL_SIZE));
if (i < config->channelList()->count()) {
chan.fromChannelObj(config->channelList()->channel(i), ctx);
if (i < ctx.count<Channel>()) {
chan.fromChannelObj(ctx.get<Channel>(i+1), ctx);
} else {
chan.clear();
}
Expand Down Expand Up @@ -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; i<NUM_CONTACTS; i++) {
for (unsigned int i=0; i<NUM_CONTACTS; i++) {
ContactElement cont(data(ADDR_CONTACTS+i*CONTACT_SIZE));
if (i < config->contacts()->digitalCount())
cont.fromContactObj(config->contacts()->digitalContact(i));
if (i < ctx.count<DMRContact>())
cont.fromContactObj(ctx.get<DMRContact>(i+1));
else
cont.clear();
}
Expand Down
16 changes: 8 additions & 8 deletions lib/md390_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<NUM_CHANNELS; i++) {
for (unsigned int i=0; i<NUM_CHANNELS; i++) {
ChannelElement chan(data(ADDR_CHANNELS+i*CHANNEL_SIZE));
if (i < config->channelList()->count()) {
chan.fromChannelObj(config->channelList()->channel(i), ctx);
if (i < ctx.count<Channel>()) {
chan.fromChannelObj(ctx.get<Channel>(i+1), ctx);
} else {
chan.clear();
}
Expand Down Expand Up @@ -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; i<NUM_CONTACTS; i++) {
for (unsigned int i=0; i<NUM_CONTACTS; i++) {
ContactElement cont(data(ADDR_CONTACTS+i*CONTACT_SIZE));
if (i < config->contacts()->digitalCount())
cont.fromContactObj(config->contacts()->digitalContact(i));
if (i < ctx.count<DMRContact>())
cont.fromContactObj(ctx.get<DMRContact>(i+1));
else
cont.clear();
}
Expand Down
25 changes: 19 additions & 6 deletions lib/tyt_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<config->contacts()->count(); i++) {
if (config->contacts()->contact(i)->is<DMRContact>()) {
ctx.add(config->contacts()->contact(i)->as<DMRContact>(), d+1); d++;
} else if (config->contacts()->contact(i)->is<DTMFContact>()) {
ctx.add(config->contacts()->contact(i)->as<DTMFContact>(), a+1); a++;
Contact *contact = config->contacts()->contact(i);
if (contact->is<DMRContact>()) {
ctx.add(contact->as<DMRContact>(), d+1); d++;
} else if (contact->is<DTMFContact>()) {
ctx.add(contact->as<DTMFContact>(), a+1); a++;
} else {
logInfo() << "Cannot index contact '" << contact->name()
<< "'. Contact type '" << contact->metaObject()->className()
<< "' not supported by or implemented for TyT devices.";
}
}

Expand All @@ -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; i<config->channelList()->count(); i++)
ctx.add(config->channelList()->channel(i), i+1);
for (int i=0, c=0; i<config->channelList()->count(); i++) {
Channel *channel = config->channelList()->channel(i);
if (channel->is<FMChannel>() || channel->is<DMRChannel>()) {
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; i<config->zones()->count(); i++)
Expand Down
16 changes: 8 additions & 8 deletions lib/uv390_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<NUM_CHANNELS; i++) {
for (unsigned int i=0; i<NUM_CHANNELS; i++) {
ChannelElement chan(data(ADDR_CHANNELS+i*CHANNEL_SIZE));
if (i < config->channelList()->count()) {
chan.fromChannelObj(config->channelList()->channel(i), ctx);
if (i < ctx.count<Channel>()) {
chan.fromChannelObj(ctx.get<Channel>(i+1), ctx);
} else {
chan.clear();
}
Expand Down Expand Up @@ -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; i<NUM_CONTACTS; i++) {
for (unsigned int i=0; i<NUM_CONTACTS; i++) {
ContactElement cont(data(ADDR_CONTACTS+i*CONTACT_SIZE));
if (i < config->contacts()->digitalCount())
cont.fromContactObj(config->contacts()->digitalContact(i));
if (i < ctx.count<DMRContact>())
cont.fromContactObj(ctx.get<DMRContact>(i+1));
else
cont.clear();
}
Expand Down

0 comments on commit d8c881b

Please sign in to comment.