Project

General

Profile

Feature #9043 » retevis_rt22_with_BCL_draft_#1.py

Jim Unroe, 05/21/2021 03:18 PM

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

    
16
import time
17
import os
18
import struct
19
import logging
20

    
21
from chirp import chirp_common, directory, memmap
22
from chirp import bitwise, errors, util
23
from chirp.settings import RadioSetting, RadioSettingGroup, \
24
    RadioSettingValueInteger, RadioSettingValueList, \
25
    RadioSettingValueBoolean, RadioSettings, \
26
    RadioSettingValueString
27

    
28
LOG = logging.getLogger(__name__)
29

    
30
MEM_FORMAT = """
31
#seekto 0x0010;
32
struct {
33
  lbcd rxfreq[4];
34
  lbcd txfreq[4];
35
  ul16 rx_tone;
36
  ul16 tx_tone;
37
  u8 unknown1;
38
  u8 unknown3:2,
39
     highpower:1, // Power Level
40
     wide:1,      // Bandwidth
41
     unknown4:2,
42
     signal:1,    // Signal
43
     bcl:1;       // BCL
44
  u8 unknown5[2];
45
} memory[16];
46

    
47
#seekto 0x012F;
48
struct {
49
  u8 voice;       // Voice Annunciation
50
  u8 tot;         // Time-out Timer
51
  u8 unknown1[2];
52
  u8 ch;          // Selected Channel Number
53
  u8 squelch;     // Squelch Level
54
  u8 save;        // Battery Saver
55
  u8 beep;        // Beep
56
  u8 unknown2[2];
57
  u8 vox;         // VOX
58
  u8 voxgain;     // VOX Gain
59
  u8 voxdelay;    // VOX Delay
60
  u8 unknown3[2];
61
  u8 pf2key;      // PF2 Key
62
} settings;
63

    
64
#seekto 0x017E;
65
u8 skipflags[2];  // SCAN_ADD
66

    
67
#seekto 0x0200;
68
struct {
69
  char id_0x200[8];  // Radio ID @ 0x0200
70
} radio;
71

    
72
#seekto 0x0300;
73
struct {
74
  char line1[32];
75
  char line2[32];
76
} embedded_msg;
77
"""
78

    
79
CMD_ACK = "\x06"
80

    
81
RT22_POWER_LEVELS = [chirp_common.PowerLevel("Low",  watts=2.00),
82
                     chirp_common.PowerLevel("High", watts=5.00)]
83

    
84
RT22_DTCS = sorted(chirp_common.DTCS_CODES + [645])
85

    
86
PF2KEY_LIST = ["Scan", "Local Alarm", "Remote Alarm"]
87
TIMEOUTTIMER_LIST = ["Off"] + ["%s seconds" % x for x in range(15, 615, 15)]
88
VOICE_LIST = ["Off", "Chinese", "English"]
89
VOX_LIST = ["OFF"] + ["%s" % x for x in range(1, 17)]
90
VOXDELAY_LIST = ["0.5 | Off",
91
                 "1.0 | 0",
92
                 "1.5 | 1",
93
                 "2.0 | 2",
94
                 "2.5 | 3",
95
                 "3.0 | 4",
96
                 "--- | 5"]
97

    
98
SETTING_LISTS = {
99
    "pf2key": PF2KEY_LIST,
100
    "tot": TIMEOUTTIMER_LIST,
101
    "voice": VOICE_LIST,
102
    "vox": VOX_LIST,
103
    "voxdelay": VOXDELAY_LIST,
104
    }
105

    
106
VALID_CHARS = chirp_common.CHARSET_ALPHANUMERIC + \
107
    "`{|}!\"#$%&'()*+,-./:;<=>?@[]^_"
108

    
109

    
110
def _ident_from_data(data):
111
    return data[0x1B8:0x1C0]
112

    
113

    
114
def _ident_from_image(radio):
115
    return _ident_from_data(radio.get_mmap())
