Project

General

Profile

Feature #9825 » btech-set_kt8900_band_limits_#6.py

Jim Unroe, 04/11/2022 03:07 AM

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

    
18
import time
19
import struct
20
import logging
21

    
22
from time import sleep
23
from chirp import chirp_common, directory, memmap
24
from chirp import bitwise, errors, util
25
from chirp.settings import RadioSettingGroup, RadioSetting, \
26
    RadioSettingValueBoolean, RadioSettingValueList, \
27
    RadioSettingValueString, RadioSettingValueInteger, \
28
    RadioSettingValueFloat, RadioSettings, InvalidValueError
29
from textwrap import dedent
30

    
31
LOG = logging.getLogger(__name__)
32

    
33
# A note about the memmory in these radios
34
#
35
# The real memory of these radios extends to 0x4000
36
# On read the factory software only uses up to 0x3200
37
# On write it just uploads the contents up to 0x3100
38
#
39
# The mem beyond 0x3200 holds the ID data
40

    
41
MEM_SIZE = 0x4000
42
BLOCK_SIZE = 0x40
43
TX_BLOCK_SIZE = 0x10
44
ACK_CMD = "\x06"
45
MODES = ["FM", "NFM"]
46
SKIP_VALUES = ["S", ""]
47
TONES = chirp_common.TONES
48
DTCS = sorted(chirp_common.DTCS_CODES + [645])
49

    
50
# lists related to "extra" settings
51
PTTID_LIST = ["OFF", "BOT", "EOT", "BOTH"]
52
PTTIDCODE_LIST = ["%s" % x for x in range(1, 16)]
53
OPTSIG_LIST = ["OFF", "DTMF", "2TONE", "5TONE"]
54
SPMUTE_LIST = ["Tone/DTCS", "Tone/DTCS and Optsig", "Tone/DTCS or Optsig"]
55

    
56
# lists
57
LIST_AB = ["A", "B"]
58
LIST_ABCD = LIST_AB + ["C", "D"]
59
LIST_ANIL = ["3", "4", "5"]
60
LIST_APO = ["Off"] + ["%s minutes" % x for x in range(30, 330, 30)]
61
LIST_COLOR4 = ["Off", "Blue", "Orange", "Purple"]
62
LIST_COLOR8 = ["White", "Red", "Blue", "Green", "Yellow", "Indego",
63
               "Purple", "Gray"]
64
LIST_COLOR9 = ["Black"] + LIST_COLOR8
65
LIST_DTMFST = ["OFF", "Keyboard", "ANI", "Keyboad + ANI"]
66
LIST_EMCTP = ["TX alarm sound", "TX ANI", "Both"]
67
LIST_EMCTPX = ["Off"] + LIST_EMCTP
68
LIST_LANGUA = ["English", "Chinese"]
69
LIST_MDF = ["Frequency", "Channel", "Name"]
70
LIST_OFF1TO9 = ["Off"] + ["%s seconds" % x for x in range(1, 10)]
71
LIST_OFF1TO10 = ["Off"] + ["%s seconds" % x for x in range(1, 11)]
72
LIST_OFF1TO50 = ["Off"] + ["%s seconds" % x for x in range(1, 51)]
73
LIST_PONMSG = ["Full", "Message", "Battery voltage"]
74
LIST_REPM = ["Off", "Carrier", "CTCSS or DCS", "Tone", "DTMF"]
75
LIST_REPS = ["1000 Hz", "1450 Hz", "1750 Hz", "2100Hz"]
76
LIST_RPTDL = ["Off"] + ["%s ms" % x for x in range(1, 11)]
77
LIST_SCMODE = ["Off", "PTT-SC", "MEM-SC", "PON-SC"]
78
LIST_SHIFT = ["Off", "+", "-"]
79
LIST_SKIPTX = ["Off", "Skip 1", "Skip 2"]
80
STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 25.0]
81
LIST_STEP = [str(x) for x in STEPS]
82
LIST_SYNC = ["Off", "AB", "CD", "AB+CD"]
83
# the first 12 TMR choices common to all color display mobile radios
84
LIST_TMR12 = ["OFF", "M+A", "M+B", "M+C", "M+D", "M+A+B", "M+A+C", "M+A+D",
85
              "M+B+C", "M+B+D", "M+C+D", "M+A+B+C"]
86
# the 16 choice list for color display mobile radios that correctly implement
87
# the full 16 TMR choices
88
LIST_TMR16 = LIST_TMR12 + ["M+A+B+D", "M+A+C+D", "M+B+C+D", "A+B+C+D"]
89
# the 15 choice list for color mobile radios that are missing the M+A+B+D
90
# choice in the TMR menu
91
LIST_TMR15 = LIST_TMR12 + ["M+A+C+D", "M+B+C+D", "A+B+C+D"]
92
LIST_TMRTX = ["Track", "Fixed"]
93
LIST_TOT = ["%s sec" % x for x in range(15, 615, 15)]
94
LIST_TXDISP = ["Power", "Mic Volume"]
95
LIST_TXP = ["High", "Low"]
96
LIST_TXP3 = ["High", "Mid", "Low"]
97
LIST_SCREV = ["TO (timeout)", "CO (carrier operated)", "SE (search)"]
98
LIST_VFOMR = ["Frequency", "Channel"]
99
LIST_VOICE = ["Off"] + LIST_LANGUA
100
LIST_VOX = ["Off"] + ["%s" % x for x in range(1, 11)]
101
LIST_VOXT = ["%s seconds" % x for x in range(0, 21)]
102
LIST_WIDE = ["Wide", "Narrow"]
103

    
104
# lists related to DTMF, 2TONE and 5TONE settings
105
LIST_5TONE_STANDARDS = ["CCIR1", "CCIR2", "PCCIR", "ZVEI1", "ZVEI2", "ZVEI3",
106
                        "PZVEI", "DZVEI", "PDZVEI", "EEA", "EIA", "EURO",
107
                        "CCITT", "NATEL", "MODAT", "none"]
108
LIST_5TONE_STANDARDS_without_none = ["CCIR1", "CCIR2", "PCCIR", "ZVEI1",
109
                                     "ZVEI2", "ZVEI3",
110
                                     "PZVEI", "DZVEI", "PDZVEI", "EEA", "EIA",
111
                                     "EURO", "CCITT", "NATEL", "MODAT"]
112
LIST_5TONE_STANDARD_PERIODS = ["20", "30", "40", "50", "60", "70", "80", "90",
113
                               "100", "110", "120", "130", "140", "150", "160",
114
                               "170", "180", "190", "200"]
115
LIST_5TONE_DIGITS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
116
                     "B", "C", "D", "E", "F"]
117
LIST_5TONE_DELAY = ["%s ms" % x for x in range(0, 1010, 10)]
118
LIST_5TONE_RESET = ["%s ms" % x for x in range(100, 8100, 100)]
119
LIST_5TONE_RESET_COLOR = ["%s ms" % x for x in range(100, 20100, 100)]
120
LIST_DTMF_SPEED = ["%s ms" % x for x in range(50, 2010, 10)]
121
LIST_DTMF_DIGITS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B",
122
                    "C", "D", "#", "*"]
123
LIST_DTMF_VALUES = [0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
124
                    0x0D, 0x0E, 0x0F, 0x00, 0x0C, 0x0B]
125
LIST_DTMF_SPECIAL_DIGITS = ["*", "#", "A", "B", "C", "D"]
126
LIST_DTMF_SPECIAL_VALUES = [0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00]
127
LIST_DTMF_DELAY = ["%s ms" % x for x in range(100, 4100, 100)]
128
CHARSET_DTMF_DIGITS = "0123456789AaBbCcDd#*"
129
LIST_2TONE_DEC = ["A-B", "A-C", "A-D",
130
                  "B-A", "B-C", "B-D",
131
                  "C-A", "C-B", "C-D",
132
                  "D-A", "D-B", "D-C"]
133
LIST_2TONE_RESPONSE = ["None", "Alert", "Transpond", "Alert+Transpond"]
134

    
135
# This is a general serial timeout for all serial read functions.
136
# Practice has show that about 0.7 sec will be enough to cover all radios.
137
STIMEOUT = 0.7
138

    
139
# this var controls the verbosity in the debug and by default it's low (False)
140
# make it True and you will to get a very verbose debug.log
141
debug = False
142

    
143
# valid chars on the LCD, Note that " " (space) is stored as "\xFF"
144
VALID_CHARS = chirp_common.CHARSET_ALPHANUMERIC + \
145
    "`{|}!\"#$%&'()*+,-./:;<=>?@[]^_"
146

    
147
GMRS_FREQS1 = [462.5625, 462.5875, 462.6125, 462.6375, 462.6625,
148
               462.6875, 462.7125]
149
GMRS_FREQS2 = [467.5625, 467.5875, 467.6125, 467.6375, 467.6625,
150
               467.6875, 467.7125]
151
GMRS_FREQS3 = [462.5500, 462.5750, 462.6000, 462.6250, 462.6500,
152
               462.6750, 462.7000, 462.7250]
153
GMRS_FREQS = GMRS_FREQS1 + GMRS_FREQS2 + GMRS_FREQS3 * 2
154

    
155

    
156
# #### ID strings #####################################################
157

    
158
# BTECH UV2501 pre-production units
159
UV2501pp_fp = "M2C294"
160
# BTECH UV2501 pre-production units 2 + and 1st Gen radios
161
UV2501pp2_fp = "M29204"
162
# B-TECH UV-2501 second generation (2G) radios
163
UV2501G2_fp = "BTG214"
164
# B-TECH UV-2501 third generation (3G) radios
165
UV2501G3_fp = "BTG324"
166

    
167
# B-TECH UV-2501+220 pre-production units
168
UV2501_220pp_fp = "M3C281"
169
# extra block read for the 2501+220 pre-production units
170
# the same for all of this radios so far
171
UV2501_220pp_id = "      280528"
172
# B-TECH UV-2501+220
173
UV2501_220_fp = "M3G201"
174
# new variant, let's call it Generation 2
175
UV2501_220G2_fp = "BTG211"
176
# B-TECH UV-2501+220 third generation (3G)
177
UV2501_220G3_fp = "BTG311"
178

    
179
# B-TECH UV-5001 pre-production units + 1st Gen radios
180
UV5001pp_fp = "V19204"
181
# B-TECH UV-5001 alpha units
182
UV5001alpha_fp = "V28204"
183
# B-TECH UV-5001 second generation (2G) radios
184
UV5001G2_fp = "BTG214"
185
# B-TECH UV-5001 second generation (2G2)
186
UV5001G22_fp = "V2G204"
187
# B-TECH UV-5001 third generation (3G)
188
UV5001G3_fp = "BTG304"
189

    
190
# B-TECH UV-25X2
191
UV25X2_fp = "UC2012"
192

    
193
# B-TECH UV-25X4
194
UV25X4_fp = "UC4014"
195

    
196
# B-TECH UV-50X2
197
UV50X2_fp = "UC2M12"
198

    
199
# B-TECH GMRS-50X1
200
GMRS50X1_fp = "NC1802"
201
GMRS50X1_fp1 = "NC1932"
202

    
203
# special var to know when we found a BTECH Gen 3
204
BTECH3 = [UV2501G3_fp, UV2501_220G3_fp, UV5001G3_fp]
205

    
206

    
207
# WACCOM Mini-8900
208
MINI8900_fp = "M28854"
209

    
210

    
211
# QYT KT-UV980
212
KTUV980_fp = "H28854"
213

    
214
# QYT KT8900
215
KT8900_fp = "M29154"
216
# New generations KT8900
217
KT8900_fp1 = "M2C234"
218
KT8900_fp2 = "M2G1F4"
219
KT8900_fp3 = "M2G2F4"
220
KT8900_fp4 = "M2G304"
221
KT8900_fp5 = "M2G314"
222
KT8900_fp6 = "M2G424"
223
KT8900_fp7 = "M27184"
224
# this radio has an extra ID
225
KT8900_id = "303688"
226
# another extra ID in sep/2021
227
KT8900_id2 = "\x05\x58\x3d\xf0\x10"
228

    
229
# KT8900R
230
KT8900R_fp = "M3G1F4"
231
# Second Generation
232
KT8900R_fp1 = "M3G214"
233
# another model
234
KT8900R_fp2 = "M3C234"
235
# another model G4?
236
KT8900R_fp3 = "M39164"
237
# another model
238
KT8900R_fp4 = "M3G314"
239
# AC3MB: another id
240
KT8900R_fp5 = "M3B064"
241
# this radio has an extra ID
242
KT8900R_id = "280528"
243
# another extra ID in dec/2018
244
KT8900R_id2 = "\x05\x58\x3d\xf0\x10"
245

    
246
# KT7900D (quad band)
247
KT7900D_fp = "VC4004"
248
KT7900D_fp1 = "VC4284"
249
KT7900D_fp2 = "VC4264"
250
KT7900D_fp3 = "VC4114"
251
KT7900D_fp4 = "VC4104"
252
KT7900D_fp5 = "VC4254"
253
KT7900D_fp6 = "VC5264"
254
KT7900D_fp7 = "VC9204"
255

    
256
# QB25 (quad band) - a clone of KT7900D
257
QB25_fp = "QB-25"
258

    
259
# KT8900D (dual band)
260
KT8900D_fp = "VC2002"
261
KT8900D_fp1 = "VC8632"
262
KT8900D_fp2 = "VC3402"
263
KT8900D_fp3 = "VC7062"
264

    
265
# LUITON LT-588UV
266
LT588UV_fp = "V2G1F4"
267
# Added by rstrickoff gen 2 id
268
LT588UV_fp1 = "V2G214"
269

    
270
# QYT KT-8R (quad band ht)
271
KT8R_fp = "MCB264"
272
KT8R_fp1 = "MCB284"
273
KT8R_fp2 = "MC5264"
274

    
275
# QYT KT5800 (dual band)
276
KT5800_fp = "VCB222"
277

    
278
# QYT KT980Plus (dual band)
279
KT980PLUS_fp = "VC2002"
280
KT980PLUS_fp1 = "VC6042"
281

    
282
# Radioddity DB25-G (gmrs)
283
DB25G_fp = "VC6182"
284
DB25G_fp1 = "VC7062"
285

    
286

    
287
# ### MAGICS
288
# for the Waccom Mini-8900
289
MSTRING_MINI8900 = "\x55\xA5\xB5\x45\x55\x45\x4d\x02"
290
# for the B-TECH UV-2501+220 (including pre production ones)
291
MSTRING_220 = "\x55\x20\x15\x12\x12\x01\x4d\x02"
292
# for the QYT KT8900 & R
293
MSTRING_KT8900 = "\x55\x20\x15\x09\x16\x45\x4D\x02"
294
MSTRING_KT8900R = "\x55\x20\x15\x09\x25\x01\x4D\x02"
295
# magic string for all other models
296
MSTRING = "\x55\x20\x15\x09\x20\x45\x4d\x02"
297
# for the QYT KT7900D & KT8900D
298
MSTRING_KT8900D = "\x55\x20\x16\x08\x01\xFF\xDC\x02"
299
# for the BTECH UV-25X2 and UV-50X2
300
MSTRING_UV25X2 = "\x55\x20\x16\x12\x28\xFF\xDC\x02"
301
# for the BTECH UV-25X4
302
MSTRING_UV25X4 = "\x55\x20\x16\x11\x18\xFF\xDC\x02"
303
# for the BTECH GMRS-50X1
304
MSTRING_GMRS50X1 = "\x55\x20\x18\x10\x18\xFF\xDC\x02"
305
# for the QYT KT-8R
306
MSTRING_KT8R = "\x55\x20\x17\x07\x03\xFF\xDC\x02"
307

    
308

    
309
def _clean_buffer(radio):
310
    """Cleaning the read serial buffer, hard timeout to survive an infinite
311
    data stream"""
312

    
313
    # touching the serial timeout to optimize the flushing
314
    # restored at the end to the default value
315
    radio.pipe.timeout = 0.1
316
    dump = "1"
317
    datacount = 0
318

    
319
    try:
320
        while len(dump) > 0:
321
            dump = radio.pipe.read(100)
322
            datacount += len(dump)
323
            # hard limit to survive a infinite serial data stream
324
            # 5 times bigger than a normal rx block (69 bytes)
325
            if datacount > 345:
326
                seriale = "Please check your serial port selection."
327
                raise errors.RadioError(seriale)
328

    
329
        # restore the default serial timeout
330
        radio.pipe.timeout = STIMEOUT
331

    
332
    except Exception:
333
        raise errors.RadioError("Unknown error cleaning the serial buffer")
334

    
335

    
336
def _rawrecv(radio, amount):
337
    """Raw read from the radio device, less intensive way"""
338

    
339
    data = ""
340

    
341
    try:
342
        data = radio.pipe.read(amount)
343

    
344
        # DEBUG
345
        if debug is True:
346
            LOG.debug("<== (%d) bytes:\n\n%s" %
347
                      (len(data), util.hexprint(data)))
348

    
349
        # fail if no data is received
350
        if len(data) == 0:
351
            raise errors.RadioError("No data received from radio")
352

    
353
        # notice on the logs if short
354
        if len(data) < amount:
355
            LOG.warn("Short reading %d bytes from the %d requested." %
356
                     (len(data), amount))
357

    
358
    except:
359
        raise errors.RadioError("Error reading data from radio")
360

    
361
    return data
362

    
363

    
364
def _send(radio, data, upload=False):
365
    """Send data to the radio device"""
366

    
367
    try:
368
        for byte in data:
369
            radio.pipe.write(byte)
370
            # Some OS (mainly Linux ones) are too fast on the serial and
371
            # get the MCU inside the radio stuck in the early stages, this
372
            # hits some models more than others.
373
            #
374
            # To cope with that we introduce a delay on the writes.
375
            # Many option have been tested (delaying only after error occures,
376
            # after short reads, only for linux, ...)
377
            # Finally, a static delay was chosen as simplest of all solutions
378
            # (Michael Wagner, OE4AMW)
379
            # (for details, see issue 3993)
380
            #
381
            # skip 'sleep()' when uploading added by Jim Unroe, KC9HI
382
            if upload is False:
383
                sleep(0.002)
384

    
385
        # DEBUG
386
        if debug is True:
387
            LOG.debug("==> (%d) bytes:\n\n%s" %
388
                      (len(data), util.hexprint(data)))
389
    except:
390
        raise errors.RadioError("Error sending data to radio")
391

    
392

    
393
def _make_frame(cmd, addr, length, data=""):
394
    """Pack the info in the headder format"""
395
    frame = "\x06" + struct.pack(">BHB", ord(cmd), addr, length)
396
    # add the data if set
397
    if len(data) != 0:
398
        frame += data
399

    
400
    return frame
401

    
402

    
403
def _recv(radio, addr):
404
    """Get data from the radio all at once to lower syscalls load"""
405

    
406
    # Get the full 69 bytes at a time to reduce load
407
    # 1 byte ACK + 4 bytes header + 64 bytes of data (BLOCK_SIZE)
408

    
409
    # get the whole block
410
    block = _rawrecv(radio, BLOCK_SIZE + 5)
411

    
412
    # basic check
413
    if len(block) < (BLOCK_SIZE + 5):
414
        raise errors.RadioError("Short read of the block 0x%04x" % addr)
415

    
416
    # checking for the ack
417
    if block[0] != ACK_CMD:
418
        raise errors.RadioError("Bad ack from radio in block 0x%04x" % addr)
419

    
420
    # header validation
421
    c, a, l = struct.unpack(">BHB", block[1:5])
422
    if a != addr or l != BLOCK_SIZE or c != ord("X"):
423
        LOG.debug("Invalid header for block 0x%04x" % addr)
424
        LOG.debug("CMD: %s  ADDR: %04x  SIZE: %02x" % (c, a, l))
425
        raise errors.RadioError("Invalid header for block 0x%04x:" % addr)
426

    
427
    # return the data
428
    return block[5:]
429

    
430

    
431
def _start_clone_mode(radio, status):
432
    """Put the radio in clone mode and get the ident string, 3 tries"""
433

    
434
    # cleaning the serial buffer
435
    _clean_buffer(radio)
436

    
437
    # prep the data to show in the UI
438
    status.cur = 0
439
    status.msg = "Identifying the radio..."
440
    status.max = 3
441
    radio.status_fn(status)
442

    
443
    try:
444
        for a in range(0, status.max):
445
            # Update the UI
446
            status.cur = a + 1
447
            radio.status_fn(status)
448

    
449
            # send the magic word
450
            _send(radio, radio._magic)
451

    
452
            # Now you get a x06 of ACK if all goes well
453
            ack = radio.pipe.read(1)
454

    
455
            if ack == "\x06":
456
                # DEBUG
457
                LOG.info("Magic ACK received")
458
                status.cur = status.max
459
                radio.status_fn(status)
460

    
461
                return True
462

    
463
        return False
464

    
465
    except errors.RadioError:
466
        raise
467
    except Exception, e:
468
        raise errors.RadioError("Error sending Magic to radio:\n%s" % e)
469

    
470

    
471
def _do_ident(radio, status, upload=False):
472
    """Put the radio in PROGRAM mode & identify it"""
473
    #  set the serial discipline
474
    radio.pipe.baudrate = 9600
475
    radio.pipe.parity = "N"
476

    
477
    # open the radio into program mode
478
    if _start_clone_mode(radio, status) is False:
479
        msg = "Radio did not enter clone mode"
480
        # warning about old versions of QYT KT8900
481
        if radio.MODEL == "KT8900":
482
            msg += ". You may want to try it as a WACCOM MINI-8900, there is a"
483
            msg += " known variant of this radios that is a clone of it."
484
        raise errors.RadioError(msg)
485

    
486
    # Ok, get the ident string
487
    ident = _rawrecv(radio, 49)
488

    
489
    # basic check for the ident
490
    if len(ident) != 49:
491
        raise errors.RadioError("Radio send a short ident block.")
492

    
493
    # check if ident is OK
494
    itis = False
495
    for fp in radio._fileid:
496
        if fp in ident:
497
            # got it!
498
            itis = True
499
            # checking if we are dealing with a Gen 3 BTECH
500
            if radio.VENDOR == "BTECH" and fp in BTECH3:
501
                radio.btech3 = True
502

    
503
            break
504

    
505
    if itis is False:
506
        LOG.debug("Incorrect model ID, got this:\n\n" + util.hexprint(ident))
507
        raise errors.RadioError("Radio identification failed.")
508

    
509
    # some radios needs a extra read and check for a code on it, this ones
510
    # has the check value in the _id2 var, others simply False
511
    if radio._id2 is not False:
512
        # lower the timeout here as this radios are reseting due to timeout
513
        radio.pipe.timeout = 0.05
514

    
515
        # query & receive the extra ID
516
        _send(radio, _make_frame("S", 0x3DF0, 16))
517
        id2 = _rawrecv(radio, 21)
518

    
519
        # WARNING !!!!!!
520
        # different radios send a response with a different amount of data
521
        # it seems that it's padded with \xff, \x20 and some times with \x00
522
        # we just care about the first 16, our magic string is in there
523
        if len(id2) < 16:
524
            raise errors.RadioError("The extra ID is short, aborting.")
525

    
526
        # ok, the correct string must be in the received data
527
        # the radio._id2 var will be always a list
528
        flag2 = False
529
        for _id2 in radio._id2:
530
            if _id2 in id2:
531
                flag2 = True
532

    
533
        if not flag2:
534
            LOG.debug("Full *BAD* extra ID on the %s is: \n%s" %
535
                      (radio.MODEL, util.hexprint(id2)))
536
            raise errors.RadioError("The extra ID is wrong, aborting.")
537

    
538
        # this radios need a extra request/answer here on the upload
539
        # the amount of data received depends of the radio type
540
        #
541
        # also the first block of TX must no have the ACK at the beginning
542
        # see _upload for this.
543
        if upload is True:
544
            # send an ACK
545
            _send(radio, ACK_CMD)
546

    
547
            # the amount of data depend on the radio, so far we have two radios
548
            # reading two bytes with an ACK at the end and just ONE with just
549
            # one byte (QYT KT8900)
550
            # the JT-6188 appears a clone of the last, but reads TWO bytes.
551
            #
552
            # we will read two bytes with a custom timeout to not penalize the
553
            # users for this.
554
            #
555
            # we just check for a response and last byte being a ACK, that is
556
            # the common stone for all radios (3 so far)
557
            ack = _rawrecv(radio, 2)
558

    
559
            # checking
560
            if len(ack) == 0 or ack[-1:] != ACK_CMD:
561
                raise errors.RadioError("Radio didn't ACK the upload")
562

    
563
            # restore the default serial timeout
564
            radio.pipe.timeout = STIMEOUT
565

    
566
    # DEBUG
