forked from sq5bpf/uvk5-reverse-engineering
-
Notifications
You must be signed in to change notification settings - Fork 13
/
uvk5_egzumer.py
1725 lines (1422 loc) · 60.1 KB
/
uvk5_egzumer.py
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
# Quansheng UV-K5 driver (c) 2023 Jacek Lipkowski <[email protected]>
# Adapted For UV-K5 EGZUMER custom software By EGZUMER, JOC2
#
# based on template.py Copyright 2012 Dan Smith <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
from chirp import chirp_common, directory, bitwise
from chirp.drivers import uvk5
from chirp.settings import RadioSetting, RadioSettingGroup, \
RadioSettingValueBoolean, RadioSettingValueList, \
RadioSettingValueInteger, RadioSettingValueString, \
RadioSettings, InvalidValueError, RadioSettingSubGroup
LOG = logging.getLogger(__name__)
MEM_FORMAT = """
//#seekto 0x0000;
struct {
ul32 freq;
ul32 offset;
// 0x08
u8 rxcode;
u8 txcode;
// 0x0A
u8 txcodeflag:4,
rxcodeflag:4;
// 0x0B
u8 modulation:4,
shift:4;
// 0x0C
u8 __UNUSED1:3,
bclo:1,
txpower:2,
bandwidth:1,
freq_reverse:1;
// 0x0D
u8 __UNUSED2:4,
dtmf_pttid:3,
dtmf_decode:1;
// 0x0E
u8 step;
u8 scrambler;
} channel[214];
//#seekto 0xd60;
struct {
u8 is_scanlist1:1,
is_scanlist2:1,
compander:2,
is_free:1,
band:3;
} channel_attributes[207];
#seekto 0xe40;
ul16 fmfreq[20];
#seekto 0xe70;
u8 call_channel;
u8 squelch;
u8 max_talk_time;
u8 noaa_autoscan;
u8 key_lock;
u8 vox_switch;
u8 vox_level;
u8 mic_gain;
u8 backlight_min:4,
backlight_max:4;
u8 channel_display_mode;
u8 crossband;
u8 battery_save;
u8 dual_watch;
u8 backlight_time;
u8 ste;
u8 freq_mode_allowed;
#seekto 0xe80;
u8 ScreenChannel_A;
u8 MrChannel_A;
u8 FreqChannel_A;
u8 ScreenChannel_B;
u8 MrChannel_B;
u8 FreqChannel_B;
u8 NoaaChannel_A;
u8 NoaaChannel_B;
#seekto 0xe90;
u8 keyM_longpress_action:7,
button_beep:1;
u8 key1_shortpress_action;
u8 key1_longpress_action;
u8 key2_shortpress_action;
u8 key2_longpress_action;
u8 scan_resume_mode;
u8 auto_keypad_lock;
u8 power_on_dispmode;
ul32 password;
#seekto 0xea0;
u8 voice;
u8 s0_level;
u8 s9_level;
#seekto 0xea8;
u8 alarm_mode;
u8 roger_beep;
u8 rp_ste;
u8 TX_VFO;
u8 Battery_type;
#seekto 0xeb0;
char logo_line1[16];
char logo_line2[16];
//#seekto 0xed0;
struct {
u8 side_tone;
char separate_code;
char group_call_code;
u8 decode_response;
u8 auto_reset_time;
u8 preload_time;
u8 first_code_persist_time;
u8 hash_persist_time;
u8 code_persist_time;
u8 code_interval_time;
u8 permit_remote_kill;
#seekto 0xee0;
char local_code[3];
#seek 5;
char kill_code[5];
#seek 3;
char revive_code[5];
#seek 3;
char up_code[16];
char down_code[16];
} dtmf;
//#seekto 0xf18;
u8 slDef;
u8 sl1PriorEnab;
u8 sl1PriorCh1;
u8 sl1PriorCh2;
u8 sl2PriorEnab;
u8 sl2PriorCh1;
u8 sl2PriorCh2;
#seekto 0xf40;
u8 int_flock;
u8 int_350tx;
u8 int_KILLED;
u8 int_200tx;
u8 int_500tx;
u8 int_350en;
u8 int_scren;
u8 backlight_on_TX_RX:2,
AM_fix:1,
mic_bar:1,
battery_text:2,
live_DTMF_decoder:1,
unknown:1;
#seekto 0xf50;
struct {
char name[16];
} channelname[200];
#seekto 0x1c00;
struct {
char name[8];
char number[3];
#seek 5;
} dtmfcontact[16];
struct {
struct {
#seekto 0x1E00;
u8 openRssiThr[10];
#seekto 0x1E10;
u8 closeRssiThr[10];
#seekto 0x1E20;
u8 openNoiseThr[10];
#seekto 0x1E30;
u8 closeNoiseThr[10];
#seekto 0x1E40;
u8 closeGlitchThr[10];
#seekto 0x1E50;
u8 openGlitchThr[10];
} sqlBand4_7;
struct {
#seekto 0x1E60;
u8 openRssiThr[10];
#seekto 0x1E70;
u8 closeRssiThr[10];
#seekto 0x1E80;
u8 openNoiseThr[10];
#seekto 0x1E90;
u8 closeNoiseThr[10];
#seekto 0x1EA0;
u8 closeGlitchThr[10];
#seekto 0x1EB0;
u8 openGlitchThr[10];
} sqlBand1_3;
#seekto 0x1EC0;
struct {
ul16 level1;
ul16 level2;
ul16 level4;
ul16 level6;
} rssiLevelsBands3_7;
struct {
ul16 level1;
ul16 level2;
ul16 level4;
ul16 level6;
} rssiLevelsBands1_2;
struct {
struct {
u8 lower;
u8 center;
u8 upper;
} low;
struct {
u8 lower;
u8 center;
u8 upper;
} mid;
struct {
u8 lower;
u8 center;
u8 upper;
} hi;
#seek 7;
} txp[7];
#seekto 0x1F40;
ul16 batLvl[6];
#seekto 0x1F50;
ul16 vox1Thr[10];
#seekto 0x1F68;
ul16 vox0Thr[10];
#seekto 0x1F80;
u8 micLevel[5];
#seekto 0x1F88;
il16 xtalFreqLow;
#seekto 0x1F8E;
u8 volumeGain;
u8 dacGain;
} cal;
#seekto 0x1FF0;
struct {
u8 ENABLE_DTMF_CALLING:1,
ENABLE_PWRON_PASSWORD:1,
ENABLE_TX1750:1,
ENABLE_ALARM:1,
ENABLE_VOX:1,
ENABLE_VOICE:1,
ENABLE_NOAA:1,
ENABLE_FMRADIO:1;
u8 __UNUSED:2,
ENABLE_SPECTRUM:1,
ENABLE_AM_FIX:1,
ENABLE_BLMIN_TMP_OFF:1,
ENABLE_RAW_DEMODULATORS:1,
ENABLE_WIDE_RX:1,
ENABLE_FLASHLIGHT:1;
} BUILD_OPTIONS;
"""
# power
UVK5_POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=1.50),
chirp_common.PowerLevel("Med", watts=3.00),
chirp_common.PowerLevel("High", watts=5.00),
]
# scrambler
SCRAMBLER_LIST = ["Off", "2600Hz", "2700Hz", "2800Hz", "2900Hz", "3000Hz",
"3100Hz", "3200Hz", "3300Hz", "3400Hz", "3500Hz"]
# compander
COMPANDER_LIST = ["Off", "TX", "RX", "TX/RX"]
# rx mode
RXMODE_LIST = ["Main only", "Dual RX, respond", "Crossband",
"Dual RX, TX on main"]
# channel display mode
CHANNELDISP_LIST = ["Frequency", "Channel Number", "Name", "Name + Frequency"]
# TalkTime
TALK_TIME_LIST = ["30 sec", "1 min", "2 min", "3 min", "4 min", "5 min",
"6 min", "7 min", "8 min", "9 min", "15 min"]
# battery save
BATSAVE_LIST = ["Off", "1:1", "1:2", "1:3", "1:4"]
# battery type
BATTYPE_LIST = ["1600 mAh", "2200 mAh"]
# bat txt
BAT_TXT_LIST = ["None", "Voltage", "Percentage"]
# Backlight auto mode
BACKLIGHT_LIST = ["Off", "5s", "10s", "20s", "1min", "2min", "4min",
"Always On"]
# Backlight LVL
BACKLIGHT_LVL_LIST = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
# Backlight _TX_RX_LIST
BACKLIGHT_TX_RX_LIST = ["Off", "TX", "RX", "TX/RX"]
# flock list extended
FLOCK_LIST = ["Default+ (137-174, 400-470 + Tx200, Tx350, Tx500)",
"FCC HAM (144-148, 420-450)",
"CE HAM (144-146, 430-440)",
"GB HAM (144-148, 430-440)",
"137-174, 400-430",
"137-174, 400-438",
"Disable All",
"Unlock All"]
SCANRESUME_LIST = ["Listen 5 seconds and resume",
"Listen until carrier disappears",
"Stop scanning after receiving a signal"]
WELCOME_LIST = ["Full screen test", "User message", "Battery voltage", "None"]
VOICE_LIST = ["Off", "Chinese", "English"]
# ACTIVE CHANNEL
TX_VFO_LIST = ["A", "B"]
ALARMMODE_LIST = ["Site", "Tone"]
ROGER_LIST = ["Off", "Roger beep", "MDC data burst"]
RTE_LIST = ["Off", "100ms", "200ms", "300ms", "400ms",
"500ms", "600ms", "700ms", "800ms", "900ms", "1000ms"]
VOX_LIST = ["Off", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
# fm radio supported frequencies
FMMIN = 76.0
FMMAX = 108.0
# bands supported by the UV-K5
BANDS_STANDARD = {
0: [50.0, 76.0],
1: [108.0, 136.9999],
2: [137.0, 173.9999],
3: [174.0, 349.9999],
4: [350.0, 399.9999],
5: [400.0, 469.9999],
6: [470.0, 600.0]
}
BANDS_WIDE = {
0: [18.0, 108.0],
1: [108.0, 136.9999],
2: [137.0, 173.9999],
3: [174.0, 349.9999],
4: [350.0, 399.9999],
5: [400.0, 469.9999],
6: [470.0, 1300.0]
}
SCANLIST_SELECT_LIST = ["List 1", "List 2", "All channels"]
DTMF_CHARS = "0123456789ABCD*# "
DTMF_CHARS_ID = "0123456789ABCDabcd"
DTMF_CHARS_KILL = "0123456789ABCDabcd"
DTMF_CHARS_UPDOWN = "0123456789ABCDabcd#* "
DTMF_CODE_CHARS = "ABCD*# "
DTMF_DECODE_RESPONSE_LIST = ["Do nothing", "Local ringing", "Replay response",
"Local ringing + reply response"]
KEYACTIONS_LIST = ["None",
"Flashlight",
"TX power",
"Monitor",
"Scan",
"VOX",
"Alarm",
"FM broadcast radio",
"1750Hz tone",
"Lock keypad",
"Switch main VFO",
"Switch frequency/memory mode",
"Switch demodulation",
"Min backlight temporary off",
"Spectrum analyzer"
]
MIC_GAIN_LIST = ["+1.1dB", "+4.0dB", "+8.0dB", "+12.0dB", "+15.1dB"]
def min_max_def(value, min_val, max_val, default):
"""returns value if in bounds or default otherwise"""
if min_val is not None and value < min_val:
return default
if max_val is not None and value > max_val:
return default
return value
def list_def(value, lst, default):
"""return value if is in the list, default otherwise"""
if isinstance(default, str):
default = lst.index(default)
if value < 0 or value >= len(lst):
return default
return value
@directory.register
@directory.detected_by(uvk5.UVK5Radio)
class UVK5RadioEgzumer(uvk5.UVK5RadioBase):
"""Quansheng UV-K5 (egzumer)"""
VENDOR = "Quansheng"
MODEL = "UV-K5"
VARIANT = "egzumer"
BAUD_RATE = 38400
NEEDS_COMPAT_SERIAL = False
FIRMWARE_VERSION = ""
_cal_start = 0x1E00 # calibration memory start address
_pttid_list = ["Off", "Up code", "Down code", "Up+Down code",
"Apollo Quindar"]
_steps = [2.5, 5, 6.25, 10, 12.5, 25, 8.33, 0.01, 0.05, 0.1, 0.25, 0.5, 1,
1.25, 9, 15, 20, 30, 50, 100, 125, 200, 250, 500]
@classmethod
def k5_approve_firmware(cls, firmware):
return firmware.startswith('EGZUMER ')
def _get_bands(self):
is_wide = self._memobj.BUILD_OPTIONS.ENABLE_WIDE_RX \
if self._memobj is not None else True
bands = BANDS_WIDE if is_wide else BANDS_STANDARD
return bands
def _find_band(self, hz):
mhz = hz/1000000.0
bands = self._get_bands()
for bnd, rng in bands.items():
if rng[0] <= mhz <= rng[1]:
return bnd
return False
def _get_vfo_channel_names(self):
"""generates VFO_CHANNEL_NAMES"""
bands = self._get_bands()
names = []
for bnd, rng in bands.items():
name = f"F{bnd + 1}({round(rng[0])}M-{round(rng[1])}M)"
names.append(name + "A")
names.append(name + "B")
return names
def _get_specials(self):
"""generates SPECIALS"""
specials = {}
for idx, name in enumerate(self._get_vfo_channel_names()):
specials[name] = 200 + idx
return specials
# Return information about this radio's features, including
# how many memories it has, what bands it supports, etc
def get_features(self):
rf = super().get_features()
rf.valid_special_chans = self._get_vfo_channel_names()
rf.valid_modes = ["FM", "NFM", "AM", "NAM", "USB"]
rf.valid_bands = []
bands = self._get_bands()
for _, rng in bands.items():
rf.valid_bands.append(
(int(rng[0]*1000000), int(rng[1]*1000000)))
return rf
# Convert the raw byte array into a memory object structure
def process_mmap(self):
self._check_firmware_at_load()
self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)
def _get_mem_mode(self, _mem):
temp_modes = self.get_features().valid_modes
temp_modul = _mem.modulation * 2 + _mem.bandwidth
if temp_modul < len(temp_modes):
return temp_modes[temp_modul]
elif temp_modul == 5: # USB with narrow setting
return temp_modes[4]
elif temp_modul >= len(temp_modes):
LOG.error('Mode %i unsupported', temp_modul)
return "FM"
def get_memory(self, number):
mem = super().get_memory(number)
try:
number = self._get_specials()[number]
except KeyError:
number -= 1
if number < 200:
comp = list_def(self._memobj.channel_attributes[number].compander,
COMPANDER_LIST, 0)
else:
comp = 0
val = RadioSettingValueList(COMPANDER_LIST, None, comp)
rs = RadioSetting("compander", "Compander (Compnd)", val)
mem.extra.append(rs)
return mem
def _set_mem_mode(self, _mem, mode):
tmp_mode = self.get_features().valid_modes.index(mode)
_mem.modulation = tmp_mode / 2
_mem.bandwidth = tmp_mode % 2
if mode == "USB":
_mem.bandwidth = 1 # narrow
def set_memory(self, mem):
super().set_memory(mem)
try:
number = self._get_specials()[mem.number]
except KeyError:
number = mem.number - 1
if number < 200 and 'compander' in mem.extra:
self._memobj.channel_attributes[number].compander = (
COMPANDER_LIST.index(str(mem.extra['compander'].value)))
def set_settings(self, settings):
_mem = self._memobj
for element in settings:
if not isinstance(element, RadioSetting):
self.set_settings(element)
continue
elname = element.get_name()
# basic settings
# VFO_A e80 ScreenChannel_A
if elname == "VFO_A_chn":
_mem.ScreenChannel_A = element.value
if _mem.ScreenChannel_A < 200:
_mem.MrChannel_A = _mem.ScreenChannel_A
elif _mem.ScreenChannel_A < 207:
_mem.FreqChannel_A = _mem.ScreenChannel_A
else:
_mem.NoaaChannel_A = _mem.ScreenChannel_A
# VFO_B e83
elif elname == "VFO_B_chn":
_mem.ScreenChannel_B = element.value
if _mem.ScreenChannel_B < 200:
_mem.MrChannel_B = _mem.ScreenChannel_B
elif _mem.ScreenChannel_B < 207:
_mem.FreqChannel_B = _mem.ScreenChannel_B
else:
_mem.NoaaChannel_B = _mem.ScreenChannel_B
# TX_VFO channel selected A,B
elif elname == "TX_VFO":
_mem.TX_VFO = element.value
# call channel
elif elname == "call_channel":
_mem.call_channel = element.value
# squelch
elif elname == "squelch":
_mem.squelch = element.value
# TOT
elif elname == "tot":
_mem.max_talk_time = element.value
# NOAA autoscan
elif elname == "noaa_autoscan":
_mem.noaa_autoscan = element.value
# VOX
elif elname == "vox":
voxvalue = int(element.value)
_mem.vox_switch = voxvalue > 0
_mem.vox_level = (voxvalue - 1) if _mem.vox_switch else 0
# mic gain
elif elname == "mic_gain":
_mem.mic_gain = element.value
# Channel display mode
elif elname == "channel_display_mode":
_mem.channel_display_mode = element.value
# RX Mode
elif elname == "rx_mode":
tmptxmode = int(element.value)
tmpmainvfo = _mem.TX_VFO + 1
_mem.crossband = tmpmainvfo * bool(tmptxmode & 0b10)
_mem.dual_watch = tmpmainvfo * bool(tmptxmode & 0b01)
# Battery Save
elif elname == "battery_save":
_mem.battery_save = element.value
# Backlight auto mode
elif elname == "backlight_time":
_mem.backlight_time = element.value
# Backlight min
elif elname == "backlight_min":
_mem.backlight_min = element.value
# Backlight max
elif elname == "backlight_max":
_mem.backlight_max = element.value
# Backlight TX_RX
elif elname == "backlight_on_TX_RX":
_mem.backlight_on_TX_RX = element.value
# AM_fix
elif elname == "AM_fix":
_mem.AM_fix = element.value
# mic_bar
elif elname == "mem.mic_bar":
_mem.mic_bar = element.value
# Batterie txt
elif elname == "_mem.battery_text":
_mem.battery_text = element.value
# Tail tone elimination
elif elname == "ste":
_mem.ste = element.value
# VFO Open
elif elname == "freq_mode_allowed":
_mem.freq_mode_allowed = element.value
# Beep control
elif elname == "button_beep":
_mem.button_beep = element.value
# Scan resume mode
elif elname == "scan_resume_mode":
_mem.scan_resume_mode = element.value
# Keypad lock
elif elname == "key_lock":
_mem.key_lock = element.value
# Auto keypad lock
elif elname == "auto_keypad_lock":
_mem.auto_keypad_lock = element.value
# Power on display mode
elif elname == "welcome_mode":
_mem.power_on_dispmode = element.value
# Keypad Tone
elif elname == "voice":
_mem.voice = element.value
elif elname == "s0_level":
_mem.s0_level = element.value * -1
elif elname == "s9_level":
_mem.s9_level = element.value * -1
elif elname == "password":
if element.value.get_value() is None or element.value == "":
_mem.password = 0xFFFFFFFF
else:
_mem.password = element.value
# Alarm mode
elif elname == "alarm_mode":
_mem.alarm_mode = element.value
# Reminding of end of talk
elif elname == "roger_beep":
_mem.roger_beep = element.value
# Repeater tail tone elimination
elif elname == "rp_ste":
_mem.rp_ste = element.value
# Logo string 1
elif elname == "logo1":
bts = str(element.value).rstrip("\x20\xff\x00")+"\x00" * 12
_mem.logo_line1 = bts[0:12] + "\x00\xff\xff\xff"
# Logo string 2
elif elname == "logo2":
bts = str(element.value).rstrip("\x20\xff\x00")+"\x00" * 12
_mem.logo_line2 = bts[0:12] + "\x00\xff\xff\xff"
# unlock settings
# FLOCK
elif elname == "int_flock":
_mem.int_flock = element.value
# 350TX
elif elname == "int_350tx":
_mem.int_350tx = element.value
# KILLED
elif elname == "int_KILLED":
_mem.int_KILLED = element.value
# 200TX
elif elname == "int_200tx":
_mem.int_200tx = element.value
# 500TX
elif elname == "int_500tx":
_mem.int_500tx = element.value
# 350EN
elif elname == "int_350en":
_mem.int_350en = element.value
# SCREN
elif elname == "int_scren":
_mem.int_scren = element.value
# battery type
elif elname == "Battery_type":
_mem.Battery_type = element.value
# fm radio
for i in range(1, 21):
freqname = "FM_%i" % i
if elname == freqname:
val = str(element.value).strip()
try:
val2 = int(float(val) * 10)
except Exception:
val2 = 0xffff
if val2 < FMMIN * 10 or val2 > FMMAX * 10:
val2 = 0xffff
# raise errors.InvalidValueError(
# "FM radio frequency should be a value "
# "in the range %.1f - %.1f" % (FMMIN , FMMAX))
_mem.fmfreq[i-1] = val2
# dtmf settings
if elname == "dtmf_side_tone":
_mem.dtmf.side_tone = element.value
elif elname == "dtmf_separate_code":
_mem.dtmf.separate_code = element.value
elif elname == "dtmf_group_call_code":
_mem.dtmf.group_call_code = element.value
elif elname == "dtmf_decode_response":
_mem.dtmf.decode_response = element.value
elif elname == "dtmf_auto_reset_time":
_mem.dtmf.auto_reset_time = element.value
elif elname == "dtmf_preload_time":
_mem.dtmf.preload_time = element.value // 10
elif elname == "dtmf_first_code_persist_time":
_mem.dtmf.first_code_persist_time = element.value // 10
elif elname == "dtmf_hash_persist_time":
_mem.dtmf.hash_persist_time = element.value // 10
elif elname == "dtmf_code_persist_time":
_mem.dtmf.code_persist_time = element.value // 10
elif elname == "dtmf_code_interval_time":
_mem.dtmf.code_interval_time = element.value // 10
elif elname == "dtmf_permit_remote_kill":
_mem.dtmf.permit_remote_kill = element.value
elif elname == "dtmf_dtmf_local_code":
k = str(element.value).rstrip("\x20\xff\x00") + "\x00" * 3
_mem.dtmf.local_code = k[0:3]
elif elname == "dtmf_dtmf_up_code":
k = str(element.value).strip("\x20\xff\x00") + "\x00" * 16
_mem.dtmf.up_code = k[0:16]
elif elname == "dtmf_dtmf_down_code":
k = str(element.value).rstrip("\x20\xff\x00") + "\x00" * 16
_mem.dtmf.down_code = k[0:16]
elif elname == "dtmf_kill_code":
k = str(element.value).strip("\x20\xff\x00") + "\x00" * 5
_mem.dtmf.kill_code = k[0:5]
elif elname == "dtmf_revive_code":
k = str(element.value).strip("\x20\xff\x00") + "\x00" * 5
_mem.dtmf.revive_code = k[0:5]
elif elname == "live_DTMF_decoder":
_mem.live_DTMF_decoder = element.value
# dtmf contacts
for i in range(1, 17):
varname = "DTMF_%i" % i
if elname == varname:
k = str(element.value).rstrip("\x20\xff\x00") + "\x00" * 8
_mem.dtmfcontact[i-1].name = k[0:8]
varnumname = "DTMFNUM_%i" % i
if elname == varnumname:
k = str(element.value).rstrip("\x20\xff\x00") + "\xff" * 3
_mem.dtmfcontact[i-1].number = k[0:3]
# scanlist stuff
if elname == "slDef":
_mem.slDef = element.value
elif elname == "sl1PriorEnab":
_mem.sl1PriorEnab = element.value
elif elname == "sl2PriorEnab":
_mem.sl2PriorEnab = element.value
elif elname in ["sl1PriorCh1", "sl1PriorCh2", "sl2PriorCh1",
"sl2PriorCh2"]:
val = int(element.value)
if val > 200 or val < 1:
val = 0xff
else:
val -= 1
_mem[elname] = val
if elname == "key1_shortpress_action":
_mem.key1_shortpress_action = \
KEYACTIONS_LIST.index(element.value)
elif elname == "key1_longpress_action":
_mem.key1_longpress_action = \
KEYACTIONS_LIST.index(element.value)
elif elname == "key2_shortpress_action":
_mem.key2_shortpress_action = \
KEYACTIONS_LIST.index(element.value)
elif elname == "key2_longpress_action":
_mem.key2_longpress_action = \
KEYACTIONS_LIST.index(element.value)
elif elname == "keyM_longpress_action":
_mem.keyM_longpress_action = \
KEYACTIONS_LIST.index(element.value)
elif elname == "upload_calibration":
self._upload_calibration = bool(element.value)
elif element.changed() and elname.startswith("cal."):
_mem.get_path(elname).set_value(element.value)
def get_settings(self):
_mem = self._memobj
basic = RadioSettingGroup("basic", "Basic Settings")
advanced = RadioSettingGroup("advanced", "Advanced Settings")
keya = RadioSettingGroup("keya", "Programmable Keys")
dtmf = RadioSettingGroup("dtmf", "DTMF Settings")
dtmfc = RadioSettingGroup("dtmfc", "DTMF Contacts")
scanl = RadioSettingGroup("scn", "Scan Lists")
unlock = RadioSettingGroup("unlock", "Unlock Settings")
fmradio = RadioSettingGroup("fmradio", "FM Radio")
calibration = RadioSettingGroup("calibration", "Calibration")
roinfo = RadioSettingGroup("roinfo", "Driver Information")
top = RadioSettings()
top.append(basic)
top.append(advanced)
top.append(keya)
top.append(dtmf)
if _mem.BUILD_OPTIONS.ENABLE_DTMF_CALLING:
top.append(dtmfc)
top.append(scanl)
top.append(unlock)
if _mem.BUILD_OPTIONS.ENABLE_FMRADIO:
top.append(fmradio)
top.append(roinfo)
top.append(calibration)
# helper function
def append_label(radio_setting, label, descr=""):
if not hasattr(append_label, 'idx'):
append_label.idx = 0
val = RadioSettingValueString(len(descr), len(descr), descr)
val.set_mutable(False)
rs = RadioSetting("label%s" % append_label.idx, label, val)
append_label.idx += 1
radio_setting.append(rs)
# Programmable keys
def get_action(action_num):
""""get actual key action"""
lst = KEYACTIONS_LIST.copy()
if not self._memobj.BUILD_OPTIONS.ENABLE_ALARM:
lst.remove("Alarm")
if not self._memobj.BUILD_OPTIONS.ENABLE_TX1750:
lst.remove("1750Hz tone")
if not self._memobj.BUILD_OPTIONS.ENABLE_FLASHLIGHT:
lst.remove("Flashlight")
if not self._memobj.BUILD_OPTIONS.ENABLE_VOX:
lst.remove("VOX")
if not self._memobj.BUILD_OPTIONS.ENABLE_FMRADIO:
lst.remove("FM broadcast radio")
if not self._memobj.BUILD_OPTIONS.ENABLE_BLMIN_TMP_OFF:
lst.remove("Min backlight temporary off")
if not self._memobj.BUILD_OPTIONS.ENABLE_SPECTRUM:
lst.remove("Spectrum analyzer")
action_num = int(action_num)
if action_num >= len(KEYACTIONS_LIST) or \
KEYACTIONS_LIST[action_num] not in lst:
action_num = 0
return lst, KEYACTIONS_LIST[action_num]
val = RadioSettingValueList(*get_action(_mem.key1_shortpress_action))
rs = RadioSetting("key1_shortpress_action",
"Side key 1 short press (F1Shrt)", val)
keya.append(rs)
val = RadioSettingValueList(*get_action(_mem.key1_longpress_action))
rs = RadioSetting("key1_longpress_action",
"Side key 1 long press (F1Long)", val)
keya.append(rs)
val = RadioSettingValueList(*get_action(_mem.key2_shortpress_action))
rs = RadioSetting("key2_shortpress_action",
"Side key 2 short press (F2Shrt)", val)
keya.append(rs)
val = RadioSettingValueList(*get_action(_mem.key2_longpress_action))
rs = RadioSetting("key2_longpress_action",
"Side key 2 long press (F2Long)", val)
keya.append(rs)
val = RadioSettingValueList(*get_action(_mem.keyM_longpress_action))
rs = RadioSetting("keyM_longpress_action",
"Menu key long press (M Long)", val)
keya.append(rs)
# ----------------- DTMF settings
tmpval = str(_mem.dtmf.separate_code)
if tmpval not in DTMF_CODE_CHARS:
tmpval = '*'
val = RadioSettingValueString(1, 1, tmpval)
val.set_charset(DTMF_CODE_CHARS)
sep_code_setting = RadioSetting("dtmf_separate_code",
"Separate Code", val)
tmpval = str(_mem.dtmf.group_call_code)
if tmpval not in DTMF_CODE_CHARS:
tmpval = '#'
val = RadioSettingValueString(1, 1, tmpval)
val.set_charset(DTMF_CODE_CHARS)