116

    
117

    
118
def _get_radio_model(radio):
119
    block = _rt22_read_block(radio, 0x360, 0x10)
120
    block = _rt22_read_block(radio, 0x1B8, 0x10)
121
    version = block[0:8]
122
    return version
123

    
124

    
125
def _rt22_enter_programming_mode(radio):
126
    serial = radio.pipe
127

    
128
    magic = "PROGRGS"
129
    exito = False
130
    for i in range(0, 5):
131
        for j in range(0, len(magic)):
132
            time.sleep(0.005)
133
            serial.write(magic[j])
134
        ack = serial.read(1)
135

    
136
        try:
137
            if ack == CMD_ACK:
138
                exito = True
139
                break
140
        except:
141
            LOG.debug("Attempt #%s, failed, trying again" % i)
142
            pass
143

    
144
    # check if we had EXITO
145
    if exito is False:
146
        msg = "The radio did not accept program mode after five tries.\n"
147
        msg += "Check you interface cable and power cycle your radio."
148
        raise errors.RadioError(msg)
149

    
150
    try:
151
        serial.write("\x02")
152
        ident = serial.read(8)
153
    except:
154
        _rt22_exit_programming_mode(radio)
155
        raise errors.RadioError("Error communicating with radio")
156

    
157
    # check if ident is OK
158
    itis = False
159
    for fp in radio._fileid:
160
        if fp in ident:
161
            # got it!
162
            itis = True
163

    
164
            break
165

    
166
    if itis is False:
167
        LOG.debug("Incorrect model ID, got this:\n\n" + util.hexprint(ident))
168
        raise errors.RadioError("Radio identification failed.")
169

    
170
    try:
171
        serial.write(CMD_ACK)
172
        ack = serial.read(1)
173
    except:
174
        _rt22_exit_programming_mode(radio)
175
        raise errors.RadioError("Error communicating with radio")
176

    
177
    if ack != CMD_ACK:
178
        _rt22_exit_programming_mode(radio)
179
        raise errors.RadioError("Radio refused to enter programming mode")
180

    
181
    try:
182
        serial.write("\x07")
183
        ack = serial.read(1)
184
    except:
185
        _rt22_exit_programming_mode(radio)
186
        raise errors.RadioError("Error communicating with radio")
187

    
188
    if ack != "\x4E":
189
        _rt22_exit_programming_mode(radio)
190
        raise errors.RadioError("Radio refused to enter programming mode")
191

    
192
    return ident
193

    
194

    
195
def _rt22_exit_programming_mode(radio):
196
    serial = radio.pipe
197
    try:
198
        serial.write("E")
199
    except:
200
        raise errors.RadioError("Radio refused to exit programming mode")
201

    
202

    
203
def _rt22_read_block(radio, block_addr, block_size):
204
    serial = radio.pipe
205

    
206
    cmd = struct.pack(">cHb", 'R', block_addr, block_size)
207
    expectedresponse = "W" + cmd[1:]
208
    LOG.debug("Reading block %04x..." % (block_addr))
209

    
210
    try:
211
        for j in range(0, len(cmd)):
212
            time.sleep(0.005)
213
            serial.write(cmd[j])
214

    
215
        response = serial.read(4 + block_size)
216
        if response[:4] != expectedresponse:
217
            _rt22_exit_programming_mode(radio)
218
            raise Exception("Error reading block %04x." % (block_addr))
219

    
220
        block_data = response[4:]
221

    
222
        time.sleep(0.005)
223
        serial.write(CMD_ACK)
224
        ack = serial.read(1)
225
    except:
226
        _rt22_exit_programming_mode(radio)
227
        raise errors.RadioError("Failed to read block at %04x" % block_addr)
228

    
229
    if ack != CMD_ACK:
230
        _rt22_exit_programming_mode(radio)
231
        raise Exception("No ACK reading block %04x." % (block_addr))
232

    
233
    return block_data