567
    LOG.info("Positive ident, this is a %s %s" % (radio.VENDOR, radio.MODEL))
568

    
569
    return True
570

    
571

    
572
def _download(radio):
573
    """Get the memory map"""
574

    
575
    # UI progress
576
    status = chirp_common.Status()
577

    
578
    # put radio in program mode and identify it
579
    _do_ident(radio, status)
580

    
581
    # the models that doesn't have the extra ID have to make a dummy read here
582
    if radio._id2 is False:
583
        _send(radio, _make_frame("S", 0, BLOCK_SIZE))
584
        discard = _rawrecv(radio, BLOCK_SIZE + 5)
585

    
586
        if debug is True:
587
            LOG.info("Dummy first block read done, got this:\n\n %s",
588
                     util.hexprint(discard))
589

    
590
    # reset the progress bar in the UI
591
    status.max = MEM_SIZE / BLOCK_SIZE
592
    status.msg = "Cloning from radio..."
593
    status.cur = 0
594
    radio.status_fn(status)
595

    
596
    # cleaning the serial buffer
597
    _clean_buffer(radio)
598

    
599
    data = ""
600
    for addr in range(0, MEM_SIZE, BLOCK_SIZE):
601
        # sending the read request
602
        _send(radio, _make_frame("S", addr, BLOCK_SIZE))
603

    
604
        # read
605
        d = _recv(radio, addr)
606

    
607
        # aggregate the data
608
        data += d
609

    
610
        # UI Update
611
        status.cur = addr / BLOCK_SIZE
612
        status.msg = "Cloning from radio..."
613
        radio.status_fn(status)
614

    
615
    return data
616

    
617

    
618
def _upload(radio):
619
    """Upload procedure"""
620

    
621
    # The UPLOAD mem is restricted to lower than 0x3100,
622
    # so we will overide that here localy
623
    MEM_SIZE = radio.UPLOAD_MEM_SIZE
624

    
625
    # UI progress
626
    status = chirp_common.Status()
627

    
628
    # put radio in program mode and identify it
629
    _do_ident(radio, status, True)
630

    
631
    # get the data to upload to radio
632
    data = radio.get_mmap()
633

    
634
    # Reset the UI progress
635
    status.max = MEM_SIZE / TX_BLOCK_SIZE
636
    status.cur = 0
637
    status.msg = "Cloning to radio..."
638
    radio.status_fn(status)
639

    
640
    # the radios that doesn't have the extra ID 'may' do a dummy write, I found
641
    # that leveraging the bad ACK and NOT doing the dummy write is ok, as the
642
    # dummy write is accepted (it actually writes to the mem!) by the radio.
643

    
644
    # cleaning the serial buffer
645
    _clean_buffer(radio)
646

    
647
    # the fun start here
648
    for addr in range(0, MEM_SIZE, TX_BLOCK_SIZE):
649
        # getting the block of data to send
650
        d = data[addr:addr + TX_BLOCK_SIZE]
651

    
652
        # build the frame to send
653
        frame = _make_frame("X", addr, TX_BLOCK_SIZE, d)
654

    
655
        # first block must not send the ACK at the beginning for the
656
        # ones that has the extra id, since this have to do a extra step
657
        if addr == 0 and radio._id2 is not False:
658
            frame = frame[1:]
659

    
660
        # send the frame
661
        _send(radio, frame, True)
662

    
663
        # receiving the response
664
        ack = _rawrecv(radio, 1)
665

    
666
        # basic check
667
        if len(ack) != 1:
668
            raise errors.RadioError("No ACK when writing block 0x%04x" % addr)
669

    
670
        if ack not in "\x06\x05":
671
            raise errors.RadioError("Bad ACK writing block 0x%04x:" % addr)
672

    
673
        # UI Update
674
        status.cur = addr / TX_BLOCK_SIZE
675
        status.msg = "Cloning to radio..."
676
        radio.status_fn(status)
677

    
678

    
679
def model_match(cls, data):
680
    """Match the opened/downloaded image to the correct version"""
681
    rid = data[0x3f70:0x3f76]
682

    
683
    if rid in cls._fileid:
684
        return True
685

    
686
    return False
687

    
688

    
689
def _decode_ranges(low, high):
690
    """Unpack the data in the ranges zones in the memmap and return
691
    a tuple with the integer corresponding to the Mhz it means"""
692
    ilow = int(low[0]) * 100 + int(low[1]) * 10 + int(low[2])
693
    ihigh = int(high[0]) * 100 + int(high[1]) * 10 + int(high[2])
694
    ilow *= 1000000
695
    ihigh *= 1000000
696

    
697
    return (ilow, ihigh)
698

    
699

    
700
def _split(rf, f1, f2):
701
    """Returns False if the two freqs are in the same band (no split)
702
    or True otherwise"""
703

    
704
    # determine if the two freqs are in the same band
705
    for low, high in rf.valid_bands:
706
        if f1 >= low and f1 <= high and \
707
                f2 >= low and f2 <= high:
708
            # if the two freqs are on the same Band this is not a split
709
            return False
710

    
711
    # if you get here is because the freq pairs are split
712
    return True
713

    
714

    
715
class BTechMobileCommon(chirp_common.CloneModeRadio,
716
                        chirp_common.ExperimentalRadio):
717
    """BTECH's UV-5001 and alike radios"""
718
    VENDOR = "BTECH"
719
    MODEL = ""
720
    IDENT = ""
721
    BANDS = 2
722
    COLOR_LCD = False
723
    COLOR_LCD2 = False
724
    COLOR_LCD3 = False
725
    NAME_LENGTH = 6
726
    UPLOAD_MEM_SIZE = 0X3E00  ##0X3100
727
    _power_levels = [chirp_common.PowerLevel("High", watts=25),
728
                     chirp_common.PowerLevel("Low", watts=10)]
729
    _vhf_range = (130000000, 180000000)
730
    _220_range = (200000000, 271000000)
731
    _uhf_range = (400000000, 521000000)
732
    _350_range = (350000000, 391000000)
733
    _upper = 199
734
    _magic = MSTRING
735
    _fileid = None
736
    _id2 = False
737
    btech3 = False
738
    _gmrs = False
739

    
740
    @classmethod
741
    def get_prompts(cls):
742
        rp = chirp_common.RadioPrompts()
743
        rp.experimental = \
744
            ('This driver is experimental.\n'
745
             '\n'
746
             'Please keep a copy of your memories with the original software '
747
             'if you treasure them, this driver is new and may contain'
748
             ' bugs.\n'
749
             '\n'
750
             )
751
        rp.pre_download = _(dedent("""\
752
            Follow these instructions to download your info:
753

    
754
            1 - Turn off your radio
755
            2 - Connect your interface cable
756
            3 - Turn on your radio
757
            4 - Do the download of your radio data
758

    
759
            """))
760
        rp.pre_upload = _(dedent("""\
761
            Follow these instructions to upload your info:
762

    
763
            1 - Turn off your radio
764
            2 - Connect your interface cable
765
            3 - Turn on your radio
766
            4 - Do the upload of your radio data
767

    
768
            """))
769
        return rp
770

    
771
    def get_features(self):
772
        """Get the radio's features"""
773

    
774
        # we will use the following var as global
775
        global POWER_LEVELS
776

    
777
        rf = chirp_common.RadioFeatures()
778
        rf.has_settings = False
779
        rf.has_bank = False
780
        rf.has_tuning_step = False
781
        rf.can_odd_split = True
782
        rf.has_name = True
783
        rf.has_offset = True
784
        rf.has_mode = True
785
        rf.has_dtcs = True
786
        rf.has_rx_dtcs = True
787
        rf.has_dtcs_polarity = True
788
        rf.has_ctone = True
789
        rf.has_cross = True
790
        rf.valid_modes = MODES
791
        rf.valid_characters = VALID_CHARS
792
        rf.valid_name_length = self.NAME_LENGTH
793
        rf.valid_duplexes = ["", "-", "+", "split", "off"]
794
        rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS', 'Cross']
795
        rf.valid_cross_modes = [
796
            "Tone->Tone",
797
            "DTCS->",
798
            "->DTCS",
799
            "Tone->DTCS",
800
            "DTCS->Tone",
801
            "->Tone",
802
            "DTCS->DTCS"]
803
        rf.valid_skips = SKIP_VALUES
804
        rf.valid_dtcs_codes = DTCS
805
        rf.valid_tuning_steps = STEPS
806
        rf.memory_bounds = (0, self._upper)
807

    
808
        # power levels
809
        POWER_LEVELS = self._power_levels
810
        rf.valid_power_levels = POWER_LEVELS
811

    
812
        # normal dual bands
813
        rf.valid_bands = [self._vhf_range, self._uhf_range]
814

    
815
        # 220 band
816
        if self.BANDS == 3 or self.BANDS == 4:
817
            rf.valid_bands.append(self._220_range)
818

    
819
        # 350 band
820
        if self.BANDS == 4:
821
            rf.valid_bands.append(self._350_range)
822

    
823
        return rf
824

    
825
    def validate_memory(self, mem):
826
        msgs = chirp_common.CloneModeRadio.validate_memory(self, mem)
827

    
828
        _msg_duplex1 = 'Memory location only supports "Low"'
829
        _msg_duplex2 = 'Memory location only supports "off"'
830
        _msg_duplex3 = 'Memory location only supports "(None)", "+" or "off"'
831

    
832
        if self._gmrs:
833
            if mem.number < 1 or mem.number > 30:
834
                if float(mem.freq) / 1000000 in GMRS_FREQS1:
835
                    if mem.duplex not in ['', 'off']:
836
                        # warn user wrong Duplex
837
                        msgs.append(chirp_common.ValidationError(_msg_duplex2))
838
                    if mem.power != self._power_levels[2]:
839
                        # warn user wrong Duplex
840
                        msgs.append(chirp_common.ValidationError(_msg_duplex1))
841

    
842
                if float(mem.freq) / 1000000 in GMRS_FREQS2:
843
                    if mem.duplex not in ['off', ]:
844
                        # warn user wrong Duplex
845
                        msgs.append(chirp_common.ValidationError(_msg_duplex2))
846

    
847
                if float(mem.freq) / 1000000 in GMRS_FREQS3:
848
                    if mem.duplex not in ['', '+', 'off']:
849
                        # warn user wrong Duplex
850
                        msgs.append(chirp_common.ValidationError(_msg_duplex3))
851

    
852
        return msgs
853

    
854
    def sync_in(self):
855
        """Download from radio"""
856
        data = _download(self)
857
        self._mmap = memmap.MemoryMap(data)
858
        self.process_mmap()
859

    
860
    def sync_out(self):
861
        """Upload to radio"""
862
        try:
863
            _upload(self)
864
        except errors.RadioError:
865
            raise
866
        except Exception, e:
867
            raise errors.RadioError("Error: %s" % e)
868

    
869
    def get_raw_memory(self, number):
870
        return repr(self._memobj.memory[number])
871

    
872
    def _decode_tone(self, val):
873
        """Parse the tone data to decode from mem, it returns:
874
        Mode (''|DTCS|Tone), Value (None|###), Polarity (None,N,R)"""
875
        pol = None
876

    
877
        if val in [0, 65535]:
878
            return '', None, None
879
        elif val > 0x0258:
880
            a = val / 10.0
881
            return 'Tone', a, pol
882
        else:
883
            if val > 0x69:
884
                index = val - 0x6A
885
                pol = "R"
886
            else:
887
                index = val - 1
888
                pol = "N"
889

    
890
            tone = DTCS[index]
891
            return 'DTCS', tone, pol
892

    
893
    def _encode_tone(self, memval, mode, val, pol):
894
        """Parse the tone data to encode from UI to mem"""
895
        if mode == '' or mode is None:
896
            memval.set_raw("\x00\x00")
897
        elif mode == 'Tone':
898
            memval.set_value(val * 10)
899
        elif mode == 'DTCS':
900
            # detect the index in the DTCS list
901
            try:
902
                index = DTCS.index(val)
903
                if pol == "N":
904
                    index += 1
905
                else:
906
                    index += 0x6A
907
                memval.set_value(index)
908
            except:
909
                msg = "Digital Tone '%d' is not supported" % value
910
                LOG.error(msg)
911
                raise errors.RadioError(msg)
912
        else:
913
            msg = "Internal error: invalid mode '%s'" % mode
914
            LOG.error(msg)
915
            raise errors.InvalidDataError(msg)
916

    
917
    def get_memory(self, number):
918
        """Get the mem representation from the radio image"""
919
        _mem = self._memobj.memory[number]
920
        _names = self._memobj.names[number]
921

    
922
        # Create a high-level memory object to return to the UI
923
        mem = chirp_common.Memory()
924

    
925
        # Memory number
926
        mem.number = number
927

    
928
        if _mem.get_raw()[0] == "\xFF":
929
            mem.empty = True
930
            return mem
931

    
932
        # Freq and offset
933
        mem.freq = int(_mem.rxfreq) * 10
934
        # tx freq can be blank
935
        if _mem.get_raw()[4] == "\xFF":
936
            # TX freq not set
937
            mem.offset = 0
938
            mem.duplex = "off"
939
        else:
940
            # TX freq set
941
            offset = (int(_mem.txfreq) * 10) - mem.freq
942
            if offset != 0:
943
                if _split(self.get_features(), mem.freq, int(
944
                          _mem.txfreq) * 10):
945
                    mem.duplex = "split"
946
                    mem.offset = int(_mem.txfreq) * 10
947
                elif offset < 0:
948
                    mem.offset = abs(offset)
949
                    mem.duplex = "-"
950
                elif offset > 0:
951
                    mem.offset = offset
952
                    mem.duplex = "+"
953
            else:
954
                mem.offset = 0
955

    
956
        # name TAG of the channel
957
        mem.name = str(_names.name).rstrip("\xFF").replace("\xFF", " ")
958

    
959
        # power
960
        mem.power = POWER_LEVELS[int(_mem.power)]
961

    
962
        # wide/narrow
963
        mem.mode = MODES[int(_mem.wide)]
964

    
965
        # skip
966
        mem.skip = SKIP_VALUES[_mem.add]
967

    
968
        # tone data
969
        rxtone = txtone = None
970
        txtone = self._decode_tone(_mem.txtone)
971
        rxtone = self._decode_tone(_mem.rxtone)
972
        chirp_common.split_tone_decode(mem, txtone, rxtone)
973

    
974
        # Extra
975
        mem.extra = RadioSettingGroup("extra", "Extra")
976

    
977
        if not self.COLOR_LCD or \
978
                (self.COLOR_LCD and not self.VENDOR == "BTECH"):
979
            scramble = RadioSetting("scramble", "Scramble",
980
                                    RadioSettingValueBoolean(bool(
981
                                        _mem.scramble)))
982
            mem.extra.append(scramble)
983

    
984
        bcl = RadioSetting("bcl", "Busy channel lockout",
985
                           RadioSettingValueBoolean(bool(_mem.bcl)))
986
        mem.extra.append(bcl)
987

    
988
        pttid = RadioSetting("pttid", "PTT ID",
989
                             RadioSettingValueList(PTTID_LIST,
990
                                                   PTTID_LIST[_mem.pttid]))
991
        mem.extra.append(pttid)
992

    
993
        # validating scode
994
        scode = _mem.scode if _mem.scode != 15 else 0
995
        pttidcode = RadioSetting("scode", "PTT ID signal code",
996
                                 RadioSettingValueList(
997
                                     PTTIDCODE_LIST,
998
                                     PTTIDCODE_LIST[scode]))
999
        mem.extra.append(pttidcode)
1000

    
1001
        optsig = RadioSetting("optsig", "Optional signaling",
1002
                              RadioSettingValueList(
1003
                                  OPTSIG_LIST,
1004
                                  OPTSIG_LIST[_mem.optsig]))
1005
        mem.extra.append(optsig)
1006

    
1007
        spmute = RadioSetting("spmute", "Speaker mute",
1008
                              RadioSettingValueList(
1009
                                  SPMUTE_LIST,
1010
                                  SPMUTE_LIST[_mem.spmute]))
1011
        mem.extra.append(spmute)
1012

    
1013
        return mem
1014

    
1015
    def set_memory(self, mem):
1016
        """Set the memory data in the eeprom img from the UI"""
1017
        # get the eprom representation of this channel
1018
        _mem = self._memobj.memory[mem.number]
1019
        _names = self._memobj.names[mem.number]
1020

    
1021
        mem_was_empty = False
1022
        # same method as used in get_memory for determining if mem is empty
1023
        # doing this BEFORE overwriting it with new values ...
1024
        if _mem.get_raw()[0] == "\xFF":
1025
            LOG.debug("This mem was empty before")
1026
            mem_was_empty = True
1027

    
1028
        # if empty memmory
1029
        if mem.empty:
1030
            # the channel itself
1031
            _mem.set_raw("\xFF" * 16)
1032
            # the name tag
1033
            _names.set_raw("\xFF" * 16)
1034
            return
1035

    
1036
        if mem_was_empty:
1037
            # Zero the whole memory if we're making it unempty for
1038
            # the first time
1039
            LOG.debug('Zeroing new memory')
1040
            _mem.set_raw('\x00' * 16)
1041

    
1042
        if self._gmrs:
1043
            if mem.number >= 1 and mem.number <= 30:
1044
                GMRS_FREQ = int(GMRS_FREQS[mem.number - 1] * 1000000)
1045
                mem.freq = GMRS_FREQ
1046
                if mem.number <= 22:
1047
                    mem.duplex = ''
1048
                    mem.offset = 0
1049
                    if mem.number <= 7:
1050
                        mem.power = self._power_levels[2]
1051
                    if mem.number >= 8 and mem.number <= 14:
1052
                        mem.duplex = 'off'
1053
                        mem.mode = "NFM"
1054
                        mem.power = self._power_levels[2]
1055
                if mem.number > 22:
1056
                    mem.duplex = '+'
1057
                    mem.offset = 5000000
1058
            elif float(mem.freq) / 1000000 in GMRS_FREQS:
1059
                if float(mem.freq) / 1000000 in GMRS_FREQS1:
1060
                    mem.duplex = ''
1061
                    mem.offset = 0
1062
                    mem.power = self._power_levels[2]
1063
                if float(mem.freq) / 1000000 in GMRS_FREQS2:
1064
                    mem.duplex = 'off'
1065
                    mem.offset = 0
1066
                    mem.mode = "NFM"
1067
                    mem.power = self._power_levels[2]
1068
                if float(mem.freq) / 1000000 in GMRS_FREQS3:
1069
                    if mem.duplex == '+':
1070
                        mem.offset = 5000000
1071
                    else:
1072
                        mem.offset = 0
1073
            else:
1074
                mem.duplex = 'off'
1075
                mem.offset = 0
1076

    
1077
        # frequency
1078
        _mem.rxfreq = mem.freq / 10
1079

    
1080
        # duplex
1081
        if mem.duplex == "+":
1082
            _mem.txfreq = (mem.freq + mem.offset) / 10
1083
        elif mem.duplex == "-":
1084
            _mem.txfreq = (mem.freq - mem.offset) / 10
1085
        elif mem.duplex == "off":
1086
            for i in _mem.txfreq:
1087
                i.set_raw("\xFF")
1088
        elif mem.duplex == "split":
1089
            _mem.txfreq = mem.offset / 10
1090
        else:
1091
            _mem.txfreq = mem.freq / 10
1092

    
1093
        # tone data
1094
        ((txmode, txtone, txpol), (rxmode, rxtone, rxpol)) = \
1095
            chirp_common.split_tone_encode(mem)
1096
        self._encode_tone(_mem.txtone, txmode, txtone, txpol)
1097
        self._encode_tone(_mem.rxtone, rxmode, rxtone, rxpol)
1098

    
1099
        # name TAG of the channel
1100
        if len(mem.name) < self.NAME_LENGTH:
1101
            # we must pad to self.NAME_LENGTH chars, " " = "\xFF"
1102
            mem.name = str(mem.name).ljust(self.NAME_LENGTH, " ")
1103
        _names.name = str(mem.name).replace(" ", "\xFF")
1104

    
1105
        # power, # default power level is high
1106
        _mem.power = 0 if mem.power is None else POWER_LEVELS.index(mem.power)
1107

    
1108
        # wide/narrow
1109
        _mem.wide = MODES.index(mem.mode)
1110

    
1111
        # scan add property
1112
        _mem.add = SKIP_VALUES.index(mem.skip)
1113

    
1114
        # reseting unknowns, this have to be set by hand
1115
        _mem.unknown0 = 0
1116
        _mem.unknown1 = 0
1117
        _mem.unknown2 = 0
1118
        _mem.unknown3 = 0
1119
        _mem.unknown4 = 0
1120
        _mem.unknown5 = 0
1121
        _mem.unknown6 = 0
1122

    
1123
        def _zero_settings():
1124
            _mem.spmute = 0
1125
            _mem.optsig = 0
1126
            _mem.scramble = 0
1127
            _mem.bcl = 0
1128
            _mem.pttid = 0
1129
            _mem.scode = 0
1130

    
1131
        if self.COLOR_LCD and _mem.scramble:
1132
            LOG.info('Resetting scramble bit for BTECH COLOR_LCD variant')
1133
            _mem.scramble = 0
1134

    
1135
        # extra settings
1136
        if len(mem.extra) > 0:
1137
            # there are setting, parse
1138
            LOG.debug("Extra-Setting supplied. Setting them.")
1139
            # Zero them all first so any not provided by model don't
1140
            # stay set
1141
            _zero_settings()
1142
            for setting in mem.extra:
1143
                setattr(_mem, setting.get_name(), setting.value)
1144
        else:
1145
            if mem.empty:
1146
                LOG.debug("New mem is empty.")
1147
            else:
1148
                LOG.debug("New mem is NOT empty")
1149
                # set extra-settings to default ONLY when apreviously empty or
1150
                # deleted memory was edited to prevent errors such as #4121
1151
                if mem_was_empty:
1152
                    LOG.debug("old mem was empty. Setting default for extras.")
1153
                    _zero_settings()
1154

    
1155
        return mem
1156

    
1157
    def get_settings(self):
1158
        """Translate the bit in the mem_struct into settings in the UI"""
1159
        _mem = self._memobj
1160
        basic = RadioSettingGroup("basic", "Basic Settings")
1161
        advanced = RadioSettingGroup("advanced", "Advanced Settings")
1162
        other = RadioSettingGroup("other", "Other Settings")
1163
        work = RadioSettingGroup("work", "Work Mode Settings")
1164
        top = RadioSettings(basic, advanced, other, work)
1165

    
1166
        # Basic
1167
        if self.COLOR_LCD:
1168
            tmr = RadioSetting("settings.tmr", "Transceiver multi-receive",
1169
                               RadioSettingValueList(
1170
                                   self.LIST_TMR,
1171
                                   self.LIST_TMR[_mem.settings.tmr]))
1172
            basic.append(tmr)
1173
        else:
1174
            tdr = RadioSetting("settings.tdr", "Transceiver dual receive",
1175
                               RadioSettingValueBoolean(_mem.settings.tdr))
1176
            basic.append(tdr)
1177

    
1178
        sql = RadioSetting("settings.sql", "Squelch level",
1179
                           RadioSettingValueInteger(0, 9, _mem.settings.sql))
1180
        basic.append(sql)
1181

    
1182
        if self.MODEL == "GMRS-50X1":
1183
            autolk = RadioSetting("settings.autolk", "Auto keylock",
1184
                                  RadioSettingValueBoolean(
1185
                                      _mem.settings.autolk))
1186
            basic.append(autolk)
1187

    
1188
        if self.MODEL == "DB25-G":
1189
            rs = RadioSettingValueInteger(0, 127, _mem.settings.mgain2)
1190
            mgain2 = RadioSetting("settings.mgain2", "Mic gain", rs)
1191
            basic.append(mgain2)
1192

    
1193
        tot = RadioSetting("settings.tot", "Time out timer",
1194
                           RadioSettingValueList(
1195
                               LIST_TOT,
1196
                               LIST_TOT[_mem.settings.tot]))
1197
        basic.append(tot)
1198

    
1199
        if self.MODEL == "KT-8R":
1200
                save = RadioSetting("settings.save", "Battery Save",
1201
                                    RadioSettingValueBoolean(
1202
                                        _mem.settings.save))
1203
                basic.append(save)
1204

    
1205
        if not self.MODEL == "KT-8R":
1206
            if self.VENDOR == "BTECH" or self.COLOR_LCD:
1207
                apo = RadioSetting("settings.apo", "Auto power off timer",
1208
                                   RadioSettingValueList(
1209
                                       LIST_APO,
1210
                                       LIST_APO[_mem.settings.apo]))
1211
                basic.append(apo)
1212
            else:
1213
                toa = RadioSetting("settings.apo", "Time out alert timer",
1214
                                   RadioSettingValueList(
1215
                                       LIST_OFF1TO10,
1216
                                       LIST_OFF1TO10[_mem.settings.apo]))
