Project

General

Profile

Bug #10080 » retevis_rt22_incorrect_model_id.py

Jim Unroe, 10/18/2022 09:56 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[3];
52
  u8 squelch;     // Squelch Level
53
  u8 save;        // Battery Saver
54
  u8 beep;        // Beep
55
  u8 unknown2[2];
56
  u8 vox;         // VOX
57
  u8 voxgain;     // VOX Gain
58
  u8 voxdelay;    // VOX Delay
59
  u8 unknown3[2];
60
  u8 pf2key;      // PF2 Key
61
} settings;
62

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

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

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

    
78
CMD_ACK = "\x06"
79

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

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

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

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

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

    
108

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

    
112

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

    
116

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

    
123

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

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

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

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

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

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

    
163
            break
164

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

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

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

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

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

    
191
    return ident
192

    
193

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

    
201

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

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

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

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

    
219
        block_data = response[4:]
220

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

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

    
232
    return block_data
233

    
234

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

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

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

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

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

    
270

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

    
276
    data = ""
277

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

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

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

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

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

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

    
296
    _rt22_exit_programming_mode(radio)
297

    
298
    return memmap.MemoryMap(data)
299

    
300

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

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

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

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

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

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

    
327
    _rt22_exit_programming_mode(radio)
328

    
329

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

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

    
339

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

    
347
    _ranges = [
348
               (0x0000, 0x0180, 0x10),
349
               (0x01B8, 0x01F8, 0x10),
350
               (0x01F8, 0x0200, 0x08),
351
               (0x0200, 0x0340, 0x10),
352
              ]
353
    _memsize = 0x0400
354
    _block_size = 0x40
355
    _fileid = ["P32073", "P3" + "\x00\x00\x00" + "3", "P3207!",
356
               "\x00\x00\x00\x00\x00\x00\xF8\xFF"]
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"
(3-3/4)