Project

General

Profile

Bug #10386 » ft90.py

b0cd02bd - Dan Smith, 02/23/2023 01:03 AM

 
1
# Copyright 2011 Dan Smith <dsmith@danplanet.com>
2
# Copyright 2013 Jens Jensen AF5MI <kd4tjx@yahoo.com>
3
#
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

    
17
from chirp.drivers import yaesu_clone
18
from chirp import chirp_common, bitwise, memmap, directory, errors, util
19
from chirp.settings import RadioSetting, RadioSettingGroup, \
20
    RadioSettingValueInteger, RadioSettingValueList, \
21
    RadioSettingValueBoolean, RadioSettingValueString, \
22
    RadioSettings
23

    
24
import time
25
import os
26
import traceback
27
import string
28
import re
29
import logging
30

    
31
from textwrap import dedent
32

    
33
LOG = logging.getLogger(__name__)
34

    
35
CMD_ACK = b'\x06'
36

    
37
FT90_STEPS = [5.0, 10.0, 12.5, 15.0, 20.0, 25.0, 50.0]
38
FT90_MODES = ["AM", "FM", "Auto"]
39
# idx 3 (Bell) not supported yet
40
FT90_TMODES = ["", "Tone", "TSQL", "", "DTCS"]
41
FT90_TONES = list(chirp_common.TONES)
42
for tone in [165.5, 171.3, 177.3]:
43
    FT90_TONES.remove(tone)
44
FT90_POWER_LEVELS_VHF = [chirp_common.PowerLevel("Hi", watts=50),
45
                         chirp_common.PowerLevel("Mid1", watts=20),
46
                         chirp_common.PowerLevel("Mid2", watts=10),
47
                         chirp_common.PowerLevel("Low", watts=5)]
48

    
49
FT90_POWER_LEVELS_UHF = [chirp_common.PowerLevel("Hi", watts=35),
50
                         chirp_common.PowerLevel("Mid1", watts=20),
51
                         chirp_common.PowerLevel("Mid2", watts=10),
52
                         chirp_common.PowerLevel("Low", watts=5)]
53

    
54
FT90_DUPLEX = ["", "-", "+", "split"]
55
FT90_CWID_CHARS = list(string.digits) + list(string.ascii_uppercase) \
56
                  + list(" ")
57
FT90_DTMF_CHARS = list("0123456789ABCD*#")
58
FT90_SPECIAL = ["vfo_vhf", "home_vhf", "vfo_uhf", "home_uhf",
59
                "pms_1L", "pms_1U", "pms_2L", "pms_2U"]
60

    
61

    
62
@directory.register
63
class FT90Radio(yaesu_clone.YaesuCloneModeRadio):
64
    VENDOR = "Yaesu"
65
    MODEL = "FT-90"
66
    ID = b"\x8E\xF6"
67
    NEEDS_COMPAT_SERIAL = False
68

    
69
    _memsize = 4063
70
    # block 03 (200 Bytes long) repeats 18 times; channel memories
71
    _block_lengths = [2, 232, 24] + ([200] * 18) + [205]