1217
                basic.append(toa)
1218

    
1219
        abr = RadioSetting("settings.abr", "Backlight timer",
1220
                           RadioSettingValueList(
1221
                               LIST_OFF1TO50,
1222
                               LIST_OFF1TO50[_mem.settings.abr]))
1223
        basic.append(abr)
1224

    
1225
        beep = RadioSetting("settings.beep", "Key beep",
1226
                            RadioSettingValueBoolean(_mem.settings.beep))
1227
        basic.append(beep)
1228

    
1229
        if self.MODEL == "KT-8R":
1230
                dsub = RadioSetting("settings.dsub", "CTCSS/DCS code display",
1231
                                    RadioSettingValueBoolean(
1232
                                        _mem.settings.dsub))
1233
                basic.append(dsub)
1234

    
1235
        if self.MODEL == "KT-8R":
1236
                dtmfst = RadioSetting("settings.dtmfst", "DTMF side tone",
1237
                                      RadioSettingValueBoolean(
1238
                                          _mem.settings.dtmfst))
1239
                basic.append(dtmfst)
1240
        else:
1241
            dtmfst = RadioSetting("settings.dtmfst", "DTMF side tone",
1242
                                  RadioSettingValueList(
1243
                                      LIST_DTMFST,
1244
                                      LIST_DTMFST[_mem.settings.dtmfst]))
1245
            basic.append(dtmfst)
1246

    
1247
        if not self.COLOR_LCD:
1248
            prisc = RadioSetting("settings.prisc", "Priority scan",
1249
                                 RadioSettingValueBoolean(
1250
                                     _mem.settings.prisc))
1251
            basic.append(prisc)
1252

    
1253
            prich = RadioSetting("settings.prich", "Priority channel",
1254
                                 RadioSettingValueInteger(0, self._upper,
1255
                                                          _mem.settings.prich))
1256
            basic.append(prich)
1257

    
1258
        screv = RadioSetting("settings.screv", "Scan resume method",
1259
                             RadioSettingValueList(
1260
                                 LIST_SCREV,
1261
                                 LIST_SCREV[_mem.settings.screv]))
1262
        basic.append(screv)
1263

    
1264
        pttlt = RadioSetting("settings.pttlt", "PTT transmit delay",
1265
                             RadioSettingValueInteger(0, 30,
1266
                                                      _mem.settings.pttlt))
1267
        basic.append(pttlt)
1268

    
1269
        if self.VENDOR == "BTECH" and self.COLOR_LCD:
1270
            emctp = RadioSetting("settings.emctp", "Alarm mode",
1271
                                 RadioSettingValueList(
1272
                                     LIST_EMCTPX,
1273
                                     LIST_EMCTPX[_mem.settings.emctp]))
1274
            basic.append(emctp)
1275
        else:
1276
            emctp = RadioSetting("settings.emctp", "Alarm mode",
1277
                                 RadioSettingValueList(
1278
                                     LIST_EMCTP,
1279
                                     LIST_EMCTP[_mem.settings.emctp]))
1280
            basic.append(emctp)
1281

    
1282
        emcch = RadioSetting("settings.emcch", "Alarm channel",
1283
                             RadioSettingValueInteger(0, self._upper,
1284
                                                      _mem.settings.emcch))
1285
        basic.append(emcch)
1286

    
1287
        if self.COLOR_LCD:
1288
            if _mem.settings.sigbp > 0x01:
1289
                val = 0x00
1290
            else:
1291
                val = _mem.settings.sigbp
1292
            sigbp = RadioSetting("settings.sigbp", "Signal beep",
1293
                                 RadioSettingValueBoolean(val))
1294
            basic.append(sigbp)
1295
        else:
1296
            ringt = RadioSetting("settings.ringt", "Ring time",
1297
                                 RadioSettingValueList(
1298
                                     LIST_OFF1TO9,
1299
                                     LIST_OFF1TO9[_mem.settings.ringt]))
1300
            basic.append(ringt)
1301

    
1302
        camdf = RadioSetting("settings.camdf", "Display mode A",
1303
                             RadioSettingValueList(
1304
                                 LIST_MDF,
1305
                                 LIST_MDF[_mem.settings.camdf]))
1306
        basic.append(camdf)
1307

    
1308
        cbmdf = RadioSetting("settings.cbmdf", "Display mode B",
1309
                             RadioSettingValueList(
1310
                                 LIST_MDF,
1311
                                 LIST_MDF[_mem.settings.cbmdf]))
1312
        basic.append(cbmdf)
1313

    
1314
        if self.COLOR_LCD:
1315
            ccmdf = RadioSetting("settings.ccmdf", "Display mode C",
1316
                                 RadioSettingValueList(
1317
                                     LIST_MDF,
1318
                                     LIST_MDF[_mem.settings.ccmdf]))
1319
            basic.append(ccmdf)
1320

    
1321
            cdmdf = RadioSetting("settings.cdmdf", "Display mode D",
1322
                                 RadioSettingValueList(
1323
                                     LIST_MDF,
1324
                                     LIST_MDF[_mem.settings.cdmdf]))
1325
            basic.append(cdmdf)
1326

    
1327
            langua = RadioSetting("settings.langua", "Language",
1328
                                  RadioSettingValueList(
1329
                                      LIST_LANGUA,
1330
                                      LIST_LANGUA[_mem.settings.langua]))
1331
            basic.append(langua)
1332

    
1333
        if self.MODEL == "KT-8R":
1334
            voice = RadioSetting("settings.voice", "Voice prompt",
1335
                                 RadioSettingValueList(
1336
                                     LIST_VOICE,
1337
                                     LIST_VOICE[_mem.settings.voice]))
1338
            basic.append(voice)
1339

    
1340
            vox = RadioSetting("settings.vox", "VOX",
1341
                               RadioSettingValueList(
1342
                                   LIST_VOX,
1343
                                   LIST_VOX[_mem.settings.vox]))
1344
            basic.append(vox)
1345

    
1346
            voxt = RadioSetting("settings.voxt", "VOX delay time",
1347
                                RadioSettingValueList(
1348
                                    LIST_VOXT,
1349
                                    LIST_VOXT[_mem.settings.voxt]))
1350
            basic.append(voxt)
1351

    
1352
        if self.VENDOR == "BTECH":
1353
            if self.COLOR_LCD:
1354
                sync = RadioSetting("settings.sync", "Channel display sync",
1355
                                    RadioSettingValueList(
1356
                                        LIST_SYNC,
1357
                                        LIST_SYNC[_mem.settings.sync]))
1358
                basic.append(sync)
1359
            else:
1360
                sync = RadioSetting("settings.sync", "A/B channel sync",
1361
                                    RadioSettingValueBoolean(
1362
                                        _mem.settings.sync))
1363
                basic.append(sync)
1364
        else:
1365
            autolk = RadioSetting("settings.sync", "Auto keylock",
1366
                                  RadioSettingValueBoolean(
1367
                                      _mem.settings.sync))
1368
            basic.append(autolk)
1369

    
1370
        if not self.COLOR_LCD:
1371
            ponmsg = RadioSetting("settings.ponmsg", "Power-on message",
1372
                                  RadioSettingValueList(
1373
                                      LIST_PONMSG,
1374
                                      LIST_PONMSG[_mem.settings.ponmsg]))
1375
            basic.append(ponmsg)
1376

    
1377
        if self.COLOR_LCD and not (self.COLOR_LCD2 or self.COLOR_LCD3):
1378
            mainfc = RadioSetting("settings.mainfc",
1379
                                  "Main LCD foreground color",
1380
                                  RadioSettingValueList(
1381
                                      LIST_COLOR9,
1382
                                      LIST_COLOR9[_mem.settings.mainfc]))
1383
            basic.append(mainfc)
1384

    
1385
            mainbc = RadioSetting("settings.mainbc",
1386
                                  "Main LCD background color",
1387
                                  RadioSettingValueList(
1388
                                      LIST_COLOR9,
1389
                                      LIST_COLOR9[_mem.settings.mainbc]))
1390
            basic.append(mainbc)
1391

    
1392
            menufc = RadioSetting("settings.menufc", "Menu foreground color",
1393
                                  RadioSettingValueList(
1394
                                      LIST_COLOR9,
1395
                                      LIST_COLOR9[_mem.settings.menufc]))
1396
            basic.append(menufc)
1397

    
1398
            menubc = RadioSetting("settings.menubc", "Menu background color",
1399
                                  RadioSettingValueList(
1400
                                      LIST_COLOR9,
1401
                                      LIST_COLOR9[_mem.settings.menubc]))
1402
            basic.append(menubc)
1403

    
1404
            stafc = RadioSetting("settings.stafc",
1405
                                 "Top status foreground color",
1406
                                 RadioSettingValueList(
1407
                                     LIST_COLOR9,
1408
                                     LIST_COLOR9[_mem.settings.stafc]))
1409
            basic.append(stafc)
1410

    
1411
            stabc = RadioSetting("settings.stabc",
1412
                                 "Top status background color",
1413
                                 RadioSettingValueList(
1414
                                     LIST_COLOR9,
1415
                                     LIST_COLOR9[_mem.settings.stabc]))
1416
            basic.append(stabc)
1417

    
1418
            sigfc = RadioSetting("settings.sigfc",
1419
                                 "Bottom status foreground color",
1420
                                 RadioSettingValueList(
1421
                                     LIST_COLOR9,
1422
                                     LIST_COLOR9[_mem.settings.sigfc]))
1423
            basic.append(sigfc)
1424

    
1425
            sigbc = RadioSetting("settings.sigbc",
1426
                                 "Bottom status background color",
1427
                                 RadioSettingValueList(
1428
                                     LIST_COLOR9,
1429
                                     LIST_COLOR9[_mem.settings.sigbc]))
1430
            basic.append(sigbc)
1431

    
1432
            rxfc = RadioSetting("settings.rxfc", "Receiving character color",
1433
                                RadioSettingValueList(
1434
                                    LIST_COLOR9,
1435
                                    LIST_COLOR9[_mem.settings.rxfc]))
1436
            basic.append(rxfc)
1437

    
1438
            txfc = RadioSetting("settings.txfc",
1439
                                "Transmitting character color",
1440
                                RadioSettingValueList(
1441
                                    LIST_COLOR9,
1442
                                    LIST_COLOR9[_mem.settings.txfc]))
1443
            basic.append(txfc)
1444

    
1445
            txdisp = RadioSetting("settings.txdisp",
1446
                                  "Transmitting status display",
1447
                                  RadioSettingValueList(
1448
                                      LIST_TXDISP,
1449
                                      LIST_TXDISP[_mem.settings.txdisp]))
1450
            basic.append(txdisp)
1451
        elif self.COLOR_LCD2 or self.COLOR_LCD3:
1452
            stfc = RadioSetting("settings.stfc",
1453
                                "ST-FC",
1454
                                RadioSettingValueList(
1455
                                    LIST_COLOR8,
1456
                                    LIST_COLOR8[_mem.settings.stfc]))
1457
            basic.append(stfc)
1458

    
1459
            mffc = RadioSetting("settings.mffc",
1460
                                "MF-FC",
1461
                                RadioSettingValueList(
1462
                                    LIST_COLOR8,
1463
                                    LIST_COLOR8[_mem.settings.mffc]))
1464
            basic.append(mffc)
1465

    
1466
            sfafc = RadioSetting("settings.sfafc",
1467
                                 "SFA-FC",
1468
                                 RadioSettingValueList(
1469
                                     LIST_COLOR8,
1470
                                     LIST_COLOR8[_mem.settings.sfafc]))
1471
            basic.append(sfafc)
1472

    
1473
            sfbfc = RadioSetting("settings.sfbfc",
1474
                                 "SFB-FC",
1475
                                 RadioSettingValueList(
1476
                                     LIST_COLOR8,
1477
                                     LIST_COLOR8[_mem.settings.sfbfc]))
1478
            basic.append(sfbfc)
1479

    
1480
            sfcfc = RadioSetting("settings.sfcfc",
1481
                                 "SFC-FC",
1482
                                 RadioSettingValueList(
1483
                                     LIST_COLOR8,
1484
                                     LIST_COLOR8[_mem.settings.sfcfc]))
1485
            basic.append(sfcfc)
1486

    
1487
            sfdfc = RadioSetting("settings.sfdfc",
1488
                                 "SFD-FC",
1489
                                 RadioSettingValueList(
1490
                                     LIST_COLOR8,
1491
                                     LIST_COLOR8[_mem.settings.sfdfc]))
1492
            basic.append(sfdfc)
1493

    
1494
            subfc = RadioSetting("settings.subfc",
1495
                                 "SUB-FC",
1496
                                 RadioSettingValueList(
1497
                                     LIST_COLOR8,
1498
                                     LIST_COLOR8[_mem.settings.subfc]))
1499
            basic.append(subfc)
1500

    
1501
            fmfc = RadioSetting("settings.fmfc",
1502
                                "FM-FC",
1503
                                RadioSettingValueList(
1504
                                    LIST_COLOR8,
1505
                                    LIST_COLOR8[_mem.settings.fmfc]))
1506
            basic.append(fmfc)
1507

    
1508
            sigfc = RadioSetting("settings.sigfc",
1509
                                 "SIG-FC",
1510
                                 RadioSettingValueList(
1511
                                     LIST_COLOR8,
1512
                                     LIST_COLOR8[_mem.settings.sigfc]))
1513
            basic.append(sigfc)
1514

    
1515
            if not self.MODEL == "KT-8R":
1516
                modfc = RadioSetting("settings.modfc",
1517
                                     "MOD-FC",
1518
                                     RadioSettingValueList(
1519
                                         LIST_COLOR8,
1520
                                         LIST_COLOR8[_mem.settings.modfc]))
1521
                basic.append(modfc)
1522

    
1523
            menufc = RadioSetting("settings.menufc",
1524
                                  "MENUFC",
1525
                                  RadioSettingValueList(
1526
                                      LIST_COLOR8,
1527
                                      LIST_COLOR8[_mem.settings.menufc]))
1528
            basic.append(menufc)
1529

    
1530
            txfc = RadioSetting("settings.txfc",
1531
                                "TX-FC",
1532
                                RadioSettingValueList(
1533
                                    LIST_COLOR8,
1534
                                    LIST_COLOR8[_mem.settings.txfc]))
1535
            basic.append(txfc)
1536

    
1537
            if self.MODEL == "KT-8R":
1538
                rxfc = RadioSetting("settings.rxfc",
1539
                                    "RX-FC",
1540
                                    RadioSettingValueList(
1541
                                        LIST_COLOR8,
1542
                                        LIST_COLOR8[_mem.settings.rxfc]))
1543
                basic.append(rxfc)
1544

    
1545
            if not self.MODEL == "KT-8R":
1546
                txdisp = RadioSetting("settings.txdisp",
1547
                                      "Transmitting status display",
1548
                                      RadioSettingValueList(
1549
                                          LIST_TXDISP,
1550
                                          LIST_TXDISP[_mem.settings.txdisp]))
1551
                basic.append(txdisp)
1552
        else:
1553
            wtled = RadioSetting("settings.wtled", "Standby backlight Color",
1554
                                 RadioSettingValueList(
1555
                                     LIST_COLOR4,
1556
                                     LIST_COLOR4[_mem.settings.wtled]))
1557
            basic.append(wtled)
1558

    
1559
            rxled = RadioSetting("settings.rxled", "RX backlight Color",
1560
                                 RadioSettingValueList(
1561
                                     LIST_COLOR4,
1562
                                     LIST_COLOR4[_mem.settings.rxled]))
1563
            basic.append(rxled)
1564

    
1565
            txled = RadioSetting("settings.txled", "TX backlight Color",
1566
                                 RadioSettingValueList(
1567
                                     LIST_COLOR4,
1568
                                     LIST_COLOR4[_mem.settings.txled]))
1569
            basic.append(txled)
1570

    
1571
        anil = RadioSetting("settings.anil", "ANI length",
1572
                            RadioSettingValueList(
1573
                                LIST_ANIL,
1574
                                LIST_ANIL[_mem.settings.anil]))
1575
        basic.append(anil)
1576

    
1577
        reps = RadioSetting("settings.reps", "Relay signal (tone burst)",
1578
                            RadioSettingValueList(
1579
                                LIST_REPS,
1580
                                LIST_REPS[_mem.settings.reps]))
1581
        basic.append(reps)
1582

    
1583
        if not self.MODEL == "GMRS-50X1" and not self.MODEL == "KT-8R":
1584
            repm = RadioSetting("settings.repm", "Relay condition",
1585
                                RadioSettingValueList(
1586
                                    LIST_REPM,
1587
                                    LIST_REPM[_mem.settings.repm]))
1588
            basic.append(repm)
1589

    
1590
        if self.VENDOR == "BTECH" or self.COLOR_LCD:
1591
            if self.COLOR_LCD:
1592
                tmrmr = RadioSetting("settings.tmrmr", "TMR return time",
1593
                                     RadioSettingValueList(
1594
                                         LIST_OFF1TO50,
1595
                                         LIST_OFF1TO50[_mem.settings.tmrmr]))
1596
                basic.append(tmrmr)
1597
            else:
1598
                tdrab = RadioSetting("settings.tdrab", "TDR return time",
1599
                                     RadioSettingValueList(
1600
                                         LIST_OFF1TO50,
1601
                                         LIST_OFF1TO50[_mem.settings.tdrab]))
1602
                basic.append(tdrab)
1603

    
1604
            ste = RadioSetting("settings.ste", "Squelch tail eliminate",
1605
                               RadioSettingValueBoolean(_mem.settings.ste))
1606
            basic.append(ste)
1607

    
1608
            rpste = RadioSetting("settings.rpste", "Repeater STE",
1609
                                 RadioSettingValueList(
1610
                                     LIST_OFF1TO9,
1611
                                     LIST_OFF1TO9[_mem.settings.rpste]))
1612
            basic.append(rpste)
1613

    
1614
            rptdl = RadioSetting("settings.rptdl", "Repeater STE delay",
1615
                                 RadioSettingValueList(
1616
                                     LIST_RPTDL,
1617
                                     LIST_RPTDL[_mem.settings.rptdl]))
1618
            basic.append(rptdl)
1619

    
1620
        if self.MODEL == "DB25-G":
1621
            mgain = RadioSetting("settings.mgain", "Auto power-on",
1622
                                 RadioSettingValueBoolean(_mem.settings.mgain))
1623
            basic.append(mgain)
1624

    
1625
        if str(_mem.fingerprint.fp) in BTECH3:
1626
            mgain = RadioSetting("settings.mgain", "Mic gain",
1627
                                 RadioSettingValueInteger(0, 120,
1628
                                                          _mem.settings.mgain))
1629
            basic.append(mgain)
1630

    
1631
        if str(_mem.fingerprint.fp) in BTECH3 or self.COLOR_LCD:
1632
            dtmfg = RadioSetting("settings.dtmfg", "DTMF gain",
1633
                                 RadioSettingValueInteger(0, 60,
1634
                                                          _mem.settings.dtmfg))
1635
            basic.append(dtmfg)
1636

    
1637
        if self.VENDOR == "BTECH" and self.COLOR_LCD:
1638
            mgain = RadioSetting("settings.mgain", "Mic gain",
1639
                                 RadioSettingValueInteger(0, 120,
1640
                                                          _mem.settings.mgain))
1641
            basic.append(mgain)
1642

    
1643
            skiptx = RadioSetting("settings.skiptx", "Skip TX",
1644
                                  RadioSettingValueList(
1645
                                      LIST_SKIPTX,
1646
                                      LIST_SKIPTX[_mem.settings.skiptx]))
1647
            basic.append(skiptx)
1648

    
1649
            scmode = RadioSetting("settings.scmode", "Scan mode",
1650
                                  RadioSettingValueList(
1651
                                      LIST_SCMODE,
1652
                                      LIST_SCMODE[_mem.settings.scmode]))
1653
            basic.append(scmode)
1654

    
1655
        if self.MODEL == "KT-8R":
1656
            tmrtx = RadioSetting("settings.tmrtx", "TX in multi-standby",
1657
                                 RadioSettingValueList(
1658
                                     LIST_TMRTX,
1659
                                     LIST_TMRTX[_mem.settings.tmrtx]))
1660
            basic.append(tmrtx)
1661

    
1662
        # Advanced
1663
        def _filter(name):
1664
            filtered = ""
1665
            for char in str(name):
1666
                if char in VALID_CHARS:
1667
                    filtered += char
1668
                else:
1669
                    filtered += " "
1670
            return filtered
1671

    
1672
        if self.COLOR_LCD and not (self.COLOR_LCD2 or self.COLOR_LCD3):
1673
            _msg = self._memobj.poweron_msg
1674
            line1 = RadioSetting("poweron_msg.line1",
1675
                                 "Power-on message line 1",
1676
                                 RadioSettingValueString(0, 8, _filter(
1677
                                                         _msg.line1)))
1678
            advanced.append(line1)
1679
            line2 = RadioSetting("poweron_msg.line2",
1680
                                 "Power-on message line 2",
1681
                                 RadioSettingValueString(0, 8, _filter(
1682
                                                         _msg.line2)))
1683
            advanced.append(line2)
1684
            line3 = RadioSetting("poweron_msg.line3",
1685
                                 "Power-on message line 3",
1686
                                 RadioSettingValueString(0, 8, _filter(
1687
                                                         _msg.line3)))
1688
            advanced.append(line3)
1689
            line4 = RadioSetting("poweron_msg.line4",
1690
                                 "Power-on message line 4",
1691
                                 RadioSettingValueString(0, 8, _filter(
1692
                                                         _msg.line4)))
1693
            advanced.append(line4)
1694
            line5 = RadioSetting("poweron_msg.line5",
1695
                                 "Power-on message line 5",
1696
                                 RadioSettingValueString(0, 8, _filter(
1697
                                                         _msg.line5)))
1698
            advanced.append(line5)
1699
            line6 = RadioSetting("poweron_msg.line6",
1700
                                 "Power-on message line 6",
1701
                                 RadioSettingValueString(0, 8, _filter(
1702
                                                         _msg.line6)))
1703
            advanced.append(line6)
1704
            line7 = RadioSetting("poweron_msg.line7",
1705
                                 "Power-on message line 7",
1706
                                 RadioSettingValueString(0, 8, _filter(
1707
                                                         _msg.line7)))
1708
            advanced.append(line7)
1709
            line8 = RadioSetting("poweron_msg.line8", "Static message",
1710
                                 RadioSettingValueString(0, 8, _filter(
1711
                                                         _msg.line8)))
1712
            advanced.append(line8)
1713
        elif self.COLOR_LCD2 or self.COLOR_LCD3:
1714
            _msg = self._memobj.static_msg
1715
            line = RadioSetting("static_msg.line", "Static message",
1716
                                RadioSettingValueString(0, 16, _filter(
1717
                                    _msg.line)))
1718
            advanced.append(line)
1719
        else:
1720
            _msg = self._memobj.poweron_msg
1721
            line1 = RadioSetting("poweron_msg.line1",
1722
                                 "Power-on message line 1",
1723
                                 RadioSettingValueString(0, 6, _filter(
1724
                                                         _msg.line1)))
1725
            advanced.append(line1)
1726
            line2 = RadioSetting("poweron_msg.line2",
1727
                                 "Power-on message line 2",
1728
                                 RadioSettingValueString(0, 6, _filter(
1729
                                                         _msg.line2)))
1730
            advanced.append(line2)
1731

    
1732
        if self.MODEL in ("UV-2501", "UV-5001"):
1733
            vfomren = RadioSetting("settings2.vfomren", "VFO/MR switching",
1734
                                   RadioSettingValueBoolean(
1735
                                       _mem.settings2.vfomren))
1736
            advanced.append(vfomren)
1737

    
1738
            reseten = RadioSetting("settings2.reseten", "RESET",
1739
                                   RadioSettingValueBoolean(
1740
                                       _mem.settings2.reseten))
1741
            advanced.append(reseten)
1742

    
1743
            menuen = RadioSetting("settings2.menuen", "Menu",
1744
                                  RadioSettingValueBoolean(
1745
                                      _mem.settings2.menuen))
1746
            advanced.append(menuen)
1747

    
1748
        # Other
1749
        def convert_bytes_to_limit(bytes):
1750
            limit = ""
1751
            for byte in bytes:
1752
                if byte < 10:
1753
                    limit += chr(byte + 0x30)
1754
                else:
1755
                    break
1756
            return limit
1757

    
1758
        if self.MODEL in ["UV-2501+220", "KT8900R"]:
1759
            _ranges = self._memobj.ranges220
1760
            ranges = "ranges220"
1761
        else:
1762
            _ranges = self._memobj.ranges