234

    
235

    
236
def _rt22_write_block(radio, block_addr, block_size, _requires_patch=False,
237
                      _radio_id=""):
238
    serial = radio.pipe
239

    
240
    cmd = struct.pack(">cHb", 'W', block_addr, block_size)
241
    if _requires_patch:
242
        mmap = radio.get_mmap()
243
        data = mmap[block_addr:block_addr + block_size]
244

    
245
        # For some radios (RT-622 & RT22FRS) memory at 0x1b8 reads as 0, but
246
        # radio ID should be written instead
247
        if block_addr == 0x1b8:
248
            for fp in _radio_id:
249
                if fp in mmap[0:len(_radio_id)]:
250
                    data = mmap[0:len(_radio_id)] + data[len(_radio_id):]
251
    else:
252
        data = radio.get_mmap()[block_addr:block_addr + block_size]
253

    
254
    LOG.debug("Writing Data:")
255
    LOG.debug(util.hexprint(cmd + data))
256

    
257
    try:
258
        for j in range(0, len(cmd)):
259
            time.sleep(0.005)
260
            serial.write(cmd[j])
261
        for j in range(0, len(data)):
262
            time.sleep(0.005)
263
            serial.write(data[j])
264
        if serial.read(1) != CMD_ACK:
265
            raise Exception("No ACK")
266
    except:
267
        _rt22_exit_programming_mode(radio)
268
        raise errors.RadioError("Failed to send block "
269
                                "to radio at %04x" % block_addr)
270

    
271

    
272
def do_download(radio):
273
    LOG.debug("download")
274
    radio_ident = _rt22_enter_programming_mode(radio)
275
    LOG.info("Radio Ident is %s" % repr(radio_ident))
276

    
277
    data = ""
278

    
279
    status = chirp_common.Status()
280
    status.msg = "Cloning from radio"
281

    
282
    status.cur = 0
283
    status.max = radio._memsize
284

    
285
    for addr in range(0, radio._memsize, radio._block_size):
286
        status.cur = addr + radio._block_size
287
        radio.status_fn(status)
288

    
289
        block = _rt22_read_block(radio, addr, radio._block_size)
290
        data += block
291

    
292
        LOG.debug("Address: %04x" % addr)
293
        LOG.debug(util.hexprint(block))
294

    
295
    data += radio.MODEL.ljust(8)
296

    
297
    _rt22_exit_programming_mode(radio)
298

    
299
    return memmap.MemoryMap(data)
300

    
301

    
302
def do_upload(radio):
303
    status = chirp_common.Status()
304
    status.msg = "Uploading to radio"
305

    
306
    radio_ident = _rt22_enter_programming_mode(radio)
307
    LOG.info("Radio Ident is %s" % repr(radio_ident))
308

    
309
    image_ident = _ident_from_image(radio)
310
    LOG.info("Image Ident is %s" % repr(image_ident))
311

    
312
    # Determine if upload requires patching
313
    if image_ident == "\x00\x00\x00\x00\x00\x00\xFF\xFF":
314
        patch_block = True
315
    else:
316
        patch_block = False
317

    
318
    status.cur = 0
319
    status.max = radio._memsize
320

    
321
    for start_addr, end_addr, block_size in radio._ranges:
322
        for addr in range(start_addr, end_addr, block_size):
323
            status.cur = addr + block_size
324
            radio.status_fn(status)
325
            _rt22_write_block(radio, addr, block_size, patch_block,
326
                              radio_ident)
327

    
328
    _rt22_exit_programming_mode(radio)
329

    
330

    
331
def model_match(cls, data):
332
    """Match the opened/downloaded image to the correct version"""
333

    
334
    if len(data) == 0x0408:
335
        rid = data[0x0400:0x0408]
336
        return rid.startswith(cls.MODEL)
337
    else:
338
        return False
339

    
340

    
341
@directory.register
342
class RT22Radio(chirp_common.CloneModeRadio):
343
    """Retevis RT22"""