72

    
73
    mem_format = """
74
u16 id;
75
#seekto 0x22;
76
struct {
77
    u8 dtmf_active;
78
    u8 dtmf1_len;
79
    u8 dtmf2_len;
80
    u8 dtmf3_len;
81
    u8 dtmf4_len;
82
    u8 dtmf5_len;
83
    u8 dtmf6_len;
84
    u8 dtmf7_len;
85
    u8 dtmf8_len;
86
    u8 dtmf1[8];
87
    u8 dtmf2[8];
88
    u8 dtmf3[8];
89
    u8 dtmf4[8];
90
    u8 dtmf5[8];
91
    u8 dtmf6[8];
92
    u8 dtmf7[8];
93
    u8 dtmf8[8];
94
    char cwid[7];
95
    u8 unk1;
96
    u8 scan1:2,
97
       beep:1,
98
       unk3:3,
99
       rfsqlvl:2;
100
    u8 unk4:2,
101
       scan2:1,
102
       cwid_en:1,
103
       txnarrow:1,
104
       dtmfspeed:1,
105
       pttlock:2;
106
    u8 dtmftxdelay:3,
107
       fancontrol:2,
108
       unk5:3;
109
    u8 dimmer:3,
110
       unk6:1,
111
       lcdcontrast:4;
112
    u8 dcsmode:2,
113
       unk16:2,
114
       tot:4;
115
    u8 unk14;
116
    u8 unk8:1,
117
       ars:1,
118
       lock:1,
119
       txpwrsave:1,
120
       apo:4;
121
    u8 unk15;
122
    u8 unk9:4,
123
       key_lt:4;
124
    u8 unk10:4,
125
       key_rt:4;
126
    u8 unk11:4,
127
       key_p1:4;
128
    u8 unk12:4,
129
       key_p2:4;
130
    u8 unk13:4,
131
       key_acc:4;
132
} settings;
133

    
134
struct mem_struct {
135
    u8 mode:2,
136
       isUhf1:1,
137
       unknown1:2,
138
       step:3;
139
    u8 artsmode:2,
140
       unknown2:1,
141
       isUhf2:1
142
       power:2,
143
       shift:2;
144
    u8 skip:1,
145
       showname:1,
146
       unknown3:1,
147
       isUhfHi:1,
148
       unknown4:1,
149
       tmode:3;
150
    u32 rxfreq;
151
    u32 txfreqoffset;
152
    u8 UseDefaultName:1,
153
       ars:1,
154
       tone:6;
155
    u8 packetmode:1,
156
       unknown5:1,
157
       dcstone:6;
158
    char name[7];
159
};
160

    
161
#seekto 0x86;
162
struct mem_struct vfo_vhf;
163
struct mem_struct home_vhf;
164
struct mem_struct vfo_uhf;
165
struct mem_struct home_uhf;
166

    
167
#seekto 0xEB;
168
u8 chan_enable[23];
169

    
170
#seekto 0x101;
171
struct {
172
    u8 pms_2U_enable:1,
173
       pms_2L_enable:1,
174
       pms_1U_enable:1,
175
       pms_1L_enable:1,
176
       unknown6:4;
177
} special_enables;
178

    
179
#seekto 0x102;
180
struct mem_struct memory[180];
181

    
182
#seekto 0xf12;
183
struct mem_struct pms_1L;
184
struct mem_struct pms_1U;
185
struct mem_struct pms_2L;
186
struct mem_struct pms_2U;
187

    
188
#seekto 0x0F7B;
189
struct  {
190
    char demomsg1[50];
191
    char demomsg2[50];
192
} demomsg;
193
"""
194

    
195
    @classmethod
196
    def get_prompts(cls):
197
        rp = chirp_common.RadioPrompts()
198
        rp.pre_download = _(dedent("""\
199
1. Turn radio off.
200
2. Connect mic and hold [ACC] on mic while powering on.
201
    ("CLONE" will appear on the display)
202
3. Replace mic with PC programming cable.
203
4. <b>After clicking OK</b>, press the [SET] key to send image."""))
204
        rp.pre_upload = _(dedent("""\
205
1. Turn radio off.
206
2. Connect mic and hold [ACC] on mic while powering on.
207
    ("CLONE" will appear on the display)
208
3. Replace mic with PC programming cable.
209
4. Press the [DISP/SS] key
210
    ("R" will appear on the lower left of LCD)."""))
211
        rp.display_pre_upload_prompt_before_opening_port = False
212
        return rp
213

    
214
    @classmethod
215
    def match_model(cls, filedata, filename):
216
        return len(filedata) == cls._memsize
217

    
218
    def get_features(self):
219
        rf = chirp_common.RadioFeatures()
220
        rf.has_settings = True
221
        rf.has_ctone = False
222
        rf.has_bank = False
223
        rf.has_dtcs_polarity = False
224
        rf.has_dtcs = True
225
        rf.valid_modes = FT90_MODES
226
        rf.valid_tmodes = FT90_TMODES
