Project

General

Profile

New Model #9816 » btech_M3B064_fast.py

Jim Unroe, 04/02/2022 05:14 PM

 
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):
365
    """Send data to the radio device"""
366

    
367
    try:
368
        radio.pipe.write(data)
369

    
370
        # DEBUG
371
        if debug is True:
372
            LOG.debug("==> (%d) bytes:\n\n%s" %
373
                      (len(data), util.hexprint(data)))
374
    except:
375
        raise errors.RadioError("Error sending data to radio")
376

    
377

    
378
def _make_frame(cmd, addr, length, data=""):
379
    """Pack the info in the headder format"""
380
    frame = "\x06" + struct.pack(">BHB", ord(cmd), addr, length)
381
    # add the data if set
382
    if len(data) != 0:
383
        frame += data
384

    
385
    return frame
386

    
387

    
388
def _recv(radio, addr):
389
    """Get data from the radio all at once to lower syscalls load"""
390

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

    
394
    # get the whole block
395
    block = _rawrecv(radio, BLOCK_SIZE + 5)
396

    
397
    # basic check
398
    if len(block) < (BLOCK_SIZE + 5):
399
        raise errors.RadioError("Short read of the block 0x%04x" % addr)
400

    
401
    # checking for the ack
402
    if block[0] != ACK_CMD:
403
        raise errors.RadioError("Bad ack from radio in block 0x%04x" % addr)
404

    
405
    # header validation
406
    c, a, l = struct.unpack(">BHB", block[1:5])
407
    if a != addr or l != BLOCK_SIZE or c != ord("X"):
408
        LOG.debug("Invalid header for block 0x%04x" % addr)
409
        LOG.debug("CMD: %s  ADDR: %04x  SIZE: %02x" % (c, a, l))
410
        raise errors.RadioError("Invalid header for block 0x%04x:" % addr)
411

    
412
    # return the data
413
    return block[5:]
414

    
415

    
416
def _start_clone_mode(radio, status):
417
    """Put the radio in clone mode and get the ident string, 3 tries"""
418

    
419
    # cleaning the serial buffer
420
    _clean_buffer(radio)
421

    
422
    # prep the data to show in the UI
423
    status.cur = 0
424
    status.msg = "Identifying the radio..."
425
    status.max = 3
426
    radio.status_fn(status)
427

    
428
    try:
429
        for a in range(0, status.max):
430
            # Update the UI
431
            status.cur = a + 1
432
            radio.status_fn(status)
433

    
434
            # send the magic word
435
            _send(radio, radio._magic)
436

    
437
            # Now you get a x06 of ACK if all goes well
438
            ack = radio.pipe.read(1)
439

    
440
            if ack == "\x06":
441
                # DEBUG
442
                LOG.info("Magic ACK received")
443
                status.cur = status.max
444
                radio.status_fn(status)
445

    
446
                return True
447

    
448
        return False
449

    
450
    except errors.RadioError:
451
        raise
452
    except Exception, e:
453
        raise errors.RadioError("Error sending Magic to radio:\n%s" % e)
454

    
455

    
456
def _do_ident(radio, status, upload=False):
457
    """Put the radio in PROGRAM mode & identify it"""
458
    #  set the serial discipline
459
    radio.pipe.baudrate = 9600
460
    radio.pipe.parity = "N"
461

    
462
    # open the radio into program mode
463
    if _start_clone_mode(radio, status) is False:
464
        msg = "Radio did not enter clone mode"
465
        # warning about old versions of QYT KT8900
466
        if radio.MODEL == "KT8900":
467
            msg += ". You may want to try it as a WACCOM MINI-8900, there is a"
468
            msg += " known variant of this radios that is a clone of it."
469
        raise errors.RadioError(msg)
470

    
471
    # Ok, get the ident string
472
    ident = _rawrecv(radio, 49)
473

    
474
    # basic check for the ident
475
    if len(ident) != 49:
476
        raise errors.RadioError("Radio send a short ident block.")
477

    
478
    # check if ident is OK
479
    itis = False
480
    for fp in radio._fileid:
481
        if fp in ident:
482
            # got it!
483
            itis = True
484
            # checking if we are dealing with a Gen 3 BTECH
485
            if radio.VENDOR == "BTECH" and fp in BTECH3:
486
                radio.btech3 = True
487

    
488
            break
489

    
490
    if itis is False:
491
        LOG.debug("Incorrect model ID, got this:\n\n" + util.hexprint(ident))
492
        raise errors.RadioError("Radio identification failed.")
493

    
494
    # some radios needs a extra read and check for a code on it, this ones
495
    # has the check value in the _id2 var, others simply False
496
    if radio._id2 is not False:
497
        # query & receive the extra ID
498
        _send(radio, _make_frame("S", 0x3DF0, 16))
499
        id2 = _rawrecv(radio, 21)
500

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

    
508
        # ok, the correct string must be in the received data
509
        # the radio._id2 var will be always a list
510
        flag2 = False
511
        for _id2 in radio._id2:
512
            if _id2 in id2:
513
                flag2 = True
514

    
515
        if not flag2:
516
            LOG.debug("Full *BAD* extra ID on the %s is: \n%s" %
517
                      (radio.MODEL, util.hexprint(id2)))
518
            raise errors.RadioError("The extra ID is wrong, aborting.")
519

    
520
        # this radios need a extra request/answer here on the upload
521
        # the amount of data received depends of the radio type
522
        #
523
        # also the first block of TX must no have the ACK at the beginning
524
        # see _upload for this.
525
        if upload is True:
526
            # send an ACK
527
            _send(radio, ACK_CMD)
528

    
529
            # the amount of data depend on the radio, so far we have two radios
530
            # reading two bytes with an ACK at the end and just ONE with just
531
            # one byte (QYT KT8900)
532
            # the JT-6188 appears a clone of the last, but reads TWO bytes.
533
            #
534
            # we will read two bytes with a custom timeout to not penalize the
535
            # users for this.
536
            #
537
            # we just check for a response and last byte being a ACK, that is
538
            # the common stone for all radios (3 so far)
539
            ack = _rawrecv(radio, 2)
540

    
541
            # checking
542
            if len(ack) == 0 or ack[-1:] != ACK_CMD:
543
                raise errors.RadioError("Radio didn't ACK the upload")
544

    
545
    # DEBUG
546
    LOG.info("Positive ident, this is a %s %s" % (radio.VENDOR, radio.MODEL))
547

    
548
    return True
549

    
550

    
551
def _download(radio):
552
    """Get the memory map"""
553

    
554
    # UI progress
555
    status = chirp_common.Status()
556

    
557
    # put radio in program mode and identify it
558
    _do_ident(radio, status)
559

    
560
    # pause here for the radio to catch up
561
    sleep(0.1)
562

    
563
    # the models that doesn't have the extra ID have to make a dummy read here
564
    if radio._id2 is False:
565
        _send(radio, _make_frame("S", 0, BLOCK_SIZE))
566
        discard = _rawrecv(radio, BLOCK_SIZE + 5)
567

    
568
        if debug is True:
569
            LOG.info("Dummy first block read done, got this:\n\n %s",
570
                     util.hexprint(discard))
571

    
572
    # reset the progress bar in the UI
573
    status.max = MEM_SIZE / BLOCK_SIZE
574
    status.msg = "Cloning from radio..."
575
    status.cur = 0
576
    radio.status_fn(status)
577

    
578
    # cleaning the serial buffer
579
    _clean_buffer(radio)
580

    
581
    data = ""
582
    for addr in range(0, MEM_SIZE, BLOCK_SIZE):
583
        # sending the read request
584
        _send(radio, _make_frame("S", addr, BLOCK_SIZE))
585

    
586
        # read
587
        d = _recv(radio, addr)
588

    
589
        # aggregate the data
590
        data += d
591

    
592
        # UI Update
593
        status.cur = addr / BLOCK_SIZE
594
        status.msg = "Cloning from radio..."
595
        radio.status_fn(status)
596

    
597
    return data
598

    
599

    
600
def _upload(radio):
601
    """Upload procedure"""
602

    
603
    # The UPLOAD mem is restricted to lower than 0x3100,
604
    # so we will overide that here localy
605
    MEM_SIZE = radio.UPLOAD_MEM_SIZE
606

    
607
    # UI progress
608
    status = chirp_common.Status()
609

    
610
    # put radio in program mode and identify it
611
    _do_ident(radio, status, True)
612

    
613
    # get the data to upload to radio
614
    data = radio.get_mmap()
615

    
616
    # Reset the UI progress
617
    status.max = MEM_SIZE / TX_BLOCK_SIZE
618
    status.cur = 0
619
    status.msg = "Cloning to radio..."
620
    radio.status_fn(status)
621

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

    
626
    # cleaning the serial buffer
627
    _clean_buffer(radio)
628

    
629
    # the fun start here
630
    for addr in range(0, MEM_SIZE, TX_BLOCK_SIZE):
631
        # getting the block of data to send
632
        d = data[addr:addr + TX_BLOCK_SIZE]
633

    
634
        # build the frame to send
635
        frame = _make_frame("X", addr, TX_BLOCK_SIZE, d)
636

    
637
        # first block must not send the ACK at the beginning for the
638
        # ones that has the extra id, since this have to do a extra step
639
        if addr == 0 and radio._id2 is not False:
640
            frame = frame[1:]
641

    
642
        # send the frame
643
        _send(radio, frame)
644

    
645
        # receiving the response
646
        ack = _rawrecv(radio, 1)
647

    
648
        # basic check
649
        if len(ack) != 1:
650
            raise errors.RadioError("No ACK when writing block 0x%04x" % addr)
651

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

    
655
        # UI Update
656
        status.cur = addr / TX_BLOCK_SIZE
657
        status.msg = "Cloning to radio..."
658
        radio.status_fn(status)
659

    
660

    
661
def model_match(cls, data):
662
    """Match the opened/downloaded image to the correct version"""
663
    rid = data[0x3f70:0x3f76]
664

    
665
    if rid in cls._fileid:
666
        return True
667

    
668
    return False
669

    
670

    
671
def _decode_ranges(low, high):
672
    """Unpack the data in the ranges zones in the memmap and return
673
    a tuple with the integer corresponding to the Mhz it means"""
674
    ilow = int(low[0]) * 100 + int(low[1]) * 10 + int(low[2])
675
    ihigh = int(high[0]) * 100 + int(high[1]) * 10 + int(high[2])
676
    ilow *= 1000000
677
    ihigh *= 1000000
678

    
679
    return (ilow, ihigh)
680

    
681

    
682
def _split(rf, f1, f2):
683
    """Returns False if the two freqs are in the same band (no split)
684
    or True otherwise"""
685

    
686
    # determine if the two freqs are in the same band
687
    for low, high in rf.valid_bands:
688
        if f1 >= low and f1 <= high and \
689
                f2 >= low and f2 <= high:
690
            # if the two freqs are on the same Band this is not a split
691
            return False
692

    
693
    # if you get here is because the freq pairs are split
694
    return True
695

    
696

    
697
class BTechMobileCommon(chirp_common.CloneModeRadio,
698
                        chirp_common.ExperimentalRadio):
699
    """BTECH's UV-5001 and alike radios"""
700
    VENDOR = "BTECH"
701
    MODEL = ""
702
    IDENT = ""
703
    BANDS = 2
704
    COLOR_LCD = False
705
    COLOR_LCD2 = False
706
    COLOR_LCD3 = False
707
    NAME_LENGTH = 6
708
    UPLOAD_MEM_SIZE = 0X3100
709
    _power_levels = [chirp_common.PowerLevel("High", watts=25),
710
                     chirp_common.PowerLevel("Low", watts=10)]
711
    _vhf_range = (130000000, 180000000)
712
    _220_range = (200000000, 271000000)
713
    _uhf_range = (400000000, 521000000)
714
    _350_range = (350000000, 391000000)
715
    _upper = 199
716
    _magic = MSTRING
717
    _fileid = None
718
    _id2 = False
719
    btech3 = False
720
    _gmrs = False
721

    
722
    @classmethod
723
    def get_prompts(cls):
724
        rp = chirp_common.RadioPrompts()
725
        rp.experimental = \
726
            ('This driver is experimental.\n'
727
             '\n'
728
             'Please keep a copy of your memories with the original software '
729
             'if you treasure them, this driver is new and may contain'
730
             ' bugs.\n'
731
             '\n'
732
             )
733
        rp.pre_download = _(dedent("""\
734
            Follow these instructions to download your info:
735

    
736
            1 - Turn off your radio
737
            2 - Connect your interface cable
738
            3 - Turn on your radio
739
            4 - Do the download of your radio data
740

    
741
            """))
742
        rp.pre_upload = _(dedent("""\
743
            Follow these instructions to upload your info:
744

    
745
            1 - Turn off your radio
746
            2 - Connect your interface cable
747
            3 - Turn on your radio
748
            4 - Do the upload of your radio data
749

    
750
            """))
751
        return rp
752

    
753
    def get_features(self):
754
        """Get the radio's features"""
755

    
756
        # we will use the following var as global
757
        global POWER_LEVELS
758

    
759
        rf = chirp_common.RadioFeatures()
760
        rf.has_settings = True
761
        rf.has_bank = False
762
        rf.has_tuning_step = False
763
        rf.can_odd_split = True
764
        rf.has_name = True
765
        rf.has_offset = True
766
        rf.has_mode = True
767
        rf.has_dtcs = True
768
        rf.has_rx_dtcs = True
769
        rf.has_dtcs_polarity = True
770
        rf.has_ctone = True
771
        rf.has_cross = True
772
        rf.valid_modes = MODES
773
        rf.valid_characters = VALID_CHARS
774
        rf.valid_name_length = self.NAME_LENGTH
775
        rf.valid_duplexes = ["", "-", "+", "split", "off"]
776
        rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS', 'Cross']
777
        rf.valid_cross_modes = [
778
            "Tone->Tone",
779
            "DTCS->",
780
            "->DTCS",
781
            "Tone->DTCS",
782
            "DTCS->Tone",
783
            "->Tone",
784
            "DTCS->DTCS"]
785
        rf.valid_skips = SKIP_VALUES
786
        rf.valid_dtcs_codes = DTCS
787
        rf.valid_tuning_steps = STEPS
788
        rf.memory_bounds = (0, self._upper)
789

    
790
        # power levels
791
        POWER_LEVELS = self._power_levels
792
        rf.valid_power_levels = POWER_LEVELS
793

    
794
        # normal dual bands
795
        rf.valid_bands = [self._vhf_range, self._uhf_range]
796

    
797
        # 220 band
798
        if self.BANDS == 3 or self.BANDS == 4:
799
            rf.valid_bands.append(self._220_range)
800

    
801
        # 350 band
802
        if self.BANDS == 4:
803
            rf.valid_bands.append(self._350_range)
804

    
805
        return rf
806

    
807
    def validate_memory(self, mem):
808
        msgs = chirp_common.CloneModeRadio.validate_memory(self, mem)
809

    
810
        _msg_duplex1 = 'Memory location only supports "Low"'
811
        _msg_duplex2 = 'Memory location only supports "off"'
812
        _msg_duplex3 = 'Memory location only supports "(None)", "+" or "off"'
813

    
814
        if self._gmrs:
815
            if mem.number < 1 or mem.number > 30:
816
                if float(mem.freq) / 1000000 in GMRS_FREQS1:
817
                    if mem.duplex not in ['', 'off']:
818
                        # warn user wrong Duplex
819
                        msgs.append(chirp_common.ValidationError(_msg_duplex2))
820
                    if mem.power != self._power_levels[2]:
821
                        # warn user wrong Duplex
822
                        msgs.append(chirp_common.ValidationError(_msg_duplex1))
823

    
824
                if float(mem.freq) / 1000000 in GMRS_FREQS2:
825
                    if mem.duplex not in ['off', ]:
826
                        # warn user wrong Duplex
827
                        msgs.append(chirp_common.ValidationError(_msg_duplex2))
828

    
829
                if float(mem.freq) / 1000000 in GMRS_FREQS3:
830
                    if mem.duplex not in ['', '+', 'off']:
831
                        # warn user wrong Duplex
832
                        msgs.append(chirp_common.ValidationError(_msg_duplex3))
833

    
834
        return msgs
835

    
836
    def sync_in(self):
837
        """Download from radio"""
838
        data = _download(self)
839
        self._mmap = memmap.MemoryMap(data)
840
        self.process_mmap()
841

    
842
    def sync_out(self):
843
        """Upload to radio"""
844
        try:
845
            _upload(self)
846
        except errors.RadioError:
847
            raise
848
        except Exception, e:
849
            raise errors.RadioError("Error: %s" % e)
850

    
851
    def get_raw_memory(self, number):
852
        return repr(self._memobj.memory[number])
853

    
854
    def _decode_tone(self, val):
855
        """Parse the tone data to decode from mem, it returns:
856
        Mode (''|DTCS|Tone), Value (None|###), Polarity (None,N,R)"""
857
        pol = None
858

    
859
        if val in [0, 65535]:
860
            return '', None, None
861
        elif val > 0x0258:
862
            a = val / 10.0
863
            return 'Tone', a, pol
864
        else:
865
            if val > 0x69:
866
                index = val - 0x6A
867
                pol = "R"
868
            else:
869
                index = val - 1
870
                pol = "N"
871

    
872
            tone = DTCS[index]
873
            return 'DTCS', tone, pol
874

    
875
    def _encode_tone(self, memval, mode, val, pol):
876
        """Parse the tone data to encode from UI to mem"""
877
        if mode == '' or mode is None:
878
            memval.set_raw("\x00\x00")
879
        elif mode == 'Tone':
880
            memval.set_value(val * 10)
881
        elif mode == 'DTCS':
882
            # detect the index in the DTCS list
883
            try:
884
                index = DTCS.index(val)
885
                if pol == "N":
886
                    index += 1
887
                else:
888
                    index += 0x6A
889
                memval.set_value(index)
890
            except:
891
                msg = "Digital Tone '%d' is not supported" % value
892
                LOG.error(msg)
893
                raise errors.RadioError(msg)
894
        else:
895
            msg = "Internal error: invalid mode '%s'" % mode
896
            LOG.error(msg)
897
            raise errors.InvalidDataError(msg)
898

    
899
    def get_memory(self, number):
900
        """Get the mem representation from the radio image"""
901
        _mem = self._memobj.memory[number]
902
        _names = self._memobj.names[number]
903

    
904
        # Create a high-level memory object to return to the UI
905
        mem = chirp_common.Memory()
906

    
907
        # Memory number
908
        mem.number = number
909

    
910
        if _mem.get_raw()[0] == "\xFF":
911
            mem.empty = True
912
            return mem
913

    
914
        # Freq and offset
915
        mem.freq = int(_mem.rxfreq) * 10
916
        # tx freq can be blank
917
        if _mem.get_raw()[4] == "\xFF":
918
            # TX freq not set
919
            mem.offset = 0
920
            mem.duplex = "off"
921
        else:
922
            # TX freq set
923
            offset = (int(_mem.txfreq) * 10) - mem.freq
924
            if offset != 0:
925
                if _split(self.get_features(), mem.freq, int(
926
                          _mem.txfreq) * 10):
927
                    mem.duplex = "split"
928
                    mem.offset = int(_mem.txfreq) * 10
929
                elif offset < 0:
930
                    mem.offset = abs(offset)
931
                    mem.duplex = "-"
932
                elif offset > 0:
933
                    mem.offset = offset
934
                    mem.duplex = "+"
935
            else:
936
                mem.offset = 0
937

    
938
        # name TAG of the channel
939
        mem.name = str(_names.name).rstrip("\xFF").replace("\xFF", " ")
940

    
941
        # power
942
        mem.power = POWER_LEVELS[int(_mem.power)]
943

    
944
        # wide/narrow
945
        mem.mode = MODES[int(_mem.wide)]
946

    
947
        # skip
948
        mem.skip = SKIP_VALUES[_mem.add]
949

    
950
        # tone data
951
        rxtone = txtone = None
952
        txtone = self._decode_tone(_mem.txtone)
953
        rxtone = self._decode_tone(_mem.rxtone)
954
        chirp_common.split_tone_decode(mem, txtone, rxtone)
955

    
956
        # Extra
957
        mem.extra = RadioSettingGroup("extra", "Extra")
958

    
959
        if not self.COLOR_LCD or \
960
                (self.COLOR_LCD and not self.VENDOR == "BTECH"):
961
            scramble = RadioSetting("scramble", "Scramble",
962
                                    RadioSettingValueBoolean(bool(
963
                                        _mem.scramble)))
964
            mem.extra.append(scramble)
965

    
966
        bcl = RadioSetting("bcl", "Busy channel lockout",
967
                           RadioSettingValueBoolean(bool(_mem.bcl)))
968
        mem.extra.append(bcl)
969

    
970
        pttid = RadioSetting("pttid", "PTT ID",
971
                             RadioSettingValueList(PTTID_LIST,
972
                                                   PTTID_LIST[_mem.pttid]))
973
        mem.extra.append(pttid)
974

    
975
        # validating scode
976
        scode = _mem.scode if _mem.scode != 15 else 0
977
        pttidcode = RadioSetting("scode", "PTT ID signal code",
978
                                 RadioSettingValueList(
979
                                     PTTIDCODE_LIST,
980
                                     PTTIDCODE_LIST[scode]))
981
        mem.extra.append(pttidcode)
982

    
983
        optsig = RadioSetting("optsig", "Optional signaling",
984
                              RadioSettingValueList(
985
                                  OPTSIG_LIST,
986
                                  OPTSIG_LIST[_mem.optsig]))
987
        mem.extra.append(optsig)
988

    
989
        spmute = RadioSetting("spmute", "Speaker mute",
990
                              RadioSettingValueList(
991
                                  SPMUTE_LIST,
992
                                  SPMUTE_LIST[_mem.spmute]))
