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 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
|
#include "uv390_codeplug.hh"
#include "logger.hh"
#include "config.hh"
#include "tyt_extensions.hh"
#include <QTimeZone>
#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 SETTINGS_SIZE 0x0000b0
#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
/* ******************************************************************************************** *
* Implementation of UV390Codeplug::ChannelElement
* ******************************************************************************************** */
UV390Codeplug::ChannelElement::ChannelElement(uint8_t *ptr, size_t size)
: TyTCodeplug::ChannelElement(ptr, size)
{
// pass...
}
UV390Codeplug::ChannelElement::ChannelElement(uint8_t *ptr)
: TyTCodeplug::ChannelElement(ptr, size())
{
// pass...
}
void
UV390Codeplug::ChannelElement::clear() {
TyTCodeplug::ChannelElement::clear();
enableTalkaround(false);
clearBit(5,0);
setInCallCriteria(TyTChannelExtension::InCallCriterion::Always);
setTurnOffFreq(TyTChannelExtension::KillTone::Off);
setSquelch(1);
setPower(Channel::Power::High);
enableAllowInterrupt(true);
enableDualCapacityDirectMode(false);
enableDCDMLeader(true);
enablePrivacySwitch(false);
}
bool
UV390Codeplug::ChannelElement::talkaround() const {
return getBit(Offset::talkaround());
}
void
UV390Codeplug::ChannelElement::enableTalkaround(bool enable) {
setBit(Offset::talkaround(), enable);
}
bool
UV390Codeplug::ChannelElement::privacySwitch() const {
return getBit(Offset::privacySwitch());
}
void
UV390Codeplug::ChannelElement::enablePrivacySwitch(bool enable) {
setBit(Offset::privacySwitch(), enable);
}
void
UV390Codeplug::ChannelElement::setPrivacyType(PrivacyType type) {
enablePrivacySwitch(PrivacyType::PRIV_NONE != type);
TyTCodeplug::ChannelElement::setPrivacyType(type);
}
TyTChannelExtension::InCallCriterion UV390Codeplug::ChannelElement::inCallCriteria() const {
return TyTChannelExtension::InCallCriterion(getUInt2(Offset::inCallCriteria()));
}
void
UV390Codeplug::ChannelElement::setInCallCriteria(TyTChannelExtension::InCallCriterion crit) {
setUInt2(Offset::inCallCriteria(), uint8_t(crit));
}
TyTChannelExtension::KillTone UV390Codeplug::ChannelElement::turnOffFreq() const {
return TyTChannelExtension::KillTone(getUInt2(Offset::turnOffFreq()));
}
void
UV390Codeplug::ChannelElement::setTurnOffFreq(TyTChannelExtension::KillTone freq) {
setUInt2(Offset::turnOffFreq(), uint8_t(freq));
}
unsigned
UV390Codeplug::ChannelElement::squelch() const {
return getUInt8(Offset::squelch());
}
void
UV390Codeplug::ChannelElement::setSquelch(unsigned value) {
value = std::min(unsigned(10), value);
return setUInt8(Offset::squelch(), value);
}
Channel::Power
UV390Codeplug::ChannelElement::power() const {
switch (getUInt2(Offset::power())) {
case 0: return Channel::Power::Low;
case 2: return Channel::Power::Mid;
case 3: return Channel::Power::High;
default: break;
}
return Channel::Power::Low;
}
void
UV390Codeplug::ChannelElement::setPower(Channel::Power pwr) {
switch (pwr) {
case Channel::Power::Min:
case Channel::Power::Low:
setUInt2(Offset::power(), 0);
break;
case Channel::Power::Mid:
setUInt2(Offset::power(), 2);
break;
case Channel::Power::High:
case Channel::Power::Max:
setUInt2(Offset::power(), 3);
}
}
bool
UV390Codeplug::ChannelElement::allowInterrupt() const {
return !getBit(Offset::allowInterrupt());
}
void
UV390Codeplug::ChannelElement::enableAllowInterrupt(bool enable) {
setBit(Offset::allowInterrupt(), !enable);
}
bool
UV390Codeplug::ChannelElement::dualCapacityDirectMode() const {
return !getBit(Offset::dualCapacityDirectMode());
}
void
UV390Codeplug::ChannelElement::enableDualCapacityDirectMode(bool enable) {
setBit(Offset::dualCapacityDirectMode(), !enable);
}
bool
UV390Codeplug::ChannelElement::dcdmLeader() const {
return !getBit(Offset::dcdmLeader());
}
void
UV390Codeplug::ChannelElement::enableDCDMLeader(bool enable) {
setBit(Offset::dcdmLeader(), !enable);
}
Channel *
UV390Codeplug::ChannelElement::toChannelObj(const ErrorStack &err) const {
if (! isValid()) {
errMsg(err) << "Cannot decode invalid channel.";
return nullptr;
}
Channel *ch = TyTCodeplug::ChannelElement::toChannelObj(err);
if (nullptr == ch) {
errMsg(err) << "Cannot decode base TyT channel element.";
return nullptr;
}
// decode squelch setting
if (ch->is<FMChannel>()) {
FMChannel *ach = ch->as<FMChannel>();
ach->setSquelch(squelch());
}
// Common settings
ch->setPower(power());
// assemble extension
if (TyTChannelExtension *ex = ch->tytChannelExtension()) {
ex->setKillTone(turnOffFreq());
ex->setInCallCriterion(inCallCriteria());
ex->enableAllowInterrupt(allowInterrupt());
ex->enableDCDM(dualCapacityDirectMode());
ex->enableDCDMLeader(dcdmLeader());
if (ch->is<DMRChannel>())
ex->setDMRSquelch(squelch());
}
return ch;
}
void
UV390Codeplug::ChannelElement::fromChannelObj(const Channel *chan, Context &ctx) {
TyTCodeplug::ChannelElement::fromChannelObj(chan, ctx);
// encode power setting
if (chan->defaultPower())
setPower(ctx.config()->settings()->power());
else
setPower(chan->power());
// By default, set to global default value.
setSquelch(ctx.config()->settings()->squelch());
if (chan->is<FMChannel>()) {
const FMChannel *achan = chan->as<const FMChannel>();
if (! achan->defaultSquelch())
setSquelch(achan->squelch());
}
// apply extensions
if (TyTChannelExtension *ex = chan->tytChannelExtension()) {
setTurnOffFreq(ex->killTone());
setInCallCriteria(ex->inCallCriterion());
enableAllowInterrupt(ex->allowInterrupt());
enableDualCapacityDirectMode(ex->dcdm());
enableDCDMLeader(ex->dcdmLeader());
if (chan->is<DMRChannel>())
setSquelch(ex->dmrSquelch());
}
}
/* ******************************************************************************************** *
* Implementation of UV390Codeplug::VFOChannelElement
* ******************************************************************************************** */
UV390Codeplug::VFOChannelElement::VFOChannelElement(uint8_t *ptr, size_t size)
: ChannelElement(ptr, size)
{
// pass...
}
UV390Codeplug::VFOChannelElement::VFOChannelElement(uint8_t *ptr)
: ChannelElement(ptr, size())
{
// pass...
}
UV390Codeplug::VFOChannelElement::~VFOChannelElement() {
// pass...
}
QString
UV390Codeplug::VFOChannelElement::name() const {
return "";
}
void
UV390Codeplug::VFOChannelElement::setName(const QString &txt) {
Q_UNUSED(txt)
// pass...
}
unsigned
UV390Codeplug::VFOChannelElement::stepSize() const {
return (getUInt8(32)+1)*2500;
}
void
UV390Codeplug::VFOChannelElement::setStepSize(unsigned ss_Hz) {
ss_Hz = std::min(50000U, std::max(ss_Hz, 2500U));
setUInt8(32, ss_Hz/2500-1);
setUInt8(33, 0xff);
}
/* ******************************************************************************************** *
* Implementation of UV390Codeplug::GeneralSettingsElement
* ******************************************************************************************** */
UV390Codeplug::GeneralSettingsElement::GeneralSettingsElement(uint8_t *ptr, size_t size)
: DM1701Codeplug::GeneralSettingsElement(ptr, size)
{
// pass...
}
UV390Codeplug::GeneralSettingsElement::GeneralSettingsElement(uint8_t *ptr)
: DM1701Codeplug::GeneralSettingsElement(ptr, SETTINGS_SIZE)
{
// pass...
}
void
UV390Codeplug::GeneralSettingsElement::clear() {
TyTCodeplug::GeneralSettingsElement::clear();
setTransmitMode(DESIGNED_AND_HAND_CH);
enableChannelVoiceAnnounce(false);
setBit(0x43,0, 1); setBit(0x43,1, 1);
setUInt4(0x43,3, 0xf);
setBit(0x6b, 2, 1);
setUInt8(0x91, 0xff); setUInt2(0x92, 0, 0x03);
enablePublicZone(true);
setUInt5(0x92, 3, 0x1f);
setUInt8(0x93, 0xff);
setAdditionalDMRId(0, 1); setUInt8(0x97, 0);
setAdditionalDMRId(1, 2); setUInt8(0x9b, 0);
setAdditionalDMRId(2, 3); setUInt8(0x9f, 0);
setUInt3(0xa0, 0, 0b111);
setMICLevel(2);
enableEditRadioID(true);
setBit(0xa0, 7, true);
memset(_data+0xa1, 0xff, 15);
}
UV390Codeplug::GeneralSettingsElement::TransmitMode
UV390Codeplug::GeneralSettingsElement::transmitMode() const {
return TransmitMode(getUInt2(0x40,6));
}
void
UV390Codeplug::GeneralSettingsElement::setTransmitMode(TransmitMode mode) {
setUInt2(0x40,6, mode);
}
bool
UV390Codeplug::GeneralSettingsElement::channelVoiceAnnounce() const {
return getBit(0x42,1);
}
void
UV390Codeplug::GeneralSettingsElement::enableChannelVoiceAnnounce(bool enable) {
setBit(0x42,1, enable);
}
bool
UV390Codeplug::GeneralSettingsElement::keypadTones() const {
return getBit(0x42,5);
}
void
UV390Codeplug::GeneralSettingsElement::enableKeypadTones(bool enable) {
setBit(0x42,5, enable);
}
bool
UV390Codeplug::GeneralSettingsElement::publicZone() const {
return getBit(0x92, 2);
}
void
UV390Codeplug::GeneralSettingsElement::enablePublicZone(bool enable) {
setBit(0x92, 2, enable);
}
uint32_t
UV390Codeplug::GeneralSettingsElement::additionalDMRId(unsigned n) const {
return getUInt24_le(0x94+4*n);
}
void
UV390Codeplug::GeneralSettingsElement::setAdditionalDMRId(unsigned n, uint32_t id) {
setUInt24_le(0x94+4*n, id);
}
unsigned
UV390Codeplug::GeneralSettingsElement::micLevel() const {
return (unsigned(getUInt3(0xa0,3)+1)*100)/60;
}
void
UV390Codeplug::GeneralSettingsElement::setMICLevel(unsigned level) {
setUInt3(0xa0,3, ((level-1)*60)/100);
}
bool
UV390Codeplug::GeneralSettingsElement::editRadioID() const {
return !getBit(0xa0, 6);
}
void
UV390Codeplug::GeneralSettingsElement::enableEditRadioID(bool enable) {
setBit(0xa0,6, !enable);
}
bool
UV390Codeplug::GeneralSettingsElement::fromConfig(const Config *config) {
if (! DM1701Codeplug::GeneralSettingsElement::fromConfig(config))
return false;
setTimeZone(QTimeZone::systemTimeZone());
setMICLevel(config->settings()->micLevel());
enableChannelVoiceAnnounce(config->settings()->speech());
return true;
}
bool
UV390Codeplug::GeneralSettingsElement::updateConfig(Config *config) {
if (! DM1701Codeplug::GeneralSettingsElement::updateConfig(config))
return false;
config->settings()->setMicLevel(micLevel());
config->settings()->enableSpeech(channelVoiceAnnounce());
return true;
}
/* ******************************************************************************************** *
* Implementation of UV390Codeplug::BootSettingsElement
* ******************************************************************************************** */
UV390Codeplug::BootSettingsElement::BootSettingsElement(uint8_t *ptr, size_t size)
: Codeplug::Element(ptr, size)
{
// pass...
}
UV390Codeplug::BootSettingsElement::BootSettingsElement(uint8_t *ptr)
: Codeplug::Element(ptr, 0x0010)
{
// pass...
}
UV390Codeplug::BootSettingsElement::~BootSettingsElement() {
// pass...
}
void
UV390Codeplug::BootSettingsElement::clear() {
setUInt24_le(0, 0xffffff);
setZoneIndex(1);
setChannelIndexA(1);
setUInt8(0x05, 0xff);
setChannelIndexB(1);
setUInt16_le(0x07, 0xffff);
setUInt16_le(0x09, 0x0001);
setUInt8(0x0b, 0xff);
setUInt32_le(0x0c, 0xffffffff);
}
unsigned
UV390Codeplug::BootSettingsElement::zoneIndex() const {
return getUInt8(0x03);
}
void
UV390Codeplug::BootSettingsElement::setZoneIndex(unsigned idx) {
setUInt8(0x03, idx);
}
unsigned
UV390Codeplug::BootSettingsElement::channelIndexA() const {
return getUInt8(0x04);
}
void
UV390Codeplug::BootSettingsElement::setChannelIndexA(unsigned idx) {
setUInt8(0x04, idx);
}
unsigned
UV390Codeplug::BootSettingsElement::channelIndexB() const {
return getUInt8(0x06);
}
void
UV390Codeplug::BootSettingsElement::setChannelIndexB(unsigned idx) {
setUInt8(0x06, idx);
}
/* ******************************************************************************************** *
* Implementation of UV390Codeplug::MenuSettingsElement
* ******************************************************************************************** */
UV390Codeplug::MenuSettingsElement::MenuSettingsElement(uint8_t *ptr, size_t size)
: TyTCodeplug::MenuSettingsElement(ptr, size)
{
// pass...
}
UV390Codeplug::MenuSettingsElement::MenuSettingsElement(uint8_t *ptr)
: TyTCodeplug::MenuSettingsElement(ptr)
{
// pass...
}
void
UV390Codeplug::MenuSettingsElement::clear() {
TyTCodeplug::MenuSettingsElement::clear();
enableGPSSettings(true);
enableRecording(true);
enableGroupCallMatch(true);
enablePrivateCallMatch(true);
enableMenuHangtimeItem(true);
enableTXMode(true);
enableZoneSettings(true);
enableNewZone(true);
enableEditZone(true);
enableNewScanList(true);
setBit(0x05, 0, true);
setBit(0x05, 1, true);
enableGroupCallMatch(true);
enablePrivateCallMatch(true);
enableMenuHangtimeItem(true);
enableTXMode(true);
enableZoneSettings(true);
enableNewZone(true);
enableEditZone(true);
enableNewScanList(true);
}
bool
UV390Codeplug::MenuSettingsElement::gpsSettings() const {
return !getBit(0x04, 3);
}
void
UV390Codeplug::MenuSettingsElement::enableGPSSettings(bool enable) {
setBit(0x04, 3, !enable);
}
bool
UV390Codeplug::MenuSettingsElement::recording() const {
return getBit(0x04, 5);
}
void
UV390Codeplug::MenuSettingsElement::enableRecording(bool enable) {
setBit(0x04, 5, enable);
}
bool
UV390Codeplug::MenuSettingsElement::groupCallMatch() const {
return getBit(0x05, 2);
}
void
UV390Codeplug::MenuSettingsElement::enableGroupCallMatch(bool enable) {
setBit(0x05, 2, enable);
}
bool
UV390Codeplug::MenuSettingsElement::privateCallMatch() const {
return getBit(0x05, 3);
}
void
UV390Codeplug::MenuSettingsElement::enablePrivateCallMatch(bool enable) {
setBit(0x05, 3, enable);
}
bool
UV390Codeplug::MenuSettingsElement::menuHangtimeItem() const {
return getBit(0x05, 4);
}
void
UV390Codeplug::MenuSettingsElement::enableMenuHangtimeItem(bool enable) {
setBit(0x05, 4, enable);
}
bool
UV390Codeplug::MenuSettingsElement::txMode() const {
return getBit(0x05, 5);
}
void
UV390Codeplug::MenuSettingsElement::enableTXMode(bool enable) {
setBit(0x05, 5, enable);
}
bool
UV390Codeplug::MenuSettingsElement::zoneSettings() const {
return getBit(0x05, 6);
}
void
UV390Codeplug::MenuSettingsElement::enableZoneSettings(bool enable) {
setBit(0x05, 6, enable);
}
bool
UV390Codeplug::MenuSettingsElement::newZone() const {
return getBit(0x05, 7);
}
void
UV390Codeplug::MenuSettingsElement::enableNewZone(bool enable) {
setBit(0x05, 7, enable);
}
bool
UV390Codeplug::MenuSettingsElement::editZone() const {
return getBit(0x06, 0);
}
void
UV390Codeplug::MenuSettingsElement::enableEditZone(bool enable) {
setBit(0x06, 0, enable);
}
bool
UV390Codeplug::MenuSettingsElement::newScanList() const {
return getBit(0x06, 1);
}
void
UV390Codeplug::MenuSettingsElement::enableNewScanList(bool enable) {
setBit(0x06, 1, enable);
}
/* ******************************************************************************************** *
* Implementation of UV390Codeplug
* ******************************************************************************************** */
UV390Codeplug::UV390Codeplug(QObject *parent)
: TyTCodeplug(parent)
{
addImage("TYT MD-UV390 Codeplug");
image(0).addElement(0x002000, 0x3e000);
image(0).addElement(0x110000, 0x90000);
// Clear entire codeplug
UV390Codeplug::clear();
}
UV390Codeplug::~UV390Codeplug() {
// pass...
}
void
UV390Codeplug::clear() {
TyTCodeplug::clear();
UV390Codeplug::clearBootSettings();
UV390Codeplug::clearVFOSettings();
}
void
UV390Codeplug::clearTimestamp() {
TimestampElement(data(ADDR_TIMESTAMP)).clear();
}
bool
UV390Codeplug::encodeTimestamp() {
TimestampElement ts(data(ADDR_TIMESTAMP));
ts.setTimestamp(QDateTime::currentDateTime());
return true;
}
void
UV390Codeplug::clearGeneralSettings() {
GeneralSettingsElement(data(ADDR_SETTINGS)).clear();
}
bool
UV390Codeplug::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
UV390Codeplug::decodeGeneralSettings(Config *config, const ErrorStack &err) {
Q_UNUSED(err)
return GeneralSettingsElement(data(ADDR_SETTINGS)).updateConfig(config);
}
void
UV390Codeplug::clearChannels() {
// Clear channels
for (unsigned int i=0; i<Limit::channels(); i++)
ChannelElement(data(Offset::channels()+i*Offset::betweenChannels())).clear();
}
bool
UV390Codeplug::encodeChannels(Config *config, const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(err)
// Define Channels
for (unsigned int i=0; i<Limit::channels(); i++) {
ChannelElement chan(data(Offset::channels()+i*Offset::betweenChannels()));
chan.clear();
if (i < (unsigned int)config->channelList()->count()) {
chan.fromChannelObj(config->channelList()->channel(i), ctx);
}
}
return true;
}
bool
UV390Codeplug::createChannels(Config *config, Context &ctx, const ErrorStack &err) {
for (unsigned int i=0; i<Limit::channels(); i++) {
ChannelElement chan(data(Offset::channels()+i*Offset::betweenChannels()));
if (! chan.isValid())
continue;
if (Channel *obj = chan.toChannelObj()) {
config->channelList()->add(obj); ctx.add(obj, i+1);
} else {
errMsg(err) << "Invalid channel at index " << i << ".";
return false;
}
}
return true;
}
bool
UV390Codeplug::linkChannels(Context &ctx, const ErrorStack &err) {
for (unsigned int i=0; i<Limit::channels(); i++) {
ChannelElement chan(data(Offset::channels()+i*Offset::betweenChannels()));
if (! chan.isValid())
continue;
if (! chan.linkChannelObj(ctx.get<Channel>(i+1), ctx, err)) {
errMsg(err) << "Cannot link channel at index " << i << ".";
return false;
}
}
return true;
}
void
UV390Codeplug::clearContacts() {
// Clear contacts
for (int i=0; i<NUM_CONTACTS; i++)
ContactElement(data(ADDR_CONTACTS+i*CONTACT_SIZE)).clear();
}
bool
UV390Codeplug::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
UV390Codeplug::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
UV390Codeplug::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
UV390Codeplug::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
UV390Codeplug::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
UV390Codeplug::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
UV390Codeplug::clearGroupLists() {
for (int i=0; i<NUM_GROUPLISTS; i++)
GroupListElement(data(ADDR_GROUPLISTS+i*GROUPLIST_SIZE)).clear();
}
bool
UV390Codeplug::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
UV390Codeplug::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 RX group list at index " << i << ".";
return false;
}
}
return true;
}
bool
UV390Codeplug::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
UV390Codeplug::clearScanLists() {
// Clear scan lists
for (int i=0; i<NUM_SCANLISTS; i++)
ScanListElement(data(ADDR_SCANLISTS + i*SCANLIST_SIZE)).clear();
}
bool
UV390Codeplug::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
UV390Codeplug::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 scan list at index " << i << ".";
return false;
}
}
return true;
}
bool
UV390Codeplug::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
UV390Codeplug::clearPositioningSystems() {
// Clear GPS systems
for (int i=0; i<NUM_GPSSYSTEMS; i++)
GPSSystemElement(data(ADDR_GPSSYSTEMS+i*GPSSYSTEM_SIZE)).clear();
}
bool
UV390Codeplug::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()) {
logDebug() << "Encode GPS system #" << i << " '" <<
config->posSystems()->gpsSystem(i)->name() << "'.";
gps.fromGPSSystemObj(config->posSystems()->gpsSystem(i), ctx);
} else {
gps.clear();
}
}
return true;
}
bool
UV390Codeplug::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
UV390Codeplug::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
UV390Codeplug::clearButtonSettings() {
ButtonSettingsElement(data(ADDR_BUTTONSETTINGS)).clear();
}
bool
UV390Codeplug::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
UV390Codeplug::decodeButtonSetttings(Config *config, const ErrorStack &err) {
Q_UNUSED(err)
return ButtonSettingsElement(data(ADDR_BUTTONSETTINGS)).updateConfig(config);
}
void
UV390Codeplug::clearPrivacyKeys() {
EncryptionElement(data(ADDR_PRIVACY_KEYS)).clear();
}
bool
UV390Codeplug::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));
return keys.fromCommercialExt(config->commercialExtension(), ctx);
}
bool
UV390Codeplug::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 extension.";
return false;
}
return true;
}
void
UV390Codeplug::clearBootSettings() {
BootSettingsElement(data(ADDR_BOOTSETTINGS)).clear();
}
void
UV390Codeplug::clearMenuSettings() {
MenuSettingsElement(data(ADDR_MENUSETTINGS)).clear();
}
void
UV390Codeplug::clearTextMessages() {
MessageBankElement(data(Offset::messages())).clear();
}
bool
UV390Codeplug::encodeTextMessages(Context &ctx, const Flags &flags, const ErrorStack &err) {
return MessageBankElement(data(Offset::messages())).encode(ctx, flags, err);
}
bool
UV390Codeplug::decodeTextMessages(Context &ctx, const ErrorStack &err) {
return MessageBankElement(data(Offset::messages())).decode(ctx, err);
}
void
UV390Codeplug::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
UV390Codeplug::clearVFOSettings() {
VFOChannelElement(data(ADDR_VFO_CHANNEL_A)).clear();
VFOChannelElement(data(ADDR_VFO_CHANNEL_B)).clear();
}
|