1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
|
#include "md2017_codeplug.hh"
#include "config.hh"
#include "logger.hh"
#define NUM_CHANNELS 3000
#define ADDR_CHANNELS 0x110000
#define CHANNEL_SIZE 0x000040
#define NUM_CONTACTS 10000
#define ADDR_CONTACTS 0x140000
#define CONTACT_SIZE 0x000024
#define NUM_ZONES 250
#define ADDR_ZONES 0x0149e0
#define ZONE_SIZE 0x000040
#define ADDR_ZONEEXTS 0x031000
#define ZONEEXT_SIZE 0x0000e0
#define NUM_GROUPLISTS 250
#define ADDR_GROUPLISTS 0x00ec20
#define GROUPLIST_SIZE 0x000060
#define NUM_SCANLISTS 250
#define ADDR_SCANLISTS 0x018860
#define SCANLIST_SIZE 0x000068
#define ADDR_TIMESTAMP 0x002000
#define ADDR_SETTINGS 0x002040
#define ADDR_BOOTSETTINGS 0x02f000
#define ADDR_MENUSETTINGS 0x0020f0
#define ADDR_BUTTONSETTINGS 0x002100
#define ADDR_PRIVACY_KEYS 0x0059c0
#define NUM_GPSSYSTEMS 16
#define ADDR_GPSSYSTEMS 0x03ec40
#define GPSSYSTEM_SIZE 0x000010
#define ADDR_EMERGENCY_SETTINGS 0x005a50
#define NUM_EMERGENCY_SYSTEMS 32
#define ADDR_EMERGENCY_SYSTEMS 0x005a60
#define EMERGENCY_SYSTEM_SIZE 0x000028
#define ADDR_VFO_CHANNEL_A 0x02ef00
#define ADDR_VFO_CHANNEL_B 0x02ef40
/* ********************************************************************************************* *
* MD2017Codeplug::ContactElement
* ********************************************************************************************* */
MD2017Codeplug::ContactElement::ContactElement(uint8_t *ptr, size_t size)
: TyTCodeplug::ContactElement(ptr, size)
{
// pass...
}
MD2017Codeplug::ContactElement::ContactElement(uint8_t *ptr)
: TyTCodeplug::ContactElement(ptr)
{
// pass...
}
bool
MD2017Codeplug::ContactElement::isValid() const {
return Codeplug::Element::isValid() && (! name().isEmpty());
}
MD2017Codeplug::MD2017Codeplug(QObject *parent)
: TyTCodeplug(parent)
{
addImage("TYT MD-2017 Codeplug");
image(0).addElement(0x002000, 0x3e000);
image(0).addElement(0x110000, 0x90000);
// Clear entire codeplug
clear();
}
MD2017Codeplug::~MD2017Codeplug() {
// pass...
}
void
MD2017Codeplug::clearTimestamp() {
TimestampElement(data(ADDR_TIMESTAMP)).clear();
}
bool
MD2017Codeplug::encodeTimestamp() {
TimestampElement ts(data(ADDR_TIMESTAMP));
ts.setTimestamp(QDateTime::currentDateTime());
return true;
}
void
MD2017Codeplug::clearGeneralSettings() {
GeneralSettingsElement(data(ADDR_SETTINGS)).clear();
}
bool
MD2017Codeplug::encodeGeneralSettings(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(ctx); Q_UNUSED(err)
return GeneralSettingsElement(data(ADDR_SETTINGS)).fromConfig(config);
}
bool
MD2017Codeplug::decodeGeneralSettings(Config *config, const ErrorStack &err) {
Q_UNUSED(err)
return GeneralSettingsElement(data(ADDR_SETTINGS)).updateConfig(config);
}
void
MD2017Codeplug::clearChannels() {
// Clear channels
for (int i=0; i<NUM_CHANNELS; i++)
ChannelElement(data(ADDR_CHANNELS+i*CHANNEL_SIZE)).clear();
}
bool
MD2017Codeplug::encodeChannels(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(err)
// Define Channels
for (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);
} else {
chan.clear();
}
}
return true;
}
bool
MD2017Codeplug::createChannels(Config *config, Context &ctx, const ErrorStack &err) {
Q_UNUSED(err);
for (int i=0; i<NUM_CHANNELS; i++) {
ChannelElement chan(data(ADDR_CHANNELS+i*CHANNEL_SIZE));
if (! chan.isValid())
continue;
ErrorStack err;
if (Channel *obj = chan.toChannelObj(err)) {
config->channelList()->add(obj);
ctx.add(obj, i+1);
} else {
logWarn() << "Cannot decode channel at index " << i << ":\n"
<< err.format(" ");
continue;
}
}
return true;
}
bool
MD2017Codeplug::linkChannels(Context &ctx, const ErrorStack &err) {
Q_UNUSED(err);
for (int i=0; i<NUM_CHANNELS; i++) {
ChannelElement chan(data(ADDR_CHANNELS+i*CHANNEL_SIZE));
if ((! chan.isValid()) || (! ctx.has<Channel>(i+1)))
continue;
ErrorStack err;
if (! chan.linkChannelObj(ctx.get<Channel>(i+1), ctx, err)) {
logWarn() << "Cannot link channel at index " << i << ":\n"
<< err.format(" ");
continue;
}
}
return true;
}
void
MD2017Codeplug::clearContacts() {
// Clear contacts
for (int i=0; i<NUM_CONTACTS; i++)
ContactElement(data(ADDR_CONTACTS+i*CONTACT_SIZE)).clear();
}
bool
MD2017Codeplug::encodeContacts(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(ctx); Q_UNUSED(err)
// Encode contacts
for (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));
else
cont.clear();
}
return true;
}
bool
MD2017Codeplug::createContacts(Config *config, Context &ctx, const ErrorStack &err) {
for (int i=0; i<NUM_CONTACTS; i++) {
ContactElement cont(data(ADDR_CONTACTS+i*CONTACT_SIZE));
if (! cont.isValid())
continue;
if (DMRContact *obj = cont.toContactObj()) {
config->contacts()->add(obj); ctx.add(obj, i+1);
} else {
errMsg(err) << "Invalid contact at index " << i << ".";
return false;
}
}
return true;
}
void
MD2017Codeplug::clearZones() {
// Clear zones & zone extensions
for (int i=0; i<NUM_ZONES; i++) {
ZoneElement(data(ADDR_ZONES+i*ZONE_SIZE)).clear();
ZoneExtElement(data(ADDR_ZONEEXTS+i*ZONEEXT_SIZE)).clear();
}
}
bool
MD2017Codeplug::encodeZones(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(err)
for (int i=0; i<NUM_ZONES; i++) {
ZoneElement zone(data(ADDR_ZONES + i*ZONE_SIZE));
ZoneExtElement ext(data(ADDR_ZONEEXTS + i*ZONEEXT_SIZE));
zone.clear();
ext.clear();
if (i < config->zones()->count()) {
zone.fromZoneObj(config->zones()->zone(i), ctx);
if (config->zones()->zone(i)->B()->count() || (16 < config->zones()->zone(i)->A()->count()))
ext.fromZoneObj(config->zones()->zone(i), ctx);
}
}
return true;
}
bool
MD2017Codeplug::createZones(Config *config, Context &ctx, const ErrorStack &err) {
for (int i=0; i<NUM_ZONES; i++) {
ZoneElement zone(data(ADDR_ZONES+i*ZONE_SIZE));
if (! zone.isValid())
continue;
if (Zone *obj = zone.toZoneObj()) {
config->zones()->add(obj); ctx.add(obj, i+1);
} else {
errMsg(err) << "Invalid zone at index " << i << ".";
return false;
}
}
return true;
}
bool
MD2017Codeplug::linkZones(Context &ctx, const ErrorStack &err) {
for (int i=0; i<NUM_ZONES; i++) {
ZoneElement zone(data(ADDR_ZONES+i*ZONE_SIZE));
if (! zone.isValid())
continue;
if (! zone.linkZone(ctx.get<Zone>(i+1), ctx)) {
errMsg(err) << "Cannot link zone at index " << i << ".";
return false;
}
ZoneExtElement zoneext(data(ADDR_ZONEEXTS + i*ZONEEXT_SIZE));
if (! zoneext.linkZoneObj(ctx.get<Zone>(i+1), ctx)) {
errMsg(err) << "Cannot link zone extension at index " << i << ".";
return false;
}
}
return true;
}
void
MD2017Codeplug::clearGroupLists() {
for (int i=0; i<NUM_GROUPLISTS; i++)
GroupListElement(data(ADDR_GROUPLISTS+i*GROUPLIST_SIZE)).clear();
}
bool
MD2017Codeplug::encodeGroupLists(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(err)
for (int i=0; i<NUM_GROUPLISTS; i++) {
GroupListElement glist(data(ADDR_GROUPLISTS+i*GROUPLIST_SIZE));
if (i < config->rxGroupLists()->count())
glist.fromGroupListObj(config->rxGroupLists()->list(i), ctx);
else
glist.clear();
}
return true;
}
bool
MD2017Codeplug::createGroupLists(Config *config, Context &ctx, const ErrorStack &err) {
for (int i=0; i<NUM_GROUPLISTS; i++) {
GroupListElement glist(data(ADDR_GROUPLISTS+i*GROUPLIST_SIZE));
if (! glist.isValid())
continue;
if (RXGroupList *obj = glist.toGroupListObj(ctx)) {
config->rxGroupLists()->add(obj); ctx.add(obj, i+1);
} else {
errMsg(err) << "Invalid group list at index " << i << ".";
return false;
}
}
return true;
}
bool
MD2017Codeplug::linkGroupLists(Context &ctx, const ErrorStack &err) {
for (int i=0; i<NUM_GROUPLISTS; i++) {
GroupListElement glist(data(ADDR_GROUPLISTS+i*GROUPLIST_SIZE));
if (! glist.isValid())
continue;
if (! glist.linkGroupListObj(ctx.get<RXGroupList>(i+1), ctx)) {
errMsg(err) << "Cannot link group list at index " << i << ".";
return false;
}
}
return true;
}
void
MD2017Codeplug::clearScanLists() {
// Clear scan lists
for (int i=0; i<NUM_SCANLISTS; i++)
ScanListElement(data(ADDR_SCANLISTS + i*SCANLIST_SIZE)).clear();
}
bool
MD2017Codeplug::encodeScanLists(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(err)
// Define Scanlists
for (int i=0; i<NUM_SCANLISTS; i++) {
ScanListElement scan(data(ADDR_SCANLISTS + i*SCANLIST_SIZE));
if (i < config->scanlists()->count())
scan.fromScanListObj(config->scanlists()->scanlist(i), ctx);
else
scan.clear();
}
return true;
}
bool
MD2017Codeplug::createScanLists(Config *config, Context &ctx, const ErrorStack &err) {
for (int i=0; i<NUM_SCANLISTS; i++) {
ScanListElement scan(data(ADDR_SCANLISTS + i*SCANLIST_SIZE));
if (! scan.isValid())
continue;
if (ScanList *obj = scan.toScanListObj(ctx)) {
config->scanlists()->add(obj); ctx.add(obj, i+1);
} else {
errMsg(err) << "Invalid scanlist at index " << i << ".";
return false;
}
}
return true;
}
bool
MD2017Codeplug::linkScanLists(Context &ctx, const ErrorStack &err) {
for (int i=0; i<NUM_SCANLISTS; i++) {
ScanListElement scan(data(ADDR_SCANLISTS + i*SCANLIST_SIZE));
if (! scan.isValid())
continue;
if (! scan.linkScanListObj(ctx.get<ScanList>(i+1), ctx)) {
errMsg(err) << "Cannot link scan list at index" << i << ".";
return false;
}
}
return true;
}
void
MD2017Codeplug::clearPositioningSystems() {
// Clear GPS systems
for (int i=0; i<NUM_GPSSYSTEMS; i++)
GPSSystemElement(data(ADDR_GPSSYSTEMS+i*GPSSYSTEM_SIZE)).clear();
}
bool
MD2017Codeplug::encodePositioningSystems(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(err)
for (int i=0; i<NUM_GPSSYSTEMS; i++) {
GPSSystemElement gps(data(ADDR_GPSSYSTEMS+i*GPSSYSTEM_SIZE));
if (i < config->posSystems()->gpsCount())
gps.fromGPSSystemObj(config->posSystems()->gpsSystem(i), ctx);
else
gps.clear();
}
return true;
}
bool
MD2017Codeplug::createPositioningSystems(Config *config, Context &ctx, const ErrorStack &err) {
for (int i=0; i<NUM_GPSSYSTEMS; i++) {
GPSSystemElement gps(data(ADDR_GPSSYSTEMS+i*GPSSYSTEM_SIZE));
if (! gps.isValid())
continue;
if (GPSSystem *obj = gps.toGPSSystemObj()) {
config->posSystems()->add(obj); ctx.add(obj, i+1);
} else {
errMsg(err) << "Invalid GPS system at index " << i << ".";
return false;
}
}
return true;
}
bool
MD2017Codeplug::linkPositioningSystems(Context &ctx, const ErrorStack &err) {
for (int i=0; i<NUM_GPSSYSTEMS; i++) {
GPSSystemElement gps(data(ADDR_GPSSYSTEMS+i*GPSSYSTEM_SIZE));
if (! gps.isValid())
continue;
if (! gps.linkGPSSystemObj(ctx.get<GPSSystem>(i+1), ctx)) {
errMsg(err) << "Cannot link GPS system at index " << i << ".";
return false;
}
}
return true;
}
void
MD2017Codeplug::clearBootSettings() {
BootSettingsElement(data(ADDR_BOOTSETTINGS)).clear();
}
void
MD2017Codeplug::clearMenuSettings() {
MenuSettingsElement(data(ADDR_MENUSETTINGS)).clear();
}
void
MD2017Codeplug::clearButtonSettings() {
ButtonSettingsElement(data(ADDR_BUTTONSETTINGS)).clear();
}
bool
MD2017Codeplug::encodeButtonSettings(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(ctx); Q_UNUSED(err)
// Encode settings
return ButtonSettingsElement(data(ADDR_BUTTONSETTINGS)).fromConfig(config);
}
bool
MD2017Codeplug::decodeButtonSetttings(Config *config, const ErrorStack &err) {
Q_UNUSED(err)
return ButtonSettingsElement(data(ADDR_BUTTONSETTINGS)).updateConfig(config);
}
void
MD2017Codeplug::clearPrivacyKeys() {
EncryptionElement(data(ADDR_PRIVACY_KEYS)).clear();
}
bool
MD2017Codeplug::encodePrivacyKeys(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(err);
// First, reset keys
clearPrivacyKeys();
// Get keys
EncryptionElement keys(data(ADDR_PRIVACY_KEYS));
// If there is no encryption extension -> done.
if (! config->commercialExtension())
return true;
// Otherwise encode
return keys.fromCommercialExt(config->commercialExtension(), ctx);
}
bool
MD2017Codeplug::decodePrivacyKeys(Config *config, Context &ctx, const ErrorStack &err) {
Q_UNUSED(config)
// Get keys
EncryptionElement keys(data(ADDR_PRIVACY_KEYS));
// Decode element
if(! keys.updateCommercialExt(ctx)) {
errMsg(err) << "Cannot create encryption keys.";
return false;
}
return true;
}
void
MD2017Codeplug::clearTextMessages() {
MessageBankElement(data(Offset::messages())).clear();
}
bool
MD2017Codeplug::encodeTextMessages(Context &ctx, const Flags &flags, const ErrorStack &err) {
return MessageBankElement(data(Offset::messages())).encode(ctx, flags, err);
}
bool
MD2017Codeplug::decodeTextMessages(Context &ctx, const ErrorStack &err) {
return MessageBankElement(data(Offset::messages())).decode(ctx, err);
}
void
MD2017Codeplug::clearEmergencySystems() {
EmergencySettingsElement(data(ADDR_EMERGENCY_SETTINGS)).clear();
for (int i=0; i<NUM_EMERGENCY_SYSTEMS; i++)
EmergencySystemElement(data(ADDR_EMERGENCY_SYSTEMS + i*EMERGENCY_SYSTEM_SIZE)).clear();
}
void
MD2017Codeplug::clearVFOSettings() {
VFOChannelElement(data(ADDR_VFO_CHANNEL_A)).clear();
VFOChannelElement(data(ADDR_VFO_CHANNEL_B)).clear();
}
|