993
        mem.extra.append(spmute)
994

    
995
        return mem
996

    
997
    def set_memory(self, mem):
998
        """Set the memory data in the eeprom img from the UI"""
999
        # get the eprom representation of this channel
1000
        _mem = self._memobj.memory[mem.number]
1001
        _names = self._memobj.names[mem.number]
1002

    
1003
        mem_was_empty = False
1004
        # same method as used in get_memory for determining if mem is empty
1005
        # doing this BEFORE overwriting it with new values ...
1006
        if _mem.get_raw()[0] == "\xFF":
1007
            LOG.debug("This mem was empty before")
1008
            mem_was_empty = True
1009

    
1010
        # if empty memmory
1011
        if mem.empty:
1012
            # the channel itself
1013
            _mem.set_raw("\xFF" * 16)
1014
            # the name tag
1015
            _names.set_raw("\xFF" * 16)
1016
            return
1017

    
1018
        if mem_was_empty:
1019
            # Zero the whole memory if we're making it unempty for
1020
            # the first time
1021
            LOG.debug('Zeroing new memory')
1022
            _mem.set_raw('\x00' * 16)
1023

    
1024
        if self._gmrs:
1025
            if mem.number >= 1 and mem.number <= 30:
1026
                GMRS_FREQ = int(GMRS_FREQS[mem.number - 1] * 1000000)
1027
                mem.freq = GMRS_FREQ
1028
                if mem.number <= 22:
1029
                    mem.duplex = ''
1030
                    mem.offset = 0
1031
                    if mem.number <= 7:
1032
                        mem.power = self._power_levels[2]
1033
                    if mem.number >= 8 and mem.number <= 14:
1034
                        mem.duplex = 'off'
1035
                        mem.mode = "NFM"
1036
                        mem.power = self._power_levels[2]
1037
                if mem.number > 22:
1038
                    mem.duplex = '+'
1039
                    mem.offset = 5000000
1040
            elif float(mem.freq) / 1000000 in GMRS_FREQS:
1041
                if float(mem.freq) / 1000000 in GMRS_FREQS1:
1042
                    mem.duplex = ''
1043
                    mem.offset = 0
1044
                    mem.power = self._power_levels[2]
1045
                if float(mem.freq) / 1000000 in GMRS_FREQS2:
1046
                    mem.duplex = 'off'
1047
                    mem.offset = 0
1048
                    mem.mode = "NFM"
1049
                    mem.power = self._power_levels[2]
1050
                if float(mem.freq) / 1000000 in GMRS_FREQS3:
1051
                    if mem.duplex == '+':
1052
                        mem.offset = 5000000
1053
                    else:
1054
                        mem.offset = 0
1055
            else:
1056
                mem.duplex = 'off'
1057
                mem.offset = 0
1058

    
1059
        # frequency
1060
        _mem.rxfreq = mem.freq / 10
1061

    
1062
        # duplex
1063
        if mem.duplex == "+":
1064
            _mem.txfreq = (mem.freq + mem.offset) / 10
1065
        elif mem.duplex == "-":
1066
            _mem.txfreq = (mem.freq - mem.offset) / 10
1067
        elif mem.duplex == "off":
1068
            for i in _mem.txfreq:
1069
                i.set_raw("\xFF")
1070
        elif mem.duplex == "split":
1071
            _mem.txfreq = mem.offset / 10
1072
        else:
1073
            _mem.txfreq = mem.freq / 10
1074

    
1075
        # tone data
1076
        ((txmode, txtone, txpol), (rxmode, rxtone, rxpol)) = \
1077
            chirp_common.split_tone_encode(mem)
1078
        self._encode_tone(_mem.txtone, txmode, txtone, txpol)
1079
        self._encode_tone(_mem.rxtone, rxmode, rxtone, rxpol)
1080

    
1081
        # name TAG of the channel
1082
        if len(mem.name) < self.NAME_LENGTH:
1083
            # we must pad to self.NAME_LENGTH chars, " " = "\xFF"
1084
            mem.name = str(mem.name).ljust(self.NAME_LENGTH, " ")
1085
        _names.name = str(mem.name).replace(" ", "\xFF")
1086

    
1087
        # power, # default power level is high
1088
        _mem.power = 0 if mem.power is None else POWER_LEVELS.index(mem.power)
1089

    
1090
        # wide/narrow
1091
        _mem.wide = MODES.index(mem.mode)
1092

    
1093
        # scan add property
1094
        _mem.add = SKIP_VALUES.index(mem.skip)
1095

    
1096
        # reseting unknowns, this have to be set by hand
1097
        _mem.unknown0 = 0
1098
        _mem.unknown1 = 0
1099
        _mem.unknown2 = 0
1100
        _mem.unknown3 = 0
1101
        _mem.unknown4 = 0
1102
        _mem.unknown5 = 0
1103
        _mem.unknown6 = 0
1104

    
1105
        def _zero_settings():
1106
            _mem.spmute = 0
1107
            _mem.optsig = 0
1108
            _mem.scramble = 0
1109
            _mem.bcl = 0
1110
            _mem.pttid = 0
1111
            _mem.scode = 0
1112

    
1113
        if self.COLOR_LCD and _mem.scramble:
1114
            LOG.info('Resetting scramble bit for BTECH COLOR_LCD variant')
1115
            _mem.scramble = 0
1116

    
1117
        # extra settings
1118
        if len(mem.extra) > 0:
1119
            # there are setting, parse
1120
            LOG.debug("Extra-Setting supplied. Setting them.")
1121
            # Zero them all first so any not provided by model don't
1122
            # stay set
1123
            _zero_settings()
1124
            for setting in mem.extra:
1125
                setattr(_mem, setting.get_name(), setting.value)
1126
        else:
1127
            if mem.empty:
1128
                LOG.debug("New mem is empty.")
1129
            else:
1130
                LOG.debug("New mem is NOT empty")
1131
                # set extra-settings to default ONLY when apreviously empty or
1132
                # deleted memory was edited to prevent errors such as #4121
1133
                if mem_was_empty:
1134
                    LOG.debug("old mem was empty. Setting default for extras.")
1135
                    _zero_settings()
1136

    
1137
        return mem
1138

    
1139
    def get_settings(self):
1140
        """Translate the bit in the mem_struct into settings in the UI"""
1141
        _mem = self._memobj
1142
        basic = RadioSettingGroup("basic", "Basic Settings")
1143
        advanced = RadioSettingGroup("advanced", "Advanced Settings")
1144
        other = RadioSettingGroup("other", "Other Settings")
1145
        work = RadioSettingGroup("work", "Work Mode Settings")
1146
        top = RadioSettings(basic, advanced, other, work)
1147

    
1148
        # Basic
1149
        if self.COLOR_LCD:
1150
            tmr = RadioSetting("settings.tmr", "Transceiver multi-receive",
1151
                               RadioSettingValueList(
1152
                                   self.LIST_TMR,
1153
                                   self.LIST_TMR[_mem.settings.tmr]))
1154
            basic.append(tmr)
1155
        else:
1156
            tdr = RadioSetting("settings.tdr", "Transceiver dual receive",
1157
                               RadioSettingValueBoolean(_mem.settings.tdr))
1158
            basic.append(tdr)
1159

    
1160
        sql = RadioSetting("settings.sql", "Squelch level",
1161
                           RadioSettingValueInteger(0, 9, _mem.settings.sql))
1162
        basic.append(sql)
1163

    
1164
        if self.MODEL == "GMRS-50X1":
1165
            autolk = RadioSetting("settings.autolk", "Auto keylock",
1166
                                  RadioSettingValueBoolean(
1167
                                      _mem.settings.autolk))
1168
            basic.append(autolk)
1169

    
1170
        if self.MODEL == "DB25-G":
1171
            rs = RadioSettingValueInteger(0, 127, _mem.settings.mgain2)
1172
            mgain2 = RadioSetting("settings.mgain2", "Mic gain", rs)
1173
            basic.append(mgain2)
1174

    
1175
        tot = RadioSetting("settings.tot", "Time out timer",
1176
                           RadioSettingValueList(
1177
                               LIST_TOT,
1178
                               LIST_TOT[_mem.settings.tot]))
1179
        basic.append(tot)
1180

    
1181
        if self.MODEL == "KT-8R":
1182
                save = RadioSetting("settings.save", "Battery Save",
1183
                                    RadioSettingValueBoolean(
1184
                                        _mem.settings.save))
1185
                basic.append(save)
1186

    
1187
        if not self.MODEL == "KT-8R":
1188
            if self.VENDOR == "BTECH" or self.COLOR_LCD:
1189
                apo = RadioSetting("settings.apo", "Auto power off timer",
1190
                                   RadioSettingValueList(
1191
                                       LIST_APO,
1192
                                       LIST_APO[_mem.settings.apo]))
1193
                basic.append(apo)
1194
            else:
1195
                toa = RadioSetting("settings.apo", "Time out alert timer",
1196
                                   RadioSettingValueList(
1197
                                       LIST_OFF1TO10,
1198
                                       LIST_OFF1TO10[_mem.settings.apo]))
1199
                basic.append(toa)
1200

    
1201
        abr = RadioSetting("settings.abr", "Backlight timer",
1202
                           RadioSettingValueList(
1203
                               LIST_OFF1TO50,
1204
                               LIST_OFF1TO50[_mem.settings.abr]))
1205
        basic.append(abr)
1206

    
1207
        beep = RadioSetting("settings.beep", "Key beep",
1208
                            RadioSettingValueBoolean(_mem.settings.beep))
1209
        basic.append(beep)
1210

    
1211
        if self.MODEL == "KT-8R":
1212
                dsub = RadioSetting("settings.dsub", "CTCSS/DCS code display",
1213
                                    RadioSettingValueBoolean(
1214
                                        _mem.settings.dsub))
1215
                basic.append(dsub)
1216

    
1217
        if self.MODEL == "KT-8R":
1218
                dtmfst = RadioSetting("settings.dtmfst", "DTMF side tone",
1219
                                      RadioSettingValueBoolean(
1220
                                          _mem.settings.dtmfst))
1221
                basic.append(dtmfst)
1222
        else:
1223
            dtmfst = RadioSetting("settings.dtmfst", "DTMF side tone",
1224
                                  RadioSettingValueList(
1225
                                      LIST_DTMFST,
1226
                                      LIST_DTMFST[_mem.settings.dtmfst]))
1227
            basic.append(dtmfst)
1228

    
1229
        if not self.COLOR_LCD:
1230
            prisc = RadioSetting("settings.prisc", "Priority scan",
1231
                                 RadioSettingValueBoolean(
1232
                                     _mem.settings.prisc))
1233
            basic.append(prisc)
1234

    
1235
            prich = RadioSetting("settings.prich", "Priority channel",
1236
                                 RadioSettingValueInteger(0, self._upper,
1237
                                                          _mem.settings.prich))
1238
            basic.append(prich)
1239

    
1240
        screv = RadioSetting("settings.screv", "Scan resume method",
1241
                             RadioSettingValueList(
1242
                                 LIST_SCREV,
1243
                                 LIST_SCREV[_mem.settings.screv]))
1244
        basic.append(screv)
1245

    
1246
        pttlt = RadioSetting("settings.pttlt", "PTT transmit delay",
1247
                             RadioSettingValueInteger(0, 30,
1248
                                                      _mem.settings.pttlt))
1249
        basic.append(pttlt)
1250

    
1251
        if self.VENDOR == "BTECH" and self.COLOR_LCD:
1252
            emctp = RadioSetting("settings.emctp", "Alarm mode",
1253
                                 RadioSettingValueList(
1254
                                     LIST_EMCTPX,
1255
                                     LIST_EMCTPX[_mem.settings.emctp]))
1256
            basic.append(emctp)
1257
        else:
1258
            emctp = RadioSetting("settings.emctp", "Alarm mode",
1259
                                 RadioSettingValueList(
1260
                                     LIST_EMCTP,
1261
                                     LIST_EMCTP[_mem.settings.emctp]))
1262
            basic.append(emctp)
1263

    
1264
        emcch = RadioSetting("settings.emcch", "Alarm channel",
1265
                             RadioSettingValueInteger(0, self._upper,
1266
                                                      _mem.settings.emcch))
1267
        basic.append(emcch)
1268

    
1269
        if self.COLOR_LCD:
1270
            if _mem.settings.sigbp > 0x01:
1271
                val = 0x00
1272
            else:
1273
                val = _mem.settings.sigbp
1274
            sigbp = RadioSetting("settings.sigbp", "Signal beep",
1275
                                 RadioSettingValueBoolean(val))
1276
            basic.append(sigbp)
1277
        else:
1278
            ringt = RadioSetting("settings.ringt", "Ring time",
1279
                                 RadioSettingValueList(
1280
                                     LIST_OFF1TO9,
1281
                                     LIST_OFF1TO9[_mem.settings.ringt]))
1282
            basic.append(ringt)
1283

    
1284
        camdf = RadioSetting("settings.camdf", "Display mode A",
1285
                             RadioSettingValueList(
1286
                                 LIST_MDF,
1287
                                 LIST_MDF[_mem.settings.camdf]))
1288
        basic.append(camdf)
1289

    
1290
        cbmdf = RadioSetting("settings.cbmdf", "Display mode B",
1291
                             RadioSettingValueList(
1292
                                 LIST_MDF,
1293
                                 LIST_MDF[_mem.settings.cbmdf]))
1294
        basic.append(cbmdf)
1295

    
1296
        if self.COLOR_LCD:
1297
            ccmdf = RadioSetting("settings.ccmdf", "Display mode C",
1298
                                 RadioSettingValueList(
1299
                                     LIST_MDF,
1300
                                     LIST_MDF[_mem.settings.ccmdf]))
1301
            basic.append(ccmdf)
1302

    
1303
            cdmdf = RadioSetting("settings.cdmdf", "Display mode D",
1304
                                 RadioSettingValueList(
1305
                                     LIST_MDF,
1306
                                     LIST_MDF[_mem.settings.cdmdf]))
1307
            basic.append(cdmdf)
1308

    
1309
            langua = RadioSetting("settings.langua", "Language",
1310
                                  RadioSettingValueList(
1311
                                      LIST_LANGUA,
1312
                                      LIST_LANGUA[_mem.settings.langua]))
1313
            basic.append(langua)
1314

    
1315
        if self.MODEL == "KT-8R":
1316
            voice = RadioSetting("settings.voice", "Voice prompt",
1317
                                 RadioSettingValueList(
1318
                                     LIST_VOICE,
1319
                                     LIST_VOICE[_mem.settings.voice]))
1320
            basic.append(voice)
1321

    
1322
            vox = RadioSetting("settings.vox", "VOX",
1323
                               RadioSettingValueList(
1324
                                   LIST_VOX,
1325
                                   LIST_VOX[_mem.settings.vox]))
1326
            basic.append(vox)
1327

    
1328
            voxt = RadioSetting("settings.voxt", "VOX delay time",
1329
                                RadioSettingValueList(
1330
                                    LIST_VOXT,
1331
                                    LIST_VOXT[_mem.settings.voxt]))
1332
            basic.append(voxt)
1333

    
1334
        if self.VENDOR == "BTECH":
1335
            if self.COLOR_LCD:
1336
                sync = RadioSetting("settings.sync", "Channel display sync",
1337
                                    RadioSettingValueList(
1338
                                        LIST_SYNC,
1339
                                        LIST_SYNC[_mem.settings.sync]))
1340
                basic.append(sync)
1341
            else:
1342
                sync = RadioSetting("settings.sync", "A/B channel sync",
1343
                                    RadioSettingValueBoolean(
1344
                                        _mem.settings.sync))
1345
                basic.append(sync)
1346
        else:
1347
            autolk = RadioSetting("settings.sync", "Auto keylock",
1348
                                  RadioSettingValueBoolean(
1349
                                      _mem.settings.sync))
1350
            basic.append(autolk)
1351

    
1352
        if not self.COLOR_LCD:
1353
            ponmsg = RadioSetting("settings.ponmsg", "Power-on message",
1354
                                  RadioSettingValueList(
1355
                                      LIST_PONMSG,
1356
                                      LIST_PONMSG[_mem.settings.ponmsg]))
1357
            basic.append(ponmsg)
1358

    
1359
        if self.COLOR_LCD and not (self.COLOR_LCD2 or self.COLOR_LCD3):
1360
            mainfc = RadioSetting("settings.mainfc",
1361
                                  "Main LCD foreground color",
1362
                                  RadioSettingValueList(
1363
                                      LIST_COLOR9,
1364
                                      LIST_COLOR9[_mem.settings.mainfc]))
1365
            basic.append(mainfc)
1366

    
1367
            mainbc = RadioSetting("settings.mainbc",
1368
                                  "Main LCD background color",
1369
                                  RadioSettingValueList(
1370
                                      LIST_COLOR9,
1371
                                      LIST_COLOR9[_mem.settings.mainbc]))
1372
            basic.append(mainbc)
1373

    
1374
            menufc = RadioSetting("settings.menufc", "Menu foreground color",
1375
                                  RadioSettingValueList(
1376
                                      LIST_COLOR9,
1377
                                      LIST_COLOR9[_mem.settings.menufc]))
1378
            basic.append(menufc)
1379

    
1380
            menubc = RadioSetting("settings.menubc", "Menu background color",
1381
                                  RadioSettingValueList(
1382
                                      LIST_COLOR9,
1383
                                      LIST_COLOR9[_mem.settings.menubc]))
1384
            basic.append(menubc)
1385

    
1386
            stafc = RadioSetting("settings.stafc",
1387
                                 "Top status foreground color",
1388
                                 RadioSettingValueList(
1389
                                     LIST_COLOR9,
1390
                                     LIST_COLOR9[_mem.settings.stafc]))
1391
            basic.append(stafc)
1392

    
1393
            stabc = RadioSetting("settings.stabc",
1394
                                 "Top status background color",
1395
                                 RadioSettingValueList(
1396
                                     LIST_COLOR9,
1397
                                     LIST_COLOR9[_mem.settings.stabc]))
1398
            basic.append(stabc)
1399

    
1400
            sigfc = RadioSetting("settings.sigfc",
1401
                                 "Bottom status foreground color",
1402
                                 RadioSettingValueList(
1403
                                     LIST_COLOR9,
1404
                                     LIST_COLOR9[_mem.settings.sigfc]))
1405
            basic.append(sigfc)
1406

    
1407
            sigbc = RadioSetting("settings.sigbc",
1408
                                 "Bottom status background color",
1409
                                 RadioSettingValueList(
1410
                                     LIST_COLOR9,
1411
                                     LIST_COLOR9[_mem.settings.sigbc]))
1412
            basic.append(sigbc)
1413

    
1414
            rxfc = RadioSetting("settings.rxfc", "Receiving character color",
1415
                                RadioSettingValueList(
1416
                                    LIST_COLOR9,
1417
                                    LIST_COLOR9[_mem.settings.rxfc]))
1418
            basic.append(rxfc)
1419

    
1420
            txfc = RadioSetting("settings.txfc",
1421
                                "Transmitting character color",
1422
                                RadioSettingValueList(
1423
                                    LIST_COLOR9,
1424
                                    LIST_COLOR9[_mem.settings.txfc]))
1425
            basic.append(txfc)
1426

    
1427
            txdisp = RadioSetting("settings.txdisp",
1428
                                  "Transmitting status display",
1429
                                  RadioSettingValueList(
1430
                                      LIST_TXDISP,
1431
                                      LIST_TXDISP[_mem.settings.txdisp]))
1432
            basic.append(txdisp)
1433
        elif self.COLOR_LCD2 or self.COLOR_LCD3:
1434
            stfc = RadioSetting("settings.stfc",
1435
                                "ST-FC",
1436
                                RadioSettingValueList(
1437
                                    LIST_COLOR8,
1438
                                    LIST_COLOR8[_mem.settings.stfc]))
1439
            basic.append(stfc)
1440

    
1441
            mffc = RadioSetting("settings.mffc",
1442
                                "MF-FC",
1443
                                RadioSettingValueList(
1444
                                    LIST_COLOR8,
1445
                                    LIST_COLOR8[_mem.settings.mffc]))
1446
            basic.append(mffc)
1447

    
1448
            sfafc = RadioSetting("settings.sfafc",
1449
                                 "SFA-FC",
1450
                                 RadioSettingValueList(
1451
                                     LIST_COLOR8,
1452
                                     LIST_COLOR8[_mem.settings.sfafc]))
1453
            basic.append(sfafc)
1454

    
1455
            sfbfc = RadioSetting("settings.sfbfc",
1456
                                 "SFB-FC",
1457
                                 RadioSettingValueList(
1458
                                     LIST_COLOR8,
1459
                                     LIST_COLOR8[_mem.settings.sfbfc]))
1460
            basic.append(sfbfc)
1461

    
1462
            sfcfc = RadioSetting("settings.sfcfc",
1463
                                 "SFC-FC",
1464
                                 RadioSettingValueList(
1465
                                     LIST_COLOR8,
1466
                                     LIST_COLOR8[_mem.settings.sfcfc]))
1467
            basic.append(sfcfc)
1468

    
1469
            sfdfc = RadioSetting("settings.sfdfc",
1470
                                 "SFD-FC",
1471
                                 RadioSettingValueList(
1472
                                     LIST_COLOR8,
1473
                                     LIST_COLOR8[_mem.settings.sfdfc]))
1474
            basic.append(sfdfc)
1475

    
1476
            subfc = RadioSetting("settings.subfc",
1477
                                 "SUB-FC",
1478
                                 RadioSettingValueList(
1479
                                     LIST_COLOR8,
1480
                                     LIST_COLOR8[_mem.settings.subfc]))
1481
            basic.append(subfc)