227
        rf.valid_duplexes = FT90_DUPLEX
228
        rf.valid_tuning_steps = FT90_STEPS
229
        rf.valid_power_levels = FT90_POWER_LEVELS_VHF
230
        rf.valid_name_length = 7
231
        rf.valid_characters = chirp_common.CHARSET_ASCII
232
        rf.valid_skips = ["", "S"]
233
        rf.valid_special_chans = FT90_SPECIAL
234
        rf.memory_bounds = (1, 180)
235
        rf.valid_bands = [(100000000, 230000000),
236
                          (300000000, 530000000),
237
                          (810000000, 999975000)]
238

    
239
        return rf
240

    
241
    def _read(self, blocksize, blocknum):
242
        data = self.pipe.read(blocksize+2)
243

    
244
        # chew echo'd ack
245
        self.pipe.write(CMD_ACK)
246
        time.sleep(0.02)
247
        self.pipe.read(1)  # chew echoed ACK from 1-wire serial
248

    
249
        if len(data) == blocksize + 2 and data[0] == blocknum:
250
            checksum = yaesu_clone.YaesuChecksum(1, blocksize)
251
            if checksum.get_existing(data) != checksum.get_calculated(data):
252
                raise Exception("Checksum Failed [%02X<>%02X] block %02X, "
253
                                "data len: %i" %
254
                                (checksum.get_existing(data),
255
                                 checksum.get_calculated(data),
256
                                 blocknum, len(data)))
257
            data = data[1:blocksize + 1]  # Chew blocknum and checksum
258

    
259
        else:
260
            raise Exception("Unable to read blocknum %02X "
261
                            "expected blocksize %i got %i." %
262
                            (blocknum, blocksize+2, len(data)))
263

    
264
        return data
265

    
266
    def _clone_in(self):
267
        # Be very patient with the radio
268
        self.pipe.timeout = 4
269
        start = time.time()
270

    
271
        data = b""
272
        blocknum = 0
273
        status = chirp_common.Status()
274
        status.msg = "Cloning..."
275
        self.status_fn(status)
276
        status.max = len(self._block_lengths)
277
        for blocksize in self._block_lengths:
278
            data += self._read(blocksize, blocknum)
279
            blocknum += 1
280
            status.cur = blocknum
281
            self.status_fn(status)
282

    
283
        LOG.info("Clone completed in %i seconds, blocks read: %i" %
284
                 (time.time() - start, blocknum))
285

    
286
        return memmap.MemoryMapBytes(data)
287

    
288
    def _clone_out(self):
289
        looppredelay = 0.4
290
        looppostdelay = 1.9
291
        self.pipe.timeout = 4
292
        start = time.time()
293

    
294
        blocknum = 0
295
        pos = 0
296
        status = chirp_common.Status()
297
        status.msg = "Cloning to radio..."
298
        self.status_fn(status)
299
        status.max = len(self._block_lengths)
300

    
301
        for blocksize in self._block_lengths:
302
            checksum = yaesu_clone.YaesuChecksum(pos, pos+blocksize-1)
303
            blocknumbyte = bytes([blocknum])
304
            payloadbytes = self.get_mmap()[pos:pos+blocksize]
305
            checksumbyte = bytes([checksum.get_calculated(self.get_mmap())])
306
            LOG.debug("Block %i - will send from %i to %i byte " %
307
                      (blocknum, pos, pos + blocksize))
308
            LOG.debug(util.hexprint(blocknumbyte))
309
            LOG.debug(util.hexprint(payloadbytes))
310
            LOG.debug(util.hexprint(checksumbyte))
311
            # send wrapped bytes
312
            time.sleep(looppredelay)
313
            self.pipe.write(blocknumbyte)
314
            self.pipe.write(payloadbytes)
315
            self.pipe.write(checksumbyte)
316
            tmp = self.pipe.read(blocksize + 2)  # chew echo
317
            LOG.debug("bytes echoed: ")
318
            LOG.debug(util.hexprint(tmp))
