Project

General

Profile

New Model #217 » ts2000.py

read/write capable driver, split mode operation broken - Charles Stewart, 03/27/2015 07:49 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, util, errors
17
from chirp.drivers import kenwood_live
18
from chirp.drivers.kenwood_live import NOCACHE, KenwoodLiveRadio, command, iserr
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(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

    
52
        # TS-2000 uses ";" as a message separator even though it seems to
53
        # allow you to to use all printable ASCII characters at the manual
54
        # controls.  The radio doesn't send the name after the ";" if you
55
        # input one from the manual controls.
56
        rf.valid_characters = chirp_common.CHARSET_ASCII.replace(';', '')
57
        rf.valid_name_length = 7    # 7 character channel names
58
        rf.memory_bounds = (0, self._upper)
59
        return rf
60

    
61
    def _cmd_set_memory(self, number, spec):
62
        return "MW0%03i%s" % (number, spec)
63

    
64
    def _cmd_get_memory(self, number):
65
        return "MR0%03i" % number
66

    
67
    def _cmd_recall_memory(self, number):
68
        return "MC%03i" % (number)
69

    
70
    def _cmd_get_split(self, number):
71
        return "MR1%03i" % number
72

    
73
    def _cmd_set_split(self, number, spec):
74
        return "MW1%03i%s" % (number, spec)
75

    
76
    def get_memory(self, number):
77
        if number < 0 or number > self._upper:
78
            raise errors.InvalidMemoryLocation( \
79
                "Number must be between 0 and %i" % self._upper)
80
        if number in self._memcache and not NOCACHE:
81
            return self._memcache[number]
82

    
83
        result = command(self.pipe, *self._cmd_get_memory(number))
84
        if result == "N":
85
            mem = chirp_common.Memory()
86
            mem.number = number
87
            mem.empty = True
88
            self._memcache[mem.number] = mem
89
            return mem
90

    
91
        spec = result[2:]
92

    
93
        mem = self._parse_mem_spec(result)
94
        self._memcache[mem.number] = mem
95

    
96
        # FIXME
97
        if mem.duplex == "" and self._kenwood_split:
98
            result = command(self.pipe, *self._cmd_get_split(number))
99

    
100
            # TODO dirty hack for now, and life goes on
101
            #
102
            # really, this needs to be checked from the radio output, but radio is
103
            # queried RX and TX channel separatedly and gives the same freq info
104
            # whether it's simplex, offset, and unsure of split at moment.
105
            split = False
106
            if split:
107
                self._parse_split_spec(mem, result)
108

    
109
        return mem
110
    
111
    def _parse_mem_spec(self, spec):
112
        mem = chirp_common.Memory()
113

    
114
        # pad string so indexes match Kenwood docs
115
        spec = " " + spec
116
        
117
        # use the same variable names as the Kenwood docs
118
        _p1  = spec[3]
119
        _p2  = spec[4]
120
        _p3  = spec[5:7]
121
        _p4  = spec[7:18]
122
        _p5  = spec[18]
123
        _p6  = spec[19]
124
        _p7  = spec[20]
125
        _p8  = spec[21:23]
126
        _p9  = spec[23:25]
127
        _p10 = spec[25:28]
128
        _p11 = spec[28]
129
        _p12 = spec[29]
130
        _p13 = spec[30:39]
131
        _p14 = spec[39:41]
132
        _p15 = spec[41]
133
        _p16 = spec[42:49]
134

    
135
        mem.number = int(_p2 + _p3) # concat bank num and chan num
136
        mem.freq = int(_p4)
137
        mem.mode = TS2000_MODES[int(_p5)]
138
        mem.skip = ["", "S"][int(_p6)]
139
        mem.tmode = TS2000_TMODES[int(_p7)]
140
        mem.rtone = self._kenwood_valid_tones[int(_p8) - 1] # PL is 1 indexed
141
        mem.ctone = self._kenwood_valid_tones[int(_p9) - 1] # CTCSS is 1 indexed
142
        mem.dtcs = chirp_common.DTCS_CODES[int(_p10)]       # DCS is 0 indexed
143
        mem.duplex = TS2000_DUPLEX[int(_p12)]
144
        mem.offset = int(_p13) # 9-digit
145
        if mem.mode in ["AM", "FM"]:
146
            mem.tuning_step = TS2000_FM_STEPS[int(_p14)]
147
        else:
148
            mem.tuning_step = TS2000_SSB_STEPS[int(_p14)]
149
        mem.name = _p16
150

    
151
        return mem
152

    
153
    def set_memory(self, memory):
154
        if memory.number < 0 or memory.number > self._upper:
155
            raise errors.InvalidMemoryLocation( \
156
                "Number must be between 0 and %i" % self._upper)
157

    
158
        spec = self._make_mem_spec(memory)
159
        spec = "".join(spec)
160
        r1 = command(self.pipe, *self._cmd_set_memory(memory.number, spec))
161
        if not iserr(r1):
162
            memory.name = memory.name.rstrip()
163
            self._memcache[memory.number] = memory
164
        else:
165
            raise errors.InvalidDataError("Radio refused %i" % memory.number)
166

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

    
205
        return spec
(9-9/10)