-
Notifications
You must be signed in to change notification settings - Fork 173
/
kenwood_live.py
1569 lines (1333 loc) · 52.2 KB
/
kenwood_live.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
# Copyright 2010 Dan Smith <dsmith@danplanet.com>
#
# 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 3 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 threading
import os
import sys
import time
import logging
from chirp import chirp_common, errors, directory, util
from chirp.settings import RadioSetting, RadioSettingGroup, \
RadioSettingValueInteger, RadioSettingValueBoolean, \
RadioSettingValueString, RadioSettingValueList, RadioSettings
LOG = logging.getLogger(__name__)
NOCACHE = "CHIRP_NOCACHE" in os.environ
DUPLEX = {0: "", 1: "+", 2: "-"}
MODES = {0: "FM", 1: "AM"}
STEPS = list(chirp_common.TUNING_STEPS)
STEPS.append(100.0)
KENWOOD_TONES = list(chirp_common.TONES)
KENWOOD_TONES.remove(159.8)
KENWOOD_TONES.remove(165.5)
KENWOOD_TONES.remove(171.3)
KENWOOD_TONES.remove(177.3)
KENWOOD_TONES.remove(183.5)
KENWOOD_TONES.remove(189.9)
KENWOOD_TONES.remove(196.6)
KENWOOD_TONES.remove(199.5)
THF6_MODES = ["FM", "WFM", "AM", "LSB", "USB", "CW"]
RADIO_IDS = {
"ID019": "TS-2000",
"ID009": "TS-850",
"ID020": "TS-480_LiveMode",
"ID021": "TS-590S/SG_LiveMode", # S-model uses same class
"ID023": "TS-590S/SG_LiveMode" # as SG
}
LOCK = threading.Lock()
COMMAND_RESP_BUFSIZE = 8
LAST_BAUD = 4800
LAST_DELIMITER = ("\r", " ")
# The Kenwood TS-2000, TS-480, TS-590 & TS-850 use ";"
# as a CAT command message delimiter, and all others use "\n".
# Also, TS-2000 and TS-590 don't space delimite the command
# fields, but others do.
def _command(ser, cmd, *args):
"""Send @cmd to radio via @ser"""
global LOCK, LAST_DELIMITER, COMMAND_RESP_BUFSIZE
start = time.time()
# TODO: This global use of LAST_DELIMITER breaks reentrancy
# and needs to be fixed.
if args:
cmd += LAST_DELIMITER[1] + LAST_DELIMITER[1].join(args)
cmd += LAST_DELIMITER[0]
LOG.debug("PC->RADIO: %s" % cmd.strip())
ser.write(cmd.encode('cp1252'))
result = ""
while not result.endswith(LAST_DELIMITER[0]):
result += ser.read(COMMAND_RESP_BUFSIZE).decode('cp1252')
if (time.time() - start) > 1: # TXH sometimes takes longer on TH-D7G
LOG.error("Timeout waiting for data")
break
if result.endswith(LAST_DELIMITER[0]):
LOG.debug("RADIO->PC: %r" % result.strip())
result = result[:-1]
else:
LOG.error("Giving up")
return result.strip()
def command(ser, cmd, *args):
with LOCK:
return _command(ser, cmd, *args)
def get_id(ser):
"""Get the ID of the radio attached to @ser"""
global LAST_BAUD
bauds = [4800, 9600, 19200, 38400, 57600, 115200]
bauds.remove(LAST_BAUD)
# Make sure LAST_BAUD is last so that it is tried first below
bauds.append(LAST_BAUD)
global LAST_DELIMITER
command_delimiters = [("\r", " "), (";", "")]
for delimiter in command_delimiters:
# Process the baud options in reverse order so that we try the
# last one first, and then start with the high-speed ones next
for i in reversed(bauds):
LAST_DELIMITER = delimiter
LOG.info("Trying ID at baud %i with delimiter \"%s\"" %
(i, repr(delimiter)))
ser.baudrate = i
ser.write(LAST_DELIMITER[0].encode())
ser.read(25)
try:
resp = command(ser, "ID")
except UnicodeDecodeError:
# If we got binary here, we are using the wrong rate
# or not talking to a Kenwood live radio.
continue
# most Kenwood radios
if " " in resp:
LAST_BAUD = i
return resp.split(" ")[1]
# Radio responded in the right baud rate,
# but threw an error because of all the crap
# we have been hurling at it. Retry the ID at this
# baud rate, which will almost definitely work.
if "?" in resp:
resp = command(ser, "ID")
LAST_BAUD = i
if " " in resp:
return resp.split(" ")[1]
# Kenwood radios that return ID numbers
if resp in list(RADIO_IDS.keys()):
return RADIO_IDS[resp]
raise errors.RadioError("No response from radio")
def get_tmode(tone, ctcss, dcs):
"""Get the tone mode based on the values of the tone, ctcss, dcs"""
if dcs and int(dcs) == 1:
return "DTCS"
elif int(ctcss):
return "TSQL"
elif int(tone):
return "Tone"
else:
return ""
def iserr(result):
"""Returns True if the @result from a radio is an error"""
return result in ["N", "?"]
class KenwoodLiveRadio(chirp_common.LiveRadio):
"""Base class for all live-mode Kenwood radios"""
BAUD_RATE = 9600
VENDOR = "Kenwood"
MODEL = ""
NEEDS_COMPAT_SERIAL = False
# Lots of Kenwood radios actually require RTS, even some of the ones with
# USB integrated
HARDWARE_FLOW = True
_vfo = 0
_upper = 200
_kenwood_split = False
_kenwood_valid_tones = list(chirp_common.TONES)
_has_name = True
def __init__(self, *args, **kwargs):
chirp_common.LiveRadio.__init__(self, *args, **kwargs)
self._memcache = {}
if self.pipe:
self.pipe.timeout = 0.1
radio_id = get_id(self.pipe)
if radio_id != self.MODEL.split(" ")[0]:
raise Exception("Radio reports %s (not %s)" % (radio_id,
self.MODEL))
command(self.pipe, "AI", "0")
def _cmd_get_memory(self, number):
return "MR", "%i,0,%03i" % (self._vfo, number)
def _cmd_get_memory_name(self, number):
return "MNA", "%i,%03i" % (self._vfo, number)
def _cmd_get_split(self, number):
return "MR", "%i,1,%03i" % (self._vfo, number)
def _cmd_set_memory(self, number, spec):
if spec:
spec = "," + spec
return "MW", "%i,0,%03i%s" % (self._vfo, number, spec)
def _cmd_set_memory_name(self, number, name):
return "MNA", "%i,%03i,%s" % (self._vfo, number, name)
def _cmd_set_split(self, number, spec):
return "MW", "%i,1,%03i,%s" % (self._vfo, number, spec)
def get_raw_memory(self, number):
return command(self.pipe, *self._cmd_get_memory(number))
def get_memory(self, number):
if number < 0 or number > self._upper:
raise errors.InvalidMemoryLocation(
"Number must be between 0 and %i" % self._upper)
if number in self._memcache and not NOCACHE:
return self._memcache[number]
result = command(self.pipe, *self._cmd_get_memory(number))
if result == "N" or result == "E":
mem = chirp_common.Memory()
mem.number = number
mem.empty = True
self._memcache[mem.number] = mem
return mem
elif " " not in result:
LOG.error("Not sure what to do with this: `%s'" % result)
raise errors.RadioError("Unexpected result returned from radio")
value = result.split(" ")[1]
spec = value.split(",")
mem = self._parse_mem_spec(spec)
self._memcache[mem.number] = mem
if self._has_name:
result = command(self.pipe, *self._cmd_get_memory_name(number))
if " " in result:
value = result.split(" ", 1)[1]
if value.count(",") == 2:
_zero, _loc, mem.name = value.split(",")
else:
_loc, mem.name = value.split(",")
if mem.duplex == "" and self._kenwood_split:
result = command(self.pipe, *self._cmd_get_split(number))
if " " in result:
value = result.split(" ", 1)[1]
self._parse_split_spec(mem, value.split(","))
return mem
def _make_mem_spec(self, mem):
pass
def _parse_mem_spec(self, spec):
pass
def _parse_split_spec(self, mem, spec):
mem.duplex = "split"
mem.offset = int(spec[2])
def _make_split_spec(self, mem):
return ("%011i" % mem.offset, "0")
def set_memory(self, memory):
if memory.number < 0 or memory.number > self._upper:
raise errors.InvalidMemoryLocation(
"Number must be between 0 and %i" % self._upper)
spec = self._make_mem_spec(memory)
spec = ",".join(spec)
r1 = command(self.pipe, *self._cmd_set_memory(memory.number, spec))
if not iserr(r1) and self._has_name:
time.sleep(0.5)
r2 = command(self.pipe, *self._cmd_set_memory_name(memory.number,
memory.name))
if not iserr(r2):
memory.name = memory.name.rstrip()
self._memcache[memory.number] = memory.dupe()
else:
raise errors.InvalidDataError("Radio refused name %i: %s" %
(memory.number,
repr(memory.name)))
elif self._has_name:
raise errors.InvalidDataError("Radio refused %i" % memory.number)
if memory.duplex == "split" and self._kenwood_split:
spec = ",".join(self._make_split_spec(memory))
result = command(self.pipe, *self._cmd_set_split(memory.number,
spec))
if iserr(result):
raise errors.InvalidDataError("Radio refused %i" %
memory.number)
def erase_memory(self, number):
if number not in self._memcache:
return
resp = command(self.pipe, *self._cmd_set_memory(number, ""))
if iserr(resp):
raise errors.RadioError("Radio refused delete of %i" % number)
del self._memcache[number]
def _kenwood_get(self, cmd):
resp = command(self.pipe, cmd)
if " " in resp:
return resp.split(" ", 1)
else:
if resp == cmd:
return [resp, ""]
else:
raise errors.RadioError("Radio refused to return %s" % cmd)
def _kenwood_set(self, cmd, value):
resp = command(self.pipe, cmd, value)
if resp[:len(cmd)] == cmd:
return
raise errors.RadioError("Radio refused to set %s" % cmd)
def _kenwood_get_bool(self, cmd):
_cmd, result = self._kenwood_get(cmd)
return result == "1"
def _kenwood_set_bool(self, cmd, value):
return self._kenwood_set(cmd, str(int(value)))
def _kenwood_get_int(self, cmd):
_cmd, result = self._kenwood_get(cmd)
return int(result)
def _kenwood_set_int(self, cmd, value, digits=1):
return self._kenwood_set(cmd, ("%%0%ii" % digits) % value)
def set_settings(self, settings):
for element in settings:
if not isinstance(element, RadioSetting):
self.set_settings(element)
continue
if not element.changed():
continue
if isinstance(element.value, RadioSettingValueBoolean):
self._kenwood_set_bool(element.get_name(), element.value)
elif isinstance(element.value, RadioSettingValueList):
options = self._get_setting_options(element.get_name())
if len(options) > 9:
digits = 2
else:
digits = 1
self._kenwood_set_int(element.get_name(),
options.index(str(element.value)),
digits)
elif isinstance(element.value, RadioSettingValueInteger):
if element.value.get_max() > 9:
digits = 2
else:
digits = 1
self._kenwood_set_int(element.get_name(),
element.value, digits)
elif isinstance(element.value, RadioSettingValueString):
self._kenwood_set(element.get_name(), str(element.value))
else:
LOG.error("Unknown type %s" % element.value)
class KenwoodOldLiveRadio(KenwoodLiveRadio):
_kenwood_valid_tones = list(chirp_common.OLD_TONES)
def set_memory(self, memory):
supported_tones = list(chirp_common.OLD_TONES)
supported_tones.remove(69.3)
if memory.rtone not in supported_tones:
raise errors.UnsupportedToneError("This radio does not support " +
"tone %.1fHz" % memory.rtone)
if memory.ctone not in supported_tones:
raise errors.UnsupportedToneError("This radio does not support " +
"tone %.1fHz" % memory.ctone)
return KenwoodLiveRadio.set_memory(self, memory)
@directory.register
class TMV7Radio(KenwoodOldLiveRadio):
"""Kenwood TM-V7"""
MODEL = "TM-V7"
mem_upper_limit = 200 # Will be updated
def get_features(self):
rf = chirp_common.RadioFeatures()
rf.has_dtcs = False
rf.has_dtcs_polarity = False
rf.has_bank = False
rf.has_mode = False
rf.has_tuning_step = False
rf.valid_modes = ["FM"]
rf.valid_tmodes = ["", "Tone", "TSQL"]
rf.valid_characters = chirp_common.CHARSET_ALPHANUMERIC
rf.valid_name_length = 7
rf.valid_tuning_steps = STEPS
rf.has_sub_devices = True
rf.memory_bounds = (1, self._upper)
return rf
def _make_mem_spec(self, mem):
spec = (
"%011i" % mem.freq,
"%X" % STEPS.index(mem.tuning_step),
"%i" % util.get_dict_rev(DUPLEX, mem.duplex),
"0",
"%i" % (mem.tmode == "Tone"),
"%i" % (mem.tmode == "TSQL"),
"0",
"%02i" % (self._kenwood_valid_tones.index(mem.rtone) + 1),
"000",
"%02i" % (self._kenwood_valid_tones.index(mem.ctone) + 1),
"",
"0")
return spec
def _parse_mem_spec(self, spec):
mem = chirp_common.Memory()
mem.number = int(spec[2])
mem.freq = int(spec[3])
mem.tuning_step = STEPS[int(spec[4], 16)]
mem.duplex = DUPLEX[int(spec[5])]
if int(spec[7]):
mem.tmode = "Tone"
elif int(spec[8]):
mem.tmode = "TSQL"
mem.rtone = self._kenwood_valid_tones[int(spec[10]) - 1]
mem.ctone = self._kenwood_valid_tones[int(spec[12]) - 1]
return mem
def get_sub_devices(self):
return [TMV7RadioVHF(self.pipe), TMV7RadioUHF(self.pipe)]
def __test_location(self, loc):
mem = self.get_memory(loc)
if not mem.empty:
# Memory was not empty, must be valid
return True
# Mem was empty (or invalid), try to set it
if self._vfo == 0:
mem.freq = 144000000
else:
mem.freq = 440000000
mem.empty = False
try:
self.set_memory(mem)
except Exception:
# Failed, so we're past the limit
return False
# Erase what we did
try:
self.erase_memory(loc)
except Exception:
pass # V7A Can't delete just yet
return True
def _detect_split(self):
return 50
class TMV7RadioSub(TMV7Radio):
"""Base class for the TM-V7 sub devices"""
def __init__(self, pipe):
TMV7Radio.__init__(self, pipe)
self._detect_split()
class TMV7RadioVHF(TMV7RadioSub):
"""TM-V7 VHF subdevice"""
VARIANT = "VHF"
_vfo = 0
class TMV7RadioUHF(TMV7RadioSub):
"""TM-V7 UHF subdevice"""
VARIANT = "UHF"
_vfo = 1
@directory.register
class TMG707Radio(TMV7Radio):
"""Kenwood TM-G707"""
MODEL = "TM-G707"
def get_features(self):
rf = TMV7Radio.get_features(self)
rf.has_sub_devices = False
rf.memory_bounds = (1, 180)
rf.valid_bands = [(118000000, 174000000),
(300000000, 520000000),
(800000000, 999000000)]
return rf
THG71_STEPS = [5, 6.25, 10, 12.5, 15, 20, 25, 30, 50, 100]
@directory.register
class THG71Radio(TMV7Radio):
"""Kenwood TH-G71"""
MODEL = "TH-G71"
def get_features(self):
rf = TMV7Radio.get_features(self)
rf.has_tuning_step = True
rf.valid_tuning_steps = list(THG71_STEPS)
rf.valid_name_length = 6
rf.has_sub_devices = False
rf.valid_bands = [(118000000, 174000000),
(320000000, 470000000),
(800000000, 945000000)]
return rf
def _make_mem_spec(self, mem):
spec = (
"%011i" % mem.freq,
"%X" % THG71_STEPS.index(mem.tuning_step),
"%i" % util.get_dict_rev(DUPLEX, mem.duplex),
"0",
"%i" % (mem.tmode == "Tone"),
"%i" % (mem.tmode == "TSQL"),
"0",
"%02i" % (self._kenwood_valid_tones.index(mem.rtone) + 1),
"000",
"%02i" % (self._kenwood_valid_tones.index(mem.ctone) + 1),
"%09i" % mem.offset,
"%i" % ((mem.skip == "S") and 1 or 0))
return spec
def _parse_mem_spec(self, spec):
mem = chirp_common.Memory()
mem.number = int(spec[2])
mem.freq = int(spec[3])
mem.tuning_step = THG71_STEPS[int(spec[4], 16)]
mem.duplex = DUPLEX[int(spec[5])]
if int(spec[7]):
mem.tmode = "Tone"
elif int(spec[8]):
mem.tmode = "TSQL"
mem.rtone = self._kenwood_valid_tones[int(spec[10]) - 1]
mem.ctone = self._kenwood_valid_tones[int(spec[12]) - 1]
if spec[13]:
mem.offset = int(spec[13])
else:
mem.offset = 0
return mem
THF6A_STEPS = [5.0, 6.25, 8.33, 9.0, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0, 50.0,
100.0]
THF6A_DUPLEX = dict(DUPLEX)
THF6A_DUPLEX[3] = "split"
@directory.register
class THF6ARadio(KenwoodLiveRadio):
"""Kenwood TH-F6"""
MODEL = "TH-F6"
HARDWARE_FLOW = False
_charset = chirp_common.CHARSET_ASCII
_upper = 399
_kenwood_split = True
_kenwood_valid_tones = list(KENWOOD_TONES)
def get_features(self):
rf = chirp_common.RadioFeatures()
rf.has_dtcs_polarity = False
rf.has_bank = False
rf.can_odd_split = True
rf.valid_modes = list(THF6_MODES)
rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS"]
rf.valid_tuning_steps = list(THF6A_STEPS)
rf.valid_bands = [(1000, 1300000000)]
rf.valid_skips = ["", "S"]
rf.valid_duplexes = list(THF6A_DUPLEX.values())
rf.valid_characters = self._charset
rf.valid_name_length = 8
rf.memory_bounds = (0, self._upper)
rf.has_settings = True
return rf
def _cmd_set_memory(self, number, spec):
if spec:
spec = "," + spec
return "MW", "0,%03i%s" % (number, spec)
def _cmd_get_memory(self, number):
return "MR", "0,%03i" % number
def _cmd_get_memory_name(self, number):
return "MNA", "%03i" % number
def _cmd_set_memory_name(self, number, name):
return "MNA", "%03i,%s" % (number, name)
def _cmd_get_split(self, number):
return "MR", "1,%03i" % number
def _cmd_set_split(self, number, spec):
return "MW", "1,%03i,%s" % (number, spec)
def _parse_mem_spec(self, spec):
mem = chirp_common.Memory()
mem.number = int(spec[1])
mem.freq = int(spec[2])
mem.tuning_step = THF6A_STEPS[int(spec[3], 16)]
mem.duplex = THF6A_DUPLEX[int(spec[4])]
mem.tmode = get_tmode(spec[6], spec[7], spec[8])
mem.rtone = self._kenwood_valid_tones[int(spec[9])]
mem.ctone = self._kenwood_valid_tones[int(spec[10])]
if spec[11] and spec[11].isdigit():
mem.dtcs = chirp_common.DTCS_CODES[int(spec[11])]
else:
LOG.warn("Unknown or invalid DCS: %s" % spec[11])
if spec[12]:
mem.offset = int(spec[12])
else:
mem.offset = 0
mem.mode = THF6_MODES[int(spec[13])]
if spec[14] == "1":
mem.skip = "S"
return mem
def _make_mem_spec(self, mem):
if mem.duplex in " +-":
duplex = util.get_dict_rev(THF6A_DUPLEX, mem.duplex)
offset = mem.offset
elif mem.duplex == "split":
duplex = 0
offset = 0
else:
LOG.warn("Bug: unsupported duplex `%s'" % mem.duplex)
spec = (
"%011i" % mem.freq,
"%X" % THF6A_STEPS.index(mem.tuning_step),
"%i" % duplex,
"0",
"%i" % (mem.tmode == "Tone"),
"%i" % (mem.tmode == "TSQL"),
"%i" % (mem.tmode == "DTCS"),
"%02i" % (self._kenwood_valid_tones.index(mem.rtone)),
"%02i" % (self._kenwood_valid_tones.index(mem.ctone)),
"%03i" % (chirp_common.DTCS_CODES.index(mem.dtcs)),
"%09i" % offset,
"%i" % (THF6_MODES.index(mem.mode)),
"%i" % (mem.skip == "S"))
return spec
_SETTINGS_OPTIONS = {
"APO": ["Off", "30min", "60min"],
"BAL": ["100%:0%", "75%:25%", "50%:50%", "25%:75%", "%0:100%"],
"BAT": ["Lithium", "Alkaline"],
"CKEY": ["Call", "1750 Hz"],
"DATP": ["1200bps", "9600bps"],
"LAN": ["English", "Japanese"],
"MNF": ["Name", "Frequency"],
"MRM": ["All Band", "Current Band"],
"PT": ["100ms", "250ms", "500ms", "750ms",
"1000ms", "1500ms", "2000ms"],
"SCR": ["Time", "Carrier", "Seek"],
"SV": ["Off", "0.2s", "0.4s", "0.6s", "0.8s", "1.0s",
"2s", "3s", "4s", "5s"],
"VXD": ["250ms", "500ms", "750ms", "1s", "1.5s", "2s", "3s"],
}
def get_settings(self):
main = RadioSettingGroup("main", "Main")
aux = RadioSettingGroup("aux", "Aux")
save = RadioSettingGroup("save", "Save")
display = RadioSettingGroup("display", "Display")
dtmf = RadioSettingGroup("dtmf", "DTMF")
top = RadioSettings(main, aux, save, display, dtmf)
lists = [("APO", save, "Automatic Power Off"),
("BAL", main, "Balance"),
("BAT", save, "Battery Type"),
("CKEY", aux, "CALL Key Set Up"),
("DATP", aux, "Data Packet Speed"),
("LAN", display, "Language"),
("MNF", main, "Memory Display Mode"),
("MRM", main, "Memory Recall Method"),
("PT", dtmf, "DTMF Speed"),
("SCR", main, "Scan Resume"),
("SV", save, "Battery Save"),
("VXD", aux, "VOX Drop Delay"),
]
bools = [("ANT", aux, "Bar Antenna"),
("ATT", main, "Attenuator Enabled"),
("ARO", main, "Automatic Repeater Offset"),
("BEP", aux, "Beep for keypad"),
("DL", main, "Dual"),
("DLK", dtmf, "DTMF Lockout On Transmit"),
("ELK", aux, "Enable Locked Tuning"),
("LK", main, "Lock"),
("LMP", display, "Lamp"),
("NSFT", aux, "Noise Shift"),
("TH", aux, "Tx Hold for 1750"),
("TSP", dtmf, "DTMF Fast Transmission"),
("TXH", dtmf, "TX Hold DTMF"),
("TXS", main, "Transmit Inhibit"),
("VOX", aux, "VOX Enable"),
("VXB", aux, "VOX On Busy"),
]
ints = [("CNT", display, "Contrast", 1, 16),
("VXG", aux, "VOX Gain", 0, 9),
]
strings = [("MES", display, "Power-on Message", 8),
]
for setting, group, name in bools:
value = self._kenwood_get_bool(setting)
rs = RadioSetting(setting, name,
RadioSettingValueBoolean(value))
group.append(rs)
for setting, group, name in lists:
value = self._kenwood_get_int(setting)
options = self._SETTINGS_OPTIONS[setting]
rs = RadioSetting(setting, name,
RadioSettingValueList(options,
options[value]))
group.append(rs)
for setting, group, name, minv, maxv in ints:
value = self._kenwood_get_int(setting)
rs = RadioSetting(setting, name,
RadioSettingValueInteger(minv, maxv, value))
group.append(rs)
for setting, group, name, length in strings:
_cmd, value = self._kenwood_get(setting)
rs = RadioSetting(setting, name,
RadioSettingValueString(0, length, value))
group.append(rs)
return top
@directory.register
class THF7ERadio(THF6ARadio):
"""Kenwood TH-F7"""
MODEL = "TH-F7"
_charset = chirp_common.CHARSET_1252
D710_DUPLEX = ["", "+", "-", "split"]
D710_MODES = ["FM", "NFM", "AM"]
D710_SKIP = ["", "S"]
D710_STEPS = [5.0, 6.25, 8.33, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0, 50.0, 100.0]
@directory.register
class TMD710Radio(KenwoodLiveRadio):
"""Kenwood TM-D710"""
MODEL = "TM-D710"
_upper = 999
_kenwood_valid_tones = list(KENWOOD_TONES)
def get_features(self):
rf = chirp_common.RadioFeatures()
rf.can_odd_split = True
rf.has_dtcs_polarity = False
rf.has_bank = False
rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS"]
rf.valid_modes = D710_MODES
rf.valid_duplexes = D710_DUPLEX
rf.valid_tuning_steps = D710_STEPS
rf.valid_characters = chirp_common.CHARSET_ASCII.replace(',', '')
rf.valid_name_length = 8
rf.valid_skips = D710_SKIP
rf.memory_bounds = (0, 999)
return rf
def _cmd_get_memory(self, number):
return "ME", "%03i" % number
def _cmd_get_memory_name(self, number):
return "MN", "%03i" % number
def _cmd_set_memory(self, number, spec):
return "ME", "%03i,%s" % (number, spec)
def _cmd_set_memory_name(self, number, name):
return "MN", "%03i,%s" % (number, name)
def _parse_mem_spec(self, spec):
mem = chirp_common.Memory()
mem.number = int(spec[0])
mem.freq = int(spec[1])
mem.tuning_step = D710_STEPS[int(spec[2], 16)]
mem.duplex = D710_DUPLEX[int(spec[3])]
# Reverse
if int(spec[5]):
mem.tmode = "Tone"
elif int(spec[6]):
mem.tmode = "TSQL"
elif int(spec[7]):
mem.tmode = "DTCS"
mem.rtone = self._kenwood_valid_tones[int(spec[8])]
mem.ctone = self._kenwood_valid_tones[int(spec[9])]
mem.dtcs = chirp_common.DTCS_CODES[int(spec[10])]
mem.offset = int(spec[11])
mem.mode = D710_MODES[int(spec[12])]
# TX Frequency
if int(spec[13]):
mem.duplex = "split"
mem.offset = int(spec[13])
# Unknown
mem.skip = D710_SKIP[int(spec[15])] # Memory Lockout
return mem
def _make_mem_spec(self, mem):
spec = (
"%010i" % mem.freq,
"%X" % D710_STEPS.index(mem.tuning_step),
"%i" % (0 if mem.duplex == "split"
else D710_DUPLEX.index(mem.duplex)),
"0", # Reverse
"%i" % (mem.tmode == "Tone" and 1 or 0),
"%i" % (mem.tmode == "TSQL" and 1 or 0),
"%i" % (mem.tmode == "DTCS" and 1 or 0),
"%02i" % (self._kenwood_valid_tones.index(mem.rtone)),
"%02i" % (self._kenwood_valid_tones.index(mem.ctone)),
"%03i" % (chirp_common.DTCS_CODES.index(mem.dtcs)),
"%08i" % (0 if mem.duplex == "split" else mem.offset), # Offset
"%i" % D710_MODES.index(mem.mode),
"%010i" % (mem.offset if mem.duplex == "split" else 0), # TX Freq
"0", # Unknown
"%i" % D710_SKIP.index(mem.skip), # Memory Lockout
)
return spec
@directory.register
class THD72Radio(TMD710Radio):
"""Kenwood TH-D72"""
MODEL = "TH-D72 (live mode)"
HARDWARE_FLOW = sys.platform == "darwin" # only OS X driver needs hw flow
def _parse_mem_spec(self, spec):
mem = chirp_common.Memory()
mem.number = int(spec[0])
mem.freq = int(spec[1])
mem.tuning_step = D710_STEPS[int(spec[2], 16)]
mem.duplex = D710_DUPLEX[int(spec[3])]
# Reverse
if int(spec[5]):
mem.tmode = "Tone"
elif int(spec[6]):
mem.tmode = "TSQL"
elif int(spec[7]):
mem.tmode = "DTCS"
mem.rtone = self._kenwood_valid_tones[int(spec[9])]
mem.ctone = self._kenwood_valid_tones[int(spec[10])]
mem.dtcs = chirp_common.DTCS_CODES[int(spec[11])]
mem.offset = int(spec[13])
mem.mode = D710_MODES[int(spec[14])]
# TX Frequency
if int(spec[15]):
mem.duplex = "split"
mem.offset = int(spec[15])
# Lockout
mem.skip = D710_SKIP[int(spec[17])] # Memory Lockout
return mem
def _make_mem_spec(self, mem):
spec = (
"%010i" % mem.freq,
"%X" % D710_STEPS.index(mem.tuning_step),
"%i" % (0 if mem.duplex == "split"
else D710_DUPLEX.index(mem.duplex)),
"0", # Reverse
"%i" % (mem.tmode == "Tone" and 1 or 0),
"%i" % (mem.tmode == "TSQL" and 1 or 0),
"%i" % (mem.tmode == "DTCS" and 1 or 0),
"0",
"%02i" % (self._kenwood_valid_tones.index(mem.rtone)),
"%02i" % (self._kenwood_valid_tones.index(mem.ctone)),
"%03i" % (chirp_common.DTCS_CODES.index(mem.dtcs)),
"0",
"%08i" % (0 if mem.duplex == "split" else mem.offset), # Offset
"%i" % D710_MODES.index(mem.mode),
"%010i" % (mem.offset if mem.duplex == "split" else 0), # TX Freq
"0", # Unknown
"%i" % D710_SKIP.index(mem.skip), # Memory Lockout
)
return spec
@directory.register
class THD74Radio(TMD710Radio):
"""Kenwood TH_D74"""
MODEL = "TH-D74 (live mode)"
HARDWARE_FLOW = sys.platform == "darwin"
STEPS = [5.0, 6.25, 8.33, 9.0, 10.0, 12.5, 15.0, 20.0,
25.0, 30.0, 50.0, 100.0]
MODES = ['FM', 'DV', 'AM', 'LSB', 'USB', 'CW', 'NFM', 'DR',
'WFM', 'R-CW']
CROSS_MODES = ['DTCS->', 'Tone->DTCS', 'DTCS->Tone', 'Tone->Tone']
DUPLEX = ['', '+', '-', 'split']
_has_name = False
@classmethod
def get_prompts(cls):
rp = chirp_common.RadioPrompts()
rp.experimental = ("This driver is incomplete as the D74 lacks "
"the full serial command set of older radios. "
"As such, this should be considered permanently "
"experimental.")
return rp
def _cmd_get_memory_name(self, number):
return ''
def get_features(self):
rf = super(THD74Radio, self).get_features()
rf.valid_tuning_steps = self.STEPS
rf.valid_modes = self.MODES
rf.valid_cross_modes = self.CROSS_MODES
rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS', 'Cross']
rf.has_name = False # Radio has it, but no command to retrieve
rf.has_cross = True
return rf
def _parse_mem_spec(self, spec):
mem = chirp_common.Memory()
mem.number = int(spec[0])
mem.freq = int(spec[1])
mem.offset = int(spec[2])
mem.tuning_step = self.STEPS[int(spec[3])]
mem.mode = self.MODES[int(spec[5])]
if int(spec[11]):
mem.tmode = "Cross"
mem.cross_mode = self.CROSS_MODES[int(spec[18])]
elif int(spec[8]):
mem.tmode = "Tone"
elif int(spec[9]):
mem.tmode = "TSQL"
elif int(spec[10]):
mem.tmode = "DTCS"
mem.duplex = self.DUPLEX[int(spec[14])]
mem.rtone = chirp_common.TONES[int(spec[15])]
mem.ctone = chirp_common.TONES[int(spec[16])]
mem.dtcs = chirp_common.DTCS_CODES[int(spec[17])]
mem.skip = int(spec[22]) and 'S' or ''
return mem
def _make_mem_spec(self, mem):
spec = (
"%010i" % mem.freq,
"%010i" % mem.offset,
"%X" % self.STEPS.index(mem.tuning_step),
"%X" % self.STEPS.index(mem.tuning_step),
"%i" % self.MODES.index(mem.mode),
"0", # Fine mode
"0", # Fine step
"%i" % (mem.tmode == "Tone" and 1 or 0),
"%i" % (mem.tmode == "TSQL" and 1 or 0),
"%i" % (mem.tmode == "DTCS" and 1 or 0),
"%i" % (mem.tmode == 'Cross'),
"0", # Reverse