344
    VENDOR = "Retevis"
345
    MODEL = "RT22"
346
    BAUD_RATE = 9600
347

    
348
    _ranges = [
349
               (0x0000, 0x0180, 0x10),
350
               (0x01B8, 0x01F8, 0x10),
351
               (0x01F8, 0x0200, 0x08),
352
               (0x0200, 0x0340, 0x10),
353
              ]
354
    _memsize = 0x0400
355
    _block_size = 0x40
356
    _fileid = ["P32073", "P3" + "\x00\x00\x00" + "3", "P3207!"]
357

    
358
    def get_features(self):
359
        rf = chirp_common.RadioFeatures()
360
        rf.has_settings = True
361
        rf.has_bank = False
362
        rf.has_ctone = True
363
        rf.has_cross = True
364
        rf.has_rx_dtcs = True
365
        rf.has_tuning_step = False
366
        rf.can_odd_split = True
367
        rf.has_name = False
368
        rf.valid_skips = ["", "S"]
369
        rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"]
370
        rf.valid_cross_modes = ["Tone->Tone", "Tone->DTCS", "DTCS->Tone",
371
                                "->Tone", "->DTCS", "DTCS->", "DTCS->DTCS"]
372
        rf.valid_power_levels = RT22_POWER_LEVELS
373
        rf.valid_duplexes = ["", "-", "+", "split", "off"]
374
        rf.valid_modes = ["NFM", "FM"]  # 12.5 KHz, 25 kHz.
375
        rf.valid_dtcs_codes = RT22_DTCS
376
        rf.memory_bounds = (1, 16)
377
        rf.valid_tuning_steps = [2.5, 5., 6.25, 10., 12.5, 25.]
378
        rf.valid_bands = [(400000000, 520000000)]
379

    
380
        return rf
381

    
382
    def process_mmap(self):
383
        self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)
384

    
385
    def sync_in(self):
386
        """Download from radio"""
387
        try:
388
            data = do_download(self)
389
        except errors.RadioError:
390
            # Pass through any real errors we raise
391
            raise
392
        except:
393
            # If anything unexpected happens, make sure we raise
394
            # a RadioError and log the problem
395
            LOG.exception('Unexpected error during download')
396
            raise errors.RadioError('Unexpected error communicating '
397
                                    'with the radio')
398
        self._mmap = data
399
        self.process_mmap()
400

    
401
    def sync_out(self):
402
        """Upload to radio"""
403
        try:
404
            do_upload(self)
405
        except:
406
            # If anything unexpected happens, make sure we raise
407
            # a RadioError and log the problem
408
            LOG.exception('Unexpected error during upload')
409
            raise errors.RadioError('Unexpected error communicating '
410
                                    'with the radio')
411

    
412
    def get_raw_memory(self, number):
413
        return repr(self._memobj.memory[number - 1])
414

    
415
    def _get_tone(self, _mem, mem):
416
        def _get_dcs(val):
417
            code = int("%03o" % (val & 0x07FF))
418
            pol = (val & 0x8000) and "R" or "N"
419
            return code, pol
420

    
421
        if _mem.tx_tone != 0xFFFF and _mem.tx_tone > 0x2800:
422
            tcode, tpol = _get_dcs(_mem.tx_tone)
423
            mem.dtcs = tcode
424
            txmode = "DTCS"
425
        elif _mem.tx_tone != 0xFFFF:
426
            mem.rtone = _mem.tx_tone / 10.0
427
            txmode = "Tone"
428
        else:
429
            txmode = ""
430

    
431
        if _mem.rx_tone != 0xFFFF and _mem.rx_tone > 0x2800:
432
            rcode, rpol = _get_dcs(_mem.rx_tone)
433
            mem.rx_dtcs = rcode
434
            rxmode = "DTCS"
435
        elif _mem.rx_tone != 0xFFFF:
436
            mem.ctone = _mem.rx_tone / 10.0
437
            rxmode = "Tone"