1482

    
1483
            fmfc = RadioSetting("settings.fmfc",
1484
                                "FM-FC",
1485
                                RadioSettingValueList(
1486
                                    LIST_COLOR8,
1487
                                    LIST_COLOR8[_mem.settings.fmfc]))
1488
            basic.append(fmfc)
1489

    
1490
            sigfc = RadioSetting("settings.sigfc",
1491
                                 "SIG-FC",
1492
                                 RadioSettingValueList(
1493
                                     LIST_COLOR8,
1494
                                     LIST_COLOR8[_mem.settings.sigfc]))
1495
            basic.append(sigfc)
1496

    
1497
            if not self.MODEL == "KT-8R":
1498
                modfc = RadioSetting("settings.modfc",
1499
                                     "MOD-FC",
1500
                                     RadioSettingValueList(
1501
                                         LIST_COLOR8,
1502
                                         LIST_COLOR8[_mem.settings.modfc]))
1503
                basic.append(modfc)
1504

    
1505
            menufc = RadioSetting("settings.menufc",
1506
                                  "MENUFC",
1507
                                  RadioSettingValueList(
1508
                                      LIST_COLOR8,
1509
                                      LIST_COLOR8[_mem.settings.menufc]))
1510
            basic.append(menufc)
1511

    
1512
            txfc = RadioSetting("settings.txfc",
1513
                                "TX-FC",
1514
                                RadioSettingValueList(
1515
                                    LIST_COLOR8,
1516
                                    LIST_COLOR8[_mem.settings.txfc]))
1517
            basic.append(txfc)
1518

    
1519
            if self.MODEL == "KT-8R":
1520
                rxfc = RadioSetting("settings.rxfc",
1521
                                    "RX-FC",
1522
                                    RadioSettingValueList(
1523
                                        LIST_COLOR8,
1524
                                        LIST_COLOR8[_mem.settings.rxfc]))
1525
                basic.append(rxfc)
1526

    
1527
            if not self.MODEL == "KT-8R":
1528
                txdisp = RadioSetting("settings.txdisp",
1529
                                      "Transmitting status display",
1530
                                      RadioSettingValueList(
1531
                                          LIST_TXDISP,
1532
                                          LIST_TXDISP[_mem.settings.txdisp]))
1533
                basic.append(txdisp)
1534
        else:
1535
            wtled = RadioSetting("settings.wtled", "Standby backlight Color",
1536
                                 RadioSettingValueList(
1537
                                     LIST_COLOR4,
1538
                                     LIST_COLOR4[_mem.settings.wtled]))
1539
            basic.append(wtled)
1540

    
1541
            rxled = RadioSetting("settings.rxled", "RX backlight Color",
1542
                                 RadioSettingValueList(
1543
                                     LIST_COLOR4,
1544
                                     LIST_COLOR4[_mem.settings.rxled]))
1545
            basic.append(rxled)
1546

    
1547
            txled = RadioSetting("settings.txled", "TX backlight Color",
1548
                                 RadioSettingValueList(
1549
                                     LIST_COLOR4,
1550
                                     LIST_COLOR4[_mem.settings.txled]))
1551
            basic.append(txled)
1552

    
1553
        anil = RadioSetting("settings.anil", "ANI length",
1554
                            RadioSettingValueList(
1555
                                LIST_ANIL,
1556
                                LIST_ANIL[_mem.settings.anil]))
1557
        basic.append(anil)
1558

    
1559
        reps = RadioSetting("settings.reps", "Relay signal (tone burst)",
1560
                            RadioSettingValueList(
1561
                                LIST_REPS,
1562
                                LIST_REPS[_mem.settings.reps]))
1563
        basic.append(reps)
1564

    
1565
        if not self.MODEL == "GMRS-50X1" and not self.MODEL == "KT-8R":
1566
            repm = RadioSetting("settings.repm", "Relay condition",
1567
                                RadioSettingValueList(
1568
                                    LIST_REPM,
1569
                                    LIST_REPM[_mem.settings.repm]))
1570
            basic.append(repm)
1571

    
1572
        if self.VENDOR == "BTECH" or self.COLOR_LCD:
1573
            if self.COLOR_LCD:
1574
                tmrmr = RadioSetting("settings.tmrmr", "TMR return time",
1575
                                     RadioSettingValueList(
1576
                                         LIST_OFF1TO50,
1577
                                         LIST_OFF1TO50[_mem.settings.tmrmr]))
1578
                basic.append(tmrmr)
1579
            else:
1580
                tdrab = RadioSetting("settings.tdrab", "TDR return time",
1581
                                     RadioSettingValueList(
1582
                                         LIST_OFF1TO50,
1583
                                         LIST_OFF1TO50[_mem.settings.tdrab]))
1584
                basic.append(tdrab)
1585

    
1586
            ste = RadioSetting("settings.ste", "Squelch tail eliminate",
1587
                               RadioSettingValueBoolean(_mem.settings.ste))
1588
            basic.append(ste)
1589

    
1590
            rpste = RadioSetting("settings.rpste", "Repeater STE",
1591
                                 RadioSettingValueList(
1592
                                     LIST_OFF1TO9,
1593
                                     LIST_OFF1TO9[_mem.settings.rpste]))
1594
            basic.append(rpste)
1595

    
1596
            rptdl = RadioSetting("settings.rptdl", "Repeater STE delay",
1597
                                 RadioSettingValueList(
1598
                                     LIST_RPTDL,
1599
                                     LIST_RPTDL[_mem.settings.rptdl]))
1600
            basic.append(rptdl)
1601

    
1602
        if self.MODEL == "DB25-G":
1603
            mgain = RadioSetting("settings.mgain", "Auto power-on",
1604
                                 RadioSettingValueBoolean(_mem.settings.mgain))
1605
            basic.append(mgain)
1606

    
1607
        if str(_mem.fingerprint.fp) in BTECH3:
1608
            mgain = RadioSetting("settings.mgain", "Mic gain",
1609
                                 RadioSettingValueInteger(0, 120,
1610
                                                          _mem.settings.mgain))
1611
            basic.append(mgain)
1612

    
1613
        if str(_mem.fingerprint.fp) in BTECH3 or self.COLOR_LCD:
1614
            dtmfg = RadioSetting("settings.dtmfg", "DTMF gain",
1615
                                 RadioSettingValueInteger(0, 60,
1616
                                                          _mem.settings.dtmfg))
1617
            basic.append(dtmfg)
1618

    
1619
        if self.VENDOR == "BTECH" and self.COLOR_LCD:
1620
            mgain = RadioSetting("settings.mgain", "Mic gain",
1621
                                 RadioSettingValueInteger(0, 120,
1622
                                                          _mem.settings.mgain))
1623
            basic.append(mgain)
1624

    
1625
            skiptx = RadioSetting("settings.skiptx", "Skip TX",
1626
                                  RadioSettingValueList(
1627
                                      LIST_SKIPTX,
1628
                                      LIST_SKIPTX[_mem.settings.skiptx]))
1629
            basic.append(skiptx)
1630

    
1631
            scmode = RadioSetting("settings.scmode", "Scan mode",
1632
                                  RadioSettingValueList(
1633
                                      LIST_SCMODE,
1634
                                      LIST_SCMODE[_mem.settings.scmode]))
1635
            basic.append(scmode)
1636

    
1637
        if self.MODEL == "KT-8R":
1638
            tmrtx = RadioSetting("settings.tmrtx", "TX in multi-standby",
1639
                                 RadioSettingValueList(
1640
                                     LIST_TMRTX,
1641
                                     LIST_TMRTX[_mem.settings.tmrtx]))
1642
            basic.append(tmrtx)
1643

    
1644
        # Advanced
1645
        def _filter(name):
1646
            filtered = ""
1647
            for char in str(name):
1648
                if char in VALID_CHARS:
1649
                    filtered += char
1650
                else:
1651
                    filtered += " "
1652
            return filtered
1653

    
1654
        if self.COLOR_LCD and not (self.COLOR_LCD2 or self.COLOR_LCD3):
1655
            _msg = self._memobj.poweron_msg
1656
            line1 = RadioSetting("poweron_msg.line1",
1657
                                 "Power-on message line 1",
1658
                                 RadioSettingValueString(0, 8, _filter(
1659
                                                         _msg.line1)))
1660
            advanced.append(line1)
1661
            line2 = RadioSetting("poweron_msg.line2",
1662
                                 "Power-on message line 2",
1663
                                 RadioSettingValueString(0, 8, _filter(
1664
                                                         _msg.line2)))
1665
            advanced.append(line2)
1666
            line3 = RadioSetting("poweron_msg.line3",
1667
                                 "Power-on message line 3",
1668
                                 RadioSettingValueString(0, 8, _filter(
1669
                                                         _msg.line3)))
1670
            advanced.append(line3)
1671
            line4 = RadioSetting("poweron_msg.line4",
1672
                                 "Power-on message line 4",
1673
                                 RadioSettingValueString(0, 8, _filter(
1674
                                                         _msg.line4)))
1675
            advanced.append(line4)
1676
            line5 = RadioSetting("poweron_msg.line5",
1677
                                 "Power-on message line 5",
1678
                                 RadioSettingValueString(0, 8, _filter(
1679
                                                         _msg.line5)))
1680
            advanced.append(line5)
1681
            line6 = RadioSetting("poweron_msg.line6",
1682
                                 "Power-on message line 6",
1683
                                 RadioSettingValueString(0, 8, _filter(
1684
                                                         _msg.line6)))
1685
            advanced.append(line6)
1686
            line7 = RadioSetting("poweron_msg.line7",
1687
                                 "Power-on message line 7",
1688
                                 RadioSettingValueString(0, 8, _filter(
1689
                                                         _msg.line7)))
1690
            advanced.append(line7)
1691
            line8 = RadioSetting("poweron_msg.line8", "Static message",
1692
                                 RadioSettingValueString(0, 8, _filter(
1693
                                                         _msg.line8)))
1694
            advanced.append(line8)
1695
        elif self.COLOR_LCD2 or self.COLOR_LCD3:
1696
            _msg = self._memobj.static_msg
1697
            line = RadioSetting("static_msg.line", "Static message",
1698
                                RadioSettingValueString(0, 16, _filter(
1699
                                    _msg.line)))
1700
            advanced.append(line)
1701
        else:
1702
            _msg = self._memobj.poweron_msg
1703
            line1 = RadioSetting("poweron_msg.line1",
1704
                                 "Power-on message line 1",
1705
                                 RadioSettingValueString(0, 6, _filter(
1706
                                                         _msg.line1)))
1707
            advanced.append(line1)
1708
            line2 = RadioSetting("poweron_msg.line2",
1709
                                 "Power-on message line 2",
1710
                                 RadioSettingValueString(0, 6, _filter(
1711
                                                         _msg.line2)))
1712
            advanced.append(line2)
1713

    
1714
        if self.MODEL in ("UV-2501", "UV-5001"):
1715
            vfomren = RadioSetting("settings2.vfomren", "VFO/MR switching",
1716
                                   RadioSettingValueBoolean(
1717
                                       _mem.settings2.vfomren))
1718
            advanced.append(vfomren)
1719

    
1720
            reseten = RadioSetting("settings2.reseten", "RESET",
1721
                                   RadioSettingValueBoolean(
1722
                                       _mem.settings2.reseten))
1723
            advanced.append(reseten)
1724

    
1725
            menuen = RadioSetting("settings2.menuen", "Menu",
1726
                                  RadioSettingValueBoolean(
1727
                                      _mem.settings2.menuen))
1728
            advanced.append(menuen)
1729

    
1730
        # Other
1731
        def convert_bytes_to_limit(bytes):
1732
            limit = ""
1733
            for byte in bytes:
1734
                if byte < 10:
1735
                    limit += chr(byte + 0x30)
1736
                else:
1737
                    break
1738
            return limit
1739

    
1740
        if self.MODEL in ["UV-2501+220", "KT8900R"]:
1741
            _ranges = self._memobj.ranges220
1742
            ranges = "ranges220"
1743
        else:
1744
            _ranges = self._memobj.ranges
1745
            ranges = "ranges"
1746

    
1747
        _limit = convert_bytes_to_limit(_ranges.vhf_low)
1748
        val = RadioSettingValueString(0, 3, _limit)
1749
        val.set_mutable(False)
1750
        vhf_low = RadioSetting("%s.vhf_low" % ranges, "VHF low", val)
1751
        other.append(vhf_low)
1752

    
1753
        _limit = convert_bytes_to_limit(_ranges.vhf_high)
1754
        val = RadioSettingValueString(0, 3, _limit)
1755
        val.set_mutable(False)
1756
        vhf_high = RadioSetting("%s.vhf_high" % ranges, "VHF high", val)
1757
        other.append(vhf_high)
1758

    
1759
        if self.BANDS == 3 or self.BANDS == 4:
1760
            _limit = convert_bytes_to_limit(_ranges.vhf2_low)
1761
            val = RadioSettingValueString(0, 3, _limit)
1762
            val.set_mutable(False)
1763
            vhf2_low = RadioSetting("%s.vhf2_low" % ranges, "VHF2 low", val)
1764
            other.append(vhf2_low)
1765

    
1766
            _limit = convert_bytes_to_limit(_ranges.vhf2_high)
1767
            val = RadioSettingValueString(0, 3, _limit)
1768
            val.set_mutable(False)
1769
            vhf2_high = RadioSetting("%s.vhf2_high" % ranges, "VHF2 high", val)
1770
            other.append(vhf2_high)
1771

    
1772
        _limit = convert_bytes_to_limit(_ranges.uhf_low)
1773
        val = RadioSettingValueString(0, 3, _limit)
1774
        val.set_mutable(False)
1775
        uhf_low = RadioSetting("%s.uhf_low" % ranges, "UHF low", val)
1776
        other.append(uhf_low)
1777

    
1778
        _limit = convert_bytes_to_limit(_ranges.uhf_high)
1779
        val = RadioSettingValueString(0, 3, _limit)
1780
        val.set_mutable(False)
1781
        uhf_high = RadioSetting("%s.uhf_high" % ranges, "UHF high", val)
1782
        other.append(uhf_high)
1783

    
1784
        if self.BANDS == 4:
1785
            _limit = convert_bytes_to_limit(_ranges.uhf2_low)
1786
            val = RadioSettingValueString(0, 3, _limit)
1787
            val.set_mutable(False)
1788
            uhf2_low = RadioSetting("%s.uhf2_low" % ranges, "UHF2 low", val)
1789
            other.append(uhf2_low)
1790

    
1791
            _limit = convert_bytes_to_limit(_ranges.uhf2_high)
1792
            val = RadioSettingValueString(0, 3, _limit)
1793
            val.set_mutable(False)
1794
            uhf2_high = RadioSetting("%s.uhf2_high" % ranges, "UHF2 high", val)
1795
            other.append(uhf2_high)
1796

    
1797
        val = RadioSettingValueString(0, 6, _filter(_mem.fingerprint.fp))
1798
        val.set_mutable(False)
1799
        fp = RadioSetting("fingerprint.fp", "Fingerprint", val)
1800
        other.append(fp)
1801

    
1802
        # Work
1803
        if self.COLOR_LCD:
1804
            dispab = RadioSetting("settings2.dispab", "Display",
1805
                                  RadioSettingValueList(
1806
                                      LIST_ABCD,
1807
                                      LIST_ABCD[_mem.settings2.dispab]))
1808
            work.append(dispab)
1809
        else:
1810
            dispab = RadioSetting("settings2.dispab", "Display",
1811
                                  RadioSettingValueList(
1812
                                      LIST_AB,
1813
                                      LIST_AB[_mem.settings2.dispab]))
1814
            work.append(dispab)
1815

    
1816
        if self.COLOR_LCD:
1817
            vfomra = RadioSetting("settings2.vfomra", "VFO/MR A mode",
1818
                                  RadioSettingValueList(
1819
                                      LIST_VFOMR,
1820
                                      LIST_VFOMR[_mem.settings2.vfomra]))
1821
            work.append(vfomra)
1822

    
1823
            vfomrb = RadioSetting("settings2.vfomrb", "VFO/MR B mode",
1824
                                  RadioSettingValueList(
1825
                                      LIST_VFOMR,
1826
                                      LIST_VFOMR[_mem.settings2.vfomrb]))
1827
            work.append(vfomrb)
1828

    
1829
            vfomrc = RadioSetting("settings2.vfomrc", "VFO/MR C mode",
1830
                                  RadioSettingValueList(
1831
                                      LIST_VFOMR,
1832
                                      LIST_VFOMR[_mem.settings2.vfomrc]))
1833
            work.append(vfomrc)
1834

    
1835
            vfomrd = RadioSetting("settings2.vfomrd", "VFO/MR D mode",
1836
                                  RadioSettingValueList(
1837
                                      LIST_VFOMR,
1838
                                      LIST_VFOMR[_mem.settings2.vfomrd]))
1839
            work.append(vfomrd)
1840
        else:
1841
            vfomr = RadioSetting("settings2.vfomr", "VFO/MR mode",
1842
                                 RadioSettingValueList(
1843
                                     LIST_VFOMR,
1844
                                     LIST_VFOMR[_mem.settings2.vfomr]))
1845
            work.append(vfomr)
1846

    
1847
        keylock = RadioSetting("settings2.keylock", "Keypad lock",
1848
                               RadioSettingValueBoolean(
1849
                                   _mem.settings2.keylock))
1850
        work.append(keylock)
1851

    
1852
        mrcha = RadioSetting("settings2.mrcha", "MR A channel",
1853
                             RadioSettingValueInteger(0, self._upper,
1854
                                                      _mem.settings2.mrcha))
1855
        work.append(mrcha)
1856

    
1857
        mrchb = RadioSetting("settings2.mrchb", "MR B channel",
1858
                             RadioSettingValueInteger(0, self._upper,
1859
                                                      _mem.settings2.mrchb))
1860
        work.append(mrchb)
1861

    
1862
        if self.COLOR_LCD:
1863
            mrchc = RadioSetting("settings2.mrchc", "MR C channel",
1864
                                 RadioSettingValueInteger(
1865
                                     0, self._upper, _mem.settings2.mrchc))
1866
            work.append(mrchc)
1867

    
1868
            mrchd = RadioSetting("settings2.mrchd", "MR D channel",
1869
                                 RadioSettingValueInteger(
1870
                                     0, self._upper, _mem.settings2.mrchd))
1871
            work.append(mrchd)
1872

    
1873
        def convert_bytes_to_freq(bytes):
1874
            real_freq = 0
1875
            for byte in bytes:
1876
                real_freq = (real_freq * 10) + byte
1877
            return chirp_common.format_freq(real_freq * 10)
1878

    
1879
        def my_validate(value):
1880
            _vhf_lower = int(convert_bytes_to_limit(_ranges.vhf_low))
1881
            _vhf_upper = int(convert_bytes_to_limit(_ranges.vhf_high))
1882
            _uhf_lower = int(convert_bytes_to_limit(_ranges.uhf_low))
1883
            _uhf_upper = int(convert_bytes_to_limit(_ranges.uhf_high))
1884
            if self.BANDS == 3 or self.BANDS == 4:
1885
                _vhf2_lower = int(convert_bytes_to_limit(_ranges.vhf2_low))
1886
                _vhf2_upper = int(convert_bytes_to_limit(_ranges.vhf2_high))
1887
            if self.BANDS == 4:
1888
                _uhf2_lower = int(convert_bytes_to_limit(_ranges.uhf2_low))
1889
                _uhf2_upper = int(convert_bytes_to_limit(_ranges.uhf2_high))
1890

    
1891
            value = chirp_common.parse_freq(value)
1892
            msg = ("Can't be less then %i.0000")
1893
            if value > 99000000 and value < _vhf_lower * 1000000:
1894
                raise InvalidValueError(msg % (_vhf_lower))
1895
            msg = ("Can't be betweeb %i.9975-%i.0000")
1896
            if self.BANDS == 2:
1897
                if (_vhf_upper + 1) * 1000000 <= value and \
1898
                        value < _uhf_lower * 1000000:
1899
                    raise InvalidValueError(msg % (_vhf_upper, _uhf_lower))
1900
            if self.BANDS == 3:
1901
                if (_vhf_upper + 1) * 1000000 <= value and \
1902
                        value < _vhf2_lower * 1000000:
1903
                    raise InvalidValueError(msg % (_vhf_upper, _vhf2_lower))
1904
                if (_vhf2_upper + 1) * 1000000 <= value and \
1905
                        value < _uhf_lower * 1000000:
1906
                    raise InvalidValueError(msg % (_vhf2_upper, _uhf_lower))
1907
            if self.BANDS == 4:
1908
                if (_vhf_upper + 1) * 1000000 <= value and \
1909
                        value < _vhf2_lower * 1000000:
1910
                    raise InvalidValueError(msg % (_vhf_upper, _vhf2_lower))
1911
                if (_vhf2_upper + 1) * 1000000 <= value and \
1912
                        value < _uhf2_lower * 1000000:
1913
                    raise InvalidValueError(msg % (_vhf2_upper, _uhf2_lower))
1914
                if (_uhf2_upper + 1) * 1000000 <= value and \
1915
                        value < _uhf_lower * 1000000:
1916
                    raise InvalidValueError(msg % (_uhf2_upper, _uhf_lower))
1917
            msg = ("Can't be greater then %i.9975")
1918
            if value > 99000000 and value >= _uhf_upper * 1000000:
1919
                raise InvalidValueError(msg % (_uhf_upper))
1920
            return chirp_common.format_freq(value)
1921

    
1922
        def apply_freq(setting, obj):
1923
            value = chirp_common.parse_freq(str(setting.value)) / 10
1924
            for i in range(7, -1, -1):
1925
                obj.freq[i] = value % 10
1926
                value /= 10
