1
|
# Copyright 2012 Tom Hayward <tom@tomh.us>
|
2
|
#
|
3
|
# This program is free software: you can redistribute it and/or modify
|
4
|
# it under the terms of the GNU General Public License as published by
|
5
|
# the Free Software Foundation, either version 3 of the License, or
|
6
|
# (at your option) any later version.
|
7
|
#
|
8
|
# This program is distributed in the hope that it will be useful,
|
9
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
# GNU General Public License for more details.
|
12
|
#
|
13
|
# You should have received a copy of the GNU General Public License
|
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
|
16
|
from chirp import chirp_common, directory, kenwood_live
|
17
|
|
18
|
TS2000_SSB_STEPS = [1.0, 2.5, 5.0, 10.0]
|
19
|
TS2000_FM_STEPS = [5.0, 6.25, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0, 50.0, 100.0]
|
20
|
TS2000_DUPLEX = dict(kenwood_live.DUPLEX)
|
21
|
TS2000_DUPLEX[3] = "="
|
22
|
TS2000_DUPLEX[4] = "split"
|
23
|
TS2000_MODES = ["?", "LSB", "USB", "CW", "FM", "AM",
|
24
|
"FSK", "CR-R", "?", "FSK-R"]
|
25
|
TS2000_TMODES = ["", "Tone", "TSQL", "DTCS"]
|
26
|
TS2000_TONES = list(kenwood_live.OLD_TONES)
|
27
|
TS2000_TONES.remove(69.3)
|
28
|
|
29
|
@directory.register
|
30
|
class TS2000Radio(kenwood_live.KenwoodLiveRadio):
|
31
|
"""Kenwood TS-2000"""
|
32
|
MODEL = "TS-2000"
|
33
|
|
34
|
_upper = 289
|
35
|
_kenwood_split = True
|
36
|
_kenwood_valid_tones = list(TS2000_TONES)
|
37
|
|
38
|
def get_features(self):
|
39
|
rf = chirp_common.RadioFeatures()
|
40
|
rf.has_dtcs_polarity = False
|
41
|
rf.has_bank = False
|
42
|
rf.can_odd_split = True
|
43
|
rf.valid_modes = ["LSB", "USB", "CW", "FM", "AM"]
|
44
|
rf.valid_tmodes = list(TS2000_TMODES)
|
45
|
rf.valid_tuning_steps = set(TS2000_SSB_STEPS + TS2000_FM_STEPS)
|
46
|
rf.valid_bands = [(1000, 1300000000)]
|
47
|
rf.valid_skips = ["", "S"]
|
48
|
rf.valid_duplexes = TS2000_DUPLEX.values()
|
49
|
rf.valid_characters = chirp_common.CHARSET_ALPHANUMERIC
|
50
|
rf.valid_name_length = 7
|
51
|
rf.memory_bounds = (0, self._upper)
|
52
|
return rf
|
53
|
|
54
|
def _cmd_set_memory(self, number, spec):
|
55
|
return "MW0%03i%s;" % (number, spec)
|
56
|
|
57
|
def _cmd_get_memory(self, number):
|
58
|
return "MR0%03i;" % number
|
59
|
|
60
|
def _cmd_get_split(self, number):
|
61
|
return "MR1%03i;" % number
|
62
|
|
63
|
def _cmd_set_split(self, number, spec):
|
64
|
return "MW1%03i%s;" % (number, spec)
|
65
|
|
66
|
def get_memory(self, number):
|
67
|
if number < 0 or number > self._upper:
|
68
|
raise errors.InvalidMemoryLocation( \
|
69
|
"Number must be between 0 and %i" % self._upper)
|
70
|
if self.__memcache.has_key(number) and not NOCACHE:
|
71
|
return self.__memcache[number]
|
72
|
|
73
|
result = command(self.pipe, *self._cmd_get_memory(number))
|
74
|
if result == "N":
|
75
|
mem = chirp_common.Memory()
|
76
|
mem.number = number
|
77
|
mem.empty = True
|
78
|
self.__memcache[mem.number] = mem
|
79
|
return mem
|
80
|
|
81
|
spec = result[2:]
|
82
|
|
83
|
mem = self._parse_mem_spec(result)
|
84
|
self.__memcache[mem.number] = mem
|
85
|
|
86
|
# FIXME
|
87
|
if mem.duplex == "" and self._kenwood_split:
|
88
|
result = command(self.pipe, *self._cmd_get_split(number))
|
89
|
if " " in result:
|
90
|
value = result.split(" ", 1)[1]
|
91
|
self._parse_split_spec(mem, value.split(","))
|
92
|
|
93
|
return mem
|
94
|
|
95
|
def _parse_mem_spec(self, spec):
|
96
|
mem = chirp_common.Memory()
|
97
|
|
98
|
# pad string so indexes match Kenwood docs
|
99
|
spec = " " + spec
|
100
|
|
101
|
# use the same variable names as the Kenwood docs
|
102
|
_p1 = spec[3]
|
103
|
_p2 = spec[4]
|
104
|
_p3 = spec[5:7]
|
105
|
_p4 = spec[7:18]
|
106
|
_p5 = spec[18]
|
107
|
_p6 = spec[19]
|
108
|
_p7 = spec[20]
|
109
|
_p8 = spec[21:23]
|
110
|
_p9 = spec[23:25]
|
111
|
_p10 = spec[25:28]
|
112
|
_p11 = spec[28]
|
113
|
_p12 = spec[29]
|
114
|
_p13 = spec[30:39]
|
115
|
_p14 = spec[39:41]
|
116
|
_p15 = spec[41]
|
117
|
_p16 = spec[42:49]
|
118
|
|
119
|
mem.number = int(_p2 + _p3) # concat bank num and chan num
|
120
|
mem.freq = int(_p4)
|
121
|
mem.mode = TS2000_MODES[int(_p5)]
|
122
|
mem.skip = ["", "S"][int(_p6)]
|
123
|
mem.tmode = TS2000_TMODES[int(_p7)]
|
124
|
mem.rtone = self._kenwood_valid_tones[int(_p8) - 1]
|
125
|
mem.ctone = self._kenwood_valid_tones[int(_p9) - 1]
|
126
|
mem.dtcs = chirp_common.DTCS_CODES[int(_p10) - 1]
|
127
|
mem.duplex = TS2000_DUPLEX[int(_p12)]
|
128
|
mem.offset = int(_p13) # 9-digit
|
129
|
if mem.mode in ["AM", "FM"]:
|
130
|
mem.tuning_step = TS2000_FM_STEPS[int(_p14)]
|
131
|
else:
|
132
|
mem.tuning_step = TS2000_SSB_STEPS[int(_p14)]
|
133
|
mem.name = _p16
|
134
|
|
135
|
return mem
|
136
|
|
137
|
def set_memory(self, memory):
|
138
|
if memory.number < 0 or memory.number > self._upper:
|
139
|
raise errors.InvalidMemoryLocation( \
|
140
|
"Number must be between 0 and %i" % self._upper)
|
141
|
|
142
|
spec = self._make_mem_spec(memory)
|
143
|
spec = "".join(spec)
|
144
|
r1 = command(self.pipe, *self._cmd_set_memory(memory.number, spec))
|
145
|
if not iserr(r1):
|
146
|
time.sleep(0.5)
|
147
|
r2 = command(self.pipe, *self._cmd_set_memory_name(memory.number,
|
148
|
memory.name))
|
149
|
if not iserr(r2):
|
150
|
memory.name = memory.name.rstrip()
|
151
|
self.__memcache[memory.number] = memory
|
152
|
else:
|
153
|
raise errors.InvalidDataError("Radio refused name %i: %s" %\
|
154
|
(memory.number,
|
155
|
repr(memory.name)))
|
156
|
else:
|
157
|
raise errors.InvalidDataError("Radio refused %i" % memory.number)
|
158
|
|
159
|
# FIXME
|
160
|
if memory.duplex == "split" and self._kenwood_split:
|
161
|
spec = "".join(self._make_split_spec(memory))
|
162
|
result = command(self.pipe, *self._cmd_set_split(memory.number,
|
163
|
spec))
|
164
|
if iserr(result):
|
165
|
raise errors.InvalidDataError("Radio refused %i" % \
|
166
|
memory.number)
|
167
|
|
168
|
def _make_mem_spec(self, mem):
|
169
|
if mem.duplex in " +-":
|
170
|
duplex = util.get_dict_rev(TS2000_DUPLEX, mem.duplex)
|
171
|
offset = mem.offset
|
172
|
elif mem.duplex == "split":
|
173
|
duplex = 0
|
174
|
offset = 0
|
175
|
else:
|
176
|
print "Bug: unsupported duplex `%s'" % mem.duplex
|
177
|
if mem.mode in ["AM", "FM"]:
|
178
|
step = TS2000_FM_STEPS.index(mem.tuning_step)
|
179
|
else:
|
180
|
step = TS2000_SSB_STEPS.index(mem.tuning_step)
|
181
|
spec = ( \
|
182
|
"0",
|
183
|
"%03i" % mem.number,
|
184
|
"%011i" % mem.freq,
|
185
|
"%i" % (TS2000_MODES.index(mem.mode)),
|
186
|
"%i" % (mem.skip == "S"),
|
187
|
"%i" % TS2000_TMODES.index(mem.tmode),
|
188
|
"%02i" % (self._kenwood_valid_tones.index(mem.rtone)),
|
189
|
"%02i" % (self._kenwood_valid_tones.index(mem.ctone)),
|
190
|
"%03i" % (chirp_common.DTCS_CODES.index(mem.dtcs)),
|
191
|
"0", # REVERSE status
|
192
|
"%i" % duplex,
|
193
|
"%09i" % offset,
|
194
|
"%i" % step,
|
195
|
"0", # Memory Group number (0-9)
|
196
|
"%s" % mem.name,
|
197
|
)
|
198
|
|
199
|
return spec
|