4
4
#include "channel.hh"
5
5
#include "gpssystem.hh"
6
#include "userdatabase.hh"
11
#define NCONTACTS 10000
16
#define NGPSSYSTEMS 16
18
// ---- first segment ---- additional offset 0x000800
19
#define OFFSET_TIMESTMP 0x002800
20
#define OFFSET_SETTINGS 0x002840
21
#define OFFSET_MSG 0x002980
22
#define OFFSET_GLISTS 0x00f420
23
#define OFFSET_ZONES 0x0151e0
24
#define OFFSET_SCANL 0x019060
25
#define OFFSET_ZONEXT 0x031800
26
#define OFFSET_GPS_SYS 0x03f40e
27
// ---- second segment ---- additional offset 0x110800
28
#define OFFSET_CHANNELS 0x110800
29
#define OFFSET_CONTACTS 0x140800
31
#define CALLSIGN_START 0x00200000 // Start of callsign database
32
#define CALLSIGN_FINISH 0x01000000 // End of callsign database
33
#define CALLSIGN_OFFSET 0x4003
35
#define VALID_TEXT(txt) (*(txt) != 0 && *(txt) != 0xffff)
36
#define VALID_CHANNEL(ch) VALID_TEXT((ch)->name)
37
#define VALID_ZONE(z) VALID_TEXT((z)->name)
38
#define VALID_SCANLIST(sl) VALID_TEXT((sl)->name)
39
#define VALID_GROUPLIST(gl) VALID_TEXT((gl)->name)
40
#define VALID_CONTACT(ct) ((ct)->type != 0 && VALID_TEXT((ct)->name))
12
#define NCONTACTS 10000
18
#define NGPSSYSTEMS 16
20
// ---- first segment ----
21
#define OFFSET_TIMESTMP 0x002800
22
#define OFFSET_SETTINGS 0x002840
23
#define OFFSET_MENU 0x0028f0
24
#define OFFSET_BUTTONS 0x002900
25
#define OFFSET_MSG 0x002980
26
#define OFFSET_PRIVACY 0x0061c0
27
#define OFFSET_EMERGENCY 0x006250
28
#define OFFSET_GLISTS 0x00f420
29
#define OFFSET_ZONES 0x0151e0
30
#define OFFSET_SCANL 0x019060
31
#define OFFSET_VFO_A 0x02f700
32
#define OFFSET_VFO_B 0x02f740
33
#define OFFSET_ZONEXT 0x031800
34
#define OFFSET_GPS_SYS 0x03f440
35
// ---- second segment ----
36
#define OFFSET_CHANNELS 0x110800
37
#define OFFSET_CONTACTS 0x140800
38
// ---- thrid segement ----
39
#define CALLSIGN_START 0x00200000 // Start of callsign database
40
#define CALLSIGN_END 0x01000000 // End of callsign database
41
#define CALLSIGN_OFFSET 0x00204003 // Start of callsign entries
43
44
/* ******************************************************************************************** *
957
967
setRepeatInterval(l->period());
971
/* ******************************************************************************************** *
972
* Implementation of UV390Codeplug::buttons_t
973
* ******************************************************************************************** */
974
UV390Codeplug::buttons_t::buttons_t()
980
UV390Codeplug::buttons_t::clear() {
981
_reserved_0 = 0x0000;
982
side_button_1 = Disabled;
983
side_button_1_long = Tone1750Hz;
984
side_button_2 = MonitorToggle;
985
side_button_2_long = Disabled;
986
memset(_unused_6, 0x00, sizeof(_unused_6));
988
long_press_dur = 0x04;
990
for (int i=0; i<6; i++)
991
one_touch[i].clear();
992
memset(_unused_42, 0x00, sizeof(_unused_42));
996
/* ******************************************************************************************** *
997
* Implementation of UV390Codeplug::emergency_t
998
* ******************************************************************************************** */
999
UV390Codeplug::emergency_t::emergency_t() {
1004
UV390Codeplug::emergency_t::clear() {
1006
remote_mon_decode = 0;
1007
em_remote_mon_decode = 1;
1008
_unknown_0_3 = 0b11111;
1011
tx_sync_wakeup_tot = 5;
1012
tx_wakeup_msg_limit = 2;
1013
memset(_unused_4, 0xff, sizeof(_unused_4));
1015
for (int i=0; i<32; i++)
1019
/* ******************************************************************************************** *
1020
* Implementation of UV390Codeplug::emergency_t::system_t
1021
* ******************************************************************************************** */
1022
UV390Codeplug::emergency_t::system_t::system_t() {
1027
UV390Codeplug::emergency_t::system_t::clear() {
1028
memset(name, 0x00, sizeof(name));
1029
alarm_type = DISABLED;
1030
_unknown_32_2 = 0b11;
1032
_unknown_32_6 = 0b01;
1033
impolite_retires = 15;
1036
revert_channel = 0x0000;
1037
_unused_37 = 0xffff;
1041
UV390Codeplug::emergency_t::system_t::isValid() const {
1042
return 0x0000 != revert_channel;
1046
/* ******************************************************************************************** *
1047
* Implementation of UV390Codeplug::privacy_t
1048
* ******************************************************************************************** */
1049
UV390Codeplug::privacy_t::privacy_t() {
1054
UV390Codeplug::privacy_t::clear() {
1055
memset(enhanced_keys, 0xff, sizeof(enhanced_keys));
1056
memset(_reserved, 0xff, sizeof(_reserved));
1057
memset(basic_keys, 0xff, sizeof(basic_keys));
1061
/* ******************************************************************************************** *
1062
* Implementation of UV390Codeplug::buttons_t::one_touch_t
1063
* ******************************************************************************************** */
1065
UV390Codeplug::buttons_t::one_touch_t::clear() {
1068
_reserved_0_6 = 0b11;
1074
/* ******************************************************************************************** *
1075
* Implementation of UV390Codeplug::menu_t
1076
* ******************************************************************************************** */
1077
UV390Codeplug::menu_t::menu_t() {
1082
UV390Codeplug::menu_t::clear() {
1098
calllog_answered = 1;
1099
calllog_outgoing = 1;
1114
hide_prog_radio = 0;
1118
_unknown_4_6 = 0b11;
1120
_unknown_5_0 = 0b11;
1121
group_call_match = 1;
1122
private_call_match = 1;
1130
_unknown_6_2 = 0b111111;
1132
memset(_reserved_7, 0xff, sizeof(_reserved_7));
1135
/* ******************************************************************************************** *
1136
* Implementation of UV390Codeplug::callsign_db_t
1137
* ******************************************************************************************** */
1138
UV390Codeplug::callsign_db_t::entry_t::entry_t() {
1143
UV390Codeplug::callsign_db_t::entry_t::clear() {
1149
UV390Codeplug::callsign_db_t::entry_t::isValid() const {
1150
return (0xfff != id_high) && (0xfffff != index);
1153
UV390Codeplug::callsign_db_t::callsign_t::callsign_t() {
1158
UV390Codeplug::callsign_db_t::callsign_t::clear() {
1159
memset(dmrid, 0xff, sizeof(dmrid));
1161
memset(callsign, 0xff, sizeof(callsign));
1162
memset(name, 0xff, sizeof(name));
1166
UV390Codeplug::callsign_db_t::callsign_t::isValid() const {
1167
return (0xff != dmrid[0]) && (0xff != dmrid[1]) && (0xff != dmrid[2]);
1171
UV390Codeplug::callsign_db_t::callsign_t::setID(uint32_t dmrid) {
1172
encode_dmr_id_bcd(this->dmrid, dmrid);
1176
UV390Codeplug::callsign_db_t::callsign_t::setCall(const QString &call) {
1177
memset(callsign, 0xff, sizeof(callsign));
1178
strncpy(callsign, call.toStdString().c_str(), sizeof(callsign));
1182
UV390Codeplug::callsign_db_t::callsign_t::setName(const QString &name) {
1183
memset(this->name, 0xff, sizeof(this->name));
1184
strncpy(this->name, name.toStdString().c_str(), sizeof(this->name));
1188
UV390Codeplug::callsign_db_t::callsign_t::fromUser(const UserDatabase::User &user) {
1191
QString name = user.name;
1192
if (! user.surname.isEmpty())
1193
name += " " + user.surname;
1194
if (! user.country.isEmpty())
1195
name += ", " + user.country;
1199
UV390Codeplug::callsign_db_t::callsign_db_t() {
1204
UV390Codeplug::callsign_db_t::clear() {
1206
for (int i=0; i<4096; i++)
1208
for (int i=0; i<122197; i++)
1213
UV390Codeplug::callsign_db_t::fromUserDB(const UserDatabase *db) {
1214
// Clear database and index
1216
// Limit users to 122197 entries
1217
n = std::min(122197ll, db->count());
1218
// If there are no users -> done.
1222
// Select n users and sort them in ascending order of their IDs
1223
QVector<UserDatabase::User> users;
1224
for (int i=0; i<n; i++)
1225
users.append(db->user(i));
1226
std::sort(users.begin(), users.end(),
1227
[](const UserDatabase::User &a, const UserDatabase::User &b) { return a.id < b.id; });
1229
// First index entry
1231
uint cidh = (users[0].id >> 12);
1232
this->index[j].id_high = cidh;
1233
this->index[j].index = 1;
1236
// Store users and update index
1237
for (int i=0; i<n; i++) {
1238
this->db[i].fromUser(users[i]);
1239
uint idh = (users[i].id >> 12);
1241
this->index[j].id_high = idh;
1242
this->index[j].index = i+1;
960
1249
/* ******************************************************************************************** *
961
1250
* Implementation of UV390Codeplug
962
1251
* ******************************************************************************************** */
966
1255
addImage("TYT MD-UV390 Codeplug");
967
1256
image(0).addElement(0x002800, 0x3e000);
968
1257
image(0).addElement(0x110800, 0x90000);
970
1258
// Clear entire codeplug
1263
UV390Codeplug::clear()
1265
// Clear entire images
1266
memset(data(0x002800), 0xff, 0x3e000);
1267
memset(data(0x110800), 0xff, 0x90000);
972
1269
// Clear timestamp
973
1270
((timestamp_t *)(data(OFFSET_TIMESTMP)))->set();
974
// Clear some unused memory sections
975
memset(data(0x00280c),0xff,52);
976
1272
// Clear general config
977
1273
((general_settings_t *)(data(OFFSET_SETTINGS)))->clear();
979
for (int i=0; i<NCONTACTS; i++)
980
((contact_t *)(data(OFFSET_CONTACTS+i*sizeof(contact_t))))->clear();
1275
// Clear menu settings
1276
((menu_t *)(data(OFFSET_MENU)))->clear();
1278
// Clear button settings
1279
((buttons_t *)(data(OFFSET_BUTTONS)))->clear();
1281
// Clear text messages
1282
for (int i=0; i<NMESSAGES; i++)
1283
((message_t *)(data(OFFSET_MSG+i*sizeof(message_t))))->clear();
1285
// Clear privacy keys
1286
((privacy_t *)(data(OFFSET_PRIVACY)))->clear();
1288
// Clear emergency systems
1289
((emergency_t *)(data(OFFSET_EMERGENCY)))->clear();
981
1291
// Clear RX group lists
982
1292
for (int i=0; i<NGLISTS; i++)
983
1293
((grouplist_t *)(data(OFFSET_GLISTS+i*sizeof(grouplist_t))))->clear();
985
for (int i=0; i<NCHAN; i++)
986
((channel_t *)(data(OFFSET_CHANNELS+i*sizeof(channel_t))))->clear();
1295
// Clear zones & zone extensions
988
1296
for (int i=0; i<NZONES; i++) {
989
1297
((zone_t *)(data(OFFSET_ZONES+i*sizeof(zone_t))))->clear();
990
1298
((zone_ext_t*)(data(OFFSET_ZONEXT+i*sizeof(zone_ext_t))))->clear();
992
1301
// Clear scan lists
993
1302
for (int i=0; i<NSCANL; i++)
994
1303
((scanlist_t *)(data(OFFSET_SCANL+i*sizeof(scanlist_t))))->clear();
1305
// Clear VFO A & B settings.
1306
((channel_t *)(data(OFFSET_VFO_A)))->clear();
1307
((channel_t *)(data(OFFSET_VFO_B)))->clear();
1309
// Clear GPS systems
1310
for (int i=0; i<NGPSSYSTEMS; i++)
1311
((gpssystem_t *)(data(OFFSET_GPS_SYS+i*sizeof(gpssystem_t))))->clear();
1314
for (int i=0; i<NCHAN; i++)
1315
((channel_t *)(data(OFFSET_CHANNELS+i*sizeof(channel_t))))->clear();
1318
for (int i=0; i<NCONTACTS; i++)
1319
((contact_t *)(data(OFFSET_CONTACTS+i*sizeof(contact_t))))->clear();
998
1323
UV390Codeplug::encode(Config *config) {
999
// Some unused memory sections
1000
memset(data(0x00280c),0xff,52);
1002
1324
// Set timestamp
1003
1325
((timestamp_t *)(data(OFFSET_TIMESTMP)))->set();