1927

    
1928
        val1a = RadioSettingValueString(0, 10, convert_bytes_to_freq(
1929
                                        _mem.vfo.a.freq))
1930
        val1a.set_validate_callback(my_validate)
1931
        vfoafreq = RadioSetting("vfo.a.freq", "VFO A frequency", val1a)
1932
        vfoafreq.set_apply_callback(apply_freq, _mem.vfo.a)
1933
        work.append(vfoafreq)
1934

    
1935
        val1b = RadioSettingValueString(0, 10, convert_bytes_to_freq(
1936
                                        _mem.vfo.b.freq))
1937
        val1b.set_validate_callback(my_validate)
1938
        vfobfreq = RadioSetting("vfo.b.freq", "VFO B frequency", val1b)
1939
        vfobfreq.set_apply_callback(apply_freq, _mem.vfo.b)
1940
        work.append(vfobfreq)
1941

    
1942
        if self.COLOR_LCD:
1943
            val1c = RadioSettingValueString(0, 10, convert_bytes_to_freq(
1944
                                            _mem.vfo.c.freq))
1945
            val1c.set_validate_callback(my_validate)
1946
            vfocfreq = RadioSetting("vfo.c.freq", "VFO C frequency", val1c)
1947
            vfocfreq.set_apply_callback(apply_freq, _mem.vfo.c)
1948
            work.append(vfocfreq)
1949

    
1950
            val1d = RadioSettingValueString(0, 10, convert_bytes_to_freq(
1951
                                            _mem.vfo.d.freq))
1952
            val1d.set_validate_callback(my_validate)
1953
            vfodfreq = RadioSetting("vfo.d.freq", "VFO D frequency", val1d)
1954
            vfodfreq.set_apply_callback(apply_freq, _mem.vfo.d)
1955
            work.append(vfodfreq)
1956

    
1957
        if not self.MODEL == "GMRS-50X1":
1958
            vfoashiftd = RadioSetting("vfo.a.shiftd", "VFO A shift",
1959
                                      RadioSettingValueList(
1960
                                          LIST_SHIFT,
1961
                                          LIST_SHIFT[_mem.vfo.a.shiftd]))
1962
            work.append(vfoashiftd)
1963

    
1964
            vfobshiftd = RadioSetting("vfo.b.shiftd", "VFO B shift",
1965
                                      RadioSettingValueList(
1966
                                          LIST_SHIFT,
1967
                                          LIST_SHIFT[_mem.vfo.b.shiftd]))
1968
            work.append(vfobshiftd)
1969

    
1970
            if self.COLOR_LCD:
1971
                vfocshiftd = RadioSetting("vfo.c.shiftd", "VFO C shift",
1972
                                          RadioSettingValueList(
1973
                                              LIST_SHIFT,
1974
                                              LIST_SHIFT[_mem.vfo.c.shiftd]))
1975
                work.append(vfocshiftd)
1976

    
1977
                vfodshiftd = RadioSetting("vfo.d.shiftd", "VFO D shift",
1978
                                          RadioSettingValueList(
1979
                                              LIST_SHIFT,
1980
                                              LIST_SHIFT[_mem.vfo.d.shiftd]))
1981
                work.append(vfodshiftd)
1982

    
1983
        def convert_bytes_to_offset(bytes):
1984
            real_offset = 0
1985
            for byte in bytes:
1986
                real_offset = (real_offset * 10) + byte
1987
            return chirp_common.format_freq(real_offset * 1000)
1988

    
1989
        def apply_offset(setting, obj):
1990
            value = chirp_common.parse_freq(str(setting.value)) / 1000
1991
            for i in range(5, -1, -1):
1992
                obj.offset[i] = value % 10
1993
                value /= 10
1994

    
1995
        if not self.MODEL == "GMRS-50X1":
1996
            if self.COLOR_LCD:
1997
                val1a = RadioSettingValueString(0, 10, convert_bytes_to_offset(
1998
                                                _mem.vfo.a.offset))
1999
                vfoaoffset = RadioSetting("vfo.a.offset",
2000
                                          "VFO A offset (0.000-999.999)",
2001
                                          val1a)
2002
                vfoaoffset.set_apply_callback(apply_offset, _mem.vfo.a)
2003
                work.append(vfoaoffset)
2004

    
2005
                val1b = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2006
                                                _mem.vfo.b.offset))
2007
                vfoboffset = RadioSetting("vfo.b.offset",
2008
                                          "VFO B offset (0.000-999.999)",
2009
                                          val1b)
2010
                vfoboffset.set_apply_callback(apply_offset, _mem.vfo.b)
2011
                work.append(vfoboffset)
2012

    
2013
                val1c = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2014
                                                _mem.vfo.c.offset))
2015
                vfocoffset = RadioSetting("vfo.c.offset",
2016
                                          "VFO C offset (0.000-999.999)",
2017
                                          val1c)
2018
                vfocoffset.set_apply_callback(apply_offset, _mem.vfo.c)
2019
                work.append(vfocoffset)
2020

    
2021
                val1d = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2022
                                                _mem.vfo.d.offset))
2023
                vfodoffset = RadioSetting("vfo.d.offset",
2024
                                          "VFO D offset (0.000-999.999)",
2025
                                          val1d)
2026
                vfodoffset.set_apply_callback(apply_offset, _mem.vfo.d)
2027
                work.append(vfodoffset)
2028
            else:
2029
                val1a = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2030
                                                _mem.vfo.a.offset))
2031
                vfoaoffset = RadioSetting("vfo.a.offset",
2032
                                          "VFO A offset (0.000-99.999)", val1a)
2033
                vfoaoffset.set_apply_callback(apply_offset, _mem.vfo.a)
2034
                work.append(vfoaoffset)
2035

    
2036
                val1b = RadioSettingValueString(0, 10, convert_bytes_to_offset(
2037
                                                _mem.vfo.b.offset))
2038
                vfoboffset = RadioSetting("vfo.b.offset",
2039
                                          "VFO B offset (0.000-99.999)", val1b)
2040
                vfoboffset.set_apply_callback(apply_offset, _mem.vfo.b)
2041
                work.append(vfoboffset)
2042

    
2043
        if not self.MODEL == "GMRS-50X1":
2044
            vfoatxp = RadioSetting("vfo.a.power", "VFO A power",
2045
                                   RadioSettingValueList(
2046
                                       LIST_TXP,
2047
                                       LIST_TXP[_mem.vfo.a.power]))
2048
            work.append(vfoatxp)
2049

    
2050
            vfobtxp = RadioSetting("vfo.b.power", "VFO B power",
2051
                                   RadioSettingValueList(
2052
                                       LIST_TXP,
2053
                                       LIST_TXP[_mem.vfo.b.power]))
2054
            work.append(vfobtxp)
2055

    
2056
            if self.COLOR_LCD:
2057
                vfoctxp = RadioSetting("vfo.c.power", "VFO C power",
2058
                                       RadioSettingValueList(
2059
                                           LIST_TXP,
2060
                                           LIST_TXP[_mem.vfo.c.power]))
2061
                work.append(vfoctxp)
2062

    
2063
                vfodtxp = RadioSetting("vfo.d.power", "VFO D power",
2064
                                       RadioSettingValueList(
2065
                                           LIST_TXP,
2066
                                           LIST_TXP[_mem.vfo.d.power]))
2067
                work.append(vfodtxp)
2068

    
2069
        if not self.MODEL == "GMRS-50X1":
2070
            vfoawide = RadioSetting("vfo.a.wide", "VFO A bandwidth",
2071
                                    RadioSettingValueList(
2072
                                        LIST_WIDE,
2073
                                        LIST_WIDE[_mem.vfo.a.wide]))
2074
            work.append(vfoawide)
2075

    
2076
            vfobwide = RadioSetting("vfo.b.wide", "VFO B bandwidth",
2077
                                    RadioSettingValueList(
2078
                                        LIST_WIDE,
2079
                                        LIST_WIDE[_mem.vfo.b.wide]))
2080
            work.append(vfobwide)
2081

    
2082
            if self.COLOR_LCD:
2083
                vfocwide = RadioSetting("vfo.c.wide", "VFO C bandwidth",
2084
                                        RadioSettingValueList(
2085
                                            LIST_WIDE,
2086
                                            LIST_WIDE[_mem.vfo.c.wide]))
2087
                work.append(vfocwide)
2088

    
2089
                vfodwide = RadioSetting("vfo.d.wide", "VFO D bandwidth",
2090
                                        RadioSettingValueList(
2091
                                            LIST_WIDE,
2092
                                            LIST_WIDE[_mem.vfo.d.wide]))
2093
                work.append(vfodwide)
2094

    
2095
        vfoastep = RadioSetting("vfo.a.step", "VFO A step",
2096
                                RadioSettingValueList(
2097
                                    LIST_STEP,
2098
                                    LIST_STEP[_mem.vfo.a.step]))
2099
        work.append(vfoastep)
2100

    
2101
        vfobstep = RadioSetting("vfo.b.step", "VFO B step",
2102
                                RadioSettingValueList(
2103
                                    LIST_STEP,
2104
                                    LIST_STEP[_mem.vfo.b.step]))
2105
        work.append(vfobstep)
2106

    
2107
        if self.COLOR_LCD:
2108
            vfocstep = RadioSetting("vfo.c.step", "VFO C step",
2109
                                    RadioSettingValueList(
2110
                                        LIST_STEP,
2111
                                        LIST_STEP[_mem.vfo.c.step]))
2112
            work.append(vfocstep)
2113

    
2114
            vfodstep = RadioSetting("vfo.d.step", "VFO D step",
2115
                                    RadioSettingValueList(
2116
                                        LIST_STEP,
2117
                                        LIST_STEP[_mem.vfo.d.step]))
2118
            work.append(vfodstep)
2119

    
2120
        vfoaoptsig = RadioSetting("vfo.a.optsig", "VFO A optional signal",
2121
                                  RadioSettingValueList(
2122
                                      OPTSIG_LIST,
2123
                                      OPTSIG_LIST[_mem.vfo.a.optsig]))
2124
        work.append(vfoaoptsig)
2125

    
2126
        vfoboptsig = RadioSetting("vfo.b.optsig", "VFO B optional signal",
2127
                                  RadioSettingValueList(
2128
                                      OPTSIG_LIST,
2129
                                      OPTSIG_LIST[_mem.vfo.b.optsig]))
2130
        work.append(vfoboptsig)
2131

    
2132
        if self.COLOR_LCD:
2133
            vfocoptsig = RadioSetting("vfo.c.optsig", "VFO C optional signal",
2134
                                      RadioSettingValueList(
2135
                                          OPTSIG_LIST,
2136
                                          OPTSIG_LIST[_mem.vfo.c.optsig]))
2137
            work.append(vfocoptsig)
2138

    
2139
            vfodoptsig = RadioSetting("vfo.d.optsig", "VFO D optional signal",
2140
                                      RadioSettingValueList(
2141
                                          OPTSIG_LIST,
2142
                                          OPTSIG_LIST[_mem.vfo.d.optsig]))
2143
            work.append(vfodoptsig)
2144

    
2145
        vfoaspmute = RadioSetting("vfo.a.spmute", "VFO A speaker mute",
2146
                                  RadioSettingValueList(
2147
                                      SPMUTE_LIST,
2148
                                      SPMUTE_LIST[_mem.vfo.a.spmute]))
2149
        work.append(vfoaspmute)
2150

    
2151
        vfobspmute = RadioSetting("vfo.b.spmute", "VFO B speaker mute",
2152
                                  RadioSettingValueList(
2153
                                      SPMUTE_LIST,
2154
                                      SPMUTE_LIST[_mem.vfo.b.spmute]))
2155
        work.append(vfobspmute)
2156

    
2157
        if self.COLOR_LCD:
2158
            vfocspmute = RadioSetting("vfo.c.spmute", "VFO C speaker mute",
2159
                                      RadioSettingValueList(
2160
                                          SPMUTE_LIST,
2161
                                          SPMUTE_LIST[_mem.vfo.c.spmute]))
2162
            work.append(vfocspmute)
2163

    
2164
            vfodspmute = RadioSetting("vfo.d.spmute", "VFO D speaker mute",
2165
                                      RadioSettingValueList(
2166
                                          SPMUTE_LIST,
2167
                                          SPMUTE_LIST[_mem.vfo.d.spmute]))
2168
            work.append(vfodspmute)
2169

    
2170
        if not self.COLOR_LCD or \
2171
                (self.COLOR_LCD and not self.VENDOR == "BTECH"):
2172
            vfoascr = RadioSetting("vfo.a.scramble", "VFO A scramble",
2173
                                   RadioSettingValueBoolean(
2174
                                       _mem.vfo.a.scramble))
2175
            work.append(vfoascr)
2176

    
2177
            vfobscr = RadioSetting("vfo.b.scramble", "VFO B scramble",
2178
                                   RadioSettingValueBoolean(
2179
                                       _mem.vfo.b.scramble))
2180
            work.append(vfobscr)
2181

    
2182
        if self.COLOR_LCD and not self.VENDOR == "BTECH":
2183
            vfocscr = RadioSetting("vfo.c.scramble", "VFO C scramble",
2184
                                   RadioSettingValueBoolean(
2185
                                       _mem.vfo.c.scramble))
2186
            work.append(vfocscr)
2187

    
2188
            vfodscr = RadioSetting("vfo.d.scramble", "VFO D scramble",
2189
                                   RadioSettingValueBoolean(
2190
                                       _mem.vfo.d.scramble))
2191
            work.append(vfodscr)
2192

    
2193
        if not self.MODEL == "GMRS-50X1":
2194
            vfoascode = RadioSetting("vfo.a.scode", "VFO A PTT-ID",
2195
                                     RadioSettingValueList(
2196
                                         PTTIDCODE_LIST,
2197
                                         PTTIDCODE_LIST[_mem.vfo.a.scode]))
2198
            work.append(vfoascode)
2199

    
2200
            vfobscode = RadioSetting("vfo.b.scode", "VFO B PTT-ID",
2201
                                     RadioSettingValueList(
2202
                                         PTTIDCODE_LIST,
2203
                                         PTTIDCODE_LIST[_mem.vfo.b.scode]))
2204
            work.append(vfobscode)
2205

    
2206
            if self.COLOR_LCD:
2207
                vfocscode = RadioSetting("vfo.c.scode", "VFO C PTT-ID",
2208
                                         RadioSettingValueList(
2209
                                             PTTIDCODE_LIST,
2210
                                             PTTIDCODE_LIST[_mem.vfo.c.scode]))
2211
                work.append(vfocscode)
2212

    
2213
                vfodscode = RadioSetting("vfo.d.scode", "VFO D PTT-ID",
2214
                                         RadioSettingValueList(
2215
                                             PTTIDCODE_LIST,
2216
                                             PTTIDCODE_LIST[_mem.vfo.d.scode]))
2217
                work.append(vfodscode)
2218

    
2219
        if not self.MODEL == "GMRS-50X1":
2220
            pttid = RadioSetting("settings.pttid", "PTT ID",
2221
                                 RadioSettingValueList(
2222
                                     PTTID_LIST,
2223
                                     PTTID_LIST[_mem.settings.pttid]))
2224
            work.append(pttid)
2225

    
2226
        if not self.COLOR_LCD:
2227
            # FM presets
2228
            fm_presets = RadioSettingGroup("fm_presets", "FM Presets")
2229
            top.append(fm_presets)
2230

    
2231
            def fm_validate(value):
2232
                if value == 0:
2233
                    return chirp_common.format_freq(value)
2234
                if not (87.5 <= value and value <= 108.0):  # 87.5-108MHz
2235
                    msg = ("FM-Preset-Frequency: " +
2236
                           "Must be between 87.5 and 108 MHz")
2237
                    raise InvalidValueError(msg)
2238
                return value
2239

    
2240
            def apply_fm_preset_name(setting, obj):
2241
                valstring = str(setting.value)
2242
                for i in range(0, 6):
2243
                    if valstring[i] in VALID_CHARS:
2244
                        obj[i] = valstring[i]
2245
                    else:
2246
                        obj[i] = '0xff'
2247

    
2248
            def apply_fm_freq(setting, obj):
2249
                value = chirp_common.parse_freq(str(setting.value)) / 10
2250
                for i in range(7, -1, -1):
2251
                    obj.freq[i] = value % 10
2252
                    value /= 10
2253

    
2254
            _presets = self._memobj.fm_radio_preset
2255
            i = 1
2256
            for preset in _presets:
2257
                line = RadioSetting("fm_presets_" + str(i),
2258
                                    "Station name " + str(i),
2259
                                    RadioSettingValueString(0, 6, _filter(
2260
                                        preset.broadcast_station_name)))
2261
                line.set_apply_callback(apply_fm_preset_name,
2262
                                        preset.broadcast_station_name)
2263

    
2264
                val = RadioSettingValueFloat(0, 108,
2265
                                             convert_bytes_to_freq(
2266
                                                 preset.freq))
2267
                fmfreq = RadioSetting("fm_presets_" + str(i) + "_freq",
2268
                                      "Frequency " + str(i), val)
2269
                val.set_validate_callback(fm_validate)
2270
                fmfreq.set_apply_callback(apply_fm_freq, preset)
2271
                fm_presets.append(line)
2272
                fm_presets.append(fmfreq)
2273

    
2274
                i = i + 1
2275

    
2276
        # DTMF-Setting
2277
        dtmf_enc_settings = RadioSettingGroup("dtmf_enc_settings",
2278
                                              "DTMF Encoding Settings")
2279
        dtmf_dec_settings = RadioSettingGroup("dtmf_dec_settings",
2280
                                              "DTMF Decoding Settings")
2281
        top.append(dtmf_enc_settings)
2282
        top.append(dtmf_dec_settings)
2283
        txdisable = RadioSetting("dtmf_settings.txdisable",
2284
                                 "TX-Disable",
2285
                                 RadioSettingValueBoolean(
2286
                                     _mem.dtmf_settings.txdisable))
2287
        dtmf_enc_settings.append(txdisable)
2288

    
2289
        rxdisable = RadioSetting("dtmf_settings.rxdisable",
2290
                                 "RX-Disable",
2291
                                 RadioSettingValueBoolean(
2292
                                     _mem.dtmf_settings.rxdisable))
2293
        dtmf_enc_settings.append(rxdisable)
2294

    
2295
        if _mem.dtmf_settings.dtmfspeed_on > 0x0F:
2296
            val = 0x03
2297
        else:
2298
            val = _mem.dtmf_settings.dtmfspeed_on
2299
        dtmfspeed_on = RadioSetting(
2300
            "dtmf_settings.dtmfspeed_on",
2301
            "DTMF Speed (On Time)",
2302
            RadioSettingValueList(LIST_DTMF_SPEED,
2303
                                  LIST_DTMF_SPEED[
2304
                                      val]))
2305
        dtmf_enc_settings.append(dtmfspeed_on)
2306

    
2307
        if _mem.dtmf_settings.dtmfspeed_off > 0x0F:
2308
            val = 0x03
2309
        else:
2310
            val = _mem.dtmf_settings.dtmfspeed_off
2311
        dtmfspeed_off = RadioSetting(
2312
            "dtmf_settings.dtmfspeed_off",
2313
            "DTMF Speed (Off Time)",
2314
            RadioSettingValueList(LIST_DTMF_SPEED,
2315
                                  LIST_DTMF_SPEED[
2316
                                      val]))
2317
        dtmf_enc_settings.append(dtmfspeed_off)
2318

    
2319
        def memory2string(dmtf_mem):
2320
            dtmf_string = ""
2321
            for digit in dmtf_mem:
2322
                if digit != 255:
2323
                    index = LIST_DTMF_VALUES.index(digit)
2324
                    dtmf_string = dtmf_string + LIST_DTMF_DIGITS[index]
2325
            return dtmf_string
2326

    
2327
        def apply_dmtf_frame(setting, obj):
2328
            LOG.debug("Setting DTMF-Code: " + str(setting.value))
2329
            val_string = str(setting.value)
2330
            for i in range(0, 16):
2331
                obj[i] = 255
2332
            i = 0
2333
            for current_char in val_string:
2334
                current_char = current_char.upper()
2335
                index = LIST_DTMF_DIGITS.index(current_char)
2336
                obj[i] = LIST_DTMF_VALUES[index]
2337
                i = i + 1
2338

    
2339
        codes = self._memobj.dtmf_codes
2340
        i = 1
2341
        for dtmfcode in codes:
2342
            val = RadioSettingValueString(0, 16, memory2string(
2343
                                              dtmfcode.code),
2344
                                          False, CHARSET_DTMF_DIGITS)
2345
            line = RadioSetting("dtmf_code_" + str(i) + "_code",
2346
                                "DMTF Code " + str(i), val)
2347
            line.set_apply_callback(apply_dmtf_frame, dtmfcode.code)
2348
            dtmf_enc_settings.append(line)
2349
            i = i + 1
2350

    
2351
        line = RadioSetting("dtmf_settings.mastervice",
2352
                            "Master and Vice ID",
2353
                            RadioSettingValueBoolean(
2354
                                _mem.dtmf_settings.mastervice))
2355
        dtmf_dec_settings.append(line)
2356

    
2357
        val = RadioSettingValueString(0, 16, memory2string(
2358
                                          _mem.dtmf_settings.masterid),
2359
                                      False, CHARSET_DTMF_DIGITS)
2360
        line = RadioSetting("dtmf_settings.masterid",
2361
                            "Master Control ID ", val)
2362
        line.set_apply_callback(apply_dmtf_frame,
2363
                                _mem.dtmf_settings.masterid)
2364
        dtmf_dec_settings.append(line)
2365

    
2366
        line = RadioSetting("dtmf_settings.minspection",
2367
                            "Master Inspection",
2368
                            RadioSettingValueBoolean(
2369
                                _mem.dtmf_settings.minspection))
