Project

General

Profile

New Model #9816 » btech_M3B064.py

Jim Unroe, 04/01/2022 08:26 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
        for byte in data:
369
            radio.pipe.write(byte)
370
            # Some OS (mainly Linux ones) are too fast on the serial and
371
            # get the MCU inside the radio stuck in the early stages, this
372
            # hits some models more than others.
373
            #
374
            # To cope with that we introduce a delay on the writes.
375
            # Many option have been tested (delaying only after error occures,
376
            # after short reads, only for linux, ...)
377
            # Finally, a static delay was chosen as simplest of all solutions
378
            # (Michael Wagner, OE4AMW)
379
            # (for details, see issue 3993)
380
            sleep(0.002)
381

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

    
389

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

    
397
    return frame
398

    
399

    
400
def _recv(radio, addr):
401
    """Get data from the radio all at once to lower syscalls load"""
402

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

    
406
    # get the whole block
407
    block = _rawrecv(radio, BLOCK_SIZE + 5)
408

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

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

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

    
424
    # return the data
425
    return block[5:]
426

    
427

    
428
def _start_clone_mode(radio, status):
429
    """Put the radio in clone mode and get the ident string, 3 tries"""
430

    
431
    # cleaning the serial buffer
432
    _clean_buffer(radio)
433

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

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

    
446
            # send the magic word
447
            _send(radio, radio._magic)
448

    
449
            # Now you get a x06 of ACK if all goes well
450
            ack = radio.pipe.read(1)
451

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

    
458
                return True
459

    
460
        return False
461

    
462
    except errors.RadioError:
463
        raise
464
    except Exception, e:
465
        raise errors.RadioError("Error sending Magic to radio:\n%s" % e)
466

    
467

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

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

    
483
    # Ok, get the ident string
484
    ident = _rawrecv(radio, 49)
485

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

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

    
500
            break
501

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

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

    
512
        # query & receive the extra ID
513
        _send(radio, _make_frame("S", 0x3DF0, 16))
514
        id2 = _rawrecv(radio, 21)
515

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

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

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

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

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

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

    
560
            # restore the default serial timeout
561
            radio.pipe.timeout = STIMEOUT
562

    
563
    # DEBUG
564
    LOG.info("Positive ident, this is a %s %s" % (radio.VENDOR, radio.MODEL))
565

    
566
    return True
567

    
568

    
569
def _download(radio):
570
    """Get the memory map"""
571

    
572
    # UI progress
573
    status = chirp_common.Status()
574

    
575
    # put radio in program mode and identify it
576
    _do_ident(radio, status)
577

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

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

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

    
593
    # cleaning the serial buffer
594
    _clean_buffer(radio)
595

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

    
601
        # read
602
        d = _recv(radio, addr)
603

    
604
        # aggregate the data
605
        data += d
606

    
607
        # UI Update
608
        status.cur = addr / BLOCK_SIZE
609
        status.msg = "Cloning from radio..."
610
        radio.status_fn(status)
611

    
612
    return data
613

    
614

    
615
def _upload(radio):
616
    """Upload procedure"""
617

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

    
622
    # UI progress
623
    status = chirp_common.Status()
624

    
625
    # put radio in program mode and identify it
626
    _do_ident(radio, status, True)
627

    
628
    # get the data to upload to radio
629
    data = radio.get_mmap()
630

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

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

    
641
    # cleaning the serial buffer
642
    _clean_buffer(radio)
643

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

    
649
        # build the frame to send
650
        frame = _make_frame("X", addr, TX_BLOCK_SIZE, d)
651

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

    
657
        # send the frame
658
        _send(radio, frame)
659

    
660
        # receiving the response
661
        ack = _rawrecv(radio, 1)
662

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

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

    
670
        # UI Update
671
        status.cur = addr / TX_BLOCK_SIZE
672
        status.msg = "Cloning to radio..."
673
        radio.status_fn(status)
674

    
675

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

    
680
    if rid in cls._fileid:
681
        return True
682

    
683
    return False
684

    
685

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

    
694
    return (ilow, ihigh)
695

    
696

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

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

    
708
    # if you get here is because the freq pairs are split
709
    return True
710

    
711

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

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

    
751
            1 - Turn off your radio
752
            2 - Connect your interface cable
753
            3 - Turn on your radio
754
            4 - Do the download of your radio data
755

    
756
            """))
757
        rp.pre_upload = _(dedent("""\
758
            Follow these instructions to upload your info:
759

    
760
            1 - Turn off your radio
761
            2 - Connect your interface cable
762
            3 - Turn on your radio
763
            4 - Do the upload of your radio data
764

    
765
            """))
766
        return rp
767

    
768
    def get_features(self):
769
        """Get the radio's features"""
770

    
771
        # we will use the following var as global
772
        global POWER_LEVELS