1763
            ranges = "ranges"
1764

    
1765
        _limit = convert_bytes_to_limit(_ranges.vhf_low)
1766
        val = RadioSettingValueString(0, 3, _limit)
1767
        val.set_mutable(False)
1768
        vhf_low = RadioSetting("%s.vhf_low" % ranges, "VHF low", val)
1769
        other.append(vhf_low)
1770

    
1771
        _limit = convert_bytes_to_limit(_ranges.vhf_high)
1772
        val = RadioSettingValueString(0, 3, _limit)
1773
        val.set_mutable(False)
1774
        vhf_high = RadioSetting("%s.vhf_high" % ranges, "VHF high", val)
1775
        other.append(vhf_high)
1776

    
1777
        if self.BANDS == 3 or self.BANDS == 4:
1778
            _limit = convert_bytes_to_limit(_ranges.vhf2_low)
1779
            val = RadioSettingValueString(0, 3, _limit)
1780
            val.set_mutable(False)
1781
            vhf2_low = RadioSetting("%s.vhf2_low" % ranges, "VHF2 low", val)
1782
            other.append(vhf2_low)
1783

    
1784
            _limit = convert_bytes_to_limit(_ranges.vhf2_high)
1785
            val = RadioSettingValueString(0, 3, _limit)
1786
            val.set_mutable(False)
1787
            vhf2_high = RadioSetting("%s.vhf2_high" % ranges, "VHF2 high", val)
1788
            other.append(vhf2_high)
1789

    
1790
        _limit = convert_bytes_to_limit(_ranges.uhf_low)
1791
        val = RadioSettingValueString(0, 3, _limit)
1792
        val.set_mutable(False)
1793
        uhf_low = RadioSetting("%s.uhf_low" % ranges, "UHF low", val)
1794
        other.append(uhf_low)
1795

    
1796
        _limit = convert_bytes_to_limit(_ranges.uhf_high)
1797
        val = RadioSettingValueString(0, 3, _limit)
1798
        val.set_mutable(False)
1799
        uhf_high = RadioSetting("%s.uhf_high" % ranges, "UHF high", val)
1800
        other.append(uhf_high)
1801

    
1802
        if self.BANDS == 4:
1803
            _limit = convert_bytes_to_limit(_ranges.uhf2_low)
1804
            val = RadioSettingValueString(0, 3, _limit)
1805
            val.set_mutable(False)
1806
            uhf2_low = RadioSetting("%s.uhf2_low" % ranges, "UHF2 low", val)
1807
            other.append(uhf2_low)
1808

    
1809
            _limit = convert_bytes_to_limit(_ranges.uhf2_high)
1810
            val = RadioSettingValueString(0, 3, _limit)
1811
            val.set_mutable(False)
1812
            uhf2_high = RadioSetting("%s.uhf2_high" % ranges, "UHF2 high", val)
1813
            other.append(uhf2_high)
1814

    
1815
        val = RadioSettingValueString(0, 6, _filter(_mem.fingerprint.fp))
1816
        val.set_mutable(False)
1817
        fp = RadioSetting("fingerprint.fp", "Fingerprint", val)
1818
        other.append(fp)
1819

    
1820
        # Work
1821
        if self.COLOR_LCD:
1822
            dispab = RadioSetting("settings2.dispab", "Display",
1823
                                  RadioSettingValueList(
1824
                                      LIST_ABCD,
1825
                                      LIST_ABCD[_mem.settings2.dispab]))
1826
            work.append(dispab)
1827
        else:
1828
            dispab = RadioSetting("settings2.dispab", "Display",
1829
                                  RadioSettingValueList(
1830
                                      LIST_AB,
1831
                                      LIST_AB[_mem.settings2.dispab]))
1832
            work.append(dispab)
1833

    
1834
        if self.COLOR_LCD:
1835
            vfomra = RadioSetting("settings2.vfomra", "VFO/MR A mode",
1836
                                  RadioSettingValueList(
1837
                                      LIST_VFOMR,
1838
                                      LIST_VFOMR[_mem.settings2.vfomra]))
1839
            work.append(vfomra)
1840

    
1841
            vfomrb = RadioSetting("settings2.vfomrb", "VFO/MR B mode",
1842
                                  RadioSettingValueList(
1843
                                      LIST_VFOMR,
1844
                                      LIST_VFOMR[_mem.settings2.vfomrb]))
1845
            work.append(vfomrb)
1846

    
1847
            vfomrc = RadioSetting("settings2.vfomrc", "VFO/MR C mode",
1848
                                  RadioSettingValueList(
1849
                                      LIST_VFOMR,
1850
                                      LIST_VFOMR[_mem.settings2.vfomrc]))
1851
            work.append(vfomrc)
1852

    
1853
            vfomrd = RadioSetting("settings2.vfomrd", "VFO/MR D mode",
1854
                                  RadioSettingValueList(
1855
                                      LIST_VFOMR,
1856
                                      LIST_VFOMR[_mem.settings2.vfomrd]))
1857
            work.append(vfomrd)
1858
        else:
1859
            vfomr = RadioSetting("settings2.vfomr", "VFO/MR mode",
1860
                                 RadioSettingValueList(
1861
                                     LIST_VFOMR,
1862
                                     LIST_VFOMR[_mem.settings2.vfomr]))
1863
            work.append(vfomr)
1864

    
1865
        keylock = RadioSetting("settings2.keylock", "Keypad lock",
1866
                               RadioSettingValueBoolean(
1867
                                   _mem.settings2.keylock))
1868
        work.append(keylock)
1869

    
1870
        mrcha = RadioSetting("settings2.mrcha", "MR A channel",
1871
                             RadioSettingValueInteger(0, self._upper,
1872
                                                      _mem.settings2.mrcha))
1873
        work.append(mrcha)
1874

    
1875
        mrchb = RadioSetting("settings2.mrchb", "MR B channel",
1876
                             RadioSettingValueInteger(0, self._upper,
1877
                                                      _mem.settings2.mrchb))
1878
        work.append(mrchb)
1879

    
1880
        if self.COLOR_LCD:
1881
            mrchc = RadioSetting("settings2.mrchc", "MR C channel",
1882
                                 RadioSettingValueInteger(
1883
                                     0, self._upper, _mem.settings2.mrchc))
1884
            work.append(mrchc)
1885

    
1886
            mrchd = RadioSetting("settings2.mrchd", "MR D channel",
1887
                                 RadioSettingValueInteger(
1888
                                     0, self._upper, _mem.settings2.mrchd))
1889
            work.append(mrchd)
1890

    
1891
        def convert_bytes_to_freq(bytes):
1892
            real_freq = 0
1893
            for byte in bytes:
1894
                real_freq = (real_freq * 10) + byte
1895
            return chirp_common.format_freq(real_freq * 10)
1896

    
1897
        def my_validate(value):
1898
            _vhf_lower = int(convert_bytes_to_limit(_ranges.vhf_low))
1899
            _vhf_upper = int(convert_bytes_to_limit(_ranges.vhf_high))
1900
            _uhf_lower = int(convert_bytes_to_limit(_ranges.uhf_low))
1901
            _uhf_upper = int(convert_bytes_to_limit(_ranges.uhf_high))
1902
            if self.BANDS == 3 or self.BANDS == 4:
1903
                _vhf2_lower = int(convert_bytes_to_limit(_ranges.vhf2_low))
1904
                _vhf2_upper = int(convert_bytes_to_limit(_ranges.vhf2_high))
1905
            if self.BANDS == 4:
1906
                _uhf2_lower = int(convert_bytes_to_limit(_ranges.uhf2_low))
1907
                _uhf2_upper = int(convert_bytes_to_limit(_ranges.uhf2_high))
1908

    
1909
            value = chirp_common.parse_freq(value)
1910
            msg = ("Can't be less then %i.0000")
1911
            if value > 99000000 and value < _vhf_lower * 1000000:
1912
                raise InvalidValueError(msg % (_vhf_lower))
1913
            msg = ("Can't be betweeb %i.9975-%i.0000")
1914
            if self.BANDS == 2:
1915
                if (_vhf_upper + 1) * 1000000 <= value and \
1916
                        value < _uhf_lower * 1000000:
1917
                    raise InvalidValueError(msg % (_vhf_upper, _uhf_lower))
1918
            if self.BANDS == 3:
1919
                if (_vhf_upper + 1) * 1000000 <= value and \
1920
                        value < _vhf2_lower * 1000000:
1921
                    raise InvalidValueError(msg % (_vhf_upper, _vhf2_lower))
1922
                if (_vhf2_upper + 1) * 1000000 <= value and \
1923
                        value < _uhf_lower * 1000000:
1924
                    raise InvalidValueError(msg % (_vhf2_upper, _uhf_lower))
1925
            if self.BANDS == 4:
1926
                if (_vhf_upper + 1) * 1000000 <= value and \
1927
                        value < _vhf2_lower * 1000000:
1928
                    raise InvalidValueError(msg % (_vhf_upper, _vhf2_lower))
1929
                if (_vhf2_upper + 1) * 1000000 <= value and \
1930
                        value < _uhf2_lower * 1000000:
1931
                    raise InvalidValueError(msg % (_vhf2_upper, _uhf2_lower))
1932
                if (_uhf2_upper + 1) * 1000000 <= value and \
1933
                        value < _uhf_lower * 1000000:
1934
                    raise InvalidValueError(msg % (_uhf2_upper, _uhf_lower))
1935
            msg = ("Can't be greater then %i.9975")
1936
            if value > 99000000 and value >= _uhf_upper * 1000000:
1937
                raise InvalidValueError(msg % (_uhf_upper))
1938
            return chirp_common.format_freq(value)
1939

    
1940
        def apply_freq(setting, obj):
1941
            value = chirp_common.parse_freq(str(setting.value)) / 10
1942
            for i in range(7, -1, -1):
1943
                obj.freq[i] = value % 10
1944
                value /= 10
1945

    
1946
        val1a = RadioSettingValueString(0, 10, convert_bytes_to_freq(
1947
                                        _mem.vfo.a.freq))
1948
        val1a.set_validate_callback(my_validate)
1949
        vfoafreq = RadioSetting("vfo.a.freq", "VFO A frequency", val1a)
1950
        vfoafreq.set_apply_callback(apply_freq, _mem.vfo.a)
1951
        work.append(vfoafreq)
1952

    
1953
        val1b = RadioSettingValueString(0, 10, convert_bytes_to_freq(
1954
                                        _mem.vfo.b.freq))
1955
        val1b.set_validate_callback(my_validate)
1956
        vfobfreq = RadioSetting("vfo.b.freq", "VFO B frequency", val1b)
1957
        vfobfreq.set_apply_callback(apply_freq, _mem.vfo.b)
1958
        work.append(vfobfreq)
1959

    
1960
        if self.COLOR_LCD:
1961
            val1c = RadioSettingValueString(0, 10, convert_bytes_to_freq(
1962
                                            _mem.vfo.c.freq))
1963
            val1c.set_validate_callback(my_validate)
1964
            vfocfreq = RadioSetting("vfo.c.freq", "VFO C frequency", val1c)
1965
            vfocfreq.set_apply_callback(apply_freq, _mem.vfo.c)
1966
            work.append(vfocfreq)
1967

    
1968
            val1d = RadioSettingValueString(0, 10, convert_bytes_to_freq(
1969
                                            _mem.vfo.d.freq))
1970
            val1d.set_validate_callback(my_validate)
1971
            vfodfreq = RadioSetting("vfo.d.freq", "VFO D frequency", val1d)
1972
            vfodfreq.set_apply_callback(apply_freq, _mem.vfo.d)
1973
            work.append(vfodfreq)
1974

    
1975
        if not self.MODEL == "GMRS-50X1":
1976
            vfoashiftd = RadioSetting("vfo.a.shiftd", "VFO A shift",
1977
                                      RadioSettingValueList(
1978
                                          LIST_SHIFT,
1979
                                          LIST_SHIFT[_mem.vfo.a.shiftd]))
1980
            work.append(vfoashiftd)
1981

    
1982
            vfobshiftd = RadioSetting("vfo.b.shiftd", "VFO B shift",
1983
                                      RadioSettingValueList(
1984
                                          LIST_SHIFT,
1985
                                          LIST_SHIFT[_mem.vfo.b.shiftd]))
1986
            work.append(vfobshiftd)
1987

    
1988
            if self.COLOR_LCD:
1989
                vfocshiftd = RadioSetting("vfo.c.shiftd", "VFO C shift",
1990
                                          RadioSettingValueList(
1991
                                              LIST_SHIFT,
1992
                                              LIST_SHIFT[_mem.vfo.c.shiftd]))
1993
                work.append(vfocshiftd)
1994

    
1995
                vfodshiftd = RadioSetting("vfo.d.shiftd", "VFO D shift",
1996
                                          RadioSettingValueList(
1997
                                              LIST_SHIFT,
1998
                                              LIST_SHIFT[_mem.vfo.d.shiftd]))
1999
                work.append(vfodshiftd)
2000

    
2001
        def convert_bytes_to_offset(bytes):
2002
            real_offset = 0
2003
            for byte in bytes:
2004
                real_offset = (real_offset * 10) + byte
2005
            return chirp_common.format_freq(real_offset * 1000)
2006

    
2007
        def apply_offset(setting, obj):
2008
            value = chirp_common.parse_freq(str(setting.value)) / 1000
2009
            for i in range(5, -1, -1):
2010
                obj.offset[i] = value % 10
2011
                value /= 10
2012

    
2013
        if not self.MODEL == "GMRS-50X1":
2014
            if self.COLOR_LCD:
2015
                val1a = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2016
                                                _mem.vfo.a.offset))
2017
                vfoaoffset = RadioSetting("vfo.a.offset",
2018
                                          "VFO A offset (0.000-999.999)",
2019
                                          val1a)
2020
                vfoaoffset.set_apply_callback(apply_offset, _mem.vfo.a)
2021
                work.append(vfoaoffset)
2022

    
2023
                val1b = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2024
                                                _mem.vfo.b.offset))
2025
                vfoboffset = RadioSetting("vfo.b.offset",
2026
                                          "VFO B offset (0.000-999.999)",
2027
                                          val1b)
2028
                vfoboffset.set_apply_callback(apply_offset, _mem.vfo.b)
2029
                work.append(vfoboffset)
2030

    
2031
                val1c = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2032
                                                _mem.vfo.c.offset))
2033
                vfocoffset = RadioSetting("vfo.c.offset",
2034
                                          "VFO C offset (0.000-999.999)",
2035
                                          val1c)
2036
                vfocoffset.set_apply_callback(apply_offset, _mem.vfo.c)
2037
                work.append(vfocoffset)
2038

    
2039
                val1d = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2040
                                                _mem.vfo.d.offset))
2041
                vfodoffset = RadioSetting("vfo.d.offset",
2042
                                          "VFO D offset (0.000-999.999)",
2043
                                          val1d)
2044
                vfodoffset.set_apply_callback(apply_offset, _mem.vfo.d)
2045
                work.append(vfodoffset)
2046
            else:
2047
                val1a = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2048
                                                _mem.vfo.a.offset))
2049
                vfoaoffset = RadioSetting("vfo.a.offset",
2050
                                          "VFO A offset (0.000-99.999)", val1a)
2051
                vfoaoffset.set_apply_callback(apply_offset, _mem.vfo.a)
2052
                work.append(vfoaoffset)
2053

    
2054
                val1b = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2055
                                                _mem.vfo.b.offset))
2056
                vfoboffset = RadioSetting("vfo.b.offset",
2057
                                          "VFO B offset (0.000-99.999)", val1b)
2058
                vfoboffset.set_apply_callback(apply_offset, _mem.vfo.b)
2059
                work.append(vfoboffset)
2060

    
2061
        if not self.MODEL == "GMRS-50X1":
2062
            vfoatxp = RadioSetting("vfo.a.power", "VFO A power",
2063
                                   RadioSettingValueList(
2064
                                       LIST_TXP,
2065
                                       LIST_TXP[_mem.vfo.a.power]))
2066
            work.append(vfoatxp)
2067

    
2068
            vfobtxp = RadioSetting("vfo.b.power", "VFO B power",
2069
                                   RadioSettingValueList(
2070
                                       LIST_TXP,
2071
                                       LIST_TXP[_mem.vfo.b.power]))
2072
            work.append(vfobtxp)
2073

    
2074
            if self.COLOR_LCD:
2075
                vfoctxp = RadioSetting("vfo.c.power", "VFO C power",
2076
                                       RadioSettingValueList(
2077
                                           LIST_TXP,
2078
                                           LIST_TXP[_mem.vfo.c.power]))
2079
                work.append(vfoctxp)
2080

    
2081
                vfodtxp = RadioSetting("vfo.d.power", "VFO D power",
2082
                                       RadioSettingValueList(
2083
                                           LIST_TXP,
2084
                                           LIST_TXP[_mem.vfo.d.power]))
2085
                work.append(vfodtxp)
2086

    
2087
        if not self.MODEL == "GMRS-50X1":
2088
            vfoawide = RadioSetting("vfo.a.wide", "VFO A bandwidth",
2089
                                    RadioSettingValueList(
2090
                                        LIST_WIDE,
2091
                                        LIST_WIDE[_mem.vfo.a.wide]))
2092
            work.append(vfoawide)
2093

    
2094
            vfobwide = RadioSetting("vfo.b.wide", "VFO B bandwidth",
2095
                                    RadioSettingValueList(
2096
                                        LIST_WIDE,
2097
                                        LIST_WIDE[_mem.vfo.b.wide]))
2098
            work.append(vfobwide)
2099

    
2100
            if self.COLOR_LCD:
2101
                vfocwide = RadioSetting("vfo.c.wide", "VFO C bandwidth",
2102
                                        RadioSettingValueList(
2103
                                            LIST_WIDE,
2104
                                            LIST_WIDE[_mem.vfo.c.wide]))
2105
                work.append(vfocwide)
2106

    
2107
                vfodwide = RadioSetting("vfo.d.wide", "VFO D bandwidth",
2108
                                        RadioSettingValueList(
2109
                                            LIST_WIDE,
2110
                                            LIST_WIDE[_mem.vfo.d.wide]))
2111
                work.append(vfodwide)
2112

    
2113
        vfoastep = RadioSetting("vfo.a.step", "VFO A step",
2114
                                RadioSettingValueList(
2115
                                    LIST_STEP,
2116
                                    LIST_STEP[_mem.vfo.a.step]))
2117
        work.append(vfoastep)
2118

    
2119
        vfobstep = RadioSetting("vfo.b.step", "VFO B step",
2120
                                RadioSettingValueList(
2121
                                    LIST_STEP,
2122
                                    LIST_STEP[_mem.vfo.b.step]))
2123
        work.append(vfobstep)
2124

    
2125
        if self.COLOR_LCD:
2126
            vfocstep = RadioSetting("vfo.c.step", "VFO C step",
2127
                                    RadioSettingValueList(
2128
                                        LIST_STEP,
2129
                                        LIST_STEP[_mem.vfo.c.step]))
2130
            work.append(vfocstep)
2131

    
2132
            vfodstep = RadioSetting("vfo.d.step", "VFO D step",
2133
                                    RadioSettingValueList(
2134
                                        LIST_STEP,
2135
                                        LIST_STEP[_mem.vfo.d.step]))
2136
            work.append(vfodstep)
2137

    
2138
        vfoaoptsig = RadioSetting("vfo.a.optsig", "VFO A optional signal",
2139
                                  RadioSettingValueList(
2140
                                      OPTSIG_LIST,
2141
                                      OPTSIG_LIST[_mem.vfo.a.optsig]))
2142
        work.append(vfoaoptsig)
2143

    
2144
        vfoboptsig = RadioSetting("vfo.b.optsig", "VFO B optional signal",
2145
                                  RadioSettingValueList(
2146
                                      OPTSIG_LIST,
2147
                                      OPTSIG_LIST[_mem.vfo.b.optsig]))
2148
        work.append(vfoboptsig)
2149

    
2150
        if self.COLOR_LCD:
2151
            vfocoptsig = RadioSetting("vfo.c.optsig", "VFO C optional signal",
2152
                                      RadioSettingValueList(
2153
                                          OPTSIG_LIST,
2154
                                          OPTSIG_LIST[_mem.vfo.c.optsig]))
2155
            work.append(vfocoptsig)
2156

    
2157
            vfodoptsig = RadioSetting("vfo.d.optsig", "VFO D optional signal",
2158
                                      RadioSettingValueList(
2159
                                          OPTSIG_LIST,
2160
                                          OPTSIG_LIST[_mem.vfo.d.optsig]))
2161
            work.append(vfodoptsig)
2162

    
2163
        vfoaspmute = RadioSetting("vfo.a.spmute", "VFO A speaker mute",
2164
                                  RadioSettingValueList(
2165
                                      SPMUTE_LIST,
2166
                                      SPMUTE_LIST[_mem.vfo.a.spmute]))
2167
        work.append(vfoaspmute)
2168

    
2169
        vfobspmute = RadioSetting("vfo.b.spmute", "VFO B speaker mute",
2170
                                  RadioSettingValueList(
2171
                                      SPMUTE_LIST,
2172
                                      SPMUTE_LIST[_mem.vfo.b.spmute]))
2173
        work.append(vfobspmute)
2174

    
2175
        if self.COLOR_LCD:
2176
            vfocspmute = RadioSetting("vfo.c.spmute", "VFO C speaker mute",
2177
                                      RadioSettingValueList(
2178
                                          SPMUTE_LIST,
2179
                                          SPMUTE_LIST[_mem.vfo.c.spmute]))
2180
            work.append(vfocspmute)
2181

    
2182
            vfodspmute = RadioSetting("vfo.d.spmute", "VFO D speaker mute",
2183
                                      RadioSettingValueList(
2184
                                          SPMUTE_LIST,
2185
                                          SPMUTE_LIST[_mem.vfo.d.spmute]))
2186
            work.append(vfodspmute)
2187

    
2188
        if not self.COLOR_LCD or \
2189
                (self.COLOR_LCD and not self.VENDOR == "BTECH"):
2190
            vfoascr = RadioSetting("vfo.a.scramble", "VFO A scramble",
2191
                                   RadioSettingValueBoolean(
2192
                                       _mem.vfo.a.scramble))
2193
            work.append(vfoascr)
2194

    
2195
            vfobscr = RadioSetting("vfo.b.scramble", "VFO B scramble",
2196
                                   RadioSettingValueBoolean(
2197
                                       _mem.vfo.b.scramble))
2198
            work.append(vfobscr)
2199

    
2200
        if self.COLOR_LCD and not self.VENDOR == "BTECH":
2201
            vfocscr = RadioSetting("vfo.c.scramble", "VFO C scramble",
2202
                                   RadioSettingValueBoolean(
2203
                                       _mem.vfo.c.scramble))
2204
            work.append(vfocscr)
2205

    
2206
            vfodscr = RadioSetting("vfo.d.scramble", "VFO D scramble",
2207
                                   RadioSettingValueBoolean(
2208
                                       _mem.vfo.d.scramble))
2209
            work.append(vfodscr)
2210

    
2211
        if not self.MODEL == "GMRS-50X1":
2212
            vfoascode = RadioSetting("vfo.a.scode", "VFO A PTT-ID",
2213
                                     RadioSettingValueList(
2214
                                         PTTIDCODE_LIST,
2215
                                         PTTIDCODE_LIST[_mem.vfo.a.scode]))
2216
            work.append(vfoascode)
2217

    
2218
            vfobscode = RadioSetting("vfo.b.scode", "VFO B PTT-ID",
2219
                                     RadioSettingValueList(
2220
                                         PTTIDCODE_LIST,
2221
                                         PTTIDCODE_LIST[_mem.vfo.b.scode]))
2222
            work.append(vfobscode)
2223

    
2224
            if self.COLOR_LCD:
2225
                vfocscode = RadioSetting("vfo.c.scode", "VFO C PTT-ID",
2226
                                         RadioSettingValueList(
2227
                                             PTTIDCODE_LIST,
2228
                                             PTTIDCODE_LIST[_mem.vfo.c.scode]))
2229
                work.append(vfocscode)
2230

    
2231
                vfodscode = RadioSetting("vfo.d.scode", "VFO D PTT-ID",
2232
                                         RadioSettingValueList(
2233
                                             PTTIDCODE_LIST,
2234
                                             PTTIDCODE_LIST[_mem.vfo.d.scode]))
2235
                work.append(vfodscode)
2236

    
2237
        if not self.MODEL == "GMRS-50X1":
2238
            pttid = RadioSetting("settings.pttid", "PTT ID",
2239
                                 RadioSettingValueList(
2240
                                     PTTID_LIST,
2241
                                     PTTID_LIST[_mem.settings.pttid]))
2242
            work.append(pttid)