2370
        dtmf_dec_settings.append(line)
2371

    
2372
        line = RadioSetting("dtmf_settings.mmonitor",
2373
                            "Master Monitor",
2374
                            RadioSettingValueBoolean(
2375
                                _mem.dtmf_settings.mmonitor))
2376
        dtmf_dec_settings.append(line)
2377

    
2378
        line = RadioSetting("dtmf_settings.mstun",
2379
                            "Master Stun",
2380
                            RadioSettingValueBoolean(
2381
                                _mem.dtmf_settings.mstun))
2382
        dtmf_dec_settings.append(line)
2383

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

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

    
2396
        val = RadioSettingValueString(0, 16, memory2string(
2397
                                          _mem.dtmf_settings.viceid),
2398
                                      False, CHARSET_DTMF_DIGITS)
2399
        line = RadioSetting("dtmf_settings.viceid",
2400
                            "Vice Control ID ", val)
2401
        line.set_apply_callback(apply_dmtf_frame,
2402
                                _mem.dtmf_settings.viceid)
2403
        dtmf_dec_settings.append(line)
2404

    
2405
        line = RadioSetting("dtmf_settings.vinspection",
2406
                            "Vice Inspection",
2407
                            RadioSettingValueBoolean(
2408
                                _mem.dtmf_settings.vinspection))
2409
        dtmf_dec_settings.append(line)
2410

    
2411
        line = RadioSetting("dtmf_settings.vmonitor",
2412
                            "Vice Monitor",
2413
                            RadioSettingValueBoolean(
2414
                                _mem.dtmf_settings.vmonitor))
2415
        dtmf_dec_settings.append(line)
2416

    
2417
        line = RadioSetting("dtmf_settings.vstun",
2418
                            "Vice Stun",
2419
                            RadioSettingValueBoolean(
2420
                                _mem.dtmf_settings.vstun))
2421
        dtmf_dec_settings.append(line)
2422

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

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

    
2435
        val = RadioSettingValueString(0, 16, memory2string(
2436
                                          _mem.dtmf_settings.inspection),
2437
                                      False, CHARSET_DTMF_DIGITS)
2438
        line = RadioSetting("dtmf_settings.inspection",
2439
                            "Inspection", val)
2440
        line.set_apply_callback(apply_dmtf_frame,
2441
                                _mem.dtmf_settings.inspection)
2442
        dtmf_dec_settings.append(line)
2443

    
2444
        val = RadioSettingValueString(0, 16, memory2string(
2445
                                          _mem.dtmf_settings.alarmcode),
2446
                                      False, CHARSET_DTMF_DIGITS)
2447
        line = RadioSetting("dtmf_settings.alarmcode",
2448
                            "Alarm", val)
2449
        line.set_apply_callback(apply_dmtf_frame,
2450
                                _mem.dtmf_settings.alarmcode)
2451
        dtmf_dec_settings.append(line)
2452

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

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

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

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

    
2489
        def apply_dmtf_listvalue(setting, obj):
2490
            LOG.debug("Setting value: " + str(setting.value) + " from list")
2491
            val = str(setting.value)
2492
            index = LIST_DTMF_SPECIAL_DIGITS.index(val)
2493
            val = LIST_DTMF_SPECIAL_VALUES[index]
2494
            obj.set_value(val)
2495

    
2496
        if _mem.dtmf_settings.groupcode not in LIST_DTMF_SPECIAL_VALUES:
2497
            val = 0x0B
2498
        else:
2499
            val = _mem.dtmf_settings.groupcode
2500
        idx = LIST_DTMF_SPECIAL_VALUES.index(val)
2501
        line = RadioSetting(
2502
            "dtmf_settings.groupcode",
2503
            "Group Code",
2504
            RadioSettingValueList(LIST_DTMF_SPECIAL_DIGITS,
2505
                                  LIST_DTMF_SPECIAL_DIGITS[idx]))
2506
        line.set_apply_callback(apply_dmtf_listvalue,
2507
                                _mem.dtmf_settings.groupcode)
2508
        dtmf_dec_settings.append(line)
2509

    
2510
        if _mem.dtmf_settings.spacecode not in LIST_DTMF_SPECIAL_VALUES:
2511
            val = 0x0C
2512
        else:
2513
            val = _mem.dtmf_settings.spacecode
2514
        idx = LIST_DTMF_SPECIAL_VALUES.index(val)
2515
        line = RadioSetting(
2516
            "dtmf_settings.spacecode",
2517
            "Space Code",
2518
            RadioSettingValueList(LIST_DTMF_SPECIAL_DIGITS,
2519
                                  LIST_DTMF_SPECIAL_DIGITS[idx]))
2520
        line.set_apply_callback(apply_dmtf_listvalue,
2521
                                _mem.dtmf_settings.spacecode)
2522
        dtmf_dec_settings.append(line)
2523

    
2524
        if self.COLOR_LCD:
2525
            if _mem.dtmf_settings.resettime > 0x63:
2526
                val = 0x4F
2527
            else:
2528
                val = _mem.dtmf_settings.resettime
2529
            line = RadioSetting(
2530
                "dtmf_settings.resettime",
2531
                "Reset time",
2532
                RadioSettingValueList(LIST_5TONE_RESET_COLOR,
2533
                                      LIST_5TONE_RESET_COLOR[
2534
                                          val]))
2535
            dtmf_dec_settings.append(line)
2536
        else:
2537
            line = RadioSetting(
2538
                "dtmf_settings.resettime",
2539
                "Reset time",
2540
                RadioSettingValueList(LIST_5TONE_RESET,
2541
                                      LIST_5TONE_RESET[
2542
                                          _mem.dtmf_settings.resettime]))
2543
            dtmf_dec_settings.append(line)
2544

    
2545
        if _mem.dtmf_settings.delayproctime > 0x27:
2546
            val = 0x04
2547
        else:
2548
            val = _mem.dtmf_settings.delayproctime
2549
        line = RadioSetting(
2550
            "dtmf_settings.delayproctime",
2551
            "Delay processing time",
2552
            RadioSettingValueList(LIST_DTMF_DELAY,
2553
                                  LIST_DTMF_DELAY[
2554
                                      val]))
2555
        dtmf_dec_settings.append(line)
2556

    
2557
        # 5 Tone Settings
2558
        stds_5tone = RadioSettingGroup("stds_5tone", "Standards")
2559
        codes_5tone = RadioSettingGroup("codes_5tone", "Codes")
2560

    
2561
        group_5tone = RadioSettingGroup("group_5tone", "5 Tone Settings")
2562
        group_5tone.append(stds_5tone)
2563
        group_5tone.append(codes_5tone)
2564

    
2565
        top.append(group_5tone)
2566

    
2567
        def apply_list_value(setting, obj):
2568
            options = setting.value.get_options()
2569
            obj.set_value(options.index(str(setting.value)))
2570

    
2571
        _5tone_standards = self._memobj._5tone_std_settings
2572
        i = 0
2573
        for standard in _5tone_standards:
2574
            std_5tone = RadioSettingGroup("std_5tone_" + str(i),
2575
                                          LIST_5TONE_STANDARDS[i])
2576
            stds_5tone.append(std_5tone)
2577

    
2578
            period = standard.period
2579
            if period == 255:
2580
                LOG.debug("Period for " + LIST_5TONE_STANDARDS[i] +
2581
                          " is not yet configured. Setting to 70ms.")
2582
                period = 5
2583

    
2584
            if period <= len(LIST_5TONE_STANDARD_PERIODS):
2585
                line = RadioSetting(
2586
                    "_5tone_std_settings_" + str(i) + "_period",
2587
                    "Period (ms)", RadioSettingValueList
2588
                    (LIST_5TONE_STANDARD_PERIODS,
2589
                     LIST_5TONE_STANDARD_PERIODS[period]))
2590
                line.set_apply_callback(apply_list_value, standard.period)
2591
                std_5tone.append(line)
2592
            else:
2593
                LOG.debug("Invalid value for 5tone period! Disabling.")
2594

    
2595
            group_tone = standard.group_tone
2596
            if group_tone == 255:
2597
                LOG.debug("Group-Tone for " + LIST_5TONE_STANDARDS[i] +
2598
                          " is not yet configured. Setting to A.")
2599
                group_tone = 10
2600

    
2601
            if group_tone <= len(LIST_5TONE_DIGITS):
2602
                line = RadioSetting(
2603
                    "_5tone_std_settings_" + str(i) + "_grouptone",
2604
                    "Group Tone",
2605
                    RadioSettingValueList(LIST_5TONE_DIGITS,
2606
                                          LIST_5TONE_DIGITS[
2607
                                              group_tone]))
2608
                line.set_apply_callback(apply_list_value,
2609
                                        standard.group_tone)
2610
                std_5tone.append(line)
2611
            else:
2612
                LOG.debug("Invalid value for 5tone digit! Disabling.")
2613

    
2614
            repeat_tone = standard.repeat_tone
2615
            if repeat_tone == 255:
2616
                LOG.debug("Repeat-Tone for " + LIST_5TONE_STANDARDS[i] +
2617
                          " is not yet configured. Setting to E.")
2618
                repeat_tone = 14
2619

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

    
2634
        def my_apply_5tonestdlist_value(setting, obj):
2635
            if LIST_5TONE_STANDARDS.index(str(setting.value)) == 15:
2636
                obj.set_value(0xFF)
2637
            else:
2638
                obj.set_value(LIST_5TONE_STANDARDS.
2639
                              index(str(setting.value)))
2640

    
2641
        def apply_5tone_frame(setting, obj):
2642
            LOG.debug("Setting 5 Tone: " + str(setting.value))
2643
            valstring = str(setting.value)
2644
            if len(valstring) == 0:
2645
                for i in range(0, 5):
2646
                    obj[i] = 255
2647
            else:
2648
                validFrame = True
2649
                for i in range(0, 5):
2650
                    currentChar = valstring[i].upper()
2651
                    if currentChar in LIST_5TONE_DIGITS:
2652
                        obj[i] = LIST_5TONE_DIGITS.index(currentChar)
2653
                    else:
2654
                        validFrame = False
2655
                        LOG.debug("invalid char: " + str(currentChar))
2656
                if not validFrame:
2657
                    LOG.debug("setting whole frame to FF")
2658
                    for i in range(0, 5):
2659
                        obj[i] = 255
2660

    
2661
        def validate_5tone_frame(value):
2662
            if (len(str(value)) != 5) and (len(str(value)) != 0):
2663
                msg = ("5 Tone must have 5 digits or 0 digits")
2664
                raise InvalidValueError(msg)
2665
            for digit in str(value):
2666
                if digit.upper() not in LIST_5TONE_DIGITS:
2667
                    msg = (str(digit) + " is not a valid digit for 5tones")
2668
                    raise InvalidValueError(msg)
2669
            return value
2670

    
2671
        def frame2string(frame):
2672
            frameString = ""
2673
            for digit in frame:
2674
                if digit != 255:
2675
                    frameString = frameString + LIST_5TONE_DIGITS[digit]
2676
            return frameString
2677

    
2678
        _5tone_codes = self._memobj._5tone_codes
2679
        i = 1
2680
        for code in _5tone_codes:
2681
            code_5tone = RadioSettingGroup("code_5tone_" + str(i),
2682
                                           "5 Tone code " + str(i))
2683
            codes_5tone.append(code_5tone)
2684
            if (code.standard == 255):
2685
                currentVal = 15
2686
            else:
2687
                currentVal = code.standard
2688
            line = RadioSetting("_5tone_code_" + str(i) + "_std",
2689
                                " Standard",
2690
                                RadioSettingValueList(LIST_5TONE_STANDARDS,
2691
                                                      LIST_5TONE_STANDARDS[
2692
                                                          currentVal]))
2693
            line.set_apply_callback(my_apply_5tonestdlist_value,
2694
                                    code.standard)
2695
            code_5tone.append(line)
2696

    
2697
            val = RadioSettingValueString(0, 6,
2698
                                          frame2string(code.frame1), False)
2699
            line = RadioSetting("_5tone_code_" + str(i) + "_frame1",
2700
                                " Frame 1", val)
2701
            val.set_validate_callback(validate_5tone_frame)
2702
            line.set_apply_callback(apply_5tone_frame, code.frame1)
2703
            code_5tone.append(line)
2704

    
2705
            val = RadioSettingValueString(0, 6,
2706
                                          frame2string(code.frame2), False)
2707
            line = RadioSetting("_5tone_code_" + str(i) + "_frame2",
2708
                                " Frame 2", val)
2709
            val.set_validate_callback(validate_5tone_frame)
2710
            line.set_apply_callback(apply_5tone_frame, code.frame2)
2711
            code_5tone.append(line)
2712

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

    
2722
        _5_tone_decode1 = RadioSetting(
2723
            "_5tone_settings._5tone_decode_call_frame1",
2724
            "5 Tone decode call Frame 1",
2725
            RadioSettingValueBoolean(
2726
                _mem._5tone_settings._5tone_decode_call_frame1))
2727
        group_5tone.append(_5_tone_decode1)
2728

    
2729
        _5_tone_decode2 = RadioSetting(
2730
            "_5tone_settings._5tone_decode_call_frame2",
2731
            "5 Tone decode call Frame 2",
2732
            RadioSettingValueBoolean(
2733
                _mem._5tone_settings._5tone_decode_call_frame2))
2734
        group_5tone.append(_5_tone_decode2)
2735

    
2736
        _5_tone_decode3 = RadioSetting(
2737
            "_5tone_settings._5tone_decode_call_frame3",
2738
            "5 Tone decode call Frame 3",
2739
            RadioSettingValueBoolean(
2740
                _mem._5tone_settings._5tone_decode_call_frame3))
2741
        group_5tone.append(_5_tone_decode3)
2742

    
2743
        _5_tone_decode_disp1 = RadioSetting(
2744
            "_5tone_settings._5tone_decode_disp_frame1",
2745
            "5 Tone decode disp Frame 1",
2746
            RadioSettingValueBoolean(
2747
                _mem._5tone_settings._5tone_decode_disp_frame1))
2748
        group_5tone.append(_5_tone_decode_disp1)
2749

    
2750
        _5_tone_decode_disp2 = RadioSetting(
2751
            "_5tone_settings._5tone_decode_disp_frame2",
2752
            "5 Tone decode disp Frame 2",
2753
            RadioSettingValueBoolean(
2754
                _mem._5tone_settings._5tone_decode_disp_frame2))
2755
        group_5tone.append(_5_tone_decode_disp2)
2756

    
2757
        _5_tone_decode_disp3 = RadioSetting(
2758
            "_5tone_settings._5tone_decode_disp_frame3",
2759
            "5 Tone decode disp Frame 3",
2760
            RadioSettingValueBoolean(
2761
                _mem._5tone_settings._5tone_decode_disp_frame3))
2762
        group_5tone.append(_5_tone_decode_disp3)
2763

    
2764
        decode_standard = _mem._5tone_settings.decode_standard
2765
        if decode_standard == 255:
2766
            decode_standard = 0
2767
        if decode_standard <= len(LIST_5TONE_STANDARDS_without_none):
2768
            line = RadioSetting("_5tone_settings.decode_standard",
2769
                                "5 Tone-decode Standard",
2770
                                RadioSettingValueList(
2771
                                    LIST_5TONE_STANDARDS_without_none,
2772
                                    LIST_5TONE_STANDARDS_without_none[
2773
                                        decode_standard]))
2774
            group_5tone.append(line)
2775
        else:
2776
            LOG.debug("Invalid decode std...")
2777

    
2778
        _5tone_delay1 = _mem._5tone_settings._5tone_delay1
2779
        if _5tone_delay1 == 255:
2780
            _5tone_delay1 = 20
2781

    
2782
        if _5tone_delay1 <= len(LIST_5TONE_DELAY):
2783
            list = RadioSettingValueList(LIST_5TONE_DELAY,
2784
                                         LIST_5TONE_DELAY[
2785
                                             _5tone_delay1])
2786
            line = RadioSetting("_5tone_settings._5tone_delay1",
2787
                                "5 Tone Delay Frame 1", list)
2788
            group_5tone.append(line)
2789
        else:
2790
            LOG.debug("Invalid value for 5tone delay (frame1) ! Disabling.")
2791

    
2792
        _5tone_delay2 = _mem._5tone_settings._5tone_delay2
2793
        if _5tone_delay2 == 255:
2794
            _5tone_delay2 = 20
2795
            LOG.debug("5 Tone delay unconfigured! Resetting to 200ms.")
2796

    
2797
        if _5tone_delay2 <= len(LIST_5TONE_DELAY):
2798
            list = RadioSettingValueList(LIST_5TONE_DELAY,
2799
                                         LIST_5TONE_DELAY[
2800
                                             _5tone_delay2])
2801
            line = RadioSetting("_5tone_settings._5tone_delay2",
2802
                                "5 Tone Delay Frame 2", list)
2803
            group_5tone.append(line)
2804
        else:
2805
            LOG.debug("Invalid value for 5tone delay (frame2)! Disabling.")
2806

    
2807
        _5tone_delay3 = _mem._5tone_settings._5tone_delay3
2808
        if _5tone_delay3 == 255:
2809
            _5tone_delay3 = 20
2810
            LOG.debug("5 Tone delay unconfigured! Resetting to 200ms.")
2811

    
2812
        if _5tone_delay3 <= len(LIST_5TONE_DELAY):
2813
            list = RadioSettingValueList(LIST_5TONE_DELAY,
2814
                                         LIST_5TONE_DELAY[
2815
                                             _5tone_delay3])
2816
            line = RadioSetting("_5tone_settings._5tone_delay3",
2817
                                "5 Tone Delay Frame 3", list)
2818
            group_5tone.append(line)
2819
        else:
2820
            LOG.debug("Invalid value for 5tone delay (frame3)! Disabling.")
2821

    
2822
        ext_length = _mem._5tone_settings._5tone_first_digit_ext_length
2823
        if ext_length == 255:
2824
            ext_length = 0
2825
            LOG.debug("1st Tone ext lenght unconfigured! Resetting to 0")
2826

    
2827
        if ext_length <= len(LIST_5TONE_DELAY):
2828
            list = RadioSettingValueList(
2829
                LIST_5TONE_DELAY,
2830
                LIST_5TONE_DELAY[
2831
                    ext_length])
2832
            line = RadioSetting(
2833
                "_5tone_settings._5tone_first_digit_ext_length",
2834
                "First digit extend length", list)
2835
            group_5tone.append(line)
2836
        else:
2837
            LOG.debug("Invalid value for 5tone ext length! Disabling.")
2838

    
2839
        decode_reset_time = _mem._5tone_settings.decode_reset_time
2840
        if decode_reset_time == 255:
2841
            decode_reset_time = 59
2842
            LOG.debug("Decode reset time unconfigured. resetting.")
2843
        if decode_reset_time <= len(LIST_5TONE_RESET):
2844
            list = RadioSettingValueList(
2845
                LIST_5TONE_RESET,
2846
                LIST_5TONE_RESET[
2847
                    decode_reset_time])
2848
            line = RadioSetting("_5tone_settings.decode_reset_time",
2849
                                "Decode reset time", list)
2850
            group_5tone.append(line)
2851
        else:
2852
            LOG.debug("Invalid value decode reset time! Disabling.")
2853

    
2854
        # 2 Tone
2855
        encode_2tone = RadioSettingGroup("encode_2tone", "2 Tone Encode")
2856
        decode_2tone = RadioSettingGroup("decode_2tone", "2 Code Decode")
2857

    
2858
        top.append(encode_2tone)
2859
        top.append(decode_2tone)
2860

    
2861
        duration_1st_tone = self._memobj._2tone.duration_1st_tone
2862
        if duration_1st_tone == 255:
2863
            LOG.debug("Duration of first 2 Tone digit is not yet " +
2864
                      "configured. Setting to 600ms")
2865
            duration_1st_tone = 60
2866

    
2867
        if duration_1st_tone <= len(LIST_5TONE_DELAY):
2868
            line = RadioSetting("_2tone.duration_1st_tone",
2869
                                "Duration 1st Tone",
2870
                                RadioSettingValueList(LIST_5TONE_DELAY,
2871
                                                      LIST_5TONE_DELAY[
2872
                                                          duration_1st_tone]))
2873
            encode_2tone.append(line)
2874

    
2875
        duration_2nd_tone = self._memobj._2tone.duration_2nd_tone
2876
        if duration_2nd_tone == 255:
2877
            LOG.debug("Duration of second 2 Tone digit is not yet " +
2878
                      "configured. Setting to 600ms")
2879
            duration_2nd_tone = 60
2880

    
2881
        if duration_2nd_tone <= len(LIST_5TONE_DELAY):
2882
            line = RadioSetting("_2tone.duration_2nd_tone",
2883
                                "Duration 2nd Tone",
2884
                                RadioSettingValueList(LIST_5TONE_DELAY,
2885
                                                      LIST_5TONE_DELAY[
2886
                                                          duration_2nd_tone]))
2887
            encode_2tone.append(line)
2888

    
2889
        duration_gap = self._memobj._2tone.duration_gap
2890
        if duration_gap == 255:
2891
            LOG.debug("Duration of gap is not yet " +
2892
                      "configured. Setting to 300ms")
2893
            duration_gap = 30
2894

    
2895
        if duration_gap <= len(LIST_5TONE_DELAY):
2896
            line = RadioSetting("_2tone.duration_gap", "Duration of gap",
2897
                                RadioSettingValueList(LIST_5TONE_DELAY,
2898
                                                      LIST_5TONE_DELAY[
2899
                                                          duration_gap]))
2900
            encode_2tone.append(line)
2901

    
2902
        def _2tone_validate(value):
2903
            if value == 0:
2904
                return 65535
2905
            if value == 65535:
2906
                return value
