Project

General

Profile

New Model #9633 » retevis_rt22_gt-22.py

Jim Unroe, 12/22/2021 12:23 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
    magic = "\x02" + "PROGRAM"
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
    VENDOR = "Baofeng"
347
    MODEL = "GT-22"
348
    BAUD_RATE = 9600
349

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

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

    
383
        return rf
384

    
385
    def process_mmap(self):
386
        self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)
387

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

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

    
415
    def get_raw_memory(self, number):
416
        return repr(self._memobj.memory[number - 1])
417

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

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

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

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

    
454
        if mem.tmode == "DTCS":
455
            mem.dtcs_polarity = "%s%s" % (tpol, rpol)
456

    
457
        LOG.debug("Got TX %s (%i) RX %s (%i)" %
458
                  (txmode, _mem.tx_tone, rxmode, _mem.rx_tone))
459

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

    
466
        _mem = self._memobj.memory[number - 1]
467
        _skp = self._memobj.skipflags[bytepos]
468

    
469
        mem = chirp_common.Memory()
470

    
471
        mem.number = number
472
        mem.freq = int(_mem.rxfreq) * 10
473

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

    
479
        if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF":
480
            mem.freq = 0
481
            mem.empty = True
482
            return mem
483

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

    
491
        mem.mode = _mem.wide and "FM" or "NFM"
492

    
493
        self._get_tone(_mem, mem)
494

    
495
        mem.power = RT22_POWER_LEVELS[_mem.highpower]
496

    
497
        mem.skip = "" if (_skp & bitpos) else "S"
498
        LOG.debug("mem.skip %s" % mem.skip)
499

    
500
        mem.extra = RadioSettingGroup("Extra", "extra")
501

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

    
507
            rs = RadioSettingValueBoolean(_mem.signal)
508
            rset = RadioSetting("signal", "Signal", rs)
509
            mem.extra.append(rset)
510

    
511
        return mem
512

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

    
520
        rx_mode = tx_mode = None
521
        rx_tone = tx_tone = 0xFFFF
522

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

    
545
        _mem.rx_tone = rx_tone
546
        _mem.tx_tone = tx_tone
547

    
548
        LOG.debug("Set TX %s (%i) RX %s (%i)" %
549
                  (tx_mode, _mem.tx_tone, rx_mode, _mem.rx_tone))
550

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

    
557
        _mem = self._memobj.memory[mem.number - 1]
558
        _skp = self._memobj.skipflags[bytepos]
559

    
560
        if mem.empty:
561
            _mem.set_raw("\xFF" * (_mem.size() / 8))
562
            return
563

    
564
        _mem.rxfreq = mem.freq / 10
565

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

    
578
        _mem.wide = mem.mode == "FM"
579

    
580
        self._set_tone(mem, _mem)
581

    
582
        _mem.highpower = mem.power == RT22_POWER_LEVELS[1]
583

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

    
590
        for setting in mem.extra:
591
            setattr(_mem, setting.get_name(), setting.value)
592

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

    
599
        rs = RadioSetting("squelch", "Squelch Level",
600
                          RadioSettingValueInteger(0, 9, _settings.squelch))
601
        basic.append(rs)
602

    
603
        rs = RadioSetting("tot", "Time-out timer",
604
                          RadioSettingValueList(
605
                              TIMEOUTTIMER_LIST,
606
                              TIMEOUTTIMER_LIST[_settings.tot]))
607
        basic.append(rs)
608

    
609
        rs = RadioSetting("voice", "Voice Prompts",
610
                          RadioSettingValueList(
611
                              VOICE_LIST, VOICE_LIST[_settings.voice]))
612
        basic.append(rs)
613

    
614
        rs = RadioSetting("pf2key", "PF2 Key",
615
                          RadioSettingValueList(
616
                              PF2KEY_LIST, PF2KEY_LIST[_settings.pf2key]))
617
        basic.append(rs)
618

    
619
        rs = RadioSetting("vox", "Vox",
620
                          RadioSettingValueBoolean(_settings.vox))
621
        basic.append(rs)
622

    
623
        rs = RadioSetting("voxgain", "VOX Level",
624
                          RadioSettingValueList(
625
                              VOX_LIST, VOX_LIST[_settings.voxgain]))
626
        basic.append(rs)
627

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

    
634
        rs = RadioSetting("save", "Battery Save",
635
                          RadioSettingValueBoolean(_settings.save))
636
        basic.append(rs)
637

    
638
        rs = RadioSetting("beep", "Beep",
639
                          RadioSettingValueBoolean(_settings.beep))
640
        basic.append(rs)
641

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

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

    
658
            rs = RadioSetting("embedded_msg.line2", "Embedded Message 2",
659
                              RadioSettingValueString(0, 32, _filter(
660
                                  _message.line2)))
661
            basic.append(rs)
662

    
663
        return top
664

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

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

    
688
    @classmethod
689
    def match_model(cls, filedata, filename):
690
        match_size = False
691
        match_model = False
692

    
693
        # testing the file data size
694
        if len(filedata) in [0x0408, ]:
695
            match_size = True
696

    
697
        # testing the model fingerprint
698
        match_model = model_match(cls, filedata)
699

    
700
        if match_size and match_model:
701
            return True
702
        else:
703
            return False
704

    
705

    
706
@directory.register
707
class KDC1(RT22Radio):
708
    """WLN KD-C1"""
709
    VENDOR = "WLN"
710
    MODEL = "KD-C1"
711

    
712

    
713
@directory.register
714
class ZTX6(RT22Radio):
715
    """Zastone ZT-X6"""
716
    VENDOR = "Zastone"
717
    MODEL = "ZT-X6"
718

    
719

    
720
@directory.register
721
class LT316(RT22Radio):
722
    """Luiton LT-316"""
723
    VENDOR = "LUITON"
724
    MODEL = "LT-316"
725

    
726

    
727
@directory.register
728
class TDM8(RT22Radio):
729
    VENDOR = "TID"
730
    MODEL = "TD-M8"
731

    
732

    
733
@directory.register
734
class RT22FRS(RT22Radio):
735
    VENDOR = "Retevis"
736
    MODEL = "RT22FRS"
737

    
738

    
739
@directory.register
740
class RT622(RT22Radio):
741
    VENDOR = "Retevis"
742
    MODEL = "RT622"
(5-5/12)