773

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

    
805
        # power levels
806
        POWER_LEVELS = self._power_levels
807
        rf.valid_power_levels = POWER_LEVELS
808

    
809
        # normal dual bands
810
        rf.valid_bands = [self._vhf_range, self._uhf_range]
811

    
812
        # 220 band
813
        if self.BANDS == 3 or self.BANDS == 4:
814
            rf.valid_bands.append(self._220_range)
815

    
816
        # 350 band
817
        if self.BANDS == 4:
818
            rf.valid_bands.append(self._350_range)
819

    
820
        return rf
821

    
822
    def validate_memory(self, mem):
823
        msgs = chirp_common.CloneModeRadio.validate_memory(self, mem)
824

    
825
        _msg_duplex1 = 'Memory location only supports "Low"'
826
        _msg_duplex2 = 'Memory location only supports "off"'
827
        _msg_duplex3 = 'Memory location only supports "(None)", "+" or "off"'
828

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

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

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

    
849
        return msgs
850

    
851
    def sync_in(self):
852
        """Download from radio"""
853
        data = _download(self)
854
        self._mmap = memmap.MemoryMap(data)
855
        self.process_mmap()
856

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

    
866
    def get_raw_memory(self, number):
867
        return repr(self._memobj.memory[number])
868

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

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

    
887
            tone = DTCS[index]
888
            return 'DTCS', tone, pol
889

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

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

    
919
        # Create a high-level memory object to return to the UI
920
        mem = chirp_common.Memory()
921

    
922
        # Memory number
923
        mem.number = number
924

    
925
        if _mem.get_raw()[0] == "\xFF":
926
            mem.empty = True
927
            return mem
928

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

    
953
        # name TAG of the channel
954
        mem.name = str(_names.name).rstrip("\xFF").replace("\xFF", " ")
955

    
956
        # power
957
        mem.power = POWER_LEVELS[int(_mem.power)]
958

    
959
        # wide/narrow
960
        mem.mode = MODES[int(_mem.wide)]
961

    
962
        # skip
963
        mem.skip = SKIP_VALUES[_mem.add]
964

    
965
        # tone data
966
        rxtone = txtone = None
967
        txtone = self._decode_tone(_mem.txtone)
968
        rxtone = self._decode_tone(_mem.rxtone)
969
        chirp_common.split_tone_decode(mem, txtone, rxtone)
970

    
971
        # Extra
972
        mem.extra = RadioSettingGroup("extra", "Extra")
973

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

    
981
        bcl = RadioSetting("bcl", "Busy channel lockout",
982
                           RadioSettingValueBoolean(bool(_mem.bcl)))
983
        mem.extra.append(bcl)
984

    
985
        pttid = RadioSetting("pttid", "PTT ID",
986
                             RadioSettingValueList(PTTID_LIST,
987
                                                   PTTID_LIST[_mem.pttid]))
988
        mem.extra.append(pttid)
989

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

    
998
        optsig = RadioSetting("optsig", "Optional signaling",
999
                              RadioSettingValueList(
1000
                                  OPTSIG_LIST,
1001
                                  OPTSIG_LIST[_mem.optsig]))
1002
        mem.extra.append(optsig)
1003

    
1004
        spmute = RadioSetting("spmute", "Speaker mute",
1005
                              RadioSettingValueList(
1006
                                  SPMUTE_LIST,
1007
                                  SPMUTE_LIST[_mem.spmute]))
1008
        mem.extra.append(spmute)
1009

    
1010
        return mem
1011

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

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

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

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

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

    
1074
        # frequency
1075
        _mem.rxfreq = mem.freq / 10
1076

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

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

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

    
1102
        # power, # default power level is high
1103
        _mem.power = 0 if mem.power is None else POWER_LEVELS.index(mem.power)
1104

    
1105
        # wide/narrow
1106
        _mem.wide = MODES.index(mem.mode)
1107

    
1108
        # scan add property
1109
        _mem.add = SKIP_VALUES.index(mem.skip)
1110

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

    
1120
        def _zero_settings():
1121
            _mem.spmute = 0
1122
            _mem.optsig = 0
1123
            _mem.scramble = 0
1124
            _mem.bcl = 0
1125
            _mem.pttid = 0
1126
            _mem.scode = 0
1127

    
1128
        if self.COLOR_LCD and _mem.scramble:
1129
            LOG.info('Resetting scramble bit for BTECH COLOR_LCD variant')
1130
            _mem.scramble = 0
1131

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

    
1152
        return mem
1153

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

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

    
1175
        sql = RadioSetting("settings.sql", "Squelch level",
1176
                           RadioSettingValueInteger(0, 9, _mem.settings.sql))
1177
        basic.append(sql)