438
        else:
439
            rxmode = ""
440

    
441
        if txmode == "Tone" and not rxmode:
442
            mem.tmode = "Tone"
443
        elif txmode == rxmode and txmode == "Tone" and mem.rtone == mem.ctone:
444
            mem.tmode = "TSQL"
445
        elif txmode == rxmode and txmode == "DTCS" and mem.dtcs == mem.rx_dtcs:
446
            mem.tmode = "DTCS"
447
        elif rxmode or txmode:
448
            mem.tmode = "Cross"
449
            mem.cross_mode = "%s->%s" % (txmode, rxmode)
450

    
451
        if mem.tmode == "DTCS":
452
            mem.dtcs_polarity = "%s%s" % (tpol, rpol)
453

    
454
        LOG.debug("Got TX %s (%i) RX %s (%i)" %
455
                  (txmode, _mem.tx_tone, rxmode, _mem.rx_tone))
456

    
457
    def get_memory(self, number):
458
        bitpos = (1 << ((number - 1) % 8))
459
        bytepos = ((number - 1) / 8)
460
        LOG.debug("bitpos %s" % bitpos)
461
        LOG.debug("bytepos %s" % bytepos)
462

    
463
        _mem = self._memobj.memory[number - 1]
464
        _skp = self._memobj.skipflags[bytepos]
465

    
466
        mem = chirp_common.Memory()
467

    
468
        mem.number = number
469
        mem.freq = int(_mem.rxfreq) * 10
470

    
471
        # We'll consider any blank (i.e. 0MHz frequency) to be empty
472
        if mem.freq == 0:
473
            mem.empty = True
474
            return mem
475

    
476
        if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF":
477
            mem.freq = 0
478
            mem.empty = True
479
            return mem
480

    
481
        if int(_mem.rxfreq) == int(_mem.txfreq):
482
            mem.duplex = ""
483
            mem.offset = 0
484
        else:
485
            mem.duplex = int(_mem.rxfreq) > int(_mem.txfreq) and "-" or "+"
486
            mem.offset = abs(int(_mem.rxfreq) - int(_mem.txfreq)) * 10
487

    
488
        mem.mode = _mem.wide and "FM" or "NFM"
489

    
490
        self._get_tone(_mem, mem)
491

    
492
        mem.power = RT22_POWER_LEVELS[_mem.highpower]
493

    
494
        mem.skip = "" if (_skp & bitpos) else "S"
495
        LOG.debug("mem.skip %s" % mem.skip)
496

    
497
        mem.extra = RadioSettingGroup("Extra", "extra")
498

    
499
        if self.MODEL == "RT22FRS" or self.MODEL == "RT622":
500
            rs = RadioSettingValueBoolean(_mem.bcl)
501
            rset = RadioSetting("bcl", "Busy Channel Lockout", rs)
502
            mem.extra.append(rset)
503

    
504
            rs = RadioSettingValueBoolean(_mem.signal)
505
            rset = RadioSetting("signal", "Signal", rs)
506
            mem.extra.append(rset)
507

    
508
        return mem
509

    
510
    def _set_tone(self, mem, _mem):
511
        def _set_dcs(code, pol):
512
            val = int("%i" % code, 8) + 0x2800
513
            if pol == "R":
514
                val += 0x8000
515
            return val
516

    
517
        rx_mode = tx_mode = None
518
        rx_tone = tx_tone = 0xFFFF
519

    
520
        if mem.tmode == "Tone":
521
            tx_mode = "Tone"
522
            rx_mode = None
523
            tx_tone = int(mem.rtone * 10)
524
        elif mem.tmode == "TSQL":
525
            rx_mode = tx_mode = "Tone"
526
            rx_tone = tx_tone = int(mem.ctone * 10)
527
        elif mem.tmode == "DTCS":
528
            tx_mode = rx_mode = "DTCS"
529
            tx_tone = _set_dcs(mem.dtcs, mem.dtcs_polarity[0])