2243

    
2244
        if not self.COLOR_LCD:
2245
            # FM presets
2246
            fm_presets = RadioSettingGroup("fm_presets", "FM Presets")
2247
            top.append(fm_presets)
2248

    
2249
            def fm_validate(value):
2250
                if value == 0:
2251
                    return chirp_common.format_freq(value)
2252
                if not (87.5 <= value and value <= 108.0):  # 87.5-108MHz
2253
                    msg = ("FM-Preset-Frequency: " +
2254
                           "Must be between 87.5 and 108 MHz")
2255
                    raise InvalidValueError(msg)
2256
                return value
2257

    
2258
            def apply_fm_preset_name(setting, obj):
2259
                valstring = str(setting.value)
2260
                for i in range(0, 6):
2261
                    if valstring[i] in VALID_CHARS:
2262
                        obj[i] = valstring[i]
2263
                    else:
2264
                        obj[i] = '0xff'
2265

    
2266
            def apply_fm_freq(setting, obj):
2267
                value = chirp_common.parse_freq(str(setting.value)) / 10
2268
                for i in range(7, -1, -1):
2269
                    obj.freq[i] = value % 10
2270
                    value /= 10
2271

    
2272
            _presets = self._memobj.fm_radio_preset
2273
            i = 1
2274
            for preset in _presets:
2275
                line = RadioSetting("fm_presets_" + str(i),
2276
                                    "Station name " + str(i),
2277
                                    RadioSettingValueString(0, 6, _filter(
2278
                                        preset.broadcast_station_name)))
2279
                line.set_apply_callback(apply_fm_preset_name,
2280
                                        preset.broadcast_station_name)
2281

    
2282
                val = RadioSettingValueFloat(0, 108,
2283
                                             convert_bytes_to_freq(
2284
                                                 preset.freq))
2285
                fmfreq = RadioSetting("fm_presets_" + str(i) + "_freq",
2286
                                      "Frequency " + str(i), val)
2287
                val.set_validate_callback(fm_validate)
2288
                fmfreq.set_apply_callback(apply_fm_freq, preset)
2289
                fm_presets.append(line)
2290
                fm_presets.append(fmfreq)
2291

    
2292
                i = i + 1
2293

    
2294
        # DTMF-Setting
2295
        dtmf_enc_settings = RadioSettingGroup("dtmf_enc_settings",
2296
                                              "DTMF Encoding Settings")
2297
        dtmf_dec_settings = RadioSettingGroup("dtmf_dec_settings",
2298
                                              "DTMF Decoding Settings")
2299
        top.append(dtmf_enc_settings)
2300
        top.append(dtmf_dec_settings)
2301
        txdisable = RadioSetting("dtmf_settings.txdisable",
2302
                                 "TX-Disable",
2303
                                 RadioSettingValueBoolean(
2304
                                     _mem.dtmf_settings.txdisable))
2305
        dtmf_enc_settings.append(txdisable)
2306

    
2307
        rxdisable = RadioSetting("dtmf_settings.rxdisable",
2308
                                 "RX-Disable",
2309
                                 RadioSettingValueBoolean(
2310
                                     _mem.dtmf_settings.rxdisable))
2311
        dtmf_enc_settings.append(rxdisable)
2312

    
2313
        if _mem.dtmf_settings.dtmfspeed_on > 0x0F:
2314
            val = 0x03
2315
        else:
2316
            val = _mem.dtmf_settings.dtmfspeed_on
2317
        dtmfspeed_on = RadioSetting(
2318
            "dtmf_settings.dtmfspeed_on",
2319
            "DTMF Speed (On Time)",
2320
            RadioSettingValueList(LIST_DTMF_SPEED,
2321
                                  LIST_DTMF_SPEED[
2322
                                      val]))
2323
        dtmf_enc_settings.append(dtmfspeed_on)
2324

    
2325
        if _mem.dtmf_settings.dtmfspeed_off > 0x0F:
2326
            val = 0x03
2327
        else:
2328
            val = _mem.dtmf_settings.dtmfspeed_off
2329
        dtmfspeed_off = RadioSetting(
2330
            "dtmf_settings.dtmfspeed_off",
2331
            "DTMF Speed (Off Time)",
2332
            RadioSettingValueList(LIST_DTMF_SPEED,
2333
                                  LIST_DTMF_SPEED[
2334
                                      val]))
2335
        dtmf_enc_settings.append(dtmfspeed_off)
2336

    
2337
        def memory2string(dmtf_mem):
2338
            dtmf_string = ""
2339
            for digit in dmtf_mem:
2340
                if digit != 255:
2341
                    index = LIST_DTMF_VALUES.index(digit)
2342
                    dtmf_string = dtmf_string + LIST_DTMF_DIGITS[index]
2343
            return dtmf_string
2344

    
2345
        def apply_dmtf_frame(setting, obj):
2346
            LOG.debug("Setting DTMF-Code: " + str(setting.value))
2347
            val_string = str(setting.value)
2348
            for i in range(0, 16):
2349
                obj[i] = 255
2350
            i = 0
2351
            for current_char in val_string:
2352
                current_char = current_char.upper()
2353
                index = LIST_DTMF_DIGITS.index(current_char)
2354
                obj[i] = LIST_DTMF_VALUES[index]
2355
                i = i + 1
2356

    
2357
        codes = self._memobj.dtmf_codes
2358
        i = 1
2359
        for dtmfcode in codes:
2360
            val = RadioSettingValueString(0, 16, memory2string(
2361
                                              dtmfcode.code),
2362
                                          False, CHARSET_DTMF_DIGITS)
2363
            line = RadioSetting("dtmf_code_" + str(i) + "_code",
2364
                                "DMTF Code " + str(i), val)
2365
            line.set_apply_callback(apply_dmtf_frame, dtmfcode.code)
2366
            dtmf_enc_settings.append(line)
2367
            i = i + 1
2368

    
2369
        line = RadioSetting("dtmf_settings.mastervice",
2370
                            "Master and Vice ID",
2371
                            RadioSettingValueBoolean(
2372
                                _mem.dtmf_settings.mastervice))
2373
        dtmf_dec_settings.append(line)
2374

    
2375
        val = RadioSettingValueString(0, 16, memory2string(
2376
                                          _mem.dtmf_settings.masterid),
2377
                                      False, CHARSET_DTMF_DIGITS)
2378
        line = RadioSetting("dtmf_settings.masterid",
2379
                            "Master Control ID ", val)
2380
        line.set_apply_callback(apply_dmtf_frame,
2381
                                _mem.dtmf_settings.masterid)
2382
        dtmf_dec_settings.append(line)
2383

    
2384
        line = RadioSetting("dtmf_settings.minspection",
2385
                            "Master Inspection",
2386
                            RadioSettingValueBoolean(
2387
                                _mem.dtmf_settings.minspection))
2388
        dtmf_dec_settings.append(line)
2389

    
2390
        line = RadioSetting("dtmf_settings.mmonitor",
2391
                            "Master Monitor",
2392
                            RadioSettingValueBoolean(
2393
                                _mem.dtmf_settings.mmonitor))
2394
        dtmf_dec_settings.append(line)
2395

    
2396
        line = RadioSetting("dtmf_settings.mstun",
2397
                            "Master Stun",
2398
                            RadioSettingValueBoolean(
2399
                                _mem.dtmf_settings.mstun))
2400
        dtmf_dec_settings.append(line)
2401

    
2402
        line = RadioSetting("dtmf_settings.mkill",
2403
                            "Master Kill",
2404
                            RadioSettingValueBoolean(
2405
                                _mem.dtmf_settings.mkill))
2406
        dtmf_dec_settings.append(line)
2407

    
2408
        line = RadioSetting("dtmf_settings.mrevive",
2409
                            "Master Revive",
2410
                            RadioSettingValueBoolean(
2411
                                _mem.dtmf_settings.mrevive))
2412
        dtmf_dec_settings.append(line)
2413

    
2414
        val = RadioSettingValueString(0, 16, memory2string(
2415
                                          _mem.dtmf_settings.viceid),
2416
                                      False, CHARSET_DTMF_DIGITS)
2417
        line = RadioSetting("dtmf_settings.viceid",
2418
                            "Vice Control ID ", val)
2419
        line.set_apply_callback(apply_dmtf_frame,
2420
                                _mem.dtmf_settings.viceid)
2421
        dtmf_dec_settings.append(line)
2422

    
2423
        line = RadioSetting("dtmf_settings.vinspection",
2424
                            "Vice Inspection",
2425
                            RadioSettingValueBoolean(
2426
                                _mem.dtmf_settings.vinspection))
2427
        dtmf_dec_settings.append(line)
2428

    
2429
        line = RadioSetting("dtmf_settings.vmonitor",
2430
                            "Vice Monitor",
2431
                            RadioSettingValueBoolean(
2432
                                _mem.dtmf_settings.vmonitor))
2433
        dtmf_dec_settings.append(line)
2434

    
2435
        line = RadioSetting("dtmf_settings.vstun",
2436
                            "Vice Stun",
2437
                            RadioSettingValueBoolean(
2438
                                _mem.dtmf_settings.vstun))
2439
        dtmf_dec_settings.append(line)
2440

    
2441
        line = RadioSetting("dtmf_settings.vkill",
2442
                            "Vice Kill",
2443
                            RadioSettingValueBoolean(
2444
                                _mem.dtmf_settings.vkill))
2445
        dtmf_dec_settings.append(line)
2446

    
2447
        line = RadioSetting("dtmf_settings.vrevive",
2448
                            "Vice Revive",
2449
                            RadioSettingValueBoolean(
2450
                                _mem.dtmf_settings.vrevive))
2451
        dtmf_dec_settings.append(line)
2452

    
2453
        val = RadioSettingValueString(0, 16, memory2string(
2454
                                          _mem.dtmf_settings.inspection),
2455
                                      False, CHARSET_DTMF_DIGITS)
2456
        line = RadioSetting("dtmf_settings.inspection",
2457
                            "Inspection", val)
2458
        line.set_apply_callback(apply_dmtf_frame,
2459
                                _mem.dtmf_settings.inspection)
2460
        dtmf_dec_settings.append(line)
2461

    
2462
        val = RadioSettingValueString(0, 16, memory2string(
2463
                                          _mem.dtmf_settings.alarmcode),
2464
                                      False, CHARSET_DTMF_DIGITS)
2465
        line = RadioSetting("dtmf_settings.alarmcode",
2466
                            "Alarm", val)
2467
        line.set_apply_callback(apply_dmtf_frame,
2468
                                _mem.dtmf_settings.alarmcode)
2469
        dtmf_dec_settings.append(line)
2470

    
2471
        val = RadioSettingValueString(0, 16, memory2string(
2472
                                          _mem.dtmf_settings.kill),
2473
                                      False, CHARSET_DTMF_DIGITS)
2474
        line = RadioSetting("dtmf_settings.kill",
2475
                            "Kill", val)
2476
        line.set_apply_callback(apply_dmtf_frame,
2477
                                _mem.dtmf_settings.kill)
2478
        dtmf_dec_settings.append(line)
2479

    
2480
        val = RadioSettingValueString(0, 16, memory2string(
2481
                                          _mem.dtmf_settings.monitor),
2482
                                      False, CHARSET_DTMF_DIGITS)
2483
        line = RadioSetting("dtmf_settings.monitor",
2484
                            "Monitor", val)
2485
        line.set_apply_callback(apply_dmtf_frame,
2486
                                _mem.dtmf_settings.monitor)
2487
        dtmf_dec_settings.append(line)
2488

    
2489
        val = RadioSettingValueString(0, 16, memory2string(
2490
                                          _mem.dtmf_settings.stun),
2491
                                      False, CHARSET_DTMF_DIGITS)
2492
        line = RadioSetting("dtmf_settings.stun",
2493
                            "Stun", val)
2494
        line.set_apply_callback(apply_dmtf_frame,
2495
                                _mem.dtmf_settings.stun)
2496
        dtmf_dec_settings.append(line)
2497

    
2498
        val = RadioSettingValueString(0, 16, memory2string(
2499
                                          _mem.dtmf_settings.revive),
2500
                                      False, CHARSET_DTMF_DIGITS)
2501
        line = RadioSetting("dtmf_settings.revive",
2502
                            "Revive", val)
2503
        line.set_apply_callback(apply_dmtf_frame,
2504
                                _mem.dtmf_settings.revive)
2505
        dtmf_dec_settings.append(line)
2506

    
2507
        def apply_dmtf_listvalue(setting, obj):
2508
            LOG.debug("Setting value: " + str(setting.value) + " from list")
2509
            val = str(setting.value)
2510
            index = LIST_DTMF_SPECIAL_DIGITS.index(val)
2511
            val = LIST_DTMF_SPECIAL_VALUES[index]
2512
            obj.set_value(val)
2513

    
2514
        if _mem.dtmf_settings.groupcode not in LIST_DTMF_SPECIAL_VALUES:
2515
            val = 0x0B
2516
        else:
2517
            val = _mem.dtmf_settings.groupcode
2518
        idx = LIST_DTMF_SPECIAL_VALUES.index(val)
2519
        line = RadioSetting(
2520
            "dtmf_settings.groupcode",
2521
            "Group Code",
2522
            RadioSettingValueList(LIST_DTMF_SPECIAL_DIGITS,
2523
                                  LIST_DTMF_SPECIAL_DIGITS[idx]))
2524
        line.set_apply_callback(apply_dmtf_listvalue,
2525
                                _mem.dtmf_settings.groupcode)
2526
        dtmf_dec_settings.append(line)
2527

    
2528
        if _mem.dtmf_settings.spacecode not in LIST_DTMF_SPECIAL_VALUES:
2529
            val = 0x0C
2530
        else:
2531
            val = _mem.dtmf_settings.spacecode
2532
        idx = LIST_DTMF_SPECIAL_VALUES.index(val)
2533
        line = RadioSetting(
2534
            "dtmf_settings.spacecode",
2535
            "Space Code",
2536
            RadioSettingValueList(LIST_DTMF_SPECIAL_DIGITS,
2537
                                  LIST_DTMF_SPECIAL_DIGITS[idx]))
2538
        line.set_apply_callback(apply_dmtf_listvalue,
2539
                                _mem.dtmf_settings.spacecode)
2540
        dtmf_dec_settings.append(line)
2541

    
2542
        if self.COLOR_LCD:
2543
            if _mem.dtmf_settings.resettime > 0x63:
2544
                val = 0x4F
2545
            else:
2546
                val = _mem.dtmf_settings.resettime
2547
            line = RadioSetting(
2548
                "dtmf_settings.resettime",
2549
                "Reset time",
2550
                RadioSettingValueList(LIST_5TONE_RESET_COLOR,
2551
                                      LIST_5TONE_RESET_COLOR[
2552
                                          val]))
2553
            dtmf_dec_settings.append(line)
2554
        else:
2555
            line = RadioSetting(
2556
                "dtmf_settings.resettime",
2557
                "Reset time",
2558
                RadioSettingValueList(LIST_5TONE_RESET,
2559
                                      LIST_5TONE_RESET[
2560
                                          _mem.dtmf_settings.resettime]))
2561
            dtmf_dec_settings.append(line)
2562

    
2563
        if _mem.dtmf_settings.delayproctime > 0x27:
2564
            val = 0x04
2565
        else:
2566
            val = _mem.dtmf_settings.delayproctime
2567
        line = RadioSetting(
2568
            "dtmf_settings.delayproctime",
2569
            "Delay processing time",
2570
            RadioSettingValueList(LIST_DTMF_DELAY,
2571
                                  LIST_DTMF_DELAY[
2572
                                      val]))
2573
        dtmf_dec_settings.append(line)
2574

    
2575
        # 5 Tone Settings
2576
        stds_5tone = RadioSettingGroup("stds_5tone", "Standards")
2577
        codes_5tone = RadioSettingGroup("codes_5tone", "Codes")
2578

    
2579
        group_5tone = RadioSettingGroup("group_5tone", "5 Tone Settings")
2580
        group_5tone.append(stds_5tone)
2581
        group_5tone.append(codes_5tone)
2582

    
2583
        top.append(group_5tone)
2584

    
2585
        def apply_list_value(setting, obj):
2586
            options = setting.value.get_options()
2587
            obj.set_value(options.index(str(setting.value)))
2588

    
2589
        _5tone_standards = self._memobj._5tone_std_settings
2590
        i = 0
2591
        for standard in _5tone_standards:
2592
            std_5tone = RadioSettingGroup("std_5tone_" + str(i),
2593
                                          LIST_5TONE_STANDARDS[i])
2594
            stds_5tone.append(std_5tone)
2595

    
2596
            period = standard.period
2597
            if period == 255:
2598
                LOG.debug("Period for " + LIST_5TONE_STANDARDS[i] +
2599
                          " is not yet configured. Setting to 70ms.")
2600
                period = 5
2601

    
2602
            if period <= len(LIST_5TONE_STANDARD_PERIODS):
2603
                line = RadioSetting(
2604
                    "_5tone_std_settings_" + str(i) + "_period",
2605
                    "Period (ms)", RadioSettingValueList
2606
                    (LIST_5TONE_STANDARD_PERIODS,
2607
                     LIST_5TONE_STANDARD_PERIODS[period]))
2608
                line.set_apply_callback(apply_list_value, standard.period)
2609
                std_5tone.append(line)
2610
            else:
2611
                LOG.debug("Invalid value for 5tone period! Disabling.")
2612

    
2613
            group_tone = standard.group_tone
2614
            if group_tone == 255:
2615
                LOG.debug("Group-Tone for " + LIST_5TONE_STANDARDS[i] +
2616
                          " is not yet configured. Setting to A.")
2617
                group_tone = 10
2618

    
2619
            if group_tone <= len(LIST_5TONE_DIGITS):
2620
                line = RadioSetting(
2621
                    "_5tone_std_settings_" + str(i) + "_grouptone",
2622
                    "Group Tone",
2623
                    RadioSettingValueList(LIST_5TONE_DIGITS,
2624
                                          LIST_5TONE_DIGITS[
2625
                                              group_tone]))
2626
                line.set_apply_callback(apply_list_value,
2627
                                        standard.group_tone)
2628
                std_5tone.append(line)
2629
            else:
2630
                LOG.debug("Invalid value for 5tone digit! Disabling.")
2631

    
2632
            repeat_tone = standard.repeat_tone
2633
            if repeat_tone == 255:
2634
                LOG.debug("Repeat-Tone for " + LIST_5TONE_STANDARDS[i] +
2635
                          " is not yet configured. Setting to E.")
2636
                repeat_tone = 14
2637

    
2638
            if repeat_tone <= len(LIST_5TONE_DIGITS):
2639
                line = RadioSetting(
2640
                    "_5tone_std_settings_" + str(i) + "_repttone",
2641
                    "Repeat Tone",
2642
                    RadioSettingValueList(LIST_5TONE_DIGITS,
2643
                                          LIST_5TONE_DIGITS[
2644
                                              repeat_tone]))
2645
                line.set_apply_callback(apply_list_value,
2646
                                        standard.repeat_tone)
2647
                std_5tone.append(line)
2648
            else:
2649
                LOG.debug("Invalid value for 5tone digit! Disabling.")
2650
            i = i + 1
2651

    
2652
        def my_apply_5tonestdlist_value(setting, obj):
2653
            if LIST_5TONE_STANDARDS.index(str(setting.value)) == 15:
2654
                obj.set_value(0xFF)
2655
            else:
2656
                obj.set_value(LIST_5TONE_STANDARDS.
2657
                              index(str(setting.value)))
2658

    
2659
        def apply_5tone_frame(setting, obj):
2660
            LOG.debug("Setting 5 Tone: " + str(setting.value))
2661
            valstring = str(setting.value)
2662
            if len(valstring) == 0:
2663
                for i in range(0, 5):
2664
                    obj[i] = 255
2665
            else:
2666
                validFrame = True
2667
                for i in range(0, 5):
2668
                    currentChar = valstring[i].upper()
2669
                    if currentChar in LIST_5TONE_DIGITS:
2670
                        obj[i] = LIST_5TONE_DIGITS.index(currentChar)
2671
                    else:
2672
                        validFrame = False
2673
                        LOG.debug("invalid char: " + str(currentChar))
2674
                if not validFrame:
2675
                    LOG.debug("setting whole frame to FF")
2676
                    for i in range(0, 5):
2677
                        obj[i] = 255
2678

    
2679
        def validate_5tone_frame(value):
2680
            if (len(str(value)) != 5) and (len(str(value)) != 0):
2681
                msg = ("5 Tone must have 5 digits or 0 digits")
2682
                raise InvalidValueError(msg)
2683
            for digit in str(value):
2684
                if digit.upper() not in LIST_5TONE_DIGITS:
2685
                    msg = (str(digit) + " is not a valid digit for 5tones")
2686
                    raise InvalidValueError(msg)
2687
            return value
2688

    
2689
        def frame2string(frame):
2690
            frameString = ""
2691
            for digit in frame:
2692
                if digit != 255:
2693
                    frameString = frameString + LIST_5TONE_DIGITS[digit]
2694
            return frameString
2695

    
2696
        _5tone_codes = self._memobj._5tone_codes
2697
        i = 1
2698
        for code in _5tone_codes:
2699
            code_5tone = RadioSettingGroup("code_5tone_" + str(i),
2700
                                           "5 Tone code " + str(i))
2701
            codes_5tone.append(code_5tone)
2702
            if (code.standard == 255):
2703
                currentVal = 15
2704
            else:
2705
                currentVal = code.standard
2706
            line = RadioSetting("_5tone_code_" + str(i) + "_std",
2707
                                " Standard",
2708
                                RadioSettingValueList(LIST_5TONE_STANDARDS,
2709
                                                      LIST_5TONE_STANDARDS[
2710
                                                          currentVal]))
2711
            line.set_apply_callback(my_apply_5tonestdlist_value,
2712
                                    code.standard)
2713
            code_5tone.append(line)
2714

    
2715
            val = RadioSettingValueString(0, 6,
2716
                                          frame2string(code.frame1), False)
2717
            line = RadioSetting("_5tone_code_" + str(i) + "_frame1",
2718
                                " Frame 1", val)
2719
            val.set_validate_callback(validate_5tone_frame)
2720
            line.set_apply_callback(apply_5tone_frame, code.frame1)
2721
            code_5tone.append(line)
2722

    
2723
            val = RadioSettingValueString(0, 6,
2724
                                          frame2string(code.frame2), False)
2725
            line = RadioSetting("_5tone_code_" + str(i) + "_frame2",
2726
                                " Frame 2", val)
2727
            val.set_validate_callback(validate_5tone_frame)
2728
            line.set_apply_callback(apply_5tone_frame, code.frame2)
2729
            code_5tone.append(line)
2730

    
2731
            val = RadioSettingValueString(0, 6,
2732
                                          frame2string(code.frame3), False)
2733
            line = RadioSetting("_5tone_code_" + str(i) + "_frame3",
2734
                                " Frame 3", val)
2735
            val.set_validate_callback(validate_5tone_frame)
2736
            line.set_apply_callback(apply_5tone_frame, code.frame3)
2737
            code_5tone.append(line)
2738
            i = i + 1
2739

    
2740
        _5_tone_decode1 = RadioSetting(
2741
            "_5tone_settings._5tone_decode_call_frame1",
2742
            "5 Tone decode call Frame 1",
2743
            RadioSettingValueBoolean(
2744
                _mem._5tone_settings._5tone_decode_call_frame1))
2745
        group_5tone.append(_5_tone_decode1)
2746

    
2747
        _5_tone_decode2 = RadioSetting(
2748
            "_5tone_settings._5tone_decode_call_frame2",
2749
            "5 Tone decode call Frame 2",
2750
            RadioSettingValueBoolean(
2751
                _mem._5tone_settings._5tone_decode_call_frame2))
2752
        group_5tone.append(_5_tone_decode2)
2753

    
2754
        _5_tone_decode3 = RadioSetting(
2755
            "_5tone_settings._5tone_decode_call_frame3",
2756
            "5 Tone decode call Frame 3",
2757
            RadioSettingValueBoolean(
2758
                _mem._5tone_settings._5tone_decode_call_frame3))
2759
        group_5tone.append(_5_tone_decode3)
2760

    
2761
        _5_tone_decode_disp1 = RadioSetting(
2762
            "_5tone_settings._5tone_decode_disp_frame1",
2763
            "5 Tone decode disp Frame 1",
2764
            RadioSettingValueBoolean(
2765
                _mem._5tone_settings._5tone_decode_disp_frame1))
2766
        group_5tone.append(_5_tone_decode_disp1)
2767

    
2768
        _5_tone_decode_disp2 = RadioSetting(
2769
            "_5tone_settings._5tone_decode_disp_frame2",
2770
            "5 Tone decode disp Frame 2",
2771
            RadioSettingValueBoolean(
2772
                _mem._5tone_settings._5tone_decode_disp_frame2))