1178

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

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

    
1190
        tot = RadioSetting("settings.tot", "Time out timer",
1191
                           RadioSettingValueList(
1192
                               LIST_TOT,
1193
                               LIST_TOT[_mem.settings.tot]))
1194
        basic.append(tot)
1195

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

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

    
1216
        abr = RadioSetting("settings.abr", "Backlight timer",
1217
                           RadioSettingValueList(
1218
                               LIST_OFF1TO50,
1219
                               LIST_OFF1TO50[_mem.settings.abr]))
1220
        basic.append(abr)
1221

    
1222
        beep = RadioSetting("settings.beep", "Key beep",
1223
                            RadioSettingValueBoolean(_mem.settings.beep))
1224
        basic.append(beep)
1225

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

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

    
1244
        if not self.COLOR_LCD:
1245
            prisc = RadioSetting("settings.prisc", "Priority scan",
1246
                                 RadioSettingValueBoolean(
1247
                                     _mem.settings.prisc))
1248
            basic.append(prisc)
1249

    
1250
            prich = RadioSetting("settings.prich", "Priority channel",
1251
                                 RadioSettingValueInteger(0, self._upper,
1252
                                                          _mem.settings.prich))
1253
            basic.append(prich)
1254

    
1255
        screv = RadioSetting("settings.screv", "Scan resume method",
1256
                             RadioSettingValueList(
1257
                                 LIST_SCREV,
1258
                                 LIST_SCREV[_mem.settings.screv]))
1259
        basic.append(screv)
1260

    
1261
        pttlt = RadioSetting("settings.pttlt", "PTT transmit delay",
1262
                             RadioSettingValueInteger(0, 30,
1263
                                                      _mem.settings.pttlt))
1264
        basic.append(pttlt)
1265

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

    
1279
        emcch = RadioSetting("settings.emcch", "Alarm channel",
1280
                             RadioSettingValueInteger(0, self._upper,
1281
                                                      _mem.settings.emcch))
1282
        basic.append(emcch)
1283

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

    
1299
        camdf = RadioSetting("settings.camdf", "Display mode A",
1300
                             RadioSettingValueList(
1301
                                 LIST_MDF,
1302
                                 LIST_MDF[_mem.settings.camdf]))
1303
        basic.append(camdf)
1304

    
1305
        cbmdf = RadioSetting("settings.cbmdf", "Display mode B",
1306
                             RadioSettingValueList(
1307
                                 LIST_MDF,
1308
                                 LIST_MDF[_mem.settings.cbmdf]))
1309
        basic.append(cbmdf)
1310

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

    
1318
            cdmdf = RadioSetting("settings.cdmdf", "Display mode D",
1319
                                 RadioSettingValueList(
1320
                                     LIST_MDF,
1321
                                     LIST_MDF[_mem.settings.cdmdf]))
1322
            basic.append(cdmdf)
1323

    
1324
            langua = RadioSetting("settings.langua", "Language",
1325
                                  RadioSettingValueList(
1326
                                      LIST_LANGUA,
1327
                                      LIST_LANGUA[_mem.settings.langua]))
1328
            basic.append(langua)
1329

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

    
1337
            vox = RadioSetting("settings.vox", "VOX",
1338
                               RadioSettingValueList(
1339
                                   LIST_VOX,
1340
                                   LIST_VOX[_mem.settings.vox]))
1341
            basic.append(vox)
1342

    
1343
            voxt = RadioSetting("settings.voxt", "VOX delay time",
1344
                                RadioSettingValueList(
1345
                                    LIST_VOXT,
1346
                                    LIST_VOXT[_mem.settings.voxt]))
1347
            basic.append(voxt)
1348

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

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

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

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

    
1389
            menufc = RadioSetting("settings.menufc", "Menu foreground color",
1390
                                  RadioSettingValueList(
1391
                                      LIST_COLOR9,
1392
                                      LIST_COLOR9[_mem.settings.menufc]))
1393
            basic.append(menufc)
1394

    
1395
            menubc = RadioSetting("settings.menubc", "Menu background color",
1396
                                  RadioSettingValueList(
1397
                                      LIST_COLOR9,
1398
                                      LIST_COLOR9[_mem.settings.menubc]))
1399
            basic.append(menubc)
1400

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

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

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

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

    
1429
            rxfc = RadioSetting("settings.rxfc", "Receiving character color",
1430
                                RadioSettingValueList(
1431
                                    LIST_COLOR9,
1432
                                    LIST_COLOR9[_mem.settings.rxfc]))
1433
            basic.append(rxfc)
1434

    
1435
            txfc = RadioSetting("settings.txfc",
1436
                                "Transmitting character color",
1437
                                RadioSettingValueList(
1438
                                    LIST_COLOR9,
1439
                                    LIST_COLOR9[_mem.settings.txfc]))
1440
            basic.append(txfc)
