Project

General

Profile

New Model #217 » ts2000.py

Semi-fixed ts2000.py driver - Charles Stewart, 03/25/2015 08:50 PM

 
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
17
from chirp.drivers import kenwood_live
18
from chirp.drivers.kenwood_live import command
19

    
20
TS2000_SSB_STEPS = [1.0, 2.5, 5.0, 10.0]
21
TS2000_FM_STEPS = [5.0, 6.25, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0, 50.0, 100.0]
22
TS2000_DUPLEX = dict(kenwood_live.DUPLEX)
23
TS2000_DUPLEX[3] = "="
24
TS2000_DUPLEX[4] = "split"
25
TS2000_MODES = ["?", "LSB", "USB", "CW", "FM", "AM",
26
                "FSK", "CR-R", "?", "FSK-R"]
27
TS2000_TMODES = ["", "Tone", "TSQL", "DTCS"]
28
TS2000_TONES = list(chirp_common.OLD_TONES)
29
TS2000_TONES.remove(69.3)
30

    
31
@directory.register
32
class TS2000Radio(kenwood_live.KenwoodLiveRadio):
33
    """Kenwood TS-2000"""
34
    MODEL = "TS-2000"
35

    
36
    _upper = 289
37
    _kenwood_split = True
38
    _kenwood_valid_tones = list(TS2000_TONES)
39

    
40
    def get_features(self):
41
        rf = chirp_common.RadioFeatures()
42
        rf.has_dtcs_polarity = False
43
        rf.has_bank = False
44
        rf.can_odd_split = True
45
        rf.valid_modes = ["LSB", "USB", "CW", "FM", "AM"]
46
        rf.valid_tmodes = list(TS2000_TMODES)
47
        rf.valid_tuning_steps = list(TS2000_SSB_STEPS + TS2000_FM_STEPS)
48
        rf.valid_bands = [(1000, 1300000000)]
49
        rf.valid_skips = ["", "S"]
50
        rf.valid_duplexes = TS2000_DUPLEX.values()
51
        rf.valid_characters = chirp_common.CHARSET_ALPHANUMERIC
52
        rf.valid_name_length = 7
53
        rf.memory_bounds = (0, self._upper)
54
        return rf
55

    
56
    def _cmd_set_memory(self, number, spec):
57
        return "MW0%03i%s" % (number, spec)
58

    
59
    def _cmd_get_memory(self, number):
60
        return "MR0%03i" % number
61

    
62
    def _cmd_get_split(self, number):
63
        return "MR1%03i" % number
64

    
65
    def _cmd_set_split(self, number, spec):
66
        return "MW1%03i%s" % (number, spec)
67

    
68
    def get_memory(self, number):
69
        if number < 0 or number > self._upper:
70
            raise errors.InvalidMemoryLocation( \
71
                "Number must be between 0 and %i" % self._upper)
72
        if number in self._memcache and not NOCACHE:
73
            return self._memcache[number]
74

    
75
        result = command(self.pipe, *self._cmd_get_memory(number))
76
        if result == "N":
77
            mem = chirp_common.Memory()
78
            mem.number = number
79
            mem.empty = True
80
            self._memcache[mem.number] = mem
81
            return mem
82

    
83
        spec = result[2:]
84

    
85
        mem = self._parse_mem_spec(result)
86
        self._memcache[mem.number] = mem
87

    
88
        # FIXME
89
        if mem.duplex == "" and self._kenwood_split:
90
            result = command(self.pipe, *self._cmd_get_split(number))
91
            if " " in result:
92
                value = result.split(" ", 1)[1]
93
                self._parse_split_spec(mem, value.split(","))
94

    
95
        return mem
96
    
97
    def _parse_mem_spec(self, spec):
98
        mem = chirp_common.Memory()
99

    
100
        # pad string so indexes match Kenwood docs
101
        spec = " " + spec
102
        
103
        # use the same variable names as the Kenwood docs
104
        _p1  = spec[3]
105
        _p2  = spec[4]
106
        _p3  = spec[5:7]
107
        _p4  = spec[7:18]
108
        _p5  = spec[18]
109
        _p6  = spec[19]
110
        _p7  = spec[20]