2907
            if not (300 <= value and value <= 3000):
2908
                msg = ("2 Tone Frequency: Must be between 300 and 3000 Hz")
2909
                raise InvalidValueError(msg)
2910
            return value
2911

    
2912
        def apply_2tone_freq(setting, obj):
2913
            val = int(setting.value)
2914
            if (val == 0) or (val == 65535):
2915
                obj.set_value(65535)
2916
            else:
2917
                obj.set_value(val)
2918

    
2919
        i = 1
2920
        for code in self._memobj._2tone._2tone_encode:
2921
            code_2tone = RadioSettingGroup("code_2tone_" + str(i),
2922
                                           "Encode Code " + str(i))
2923
            encode_2tone.append(code_2tone)
2924

    
2925
            tmp = code.freq1
2926
            if tmp == 65535:
2927
                tmp = 0
2928
            val1 = RadioSettingValueInteger(0, 65535, tmp)
2929
            freq1 = RadioSetting("2tone_code_" + str(i) + "_freq1",
2930
                                 "Frequency 1", val1)
2931
            val1.set_validate_callback(_2tone_validate)
2932
            freq1.set_apply_callback(apply_2tone_freq, code.freq1)
2933
            code_2tone.append(freq1)
2934

    
2935
            tmp = code.freq2
2936
            if tmp == 65535:
2937
                tmp = 0
2938
            val2 = RadioSettingValueInteger(0, 65535, tmp)
2939
            freq2 = RadioSetting("2tone_code_" + str(i) + "_freq2",
2940
                                 "Frequency 2", val2)
2941
            val2.set_validate_callback(_2tone_validate)
2942
            freq2.set_apply_callback(apply_2tone_freq, code.freq2)
2943
            code_2tone.append(freq2)
2944

    
2945
            i = i + 1
2946

    
2947
        decode_reset_time = _mem._2tone.reset_time
2948
        if decode_reset_time == 255:
2949
            decode_reset_time = 59
2950
            LOG.debug("Decode reset time unconfigured. resetting.")
2951
        if decode_reset_time <= len(LIST_5TONE_RESET):
2952
            list = RadioSettingValueList(
2953
                LIST_5TONE_RESET,
2954
                LIST_5TONE_RESET[
2955
                    decode_reset_time])
2956
            line = RadioSetting("_2tone.reset_time",
2957
                                "Decode reset time", list)
2958
            decode_2tone.append(line)
2959
        else:
2960
            LOG.debug("Invalid value decode reset time! Disabling.")
2961

    
2962
        def apply_2tone_freq_pair(setting, obj):
2963
            val = int(setting.value)
2964
            derived_val = 65535
2965
            frqname = str(setting._name[-5:])
2966
            derivedname = "derived_from_" + frqname
2967

    
2968
            if (val == 0):
2969
                val = 65535
2970
                derived_val = 65535
2971
            else:
2972
                derived_val = int(round(2304000.0/val))
2973

    
2974
            obj[frqname].set_value(val)
2975
            obj[derivedname].set_value(derived_val)
2976

    
2977
            LOG.debug("Apply " + frqname + ": " + str(val) + " | " +
2978
                      derivedname + ": " + str(derived_val))
2979

    
2980
        i = 1
2981
        for decode_code in self._memobj._2tone._2tone_decode:
2982
            _2tone_dec_code = RadioSettingGroup("code_2tone_" + str(i),
2983
                                                "Decode Code " + str(i))
2984
            decode_2tone.append(_2tone_dec_code)
2985

    
2986
            j = 1
2987
            for dec in decode_code.decs:
2988
                val = dec.dec
2989
                if val == 255:
2990
                    LOG.debug("Dec for Code " + str(i) + " Dec " + str(j) +
2991
                              " is not yet configured. Setting to 0.")
2992
                    val = 0
2993

    
2994
                if val <= len(LIST_2TONE_DEC):
2995
                    line = RadioSetting(
2996
                        "_2tone_dec_settings_" + str(i) + "_dec_" + str(j),
2997
                        "Dec " + str(j), RadioSettingValueList
2998
                        (LIST_2TONE_DEC,
2999
                         LIST_2TONE_DEC[val]))
3000
                    line.set_apply_callback(apply_list_value, dec.dec)
3001
                    _2tone_dec_code.append(line)
3002
                else:
3003
                    LOG.debug("Invalid value for 2tone dec! Disabling.")
3004

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

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

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

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

    
3040
            freq = self._memobj._2tone.freqs[i-1]
3041
            for char in ['A', 'B', 'C', 'D']:
3042
                setting_name = "freq" + str(char)
3043

    
3044
                tmp = freq[setting_name]
3045
                if tmp == 65535:
3046
                    tmp = 0
3047
                if tmp != 0:
3048
                    expected = int(round(2304000.0/tmp))
3049
                    from_mem = freq["derived_from_" + setting_name]
3050
                    if expected != from_mem:
3051
                        LOG.error("Expected " + str(expected) +
3052
                                  " but read " + str(from_mem) +
3053
                                  ". Disabling 2Tone Decode Freqs!")
3054
                        break
3055
                val = RadioSettingValueInteger(0, 65535, tmp)
3056
                frq = RadioSetting("2tone_dec_" + str(i) + "_freq" + str(char),
3057
                                   ("Decode Frequency " + str(char)), val)
3058
                val.set_validate_callback(_2tone_validate)
3059
                frq.set_apply_callback(apply_2tone_freq_pair, freq)
3060
                _2tone_dec_code.append(frq)
3061

    
3062
            i = i + 1
3063

    
3064
        return top
3065

    
3066
    def set_settings(self, settings):
3067
        _settings = self._memobj.settings
3068
        for element in settings:
3069
            if not isinstance(element, RadioSetting):
3070
                if element.get_name() == "fm_preset":
3071
                    self._set_fm_preset(element)
3072
                else:
3073
                    self.set_settings(element)
3074
                    continue
3075
            else:
3076
                try:
3077
                    name = element.get_name()
3078
                    if "." in name:
3079
                        bits = name.split(".")
3080
                        obj = self._memobj
3081
                        for bit in bits[:-1]:
3082
                            if "/" in bit:
3083
                                bit, index = bit.split("/", 1)
3084
                                index = int(index)
3085
                                obj = getattr(obj, bit)[index]
3086
                            else:
3087
                                obj = getattr(obj, bit)
3088
                        setting = bits[-1]
3089
                    else:
3090
                        obj = _settings
3091
                        setting = element.get_name()
3092

    
3093
                    if element.has_apply_callback():
3094
                        LOG.debug("Using apply callback")
3095
                        element.run_apply_callback()
3096
                    elif element.value.get_mutable():
3097
                        LOG.debug("Setting %s = %s" % (setting, element.value))
3098
                        setattr(obj, setting, element.value)
3099
                except Exception, e:
3100
                    LOG.debug(element.get_name())
3101
                    raise
3102

    
3103
    @classmethod
3104
    def match_model(cls, filedata, filename):
3105
        match_size = False
3106
        match_model = False
3107

    
3108
        # testing the file data size
3109
        if len(filedata) == MEM_SIZE:
3110
            match_size = True
3111

    
3112
        # testing the firmware model fingerprint
3113
        match_model = model_match(cls, filedata)
3114

    
3115
        if match_size and match_model:
3116
            return True
3117
        else:
3118
            return False
3119

    
3120

    
3121
MEM_FORMAT = """
3122
#seekto 0x0000;
3123
struct {
3124
  lbcd rxfreq[4];
3125
  lbcd txfreq[4];
3126
  ul16 rxtone;
3127
  ul16 txtone;
3128
  u8 unknown0:4,
3129
     scode:4;
3130
  u8 unknown1:2,
3131
     spmute:2,
3132
     unknown2:2,
3133
     optsig:2;
3134
  u8 unknown3:3,
3135
     scramble:1,
3136
     unknown4:3,
3137
     power:1;
3138
  u8 unknown5:1,
3139
     wide:1,
3140
     unknown6:2,
3141
     bcl:1,
3142
     add:1,
3143
     pttid:2;
3144
} memory[200];
3145

    
3146
#seekto 0x0E00;
3147
struct {
3148
  u8 tdr;
3149
  u8 unknown1;
3150
  u8 sql;
3151
  u8 unknown2[2];
3152
  u8 tot;
3153
  u8 apo;           // BTech radios use this as the Auto Power Off time
3154
                    // other radios use this as pre-Time Out Alert
3155
  u8 unknown3;
3156
  u8 abr;
3157
  u8 beep;
3158
  u8 unknown4[4];
3159
  u8 dtmfst;
3160
  u8 unknown5[2];
3161
  u8 prisc;
3162
  u8 prich;
3163
  u8 screv;
3164
  u8 unknown6[2];
3165
  u8 pttid;
3166
  u8 pttlt;
3167
  u8 unknown7;
3168
  u8 emctp;
3169
  u8 emcch;
3170
  u8 ringt;
3171
  u8 unknown8;
3172
  u8 camdf;
3173
  u8 cbmdf;
3174
  u8 sync;          // BTech radios use this as the display sync setting
3175
                    // other radios use this as the auto keypad lock setting
3176
  u8 ponmsg;
3177
  u8 wtled;
3178
  u8 rxled;
3179
  u8 txled;
3180
  u8 unknown9[5];
3181
  u8 anil;
3182
  u8 reps;
3183
  u8 repm;
3184
  u8 tdrab;
3185
  u8 ste;
3186
  u8 rpste;
3187
  u8 rptdl;
3188
  u8 mgain;
3189
  u8 dtmfg;
3190
} settings;
3191

    
3192
#seekto 0x0E80;
3193
struct {
3194
  u8 unknown1;
3195
  u8 vfomr;
3196
  u8 keylock;
3197
  u8 unknown2;
3198
  u8 unknown3:4,
3199
     vfomren:1,
3200
     unknown4:1,
3201
     reseten:1,
3202
     menuen:1;
3203
  u8 unknown5[11];
3204
  u8 dispab;
3205
  u8 mrcha;
3206
  u8 mrchb;
3207
  u8 menu;
3208
} settings2;
3209

    
3210
#seekto 0x0EC0;
3211
struct {
3212
  char line1[6];
3213
  char line2[6];
3214
} poweron_msg;
3215

    
3216
struct settings_vfo {
3217
  u8 freq[8];
3218
  u8 offset[6];
3219
  u8 unknown2[2];
3220
  ul16 rxtone;
3221
  ul16 txtone;
3222
  u8 scode;
3223
  u8 spmute;
3224
  u8 optsig;
3225
  u8 scramble;
3226
  u8 wide;
3227
  u8 power;
3228
  u8 shiftd;
3229
  u8 step;
3230
  u8 unknown3[4];
3231
};
3232

    
3233
#seekto 0x0F00;
3234
struct {
3235
  struct settings_vfo a;
3236
  struct settings_vfo b;
3237
} vfo;
3238

    
3239
#seekto 0x1000;
3240
struct {
3241
  char name[6];
3242
  u8 unknown1[10];
3243
} names[200];
3244

    
3245
#seekto 0x2400;
3246
struct {
3247
  u8 period; // one out of LIST_5TONE_STANDARD_PERIODS
3248
  u8 group_tone;
3249
  u8 repeat_tone;
3250
  u8 unused[13];
3251
} _5tone_std_settings[15];
3252

    
3253
#seekto 0x2500;
3254
struct {
3255
  u8 frame1[5];
3256
  u8 frame2[5];
3257
  u8 frame3[5];
3258
  u8 standard;   // one out of LIST_5TONE_STANDARDS
3259
} _5tone_codes[15];
3260

    
3261
#seekto 0x25F0;
3262
struct {
3263
  u8 _5tone_delay1; // * 10ms
3264
  u8 _5tone_delay2; // * 10ms
3265
  u8 _5tone_delay3; // * 10ms
3266
  u8 _5tone_first_digit_ext_length;
3267
  u8 unknown1;
3268
  u8 unknown2;
3269
  u8 unknown3;
3270
  u8 unknown4;
3271
  u8 decode_standard;
3272
  u8 unknown5:5,
3273
     _5tone_decode_call_frame3:1,
3274
     _5tone_decode_call_frame2:1,
3275
     _5tone_decode_call_frame1:1;
3276
  u8 unknown6:5,
3277
     _5tone_decode_disp_frame3:1,
3278
     _5tone_decode_disp_frame2:1,
3279
     _5tone_decode_disp_frame1:1;
3280
  u8 decode_reset_time; // * 100 + 100ms
3281
} _5tone_settings;
3282

    
3283
#seekto 0x2900;
3284
struct {
3285
  u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B
3286
} dtmf_codes[15];
3287

    
3288
#seekto 0x29F0;
3289
struct {
3290
  u8 dtmfspeed_on;  //list with 50..2000ms in steps of 10
3291
  u8 dtmfspeed_off; //list with 50..2000ms in steps of 10
3292
  u8 unknown0[14];
3293
  u8 inspection[16];
3294
  u8 monitor[16];
3295
  u8 alarmcode[16];
3296
  u8 stun[16];
3297
  u8 kill[16];
3298
  u8 revive[16];
3299
  u8 unknown1[16];
3300
  u8 unknown2[16];
3301
  u8 unknown3[16];
3302
  u8 unknown4[16];
3303
  u8 unknown5[16];
3304
  u8 unknown6[16];
3305
  u8 unknown7[16];
3306
  u8 masterid[16];
3307
  u8 viceid[16];
3308
  u8 unused01:7,
3309
     mastervice:1;
3310
  u8 unused02:3,
3311
     mrevive:1,
3312
     mkill:1,
3313
     mstun:1,
3314
     mmonitor:1,
3315
     minspection:1;
3316
  u8 unused03:3,
3317
     vrevive:1,
3318
     vkill:1,
3319
     vstun:1,
3320
     vmonitor:1,
3321
     vinspection:1;
3322
  u8 unused04:6,
3323
     txdisable:1,
3324
     rxdisable:1;
3325
  u8 groupcode;
3326
  u8 spacecode;
3327
  u8 delayproctime; // * 100 + 100ms
3328
  u8 resettime;     // * 100 + 100ms
3329
} dtmf_settings;
3330

    
3331
#seekto 0x2D00;
3332
struct {
3333
  struct {
3334
    ul16 freq1;
3335
    u8 unused01[6];
3336
    ul16 freq2;
3337
    u8 unused02[6];
3338
  } _2tone_encode[15];
3339
  u8 duration_1st_tone; // *10ms
3340
  u8 duration_2nd_tone; // *10ms
3341
  u8 duration_gap;      // *10ms
3342
  u8 unused03[13];
3343
  struct {
3344
    struct {
3345
      u8 dec;      // one out of LIST_2TONE_DEC
3346
      u8 response; // one out of LIST_2TONE_RESPONSE
3347
      u8 alert;    // 1-16
3348
    } decs[4];
3349
    u8 unused04[4];
3350
  } _2tone_decode[15];
3351
  u8 unused05[16];
3352

    
3353
  struct {
3354
    ul16 freqA;
3355
    ul16 freqB;
3356
    ul16 freqC;
3357
    ul16 freqD;
3358
    // unknown what those values mean, but they are
3359
    // derived from configured frequencies
3360
    ul16 derived_from_freqA; // 2304000/freqA
3361
    ul16 derived_from_freqB; // 2304000/freqB
3362
    ul16 derived_from_freqC; // 2304000/freqC
3363
    ul16 derived_from_freqD; // 2304000/freqD
3364
  }freqs[15];
3365
  u8 reset_time;  // * 100 + 100ms - 100-8000ms
3366
} _2tone;
3367

    
3368
#seekto 0x3000;
3369
struct {
3370
  u8 freq[8];
3371
  char broadcast_station_name[6];
3372
  u8 unknown[2];
3373
} fm_radio_preset[16];
3374

    
3375
#seekto 0x3C90;
3376
struct {
3377
  u8 vhf_low[3];
3378
  u8 vhf_high[3];
3379
  u8 uhf_low[3];
3380
  u8 uhf_high[3];
3381
} ranges;
3382

    
3383
// the UV-2501+220 & KT8900R has different zones for storing ranges
3384

    
3385
#seekto 0x3CD0;
3386
struct {
3387
  u8 vhf_low[3];
3388
  u8 vhf_high[3];
3389
  u8 unknown1[4];
3390
  u8 unknown2[6];
3391
  u8 vhf2_low[3];
3392
  u8 vhf2_high[3];
3393
  u8 unknown3[4];
3394
  u8 unknown4[6];
3395
  u8 uhf_low[3];
3396
  u8 uhf_high[3];
3397
} ranges220;
3398

    
3399
#seekto 0x3F70;
3400
struct {
3401
  char fp[6];
3402
} fingerprint;
3403

    
3404
"""
3405

    
3406

    
3407
class BTech(BTechMobileCommon):
3408
    """BTECH's UV-5001 and alike radios"""
3409
    BANDS = 2
3410
    COLOR_LCD = False
3411
    NAME_LENGTH = 6
3412

    
3413
    def set_options(self):
3414
        """This is to read the options from the image and set it in the
3415
        environment, for now just the limits of the freqs in the VHF/UHF
3416
        ranges"""
3417

    
3418
        # setting the correct ranges for each radio type
3419
        if self.MODEL in ["UV-2501+220", "KT8900R"]:
3420
            # the model 2501+220 has a segment in 220
3421
            # and a different position in the memmap
3422
            # also the QYT KT8900R
3423
            ranges = self._memobj.ranges220
3424
        else:
3425
            ranges = self._memobj.ranges
3426

    
3427
        # the normal dual bands
3428
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
3429
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
3430

    
3431
        # DEBUG
3432
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
3433
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
3434

    
3435
        # 220Mhz radios case
3436
        if self.MODEL in ["UV-2501+220", "KT8900R"]:
3437
            vhf2 = _decode_ranges(ranges.vhf2_low, ranges.vhf2_high)
3438
            LOG.info("Radio ranges: VHF(220) %d to %d" % vhf2)
3439
            self._220_range = vhf2
3440

    
3441
        # set the class with the real data
3442
        self._vhf_range = vhf
3443
        self._uhf_range = uhf
3444

    
3445
    def process_mmap(self):
3446
        """Process the mem map into the mem object"""
3447

    
3448
        # Get it
3449
        self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)
3450

    
3451
        # load specific parameters from the radio image
3452
        self.set_options()
3453

    
3454

    
3455
# Declaring Aliases (Clones of the real radios)
3456
class JT2705M(chirp_common.Alias):
3457
    VENDOR = "Jetstream"
3458
    MODEL = "JT2705M"
3459

    
3460

    
3461
class JT6188Mini(chirp_common.Alias):
3462
    VENDOR = "Juentai"
3463
    MODEL = "JT-6188 Mini"
3464

    
3465

    
3466
class JT6188Plus(chirp_common.Alias):
3467
    VENDOR = "Juentai"
3468
    MODEL = "JT-6188 Plus"
3469

    
3470

    
3471
class SSGT890(chirp_common.Alias):
3472
    VENDOR = "Sainsonic"
3473
    MODEL = "GT-890"
3474

    
3475

    
3476
class ZastoneMP300(chirp_common.Alias):
3477
    VENDOR = "Zastone"
3478
    MODEL = "MP-300"
3479

    
3480

    
3481
# real radios
3482
@directory.register
3483
class UV2501(BTech):
3484
    """Baofeng Tech UV2501"""
3485
    MODEL = "UV-2501"
3486
    _fileid = [UV2501G3_fp,
3487
               UV2501G2_fp,
3488
               UV2501pp2_fp,
3489
               UV2501pp_fp]
3490

    
3491

    
3492
@directory.register
3493
class UV2501_220(BTech):
3494
    """Baofeng Tech UV2501+220"""
3495
    MODEL = "UV-2501+220"
3496
    BANDS = 3
3497
    _magic = MSTRING_220
3498
    _id2 = [UV2501_220pp_id, ]
3499
    _fileid = [UV2501_220G3_fp,
3500
               UV2501_220G2_fp,
3501
               UV2501_220_fp,
3502
               UV2501_220pp_fp]
3503

    
3504

    
3505
@directory.register
3506
class UV5001(BTech):
3507
    """Baofeng Tech UV5001"""
3508
    MODEL = "UV-5001"
3509
    _fileid = [UV5001G3_fp,
3510
               UV5001G22_fp,
3511
               UV5001G2_fp,
3512
               UV5001alpha_fp,
3513
               UV5001pp_fp]
3514
    _power_levels = [chirp_common.PowerLevel("High", watts=50),
3515
                     chirp_common.PowerLevel("Low", watts=10)]
3516

    
3517

    
3518
@directory.register
3519
class MINI8900(BTech):
3520
    """WACCOM MINI-8900"""
3521
    VENDOR = "WACCOM"
3522
    MODEL = "MINI-8900"
3523
    _magic = MSTRING_MINI8900
3524
    _fileid = [MINI8900_fp, ]
3525
    # Clones
3526
    ALIASES = [JT6188Plus, ]
3527

    
3528

    
3529
@directory.register
3530
class KTUV980(BTech):
3531
    """QYT KT-UV980"""
3532
    VENDOR = "QYT"
3533
    MODEL = "KT-UV980"
3534
    _vhf_range = (136000000, 175000000)
3535
    _uhf_range = (400000000, 481000000)
3536
    _magic = MSTRING_MINI8900
3537
    _fileid = [KTUV980_fp, ]
3538
    # Clones
3539
    ALIASES = [JT2705M, ]
3540

    
3541
# Please note that there is a version of this radios that is a clone of the
3542
# Waccom Mini8900, maybe an early version?
3543

    
3544

    
3545
class OTGRadioV1(chirp_common.Alias):
3546
    VENDOR = 'OTGSTUFF'
3547
    MODEL = 'OTG Radio v1'