1441

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

    
1456
            mffc = RadioSetting("settings.mffc",
1457
                                "MF-FC",
1458
                                RadioSettingValueList(
1459
                                    LIST_COLOR8,
1460
                                    LIST_COLOR8[_mem.settings.mffc]))
1461
            basic.append(mffc)
1462

    
1463
            sfafc = RadioSetting("settings.sfafc",
1464
                                 "SFA-FC",
1465
                                 RadioSettingValueList(
1466
                                     LIST_COLOR8,
1467
                                     LIST_COLOR8[_mem.settings.sfafc]))
1468
            basic.append(sfafc)
1469

    
1470
            sfbfc = RadioSetting("settings.sfbfc",
1471
                                 "SFB-FC",
1472
                                 RadioSettingValueList(
1473
                                     LIST_COLOR8,
1474
                                     LIST_COLOR8[_mem.settings.sfbfc]))
1475
            basic.append(sfbfc)
1476

    
1477
            sfcfc = RadioSetting("settings.sfcfc",
1478
                                 "SFC-FC",
1479
                                 RadioSettingValueList(
1480
                                     LIST_COLOR8,
1481
                                     LIST_COLOR8[_mem.settings.sfcfc]))
1482
            basic.append(sfcfc)
1483

    
1484
            sfdfc = RadioSetting("settings.sfdfc",
1485
                                 "SFD-FC",
1486
                                 RadioSettingValueList(
1487
                                     LIST_COLOR8,
1488
                                     LIST_COLOR8[_mem.settings.sfdfc]))
1489
            basic.append(sfdfc)
1490

    
1491
            subfc = RadioSetting("settings.subfc",
1492
                                 "SUB-FC",
1493
                                 RadioSettingValueList(
1494
                                     LIST_COLOR8,
1495
                                     LIST_COLOR8[_mem.settings.subfc]))
1496
            basic.append(subfc)
1497

    
1498
            fmfc = RadioSetting("settings.fmfc",
1499
                                "FM-FC",
1500
                                RadioSettingValueList(
1501
                                    LIST_COLOR8,
1502
                                    LIST_COLOR8[_mem.settings.fmfc]))
1503
            basic.append(fmfc)
1504

    
1505
            sigfc = RadioSetting("settings.sigfc",
1506
                                 "SIG-FC",
1507
                                 RadioSettingValueList(
1508
                                     LIST_COLOR8,
1509
                                     LIST_COLOR8[_mem.settings.sigfc]))
1510
            basic.append(sigfc)
1511

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

    
1520
            menufc = RadioSetting("settings.menufc",
1521
                                  "MENUFC",
1522
                                  RadioSettingValueList(
1523
                                      LIST_COLOR8,
1524
                                      LIST_COLOR8[_mem.settings.menufc]))
1525
            basic.append(menufc)
1526

    
1527
            txfc = RadioSetting("settings.txfc",
1528
                                "TX-FC",
1529
                                RadioSettingValueList(
1530
                                    LIST_COLOR8,
1531
                                    LIST_COLOR8[_mem.settings.txfc]))
1532
            basic.append(txfc)
1533

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

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

    
1556
            rxled = RadioSetting("settings.rxled", "RX backlight Color",
1557
                                 RadioSettingValueList(
1558
                                     LIST_COLOR4,
1559
                                     LIST_COLOR4[_mem.settings.rxled]))
1560
            basic.append(rxled)
1561

    
1562
            txled = RadioSetting("settings.txled", "TX backlight Color",
1563
                                 RadioSettingValueList(
1564
                                     LIST_COLOR4,
1565
                                     LIST_COLOR4[_mem.settings.txled]))
1566
            basic.append(txled)
1567

    
1568
        anil = RadioSetting("settings.anil", "ANI length",
1569
                            RadioSettingValueList(
1570
                                LIST_ANIL,
1571
                                LIST_ANIL[_mem.settings.anil]))
1572
        basic.append(anil)
1573

    
1574
        reps = RadioSetting("settings.reps", "Relay signal (tone burst)",
1575
                            RadioSettingValueList(
1576
                                LIST_REPS,
1577
                                LIST_REPS[_mem.settings.reps]))
1578
        basic.append(reps)
1579

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

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

    
1601
            ste = RadioSetting("settings.ste", "Squelch tail eliminate",
1602
                               RadioSettingValueBoolean(_mem.settings.ste))
1603
            basic.append(ste)
1604

    
1605
            rpste = RadioSetting("settings.rpste", "Repeater STE",
1606
                                 RadioSettingValueList(
1607
                                     LIST_OFF1TO9,
1608
                                     LIST_OFF1TO9[_mem.settings.rpste]))
1609
            basic.append(rpste)