111
        _p8  = spec[21:23]
112
        _p9  = spec[23:25]
113
        _p10 = spec[25:28]
114
        _p11 = spec[28]
115
        _p12 = spec[29]
116
        _p13 = spec[30:39]
117
        _p14 = spec[39:41]
118
        _p15 = spec[41]
119
        _p16 = spec[42:49]
120

    
121
        mem.number = int(_p2 + _p3) # concat bank num and chan num
122
        mem.freq = int(_p4)
123
        mem.mode = TS2000_MODES[int(_p5)]
124
        mem.skip = ["", "S"][int(_p6)]
125
        mem.tmode = TS2000_TMODES[int(_p7)]
126
        mem.rtone = self._kenwood_valid_tones[int(_p8) - 1]
127
        mem.ctone = self._kenwood_valid_tones[int(_p9) - 1]
128
        mem.dtcs = chirp_common.DTCS_CODES[int(_p10) - 1]
129
        mem.duplex = TS2000_DUPLEX[int(_p12)]
130
        mem.offset = int(_p13) # 9-digit
131
        if mem.mode in ["AM", "FM"]:
132
            mem.tuning_step = TS2000_FM_STEPS[int(_p14)]
133
        else:
134
            mem.tuning_step = TS2000_SSB_STEPS[int(_p14)]
135
        mem.name = _p16
136

    
137
        return mem
138

    
139
    def set_memory(self, memory):
140
        if memory.number < 0 or memory.number > self._upper:
141
            raise errors.InvalidMemoryLocation( \
142
                "Number must be between 0 and %i" % self._upper)
143

    
144
        spec = self._make_mem_spec(memory)
145
        spec = "".join(spec)
146
        r1 = command(self.pipe, *self._cmd_set_memory(memory.number, spec))
147
        if not iserr(r1):
148
            time.sleep(0.5)
149
            r2 = command(self.pipe, *self._cmd_set_memory_name(memory.number,
150
                                                               memory.name))
151
            if not iserr(r2):
152
                memory.name = memory.name.rstrip()
153
                self._memcache[memory.number] = memory
154
            else:
155
                raise errors.InvalidDataError("Radio refused name %i: %s" %\
156
                                                  (memory.number,
157
                                                   repr(memory.name)))
158
        else:
159
            raise errors.InvalidDataError("Radio refused %i" % memory.number)
160

    
161
        # FIXME
162
        if memory.duplex == "split" and self._kenwood_split: 
163
            spec = "".join(self._make_split_spec(memory))
164
            result = command(self.pipe, *self._cmd_set_split(memory.number,
165
                                                             spec))
166
            if iserr(result):
167
                raise errors.InvalidDataError("Radio refused %i" % \
168
                                                  memory.number)
169
    
170
    def _make_mem_spec(self, mem):
171
        if mem.duplex in " +-":
172
            duplex = util.get_dict_rev(TS2000_DUPLEX, mem.duplex)
173
            offset = mem.offset
174
        elif mem.duplex == "split":
175
            duplex = 0
176
            offset = 0
177
        else:
178
            print "Bug: unsupported duplex `%s'" % mem.duplex
179
        if mem.mode in ["AM", "FM"]:
180
            step = TS2000_FM_STEPS.index(mem.tuning_step)
181
        else:
182
            step = TS2000_SSB_STEPS.index(mem.tuning_step)
183
        spec = ( \
184
            "0",
185
            "%03i" % mem.number,
186
            "%011i" % mem.freq,
187
            "%i" % (TS2000_MODES.index(mem.mode)),
188
            "%i" % (mem.skip == "S"),
189
            "%i" % TS2000_TMODES.index(mem.tmode),
190
            "%02i" % (self._kenwood_valid_tones.index(mem.rtone)),
191
            "%02i" % (self._kenwood_valid_tones.index(mem.ctone)),
192
            "%03i" % (chirp_common.DTCS_CODES.index(mem.dtcs)),
193
            "0", # REVERSE status
194
            "%i" % duplex,
195
            "%09i" % offset,
196
            "%i" % step,
197
            "0", # Memory Group number (0-9)
198
            "%s" % mem.name,
199
        )
200

    
201
        return spec
(7-7/10)