2773
        group_5tone.append(_5_tone_decode_disp2)
2774

    
2775
        _5_tone_decode_disp3 = RadioSetting(
2776
            "_5tone_settings._5tone_decode_disp_frame3",
2777
            "5 Tone decode disp Frame 3",
2778
            RadioSettingValueBoolean(
2779
                _mem._5tone_settings._5tone_decode_disp_frame3))
2780
        group_5tone.append(_5_tone_decode_disp3)
2781

    
2782
        decode_standard = _mem._5tone_settings.decode_standard
2783
        if decode_standard == 255:
2784
            decode_standard = 0
2785
        if decode_standard <= len(LIST_5TONE_STANDARDS_without_none):
2786
            line = RadioSetting("_5tone_settings.decode_standard",
2787
                                "5 Tone-decode Standard",
2788
                                RadioSettingValueList(
2789
                                    LIST_5TONE_STANDARDS_without_none,
2790
                                    LIST_5TONE_STANDARDS_without_none[
2791
                                        decode_standard]))
2792
            group_5tone.append(line)
2793
        else:
2794
            LOG.debug("Invalid decode std...")
2795

    
2796
        _5tone_delay1 = _mem._5tone_settings._5tone_delay1
2797
        if _5tone_delay1 == 255:
2798
            _5tone_delay1 = 20
2799

    
2800
        if _5tone_delay1 <= len(LIST_5TONE_DELAY):
2801
            list = RadioSettingValueList(LIST_5TONE_DELAY,
2802
                                         LIST_5TONE_DELAY[
2803
                                             _5tone_delay1])
2804
            line = RadioSetting("_5tone_settings._5tone_delay1",
2805
                                "5 Tone Delay Frame 1", list)
2806
            group_5tone.append(line)
2807
        else:
2808
            LOG.debug("Invalid value for 5tone delay (frame1) ! Disabling.")
2809

    
2810
        _5tone_delay2 = _mem._5tone_settings._5tone_delay2
2811
        if _5tone_delay2 == 255:
2812
            _5tone_delay2 = 20
2813
            LOG.debug("5 Tone delay unconfigured! Resetting to 200ms.")
2814

    
2815
        if _5tone_delay2 <= len(LIST_5TONE_DELAY):
2816
            list = RadioSettingValueList(LIST_5TONE_DELAY,
2817
                                         LIST_5TONE_DELAY[
2818
                                             _5tone_delay2])
2819
            line = RadioSetting("_5tone_settings._5tone_delay2",
2820
                                "5 Tone Delay Frame 2", list)
2821
            group_5tone.append(line)
2822
        else:
2823
            LOG.debug("Invalid value for 5tone delay (frame2)! Disabling.")
2824

    
2825
        _5tone_delay3 = _mem._5tone_settings._5tone_delay3
2826
        if _5tone_delay3 == 255:
2827
            _5tone_delay3 = 20
2828
            LOG.debug("5 Tone delay unconfigured! Resetting to 200ms.")
2829

    
2830
        if _5tone_delay3 <= len(LIST_5TONE_DELAY):
2831
            list = RadioSettingValueList(LIST_5TONE_DELAY,
2832
                                         LIST_5TONE_DELAY[
2833
                                             _5tone_delay3])
2834
            line = RadioSetting("_5tone_settings._5tone_delay3",
2835
                                "5 Tone Delay Frame 3", list)
2836
            group_5tone.append(line)
2837
        else:
2838
            LOG.debug("Invalid value for 5tone delay (frame3)! Disabling.")
2839

    
2840
        ext_length = _mem._5tone_settings._5tone_first_digit_ext_length
2841
        if ext_length == 255:
2842
            ext_length = 0
2843
            LOG.debug("1st Tone ext lenght unconfigured! Resetting to 0")
2844

    
2845
        if ext_length <= len(LIST_5TONE_DELAY):
2846
            list = RadioSettingValueList(
2847
                LIST_5TONE_DELAY,
2848
                LIST_5TONE_DELAY[
2849
                    ext_length])
2850
            line = RadioSetting(
2851
                "_5tone_settings._5tone_first_digit_ext_length",
2852
                "First digit extend length", list)
2853
            group_5tone.append(line)
2854
        else:
2855
            LOG.debug("Invalid value for 5tone ext length! Disabling.")
2856

    
2857
        decode_reset_time = _mem._5tone_settings.decode_reset_time
2858
        if decode_reset_time == 255:
2859
            decode_reset_time = 59
2860
            LOG.debug("Decode reset time unconfigured. resetting.")
2861
        if decode_reset_time <= len(LIST_5TONE_RESET):
2862
            list = RadioSettingValueList(
2863
                LIST_5TONE_RESET,
2864
                LIST_5TONE_RESET[
2865
                    decode_reset_time])
2866
            line = RadioSetting("_5tone_settings.decode_reset_time",
2867
                                "Decode reset time", list)
2868
            group_5tone.append(line)
2869
        else:
2870
            LOG.debug("Invalid value decode reset time! Disabling.")
2871

    
2872
        # 2 Tone
2873
        encode_2tone = RadioSettingGroup("encode_2tone", "2 Tone Encode")
2874
        decode_2tone = RadioSettingGroup("decode_2tone", "2 Code Decode")
2875

    
2876
        top.append(encode_2tone)
2877
        top.append(decode_2tone)
2878

    
2879
        duration_1st_tone = self._memobj._2tone.duration_1st_tone
2880
        if duration_1st_tone == 255:
2881
            LOG.debug("Duration of first 2 Tone digit is not yet " +
2882
                      "configured. Setting to 600ms")
2883
            duration_1st_tone = 60
2884

    
2885
        if duration_1st_tone <= len(LIST_5TONE_DELAY):
2886
            line = RadioSetting("_2tone.duration_1st_tone",
2887
                                "Duration 1st Tone",
2888
                                RadioSettingValueList(LIST_5TONE_DELAY,
2889
                                                      LIST_5TONE_DELAY[
2890
                                                          duration_1st_tone]))
2891
            encode_2tone.append(line)
2892

    
2893
        duration_2nd_tone = self._memobj._2tone.duration_2nd_tone
2894
        if duration_2nd_tone == 255:
2895
            LOG.debug("Duration of second 2 Tone digit is not yet " +
2896
                      "configured. Setting to 600ms")
2897
            duration_2nd_tone = 60
2898

    
2899
        if duration_2nd_tone <= len(LIST_5TONE_DELAY):
2900
            line = RadioSetting("_2tone.duration_2nd_tone",
2901
                                "Duration 2nd Tone",
2902
                                RadioSettingValueList(LIST_5TONE_DELAY,
2903
                                                      LIST_5TONE_DELAY[
2904
                                                          duration_2nd_tone]))
2905
            encode_2tone.append(line)
2906

    
2907
        duration_gap = self._memobj._2tone.duration_gap
2908
        if duration_gap == 255:
2909
            LOG.debug("Duration of gap is not yet " +
2910
                      "configured. Setting to 300ms")
2911
            duration_gap = 30
2912

    
2913
        if duration_gap <= len(LIST_5TONE_DELAY):
2914
            line = RadioSetting("_2tone.duration_gap", "Duration of gap",
2915
                                RadioSettingValueList(LIST_5TONE_DELAY,
2916
                                                      LIST_5TONE_DELAY[
2917
                                                          duration_gap]))
2918
            encode_2tone.append(line)
2919

    
2920
        def _2tone_validate(value):
2921
            if value == 0:
2922
                return 65535
2923
            if value == 65535:
2924
                return value
2925
            if not (300 <= value and value <= 3000):
2926
                msg = ("2 Tone Frequency: Must be between 300 and 3000 Hz")
2927
                raise InvalidValueError(msg)
2928
            return value
2929

    
2930
        def apply_2tone_freq(setting, obj):
2931
            val = int(setting.value)
2932
            if (val == 0) or (val == 65535):
2933
                obj.set_value(65535)
2934
            else:
2935
                obj.set_value(val)
2936

    
2937
        i = 1
2938
        for code in self._memobj._2tone._2tone_encode:
2939
            code_2tone = RadioSettingGroup("code_2tone_" + str(i),
2940
                                           "Encode Code " + str(i))
2941
            encode_2tone.append(code_2tone)
2942

    
2943
            tmp = code.freq1
2944
            if tmp == 65535:
2945
                tmp = 0
2946
            val1 = RadioSettingValueInteger(0, 65535, tmp)
2947
            freq1 = RadioSetting("2tone_code_" + str(i) + "_freq1",
2948
                                 "Frequency 1", val1)
2949
            val1.set_validate_callback(_2tone_validate)
2950
            freq1.set_apply_callback(apply_2tone_freq, code.freq1)
2951
            code_2tone.append(freq1)
2952

    
2953
            tmp = code.freq2
2954
            if tmp == 65535:
2955
                tmp = 0
2956
            val2 = RadioSettingValueInteger(0, 65535, tmp)
2957
            freq2 = RadioSetting("2tone_code_" + str(i) + "_freq2",
2958
                                 "Frequency 2", val2)
2959
            val2.set_validate_callback(_2tone_validate)
2960
            freq2.set_apply_callback(apply_2tone_freq, code.freq2)
2961
            code_2tone.append(freq2)
2962

    
2963
            i = i + 1
2964

    
2965
        decode_reset_time = _mem._2tone.reset_time
2966
        if decode_reset_time == 255:
2967
            decode_reset_time = 59
2968
            LOG.debug("Decode reset time unconfigured. resetting.")
2969
        if decode_reset_time <= len(LIST_5TONE_RESET):
2970
            list = RadioSettingValueList(
2971
                LIST_5TONE_RESET,
2972
                LIST_5TONE_RESET[
2973
                    decode_reset_time])
2974
            line = RadioSetting("_2tone.reset_time",
2975
                                "Decode reset time", list)
2976
            decode_2tone.append(line)
2977
        else:
2978
            LOG.debug("Invalid value decode reset time! Disabling.")
2979

    
2980
        def apply_2tone_freq_pair(setting, obj):
2981
            val = int(setting.value)
2982
            derived_val = 65535
2983
            frqname = str(setting._name[-5:])
2984
            derivedname = "derived_from_" + frqname
2985

    
2986
            if (val == 0):
2987
                val = 65535
2988
                derived_val = 65535
2989
            else:
2990
                derived_val = int(round(2304000.0/val))
2991

    
2992
            obj[frqname].set_value(val)
2993
            obj[derivedname].set_value(derived_val)
2994

    
2995
            LOG.debug("Apply " + frqname + ": " + str(val) + " | " +
2996
                      derivedname + ": " + str(derived_val))
2997

    
2998
        i = 1
2999
        for decode_code in self._memobj._2tone._2tone_decode:
3000
            _2tone_dec_code = RadioSettingGroup("code_2tone_" + str(i),
3001
                                                "Decode Code " + str(i))
3002
            decode_2tone.append(_2tone_dec_code)
3003

    
3004
            j = 1
3005
            for dec in decode_code.decs:
3006
                val = dec.dec
3007
                if val == 255:
3008
                    LOG.debug("Dec for Code " + str(i) + " Dec " + str(j) +
3009
                              " is not yet configured. Setting to 0.")
3010
                    val = 0
3011

    
3012
                if val <= len(LIST_2TONE_DEC):
3013
                    line = RadioSetting(
3014
                        "_2tone_dec_settings_" + str(i) + "_dec_" + str(j),
3015
                        "Dec " + str(j), RadioSettingValueList
3016
                        (LIST_2TONE_DEC,
3017
                         LIST_2TONE_DEC[val]))
3018
                    line.set_apply_callback(apply_list_value, dec.dec)
3019
                    _2tone_dec_code.append(line)
3020
                else:
3021
                    LOG.debug("Invalid value for 2tone dec! Disabling.")
3022

    
3023
                val = dec.response
3024
                if val == 255:
3025
                    LOG.debug("Response for Code " + str(i) + " Dec " +
3026
                              str(j) + " is not yet configured. Setting to 0.")
3027
                    val = 0
3028

    
3029
                if val <= len(LIST_2TONE_RESPONSE):
3030
                    line = RadioSetting(
3031
                        "_2tone_dec_settings_" + str(i) + "_resp_" + str(j),
3032
                        "Response " + str(j), RadioSettingValueList
3033
                        (LIST_2TONE_RESPONSE,
3034
                         LIST_2TONE_RESPONSE[val]))
3035
                    line.set_apply_callback(apply_list_value, dec.response)
3036
                    _2tone_dec_code.append(line)
3037
                else:
3038
                    LOG.debug("Invalid value for 2tone response! Disabling.")
3039

    
3040
                val = dec.alert
3041
                if val == 255:
3042
                    LOG.debug("Alert for Code " + str(i) + " Dec " + str(j) +
3043
                              " is not yet configured. Setting to 0.")
3044
                    val = 0
3045

    
3046
                if val <= len(PTTIDCODE_LIST):
3047
                    line = RadioSetting(
3048
                        "_2tone_dec_settings_" + str(i) + "_alert_" + str(j),
3049
                        "Alert " + str(j), RadioSettingValueList
3050
                        (PTTIDCODE_LIST,
3051
                         PTTIDCODE_LIST[val]))
3052
                    line.set_apply_callback(apply_list_value, dec.alert)
3053
                    _2tone_dec_code.append(line)
3054
                else:
3055
                    LOG.debug("Invalid value for 2tone alert! Disabling.")
3056
                j = j + 1
3057

    
3058
            freq = self._memobj._2tone.freqs[i-1]
3059
            for char in ['A', 'B', 'C', 'D']:
3060
                setting_name = "freq" + str(char)
3061

    
3062
                tmp = freq[setting_name]
3063
                if tmp == 65535:
3064
                    tmp = 0
3065
                if tmp != 0:
3066
                    expected = int(round(2304000.0/tmp))
3067
                    from_mem = freq["derived_from_" + setting_name]
3068
                    if expected != from_mem:
3069
                        LOG.error("Expected " + str(expected) +
3070
                                  " but read " + str(from_mem) +
3071
                                  ". Disabling 2Tone Decode Freqs!")
3072
                        break
3073
                val = RadioSettingValueInteger(0, 65535, tmp)
3074
                frq = RadioSetting("2tone_dec_" + str(i) + "_freq" + str(char),
3075
                                   ("Decode Frequency " + str(char)), val)
3076
                val.set_validate_callback(_2tone_validate)
3077
                frq.set_apply_callback(apply_2tone_freq_pair, freq)
3078
                _2tone_dec_code.append(frq)
3079

    
3080
            i = i + 1
3081

    
3082
        return top
3083

    
3084
    def set_settings(self, settings):
3085
        _settings = self._memobj.settings
3086
        for element in settings:
3087
            if not isinstance(element, RadioSetting):
3088
                if element.get_name() == "fm_preset":
3089
                    self._set_fm_preset(element)
3090
                else:
3091
                    self.set_settings(element)
3092
                    continue
3093
            else:
3094
                try:
3095
                    name = element.get_name()
3096
                    if "." in name:
3097
                        bits = name.split(".")
3098
                        obj = self._memobj
3099
                        for bit in bits[:-1]:
3100
                            if "/" in bit:
3101
                                bit, index = bit.split("/", 1)
3102
                                index = int(index)
3103
                                obj = getattr(obj, bit)[index]
3104
                            else:
3105
                                obj = getattr(obj, bit)
3106
                        setting = bits[-1]
3107
                    else:
3108
                        obj = _settings
3109
                        setting = element.get_name()
3110

    
3111
                    if element.has_apply_callback():
3112
                        LOG.debug("Using apply callback")
3113
                        element.run_apply_callback()
3114
                    elif element.value.get_mutable():
3115
                        LOG.debug("Setting %s = %s" % (setting, element.value))
3116
                        setattr(obj, setting, element.value)
3117
                except Exception, e:
3118
                    LOG.debug(element.get_name())
3119
                    raise
3120

    
3121
    @classmethod
3122
    def match_model(cls, filedata, filename):
3123
        match_size = False
3124
        match_model = False
3125

    
3126
        # testing the file data size
3127
        if len(filedata) == MEM_SIZE:
3128
            match_size = True
3129

    
3130
        # testing the firmware model fingerprint
3131
        match_model = model_match(cls, filedata)
3132

    
3133
        if match_size and match_model:
3134
            return True
3135
        else:
3136
            return False
3137

    
3138

    
3139
MEM_FORMAT = """
3140
#seekto 0x0000;
3141
struct {
3142
  lbcd rxfreq[4];
3143
  lbcd txfreq[4];
3144
  ul16 rxtone;
3145
  ul16 txtone;
3146
  u8 unknown0:4,
3147
     scode:4;
3148
  u8 unknown1:2,
3149
     spmute:2,
3150
     unknown2:2,
3151
     optsig:2;
3152
  u8 unknown3:3,
3153
     scramble:1,
3154
     unknown4:3,
3155
     power:1;
3156
  u8 unknown5:1,
3157
     wide:1,
3158
     unknown6:2,
3159
     bcl:1,
3160
     add:1,
3161
     pttid:2;
3162
} memory[200];
3163

    
3164
#seekto 0x0E00;
3165
struct {
3166
  u8 tdr;
3167
  u8 unknown1;
3168
  u8 sql;
3169
  u8 unknown2[2];
3170
  u8 tot;
3171
  u8 apo;           // BTech radios use this as the Auto Power Off time
3172
                    // other radios use this as pre-Time Out Alert
3173
  u8 unknown3;
3174
  u8 abr;
3175
  u8 beep;
3176
  u8 unknown4[4];
3177
  u8 dtmfst;
3178
  u8 unknown5[2];
3179
  u8 prisc;
3180
  u8 prich;
3181
  u8 screv;
3182
  u8 unknown6[2];
3183
  u8 pttid;
3184
  u8 pttlt;
3185
  u8 unknown7;
3186
  u8 emctp;
3187
  u8 emcch;
3188
  u8 ringt;
3189
  u8 unknown8;
3190
  u8 camdf;
3191
  u8 cbmdf;
3192
  u8 sync;          // BTech radios use this as the display sync setting
3193
                    // other radios use this as the auto keypad lock setting
3194
  u8 ponmsg;
3195
  u8 wtled;
3196
  u8 rxled;
3197
  u8 txled;
3198
  u8 unknown9[5];
3199
  u8 anil;
3200
  u8 reps;
3201
  u8 repm;
3202
  u8 tdrab;
3203
  u8 ste;
3204
  u8 rpste;
3205
  u8 rptdl;
3206
  u8 mgain;
3207
  u8 dtmfg;
3208
} settings;
3209

    
3210
#seekto 0x0E80;
3211
struct {
3212
  u8 unknown1;
3213
  u8 vfomr;
3214
  u8 keylock;
3215
  u8 unknown2;
3216
  u8 unknown3:4,
3217
     vfomren:1,
3218
     unknown4:1,
3219
     reseten:1,
3220
     menuen:1;
3221
  u8 unknown5[11];
3222
  u8 dispab;
3223
  u8 mrcha;
3224
  u8 mrchb;
3225
  u8 menu;
3226
} settings2;
3227

    
3228
#seekto 0x0EC0;
3229
struct {
3230
  char line1[6];
3231
  char line2[6];
3232
} poweron_msg;
3233

    
3234
struct settings_vfo {
3235
  u8 freq[8];
3236
  u8 offset[6];
3237
  u8 unknown2[2];
3238
  ul16 rxtone;
3239
  ul16 txtone;
3240
  u8 scode;
3241
  u8 spmute;
3242
  u8 optsig;
3243
  u8 scramble;
3244
  u8 wide;
3245
  u8 power;
3246
  u8 shiftd;
3247
  u8 step;
3248
  u8 unknown3[4];
3249
};
3250

    
3251
#seekto 0x0F00;
3252
struct {
3253
  struct settings_vfo a;
3254
  struct settings_vfo b;
3255
} vfo;
3256

    
3257
#seekto 0x1000;
3258
struct {
3259
  char name[6];
3260
  u8 unknown1[10];
3261
} names[200];
3262

    
3263
#seekto 0x2400;
3264
struct {
3265
  u8 period; // one out of LIST_5TONE_STANDARD_PERIODS
3266
  u8 group_tone;
3267
  u8 repeat_tone;
3268
  u8 unused[13];
3269
} _5tone_std_settings[15];
3270

    
3271
#seekto 0x2500;
3272
struct {
3273
  u8 frame1[5];
3274
  u8 frame2[5];
3275
  u8 frame3[5];
3276
  u8 standard;   // one out of LIST_5TONE_STANDARDS
3277
} _5tone_codes[15];
3278

    
3279
#seekto 0x25F0;
3280
struct {
3281
  u8 _5tone_delay1; // * 10ms
3282
  u8 _5tone_delay2; // * 10ms
3283
  u8 _5tone_delay3; // * 10ms
3284
  u8 _5tone_first_digit_ext_length;
3285
  u8 unknown1;
3286
  u8 unknown2;
3287
  u8 unknown3;
3288
  u8 unknown4;
3289
  u8 decode_standard;
3290
  u8 unknown5:5,
3291
     _5tone_decode_call_frame3:1,
3292
     _5tone_decode_call_frame2:1,
3293
     _5tone_decode_call_frame1:1;
3294
  u8 unknown6:5,
3295
     _5tone_decode_disp_frame3:1,
3296
     _5tone_decode_disp_frame2:1,
3297
     _5tone_decode_disp_frame1:1;
3298
  u8 decode_reset_time; // * 100 + 100ms
3299
} _5tone_settings;
3300

    
3301
#seekto 0x2900;
3302
struct {
3303
  u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B
3304
} dtmf_codes[15];
3305

    
3306
#seekto 0x29F0;
3307
struct {
3308
  u8 dtmfspeed_on;  //list with 50..2000ms in steps of 10
3309
  u8 dtmfspeed_off; //list with 50..2000ms in steps of 10
3310
  u8 unknown0[14];
3311
  u8 inspection[16];
3312
  u8 monitor[16];
3313
  u8 alarmcode[16];
3314
  u8 stun[16];
3315
  u8 kill[16];
3316
  u8 revive[16];
3317
  u8 unknown1[16];
3318
  u8 unknown2[16];
3319
  u8 unknown3[16];
3320
  u8 unknown4[16];
3321
  u8 unknown5[16];
3322
  u8 unknown6[16];
3323
  u8 unknown7[16];
3324
  u8 masterid[16];
3325
  u8 viceid[16];
3326
  u8 unused01:7,
3327
     mastervice:1;
3328
  u8 unused02:3,
3329
     mrevive:1,
3330
     mkill:1,
3331
     mstun:1,
3332
     mmonitor:1,
3333
     minspection:1;
3334
  u8 unused03:3,
3335
     vrevive:1,
3336
     vkill:1,
3337
     vstun:1,
3338
     vmonitor:1,
3339
     vinspection:1;
3340
  u8 unused04:6,
3341
     txdisable:1,
3342
     rxdisable:1;
3343
  u8 groupcode;
3344
  u8 spacecode;
3345
  u8 delayproctime; // * 100 + 100ms
3346
  u8 resettime;     // * 100 + 100ms
3347
} dtmf_settings;
3348

    
3349
#seekto 0x2D00;
3350
struct {
3351
  struct {
3352
    ul16 freq1;
3353
    u8 unused01[6];
3354
    ul16 freq2;
3355
    u8 unused02[6];
3356
  } _2tone_encode[15];
3357
  u8 duration_1st_tone; // *10ms
3358
  u8 duration_2nd_tone; // *10ms
3359
  u8 duration_gap;      // *10ms
3360
  u8 unused03[13];
3361
  struct {
3362
    struct {
3363
      u8 dec;      // one out of LIST_2TONE_DEC
3364
      u8 response; // one out of LIST_2TONE_RESPONSE
3365
      u8 alert;    // 1-16
3366
    } decs[4];
3367
    u8 unused04[4];
3368
  } _2tone_decode[15];
3369
  u8 unused05[16];
3370

    
3371
  struct {
3372
    ul16 freqA;
3373
    ul16 freqB;
3374
    ul16 freqC;
3375
    ul16 freqD;
3376
    // unknown what those values mean, but they are
3377
    // derived from configured frequencies
3378
    ul16 derived_from_freqA; // 2304000/freqA
3379
    ul16 derived_from_freqB; // 2304000/freqB
3380
    ul16 derived_from_freqC; // 2304000/freqC
3381
    ul16 derived_from_freqD; // 2304000/freqD
3382
  }freqs[15];
3383
  u8 reset_time;  // * 100 + 100ms - 100-8000ms
3384
} _2tone;
3385

    
3386
#seekto 0x3000;
3387
struct {
3388
  u8 freq[8];
3389
  char broadcast_station_name[6];
3390
  u8 unknown[2];
3391
} fm_radio_preset[16];
3392

    
3393
#seekto 0x3C90;
3394
struct {
3395
  u8 vhf_low[3];
3396
  u8 vhf_high[3];
3397
  u8 uhf_low[3];
3398
  u8 uhf_high[3];
3399
} ranges;
3400

    
3401
// the UV-2501+220 & KT8900R has different zones for storing ranges
3402

    
3403
#seekto 0x3CD0;
3404
struct {
3405
  u8 vhf_low[3];
3406
  u8 vhf_high[3];
3407
  u8 unknown1[4];
3408
  u8 unknown2[6];
3409
  u8 vhf2_low[3];
3410
  u8 vhf2_high[3];
3411
  u8 unknown3[4];
3412
  u8 unknown4[6];
3413
  u8 uhf_low[3];
3414
  u8 uhf_high[3];
3415
} ranges220;
3416

    
3417
#seekto 0x3F70;
3418
struct {
3419
  char fp[6];
3420
} fingerprint;
3421

    
3422
"""
3423

    
3424

    
3425
class BTech(BTechMobileCommon):
3426
    """BTECH's UV-5001 and alike radios"""