1610

    
1611
            rptdl = RadioSetting("settings.rptdl", "Repeater STE delay",
1612
                                 RadioSettingValueList(
1613
                                     LIST_RPTDL,
1614
                                     LIST_RPTDL[_mem.settings.rptdl]))
1615
            basic.append(rptdl)
1616

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

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

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

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

    
1640
            skiptx = RadioSetting("settings.skiptx", "Skip TX",
1641
                                  RadioSettingValueList(
1642
                                      LIST_SKIPTX,
1643
                                      LIST_SKIPTX[_mem.settings.skiptx]))
1644
            basic.append(skiptx)
1645

    
1646
            scmode = RadioSetting("settings.scmode", "Scan mode",
1647
                                  RadioSettingValueList(
1648
                                      LIST_SCMODE,
1649
                                      LIST_SCMODE[_mem.settings.scmode]))
1650
            basic.append(scmode)
1651

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

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

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

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

    
1735
            reseten = RadioSetting("settings2.reseten", "RESET",
1736
                                   RadioSettingValueBoolean(
1737
                                       _mem.settings2.reseten))
1738
            advanced.append(reseten)
1739

    
1740
            menuen = RadioSetting("settings2.menuen", "Menu",
1741
                                  RadioSettingValueBoolean(
1742
                                      _mem.settings2.menuen))
1743
            advanced.append(menuen)
1744

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

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

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

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

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

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

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

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

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

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

    
1812
        val = RadioSettingValueString(0, 6, _filter(_mem.fingerprint.fp))
1813
        val.set_mutable(False)
1814
        fp = RadioSetting("fingerprint.fp", "Fingerprint", val)
1815
        other.append(fp)
1816

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

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

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

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

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

    
1862
        keylock = RadioSetting("settings2.keylock", "Keypad lock",
1863
                               RadioSettingValueBoolean(
1864
                                   _mem.settings2.keylock))
1865
        work.append(keylock)
1866

    
1867
        mrcha = RadioSetting("settings2.mrcha", "MR A channel",
1868
                             RadioSettingValueInteger(0, self._upper,
1869
                                                      _mem.settings2.mrcha))
1870
        work.append(mrcha)
1871

    
1872
        mrchb = RadioSetting("settings2.mrchb", "MR B channel",
1873
                             RadioSettingValueInteger(0, self._upper,
1874
                                                      _mem.settings2.mrchb))
1875
        work.append(mrchb)
1876

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

    
1883
            mrchd = RadioSetting("settings2.mrchd", "MR D channel",
1884
                                 RadioSettingValueInteger(
1885
                                     0, self._upper, _mem.settings2.mrchd))
1886
            work.append(mrchd)
1887

    
1888
        def convert_bytes_to_freq(bytes):
1889
            real_freq = 0
1890
            for byte in bytes:
1891
                real_freq = (real_freq * 10) + byte
1892
            return chirp_common.format_freq(real_freq * 10)
1893

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

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

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

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

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

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

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

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

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

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

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

    
1998
        def convert_bytes_to_offset(bytes):
1999
            real_offset = 0
2000
            for byte in bytes:
2001
                real_offset = (real_offset * 10) + byte
2002
            return chirp_common.format_freq(real_offset * 1000)
2003

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

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

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

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

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

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

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

    
2065
            vfobtxp = RadioSetting("vfo.b.power", "VFO B power",
2066
                                   RadioSettingValueList(
2067
                                       LIST_TXP,
2068
                                       LIST_TXP[_mem.vfo.b.power]))
2069
            work.append(vfobtxp)
2070

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

    
2078
                vfodtxp = RadioSetting("vfo.d.power", "VFO D power",
2079
                                       RadioSettingValueList(
2080
                                           LIST_TXP,
2081
                                           LIST_TXP[_mem.vfo.d.power]))
2082
                work.append(vfodtxp)
2083

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

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

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

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

    
2110
        vfoastep = RadioSetting("vfo.a.step", "VFO A step",
2111
                                RadioSettingValueList(
2112
                                    LIST_STEP,
2113
                                    LIST_STEP[_mem.vfo.a.step]))
2114
        work.append(vfoastep)
2115

    
2116
        vfobstep = RadioSetting("vfo.b.step", "VFO B step",
2117
                                RadioSettingValueList(
2118
                                    LIST_STEP,
2119
                                    LIST_STEP[_mem.vfo.b.step]))
2120
        work.append(vfobstep)
2121

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

    
2129
            vfodstep = RadioSetting("vfo.d.step", "VFO D step",
2130
                                    RadioSettingValueList(
2131
                                        LIST_STEP,
2132
                                        LIST_STEP[_mem.vfo.d.step]))
2133
            work.append(vfodstep)
2134

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

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

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

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

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

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

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

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

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

    
2192
            vfobscr = RadioSetting("vfo.b.scramble", "VFO B scramble",
2193
                                   RadioSettingValueBoolean(
2194
                                       _mem.vfo.b.scramble))
