forked from armel/uv-k5-chirp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uvk5_egzumer_f4hwn_ver_3_2_0_fr.py
3331 lines (2706 loc) · 137 KB
/
uvk5_egzumer_f4hwn_ver_3_2_0_fr.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 <sq5bpf@lipkowski.org>
# Adapted For UV-K5 EGZUMER custom software By EGZUMER, JOC2
# Re-Adapted For UV-K5 EGZUMER/F4HWN custom software By JOC2
# First translated in french By F1ixx
#
# based on template.py Copyright 2012 Dan Smith <dsmith@danplanet.com>
#
#
# This is a preliminary version of a driver for the UV-K5
# It is based on my reverse engineering effort described here:
# https://github.com/sq5bpf/uvk5-reverse-engineering
#
# Warning: this driver is experimental, it may brick your radio,
# eat your lunch and mess up your configuration.
#
#
# 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/>.
# change/ modification
#
# 2024-02-09 :section password has been commented, because the new chirp give error with int.
# 2024-02-18 : a bug fix has been remove, that seem not work under mac os.. under investigation..
# search for (bugfix calibration)
#
#3.1.0: unknow bit change for specify name
# add web link
# explain how the change chirp language
# add User, low1 to low5 to the power level
# AM fix message information this has not change
# update info how to change language in chirp
# rename set_low to set pwr
# add the 3500ma battery selection
#3.2.0: some info still in english, translates it
# add web link in firmware
# add tx lock in all channel
# update link pdf for the 3.1 pdf instead of 3.0
import webbrowser
import os
import struct
import logging
import wx
from chirp import chirp_common, directory, bitwise, memmap, errors, util
from chirp.settings import RadioSetting, RadioSettingGroup, \
RadioSettingValueBoolean, RadioSettingValueList, \
RadioSettingValueInteger, RadioSettingValueString, \
RadioSettings, InvalidValueError
LOG = logging.getLogger(__name__)
# Show the obfuscated version of commands. Not needed normally, but
# might be useful for someone who is debugging a similar radio
DEBUG_SHOW_OBFUSCATED_COMMANDS = False
# Show the memory being written/received. Not needed normally, because
# this is the same information as in the packet hexdumps, but
# might be useful for someone debugging some obscure memory issue
DEBUG_SHOW_MEMORY_ACTIONS = False
# TODO: remove the driver version when it's in mainline chirp
DRIVER_VERSION = "Quansheng UV-K5/K6/5R driver ver: 2024/08/08 (c) EGZUMER + F4HWN v3.2.0 FR"
FIRMWARE_VERSION_UPDATE = "https://github.com/armel/uv-k5-firmware-custom/releases"
CHIRP_DRIVER_VERSION_UPDATE = "https://github.com/armel/uv-k5-chirp-driver/releases"
CHAINE_F4HWN = "https://www.youtube.com/@f4hwn"
PDF_FILE_ALAIN_UPDATE = "https://www.dropbox.com/scl/fi/6imqf9bb550a0a7605kjb/MENU-FIRMWARE-F4HWN-v3.2.pdf?rlkey=nw3cmpmqjqnoaglxjiyf6cjhb&e=1&dl=0"
PDF_FILE_QUICK_KEY = "https://github.com/armel/uv-k5-chirp-driver/blob/main/20240530%20Quick%20Keys%20F4HWNv%202.x.pdf"
YOUTUBE_INFO_FUNKWELLE = "https://www.youtube.com/watch?v=4xj0-VUe5aE"
YOUTUBE_INFO_M7FRS = "https://www.youtube.com/watch?v=duNB2xS208E"
YOUTUBE_INFO_PU4BLA = "https://www.youtube.com/watch?v=AEFwfQUq8YY"
YOUTUBE_INFO_R3MDG = "https://www.youtube.com/watch?v=DFMYwTIOUxk"
VALEUR_COMPILER = "ENABLE"
MEM_FORMAT = """
//#seekto 0x0000;
struct {
ul32 freq;
ul32 offset;
// 0x08
u8 rxcode;
u8 txcode;
// 0x0A
u8 txcodeflag:4,
rxcodeflag:4;
// 0x0B
u8 modulation:4,
offsetDir:4;
// 0x0C
u8 __UNUSED1:1,
txLock:1,
busyChLockout:1,
txpower:3,
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_scanlistx:3,
compander:2,
band:3;
} ch_attr[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 unknown_0xf19:5,
sl3PriorEnab:1,
sl2PriorEnab:1,
sl1PriorEnab:1;
u8 sl1PriorCh1;
u8 sl1PriorCh2;
u8 sl2PriorCh1;
u8 sl2PriorCh2;
u8 sl3PriorCh1;
u8 sl3PriorCh2;
#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_0xf47: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_BANDSCOPE:1,
ENABLE_AM_FIX:1,
ENABLE_BLMIN_TMP_OFF:1,
ENABLE_RAW_DEMODULATORS:1,
ENABLE_WIDE_RX:1,
ENABLE_FLASHLIGHT:1;
} BUILD_OPTIONS;
#seekto 0x1FF2;
u8 eeprom0x1ff2;
u8 eeprom0x1ff3;
u8 eeprom0x1ff4;
u8 set_gui:1,
set_met:1,
set_lck:1,
set_inv:1,
set_contrast:4;
u8 set_tot:4,
set_eot:4;
u8 set_pwr:4,
set_ptt:4;
u8 eeprom0x1ff8;
u8 eeprom0x1ff9;
u8 eeprom0x1ffa;
u8 eeprom0x1ffb;
u8 eeprom0x1ffc;
u8 eeprom0x1ffd;
u8 eeprom0x1ffe;
u8 eeprom0x1fff;
"""
# flags1
FLAGS1_OFFSET_NONE = 0b00
FLAGS1_OFFSET_MINUS = 0b10
FLAGS1_OFFSET_PLUS = 0b01
POWER_HIGH = 0b111
POWER_MEDIUM = 0b110
POWER_LOW5 = 0b101
POWER_LOW4 = 0b100
POWER_LOW3 = 0b011
POWER_LOW2 = 0b010
POWER_LOW1 = 0b001
POWER_USER = 0b000
# SET_LOW_POWER f4hwn
SET_LOW_LIST = [ "< 20mW", "125mW", "250mW", "500mW", "1W", "2W", "5W"]
# SET_PTT f4hwn
SET_PTT_LIST = ["CLASSIC", "ONEPUSH"]
# SET_TOT and SET_EOT f4hwn
SET_TOT_EOT_LIST = ["OFF", "SOUND", "VISUAL", "ALL"]
# SET_OFF_ON f4hwn
SET_OFF_ON_LIST = ["OFF", "ON"]
# SET_lck f4hwn
SET_LCK_LIST = ["KEYS", "KEYS+PTT"]
# SET_MET SET_GUI f4hwn
SET_MET_LIST = ["TINY", "CLASSIC"]
# dtmf_flags
PTTID_LIST = ["OFF", "UP CODE", "DOWN CODE", "UP+DOWN CODE", "APOLLO QUINDAR"]
# power
UVK5_POWER_LEVELS = [chirp_common.PowerLevel("USER = < 20mW a 5W", watts=0.000),
chirp_common.PowerLevel("LOW 1 = < 20mW", watts=0.020),
chirp_common.PowerLevel("LOW 2 = 125mW", watts=0.125),
chirp_common.PowerLevel("LOW 3 = 250mW", watts=0.250),
chirp_common.PowerLevel("LOW 4 = 500mW", watts=0.500),
chirp_common.PowerLevel("LOW 5 = 1W", watts=1.00),
chirp_common.PowerLevel("MID = 2W", watts=2.00),
chirp_common.PowerLevel("HIGH = 5W", 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", "CROSS BAND", "MAIN TX DUAL RX"]
# channel display mode
CHANNELDISP_LIST = ["Frequency (FREQ)", "CHANNEL NUMBER", "NAME", "Name + Frequency (NAME + FREQ)"]
# TalkTime
TALK_TIME_LIST = ["N/U", "N/U", "N/U", "N/U", "N/U", "30 sec", "35 sec", "40 sec", "45 sec", "50 sec", "55 sec",
"1 min", "1 min : 5 sec", "1 min : 10 sec", "1 min : 15 sec", "1 min : 20 sec", "1 min : 25 sec", "1 min : 30 sec", "1 min : 35 sec", "1 min : 40 sec", "1 min : 45 sec", "1 min : 50 sec", "1 min : 55 sec",
"2 min", "2 min : 5 sec", "2 min : 10 sec", "2 min : 15 sec", "2 min : 20 sec", "2 min : 25 sec", "2 min : 30 sec", "2 min : 35 sec", "2 min : 40 sec", "2 min : 45 sec", "2 min : 50 sec", "2 min : 55 sec",
"3 min", "3 min : 5 sec", "3 min : 10 sec", "3 min : 15 sec", "3 min : 20 sec", "3 min : 25 sec", "3 min : 30 sec", "3 min : 35 sec", "3 min : 40 sec", "3 min : 45 sec", "3 min : 50 sec", "3 min : 55 sec",
"4 min", "4 min : 5 sec", "4 min : 10 sec", "4 min : 15 sec", "4 min : 20 sec", "4 min : 25 sec", "4 min : 30 sec", "4 min : 35 sec", "4 min : 40 sec", "4 min : 45 sec", "4 min : 50 sec", "4 min : 55 sec",
"5 min", "5 min : 5 sec", "5 min : 10 sec", "5 min : 15 sec", "5 min : 20 sec", "5 min : 25 sec", "5 min : 30 sec", "5 min : 35 sec", "5 min : 40 sec", "5 min : 45 sec", "5 min : 50 sec", "5 min : 55 sec",
"6 min", "6 min : 5 sec", "6 min : 10 sec", "6 min : 15 sec", "6 min : 20 sec", "6 min : 25 sec", "6 min : 30 sec", "6 min : 35 sec", "6 min : 40 sec", "6 min : 45 sec", "6 min : 50 sec", "6 min : 55 sec",
"7 min", "7 min : 5 sec", "7 min : 10 sec", "7 min : 15 sec", "7 min : 20 sec", "7 min : 25 sec", "7 min : 30 sec", "7 min : 35 sec", "7 min : 40 sec", "7 min : 45 sec", "7 min : 50 sec", "7 min : 55 sec",
"8 min", "8 min : 5 sec", "8 min : 10 sec", "8 min : 15 sec", "8 min : 20 sec", "8 min : 25 sec", "8 min : 30 sec", "8 min : 35 sec", "8 min : 40 sec", "8 min : 45 sec", "8 min : 50 sec", "8 min : 55 sec",
"9 min", "9 min : 5 sec", "9 min : 10 sec", "9 min : 15 sec", "9 min : 20 sec", "9 min : 25 sec", "9 min : 30 sec", "9 min : 35 sec", "9 min : 40 sec", "9 min : 45 sec", "9 min : 50 sec", "9 min : 55 sec",
"10 min", "10 min : 5 sec", "10 min : 10 sec", "10 min : 15 sec", "10 min : 20 sec", "10 min : 25 sec", "10 min : 30 sec", "10 min : 35 sec", "10 min : 40 sec", "10 min : 45 sec", "10 min : 50 sec", "10 min : 55 sec",
"11 min", "11 min : 5 sec", "11 min : 10 sec", "11 min : 15 sec", "11 min : 20 sec", "11 min : 25 sec", "11 min : 30 sec", "11 min : 35 sec", "11 min : 40 sec", "11 min : 45 sec", "11 min : 50 sec", "11 min : 55 sec",
"12 min", "12 min : 5 sec", "12 min : 10 sec", "12 min : 15 sec", "12 min : 20 sec", "12 min : 25 sec", "12 min : 30 sec", "12 min : 35 sec", "12 min : 40 sec", "12 min : 45 sec", "12 min : 50 sec", "12 min : 55 sec",
"13 min", "13 min : 5 sec", "13 min : 10 sec", "13 min : 15 sec", "13 min : 20 sec", "13 min : 25 sec", "13 min : 30 sec", "13 min : 35 sec", "13 min : 40 sec", "13 min : 45 sec", "13 min : 50 sec", "13 min : 55 sec",
"14 min", "14 min : 5 sec", "14 min : 10 sec", "14 min : 15 sec", "14 min : 20 sec", "14 min : 25 sec", "14 min : 30 sec", "14 min : 35 sec", "14 min : 40 sec", "14 min : 45 sec", "14 min : 50 sec", "14 min : 55 sec",
"15 min"]
# Auto Keypad Lock
AUTO_KEYPAD_LOCK_LIST = ["OFF", "AUTO"]
# battery save
BATSAVE_LIST = ["OFF", "1:1", "1:2", "1:3", "1:4"]
# battery type
BATTYPE_LIST = ["1600 mAh", "2200 mAh", "3500 mAh"]
# bat txt
BAT_TXT_LIST = ["NONE", "VOLTAGE", "PERCENT"]
# Backlight auto mode
BACKLIGHT_LIST = ["OFF", "5 sec", "10 sec", "15 sec", "20 sec", "25 sec", "30 sec", "35 sec", "40 sec", "45 sec", "50 sec", "55 sec",
"1 min", "1 min : 5 sec", "1 min : 10 sec", "1 min : 15 sec", "1 min : 20 sec", "1 min : 25 sec", "1 min : 30 sec", "1 min : 35 sec", "1 min : 40 sec", "1 min : 45 sec", "1 min : 50 sec", "1 min : 55 sec",
"2 min", "2 min : 5 sec", "2 min : 10 sec", "2 min : 15 sec", "2 min : 20 sec", "2 min : 25 sec", "2 min : 30 sec", "2 min : 35 sec", "2 min : 40 sec", "2 min : 45 sec", "2 min : 50 sec", "2 min : 55 sec",
"3 min", "3 min : 5 sec", "3 min : 10 sec", "3 min : 15 sec", "3 min : 20 sec", "3 min : 25 sec", "3 min : 30 sec", "3 min : 35 sec", "3 min : 40 sec", "3 min : 45 sec", "3 min : 50 sec", "3 min : 55 sec",
"4 min", "4 min : 5 sec", "4 min : 10 sec", "4 min : 15 sec", "4 min : 20 sec", "4 min : 25 sec", "4 min : 30 sec", "4 min : 35 sec", "4 min : 40 sec", "4 min : 45 sec", "4 min : 50 sec", "4 min : 55 sec",
"5 min", "Always On (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"]
# steps TODO: change order
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]
# ctcss/dcs codes
TMODES = ["", "Tone", "DTCS", "DTCS"]
TONE_NONE = 0
TONE_CTCSS = 1
TONE_DCS = 2
TONE_RDCS = 3
CTCSS_TONES = [
67.0, 69.3, 71.9, 74.4, 77.0, 79.7, 82.5, 85.4,
88.5, 91.5, 94.8, 97.4, 100.0, 103.5, 107.2, 110.9,
114.8, 118.8, 123.0, 127.3, 131.8, 136.5, 141.3, 146.2,
151.4, 156.7, 159.8, 162.2, 165.5, 167.9, 171.3, 173.8,
177.3, 179.9, 183.5, 186.2, 189.9, 192.8, 196.6, 199.5,
203.5, 206.5, 210.7, 218.1, 225.7, 229.1, 233.6, 241.8,
250.3, 254.1
]
# lifted from ft4.py
DTCS_CODES = [ # TODO: add negative codes
23, 25, 26, 31, 32, 36, 43, 47, 51, 53, 54,
65, 71, 72, 73, 74, 114, 115, 116, 122, 125, 131,
132, 134, 143, 145, 152, 155, 156, 162, 165, 172, 174,
205, 212, 223, 225, 226, 243, 244, 245, 246, 251, 252,
255, 261, 263, 265, 266, 271, 274, 306, 311, 315, 325,
331, 332, 343, 346, 351, 356, 364, 365, 371, 411, 412,
413, 423, 431, 432, 445, 446, 452, 454, 455, 462, 464,
465, 466, 503, 506, 516, 523, 526, 532, 546, 565, 606,
612, 624, 627, 631, 632, 654, 662, 664, 703, 712, 723,
731, 732, 734, 743, 754
]
# flock list extended
FLOCK_LIST = ["DEFAULT+ (137-174, 400-470 + Tx200, Tx350, Tx500)",
"FCC HAM (144-148, 420-450)",
"CA HAM (144-148, 430-450)",
"CE HAM (144-146, 430-440)",
"GB HAM (144-148, 430-440)",
"137-174, 400-430",
"137-174, 400-438",
"PMR 446",
"GMRS FRS MURS",
"DISABLE ALL",
"UNLOCK ALL"]
SCANRESUME_LIST = ["Ecouter 5 seconds et reprendre scan (TIMEOUT)",
"Ecouter jusqu'a ce qu\'il n\'y aie plus de signal (CARRIER)",
"Arret du SCAN a la reception d'un signal (STOP)"]
WELCOME_LIST = ["Message 1 + Tension + Son (ALL)", "Bips (SOUND)", "Message 1 et Message 2 (MESSAGE)", "Tension de la Batterie (VOLTAGE)", "Rien (NONE)"]
VOICE_LIST = ["OFF", "Chinese", "English"]
# ACTIVE CHANNEL
TX_VFO_LIST = ["A", "B"]
ALARMMODE_LIST = ["SITE", "TONE"]
ROGER_LIST = ["OFF", "Bip Roger (ROGER)", "Bruit de donnees (MDC)"]
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"]
MEM_SIZE = 0x2000 # size of all memory
PROG_SIZE = 0x1d00 # size of the memory that we will write
MEM_BLOCK = 0x80 # largest block of memory that we can reliably write
CAL_START = 0x1E00 # calibration memory start address
F4HWN_START =0x1FF2 # calibration F4HWN memory start address
# 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_LIST = ["Aucune ", "List [1]", "List [2]", "List [1, 2]", "List [3]", "List [1, 3]", "List [2, 3]", "Toutes les Lists [1, 2, 3]"]
SCANLIST_SELECT_LIST = ["LIST [0] Aucune LIST ", "LIST [1]", "LIST [2]", "LIST [3]", "LISTS [1, 2, 3]", "Tout les Channel (ALL)"]
DTMF_CHARS = "0123456789ABCD*# "
DTMF_CHARS_ID = "0123456789ABCDabcd"
DTMF_CHARS_KILL = "0123456789ABCDabcd"
DTMF_CHARS_UPDOWN = "0123456789ABCDabcd#* "
DTMF_CODE_CHARS = "ABCD*# "
DTMF_DECODE_RESPONSE_LIST = ["NONE", "Sonnerie locale (RING)", "Replay response (REPLAY)",
"Sonnerie local + reply response (BOTH)"]
KEYACTIONS_LIST = ["NONE",
"FLASHLIGHT",
"POWER",
"MONITOR",
"SCAN",
"Fonction VOX (VOX)",
"ALARM",
"FM RADIO",
"1750Hz TONE",
"LOCK KEYPAD",
"Bascule de VFO A/B (Haut/Bas) (VFO A / VFO B)",
"Bascule mode Frequence/Memoire (VFO / MEM)",
"Bascule le Mode (MODE)",
"Eteindre l\'ecran (BLMIN TMP OFF)",
"Bascule mode Reception *Main only,*Dual RX,*Cross Band,*TX Dual RX (RX MODE)",
"MAIN ONLY",
"Bascule le mode PTT (PTT)",
"Bascule le filtre BF (WIDE / NARROW)"
]
MIC_GAIN_LIST = ["+1.1dB", "+4.0dB", "+8.0dB", "+12.0dB", "+15.1dB"]
def xorarr(data: bytes):
"""the communication is obfuscated using this fine mechanism"""
tbl = [22, 108, 20, 230, 46, 145, 13, 64, 33, 53, 213, 64, 19, 3, 233, 128]
ret = b""
idx = 0
for byte in data:
ret += bytes([byte ^ tbl[idx]])
idx = (idx+1) % len(tbl)
return ret
def calculate_crc16_xmodem(data: bytes):
"""
if this crc was used for communication to AND from the radio, then it
would be a measure to increase reliability.
but it's only used towards the radio, so it's for further obfuscation
"""
poly = 0x1021
crc = 0x0
for byte in data:
crc = crc ^ (byte << 8)
for _ in range(8):
crc = crc << 1
if crc & 0x10000:
crc = (crc ^ poly) & 0xFFFF
return crc & 0xFFFF
def _send_command(serport, data: bytes):
"""Send a command to UV-K5 radio"""
LOG.debug("Sending command (unobfuscated) len=0x%4.4x:\n%s",
len(data), util.hexprint(data))
crc = calculate_crc16_xmodem(data)
data2 = data + struct.pack("<H", crc)
command = struct.pack(">HBB", 0xabcd, len(data), 0) + \
xorarr(data2) + \
struct.pack(">H", 0xdcba)
if DEBUG_SHOW_OBFUSCATED_COMMANDS:
LOG.debug("Sending command (obfuscated):\n%s", util.hexprint(command))
try:
result = serport.write(command)
except Exception as e:
raise errors.RadioError("Error writing data to radio") from e
return result
def _receive_reply(serport):
header = serport.read(4)
if len(header) != 4:
LOG.warning("Header short read: [%s] len=%i",
util.hexprint(header), len(header))
raise errors.RadioError("Header short read")
if header[0] != 0xAB or header[1] != 0xCD or header[3] != 0x00:
LOG.warning("Bad response header: %s len=%i",
util.hexprint(header), len(header))
raise errors.RadioError("Bad response header")
cmd = serport.read(int(header[2]))
if len(cmd) != int(header[2]):
LOG.warning("Body short read: [%s] len=%i",
util.hexprint(cmd), len(cmd))
raise errors.RadioError("Command body short read")
footer = serport.read(4)
if len(footer) != 4:
LOG.warning("Footer short read: [%s] len=%i",
util.hexprint(footer), len(footer))
raise errors.RadioError("Footer short read")
if footer[2] != 0xDC or footer[3] != 0xBA:
LOG.debug("Reply before bad response footer (obfuscated)"
"len=0x%4.4x:\n%s", len(cmd), util.hexprint(cmd))
LOG.warning("Bad response footer: %s len=%i",
util.hexprint(footer), len(footer))
raise errors.RadioError("Bad response footer")
if DEBUG_SHOW_OBFUSCATED_COMMANDS:
LOG.debug("Received reply (obfuscated) len=0x%4.4x:\n%s",
len(cmd), util.hexprint(cmd))
cmd2 = xorarr(cmd)
LOG.debug("Received reply (unobfuscated) len=0x%4.4x:\n%s",
len(cmd2), util.hexprint(cmd2))
return cmd2
def _getstring(data: bytes, begin, maxlen):
tmplen = min(maxlen+1, len(data))
ss = [data[i] for i in range(begin, tmplen)]
key = 0
for key, val in enumerate(ss):
if val < ord(' ') or val > ord('~'):
return ''.join(chr(x) for x in ss[0:key])
return ''
def _sayhello(serport):
hellopacket = b"\x14\x05\x04\x00\x6a\x39\x57\x64"
tries = 5
while True:
LOG.debug("Sending hello packet")
_send_command(serport, hellopacket)
rep = _receive_reply(serport)
if rep:
break
tries -= 1
if tries == 0:
LOG.warning("Failed to initialise radio")
raise errors.RadioError("Failed to initialize radio")
if rep.startswith(b'\x18\x05'):
raise errors.RadioError("Radio is in programming mode, "
"restart radio into normal mode")
firmware = _getstring(rep, 4, 24)
LOG.info("Found firmware: %s", firmware)
return firmware
def _readmem(serport, offset, length):
LOG.debug("Sending readmem offset=0x%4.4x len=0x%4.4x", offset, length)
readmem = b"\x1b\x05\x08\x00" + \
struct.pack("<HBB", offset, length, 0) + \
b"\x6a\x39\x57\x64"
_send_command(serport, readmem)
rep = _receive_reply(serport)
if DEBUG_SHOW_MEMORY_ACTIONS:
LOG.debug("readmem Received data len=0x%4.4x:\n%s",
len(rep), util.hexprint(rep))
return rep[8:]
def _writemem(serport, data, offset):
LOG.debug("Sending writemem offset=0x%4.4x len=0x%4.4x",
offset, len(data))
if DEBUG_SHOW_MEMORY_ACTIONS:
LOG.debug("writemem sent data offset=0x%4.4x len=0x%4.4x:\n%s",
offset, len(data), util.hexprint(data))
dlen = len(data)
writemem = b"\x1d\x05" + \
struct.pack("<BBHBB", dlen+8, 0, offset, dlen, 1) + \
b"\x6a\x39\x57\x64"+data
_send_command(serport, writemem)
rep = _receive_reply(serport)
LOG.debug("writemem Received data: %s len=%i",
util.hexprint(rep), len(rep))
if (rep[0] == 0x1e and
rep[4] == (offset & 0xff) and
rep[5] == (offset >> 8) & 0xff):
return True
LOG.warning("Bad data from writemem")
raise errors.RadioError("Bad response to writemem")
def _resetradio(serport):
resetpacket = b"\xdd\x05\x00\x00"
_send_command(serport, resetpacket)
def do_download(radio):
"""download eeprom from radio"""
serport = radio.pipe
serport.timeout = 0.5
status = chirp_common.Status()
status.cur = 0
status.max = MEM_SIZE
status.msg = "Telechargement de la radio"
radio.status_fn(status)
eeprom = b""
f = _sayhello(serport)
if f:
radio.FIRMWARE_VERSION = f
else:
raise errors.RadioError("Erreur d'initialisation de la radio")
addr = 0
while addr < MEM_SIZE:
data = _readmem(serport, addr, MEM_BLOCK)
status.cur = addr
radio.status_fn(status)
if data and len(data) == MEM_BLOCK:
eeprom += data
addr += MEM_BLOCK
else:
raise errors.RadioError("Telechargement memoire incomplete")
return memmap.MemoryMapBytes(eeprom)
def do_upload(radio):
"""upload configuration to radio eeprom"""
serport = radio.pipe
serport.timeout = 0.5
status = chirp_common.Status()
status.cur = 0
status.msg = "Uploading to radio"
if radio.upload_f4hwn:
status.max = MEM_SIZE-F4HWN_START
start_addr = F4HWN_START
stop_addr = MEM_SIZE
else:
if radio.upload_calibration:
status.max = F4HWN_START-CAL_START
start_addr = CAL_START
stop_addr = F4HWN_START
else:
status.max = PROG_SIZE
start_addr = 0
stop_addr = PROG_SIZE
radio.status_fn(status)
f = _sayhello(serport)
if f:
radio.FIRMWARE_VERSION = f
else:
return False
addr = start_addr
while addr < stop_addr:
dat = radio.get_mmap()[addr:addr+MEM_BLOCK]
_writemem(serport, dat, addr)
status.cur = addr - start_addr
radio.status_fn(status)
if dat:
addr += MEM_BLOCK
else:
raise errors.RadioError("Envoie des donnees incomplete")
status.msg = "Uploaded OK"
_resetradio(serport)
return True
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
class UVK5RadioEgzumer(chirp_common.CloneModeRadio):
"""Quansheng UV-K5 (egzumer + f4hwn)"""
VENDOR = "Quansheng"
MODEL = "UV-K5 (egzumer + f4hwn) FR"
BAUD_RATE = 38400
NEEDS_COMPAT_SERIAL = False
FIRMWARE_VERSION = ""
# this change to send power level chan in the calibration but under macos it give error
# bugfix calibration : put in comment next line: upload_calibration = False
upload_calibration = False
upload_f4hwn = False
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
@classmethod
def get_prompts(cls):
rp = chirp_common.RadioPrompts()
rp.experimental = \
'Ceci est un pilote experimental pour le Quansheng UV-K5.\n' \
'Celui-ci peut endomager les reglages de votre radio ou pire. L\'utilisation est a vos risques.\n' \
'Avant de faire n\'import quel changement, faites une sauvegarde des parametres avec chirp\n' \
'et garder la intacte. Cela peut etre utilse pour restaurer les reglages d\'origine.\n\n' \
'Quelque detail ne sont pas encore implante ou fonctionelle.'
rp.pre_download = \
"1. Allumez la radio. ( sans tenir aucun bouton enfoncer )\n" \
"2. Connectez le cable sur le connecteur Haut-Parleur/Micro.\n" \
"3. ASSUREZ vous que le connecteur et bien enfoncer.\n" \
"4. Cliquer sur OK pour telecharger l\'image de votre radio.\n\n" \
"Cela peut ne pas fonctionner si vous allumer la radio " \
"avec le cordon deja connecter.\n"
rp.pre_upload = \
"1. Allumez la radio.( sans tenir aucun bouton enfoncer )\n" \
"2. Connectez le cable sur le connecteur Haut-Parleur/Micro.\n" \
"3. ASSUREZ vous que le connecteur et bien enfoncer.\n" \
"4. Cliquer sur OK pour envoyer l'image vers la radio.\n\n" \
"Cela peut ne pas fonctionner si vous allumer la radio " \
"avec le cordon deja connecter.\n"
return rp
# Return information about this radio's features, including
# how many memories it has, what bands it supports, etc
def get_features(self):
rf = chirp_common.RadioFeatures()
rf.has_bank = False
rf.valid_dtcs_codes = DTCS_CODES
rf.has_rx_dtcs = True
rf.has_ctone = True
rf.has_settings = True
rf.has_comment = False
rf.valid_name_length = 10
rf.valid_power_levels = UVK5_POWER_LEVELS
rf.valid_special_chans = self._get_vfo_channel_names()
rf.valid_duplexes = ["", "-", "+", "off"]
steps = STEPS.copy()
steps.sort()
rf.valid_tuning_steps = steps
rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"]
rf.valid_cross_modes = ["Tone->Tone", "Tone->DTCS", "DTCS->Tone",
"->Tone", "->DTCS", "DTCS->", "DTCS->DTCS"]
rf.valid_characters = chirp_common.CHARSET_ASCII
rf.valid_modes = ["FM", "NFM", "AM", "NAM", "USB"]
rf.valid_skips = [""]
# This radio supports memories 1-200, 201-214 are the VFO memories