319
            # radio is slow to write/ack:
320
            time.sleep(looppostdelay)
321
            buf = self.pipe.read(1)
322
            LOG.debug("ack recd:")
323
            LOG.debug(util.hexprint(buf))
324
            if buf != CMD_ACK:
325
                raise Exception("Radio did not ack block %i" % blocknum)
326
            pos += blocksize
327
            blocknum += 1
328
            status.cur = blocknum
329
            self.status_fn(status)
330

    
331
        LOG.info("Clone completed in %i seconds" % (time.time() - start))
332

    
333
    def sync_in(self):
334
        try:
335
            self._mmap = self._clone_in()
336
        except errors.RadioError:
337
            raise
338
        except Exception as e:
339
            trace = traceback.format_exc()
340
            raise errors.RadioError(
341
                    "Failed to communicate with radio: %s" % trace)
342
        self.process_mmap()
343

    
344
    def sync_out(self):
345
        try:
346
            self._clone_out()
347
        except errors.RadioError:
348
            raise
349
        except Exception as e:
350
            trace = traceback.format_exc()
351
            raise errors.RadioError(
352
                    "Failed to communicate with radio: %s" % trace)
353

    
354
    def process_mmap(self):
355
        self._memobj = bitwise.parse(self.mem_format, self._mmap)
356

    
357
    def _get_chan_enable(self, number):
358
        number = number - 1
359
        bytepos = number // 8
360
        bitpos = number % 8
361
        chan_enable = self._memobj.chan_enable[bytepos]
362
        if chan_enable & (1 << bitpos):
363
            return True
364
        else:
365
            return False
366

    
367
    def _set_chan_enable(self, number, enable):
368
        number = number - 1
369
        bytepos = number // 8
370
        bitpos = number % 8
371
        chan_enable = self._memobj.chan_enable[bytepos]
372
        if enable:
373
            chan_enable = chan_enable | (1 << bitpos)  # enable
374
        else:
375
            chan_enable = chan_enable & ~(1 << bitpos)  # disable
376
        self._memobj.chan_enable[bytepos] = chan_enable
377

    
378
    def get_memory(self, number):
379
        mem = chirp_common.Memory()
380
        if isinstance(number, str):
381
            # special channel
382
            _mem = getattr(self._memobj, number)
383
            mem.number = - len(FT90_SPECIAL) + FT90_SPECIAL.index(number)
384
            mem.extd_number = number
385
            if re.match('^pms', mem.extd_number):
386
                # enable pms_XY channel flag
387
                _special_enables = self._memobj.special_enables
388
                mem.empty = not getattr(_special_enables,
389
                                        mem.extd_number + "_enable")
390
        else:
391
            # regular memory
392
            _mem = self._memobj.memory[number-1]
393
            mem.number = number
394
            mem.empty = not self._get_chan_enable(number)
395
        if mem.empty:
396
            return mem  # bail out, do not parse junk
397
        mem.freq = _mem.rxfreq * 10
398
        mem.offset = _mem.txfreqoffset * 10
399
        if not _mem.tmode < len(FT90_TMODES):
400
            _mem.tmode = 0
401
        mem.tmode = FT90_TMODES[_mem.tmode]
402
        mem.rtone = FT90_TONES[_mem.tone]
403
        mem.dtcs = chirp_common.DTCS_CODES[_mem.dcstone]
404
        mem.mode = FT90_MODES[_mem.mode]
405
        mem.duplex = FT90_DUPLEX[_mem.shift]
406
        if mem.freq / 1000000 > 300:
407
            mem.power = FT90_POWER_LEVELS_UHF[_mem.power]
408
        else:
409
            mem.power = FT90_POWER_LEVELS_VHF[_mem.power]
410

    
411
        # radio has a known bug with 5khz step and squelch
412
        if _mem.step == 0 or _mem.step > len(FT90_STEPS)-1:
413
            _mem.step = 2
414
        mem.tuning_step = FT90_STEPS[_mem.step]
415
        mem.skip = _mem.skip and "S" or ""