2195
            work.append(vfobscr)
2196

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

    
2203
            vfodscr = RadioSetting("vfo.d.scramble", "VFO D scramble",
2204
                                   RadioSettingValueBoolean(
2205
                                       _mem.vfo.d.scramble))
2206
            work.append(vfodscr)
2207

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

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

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

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

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

    
2241
        if not self.COLOR_LCD:
2242
            # FM presets
2243
            fm_presets = RadioSettingGroup("fm_presets", "FM Presets")
2244
            top.append(fm_presets)
2245

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

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

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

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

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

    
2289
                i = i + 1
2290

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

    
2304
        rxdisable = RadioSetting("dtmf_settings.rxdisable",
2305
                                 "RX-Disable",
2306
                                 RadioSettingValueBoolean(
2307
                                     _mem.dtmf_settings.rxdisable))
2308
        dtmf_enc_settings.append(rxdisable)
2309

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

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

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

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

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

    
2366
        line = RadioSetting("dtmf_settings.mastervice",
2367
                            "Master and Vice ID",
2368
                            RadioSettingValueBoolean(
2369
                                _mem.dtmf_settings.mastervice))
2370
        dtmf_dec_settings.append(line)
2371

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

    
2381
        line = RadioSetting("dtmf_settings.minspection",
2382
                            "Master Inspection",
2383
                            RadioSettingValueBoolean(
2384
                                _mem.dtmf_settings.minspection))
2385
        dtmf_dec_settings.append(line)
2386

    
2387
        line = RadioSetting("dtmf_settings.mmonitor",
2388
                            "Master Monitor",
2389
                            RadioSettingValueBoolean(
2390
                                _mem.dtmf_settings.mmonitor))
2391
        dtmf_dec_settings.append(line)
2392

    
2393
        line = RadioSetting("dtmf_settings.mstun",
2394
                            "Master Stun",
2395
                            RadioSettingValueBoolean(
2396
                                _mem.dtmf_settings.mstun))
2397
        dtmf_dec_settings.append(line)
2398

    
2399
        line = RadioSetting("dtmf_settings.mkill",
2400
                            "Master Kill",
2401
                            RadioSettingValueBoolean(
2402
                                _mem.dtmf_settings.mkill))
2403
        dtmf_dec_settings.append(line)
2404

    
2405
        line = RadioSetting("dtmf_settings.mrevive",
2406
                            "Master Revive",
2407
                            RadioSettingValueBoolean(
2408
                                _mem.dtmf_settings.mrevive))
2409
        dtmf_dec_settings.append(line)
2410

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

    
2420
        line = RadioSetting("dtmf_settings.vinspection",
2421
                            "Vice Inspection",
2422
                            RadioSettingValueBoolean(
2423
                                _mem.dtmf_settings.vinspection))
2424
        dtmf_dec_settings.append(line)
2425

    
2426
        line = RadioSetting("dtmf_settings.vmonitor",
2427
                            "Vice Monitor",
2428
                            RadioSettingValueBoolean(
2429
                                _mem.dtmf_settings.vmonitor))
2430
        dtmf_dec_settings.append(line)
2431

    
2432
        line = RadioSetting("dtmf_settings.vstun",
2433
                            "Vice Stun",
2434
                            RadioSettingValueBoolean(
2435
                                _mem.dtmf_settings.vstun))
2436
        dtmf_dec_settings.append(line)
2437

    
2438
        line = RadioSetting("dtmf_settings.vkill",
2439
                            "Vice Kill",
2440
                            RadioSettingValueBoolean(
2441
                                _mem.dtmf_settings.vkill))
2442
        dtmf_dec_settings.append(line)
2443

    
2444
        line = RadioSetting("dtmf_settings.vrevive",
2445
                            "Vice Revive",
2446
                            RadioSettingValueBoolean(
2447
                                _mem.dtmf_settings.vrevive))
2448
        dtmf_dec_settings.append(line)
2449

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

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

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

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

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

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

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

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

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

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

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

    
2572
        # 5 Tone Settings
2573
        stds_5tone = RadioSettingGroup("stds_5tone", "Standards")
2574
        codes_5tone = RadioSettingGroup("codes_5tone", "Codes")
2575

    
2576
        group_5tone = RadioSettingGroup("group_5tone", "5 Tone Settings")
2577
        group_5tone.append(stds_5tone)
2578
        group_5tone.append(codes_5tone)
2579

    
2580
        top.append(group_5tone)
2581

    
2582
        def apply_list_value(setting, obj):
2583
            options = setting.value.get_options()
2584
            obj.set_value(options.index(str(setting.value)))
2585

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2793
        _5tone_delay1 = _mem._5tone_settings._5tone_delay1
2794
        if _5tone_delay1 == 255:
2795
            _5tone_delay1 = 20
2796

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

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

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

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

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

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

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

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

    
2869
        # 2 Tone
2870
        encode_2tone = RadioSettingGroup("encode_2tone", "2 Tone Encode")
2871
        decode_2tone = RadioSettingGroup("decode_2tone", "2 Code Decode")
2872

    
2873
        top.append(encode_2tone)
2874
        top.append(decode_2tone)
2875

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

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

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

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

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

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

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

    
2927
        def apply_2tone_freq(setting, obj):
2928
            val = int(setting.value)
2929
            if (val == 0) or (val == 65535):
2930
                obj.set_value(65535)
2931
            else:
2932
                obj.set_value(val)
2933

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

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

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

    
2960
            i = i + 1
2961

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

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

    
2983
            if (val == 0):
2984
                val = 65535
2985
                derived_val = 65535
2986
            else:
2987
                derived_val = int(round(2304000.0/val))
2988

    
2989
            obj[frqname].set_value(val)
2990
            obj[derivedname].set_value(derived_val)
2991

    
2992
            LOG.debug("Apply " + frqname + ": " + str(val) + " | " +
2993
                      derivedname + ": " + str(derived_val))
2994

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

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

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

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

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

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

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

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

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

    
3077
            i = i + 1
3078

    
3079
        return top
3080

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

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

    
3118
    @classmethod
3119
    def match_model(cls, filedata, filename):
3120
        match_size = False
3121
        match_model = False
3122

    
3123
        # testing the file data size
3124
        if len(filedata) == MEM_SIZE:
3125
            match_size = True
3126

    
3127
        # testing the firmware model fingerprint
3128
        match_model = model_match(cls, filedata)
3129

    
3130
        if match_size and match_model:
3131
            return True
3132
        else:
3133
            return False
3134

    
3135

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

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

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

    
3225
#seekto 0x0EC0;
3226
struct {
3227
  char line1[6];
3228
  char line2[6];
3229
} poweron_msg;
3230

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

    
3248
#seekto 0x0F00;
3249
struct {
3250
  struct settings_vfo a;
3251
  struct settings_vfo b;
3252
} vfo;
3253

    
3254
#seekto 0x1000;
3255
struct {
3256
  char name[6];
3257
  u8 unknown1[10];
3258
} names[200];
3259

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

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

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

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

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

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

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

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

    
3390
#seekto 0x3C90;
3391
struct {
3392
  u8 vhf_low[3];
3393
  u8 vhf_high[3];
3394
  u8 uhf_low[3];
3395
  u8 uhf_high[3];
3396
} ranges;
3397

    
3398
// the UV-2501+220 & KT8900R has different zones for storing ranges
3399

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

    
3414
#seekto 0x3F70;
3415
struct {
3416
  char fp[6];
3417
} fingerprint;
3418

    
3419
"""
3420

    
3421

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

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

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

    
3442
        # the normal dual bands
3443
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
3444
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
3445

    
3446
        # DEBUG
3447
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
3448
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
3449

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

    
3456
        # set the class with the real data
3457
        self._vhf_range = vhf
3458
        self._uhf_range = uhf
3459

    
3460
    def process_mmap(self):
3461
        """Process the mem map into the mem object"""
3462

    
3463
        # Get it
3464
        self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)
3465

    
3466
        # load specific parameters from the radio image
3467
        self.set_options()
3468

    
3469

    
3470
# Declaring Aliases (Clones of the real radios)
3471
class JT2705M(chirp_common.Alias):
3472
    VENDOR = "Jetstream"
3473
    MODEL = "JT2705M"
3474

    
3475

    
3476
class JT6188Mini(chirp_common.Alias):
3477
    VENDOR = "Juentai"
3478
    MODEL = "JT-6188 Mini"
3479

    
3480

    
3481
class JT6188Plus(chirp_common.Alias):
3482
    VENDOR = "Juentai"
3483
    MODEL = "JT-6188 Plus"
3484

    
3485

    
3486
class SSGT890(chirp_common.Alias):
3487
    VENDOR = "Sainsonic"
3488
    MODEL = "GT-890"
3489

    
3490

    
3491
class ZastoneMP300(chirp_common.Alias):
3492
    VENDOR = "Zastone"
3493
    MODEL = "MP-300"
3494

    
3495

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

    
3506

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

    
3519

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

    
3532

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

    
3543

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

    
3556
# Please note that there is a version of this radios that is a clone of the
3557
# Waccom Mini8900, maybe an early version?
3558

    
3559

    
3560
class OTGRadioV1(chirp_common.Alias):
3561
    VENDOR = 'OTGSTUFF'
3562
    MODEL = 'OTG Radio v1'
3563

    
3564

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

    
3585

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

    
3604

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

    
3618

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

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

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

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

    
3744
#seekto 0x0F00;
3745
struct {
3746
  struct settings_vfo a;
3747
  struct settings_vfo b;
3748
  struct settings_vfo c;
3749
  struct settings_vfo d;
3750
} vfo;
3751

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

    
3764
#seekto 0x1000;
3765
struct {
3766
  char name[8];
3767
  u8 unknown1[8];
3768
} names[200];
3769

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

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

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

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

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

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

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

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

    
3911
#seekto 0x3F70;
3912
struct {
3913
  char fp[6];
3914
} fingerprint;
3915

    
3916
"""
3917

    
3918

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

    
3925
    def process_mmap(self):
