Project

General

Profile

Bug #10386 » ft90.py

37bed886 - Dan Smith, 02/22/2023 11:34 PM

 
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
        start = time.time()
292

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
652
        return top
653

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