3427
    BANDS = 2
3428
    COLOR_LCD = False
3429
    NAME_LENGTH = 6
3430

    
3431
    def set_options(self):
3432
        """This is to read the options from the image and set it in the
3433
        environment, for now just the limits of the freqs in the VHF/UHF
3434
        ranges"""
3435

    
3436
        # setting the correct ranges for each radio type
3437
        if self.MODEL in ["UV-2501+220", "KT8900R"]:
3438
            # the model 2501+220 has a segment in 220
3439
            # and a different position in the memmap
3440
            # also the QYT KT8900R
3441
            ranges = self._memobj.ranges220
3442
        else:
3443
            ranges = self._memobj.ranges
3444

    
3445
        # the normal dual bands
3446
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
3447
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
3448

    
3449
        # DEBUG
3450
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
3451
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
3452

    
3453
        # 220Mhz radios case
3454
        if self.MODEL in ["UV-2501+220", "KT8900R"]:
3455
            vhf2 = _decode_ranges(ranges.vhf2_low, ranges.vhf2_high)
3456
            LOG.info("Radio ranges: VHF(220) %d to %d" % vhf2)
3457
            self._220_range = vhf2
3458

    
3459
        # set the class with the real data
3460
        self._vhf_range = vhf
3461
        self._uhf_range = uhf
3462

    
3463
    def process_mmap(self):
3464
        """Process the mem map into the mem object"""
3465

    
3466
        # Get it
3467
        self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)
3468

    
3469
        # load specific parameters from the radio image
3470
        self.set_options()
3471

    
3472

    
3473
# Declaring Aliases (Clones of the real radios)
3474
class JT2705M(chirp_common.Alias):
3475
    VENDOR = "Jetstream"
3476
    MODEL = "JT2705M"
3477

    
3478

    
3479
class JT6188Mini(chirp_common.Alias):
3480
    VENDOR = "Juentai"
3481
    MODEL = "JT-6188 Mini"
3482

    
3483

    
3484
class JT6188Plus(chirp_common.Alias):
3485
    VENDOR = "Juentai"
3486
    MODEL = "JT-6188 Plus"
3487

    
3488

    
3489
class SSGT890(chirp_common.Alias):
3490
    VENDOR = "Sainsonic"
3491
    MODEL = "GT-890"
3492

    
3493

    
3494
class ZastoneMP300(chirp_common.Alias):
3495
    VENDOR = "Zastone"
3496
    MODEL = "MP-300"
3497

    
3498

    
3499
# real radios
3500
@directory.register
3501
class UV2501(BTech):
3502
    """Baofeng Tech UV2501"""
3503
    MODEL = "UV-2501"
3504
    _fileid = [UV2501G3_fp,
3505
               UV2501G2_fp,
3506
               UV2501pp2_fp,
3507
               UV2501pp_fp]
3508

    
3509

    
3510
@directory.register
3511
class UV2501_220(BTech):
3512
    """Baofeng Tech UV2501+220"""
3513
    MODEL = "UV-2501+220"
3514
    BANDS = 3
3515
    _magic = MSTRING_220
3516
    _id2 = [UV2501_220pp_id, ]
3517
    _fileid = [UV2501_220G3_fp,
3518
               UV2501_220G2_fp,
3519
               UV2501_220_fp,
3520
               UV2501_220pp_fp]
3521

    
3522

    
3523
@directory.register
3524
class UV5001(BTech):
3525
    """Baofeng Tech UV5001"""
3526
    MODEL = "UV-5001"
3527
    _fileid = [UV5001G3_fp,
3528
               UV5001G22_fp,
3529
               UV5001G2_fp,
3530
               UV5001alpha_fp,
3531
               UV5001pp_fp]
3532
    _power_levels = [chirp_common.PowerLevel("High", watts=50),
3533
                     chirp_common.PowerLevel("Low", watts=10)]
3534

    
3535

    
3536
@directory.register
3537
class MINI8900(BTech):
3538
    """WACCOM MINI-8900"""
3539
    VENDOR = "WACCOM"
3540
    MODEL = "MINI-8900"
3541
    _magic = MSTRING_MINI8900
3542
    _fileid = [MINI8900_fp, ]
3543
    # Clones
3544
    ALIASES = [JT6188Plus, ]
3545

    
3546

    
3547
@directory.register
3548
class KTUV980(BTech):
3549
    """QYT KT-UV980"""
3550
    VENDOR = "QYT"
3551
    MODEL = "KT-UV980"
3552
    _vhf_range = (136000000, 175000000)
3553
    _uhf_range = (400000000, 481000000)
3554
    _magic = MSTRING_MINI8900
3555
    _fileid = [KTUV980_fp, ]
3556
    # Clones
3557
    ALIASES = [JT2705M, ]
3558

    
3559
# Please note that there is a version of this radios that is a clone of the
3560
# Waccom Mini8900, maybe an early version?
3561

    
3562

    
3563
class OTGRadioV1(chirp_common.Alias):
3564
    VENDOR = 'OTGSTUFF'
3565
    MODEL = 'OTG Radio v1'
3566

    
3567

    
3568
@directory.register
3569
class KT9800(BTech):
3570
    """QYT KT8900"""
3571
    VENDOR = "QYT"
3572
    MODEL = "KT8900"
3573
    _vhf_range = (136000000, 175000000)
3574
    _uhf_range = (400000000, 481000000)
3575
    _magic = MSTRING_KT8900
3576
    _fileid = [KT8900_fp,
3577
               KT8900_fp1,
3578
               KT8900_fp2,
3579
               KT8900_fp3,
3580
               KT8900_fp4,
3581
               KT8900_fp5,
3582
               KT8900_fp6,
3583
               KT8900_fp7]
3584
    _id2 = [KT8900_id, KT8900_id2]
3585
    # Clones
3586
    ALIASES = [JT6188Mini, SSGT890, ZastoneMP300]
3587

    
3588

    
3589
@directory.register
3590
class KT9800R(BTech):
3591
    """QYT KT8900R"""
3592
    VENDOR = "QYT"
3593
    MODEL = "KT8900R"
3594
    BANDS = 3
3595
    _vhf_range = (136000000, 175000000)
3596
    _220_range = (240000000, 271000000)
3597
    _uhf_range = (400000000, 481000000)
3598
    _magic = MSTRING_KT8900R
3599
    _fileid = [KT8900R_fp,
3600
               KT8900R_fp1,
3601
               KT8900R_fp2,
3602
               KT8900R_fp3,
3603
               KT8900R_fp4,
3604
               KT8900R_fp5]
3605
    _id2 = [KT8900R_id, KT8900R_id2]
3606

    
3607

    
3608
@directory.register
3609
class LT588UV(BTech):
3610
    """LUITON LT-588UV"""
3611
    VENDOR = "LUITON"
3612
    MODEL = "LT-588UV"
3613
    _vhf_range = (136000000, 175000000)
3614
    _uhf_range = (400000000, 481000000)
3615
    _magic = MSTRING_KT8900
3616
    _fileid = [LT588UV_fp,
3617
               LT588UV_fp1]
3618
    _power_levels = [chirp_common.PowerLevel("High", watts=60),
3619
                     chirp_common.PowerLevel("Low", watts=10)]
3620

    
3621

    
3622
COLOR_MEM_FORMAT = """
3623
#seekto 0x0000;
3624
struct {
3625
  lbcd rxfreq[4];
3626
  lbcd txfreq[4];
3627
  ul16 rxtone;
3628
  ul16 txtone;
3629
  u8 unknown0:4,
3630
     scode:4;
3631
  u8 unknown1:2,
3632
     spmute:2,
3633
     unknown2:2,
3634
     optsig:2;
3635
  u8 unknown3:3,
3636
     scramble:1,
3637
     unknown4:2,
3638
     power:2;
3639
  u8 unknown5:1,
3640
     wide:1,
3641
     unknown6:2,
3642
     bcl:1,
3643
     add:1,
3644
     pttid:2;
3645
} memory[200];
3646

    
3647
#seekto 0x0E00;
3648
struct {
3649
  u8 tmr;
3650
  u8 unknown1;
3651
  u8 sql;
3652
  u8 unknown2;
3653
  u8 mgain2;
3654
  u8 tot;
3655
  u8 apo;
3656
  u8 unknown3;
3657
  u8 abr;
3658
  u8 beep;
3659
  u8 unknown4[4];
3660
  u8 dtmfst;
3661
  u8 unknown5[2];
3662
  u8 screv;
3663
  u8 unknown6[2];
3664
  u8 pttid;
3665
  u8 pttlt;
3666
  u8 unknown7;
3667
  u8 emctp;
3668
  u8 emcch;
3669
  u8 sigbp;
3670
  u8 unknown8;
3671
  u8 camdf;
3672
  u8 cbmdf;
3673
  u8 ccmdf;
3674
  u8 cdmdf;
3675
  u8 langua;
3676
  u8 sync;          // BTech radios use this as the display sync
3677
                    // setting, other radios use this as the auto
3678
                    // keypad lock setting
3679
  u8 mainfc;
3680
  u8 mainbc;
3681
  u8 menufc;
3682
  u8 menubc;
3683
  u8 stafc;
3684
  u8 stabc;
3685
  u8 sigfc;
3686
  u8 sigbc;
3687
  u8 rxfc;
3688
  u8 txfc;
3689
  u8 txdisp;
3690
  u8 unknown9[5];
3691
  u8 anil;
3692
  u8 reps;
3693
  u8 repm;
3694
  u8 tmrmr;
3695
  u8 ste;
3696
  u8 rpste;
3697
  u8 rptdl;
3698
  u8 dtmfg;
3699
  u8 mgain;         // used by db25-g for ponyey
3700
  u8 skiptx;
3701
  u8 scmode;
3702
} settings;
3703

    
3704
#seekto 0x0E80;
3705
struct {
3706
  u8 unknown1;
3707
  u8 vfomr;
3708
  u8 keylock;
3709
  u8 unknown2;
3710
  u8 unknown3:4,
3711
     vfomren:1,
3712
     unknown4:1,
3713
     reseten:1,
3714
     menuen:1;
3715
  u8 unknown5[11];
3716
  u8 dispab;
3717
  u8 unknown6[2];
3718
  u8 menu;
3719
  u8 unknown7[7];
3720
  u8 vfomra;
3721
  u8 vfomrb;
3722
  u8 vfomrc;
3723
  u8 vfomrd;
3724
  u8 mrcha;
3725
  u8 mrchb;
3726
  u8 mrchc;
3727
  u8 mrchd;
3728
} settings2;
3729

    
3730
struct settings_vfo {
3731
  u8 freq[8];
3732
  u8 offset[6];
3733
  u8 unknown2[2];
3734
  ul16 rxtone;
3735
  ul16 txtone;
3736
  u8 scode;
3737
  u8 spmute;
3738
  u8 optsig;
3739
  u8 scramble;
3740
  u8 wide;
3741
  u8 power;
3742
  u8 shiftd;
3743
  u8 step;
3744
  u8 unknown3[4];
3745
};
3746

    
3747
#seekto 0x0F00;
3748
struct {
3749
  struct settings_vfo a;
3750
  struct settings_vfo b;
3751
  struct settings_vfo c;
3752
  struct settings_vfo d;
3753
} vfo;
3754

    
3755
#seekto 0x0F80;
3756
struct {
3757
  char line1[8];
3758
  char line2[8];
3759
  char line3[8];
3760
  char line4[8];
3761
  char line5[8];
3762
  char line6[8];
3763
  char line7[8];
3764
  char line8[8];
3765
} poweron_msg;
3766

    
3767
#seekto 0x1000;
3768
struct {
3769
  char name[8];
3770
  u8 unknown1[8];
3771
} names[200];
3772

    
3773
#seekto 0x2400;
3774
struct {
3775
  u8 period; // one out of LIST_5TONE_STANDARD_PERIODS
3776
  u8 group_tone;
3777
  u8 repeat_tone;
3778
  u8 unused[13];
3779
} _5tone_std_settings[15];
3780

    
3781
#seekto 0x2500;
3782
struct {
3783
  u8 frame1[5];
3784
  u8 frame2[5];
3785
  u8 frame3[5];
3786
  u8 standard;   // one out of LIST_5TONE_STANDARDS
3787
} _5tone_codes[15];
3788

    
3789
#seekto 0x25F0;
3790
struct {
3791
  u8 _5tone_delay1; // * 10ms
3792
  u8 _5tone_delay2; // * 10ms
3793
  u8 _5tone_delay3; // * 10ms
3794
  u8 _5tone_first_digit_ext_length;
3795
  u8 unknown1;
3796
  u8 unknown2;
3797
  u8 unknown3;
3798
  u8 unknown4;
3799
  u8 decode_standard;
3800
  u8 unknown5:5,
3801
     _5tone_decode_call_frame3:1,
3802
     _5tone_decode_call_frame2:1,
3803
     _5tone_decode_call_frame1:1;
3804
  u8 unknown6:5,
3805
     _5tone_decode_disp_frame3:1,
3806
     _5tone_decode_disp_frame2:1,
3807
     _5tone_decode_disp_frame1:1;
3808
  u8 decode_reset_time; // * 100 + 100ms
3809
} _5tone_settings;
3810

    
3811
#seekto 0x2900;
3812
struct {
3813
  u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B
3814
} dtmf_codes[15];
3815

    
3816
#seekto 0x29F0;
3817
struct {
3818
  u8 dtmfspeed_on;  //list with 50..2000ms in steps of 10
3819
  u8 dtmfspeed_off; //list with 50..2000ms in steps of 10
3820
  u8 unknown0[14];
3821
  u8 inspection[16];
3822
  u8 monitor[16];
3823
  u8 alarmcode[16];
3824
  u8 stun[16];
3825
  u8 kill[16];
3826
  u8 revive[16];
3827
  u8 unknown1[16];
3828
  u8 unknown2[16];
3829
  u8 unknown3[16];
3830
  u8 unknown4[16];
3831
  u8 unknown5[16];
3832
  u8 unknown6[16];
3833
  u8 unknown7[16];
3834
  u8 masterid[16];
3835
  u8 viceid[16];
3836
  u8 unused01:7,
3837
     mastervice:1;
3838
  u8 unused02:3,
3839
     mrevive:1,
3840
     mkill:1,
3841
     mstun:1,
3842
     mmonitor:1,
3843
     minspection:1;
3844
  u8 unused03:3,
3845
     vrevive:1,
3846
     vkill:1,
3847
     vstun:1,
3848
     vmonitor:1,
3849
     vinspection:1;
3850
  u8 unused04:6,
3851
     txdisable:1,
3852
     rxdisable:1;
3853
  u8 groupcode;
3854
  u8 spacecode;
3855
  u8 delayproctime; // * 100 + 100ms
3856
  u8 resettime;     // * 100 + 100ms
3857
} dtmf_settings;
3858

    
3859
#seekto 0x2D00;
3860
struct {
3861
  struct {
3862
    ul16 freq1;
3863
    u8 unused01[6];
3864
    ul16 freq2;
3865
    u8 unused02[6];
3866
  } _2tone_encode[15];
3867
  u8 duration_1st_tone; // *10ms
3868
  u8 duration_2nd_tone; // *10ms
3869
  u8 duration_gap;      // *10ms
3870
  u8 unused03[13];
3871
  struct {
3872
    struct {
3873
      u8 dec;      // one out of LIST_2TONE_DEC
3874
      u8 response; // one out of LIST_2TONE_RESPONSE
3875
      u8 alert;    // 1-16
3876
    } decs[4];
3877
    u8 unused04[4];
3878
  } _2tone_decode[15];
3879
  u8 unused05[16];
3880

    
3881
  struct {
3882
    ul16 freqA;
3883
    ul16 freqB;
3884
    ul16 freqC;
3885
    ul16 freqD;
3886
    // unknown what those values mean, but they are
3887
    // derived from configured frequencies
3888
    ul16 derived_from_freqA; // 2304000/freqA
3889
    ul16 derived_from_freqB; // 2304000/freqB
3890
    ul16 derived_from_freqC; // 2304000/freqC
3891
    ul16 derived_from_freqD; // 2304000/freqD
3892
  }freqs[15];
3893
  u8 reset_time;  // * 100 + 100ms - 100-8000ms
3894
} _2tone;
3895

    
3896
#seekto 0x3D80;
3897
struct {
3898
  u8 vhf_low[3];
3899
  u8 vhf_high[3];
3900
  u8 unknown1[4];
3901
  u8 unknown2[6];
3902
  u8 vhf2_low[3];
3903
  u8 vhf2_high[3];
3904
  u8 unknown3[4];
3905
  u8 unknown4[6];
3906
  u8 uhf_low[3];
3907
  u8 uhf_high[3];
3908
  u8 unknown5[4];
3909
  u8 unknown6[6];
3910
  u8 uhf2_low[3];
3911
  u8 uhf2_high[3];
3912
} ranges;
3913

    
3914
#seekto 0x3F70;
3915
struct {
3916
  char fp[6];
3917
} fingerprint;
3918

    
3919
"""
3920

    
3921

    
3922
class BTechColor(BTechMobileCommon):
3923
    """BTECH's Color LCD Mobile and alike radios"""
3924
    COLOR_LCD = True
3925
    NAME_LENGTH = 8
3926
    LIST_TMR = LIST_TMR16
3927

    
3928
    def process_mmap(self):
3929
        """Process the mem map into the mem object"""
3930

    
3931
        # Get it
3932
        self._memobj = bitwise.parse(COLOR_MEM_FORMAT, self._mmap)
3933

    
3934
        # load specific parameters from the radio image
3935
        self.set_options()
3936

    
3937
    def set_options(self):
3938
        """This is to read the options from the image and set it in the
3939
        environment, for now just the limits of the freqs in the VHF/UHF
3940
        ranges"""
3941

    
3942
        # setting the correct ranges for each radio type
3943
        ranges = self._memobj.ranges
3944

    
3945
        # the normal dual bands
3946
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
3947
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
3948

    
3949
        # DEBUG
3950
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
3951
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
3952

    
3953
        # the additional bands
3954
        if self.MODEL in ["UV-25X4", "KT7900D"]:
3955
            # 200Mhz band
3956
            vhf2 = _decode_ranges(ranges.vhf2_low, ranges.vhf2_high)
3957
            LOG.info("Radio ranges: VHF(220) %d to %d" % vhf2)
3958
            self._220_range = vhf2
3959

    
3960
            # 350Mhz band
3961
            uhf2 = _decode_ranges(ranges.uhf2_low, ranges.uhf2_high)
3962
            LOG.info("Radio ranges: UHF(350) %d to %d" % uhf2)
3963
            self._350_range = uhf2
3964

    
3965
        # set the class with the real data
3966
        self._vhf_range = vhf
3967
        self._uhf_range = uhf
3968

    
3969

    
3970
# Declaring Aliases (Clones of the real radios)
3971
class SKT8900D(chirp_common.Alias):
3972
    VENDOR = "Surecom"
3973
    MODEL = "S-KT8900D"
3974

    
3975

    
3976
class QB25(chirp_common.Alias):
3977
    VENDOR = "Radioddity"
3978
    MODEL = "QB25"
3979

    
3980

    
3981
# real radios
3982
@directory.register
3983
class UV25X2(BTechColor):
3984
    """Baofeng Tech UV25X2"""
3985
    MODEL = "UV-25X2"
3986
    BANDS = 2
3987
    _vhf_range = (130000000, 180000000)
3988
    _uhf_range = (400000000, 521000000)
3989
    _magic = MSTRING_UV25X2
3990
    _fileid = [UV25X2_fp, ]
3991

    
3992

    
3993
@directory.register
3994
class UV25X4(BTechColor):
3995
    """Baofeng Tech UV25X4"""
3996
    MODEL = "UV-25X4"
3997
    BANDS = 4
3998
    _vhf_range = (130000000, 180000000)
3999
    _220_range = (200000000, 271000000)
4000
    _uhf_range = (400000000, 521000000)
4001
    _350_range = (350000000, 391000000)
4002
    _magic = MSTRING_UV25X4
4003
    _fileid = [UV25X4_fp, ]
4004

    
4005

    
4006
@directory.register
4007
class UV50X2(BTechColor):
4008
    """Baofeng Tech UV50X2"""
4009
    MODEL = "UV-50X2"
4010
    BANDS = 2
4011
    _vhf_range = (130000000, 180000000)
4012
    _uhf_range = (400000000, 521000000)
4013
    _magic = MSTRING_UV25X2
4014
    _fileid = [UV50X2_fp, ]
4015
    _power_levels = [chirp_common.PowerLevel("High", watts=50),
4016
                     chirp_common.PowerLevel("Low", watts=10)]
4017

    
4018

    
4019
@directory.register
4020
class KT7900D(BTechColor):
4021
    """QYT KT7900D"""
4022
    VENDOR = "QYT"
4023
    MODEL = "KT7900D"
4024
    BANDS = 4
4025
    LIST_TMR = LIST_TMR15
4026
    _vhf_range = (136000000, 175000000)
4027
    _220_range = (200000000, 271000000)
4028
    _uhf_range = (400000000, 481000000)
4029
    _350_range = (350000000, 371000000)
4030
    _magic = MSTRING_KT8900D
4031
    _fileid = [KT7900D_fp, KT7900D_fp1, KT7900D_fp2, KT7900D_fp3, KT7900D_fp4,
4032
               KT7900D_fp5, KT7900D_fp6, KT7900D_fp7, QB25_fp, ]
4033
    # Clones
4034
    ALIASES = [SKT8900D, QB25, ]
4035

    
4036

    
4037
@directory.register
4038
class KT8900D(BTechColor):
4039
    """QYT KT8900D"""
4040
    VENDOR = "QYT"
4041
    MODEL = "KT8900D"
4042
    BANDS = 2
4043
    LIST_TMR = LIST_TMR15
4044
    _vhf_range = (136000000, 175000000)
4045
    _uhf_range = (400000000, 481000000)
4046
    _magic = MSTRING_KT8900D
4047
    _fileid = [KT8900D_fp3, KT8900D_fp2, KT8900D_fp1, KT8900D_fp]
4048

    
4049
    # Clones
4050
    ALIASES = [OTGRadioV1]
4051

    
4052

    
4053
@directory.register
4054
class KT5800(BTechColor):
4055
    """QYT KT5800"""
4056
    VENDOR = "QYT"
4057
    MODEL = "KT5800"
4058
    BANDS = 2
4059
    LIST_TMR = LIST_TMR15
4060
    _vhf_range = (136000000, 175000000)
4061
    _uhf_range = (400000000, 481000000)
4062
    _magic = MSTRING_KT8900D
4063
    _fileid = [KT5800_fp, ]
4064

    
4065

    
4066
@directory.register
4067
class KT980PLUS(BTechColor):
4068
    """QYT KT980PLUS"""
4069
    VENDOR = "QYT"
4070
    MODEL = "KT980PLUS"
4071
    BANDS = 2
4072
    LIST_TMR = LIST_TMR15
4073
    _vhf_range = (136000000, 175000000)
4074
    _uhf_range = (400000000, 481000000)
4075
    _magic = MSTRING_KT8900D
4076
    _fileid = [KT980PLUS_fp1, KT980PLUS_fp]
4077
    _power_levels = [chirp_common.PowerLevel("High", watts=75),
4078
                     chirp_common.PowerLevel("Low", watts=55)]
4079

    
4080
    @classmethod
4081
    def match_model(cls, filedata, filename):
4082
        # This model is only ever matched via metadata
4083
        return False
4084

    
4085

    
4086
@directory.register
4087
class DB25G(BTechColor):
4088
    """Radioddity DB25-G"""
4089
    VENDOR = "Radioddity"
4090
    MODEL = "DB25-G"