3926
        """Process the mem map into the mem object"""
3927

    
3928
        # Get it
3929
        self._memobj = bitwise.parse(COLOR_MEM_FORMAT, self._mmap)
3930

    
3931
        # load specific parameters from the radio image
3932
        self.set_options()
3933

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

    
3939
        # setting the correct ranges for each radio type
3940
        ranges = self._memobj.ranges
3941

    
3942
        # the normal dual bands
3943
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
3944
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
3945

    
3946
        # DEBUG
3947
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
3948
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
3949

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

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

    
3962
        # set the class with the real data
3963
        self._vhf_range = vhf
3964
        self._uhf_range = uhf
3965

    
3966

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

    
3972

    
3973
class QB25(chirp_common.Alias):
3974
    VENDOR = "Radioddity"
3975
    MODEL = "QB25"
3976

    
3977

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

    
3989

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

    
4002

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

    
4015

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

    
4033

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

    
4046
    # Clones
4047
    ALIASES = [OTGRadioV1]
4048

    
4049

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

    
4062

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

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

    
4082

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

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

    
4104

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

    
4130
#seekto 0x1000;
4131
struct {
4132
  char name[7];
4133
  u8 unknown1[9];
4134
} names[256];
4135

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

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

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

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

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

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

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

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

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

    
4297

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

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

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

    
4368
#seekto 0x3300;
4369
struct {
4370
  struct settings_vfo a;
4371
  struct settings_vfo b;
4372
  struct settings_vfo c;
4373
  struct settings_vfo d;
4374
} vfo;
4375

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

    
4394
#seekto 0x33B0;
4395
struct {
4396
  char line[16];
4397
} static_msg;
4398

    
4399
#seekto 0x3F70;
4400
struct {
4401
  char fp[6];
4402
} fingerprint;
4403

    
4404
"""
4405

    
4406

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

    
4414
    def process_mmap(self):
4415
        """Process the mem map into the mem object"""
4416

    
4417
        # Get it
4418
        self._memobj = bitwise.parse(GMRS_MEM_FORMAT, self._mmap)
4419

    
4420
        # load specific parameters from the radio image
4421
        self.set_options()
4422

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

    
4428
        # setting the correct ranges for each radio type
4429
        ranges = self._memobj.ranges
4430

    
4431
        # the normal dual bands
4432
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
4433
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
4434

    
4435
        # DEBUG
4436
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
4437
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
4438

    
4439
        # set the class with the real data
4440
        self._vhf_range = vhf
4441
        self._uhf_range = uhf
4442

    
4443

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

    
4460

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

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

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

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

    
4586
#seekto 0x0F00;
4587
struct {
4588
  struct settings_vfo a;
4589
  struct settings_vfo b;
4590
  struct settings_vfo c;
4591
  struct settings_vfo d;
4592
} vfo;
4593

    
4594
#seekto 0x0FE0;
4595
struct {
4596
  char line[16];
4597
} static_msg;
4598

    
4599
#seekto 0x1000;
4600
struct {
4601
  char name[8];
4602
  u8 unknown1[8];
4603
} names[200];
4604

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

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

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

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

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

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

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

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

    
4746
#seekto 0x3F70;
4747
struct {
4748
  char fp[6];
4749
} fingerprint;
4750

    
4751
"""
4752

    
4753

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

    
4761
    def process_mmap(self):
4762
        """Process the mem map into the mem object"""
4763

    
4764
        # Get it
4765
        self._memobj = bitwise.parse(COLORHT_MEM_FORMAT, self._mmap)
4766

    
4767
        # load specific parameters from the radio image
4768
        self.set_options()
4769

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

    
4775
        # setting the correct ranges for each radio type
4776
        ranges = self._memobj.ranges
4777

    
4778
        # the normal dual bands
4779
        vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high)
4780
        uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high)
4781

    
4782
        # DEBUG
4783
        LOG.info("Radio ranges: VHF %d to %d" % vhf)
4784
        LOG.info("Radio ranges: UHF %d to %d" % uhf)
4785

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

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

    
4798
        # set the class with the real data
4799
        self._vhf_range = vhf
4800
        self._uhf_range = uhf
4801

    
4802

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