530
            rx_tone = _set_dcs(mem.dtcs, mem.dtcs_polarity[1])
531
        elif mem.tmode == "Cross":
532
            tx_mode, rx_mode = mem.cross_mode.split("->")
533
            if tx_mode == "DTCS":
534
                tx_tone = _set_dcs(mem.dtcs, mem.dtcs_polarity[0])
535
            elif tx_mode == "Tone":
536
                tx_tone = int(mem.rtone * 10)
537
            if rx_mode == "DTCS":
538
                rx_tone = _set_dcs(mem.rx_dtcs, mem.dtcs_polarity[1])
539
            elif rx_mode == "Tone":
540
                rx_tone = int(mem.ctone * 10)
541

    
542
        _mem.rx_tone = rx_tone
543
        _mem.tx_tone = tx_tone
544

    
545
        LOG.debug("Set TX %s (%i) RX %s (%i)" %
546
                  (tx_mode, _mem.tx_tone, rx_mode, _mem.rx_tone))
547

    
548
    def set_memory(self, mem):
549
        bitpos = (1 << ((mem.number - 1) % 8))
550
        bytepos = ((mem.number - 1) / 8)
551
        LOG.debug("bitpos %s" % bitpos)
552
        LOG.debug("bytepos %s" % bytepos)
553

    
554
        _mem = self._memobj.memory[mem.number - 1]
555
        _skp = self._memobj.skipflags[bytepos]
556

    
557
        if mem.empty:
558
            _mem.set_raw("\xFF" * (_mem.size() / 8))
559
            return
560

    
561
        _mem.rxfreq = mem.freq / 10
562

    
563
        if mem.duplex == "off":
564
            for i in range(0, 4):
565
                _mem.txfreq[i].set_raw("\xFF")
566
        elif mem.duplex == "split":
567
            _mem.txfreq = mem.offset / 10
568
        elif mem.duplex == "+":
569
            _mem.txfreq = (mem.freq + mem.offset) / 10
570
        elif mem.duplex == "-":
571
            _mem.txfreq = (mem.freq - mem.offset) / 10
572
        else:
573
            _mem.txfreq = mem.freq / 10
574

    
575
        _mem.wide = mem.mode == "FM"
576

    
577
        self._set_tone(mem, _mem)
578

    
579
        _mem.highpower = mem.power == RT22_POWER_LEVELS[1]
580

    
581
        if mem.skip != "S":
582
            _skp |= bitpos
583
        else:
584
            _skp &= ~bitpos
585
        LOG.debug("_skp %s" % _skp)
586

    
587
        for setting in mem.extra:
588
            setattr(_mem, setting.get_name(), setting.value)
589

    
590
    def get_settings(self):
591
        _settings = self._memobj.settings
592
        _message = self._memobj.embedded_msg
593
        basic = RadioSettingGroup("basic", "Basic Settings")
594
        top = RadioSettings(basic)
595

    
596
        rs = RadioSetting("squelch", "Squelch Level",
597
                          RadioSettingValueInteger(0, 9, _settings.squelch))
598
        basic.append(rs)
599

    
600
        rs = RadioSetting("tot", "Time-out timer",
601
                          RadioSettingValueList(
602
                              TIMEOUTTIMER_LIST,
603
                              TIMEOUTTIMER_LIST[_settings.tot]))
604
        basic.append(rs)
605

    
606
        rs = RadioSetting("voice", "Voice Prompts",
607
                          RadioSettingValueList(
608
                              VOICE_LIST, VOICE_LIST[_settings.voice]))
609
        basic.append(rs)
610

    
611
        rs = RadioSetting("pf2key", "PF2 Key",
612
                          RadioSettingValueList(
613
                              PF2KEY_LIST, PF2KEY_LIST[_settings.pf2key]))
614
        basic.append(rs)
615

    
616
        rs = RadioSetting("vox", "Vox",
617
                          RadioSettingValueBoolean(_settings.vox))