416
        if not all(char in chirp_common.CHARSET_ASCII
417
                   for char in str(_mem.name)):
418
            # dont display blank/junk name
419
            mem.name = ""
420
        else:
421
            mem.name = str(_mem.name)
422
        return mem
423

    
424
    def get_raw_memory(self, number):
425
        return repr(self._memobj.memory[number-1])
426

    
427
    def set_memory(self, mem):
428
        if mem.number < 0:      # special channels
429
            _mem = getattr(self._memobj, mem.extd_number)
430
            if re.match('^pms', mem.extd_number):
431
                # enable pms_XY channel flag
432
                _special_enables = self._memobj.special_enables
433
                setattr(_special_enables, mem.extd_number + "_enable", True)
434
        else:
435
            _mem = self._memobj.memory[mem.number - 1]
436
            self._set_chan_enable(mem.number, not mem.empty)
437
        _mem.skip = mem.skip == "S"
438
        # radio has a known bug with 5khz step and dead squelch
439
        if not mem.tuning_step or mem.tuning_step == FT90_STEPS[0]:
440
            _mem.step = 2
441
        else:
442
            _mem.step = FT90_STEPS.index(mem.tuning_step)
443
        _mem.rxfreq = mem.freq / 10
444
        # vfo will unlock if not in right band?
445
        if mem.freq > 300000000:
446
            # uhf
447
            _mem.isUhf1 = 1
448
            _mem.isUhf2 = 1
449
            if mem.freq > 810000000:
450
                # uhf hiband
451
                _mem.isUhfHi = 1
452
            else:
453
                _mem.isUhfHi = 0
454
        else:
455
            # vhf
456
            _mem.isUhf1 = 0
457
            _mem.isUhf2 = 0
458
            _mem.isUhfHi = 0
459
        _mem.txfreqoffset = mem.offset / 10
460
        _mem.tone = FT90_TONES.index(mem.rtone)
461
        _mem.tmode = FT90_TMODES.index(mem.tmode)
462
        _mem.mode = FT90_MODES.index(mem.mode)
463
        _mem.shift = FT90_DUPLEX.index(mem.duplex)
464
        _mem.dcstone = chirp_common.DTCS_CODES.index(mem.dtcs)
465
        _mem.step = FT90_STEPS.index(mem.tuning_step)
466
        _mem.shift = FT90_DUPLEX.index(mem.duplex)
467
        if mem.power:
468
            _mem.power = FT90_POWER_LEVELS_VHF.index(mem.power)
469
        else:
470
            _mem.power = 3  # default to low power
471
        if (len(mem.name) == 0):
472
            _mem.name = bytearray.fromhex("80ffffffffffff")
473
            _mem.showname = 0
474
        else:
475
            _mem.name = str(mem.name).ljust(7)
476
            _mem.showname = 1
477
            _mem.UseDefaultName = 0
478

    
479
    def _decode_cwid(self, cwidarr):
480
        cwid = ""
481
        LOG.debug("@ +_decode_cwid:")
482
        for byte in cwidarr.get_value():
483
            char = int(byte)
484
            LOG.debug(char)
485
            # bitwise wraps in quotes! get rid of those
486
            if char < len(FT90_CWID_CHARS):
487
                cwid += FT90_CWID_CHARS[char]
488
        return cwid
489

    
490
    def _encode_cwid(self, cwidarr):
491
        cwid = ""
492
        LOG.debug("@ _encode_cwid:")
493
        for char in cwidarr.get_value():
494
            cwid += chr(FT90_CWID_CHARS.index(char))
495
        LOG.debug(cwid)
496
        return cwid
497

    
498
    def _bbcd2dtmf(self, bcdarr, strlen=16):
499
        # doing bbcd, but with support for ABCD*#
500
        LOG.debug(bcdarr.get_value())
501
        string = ''.join("%02X" % b for b in bcdarr)
502
        LOG.debug("@_bbcd2dtmf, received: %s" % string)
503
        string = string.replace('E', '*').replace('F', '#')
504
        if strlen <= 16:
505
            string = string[:strlen]
506
        return string
507

    
508
    def _dtmf2bbcd(self, dtmf):
509
        dtmfstr = dtmf.get_value()
510
        dtmfstr = dtmfstr.replace('*', 'E').replace('#', 'F')
511
        dtmfstr = str.ljust(dtmfstr.strip(), 16, "0")
512
        bcdarr = list(bytearray.fromhex(dtmfstr))
513
        LOG.debug("@_dtmf2bbcd, sending: %s" % bcdarr)
514
        return bcdarr
515

    
516
    def get_settings(self):
517
        _settings = self._memobj.settings
518
        basic = RadioSettingGroup("basic", "Basic")
519
        autodial = RadioSettingGroup("autodial", "AutoDial")
520
        keymaps = RadioSettingGroup("keymaps", "KeyMaps")
521

    
522
        top = RadioSettings(basic, keymaps, autodial)
523

    
524
        rs = RadioSetting(
525
                "beep", "Beep",
526
                RadioSettingValueBoolean(_settings.beep))
527
        basic.append(rs)
528
        rs = RadioSetting(
529
                "lock", "Lock",
530
                RadioSettingValueBoolean(_settings.lock))
531
        basic.append(rs)
532
        rs = RadioSetting(
533
                "ars", "Auto Repeater Shift",
534
                RadioSettingValueBoolean(_settings.ars))
535
        basic.append(rs)
536
        rs = RadioSetting(
537
                "txpwrsave", "TX Power Save",
538
                RadioSettingValueBoolean(_settings.txpwrsave))
539
        basic.append(rs)
540
        rs = RadioSetting(
541
                "txnarrow", "TX Narrow",
542
                RadioSettingValueBoolean(_settings.txnarrow))
543
        basic.append(rs)
544
        options = ["Off", "S-3", "S-5", "S-Full"]
545
        rs = RadioSetting(
546
                "rfsqlvl", "RF Squelch Level",
547
                RadioSettingValueList(options, options[_settings.rfsqlvl]))
548
        basic.append(rs)
549
        options = ["Off", "Band A", "Band B", "Both"]
550
        rs = RadioSetting(
551
                "pttlock", "PTT Lock",
552
                RadioSettingValueList(options, options[_settings.pttlock]))
553
        basic.append(rs)
554

    
555
        rs = RadioSetting(
556
                "cwid_en", "CWID Enable",
557
                RadioSettingValueBoolean(_settings.cwid_en))
558
        basic.append(rs)
559

    
560
        cwid = RadioSettingValueString(0, 7, self._decode_cwid(_settings.cwid))
561
        cwid.set_charset(FT90_CWID_CHARS)
562
        rs = RadioSetting("cwid", "CWID", cwid)
563
        basic.append(rs)
564

    
565
        options = ["OFF"] + [str(x) for x in (range(1, 12+1))]
566
        rs = RadioSetting(
567
                "apo", "APO time (hrs)",
568
                RadioSettingValueList(options, options[_settings.apo]))
569
        basic.append(rs)
570

    
571
        options = ["Off"] + [str(x) for x in (range(1, 60+1))]
572
        rs = RadioSetting(
573
                "tot", "Time Out Timer (mins)",
574
                RadioSettingValueList(options, options[_settings.tot]))
575
        basic.append(rs)
576

    
577
        options = ["off", "Auto/TX", "Auto", "TX"]
578
        rs = RadioSetting(
579
                "fancontrol", "Fan Control",
580
                RadioSettingValueList(options, options[_settings.fancontrol]))
581
        basic.append(rs)
582

    
583
        keyopts = ["Scan Up", "Scan Down", "Repeater", "Reverse", "Tone Burst",
584
                   "Tx Power", "Home Ch", "VFO/MR", "Tone", "Priority"]
585
        rs = RadioSetting(
586
                "key_lt", "Left Key",
587
                RadioSettingValueList(keyopts, keyopts[_settings.key_lt]))
588
        keymaps.append(rs)