4091
    BANDS = 2
4092
    LIST_TMR = LIST_TMR15
4093
    _vhf_range = (136000000, 175000000)
4094
    _uhf_range = (400000000, 481000000)
4095
    _magic = MSTRING_KT8900D
4096
    _fileid = [DB25G_fp1, DB25G_fp]
4097
    _gmrs = True
4098
    _power_levels = [chirp_common.PowerLevel("High", watts=25),
4099
                     chirp_common.PowerLevel("Mid", watts=15),
4100
                     chirp_common.PowerLevel("Low", watts=5)]
4101

    
4102
    @classmethod
4103
    def match_model(cls, filedata, filename):
4104
        # This model is only ever matched via metadata
4105
        return False
4106

    
4107

    
4108
GMRS_MEM_FORMAT = """
4109
#seekto 0x0000;
4110
struct {
4111
  lbcd rxfreq[4];
4112
  lbcd txfreq[4];
4113
  ul16 rxtone;
4114
  ul16 txtone;
4115
  u8 unknown0:4,
4116
     scode:4;
4117
  u8 unknown1:2,
4118
     spmute:2,
4119
     unknown2:2,
4120
     optsig:2;
4121
  u8 unknown3:3,
4122
     scramble:1,
4123
     unknown4:2,
4124
     power:2;
4125
  u8 unknown5:1,
4126
     wide:1,
4127
     unknown6:2,
4128
     bcl:1,
4129
     add:1,
4130
     pttid:2;
4131
} memory[256];
4132

    
4133
#seekto 0x1000;
4134
struct {
4135
  char name[7];
4136
  u8 unknown1[9];
4137
} names[256];
4138

    
4139
#seekto 0x2400;
4140
struct {
4141
  u8 period; // one out of LIST_5TONE_STANDARD_PERIODS
4142
  u8 group_tone;
4143
  u8 repeat_tone;
4144
  u8 unused[13];
4145
} _5tone_std_settings[15];
4146

    
4147
#seekto 0x2500;
4148
struct {
4149
  u8 frame1[5];
4150
  u8 frame2[5];
4151
  u8 frame3[5];
4152
  u8 standard;   // one out of LIST_5TONE_STANDARDS
4153
} _5tone_codes[15];
4154

    
4155
#seekto 0x25F0;
4156
struct {
4157
  u8 _5tone_delay1; // * 10ms
4158
  u8 _5tone_delay2; // * 10ms
4159
  u8 _5tone_delay3; // * 10ms
4160
  u8 _5tone_first_digit_ext_length;
4161
  u8 unknown1;
4162
  u8 unknown2;
4163
  u8 unknown3;
4164
  u8 unknown4;
4165
  u8 decode_standard;
4166
  u8 unknown5:5,
4167
     _5tone_decode_call_frame3:1,
4168
     _5tone_decode_call_frame2:1,
4169
     _5tone_decode_call_frame1:1;
4170
  u8 unknown6:5,
4171
     _5tone_decode_disp_frame3:1,
4172
     _5tone_decode_disp_frame2:1,
4173
     _5tone_decode_disp_frame1:1;
4174
  u8 decode_reset_time; // * 100 + 100ms
4175
} _5tone_settings;
4176

    
4177
#seekto 0x2900;
4178
struct {
4179
  u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B
4180
} dtmf_codes[15];
4181

    
4182
#seekto 0x29F0;
4183
struct {
4184
  u8 dtmfspeed_on;  //list with 50..2000ms in steps of 10
4185
  u8 dtmfspeed_off; //list with 50..2000ms in steps of 10
4186
  u8 unknown0[14];
4187
  u8 inspection[16];
4188
  u8 monitor[16];
4189
  u8 alarmcode[16];
4190
  u8 stun[16];
4191
  u8 kill[16];
4192
  u8 revive[16];
4193
  u8 unknown1[16];
4194
  u8 unknown2[16];
4195
  u8 unknown3[16];
4196
  u8 unknown4[16];
4197
  u8 unknown5[16];
4198
  u8 unknown6[16];
4199
  u8 unknown7[16];
4200
  u8 masterid[16];
4201
  u8 viceid[16];
4202
  u8 unused01:7,
4203
     mastervice:1;
4204
  u8 unused02:3,
4205
     mrevive:1,
4206
     mkill:1,
4207
     mstun:1,
4208
     mmonitor:1,
4209
     minspection:1;
4210
  u8 unused03:3,
4211
     vrevive:1,
4212
     vkill:1,
4213
     vstun:1,
4214
     vmonitor:1,
4215
     vinspection:1;
4216
  u8 unused04:6,
4217
     txdisable:1,
4218
     rxdisable:1;
4219
  u8 groupcode;
4220
  u8 spacecode;
4221
  u8 delayproctime; // * 100 + 100ms
4222
  u8 resettime;     // * 100 + 100ms
4223
} dtmf_settings;
4224

    
4225
#seekto 0x2D00;
4226
struct {
4227
  struct {
4228
    ul16 freq1;
4229
    u8 unused01[6];
4230
    ul16 freq2;
4231
    u8 unused02[6];
4232
  } _2tone_encode[15];
4233
  u8 duration_1st_tone; // *10ms
4234
  u8 duration_2nd_tone; // *10ms
4235
  u8 duration_gap;      // *10ms
4236
  u8 unused03[13];
4237
  struct {
4238
    struct {
4239
      u8 dec;      // one out of LIST_2TONE_DEC
4240
      u8 response; // one out of LIST_2TONE_RESPONSE
4241
      u8 alert;    // 1-16
4242
    } decs[4];
4243
    u8 unused04[4];
4244
  } _2tone_decode[15];
4245
  u8 unused05[16];
4246

    
4247
  struct {
4248
    ul16 freqA;
4249
    ul16 freqB;
4250
    ul16 freqC;
4251
    ul16 freqD;
4252
    // unknown what those values mean, but they are
4253
    // derived from configured frequencies
4254
    ul16 derived_from_freqA; // 2304000/freqA
4255
    ul16 derived_from_freqB; // 2304000/freqB
4256
    ul16 derived_from_freqC; // 2304000/freqC
4257
    ul16 derived_from_freqD; // 2304000/freqD
4258
  }freqs[15];
4259
  u8 reset_time;  // * 100 + 100ms - 100-8000ms
4260
} _2tone;
4261

    
4262
#seekto 0x3000;
4263
struct {
4264
  u8 freq[8];
4265
  char broadcast_station_name[6];
4266
  u8 unknown[2];
4267
} fm_radio_preset[16];
4268

    
4269
#seekto 0x3200;
4270
struct {
4271
  u8 tmr;
4272
  u8 unknown1;
4273
  u8 sql;
4274
  u8 unknown2;
4275
  u8 autolk;
4276
  u8 tot;
4277
  u8 apo;
4278
  u8 unknown3;
4279
  u8 abr;
4280
  u8 beep;
4281
  u8 unknown4[4];
4282
  u8 dtmfst;
4283
  u8 unknown5[2];
4284
  u8 screv;
4285
  u8 unknown6[2];
4286
  u8 pttid;
4287
  u8 pttlt;
4288
  u8 unknown7;
4289
  u8 emctp;
4290
  u8 emcch;
4291
  u8 sigbp;
4292
  u8 unknown8;
4293
  u8 camdf;
4294
  u8 cbmdf;
4295
  u8 ccmdf;
4296
  u8 cdmdf;
4297
  u8 langua;
4298
  u8 sync;
4299

    
4300

    
4301
  u8 stfc;
4302
  u8 mffc;
4303
  u8 sfafc;
4304
  u8 sfbfc;
4305
  u8 sfcfc;
4306
  u8 sfdfc;
4307
  u8 subfc;
4308
  u8 fmfc;
4309
  u8 sigfc;
4310
  u8 modfc;
4311
  u8 menufc;
4312
  u8 txfc;
4313
  u8 txdisp;
4314
  u8 unknown9[5];
4315
  u8 anil;
4316
  u8 reps;
4317
  u8 repm;
4318
  u8 tmrmr;
4319
  u8 ste;
4320
  u8 rpste;
4321
  u8 rptdl;
4322
  u8 dtmfg;
4323
  u8 mgain;
4324
  u8 skiptx;
4325
  u8 scmode;
4326
} settings;
4327

    
4328
#seekto 0x3280;
4329
struct {
4330
  u8 unknown1;
4331
  u8 vfomr;
4332
  u8 keylock;
4333
  u8 unknown2;
4334
  u8 unknown3:4,
4335
     vfomren:1,
4336
     unknown4:1,
4337
     reseten:1,
4338
     menuen:1;
4339
  u8 unknown5[11];
4340
  u8 dispab;
4341
  u8 unknown6[2];
4342
  u8 smenu;
4343
  u8 unknown7[7];
4344
  u8 vfomra;
4345
  u8 vfomrb;
4346
  u8 vfomrc;
4347
  u8 vfomrd;
4348
  u8 mrcha;
4349
  u8 mrchb;
4350
  u8 mrchc;
4351
  u8 mrchd;
4352
} settings2;
4353

    
4354
struct settings_vfo {
4355
  u8 freq[8];
4356
  u8 offset[6];
4357
  u8 unknown2[2];
4358
  ul16 rxtone;
4359
  ul16 txtone;
4360
  u8 scode;
4361
  u8 spmute;
4362
  u8 optsig;
4363
  u8 scramble;
4364
  u8 wide;
4365
  u8 power;
4366
  u8 shiftd;
4367
  u8 step;
4368
  u8 unknown3[4];
4369
};
4370

    
4371
#seekto 0x3300;
4372
struct {
4373
  struct settings_vfo a;
4374
  struct settings_vfo b;
4375
  struct settings_vfo c;
4376
  struct settings_vfo d;
4377
} vfo;
4378

    
4379
#seekto 0x3D80;
4380
struct {
4381
  u8 vhf_low[3];
4382
  u8 vhf_high[3];
4383
  u8 unknown1[4];
4384
  u8 unknown2[6];
4385
  u8 vhf2_low[3];
4386
  u8 vhf2_high[3];
4387
  u8 unknown3[4];
4388
  u8 unknown4[6];
4389
  u8 uhf_low[3];
4390
  u8 uhf_high[3];
4391
  u8 unknown5[4];
4392
  u8 unknown6[6];
4393
  u8 uhf2_low[3];
4394
  u8 uhf2_high[3];
4395
} ranges;
4396

    
4397
#seekto 0x33B0;
4398
struct {
4399
  char line[16];
4400
} static_msg;
4401

    
4402
#seekto 0x3F70;
4403
struct {
4404
  char fp[6];
4405
} fingerprint;
4406

    
4407
"""
4408

    
4409

    
4410
class BTechGMRS(BTechMobileCommon):
4411
    """BTECH's GMRS Mobile"""
4412
    COLOR_LCD = True
4413
    COLOR_LCD2 = True
4414
    NAME_LENGTH = 7
4415
    UPLOAD_MEM_SIZE = 0X3400
4416

    
4417
    def process_mmap(self):
4418
        """Process the mem map into the mem object"""
4419

    
4420
        # Get it
4421
        self._memobj = bitwise.parse(GMRS_MEM_FORMAT, self._mmap)
4422

    
4423
        # load specific parameters from the radio image
4424
        self.set_options()
4425

    
4426
    def set_options(self):
4427
        """This is to read the options from the image and set it in the
4428
        environment, for now just the limits of the freqs in the VHF/UHF
4429
        ranges"""
4430

    
4431
        # setting the correct ranges for each radio type
4432
        ranges = self._memobj.ranges
4433

    
4434
        # the normal dual bands
4435
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
4436
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
4437

    
4438
        # DEBUG
4439
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
4440
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
4441

    
4442
        # set the class with the real data
4443
        self._vhf_range = vhf
4444
        self._uhf_range = uhf
4445

    
4446

    
4447
# real radios
4448
@directory.register
4449
class GMRS50X1(BTechGMRS):
4450
    """Baofeng Tech GMRS50X1"""
4451
    MODEL = "GMRS-50X1"
4452
    BANDS = 2
4453
    LIST_TMR = LIST_TMR16
4454
    _power_levels = [chirp_common.PowerLevel("High", watts=50),
4455
                     chirp_common.PowerLevel("Mid", watts=10),
4456
                     chirp_common.PowerLevel("Low", watts=5)]
4457
    _vhf_range = (136000000, 175000000)
4458
    _uhf_range = (400000000, 521000000)
4459
    _upper = 255
4460
    _magic = MSTRING_GMRS50X1
4461
    _fileid = [GMRS50X1_fp1, GMRS50X1_fp, ]
4462

    
4463

    
4464
COLORHT_MEM_FORMAT = """
4465
#seekto 0x0000;
4466
struct {
4467
  lbcd rxfreq[4];
4468
  lbcd txfreq[4];
4469
  ul16 rxtone;
4470
  ul16 txtone;
4471
  u8 unknown0:4,
4472
     scode:4;
4473
  u8 unknown1:2,
4474
     spmute:2,
4475
     unknown2:2,
4476
     optsig:2;
4477
  u8 unknown3:3,
4478
     scramble:1,
4479
     unknown4:3,
4480
     power:1;
4481
  u8 unknown5:1,
4482
     wide:1,
4483
     unknown6:2,
4484
     bcl:1,
4485
     add:1,
4486
     pttid:2;
4487
} memory[200];
4488

    
4489
#seekto 0x0E00;
4490
struct {
4491
  u8 tmr;
4492
  u8 unknownE01;
4493
  u8 sql;
4494
  u8 unknownE03[2];
4495
  u8 tot;
4496
  u8 save;
4497
  u8 unknownE07;
4498
  u8 abr;
4499
  u8 beep;
4500
  u8 unknownE0A[4];
4501
  u8 dsub;
4502
  u8 dtmfst;
4503
  u8 screv;
4504
  u8 unknownE11[3];
4505
  u8 pttid;
4506
  u8 unknownE15;
4507
  u8 pttlt;
4508
  u8 unknownE17;
4509
  u8 emctp;
4510
  u8 emcch;
4511
  u8 sigbp;
4512
  u8 unknownE1B;
4513
  u8 camdf;
4514
  u8 cbmdf;
4515
  u8 ccmdf;
4516
  u8 cdmdf;
4517
  u8 langua;
4518
  u8 voice;
4519
  u8 vox;
4520
  u8 voxt;
4521
  u8 sync;          // BTech radios use this as the display sync setting
4522
                    // other radios use this as the auto keypad lock setting
4523
  u8 stfc;
4524
  u8 mffc;
4525
  u8 sfafc;
4526
  u8 sfbfc;
4527
  u8 sfcfc;
4528
  u8 sfdfc;
4529
  u8 subfc;
4530
  u8 fmfc;
4531
  u8 sigfc;
4532
  u8 menufc;
4533
  u8 txfc;
4534
  u8 rxfc;
4535
  u8 unknownE31[5];
4536
  u8 anil;
4537
  u8 reps;
4538
  u8 tmrmr;
4539
  u8 ste;
4540
  u8 rpste;
4541
  u8 rptdl;
4542
  u8 dtmfg;
4543
  u8 tmrtx;
4544
} settings;
4545

    
4546
#seekto 0x0E80;
4547
struct {
4548
  u8 unknown1;
4549
  u8 vfomr;
4550
  u8 keylock;
4551
  u8 unknown2;
4552
  u8 unknown3:4,
4553
     vfomren:1,
4554
     unknown4:1,
4555
     reseten:1,
4556
     menuen:1;
4557
  u8 unknown5[11];
4558
  u8 dispab;
4559
  u8 unknown6[2];
4560
  u8 menu;
4561
  u8 unknown7[7];
4562
  u8 vfomra;
4563
  u8 vfomrb;
4564
  u8 vfomrc;
4565
  u8 vfomrd;
4566
  u8 mrcha;
4567
  u8 mrchb;
4568
  u8 mrchc;
4569
  u8 mrchd;
4570
} settings2;
4571

    
4572
struct settings_vfo {
4573
  u8 freq[8];
4574
  u8 offset[6];
4575
  u8 unknown2[2];
4576
  ul16 rxtone;
4577
  ul16 txtone;
4578
  u8 scode;
4579
  u8 spmute;
4580
  u8 optsig;
4581
  u8 scramble;
4582
  u8 wide;
4583
  u8 power;
4584
  u8 shiftd;
4585
  u8 step;
4586
  u8 unknown3[4];
4587
};
4588

    
4589
#seekto 0x0F00;
4590
struct {
4591
  struct settings_vfo a;
4592
  struct settings_vfo b;
4593
  struct settings_vfo c;
4594
  struct settings_vfo d;
4595
} vfo;
4596

    
4597
#seekto 0x0FE0;
4598
struct {
4599
  char line[16];
4600
} static_msg;
4601

    
4602
#seekto 0x1000;
4603
struct {
4604
  char name[8];
4605
  u8 unknown1[8];
4606
} names[200];
4607

    
4608
#seekto 0x2400;
4609
struct {
4610
  u8 period; // one out of LIST_5TONE_STANDARD_PERIODS
4611
  u8 group_tone;
4612
  u8 repeat_tone;
4613
  u8 unused[13];
4614
} _5tone_std_settings[15];
4615

    
4616
#seekto 0x2500;
4617
struct {
4618
  u8 frame1[5];
4619
  u8 frame2[5];
4620
  u8 frame3[5];
4621
  u8 standard;   // one out of LIST_5TONE_STANDARDS
4622
} _5tone_codes[15];
4623

    
4624
#seekto 0x25F0;
4625
struct {
4626
  u8 _5tone_delay1; // * 10ms
4627
  u8 _5tone_delay2; // * 10ms
4628
  u8 _5tone_delay3; // * 10ms
4629
  u8 _5tone_first_digit_ext_length;
4630
  u8 unknown1;
4631
  u8 unknown2;
4632
  u8 unknown3;
4633
  u8 unknown4;
4634
  u8 decode_standard;
4635
  u8 unknown5:5,
4636
     _5tone_decode_call_frame3:1,
4637
     _5tone_decode_call_frame2:1,
4638
     _5tone_decode_call_frame1:1;
4639
  u8 unknown6:5,
4640
     _5tone_decode_disp_frame3:1,
4641
     _5tone_decode_disp_frame2:1,
4642
     _5tone_decode_disp_frame1:1;
4643
  u8 decode_reset_time; // * 100 + 100ms
4644
} _5tone_settings;
4645

    
4646
#seekto 0x2900;
4647
struct {
4648
  u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B
4649
} dtmf_codes[15];
4650

    
4651
#seekto 0x29F0;
4652
struct {
4653
  u8 dtmfspeed_on;  //list with 50..2000ms in steps of 10
4654
  u8 dtmfspeed_off; //list with 50..2000ms in steps of 10
4655
  u8 unknown0[14];
4656
  u8 inspection[16];
4657
  u8 monitor[16];
4658
  u8 alarmcode[16];
4659
  u8 stun[16];
4660
  u8 kill[16];
4661
  u8 revive[16];
4662
  u8 unknown1[16];
4663
  u8 unknown2[16];
4664
  u8 unknown3[16];
4665
  u8 unknown4[16];
4666
  u8 unknown5[16];
4667
  u8 unknown6[16];
4668
  u8 unknown7[16];
4669
  u8 masterid[16];
4670
  u8 viceid[16];
4671
  u8 unused01:7,
4672
     mastervice:1;
4673
  u8 unused02:3,
4674
     mrevive:1,
4675
     mkill:1,
4676
     mstun:1,
4677
     mmonitor:1,
4678
     minspection:1;
4679
  u8 unused03:3,
4680
     vrevive:1,
4681
     vkill:1,
4682
     vstun:1,
4683
     vmonitor:1,
4684
     vinspection:1;
4685
  u8 unused04:6,
4686
     txdisable:1,
4687
     rxdisable:1;
4688
  u8 groupcode;
4689
  u8 spacecode;
4690
  u8 delayproctime; // * 100 + 100ms
4691
  u8 resettime;     // * 100 + 100ms
4692
} dtmf_settings;
4693

    
4694
#seekto 0x2D00;
4695
struct {
4696
  struct {
4697
    ul16 freq1;
4698
    u8 unused01[6];
4699
    ul16 freq2;
4700
    u8 unused02[6];
4701
  } _2tone_encode[15];
4702
  u8 duration_1st_tone; // *10ms
4703
  u8 duration_2nd_tone; // *10ms
4704
  u8 duration_gap;      // *10ms
4705
  u8 unused03[13];
4706
  struct {
4707
    struct {
4708
      u8 dec;      // one out of LIST_2TONE_DEC
4709
      u8 response; // one out of LIST_2TONE_RESPONSE
4710
      u8 alert;    // 1-16
4711
    } decs[4];
4712
    u8 unused04[4];
4713
  } _2tone_decode[15];
4714
  u8 unused05[16];
4715

    
4716
  struct {
4717
    ul16 freqA;
4718
    ul16 freqB;
4719
    ul16 freqC;
4720
    ul16 freqD;
4721
    // unknown what those values mean, but they are
4722
    // derived from configured frequencies
4723
    ul16 derived_from_freqA; // 2304000/freqA
4724
    ul16 derived_from_freqB; // 2304000/freqB
4725
    ul16 derived_from_freqC; // 2304000/freqC
4726
    ul16 derived_from_freqD; // 2304000/freqD
4727
  }freqs[15];
4728
  u8 reset_time;  // * 100 + 100ms - 100-8000ms
4729
} _2tone;
4730

    
4731
#seekto 0x3D80;
4732
struct {
4733
  u8 vhf_low[3];
4734
  u8 vhf_high[3];
4735
  u8 unknown1[4];
4736
  u8 unknown2[6];
4737
  u8 vhf2_low[3];
4738
  u8 vhf2_high[3];
4739
  u8 unknown3[4];
4740
  u8 unknown4[6];
4741
  u8 uhf_low[3];
4742
  u8 uhf_high[3];
4743
  u8 unknown5[4];
4744
  u8 unknown6[6];
4745
  u8 uhf2_low[3];
4746
  u8 uhf2_high[3];
4747
} ranges;
4748

    
4749
#seekto 0x3F70;
4750
struct {
4751
  char fp[6];
4752
} fingerprint;
4753

    
4754
"""
4755

    
4756

    
4757
class QYTColorHT(BTechMobileCommon):
4758
    """QTY's Color LCD Handheld and alike radios"""
4759
    COLOR_LCD = True
4760
    COLOR_LCD3 = True
4761
    NAME_LENGTH = 8
4762
    LIST_TMR = LIST_TMR15
4763

    
4764
    def process_mmap(self):
4765
        """Process the mem map into the mem object"""
4766

    
4767
        # Get it
4768
        self._memobj = bitwise.parse(COLORHT_MEM_FORMAT, self._mmap)
4769

    
4770
        # load specific parameters from the radio image
4771
        self.set_options()
4772

    
4773
    def set_options(self):
4774
        """This is to read the options from the image and set it in the
4775
        environment, for now just the limits of the freqs in the VHF/UHF
4776
        ranges"""
4777

    
4778
        # setting the correct ranges for each radio type
4779
        ranges = self._memobj.ranges
4780

    
4781
        # the normal dual bands
4782
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
4783
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
4784

    
4785
        # DEBUG
4786
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
4787
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
4788

    
4789
        # the additional bands
4790
        if self.MODEL in ["KT-8R"]:
4791
            # 200Mhz band
4792
            vhf2 = _decode_ranges(ranges.vhf2_low, ranges.vhf2_high)
4793
            LOG.info("Radio ranges: VHF(220) %d to %d" % vhf2)
4794
            self._220_range = vhf2
4795

    
4796
            # 350Mhz band
4797
            uhf2 = _decode_ranges(ranges.uhf2_low, ranges.uhf2_high)
4798
            LOG.info("Radio ranges: UHF(350) %d to %d" % uhf2)
4799
            self._350_range = uhf2
4800

    
4801
        # set the class with the real data
4802
        self._vhf_range = vhf
4803
        self._uhf_range = uhf
4804

    
4805

    
4806
# real radios
4807
@directory.register
4808
class KT8R(QYTColorHT):
4809
    """QYT KT8R"""
4810
    VENDOR = "QYT"
4811
    MODEL = "KT-8R"
4812
    BANDS = 4
4813
    LIST_TMR = LIST_TMR16
4814
    _vhf_range = (136000000, 175000000)
4815
    _220_range = (200000000, 261000000)
4816
    _uhf_range = (400000000, 481000000)
4817
    _350_range = (350000000, 391000000)
4818
    _magic = MSTRING_KT8R
4819
    _fileid = [KT8R_fp2, KT8R_fp1, KT8R_fp, ]
4820
    _power_levels = [chirp_common.PowerLevel("High", watts=5),
4821
                     chirp_common.PowerLevel("Low", watts=1)]
(16-16/16)