3548

    
3549

    
3550
@directory.register
3551
class KT9800(BTech):
3552
    """QYT KT8900"""
3553
    VENDOR = "QYT"
3554
    MODEL = "KT8900"
3555
    _vhf_range = (136000000, 175000000)
3556
    _uhf_range = (400000000, 481000000)
3557
    _magic = MSTRING_KT8900
3558
    _fileid = [KT8900_fp,
3559
               KT8900_fp1,
3560
               KT8900_fp2,
3561
               KT8900_fp3,
3562
               KT8900_fp4,
3563
               KT8900_fp5,
3564
               KT8900_fp6,
3565
               KT8900_fp7]
3566
    _id2 = [KT8900_id, KT8900_id2]
3567
    # Clones
3568
    ALIASES = [JT6188Mini, SSGT890, ZastoneMP300]
3569

    
3570

    
3571
@directory.register
3572
class KT9800R(BTech):
3573
    """QYT KT8900R"""
3574
    VENDOR = "QYT"
3575
    MODEL = "KT8900R"
3576
    BANDS = 3
3577
    _vhf_range = (136000000, 175000000)
3578
    _220_range = (240000000, 271000000)
3579
    _uhf_range = (400000000, 481000000)
3580
    _magic = MSTRING_KT8900R
3581
    _fileid = [KT8900R_fp,
3582
               KT8900R_fp1,
3583
               KT8900R_fp2,
3584
               KT8900R_fp3,
3585
               KT8900R_fp4,
3586
               KT8900R_fp5]
3587
    _id2 = [KT8900R_id, KT8900R_id2]
3588

    
3589

    
3590
@directory.register
3591
class LT588UV(BTech):
3592
    """LUITON LT-588UV"""
3593
    VENDOR = "LUITON"
3594
    MODEL = "LT-588UV"
3595
    _vhf_range = (136000000, 175000000)
3596
    _uhf_range = (400000000, 481000000)
3597
    _magic = MSTRING_KT8900
3598
    _fileid = [LT588UV_fp,
3599
               LT588UV_fp1]
3600
    _power_levels = [chirp_common.PowerLevel("High", watts=60),
3601
                     chirp_common.PowerLevel("Low", watts=10)]
3602

    
3603

    
3604
COLOR_MEM_FORMAT = """
3605
#seekto 0x0000;
3606
struct {
3607
  lbcd rxfreq[4];
3608
  lbcd txfreq[4];
3609
  ul16 rxtone;
3610
  ul16 txtone;
3611
  u8 unknown0:4,
3612
     scode:4;
3613
  u8 unknown1:2,
3614
     spmute:2,
3615
     unknown2:2,
3616
     optsig:2;
3617
  u8 unknown3:3,
3618
     scramble:1,
3619
     unknown4:2,
3620
     power:2;
3621
  u8 unknown5:1,
3622
     wide:1,
3623
     unknown6:2,
3624
     bcl:1,
3625
     add:1,
3626
     pttid:2;
3627
} memory[200];
3628

    
3629
#seekto 0x0E00;
3630
struct {
3631
  u8 tmr;
3632
  u8 unknown1;
3633
  u8 sql;
3634
  u8 unknown2;
3635
  u8 mgain2;
3636
  u8 tot;
3637
  u8 apo;
3638
  u8 unknown3;
3639
  u8 abr;
3640
  u8 beep;
3641
  u8 unknown4[4];
3642
  u8 dtmfst;
3643
  u8 unknown5[2];
3644
  u8 screv;
3645
  u8 unknown6[2];
3646
  u8 pttid;
3647
  u8 pttlt;
3648
  u8 unknown7;
3649
  u8 emctp;
3650
  u8 emcch;
3651
  u8 sigbp;
3652
  u8 unknown8;
3653
  u8 camdf;
3654
  u8 cbmdf;
3655
  u8 ccmdf;
3656
  u8 cdmdf;
3657
  u8 langua;
3658
  u8 sync;          // BTech radios use this as the display sync
3659
                    // setting, other radios use this as the auto
3660
                    // keypad lock setting
3661
  u8 mainfc;
3662
  u8 mainbc;
3663
  u8 menufc;
3664
  u8 menubc;
3665
  u8 stafc;
3666
  u8 stabc;
3667
  u8 sigfc;
3668
  u8 sigbc;
3669
  u8 rxfc;
3670
  u8 txfc;
3671
  u8 txdisp;
3672
  u8 unknown9[5];
3673
  u8 anil;
3674
  u8 reps;
3675
  u8 repm;
3676
  u8 tmrmr;
3677
  u8 ste;
3678
  u8 rpste;
3679
  u8 rptdl;
3680
  u8 dtmfg;
3681
  u8 mgain;         // used by db25-g for ponyey
3682
  u8 skiptx;
3683
  u8 scmode;
3684
} settings;
3685

    
3686
#seekto 0x0E80;
3687
struct {
3688
  u8 unknown1;
3689
  u8 vfomr;
3690
  u8 keylock;
3691
  u8 unknown2;
3692
  u8 unknown3:4,
3693
     vfomren:1,
3694
     unknown4:1,
3695
     reseten:1,
3696
     menuen:1;
3697
  u8 unknown5[11];
3698
  u8 dispab;
3699
  u8 unknown6[2];
3700
  u8 menu;
3701
  u8 unknown7[7];
3702
  u8 vfomra;
3703
  u8 vfomrb;
3704
  u8 vfomrc;
3705
  u8 vfomrd;
3706
  u8 mrcha;
3707
  u8 mrchb;
3708
  u8 mrchc;
3709
  u8 mrchd;
3710
} settings2;
3711

    
3712
struct settings_vfo {
3713
  u8 freq[8];
3714
  u8 offset[6];
3715
  u8 unknown2[2];
3716
  ul16 rxtone;
3717
  ul16 txtone;
3718
  u8 scode;
3719
  u8 spmute;
3720
  u8 optsig;
3721
  u8 scramble;
3722
  u8 wide;
3723
  u8 power;
3724
  u8 shiftd;
3725
  u8 step;
3726
  u8 unknown3[4];
3727
};
3728

    
3729
#seekto 0x0F00;
3730
struct {
3731
  struct settings_vfo a;
3732
  struct settings_vfo b;
3733
  struct settings_vfo c;
3734
  struct settings_vfo d;
3735
} vfo;
3736

    
3737
#seekto 0x0F80;
3738
struct {
3739
  char line1[8];
3740
  char line2[8];
3741
  char line3[8];
3742
  char line4[8];
3743
  char line5[8];
3744
  char line6[8];
3745
  char line7[8];
3746
  char line8[8];
3747
} poweron_msg;
3748

    
3749
#seekto 0x1000;
3750
struct {
3751
  char name[8];
3752
  u8 unknown1[8];
3753
} names[200];
3754

    
3755
#seekto 0x2400;
3756
struct {
3757
  u8 period; // one out of LIST_5TONE_STANDARD_PERIODS
3758
  u8 group_tone;
3759
  u8 repeat_tone;
3760
  u8 unused[13];
3761
} _5tone_std_settings[15];
3762

    
3763
#seekto 0x2500;
3764
struct {
3765
  u8 frame1[5];
3766
  u8 frame2[5];
3767
  u8 frame3[5];
3768
  u8 standard;   // one out of LIST_5TONE_STANDARDS
3769
} _5tone_codes[15];
3770

    
3771
#seekto 0x25F0;
3772
struct {
3773
  u8 _5tone_delay1; // * 10ms
3774
  u8 _5tone_delay2; // * 10ms
3775
  u8 _5tone_delay3; // * 10ms
3776
  u8 _5tone_first_digit_ext_length;
3777
  u8 unknown1;
3778
  u8 unknown2;
3779
  u8 unknown3;
3780
  u8 unknown4;
3781
  u8 decode_standard;
3782
  u8 unknown5:5,
3783
     _5tone_decode_call_frame3:1,
3784
     _5tone_decode_call_frame2:1,
3785
     _5tone_decode_call_frame1:1;
3786
  u8 unknown6:5,
3787
     _5tone_decode_disp_frame3:1,
3788
     _5tone_decode_disp_frame2:1,
3789
     _5tone_decode_disp_frame1:1;
3790
  u8 decode_reset_time; // * 100 + 100ms
3791
} _5tone_settings;
3792

    
3793
#seekto 0x2900;
3794
struct {
3795
  u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B
3796
} dtmf_codes[15];
3797

    
3798
#seekto 0x29F0;
3799
struct {
3800
  u8 dtmfspeed_on;  //list with 50..2000ms in steps of 10
3801
  u8 dtmfspeed_off; //list with 50..2000ms in steps of 10
3802
  u8 unknown0[14];
3803
  u8 inspection[16];
3804
  u8 monitor[16];
3805
  u8 alarmcode[16];
3806
  u8 stun[16];
3807
  u8 kill[16];
3808
  u8 revive[16];
3809
  u8 unknown1[16];
3810
  u8 unknown2[16];
3811
  u8 unknown3[16];
3812
  u8 unknown4[16];
3813
  u8 unknown5[16];
3814
  u8 unknown6[16];
3815
  u8 unknown7[16];
3816
  u8 masterid[16];
3817
  u8 viceid[16];
3818
  u8 unused01:7,
3819
     mastervice:1;
3820
  u8 unused02:3,
3821
     mrevive:1,
3822
     mkill:1,
3823
     mstun:1,
3824
     mmonitor:1,
3825
     minspection:1;
3826
  u8 unused03:3,
3827
     vrevive:1,
3828
     vkill:1,
3829
     vstun:1,
3830
     vmonitor:1,
3831
     vinspection:1;
3832
  u8 unused04:6,
3833
     txdisable:1,
3834
     rxdisable:1;
3835
  u8 groupcode;
3836
  u8 spacecode;
3837
  u8 delayproctime; // * 100 + 100ms
3838
  u8 resettime;     // * 100 + 100ms
3839
} dtmf_settings;
3840

    
3841
#seekto 0x2D00;
3842
struct {
3843
  struct {
3844
    ul16 freq1;
3845
    u8 unused01[6];
3846
    ul16 freq2;
3847
    u8 unused02[6];
3848
  } _2tone_encode[15];
3849
  u8 duration_1st_tone; // *10ms
3850
  u8 duration_2nd_tone; // *10ms
3851
  u8 duration_gap;      // *10ms
3852
  u8 unused03[13];
3853
  struct {
3854
    struct {
3855
      u8 dec;      // one out of LIST_2TONE_DEC
3856
      u8 response; // one out of LIST_2TONE_RESPONSE
3857
      u8 alert;    // 1-16
3858
    } decs[4];
3859
    u8 unused04[4];
3860
  } _2tone_decode[15];
3861
  u8 unused05[16];
3862

    
3863
  struct {
3864
    ul16 freqA;
3865
    ul16 freqB;
3866
    ul16 freqC;
3867
    ul16 freqD;
3868
    // unknown what those values mean, but they are
3869
    // derived from configured frequencies
3870
    ul16 derived_from_freqA; // 2304000/freqA
3871
    ul16 derived_from_freqB; // 2304000/freqB
3872
    ul16 derived_from_freqC; // 2304000/freqC
3873
    ul16 derived_from_freqD; // 2304000/freqD
3874
  }freqs[15];
3875
  u8 reset_time;  // * 100 + 100ms - 100-8000ms
3876
} _2tone;
3877

    
3878
#seekto 0x3D80;
3879
struct {
3880
  u8 vhf_low[3];
3881
  u8 vhf_high[3];
3882
  u8 unknown1[4];
3883
  u8 unknown2[6];
3884
  u8 vhf2_low[3];
3885
  u8 vhf2_high[3];
3886
  u8 unknown3[4];
3887
  u8 unknown4[6];
3888
  u8 uhf_low[3];
3889
  u8 uhf_high[3];
3890
  u8 unknown5[4];
3891
  u8 unknown6[6];
3892
  u8 uhf2_low[3];
3893
  u8 uhf2_high[3];
3894
} ranges;
3895

    
3896
#seekto 0x3F70;
3897
struct {
3898
  char fp[6];
3899
} fingerprint;
3900

    
3901
"""
3902

    
3903

    
3904
class BTechColor(BTechMobileCommon):
3905
    """BTECH's Color LCD Mobile and alike radios"""
3906
    COLOR_LCD = True
3907
    NAME_LENGTH = 8
3908
    LIST_TMR = LIST_TMR16
3909

    
3910
    def process_mmap(self):
3911
        """Process the mem map into the mem object"""
3912

    
3913
        # Get it
3914
        self._memobj = bitwise.parse(COLOR_MEM_FORMAT, self._mmap)
3915

    
3916
        # load specific parameters from the radio image
3917
        self.set_options()
3918

    
3919
    def set_options(self):
3920
        """This is to read the options from the image and set it in the
3921
        environment, for now just the limits of the freqs in the VHF/UHF
3922
        ranges"""
3923

    
3924
        # setting the correct ranges for each radio type
3925
        ranges = self._memobj.ranges
3926

    
3927
        # the normal dual bands
3928
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
3929
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
3930

    
3931
        # DEBUG
3932
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
3933
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
3934

    
3935
        # the additional bands
3936
        if self.MODEL in ["UV-25X4", "KT7900D"]:
3937
            # 200Mhz band
3938
            vhf2 = _decode_ranges(ranges.vhf2_low, ranges.vhf2_high)
3939
            LOG.info("Radio ranges: VHF(220) %d to %d" % vhf2)
3940
            self._220_range = vhf2
3941

    
3942
            # 350Mhz band
3943
            uhf2 = _decode_ranges(ranges.uhf2_low, ranges.uhf2_high)
3944
            LOG.info("Radio ranges: UHF(350) %d to %d" % uhf2)
3945
            self._350_range = uhf2
3946

    
3947
        # set the class with the real data
3948
        self._vhf_range = vhf
3949
        self._uhf_range = uhf
3950

    
3951

    
3952
# Declaring Aliases (Clones of the real radios)
3953
class SKT8900D(chirp_common.Alias):
3954
    VENDOR = "Surecom"
3955
    MODEL = "S-KT8900D"
3956

    
3957

    
3958
class QB25(chirp_common.Alias):
3959
    VENDOR = "Radioddity"
3960
    MODEL = "QB25"
3961

    
3962

    
3963
# real radios
3964
@directory.register
3965
class UV25X2(BTechColor):
3966
    """Baofeng Tech UV25X2"""
3967
    MODEL = "UV-25X2"
3968
    BANDS = 2
3969
    _vhf_range = (130000000, 180000000)
3970
    _uhf_range = (400000000, 521000000)
3971
    _magic = MSTRING_UV25X2
3972
    _fileid = [UV25X2_fp, ]
3973

    
3974

    
3975
@directory.register
3976
class UV25X4(BTechColor):
3977
    """Baofeng Tech UV25X4"""
3978
    MODEL = "UV-25X4"
3979
    BANDS = 4
3980
    _vhf_range = (130000000, 180000000)
3981
    _220_range = (200000000, 271000000)
3982
    _uhf_range = (400000000, 521000000)
3983
    _350_range = (350000000, 391000000)
3984
    _magic = MSTRING_UV25X4
3985
    _fileid = [UV25X4_fp, ]
3986

    
3987

    
3988
@directory.register
3989
class UV50X2(BTechColor):
3990
    """Baofeng Tech UV50X2"""
3991
    MODEL = "UV-50X2"
3992
    BANDS = 2
3993
    _vhf_range = (130000000, 180000000)
3994
    _uhf_range = (400000000, 521000000)
3995
    _magic = MSTRING_UV25X2
3996
    _fileid = [UV50X2_fp, ]
3997
    _power_levels = [chirp_common.PowerLevel("High", watts=50),
3998
                     chirp_common.PowerLevel("Low", watts=10)]
3999

    
4000

    
4001
@directory.register
4002
class KT7900D(BTechColor):
4003
    """QYT KT7900D"""
4004
    VENDOR = "QYT"
4005
    MODEL = "KT7900D"
4006
    BANDS = 4
4007
    LIST_TMR = LIST_TMR15
4008
    _vhf_range = (136000000, 175000000)
4009
    _220_range = (200000000, 271000000)
4010
    _uhf_range = (400000000, 481000000)
4011
    _350_range = (350000000, 371000000)
4012
    _magic = MSTRING_KT8900D
4013
    _fileid = [KT7900D_fp, KT7900D_fp1, KT7900D_fp2, KT7900D_fp3, KT7900D_fp4,
4014
               KT7900D_fp5, KT7900D_fp6, KT7900D_fp7, QB25_fp, ]
4015
    # Clones
4016
    ALIASES = [SKT8900D, QB25, ]
4017

    
4018

    
4019
@directory.register
4020
class KT8900D(BTechColor):
4021
    """QYT KT8900D"""
4022
    VENDOR = "QYT"
4023
    MODEL = "KT8900D"
4024
    BANDS = 2
4025
    LIST_TMR = LIST_TMR15
4026
    _vhf_range = (136000000, 175000000)
4027
    _uhf_range = (400000000, 481000000)
4028
    _magic = MSTRING_KT8900D
4029
    _fileid = [KT8900D_fp3, KT8900D_fp2, KT8900D_fp1, KT8900D_fp]
4030

    
4031
    # Clones
4032
    ALIASES = [OTGRadioV1]
4033

    
4034

    
4035
@directory.register
4036
class KT5800(BTechColor):
4037
    """QYT KT5800"""
4038
    VENDOR = "QYT"
4039
    MODEL = "KT5800"
4040
    BANDS = 2
4041
    LIST_TMR = LIST_TMR15
4042
    _vhf_range = (136000000, 175000000)
4043
    _uhf_range = (400000000, 481000000)
4044
    _magic = MSTRING_KT8900D
4045
    _fileid = [KT5800_fp, ]
4046

    
4047

    
4048
@directory.register
4049
class KT980PLUS(BTechColor):
4050
    """QYT KT980PLUS"""
4051
    VENDOR = "QYT"
4052
    MODEL = "KT980PLUS"
4053
    BANDS = 2
4054
    LIST_TMR = LIST_TMR15
4055
    _vhf_range = (136000000, 175000000)
4056
    _uhf_range = (400000000, 481000000)
4057
    _magic = MSTRING_KT8900D
4058
    _fileid = [KT980PLUS_fp1, KT980PLUS_fp]
4059
    _power_levels = [chirp_common.PowerLevel("High", watts=75),
4060
                     chirp_common.PowerLevel("Low", watts=55)]
4061

    
4062
    @classmethod
4063
    def match_model(cls, filedata, filename):
4064
        # This model is only ever matched via metadata
4065
        return False
4066

    
4067

    
4068
@directory.register
4069
class DB25G(BTechColor):
4070
    """Radioddity DB25-G"""
4071
    VENDOR = "Radioddity"
4072
    MODEL = "DB25-G"
4073
    BANDS = 2
4074
    LIST_TMR = LIST_TMR15
4075
    _vhf_range = (136000000, 175000000)
4076
    _uhf_range = (400000000, 481000000)
4077
    _magic = MSTRING_KT8900D
4078
    _fileid = [DB25G_fp1, DB25G_fp]
4079
    _gmrs = True
4080
    _power_levels = [chirp_common.PowerLevel("High", watts=25),
4081
                     chirp_common.PowerLevel("Mid", watts=15),
4082
                     chirp_common.PowerLevel("Low", watts=5)]
4083

    
4084
    @classmethod
4085
    def match_model(cls, filedata, filename):
4086
        # This model is only ever matched via metadata
4087
        return False