589
        rs = RadioSetting(
590
                "key_rt", "Right Key",
591
                RadioSettingValueList(keyopts, keyopts[_settings.key_rt]))
592
        keymaps.append(rs)
593
        rs = RadioSetting(
594
                "key_p1", "P1 Key",
595
                RadioSettingValueList(keyopts, keyopts[_settings.key_p1]))
596
        keymaps.append(rs)
597
        rs = RadioSetting(
598
                "key_p2", "P2 Key",
599
                RadioSettingValueList(keyopts, keyopts[_settings.key_p2]))
600
        keymaps.append(rs)
601
        rs = RadioSetting(
602
                "key_acc", "ACC Key",
603
                RadioSettingValueList(keyopts, keyopts[_settings.key_acc]))
604
        keymaps.append(rs)
605

    
606
        options = [str(x) for x in range(0, 12+1)]
607
        rs = RadioSetting(
608
                "lcdcontrast", "LCD Contrast",
609
                RadioSettingValueList(options, options[_settings.lcdcontrast]))
610
        basic.append(rs)
611

    
612
        options = ["off", "d4", "d3", "d2", "d1"]
613
        rs = RadioSetting(
614
                "dimmer", "Dimmer",
615
                RadioSettingValueList(options, options[_settings.dimmer]))
616
        basic.append(rs)
617

    
618
        options = ["TRX Normal", "RX Reverse", "TX Reverse", "TRX Reverse"]
619
        rs = RadioSetting(
620
                "dcsmode", "DCS Mode",
621
                RadioSettingValueList(options, options[_settings.dcsmode]))
622
        basic.append(rs)
623

    
624
        options = ["50 ms", "100 ms"]
625
        rs = RadioSetting(
626
                "dtmfspeed", "DTMF Speed",
627
                RadioSettingValueList(options, options[_settings.dtmfspeed]))
628
        autodial.append(rs)
629

    
630
        options = ["50 ms", "250 ms", "450 ms", "750 ms", "1 sec"]
631
        rs = RadioSetting(
632
                "dtmftxdelay", "DTMF TX Delay",
633
                RadioSettingValueList(options, options[_settings.dtmftxdelay]))
634
        autodial.append(rs)
635

    
636
        options = [str(x) for x in range(1, 8 + 1)]
637
        rs = RadioSetting(
638
                "dtmf_active", "DTMF Active",
639
                RadioSettingValueList(options, options[_settings.dtmf_active]))
640
        autodial.append(rs)
641

    
642
        # setup 8 dtmf autodial entries
643
        for i in range(1, 9):
644
            objname = "dtmf" + str(i)
645
            dtmfsetting = getattr(_settings, objname)
646
            dtmflen = getattr(_settings, objname + "_len")
647
            dtmfstr = self._bbcd2dtmf(dtmfsetting, dtmflen)
648
            dtmf = RadioSettingValueString(0, 16, dtmfstr)
649
            dtmf.set_charset(FT90_DTMF_CHARS + list(" "))
650
            rs = RadioSetting(objname, objname.upper(), dtmf)
651
            autodial.append(rs)
652

    
653
        return top
654

    
655
    def set_settings(self, uisettings):
656
        _settings = self._memobj.settings
657
        for element in uisettings:
658
            if not isinstance(element, RadioSetting):
659
                self.set_settings(element)
660
                continue
661
            if not element.changed():
662
                continue
663
            try:
664
                setting = element.get_name()
665
                oldval = getattr(_settings, setting)
666
                newval = element.value
667
                if setting == "cwid":
668
                    newval = self._encode_cwid(newval)
669
                if re.match('dtmf\d', setting):
670
                    # set dtmf length field and then get bcd dtmf
671
                    dtmfstrlen = len(str(newval).strip())
672
                    setattr(_settings, setting + "_len", dtmfstrlen)
673
                    newval = self._dtmf2bbcd(newval)
674
                LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval))
675
                setattr(_settings, setting, newval)
676
            except Exception as e:
677
                LOG.debug(element.get_name())
678
                raise
(5-5/10)