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
|
_fileid = ["P32073", "P3" + "\x00\x00\x00" + "3", "P3207!",
|
357
|
"\x00\x00\x00\x00\x00\x00\xF8\xFF"]
|
358
|
|
359
|
def get_features(self):
|
360
|
rf = chirp_common.RadioFeatures()
|
361
|
rf.has_settings = False ##True
|
362
|
rf.has_bank = False
|
363
|
rf.has_ctone = True
|
364
|
rf.has_cross = True
|
365
|
rf.has_rx_dtcs = True
|
366
|
rf.has_tuning_step = False
|
367
|
rf.can_odd_split = True
|
368
|
rf.has_name = False
|
369
|
rf.valid_skips = ["", "S"]
|
370
|
rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"]
|
371
|
rf.valid_cross_modes = ["Tone->Tone", "Tone->DTCS", "DTCS->Tone",
|
372
|
"->Tone", "->DTCS", "DTCS->", "DTCS->DTCS"]
|
373
|
rf.valid_power_levels = RT22_POWER_LEVELS
|
374
|
rf.valid_duplexes = ["", "-", "+", "split", "off"]
|
375
|
rf.valid_modes = ["NFM", "FM"] # 12.5 KHz, 25 kHz.
|
376
|
rf.valid_dtcs_codes = RT22_DTCS
|
377
|
rf.memory_bounds = (1, 16)
|
378
|
rf.valid_tuning_steps = [2.5, 5., 6.25, 10., 12.5, 25.]
|
379
|
rf.valid_bands = [(400000000, 520000000)]
|
380
|
|
381
|
return rf
|
382
|
|
383
|
def process_mmap(self):
|
384
|
self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)
|
385
|
|
386
|
def sync_in(self):
|
387
|
"""Download from radio"""
|
388
|
try:
|
389
|
data = do_download(self)
|
390
|
except errors.RadioError:
|
391
|
# Pass through any real errors we raise
|
392
|
raise
|
393
|
except:
|
394
|
# If anything unexpected happens, make sure we raise
|
395
|
# a RadioError and log the problem
|
396
|
LOG.exception('Unexpected error during download')
|
397
|
raise errors.RadioError('Unexpected error communicating '
|
398
|
'with the radio')
|
399
|
self._mmap = data
|
400
|
self.process_mmap()
|
401
|
|
402
|
def sync_out(self):
|
403
|
"""Upload to radio"""
|
404
|
try:
|
405
|
do_upload(self)
|
406
|
except:
|
407
|
# If anything unexpected happens, make sure we raise
|
408
|
# a RadioError and log the problem
|
409
|
LOG.exception('Unexpected error during upload')
|
410
|
raise errors.RadioError('Unexpected error communicating '
|
411
|
'with the radio')
|
412
|
|
413
|
def get_raw_memory(self, number):
|
414
|
return repr(self._memobj.memory[number - 1])
|
415
|
|
416
|
def _get_tone(self, _mem, mem):
|
417
|
def _get_dcs(val):
|
418
|
code = int("%03o" % (val & 0x07FF))
|
419
|
pol = (val & 0x8000) and "R" or "N"
|
420
|
return code, pol
|
421
|
|
422
|
if _mem.tx_tone != 0xFFFF and _mem.tx_tone > 0x2800:
|
423
|
tcode, tpol = _get_dcs(_mem.tx_tone)
|
424
|
mem.dtcs = tcode
|
425
|
txmode = "DTCS"
|
426
|
elif _mem.tx_tone != 0xFFFF:
|
427
|
mem.rtone = _mem.tx_tone / 10.0
|
428
|
txmode = "Tone"
|
429
|
else:
|
430
|
txmode = ""
|
431
|
|
432
|
if _mem.rx_tone != 0xFFFF and _mem.rx_tone > 0x2800:
|
433
|
rcode, rpol = _get_dcs(_mem.rx_tone)
|
434
|
mem.rx_dtcs = rcode
|
435
|
rxmode = "DTCS"
|
436
|
elif _mem.rx_tone != 0xFFFF:
|
437
|
mem.ctone = _mem.rx_tone / 10.0
|
438
|
rxmode = "Tone"
|
439
|
else:
|
440
|
rxmode = ""
|
441
|
|
442
|
if txmode == "Tone" and not rxmode:
|
443
|
mem.tmode = "Tone"
|
444
|
elif txmode == rxmode and txmode == "Tone" and mem.rtone == mem.ctone:
|
445
|
mem.tmode = "TSQL"
|
446
|
elif txmode == rxmode and txmode == "DTCS" and mem.dtcs == mem.rx_dtcs:
|
447
|
mem.tmode = "DTCS"
|
448
|
elif rxmode or txmode:
|
449
|
mem.tmode = "Cross"
|
450
|
mem.cross_mode = "%s->%s" % (txmode, rxmode)
|
451
|
|
452
|
if mem.tmode == "DTCS":
|
453
|
mem.dtcs_polarity = "%s%s" % (tpol, rpol)
|
454
|
|
455
|
LOG.debug("Got TX %s (%i) RX %s (%i)" %
|
456
|
(txmode, _mem.tx_tone, rxmode, _mem.rx_tone))
|
457
|
|
458
|
def get_memory(self, number):
|
459
|
bitpos = (1 << ((number - 1) % 8))
|
460
|
bytepos = ((number - 1) / 8)
|
461
|
LOG.debug("bitpos %s" % bitpos)
|
462
|
LOG.debug("bytepos %s" % bytepos)
|
463
|
|
464
|
_mem = self._memobj.memory[number - 1]
|
465
|
_skp = self._memobj.skipflags[bytepos]
|
466
|
|
467
|
mem = chirp_common.Memory()
|
468
|
|
469
|
mem.number = number
|
470
|
mem.freq = int(_mem.rxfreq) * 10
|
471
|
|
472
|
# We'll consider any blank (i.e. 0MHz frequency) to be empty
|
473
|
if mem.freq == 0:
|
474
|
mem.empty = True
|
475
|
return mem
|
476
|
|
477
|
if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF":
|
478
|
mem.freq = 0
|
479
|
mem.empty = True
|
480
|
return mem
|
481
|
|
482
|
if int(_mem.rxfreq) == int(_mem.txfreq):
|
483
|
mem.duplex = ""
|
484
|
mem.offset = 0
|
485
|
else:
|
486
|
mem.duplex = int(_mem.rxfreq) > int(_mem.txfreq) and "-" or "+"
|
487
|
mem.offset = abs(int(_mem.rxfreq) - int(_mem.txfreq)) * 10
|
488
|
|
489
|
mem.mode = _mem.wide and "FM" or "NFM"
|
490
|
|
491
|
self._get_tone(_mem, mem)
|
492
|
|
493
|
mem.power = RT22_POWER_LEVELS[_mem.highpower]
|
494
|
|
495
|
mem.skip = "" if (_skp & bitpos) else "S"
|
496
|
LOG.debug("mem.skip %s" % mem.skip)
|
497
|
|
498
|
mem.extra = RadioSettingGroup("Extra", "extra")
|
499
|
|
500
|
if self.MODEL == "RT22FRS" or self.MODEL == "RT622":
|
501
|
rs = RadioSettingValueBoolean(_mem.bcl)
|
502
|
rset = RadioSetting("bcl", "Busy Channel Lockout", rs)
|
503
|
mem.extra.append(rset)
|
504
|
|
505
|
rs = RadioSettingValueBoolean(_mem.signal)
|
506
|
rset = RadioSetting("signal", "Signal", rs)
|
507
|
mem.extra.append(rset)
|
508
|
|
509
|
return mem
|
510
|
|
511
|
def _set_tone(self, mem, _mem):
|
512
|
def _set_dcs(code, pol):
|
513
|
val = int("%i" % code, 8) + 0x2800
|
514
|
if pol == "R":
|
515
|
val += 0x8000
|
516
|
return val
|
517
|
|
518
|
rx_mode = tx_mode = None
|
519
|
rx_tone = tx_tone = 0xFFFF
|
520
|
|
521
|
if mem.tmode == "Tone":
|
522
|
tx_mode = "Tone"
|
523
|
rx_mode = None
|
524
|
tx_tone = int(mem.rtone * 10)
|
525
|
elif mem.tmode == "TSQL":
|
526
|
rx_mode = tx_mode = "Tone"
|
527
|
rx_tone = tx_tone = int(mem.ctone * 10)
|
528
|
elif mem.tmode == "DTCS":
|
529
|
tx_mode = rx_mode = "DTCS"
|
530
|
tx_tone = _set_dcs(mem.dtcs, mem.dtcs_polarity[0])
|
531
|
rx_tone = _set_dcs(mem.dtcs, mem.dtcs_polarity[1])
|
532
|
elif mem.tmode == "Cross":
|
533
|
tx_mode, rx_mode = mem.cross_mode.split("->")
|
534
|
if tx_mode == "DTCS":
|
535
|
tx_tone = _set_dcs(mem.dtcs, mem.dtcs_polarity[0])
|
536
|
elif tx_mode == "Tone":
|
537
|
tx_tone = int(mem.rtone * 10)
|
538
|
if rx_mode == "DTCS":
|
539
|
rx_tone = _set_dcs(mem.rx_dtcs, mem.dtcs_polarity[1])
|
540
|
elif rx_mode == "Tone":
|
541
|
rx_tone = int(mem.ctone * 10)
|
542
|
|
543
|
_mem.rx_tone = rx_tone
|
544
|
_mem.tx_tone = tx_tone
|
545
|
|
546
|
LOG.debug("Set TX %s (%i) RX %s (%i)" %
|
547
|
(tx_mode, _mem.tx_tone, rx_mode, _mem.rx_tone))
|
548
|
|
549
|
def set_memory(self, mem):
|
550
|
bitpos = (1 << ((mem.number - 1) % 8))
|
551
|
bytepos = ((mem.number - 1) / 8)
|
552
|
LOG.debug("bitpos %s" % bitpos)
|
553
|
LOG.debug("bytepos %s" % bytepos)
|
554
|
|
555
|
_mem = self._memobj.memory[mem.number - 1]
|
556
|
_skp = self._memobj.skipflags[bytepos]
|
557
|
|
558
|
if mem.empty:
|
559
|
_mem.set_raw("\xFF" * (_mem.size() / 8))
|
560
|
return
|
561
|
|
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"
|