4088

    
4089

    
4090
GMRS_MEM_FORMAT = """
4091
#seekto 0x0000;
4092
struct {
4093
  lbcd rxfreq[4];
4094
  lbcd txfreq[4];
4095
  ul16 rxtone;
4096
  ul16 txtone;
4097
  u8 unknown0:4,
4098
     scode:4;
4099
  u8 unknown1:2,
4100
     spmute:2,
4101
     unknown2:2,
4102
     optsig:2;
4103
  u8 unknown3:3,
4104
     scramble:1,
4105
     unknown4:2,
4106
     power:2;
4107
  u8 unknown5:1,
4108
     wide:1,
4109
     unknown6:2,
4110
     bcl:1,
4111
     add:1,
4112
     pttid:2;
4113
} memory[256];
4114

    
4115
#seekto 0x1000;
4116
struct {
4117
  char name[7];
4118
  u8 unknown1[9];
4119
} names[256];
4120

    
4121
#seekto 0x2400;
4122
struct {
4123
  u8 period; // one out of LIST_5TONE_STANDARD_PERIODS
4124
  u8 group_tone;
4125
  u8 repeat_tone;
4126
  u8 unused[13];
4127
} _5tone_std_settings[15];
4128

    
4129
#seekto 0x2500;
4130
struct {
4131
  u8 frame1[5];
4132
  u8 frame2[5];
4133
  u8 frame3[5];
4134
  u8 standard;   // one out of LIST_5TONE_STANDARDS
4135
} _5tone_codes[15];
4136

    
4137
#seekto 0x25F0;
4138
struct {
4139
  u8 _5tone_delay1; // * 10ms
4140
  u8 _5tone_delay2; // * 10ms
4141
  u8 _5tone_delay3; // * 10ms
4142
  u8 _5tone_first_digit_ext_length;
4143
  u8 unknown1;
4144
  u8 unknown2;
4145
  u8 unknown3;
4146
  u8 unknown4;
4147
  u8 decode_standard;
4148
  u8 unknown5:5,
4149
     _5tone_decode_call_frame3:1,
4150
     _5tone_decode_call_frame2:1,
4151
     _5tone_decode_call_frame1:1;
4152
  u8 unknown6:5,
4153
     _5tone_decode_disp_frame3:1,
4154
     _5tone_decode_disp_frame2:1,
4155
     _5tone_decode_disp_frame1:1;
4156
  u8 decode_reset_time; // * 100 + 100ms
4157
} _5tone_settings;
4158

    
4159
#seekto 0x2900;
4160
struct {
4161
  u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B
4162
} dtmf_codes[15];
4163

    
4164
#seekto 0x29F0;
4165
struct {
4166
  u8 dtmfspeed_on;  //list with 50..2000ms in steps of 10
4167
  u8 dtmfspeed_off; //list with 50..2000ms in steps of 10
4168
  u8 unknown0[14];
4169
  u8 inspection[16];
4170
  u8 monitor[16];
4171
  u8 alarmcode[16];
4172
  u8 stun[16];
4173
  u8 kill[16];
4174
  u8 revive[16];
4175
  u8 unknown1[16];
4176
  u8 unknown2[16];
4177
  u8 unknown3[16];
4178
  u8 unknown4[16];
4179
  u8 unknown5[16];
4180
  u8 unknown6[16];
4181
  u8 unknown7[16];
4182
  u8 masterid[16];
4183
  u8 viceid[16];
4184
  u8 unused01:7,
4185
     mastervice:1;
4186
  u8 unused02:3,
4187
     mrevive:1,
4188
     mkill:1,
4189
     mstun:1,
4190
     mmonitor:1,
4191
     minspection:1;
4192
  u8 unused03:3,
4193
     vrevive:1,
4194
     vkill:1,
4195
     vstun:1,
4196
     vmonitor:1,
4197
     vinspection:1;
4198
  u8 unused04:6,
4199
     txdisable:1,
4200
     rxdisable:1;
4201
  u8 groupcode;
4202
  u8 spacecode;
4203
  u8 delayproctime; // * 100 + 100ms
4204
  u8 resettime;     // * 100 + 100ms
4205
} dtmf_settings;
4206

    
4207
#seekto 0x2D00;
4208
struct {
4209
  struct {
4210
    ul16 freq1;
4211
    u8 unused01[6];
4212
    ul16 freq2;
4213
    u8 unused02[6];
4214
  } _2tone_encode[15];
4215
  u8 duration_1st_tone; // *10ms
4216
  u8 duration_2nd_tone; // *10ms
4217
  u8 duration_gap;      // *10ms
4218
  u8 unused03[13];
4219
  struct {
4220
    struct {
4221
      u8 dec;      // one out of LIST_2TONE_DEC
4222
      u8 response; // one out of LIST_2TONE_RESPONSE
4223
      u8 alert;    // 1-16
4224
    } decs[4];
4225
    u8 unused04[4];
4226
  } _2tone_decode[15];
4227
  u8 unused05[16];
4228

    
4229
  struct {
4230
    ul16 freqA;
4231
    ul16 freqB;
4232
    ul16 freqC;
4233
    ul16 freqD;
4234
    // unknown what those values mean, but they are
4235
    // derived from configured frequencies
4236
    ul16 derived_from_freqA; // 2304000/freqA
4237
    ul16 derived_from_freqB; // 2304000/freqB
4238
    ul16 derived_from_freqC; // 2304000/freqC
4239
    ul16 derived_from_freqD; // 2304000/freqD
4240
  }freqs[15];
4241
  u8 reset_time;  // * 100 + 100ms - 100-8000ms
4242
} _2tone;
4243

    
4244
#seekto 0x3000;
4245
struct {
4246
  u8 freq[8];
4247
  char broadcast_station_name[6];
4248
  u8 unknown[2];
4249
} fm_radio_preset[16];
4250

    
4251
#seekto 0x3200;
4252
struct {
4253
  u8 tmr;
4254
  u8 unknown1;
4255
  u8 sql;
4256
  u8 unknown2;
4257
  u8 autolk;
4258
  u8 tot;
4259
  u8 apo;
4260
  u8 unknown3;
4261
  u8 abr;
4262
  u8 beep;
4263
  u8 unknown4[4];
4264
  u8 dtmfst;
4265
  u8 unknown5[2];
4266
  u8 screv;
4267
  u8 unknown6[2];
4268
  u8 pttid;
4269
  u8 pttlt;
4270
  u8 unknown7;
4271
  u8 emctp;
4272
  u8 emcch;
4273
  u8 sigbp;
4274
  u8 unknown8;
4275
  u8 camdf;
4276
  u8 cbmdf;
4277
  u8 ccmdf;
4278
  u8 cdmdf;
4279
  u8 langua;
4280
  u8 sync;
4281

    
4282

    
4283
  u8 stfc;
4284
  u8 mffc;
4285
  u8 sfafc;
4286
  u8 sfbfc;
4287
  u8 sfcfc;
4288
  u8 sfdfc;
4289
  u8 subfc;
4290
  u8 fmfc;
4291
  u8 sigfc;
4292
  u8 modfc;
4293
  u8 menufc;
4294
  u8 txfc;
4295
  u8 txdisp;
4296
  u8 unknown9[5];
4297
  u8 anil;
4298
  u8 reps;
4299
  u8 repm;
4300
  u8 tmrmr;
4301
  u8 ste;
4302
  u8 rpste;
4303
  u8 rptdl;
4304
  u8 dtmfg;
4305
  u8 mgain;
4306
  u8 skiptx;
4307
  u8 scmode;
4308
} settings;
4309

    
4310
#seekto 0x3280;
4311
struct {
4312
  u8 unknown1;
4313
  u8 vfomr;
4314
  u8 keylock;
4315
  u8 unknown2;
4316
  u8 unknown3:4,
4317
     vfomren:1,
4318
     unknown4:1,
4319
     reseten:1,
4320
     menuen:1;
4321
  u8 unknown5[11];
4322
  u8 dispab;
4323
  u8 unknown6[2];
4324
  u8 smenu;
4325
  u8 unknown7[7];
4326
  u8 vfomra;
4327
  u8 vfomrb;
4328
  u8 vfomrc;
4329
  u8 vfomrd;
4330
  u8 mrcha;
4331
  u8 mrchb;
4332
  u8 mrchc;
4333
  u8 mrchd;
4334
} settings2;
4335

    
4336
struct settings_vfo {
4337
  u8 freq[8];
4338
  u8 offset[6];
4339
  u8 unknown2[2];
4340
  ul16 rxtone;
4341
  ul16 txtone;
4342
  u8 scode;
4343
  u8 spmute;
4344
  u8 optsig;
4345
  u8 scramble;
4346
  u8 wide;
4347
  u8 power;
4348
  u8 shiftd;
4349
  u8 step;
4350
  u8 unknown3[4];
4351
};
4352

    
4353
#seekto 0x3300;
4354
struct {
4355
  struct settings_vfo a;
4356
  struct settings_vfo b;
4357
  struct settings_vfo c;
4358
  struct settings_vfo d;
4359
} vfo;
4360

    
4361
#seekto 0x3D80;
4362
struct {
4363
  u8 vhf_low[3];
4364
  u8 vhf_high[3];
4365
  u8 unknown1[4];
4366
  u8 unknown2[6];
4367
  u8 vhf2_low[3];
4368
  u8 vhf2_high[3];
4369
  u8 unknown3[4];
4370
  u8 unknown4[6];
4371
  u8 uhf_low[3];
4372
  u8 uhf_high[3];
4373
  u8 unknown5[4];
4374
  u8 unknown6[6];
4375
  u8 uhf2_low[3];
4376
  u8 uhf2_high[3];
4377
} ranges;
4378

    
4379
#seekto 0x33B0;
4380
struct {
4381
  char line[16];
4382
} static_msg;
4383

    
4384
#seekto 0x3F70;
4385
struct {
4386
  char fp[6];
4387
} fingerprint;
4388

    
4389
"""
4390

    
4391

    
4392
class BTechGMRS(BTechMobileCommon):
4393
    """BTECH's GMRS Mobile"""
4394
    COLOR_LCD = True
4395
    COLOR_LCD2 = True
4396
    NAME_LENGTH = 7
4397
    UPLOAD_MEM_SIZE = 0X3400
4398

    
4399
    def process_mmap(self):
4400
        """Process the mem map into the mem object"""
4401

    
4402
        # Get it
4403
        self._memobj = bitwise.parse(GMRS_MEM_FORMAT, self._mmap)
4404

    
4405
        # load specific parameters from the radio image
4406
        self.set_options()
4407

    
4408
    def set_options(self):
4409
        """This is to read the options from the image and set it in the
4410
        environment, for now just the limits of the freqs in the VHF/UHF
4411
        ranges"""
4412

    
4413
        # setting the correct ranges for each radio type
4414
        ranges = self._memobj.ranges
4415

    
4416
        # the normal dual bands
4417
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
4418
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
4419

    
4420
        # DEBUG
4421
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
4422
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
4423

    
4424
        # set the class with the real data
4425
        self._vhf_range = vhf
4426
        self._uhf_range = uhf
4427

    
4428

    
4429
# real radios
4430
@directory.register
4431
class GMRS50X1(BTechGMRS):
4432
    """Baofeng Tech GMRS50X1"""
4433
    MODEL = "GMRS-50X1"
4434
    BANDS = 2
4435
    LIST_TMR = LIST_TMR16
4436
    _power_levels = [chirp_common.PowerLevel("High", watts=50),
4437
                     chirp_common.PowerLevel("Mid", watts=10),
4438
                     chirp_common.PowerLevel("Low", watts=5)]
4439
    _vhf_range = (136000000, 175000000)
4440
    _uhf_range = (400000000, 521000000)
4441
    _upper = 255
4442
    _magic = MSTRING_GMRS50X1
4443
    _fileid = [GMRS50X1_fp1, GMRS50X1_fp, ]
4444

    
4445

    
4446
COLORHT_MEM_FORMAT = """
4447
#seekto 0x0000;
4448
struct {
4449
  lbcd rxfreq[4];
4450
  lbcd txfreq[4];
4451
  ul16 rxtone;
4452
  ul16 txtone;
4453
  u8 unknown0:4,
4454
     scode:4;
4455
  u8 unknown1:2,
4456
     spmute:2,
4457
     unknown2:2,
4458
     optsig:2;
4459
  u8 unknown3:3,
4460
     scramble:1,
4461
     unknown4:3,
4462
     power:1;
4463
  u8 unknown5:1,
4464
     wide:1,
4465
     unknown6:2,
4466
     bcl:1,
4467
     add:1,
4468
     pttid:2;
4469
} memory[200];
4470

    
4471
#seekto 0x0E00;
4472
struct {
4473
  u8 tmr;
4474
  u8 unknownE01;
4475
  u8 sql;
4476
  u8 unknownE03[2];
4477
  u8 tot;
4478
  u8 save;
4479
  u8 unknownE07;
4480
  u8 abr;
4481
  u8 beep;
4482
  u8 unknownE0A[4];
4483
  u8 dsub;
4484
  u8 dtmfst;
4485
  u8 screv;
4486
  u8 unknownE11[3];
4487
  u8 pttid;
4488
  u8 unknownE15;
4489
  u8 pttlt;
4490
  u8 unknownE17;
4491
  u8 emctp;
4492
  u8 emcch;
4493
  u8 sigbp;
4494
  u8 unknownE1B;
4495
  u8 camdf;
4496
  u8 cbmdf;
4497
  u8 ccmdf;
4498
  u8 cdmdf;
4499
  u8 langua;
4500
  u8 voice;
4501
  u8 vox;
4502
  u8 voxt;
4503
  u8 sync;          // BTech radios use this as the display sync setting
4504
                    // other radios use this as the auto keypad lock setting
4505
  u8 stfc;
4506
  u8 mffc;
4507
  u8 sfafc;
4508
  u8 sfbfc;
4509
  u8 sfcfc;
4510
  u8 sfdfc;
4511
  u8 subfc;
4512
  u8 fmfc;
4513
  u8 sigfc;
4514
  u8 menufc;
4515
  u8 txfc;
4516
  u8 rxfc;
4517
  u8 unknownE31[5];
4518
  u8 anil;
4519
  u8 reps;
4520
  u8 tmrmr;
4521
  u8 ste;
4522
  u8 rpste;
4523
  u8 rptdl;
4524
  u8 dtmfg;
4525
  u8 tmrtx;
4526
} settings;
4527

    
4528
#seekto 0x0E80;
4529
struct {
4530
  u8 unknown1;
4531
  u8 vfomr;
4532
  u8 keylock;
4533
  u8 unknown2;
4534
  u8 unknown3:4,
4535
     vfomren:1,
4536
     unknown4:1,
4537
     reseten:1,
4538
     menuen:1;
4539
  u8 unknown5[11];
4540
  u8 dispab;
4541
  u8 unknown6[2];
4542
  u8 menu;
4543
  u8 unknown7[7];
4544
  u8 vfomra;
4545
  u8 vfomrb;
4546
  u8 vfomrc;
4547
  u8 vfomrd;
4548
  u8 mrcha;
4549
  u8 mrchb;
4550
  u8 mrchc;
4551
  u8 mrchd;
4552
} settings2;
4553

    
4554
struct settings_vfo {
4555
  u8 freq[8];
4556
  u8 offset[6];
4557
  u8 unknown2[2];
4558
  ul16 rxtone;
4559
  ul16 txtone;
4560
  u8 scode;
4561
  u8 spmute;
4562
  u8 optsig;
4563
  u8 scramble;
4564
  u8 wide;
4565
  u8 power;
4566
  u8 shiftd;
4567
  u8 step;
4568
  u8 unknown3[4];
4569
};
4570

    
4571
#seekto 0x0F00;
4572
struct {
4573
  struct settings_vfo a;
4574
  struct settings_vfo b;
4575
  struct settings_vfo c;
4576
  struct settings_vfo d;
4577
} vfo;
4578

    
4579
#seekto 0x0FE0;
4580
struct {
4581
  char line[16];
4582
} static_msg;
4583

    
4584
#seekto 0x1000;
4585
struct {
4586
  char name[8];
4587
  u8 unknown1[8];
4588
} names[200];
4589

    
4590
#seekto 0x2400;
4591
struct {
4592
  u8 period; // one out of LIST_5TONE_STANDARD_PERIODS
4593
  u8 group_tone;
4594
  u8 repeat_tone;
4595
  u8 unused[13];
4596
} _5tone_std_settings[15];
4597

    
4598
#seekto 0x2500;
4599
struct {
4600
  u8 frame1[5];
4601
  u8 frame2[5];
4602
  u8 frame3[5];
4603
  u8 standard;   // one out of LIST_5TONE_STANDARDS
4604
} _5tone_codes[15];
4605

    
4606
#seekto 0x25F0;
4607
struct {
4608
  u8 _5tone_delay1; // * 10ms
4609
  u8 _5tone_delay2; // * 10ms
4610
  u8 _5tone_delay3; // * 10ms
4611
  u8 _5tone_first_digit_ext_length;
4612
  u8 unknown1;
4613
  u8 unknown2;
4614
  u8 unknown3;
4615
  u8 unknown4;
4616
  u8 decode_standard;
4617
  u8 unknown5:5,
4618
     _5tone_decode_call_frame3:1,
4619
     _5tone_decode_call_frame2:1,
4620
     _5tone_decode_call_frame1:1;
4621
  u8 unknown6:5,
4622
     _5tone_decode_disp_frame3:1,
4623
     _5tone_decode_disp_frame2:1,
4624
     _5tone_decode_disp_frame1:1;
4625
  u8 decode_reset_time; // * 100 + 100ms
4626
} _5tone_settings;
4627

    
4628
#seekto 0x2900;
4629
struct {
4630
  u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B
4631
} dtmf_codes[15];
4632

    
4633
#seekto 0x29F0;
4634
struct {
4635
  u8 dtmfspeed_on;  //list with 50..2000ms in steps of 10
4636
  u8 dtmfspeed_off; //list with 50..2000ms in steps of 10
4637
  u8 unknown0[14];
4638
  u8 inspection[16];
4639
  u8 monitor[16];
4640
  u8 alarmcode[16];
4641
  u8 stun[16];
4642
  u8 kill[16];
4643
  u8 revive[16];
4644
  u8 unknown1[16];
4645
  u8 unknown2[16];
4646
  u8 unknown3[16];
4647
  u8 unknown4[16];
4648
  u8 unknown5[16];
4649
  u8 unknown6[16];
4650
  u8 unknown7[16];
4651
  u8 masterid[16];
4652
  u8 viceid[16];
4653
  u8 unused01:7,
4654
     mastervice:1;
4655
  u8 unused02:3,
4656
     mrevive:1,
4657
     mkill:1,
4658
     mstun:1,
4659
     mmonitor:1,
4660
     minspection:1;
4661
  u8 unused03:3,
4662
     vrevive:1,
4663
     vkill:1,
4664
     vstun:1,
4665
     vmonitor:1,
4666
     vinspection:1;
4667
  u8 unused04:6,
4668
     txdisable:1,
4669
     rxdisable:1;
4670
  u8 groupcode;
4671
  u8 spacecode;
4672
  u8 delayproctime; // * 100 + 100ms
4673
  u8 resettime;     // * 100 + 100ms
4674
} dtmf_settings;
4675

    
4676
#seekto 0x2D00;
4677
struct {
4678
  struct {
4679
    ul16 freq1;
4680
    u8 unused01[6];
4681
    ul16 freq2;
4682
    u8 unused02[6];
4683
  } _2tone_encode[15];
4684
  u8 duration_1st_tone; // *10ms
4685
  u8 duration_2nd_tone; // *10ms
4686
  u8 duration_gap;      // *10ms
4687
  u8 unused03[13];
4688
  struct {
4689
    struct {
4690
      u8 dec;      // one out of LIST_2TONE_DEC
4691
      u8 response; // one out of LIST_2TONE_RESPONSE
4692
      u8 alert;    // 1-16
4693
    } decs[4];
4694
    u8 unused04[4];
4695
  } _2tone_decode[15];
4696
  u8 unused05[16];
4697

    
4698
  struct {
4699
    ul16 freqA;
4700
    ul16 freqB;
4701
    ul16 freqC;
4702
    ul16 freqD;
4703
    // unknown what those values mean, but they are
4704
    // derived from configured frequencies
4705
    ul16 derived_from_freqA; // 2304000/freqA
4706
    ul16 derived_from_freqB; // 2304000/freqB
4707
    ul16 derived_from_freqC; // 2304000/freqC
4708
    ul16 derived_from_freqD; // 2304000/freqD
4709
  }freqs[15];
4710
  u8 reset_time;  // * 100 + 100ms - 100-8000ms
4711
} _2tone;
4712

    
4713
#seekto 0x3D80;
4714
struct {
4715
  u8 vhf_low[3];
4716
  u8 vhf_high[3];
4717
  u8 unknown1[4];
4718
  u8 unknown2[6];
4719
  u8 vhf2_low[3];
4720
  u8 vhf2_high[3];
4721
  u8 unknown3[4];
4722
  u8 unknown4[6];
4723
  u8 uhf_low[3];
4724
  u8 uhf_high[3];
4725
  u8 unknown5[4];
4726
  u8 unknown6[6];
4727
  u8 uhf2_low[3];
4728
  u8 uhf2_high[3];
4729
} ranges;
4730

    
4731
#seekto 0x3F70;
4732
struct {
4733
  char fp[6];
4734
} fingerprint;
4735

    
4736
"""
4737

    
4738

    
4739
class QYTColorHT(BTechMobileCommon):
4740
    """QTY's Color LCD Handheld and alike radios"""
4741
    COLOR_LCD = True
4742
    COLOR_LCD3 = True
4743
    NAME_LENGTH = 8
4744
    LIST_TMR = LIST_TMR15
4745

    
4746
    def process_mmap(self):
4747
        """Process the mem map into the mem object"""
4748

    
4749
        # Get it
4750
        self._memobj = bitwise.parse(COLORHT_MEM_FORMAT, self._mmap)
4751

    
4752
        # load specific parameters from the radio image
4753
        self.set_options()
4754

    
4755
    def set_options(self):
4756
        """This is to read the options from the image and set it in the
4757
        environment, for now just the limits of the freqs in the VHF/UHF
4758
        ranges"""
4759

    
4760
        # setting the correct ranges for each radio type
4761
        ranges = self._memobj.ranges
4762

    
4763
        # the normal dual bands
4764
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
4765
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
4766

    
4767
        # DEBUG
4768
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
4769
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
4770

    
4771
        # the additional bands
4772
        if self.MODEL in ["KT-8R"]:
4773
            # 200Mhz band
4774
            vhf2 = _decode_ranges(ranges.vhf2_low, ranges.vhf2_high)
4775
            LOG.info("Radio ranges: VHF(220) %d to %d" % vhf2)
4776
            self._220_range = vhf2
4777

    
4778
            # 350Mhz band
4779
            uhf2 = _decode_ranges(ranges.uhf2_low, ranges.uhf2_high)
4780
            LOG.info("Radio ranges: UHF(350) %d to %d" % uhf2)
4781
            self._350_range = uhf2
4782

    
4783
        # set the class with the real data
4784
        self._vhf_range = vhf
4785
        self._uhf_range = uhf
4786

    
4787

    
4788
# real radios
4789
@directory.register
4790
class KT8R(QYTColorHT):
4791
    """QYT KT8R"""
4792
    VENDOR = "QYT"
4793
    MODEL = "KT-8R"
4794
    BANDS = 4
4795
    LIST_TMR = LIST_TMR16
4796
    _vhf_range = (136000000, 175000000)
4797
    _220_range = (200000000, 261000000)
4798
    _uhf_range = (400000000, 481000000)
4799
    _350_range = (350000000, 391000000)
4800
    _magic = MSTRING_KT8R
4801
    _fileid = [KT8R_fp2, KT8R_fp1, KT8R_fp, ]
4802
    _power_levels = [chirp_common.PowerLevel("High", watts=5),
4803
                     chirp_common.PowerLevel("Low", watts=1)]
(3-3/3)