618
        basic.append(rs)
619

    
620
        rs = RadioSetting("voxgain", "VOX Level",
621
                          RadioSettingValueList(
622
                              VOX_LIST, VOX_LIST[_settings.voxgain]))
623
        basic.append(rs)
624

    
625
        rs = RadioSetting("voxdelay", "VOX Delay Time (Old | New)",
626
                          RadioSettingValueList(
627
                              VOXDELAY_LIST,
628
                              VOXDELAY_LIST[_settings.voxdelay]))
629
        basic.append(rs)
630

    
631
        rs = RadioSetting("save", "Battery Save",
632
                          RadioSettingValueBoolean(_settings.save))
633
        basic.append(rs)
634

    
635
        rs = RadioSetting("beep", "Beep",
636
                          RadioSettingValueBoolean(_settings.beep))
637
        basic.append(rs)
638

    
639
        def _filter(name):
640
            filtered = ""
641
            for char in str(name):
642
                if char in VALID_CHARS:
643
                    filtered += char
644
                else:
645
                    filtered += " "
646
            return filtered
647

    
648
        val = str(self._memobj.radio.id_0x200)
649
        if val == "\xFF" * 8:
650
            rs = RadioSetting("embedded_msg.line1", "Embedded Message 1",
651
                              RadioSettingValueString(0, 32, _filter(
652
                                  _message.line1)))
653
            basic.append(rs)
654

    
655
            rs = RadioSetting("embedded_msg.line2", "Embedded Message 2",
656
                              RadioSettingValueString(0, 32, _filter(
657
                                  _message.line2)))
658
            basic.append(rs)
659

    
660
        return top
661

    
662
    def set_settings(self, settings):
663
        for element in settings:
664
            if not isinstance(element, RadioSetting):
665
                self.set_settings(element)
666
                continue
667
            else:
668
                try:
669
                    if "." in element.get_name():
670
                        bits = element.get_name().split(".")
671
                        obj = self._memobj
672
                        for bit in bits[:-1]:
673
                            obj = getattr(obj, bit)
674
                        setting = bits[-1]
675
                    else:
676
                        obj = self._memobj.settings
677
                        setting = element.get_name()
678

    
679
                    LOG.debug("Setting %s = %s" % (setting, element.value))
680
                    setattr(obj, setting, element.value)
681
                except Exception, e:
682
                    LOG.debug(element.get_name())
683
                    raise
684

    
685
    @classmethod
686
    def match_model(cls, filedata, filename):
687
        match_size = False
688
        match_model = False
689

    
690
        # testing the file data size
691
        if len(filedata) in [0x0408, ]:
692
            match_size = True
693

    
694
        # testing the model fingerprint
695
        match_model = model_match(cls, filedata)
696

    
697
        if match_size and match_model:
698
            return True
699
        else:
700
            return False
701

    
702

    
703
@directory.register
704
class KDC1(RT22Radio):
705
    """WLN KD-C1"""
706
    VENDOR = "WLN"
707
    MODEL = "KD-C1"
708

    
709

    
710
@directory.register
711
class ZTX6(RT22Radio):
712
    """Zastone ZT-X6"""
713
    VENDOR = "Zastone"
714
    MODEL = "ZT-X6"
715

    
716

    
717
@directory.register
718
class LT316(RT22Radio):
719
    """Luiton LT-316"""
720
    VENDOR = "LUITON"
721
    MODEL = "LT-316"
722

    
723

    
724
@directory.register
725
class TDM8(RT22Radio):
726
    VENDOR = "TID"
727
    MODEL = "TD-M8"
728

    
729

    
730
@directory.register
731
class RT22FRS(RT22Radio):
732
    VENDOR = "Retevis"
733
    MODEL = "RT22FRS"
734

    
735

    
736
@directory.register
737
class RT622(RT22Radio):
738
    VENDOR = "Retevis"
739
    MODEL = "RT622"
(6-6/8)