1
|
# Copyright 2011 Dan Smith <dsmith@danplanet.com>
|
2
|
# 2016 Matt Weyland <lt-betrieb@hb9uf.ch>
|
3
|
#
|
4
|
# This program is free software: you can redistribute it and/or modify
|
5
|
# it under the terms of the GNU General Public License as published by
|
6
|
# the Free Software Foundation, either version 3 of the License, or
|
7
|
# (at your option) any later version.
|
8
|
#
|
9
|
# This program is distributed in the hope that it will be useful,
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
# GNU General Public License for more details.
|
13
|
#
|
14
|
# You should have received a copy of the GNU General Public License
|
15
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
|
17
|
from chirp import chirp_common, bitwise, memmap, errors, directory, util
|
18
|
from chirp.settings import RadioSettingGroup, RadioSetting
|
19
|
from chirp.settings import RadioSettingValueBoolean, RadioSettings
|
20
|
|
21
|
from textwrap import dedent
|
22
|
|
23
|
import time
|
24
|
import logging
|
25
|
|
26
|
LOG = logging.getLogger(__name__)
|
27
|
|
28
|
|
29
|
DRX35_MEM_FORMAT = """
|
30
|
#seekto 0x0120;
|
31
|
u8 used_flags[25];
|
32
|
|
33
|
#seekto 0x0200;
|
34
|
struct {
|
35
|
u8 new_used:1,
|
36
|
unknown1:1,
|
37
|
isnarrow:1,
|
38
|
isdigital:1,
|
39
|
ishigh:1,
|
40
|
unknown2:3;
|
41
|
u8 unknown3:6,
|
42
|
duplex:2;
|
43
|
u8 unknown4:4,
|
44
|
tmode:4;
|
45
|
u8 unknown5:4,
|
46
|
step:4;
|
47
|
bbcd freq[4];
|
48
|
u8 unknown6[1];
|
49
|
bbcd offset[3];
|
50
|
u8 rtone;
|
51
|
u8 ctone;
|
52
|
u8 dtcs_tx;
|
53
|
u8 dtcs_rx;
|
54
|
u8 name[7];
|
55
|
u8 unknown8[2];
|
56
|
u8 unknown9:6,
|
57
|
power:2;
|
58
|
u8 unknownA[6];
|
59
|
} memory[100];
|
60
|
|
61
|
#seekto 0x0130;
|
62
|
u8 skips[25];
|
63
|
"""
|
64
|
|
65
|
# 0000 0111
|
66
|
# 0000 0010
|
67
|
|
68
|
# Response length is:
|
69
|
# 1. \r\n
|
70
|
# 2. Four-digit address, followed by a colon
|
71
|
# 3. 16 bytes in hex (32 characters)
|
72
|
# 4. \r\n
|
73
|
RLENGTH = 2 + 5 + 32 + 2
|
74
|
|
75
|
STEPS = [5.0, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0]
|
76
|
|
77
|
|
78
|
def isascii(data):
|
79
|
for byte in data:
|
80
|
if (ord(byte) < ord(" ") or ord(byte) > ord("~")) and \
|
81
|
byte not in "\r\n":
|
82
|
return False
|
83
|
return True
|
84
|
|
85
|
|
86
|
def tohex(data):
|
87
|
if isascii(data):
|
88
|
return repr(data)
|
89
|
string = ""
|
90
|
for byte in data:
|
91
|
string += "%02X" % ord(byte)
|
92
|
return string
|
93
|
|
94
|
|
95
|
class AlincoStyleRadio(chirp_common.CloneModeRadio):
|
96
|
"""Base class for all known Alinco radios"""
|
97
|
_memsize = 0
|
98
|
_model = "NONE"
|
99
|
|
100
|
def _send(self, data):
|
101
|
LOG.debug("PC->R: (%2i) %s" % (len(data), tohex(data)))
|
102
|
self.pipe.write(data)
|
103
|
self.pipe.read(len(data))
|
104
|
|
105
|
def _read(self, length):
|
106
|
data = self.pipe.read(length)
|
107
|
LOG.debug("R->PC: (%2i) %s" % (len(data), tohex(data)))
|
108
|
return data
|
109
|
|
110
|
def _download_chunk(self, addr):
|
111
|
if addr % 16:
|
112
|
raise Exception("Addr 0x%04x not on 16-byte boundary" % addr)
|
113
|
|
114
|
cmd = "AL~F%04XR\r\n" % addr
|
115
|
self._send(cmd)
|
116
|
|
117
|
resp = self._read(RLENGTH).strip()
|
118
|
if len(resp) == 0:
|
119
|
raise errors.RadioError("No response from radio")
|
120
|
if ":" not in resp:
|
121
|
raise errors.RadioError("Unexpected response from radio")
|
122
|
addr, _data = resp.split(":", 1)
|
123
|
data = ""
|
124
|
for i in range(0, len(_data), 2):
|
125
|
data += chr(int(_data[i:i+2], 16))
|
126
|
|
127
|
if len(data) != 16:
|
128
|
LOG.debug("Response was:")
|
129
|
LOG.debug("|%s|")
|
130
|
LOG.debug("Which I converted to:")
|
131
|
LOG.debug(util.hexprint(data))
|
132
|
raise Exception("Radio returned less than 16 bytes")
|
133
|
|
134
|
return data
|
135
|
|
136
|
def _download(self, limit):
|
137
|
self._identify()
|
138
|
|
139
|
data = ""
|
140
|
for addr in range(0, limit, 16):
|
141
|
data += self._download_chunk(addr)
|
142
|
time.sleep(0.1)
|
143
|
|
144
|
if self.status_fn:
|
145
|
status = chirp_common.Status()
|
146
|
status.cur = addr + 16
|
147
|
status.max = self._memsize
|
148
|
status.msg = "Downloading from radio"
|
149
|
self.status_fn(status)
|
150
|
|
151
|
self._send("AL~E\r\n")
|
152
|
self._read(20)
|
153
|
|
154
|
return memmap.MemoryMap(data)
|
155
|
|
156
|
def _identify(self):
|
157
|
for _i in range(0, 3):
|
158
|
self._send("%s\r\n" % self._model)
|
159
|
resp = self._read(6)
|
160
|
if resp.strip() == "OK":
|
161
|
return True
|
162
|
time.sleep(1)
|
163
|
|
164
|
return False
|
165
|
|
166
|
def _upload_chunk(self, addr):
|
167
|
if addr % 16:
|
168
|
raise Exception("Addr 0x%04x not on 16-byte boundary" % addr)
|
169
|
|
170
|
_data = self._mmap[addr:addr+16]
|
171
|
data = "".join(["%02X" % ord(x) for x in _data])
|
172
|
|
173
|
cmd = "AL~F%04XW%s\r\n" % (addr, data)
|
174
|
self._send(cmd)
|
175
|
|
176
|
def _upload(self, limit):
|
177
|
if not self._identify():
|
178
|
raise Exception("I can't talk to this model")
|
179
|
|
180
|
for addr in range(0x100, limit, 16):
|
181
|
self._upload_chunk(addr)
|
182
|
time.sleep(0.1)
|
183
|
|
184
|
if self.status_fn:
|
185
|
status = chirp_common.Status()
|
186
|
status.cur = addr + 16
|
187
|
status.max = self._memsize
|
188
|
status.msg = "Uploading to radio"
|
189
|
self.status_fn(status)
|
190
|
|
191
|
self._send("AL~E\r\n")
|
192
|
self.pipe._read(20)
|
193
|
|
194
|
def process_mmap(self):
|
195
|
self._memobj = bitwise.parse(DRX35_MEM_FORMAT, self._mmap)
|
196
|
|
197
|
def sync_in(self):
|
198
|
try:
|
199
|
self._mmap = self._download(self._memsize)
|
200
|
except errors.RadioError:
|
201
|
raise
|
202
|
except Exception, e:
|
203
|
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
204
|
self.process_mmap()
|
205
|
|
206
|
def sync_out(self):
|
207
|
try:
|
208
|
self._upload(self._memsize)
|
209
|
except errors.RadioError:
|
210
|
raise
|
211
|
except Exception, e:
|
212
|
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
213
|
|
214
|
def get_raw_memory(self, number):
|
215
|
return repr(self._memobj.memory[number])
|
216
|
|
217
|
|
218
|
DUPLEX = ["", "-", "+"]
|
219
|
TMODES = ["", "Tone", "", "TSQL"] + [""] * 12
|
220
|
TMODES[12] = "DTCS"
|
221
|
DCS_CODES = {
|
222
|
"Alinco": chirp_common.DTCS_CODES,
|
223
|
"Jetstream": [17] + chirp_common.DTCS_CODES,
|
224
|
}
|
225
|
|
226
|
CHARSET = (["\x00"] * 0x30) + \
|
227
|
[chr(x + ord("0")) for x in range(0, 10)] + \
|
228
|
[chr(x + ord("A")) for x in range(0, 26)] + [" "] + \
|
229
|
list("\x00" * 128)
|
230
|
|
231
|
|
232
|
def _get_name(_mem):
|
233
|
name = ""
|
234
|
for i in _mem.name:
|
235
|
if i in [0x00, 0xFF]:
|
236
|
break
|
237
|
name += CHARSET[i]
|
238
|
return name
|
239
|
|
240
|
|
241
|
def _set_name(mem, _mem):
|
242
|
name = [0x00] * 7
|
243
|
j = 0
|
244
|
for i in range(0, 7):
|
245
|
try:
|
246
|
name[j] = CHARSET.index(mem.name[i])
|
247
|
j += 1
|
248
|
except IndexError:
|
249
|
pass
|
250
|
except ValueError:
|
251
|
pass
|
252
|
return name
|
253
|
|
254
|
ALINCO_TONES = list(chirp_common.TONES)
|
255
|
ALINCO_TONES.remove(159.8)
|
256
|
ALINCO_TONES.remove(165.5)
|
257
|
ALINCO_TONES.remove(171.3)
|
258
|
ALINCO_TONES.remove(177.3)
|
259
|
ALINCO_TONES.remove(183.5)
|
260
|
ALINCO_TONES.remove(189.9)
|
261
|
ALINCO_TONES.remove(196.6)
|
262
|
ALINCO_TONES.remove(199.5)
|
263
|
ALINCO_TONES.remove(206.5)
|
264
|
ALINCO_TONES.remove(229.1)
|
265
|
ALINCO_TONES.remove(254.1)
|
266
|
|
267
|
|
268
|
class DRx35Radio(AlincoStyleRadio):
|
269
|
"""Base class for the DR-x35 radios"""
|
270
|
_range = [(118000000, 155000000)]
|
271
|
_power_levels = []
|
272
|
_valid_tones = ALINCO_TONES
|
273
|
|
274
|
def get_features(self):
|
275
|
rf = chirp_common.RadioFeatures()
|
276
|
rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS"]
|
277
|
rf.valid_modes = ["FM", "NFM"]
|
278
|
rf.valid_skips = ["", "S"]
|
279
|
rf.valid_bands = self._range
|
280
|
rf.memory_bounds = (0, 99)
|
281
|
rf.has_ctone = True
|
282
|
rf.has_bank = False
|
283
|
rf.has_dtcs_polarity = False
|
284
|
rf.can_delete = False
|
285
|
rf.valid_tuning_steps = STEPS
|
286
|
rf.valid_name_length = 7
|
287
|
rf.valid_power_levels = self._power_levels
|
288
|
return rf
|
289
|
|
290
|
def _get_used(self, number):
|
291
|
_usd = self._memobj.used_flags[number / 8]
|
292
|
bit = (0x80 >> (number % 8))
|
293
|
return _usd & bit
|
294
|
|
295
|
def _set_used(self, number, is_used):
|
296
|
_usd = self._memobj.used_flags[number / 8]
|
297
|
bit = (0x80 >> (number % 8))
|
298
|
if is_used:
|
299
|
_usd |= bit
|
300
|
else:
|
301
|
_usd &= ~bit
|
302
|
|
303
|
def _get_power(self, _mem):
|
304
|
if self._power_levels:
|
305
|
return self._power_levels[_mem.ishigh]
|
306
|
return None
|
307
|
|
308
|
def _set_power(self, _mem, mem):
|
309
|
if self._power_levels:
|
310
|
_mem.ishigh = mem.power is None or \
|
311
|
mem.power == self._power_levels[1]
|
312
|
|
313
|
def _get_extra(self, _mem, mem):
|
314
|
mem.extra = RadioSettingGroup("extra", "Extra")
|
315
|
dig = RadioSetting("isdigital", "Digital",
|
316
|
RadioSettingValueBoolean(bool(_mem.isdigital)))
|
317
|
dig.set_doc("Digital/Packet mode enabled")
|
318
|
mem.extra.append(dig)
|
319
|
|
320
|
def _set_extra(self, _mem, mem):
|
321
|
for setting in mem.extra:
|
322
|
setattr(_mem, setting.get_name(), setting.value)
|
323
|
|
324
|
def get_memory(self, number):
|
325
|
_mem = self._memobj.memory[number]
|
326
|
_skp = self._memobj.skips[number / 8]
|
327
|
_usd = self._memobj.used_flags[number / 8]
|
328
|
bit = (0x80 >> (number % 8))
|
329
|
|
330
|
mem = chirp_common.Memory()
|
331
|
mem.number = number
|
332
|
if not self._get_used(number) and self.MODEL != "JT220M":
|
333
|
mem.empty = True
|
334
|
return mem
|
335
|
|
336
|
mem.freq = int(_mem.freq) * 100
|
337
|
mem.rtone = self._valid_tones[_mem.rtone]
|
338
|
mem.ctone = self._valid_tones[_mem.ctone]
|
339
|
mem.duplex = DUPLEX[_mem.duplex]
|
340
|
mem.offset = int(_mem.offset) * 100
|
341
|
mem.tmode = TMODES[_mem.tmode]
|
342
|
mem.dtcs = DCS_CODES[self.VENDOR][_mem.dtcs_tx]
|
343
|
mem.tuning_step = STEPS[_mem.step]
|
344
|
|
345
|
if _mem.isnarrow:
|
346
|
mem.mode = "NFM"
|
347
|
|
348
|
mem.power = self._get_power(_mem)
|
349
|
|
350
|
if _skp & bit:
|
351
|
mem.skip = "S"
|
352
|
|
353
|
mem.name = _get_name(_mem).rstrip()
|
354
|
|
355
|
self._get_extra(_mem, mem)
|
356
|
|
357
|
return mem
|
358
|
|
359
|
def set_memory(self, mem):
|
360
|
_mem = self._memobj.memory[mem.number]
|
361
|
_skp = self._memobj.skips[mem.number / 8]
|
362
|
_usd = self._memobj.used_flags[mem.number / 8]
|
363
|
bit = (0x80 >> (mem.number % 8))
|
364
|
|
365
|
if self._get_used(mem.number) and not mem.empty:
|
366
|
# Initialize the memory
|
367
|
_mem.set_raw("\x00" * 32)
|
368
|
|
369
|
self._set_used(mem.number, not mem.empty)
|
370
|
if mem.empty:
|
371
|
return
|
372
|
|
373
|
_mem.freq = mem.freq / 100
|
374
|
|
375
|
try:
|
376
|
_tone = mem.rtone
|
377
|
_mem.rtone = self._valid_tones.index(mem.rtone)
|
378
|
_tone = mem.ctone
|
379
|
_mem.ctone = self._valid_tones.index(mem.ctone)
|
380
|
except ValueError:
|
381
|
raise errors.UnsupportedToneError("This radio does not support " +
|
382
|
"tone %.1fHz" % _tone)
|
383
|
|
384
|
_mem.duplex = DUPLEX.index(mem.duplex)
|
385
|
_mem.offset = mem.offset / 100
|
386
|
_mem.tmode = TMODES.index(mem.tmode)
|
387
|
_mem.dtcs_tx = DCS_CODES[self.VENDOR].index(mem.dtcs)
|
388
|
_mem.dtcs_rx = DCS_CODES[self.VENDOR].index(mem.dtcs)
|
389
|
_mem.step = STEPS.index(mem.tuning_step)
|
390
|
|
391
|
_mem.isnarrow = mem.mode == "NFM"
|
392
|
self._set_power(_mem, mem)
|
393
|
|
394
|
if mem.skip:
|
395
|
_skp |= bit
|
396
|
else:
|
397
|
_skp &= ~bit
|
398
|
|
399
|
_mem.name = _set_name(mem, _mem)
|
400
|
|
401
|
self._set_extra(_mem, mem)
|
402
|
|
403
|
|
404
|
@directory.register
|
405
|
class DR03Radio(DRx35Radio):
|
406
|
"""Alinco DR03"""
|
407
|
VENDOR = "Alinco"
|
408
|
MODEL = "DR03T"
|
409
|
|
410
|
_model = "DR135"
|
411
|
_memsize = 4096
|
412
|
_range = [(28000000, 29695000)]
|
413
|
|
414
|
@classmethod
|
415
|
def match_model(cls, filedata, filename):
|
416
|
return len(filedata) == cls._memsize and \
|
417
|
filedata[0x64] == chr(0x00) and filedata[0x65] == chr(0x28)
|
418
|
|
419
|
|
420
|
@directory.register
|
421
|
class DR06Radio(DRx35Radio):
|
422
|
"""Alinco DR06"""
|
423
|
VENDOR = "Alinco"
|
424
|
MODEL = "DR06T"
|
425
|
|
426
|
_model = "DR435"
|
427
|
_memsize = 4096
|
428
|
_range = [(50000000, 53995000)]
|
429
|
|
430
|
@classmethod
|
431
|
def match_model(cls, filedata, filename):
|
432
|
return len(filedata) == cls._memsize and \
|
433
|
filedata[0x64] == chr(0x00) and filedata[0x65] == chr(0x50)
|
434
|
|
435
|
|
436
|
@directory.register
|
437
|
class DR135Radio(DRx35Radio):
|
438
|
"""Alinco DR135"""
|
439
|
VENDOR = "Alinco"
|
440
|
MODEL = "DR135T"
|
441
|
|
442
|
_model = "DR135"
|
443
|
_memsize = 4096
|
444
|
_range = [(118000000, 173000000)]
|
445
|
|
446
|
@classmethod
|
447
|
def match_model(cls, filedata, filename):
|
448
|
return len(filedata) == cls._memsize and \
|
449
|
filedata[0x64] == chr(0x01) and filedata[0x65] == chr(0x44)
|
450
|
|
451
|
|
452
|
@directory.register
|
453
|
class DR235Radio(DRx35Radio):
|
454
|
"""Alinco DR235"""
|
455
|
VENDOR = "Alinco"
|
456
|
MODEL = "DR235T"
|
457
|
|
458
|
_model = "DR235"
|
459
|
_memsize = 4096
|
460
|
_range = [(216000000, 280000000)]
|
461
|
|
462
|
@classmethod
|
463
|
def match_model(cls, filedata, filename):
|
464
|
return len(filedata) == cls._memsize and \
|
465
|
filedata[0x64] == chr(0x02) and filedata[0x65] == chr(0x22)
|
466
|
|
467
|
@directory.register
|
468
|
class DR235Radio(DRx35Radio):
|
469
|
"""Alinco DR235-MODA"""
|
470
|
VENDOR = "Alinco"
|
471
|
MODEL = "DR235T-MODA"
|
472
|
|
473
|
_model = "DR235"
|
474
|
_memsize = 4096
|
475
|
_range = [(216000000, 299999000)]
|
476
|
|
477
|
@classmethod
|
478
|
def match_model(cls, filedata, filename):
|
479
|
return len(filedata) == cls._memsize and \
|
480
|
filedata[0x64] == chr(0x04) and filedata[0x65] == chr(0x00)
|
481
|
|
482
|
|
483
|
@directory.register
|
484
|
class DR435Radio(DRx35Radio):
|
485
|
"""Alinco DR235-MODB"""
|
486
|
VENDOR = "Alinco"
|
487
|
MODEL = "DR235T-MODB"
|
488
|
|
489
|
_model = "DR435"
|
490
|
_memsize = 4096
|
491
|
_range = [(200000000, 299999000)]
|
492
|
|
493
|
@classmethod
|
494
|
def match_model(cls, filedata, filename):
|
495
|
return len(filedata) == cls._memsize and \
|
496
|
filedata[0x64] == chr(0x04) and filedata[0x65] == chr(0x00)
|
497
|
|
498
|
@directory.register
|
499
|
class DR435Radio(DRx35Radio):
|
500
|
"""Alinco DR435"""
|
501
|
VENDOR = "Alinco"
|
502
|
MODEL = "DR435T"
|
503
|
|
504
|
_model = "DR435"
|
505
|
_memsize = 4096
|
506
|
_range = [(350000000, 511000000)]
|
507
|
|
508
|
@classmethod
|
509
|
def match_model(cls, filedata, filename):
|
510
|
return len(filedata) == cls._memsize and \
|
511
|
filedata[0x64] == chr(0x04) and filedata[0x65] == chr(0x00)
|
512
|
|
513
|
|
514
|
@directory.register
|
515
|
class DJ596Radio(DRx35Radio):
|
516
|
"""Alinco DJ596"""
|
517
|
VENDOR = "Alinco"
|
518
|
MODEL = "DJ596"
|
519
|
|
520
|
_model = "DJ596"
|
521
|
_memsize = 4096
|
522
|
_range = [(136000000, 174000000), (400000000, 511000000)]
|
523
|
_power_levels = [chirp_common.PowerLevel("Low", watts=1.00),
|
524
|
chirp_common.PowerLevel("High", watts=5.00)]
|
525
|
|
526
|
@classmethod
|
527
|
def match_model(cls, filedata, filename):
|
528
|
return len(filedata) == cls._memsize and \
|
529
|
filedata[0x64] == chr(0x45) and filedata[0x65] == chr(0x01)
|
530
|
|
531
|
|
532
|
@directory.register
|
533
|
class JT220MRadio(DRx35Radio):
|
534
|
"""Jetstream JT220"""
|
535
|
VENDOR = "Jetstream"
|
536
|
MODEL = "JT220M"
|
537
|
|
538
|
_model = "DR136"
|
539
|
_memsize = 8192
|
540
|
_range = [(216000000, 280000000)]
|
541
|
|
542
|
@classmethod
|
543
|
def match_model(cls, filedata, filename):
|
544
|
return len(filedata) == cls._memsize and \
|
545
|
filedata[0x60:0x64] == "2009"
|
546
|
|
547
|
|
548
|
@directory.register
|
549
|
class DJ175Radio(DRx35Radio):
|
550
|
"""Alinco DJ175"""
|
551
|
VENDOR = "Alinco"
|
552
|
MODEL = "DJ175"
|
553
|
|
554
|
_model = "DJ175"
|
555
|
_memsize = 6896
|
556
|
_range = [(136000000, 174000000), (400000000, 511000000)]
|
557
|
_power_levels = [
|
558
|
chirp_common.PowerLevel("Low", watts=0.50),
|
559
|
chirp_common.PowerLevel("Mid", watts=2.00),
|
560
|
chirp_common.PowerLevel("High", watts=5.00),
|
561
|
]
|
562
|
|
563
|
@classmethod
|
564
|
def match_model(cls, filedata, filename):
|
565
|
return len(filedata) == cls._memsize
|
566
|
|
567
|
def _get_used(self, number):
|
568
|
return self._memobj.memory[number].new_used
|
569
|
|
570
|
def _set_used(self, number, is_used):
|
571
|
self._memobj.memory[number].new_used = is_used
|
572
|
|
573
|
def _get_power(self, _mem):
|
574
|
return self._power_levels[_mem.power]
|
575
|
|
576
|
def _set_power(self, _mem, mem):
|
577
|
if mem.power in self._power_levels:
|
578
|
_mem.power = self._power_levels.index(mem.power)
|
579
|
|
580
|
def _download_chunk(self, addr):
|
581
|
if addr % 16:
|
582
|
raise Exception("Addr 0x%04x not on 16-byte boundary" % addr)
|
583
|
|
584
|
cmd = "AL~F%04XR\r\n" % addr
|
585
|
self._send(cmd)
|
586
|
|
587
|
_data = self._read(34).strip()
|
588
|
if len(_data) == 0:
|
589
|
raise errors.RadioError("No response from radio")
|
590
|
|
591
|
data = ""
|
592
|
for i in range(0, len(_data), 2):
|
593
|
data += chr(int(_data[i:i+2], 16))
|
594
|
|
595
|
if len(data) != 16:
|
596
|
LOG.debug("Response was:")
|
597
|
LOG.debug("|%s|")
|
598
|
LOG.debug("Which I converted to:")
|
599
|
LOG.debug(util.hexprint(data))
|
600
|
raise Exception("Radio returned less than 16 bytes")
|
601
|
|
602
|
return data
|
603
|
|
604
|
|
605
|
DJG7EG_MEM_FORMAT = """
|
606
|
#seekto 0x200;
|
607
|
ul16 bank[50];
|
608
|
ul16 special_bank[7];
|
609
|
#seekto 0x1200;
|
610
|
struct {
|
611
|
u8 empty;
|
612
|
ul32 freq;
|
613
|
u8 mode;
|
614
|
u8 step;
|
615
|
ul32 offset;
|
616
|
u8 duplex;
|
617
|
u8 squelch_type;
|
618
|
u8 tx_tone;
|
619
|
u8 rx_tone;
|
620
|
u8 dcs;
|
621
|
ul24 unknown1;
|
622
|
u8 skip;
|
623
|
ul32 unknown2;
|
624
|
ul32 unknown3;
|
625
|
ul32 unknown4;
|
626
|
char name[32];
|
627
|
} memory[1000];
|
628
|
"""
|
629
|
|
630
|
|
631
|
@directory.register
|
632
|
class AlincoDJG7EG(AlincoStyleRadio):
|
633
|
"""Alinco DJ-G7EG"""
|
634
|
VENDOR = "Alinco"
|
635
|
MODEL = "DJ-G7EG"
|
636
|
BAUD_RATE = 57600
|
637
|
|
638
|
# Those are different from the other Alinco radios.
|
639
|
STEPS = [5.0, 6.25, 8.33, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0, 50.0,
|
640
|
100.0, 125.0, 150.0, 200.0, 500.0, 1000.0]
|
641
|
DUPLEX = ["", "+", "-"]
|
642
|
MODES = ["NFM", "FM", "AM", "WFM"]
|
643
|
TMODES = ["", "??1", "Tone", "TSQL", "TSQL-R", "DTCS"]
|
644
|
|
645
|
# This is a bit of a hack to avoid overwriting _identify()
|
646
|
_model = "AL~DJ-G7EG"
|
647
|
_memsize = 0x1a7c0
|
648
|
_range = [(500000, 1300000000)]
|
649
|
|
650
|
@classmethod
|
651
|
def get_prompts(cls):
|
652
|
rp = chirp_common.RadioPrompts()
|
653
|
rp.pre_download = _(dedent("""\
|
654
|
1. Ensure your firmware version is 4_10 or higher
|
655
|
2. Turn radio off
|
656
|
3. Connect your interface cable
|
657
|
4. Turn radio on
|
658
|
5. Press and release PTT 3 times while holding MONI key
|
659
|
6. Supported baud rates: 57600 (default) and 19200
|
660
|
(rotate dial while holding MONI to change)
|
661
|
7. Click OK
|
662
|
"""))
|
663
|
rp.pre_upload = _(dedent("""\
|
664
|
1. Ensure your firmware version is 4_10 or higher
|
665
|
2. Turn radio off
|
666
|
3. Connect your interface cable
|
667
|
4. Turn radio on
|
668
|
5. Press and release PTT 3 times while holding MONI key
|
669
|
6. Supported baud rates: 57600 (default) and 19200
|
670
|
(rotate dial while holding MONI to change)
|
671
|
7. Click OK
|
672
|
"""))
|
673
|
return rp
|
674
|
|
675
|
def get_features(self):
|
676
|
rf = chirp_common.RadioFeatures()
|
677
|
rf.has_dtcs_polarity = False
|
678
|
rf.has_bank = False
|
679
|
rf.has_settings = False
|
680
|
|
681
|
rf.valid_modes = self.MODES
|
682
|
rf.valid_tmodes = ["", "Tone", "TSQL", "Cross", "TSQL-R", "DTCS"]
|
683
|
rf.valid_tuning_steps = self.STEPS
|
684
|
rf.valid_bands = self._range
|
685
|
rf.valid_skips = ["", "S"]
|
686
|
rf.valid_characters = chirp_common.CHARSET_ASCII
|
687
|
rf.valid_name_length = 16
|
688
|
rf.memory_bounds = (0, 999)
|
689
|
|
690
|
return rf
|
691
|
|
692
|
def _download_chunk(self, addr):
|
693
|
if addr % 0x40:
|
694
|
raise Exception("Addr 0x%04x not on 64-byte boundary" % addr)
|
695
|
|
696
|
cmd = "AL~F%05XR\r" % addr
|
697
|
self._send(cmd)
|
698
|
|
699
|
# Response: "\r\n[ ... data ... ]\r\n
|
700
|
# data is encoded in hex, hence we read two chars per byte
|
701
|
_data = self._read(2+2*64+2).strip()
|
702
|
if len(_data) == 0:
|
703
|
raise errors.RadioError("No response from radio")
|
704
|
|
705
|
data = ""
|
706
|
for i in range(0, len(_data), 2):
|
707
|
data += chr(int(_data[i:i+2], 16))
|
708
|
|
709
|
if len(data) != 64:
|
710
|
LOG.debug("Response was:")
|
711
|
LOG.debug("|%s|")
|
712
|
LOG.debug("Which I converted to:")
|
713
|
LOG.debug(util.hexprint(data))
|
714
|
raise Exception("Chunk from radio has wrong size")
|
715
|
|
716
|
return data
|
717
|
|
718
|
def _detect_baudrate_and_identify(self):
|
719
|
if self._identify():
|
720
|
return True
|
721
|
else:
|
722
|
# Apparenly Alinco support suggests to try again at a lower baud
|
723
|
# rate if their cable fails with the default rate. See #4355.
|
724
|
LOG.info("Could not talk to radio. Trying again at 19200 baud")
|
725
|
self.pipe.baudrate = 19200
|
726
|
return self._identify()
|
727
|
|
728
|
def _download(self, limit):
|
729
|
self._detect_baudrate_and_identify()
|
730
|
|
731
|
data = "\x00"*0x200
|
732
|
|
733
|
for addr in range(0x200, limit, 0x40):
|
734
|
data += self._download_chunk(addr)
|
735
|
# Other Alinco drivers delay here, but doesn't seem to be necessary
|
736
|
# for this model.
|
737
|
|
738
|
if self.status_fn:
|
739
|
status = chirp_common.Status()
|
740
|
status.cur = addr
|
741
|
status.max = limit
|
742
|
status.msg = "Downloading from radio"
|
743
|
self.status_fn(status)
|
744
|
return memmap.MemoryMap(data)
|
745
|
|
746
|
def _upload_chunk(self, addr):
|
747
|
if addr % 0x40:
|
748
|
raise Exception("Addr 0x%04x not on 64-byte boundary" % addr)
|
749
|
|
750
|
_data = self._mmap[addr:addr+0x40]
|
751
|
data = "".join(["%02X" % ord(x) for x in _data])
|
752
|
|
753
|
cmd = "AL~F%05XW%s\r" % (addr, data)
|
754
|
self._send(cmd)
|
755
|
|
756
|
resp = self._read(6)
|
757
|
if resp.strip() != "OK":
|
758
|
raise Exception("Unexpected response from radio: %s" % resp)
|
759
|
|
760
|
def _upload(self, limit):
|
761
|
if not self._detect_baudrate_and_identify():
|
762
|
raise Exception("I can't talk to this model")
|
763
|
|
764
|
for addr in range(0x200, self._memsize, 0x40):
|
765
|
self._upload_chunk(addr)
|
766
|
# Other Alinco drivers delay here, but doesn't seem to be necessary
|
767
|
# for this model.
|
768
|
|
769
|
if self.status_fn:
|
770
|
status = chirp_common.Status()
|
771
|
status.cur = addr
|
772
|
status.max = self._memsize
|
773
|
status.msg = "Uploading to radio"
|
774
|
self.status_fn(status)
|
775
|
|
776
|
def _get_empty_flag(self, freq, mode):
|
777
|
# Returns flag used to hide a channel from the main band. This occurs
|
778
|
# when the mode is anything but NFM or FM (main band can only do those)
|
779
|
# or when the frequency is outside of the range supported by the main
|
780
|
# band.
|
781
|
if mode not in ("NFM", "FM"):
|
782
|
return 0x01
|
783
|
if (freq >= 136000000 and freq < 174000000) or \
|
784
|
(freq >= 400000000 and freq < 470000000) or \
|
785
|
(freq >= 1240000000 and freq < 1300000000):
|
786
|
return 0x02
|
787
|
else:
|
788
|
return 0x01
|
789
|
|
790
|
def _check_channel_consistency(self, number):
|
791
|
_mem = self._memobj.memory[number]
|
792
|
if _mem.empty != 0x00:
|
793
|
if _mem.unknown1 == 0xffffff:
|
794
|
# Previous versions of this code have skipped the unknown
|
795
|
# fields. They contain bytes of value if the channel is empty
|
796
|
# and thus those bytes remain 0xff when the channel is put to
|
797
|
# use. The radio is totally fine with this but the Alinco
|
798
|
# programming software is not (see #5275). Here, we check for
|
799
|
# this and report if it is encountered.
|
800
|
LOG.warning("Channel %d is inconsistent: Found 0xff in "
|
801
|
"non-empty channel. Touch channel to fix."
|
802
|
% number)
|
803
|
|
804
|
if _mem.empty != self._get_empty_flag(_mem.freq,
|
805
|
self.MODES[_mem.mode]):
|
806
|
LOG.warning("Channel %d is inconsistent: Found out of band "
|
807
|
"frequency. Touch channel to fix." % number)
|
808
|
|
809
|
def process_mmap(self):
|
810
|
self._memobj = bitwise.parse(DJG7EG_MEM_FORMAT, self._mmap)
|
811
|
# We check all channels for corruption (see bug #5275) but we don't fix
|
812
|
# it automatically because it would be unpolite to modify something on
|
813
|
# a read operation. A log message is emitted though for the user to
|
814
|
# take actions.
|
815
|
for number in range(len(self._memobj.memory)):
|
816
|
self._check_channel_consistency(number)
|
817
|
|
818
|
def get_memory(self, number):
|
819
|
_mem = self._memobj.memory[number]
|
820
|
mem = chirp_common.Memory()
|
821
|
mem.number = number
|
822
|
if _mem.empty == 0:
|
823
|
mem.empty = True
|
824
|
else:
|
825
|
mem.freq = int(_mem.freq)
|
826
|
mem.mode = self.MODES[_mem.mode]
|
827
|
mem.tuning_step = self.STEPS[_mem.step]
|
828
|
mem.offset = int(_mem.offset)
|
829
|
mem.duplex = self.DUPLEX[_mem.duplex]
|
830
|
if self.TMODES[_mem.squelch_type] == "TSQL" and \
|
831
|
_mem.tx_tone != _mem.rx_tone:
|
832
|
mem.tmode = "Cross"
|
833
|
mem.cross_mode = "Tone->Tone"
|
834
|
else:
|
835
|
mem.tmode = self.TMODES[_mem.squelch_type]
|
836
|
mem.rtone = ALINCO_TONES[_mem.tx_tone-1]
|
837
|
mem.ctone = ALINCO_TONES[_mem.rx_tone-1]
|
838
|
mem.dtcs = DCS_CODES[self.VENDOR][_mem.dcs]
|
839
|
if _mem.skip:
|
840
|
mem.skip = "S"
|
841
|
# FIXME find out what every other byte is used for. Japanese?
|
842
|
mem.name = str(_mem.name.get_raw()[::2]).rstrip('\0')
|
843
|
return mem
|
844
|
|
845
|
def set_memory(self, mem):
|
846
|
# Get a low-level memory object mapped to the image
|
847
|
_mem = self._memobj.memory[mem.number]
|
848
|
if mem.empty:
|
849
|
_mem.set_raw("\xff" * (_mem.size()/8))
|
850
|
_mem.empty = 0x00
|
851
|
else:
|
852
|
_mem.empty = self._get_empty_flag(mem.freq, mem.mode)
|
853
|
_mem.freq = mem.freq
|
854
|
_mem.mode = self.MODES.index(mem.mode)
|
855
|
_mem.step = self.STEPS.index(mem.tuning_step)
|
856
|
_mem.offset = mem.offset
|
857
|
_mem.duplex = self.DUPLEX.index(mem.duplex)
|
858
|
if mem.tmode == "Cross":
|
859
|
_mem.squelch_type = self.TMODES.index("TSQL")
|
860
|
try:
|
861
|
_mem.tx_tone = ALINCO_TONES.index(mem.rtone)+1
|
862
|
except ValueError:
|
863
|
raise errors.UnsupportedToneError(
|
864
|
"This radio does not support tone %.1fHz" % mem.rtone)
|
865
|
try:
|
866
|
_mem.rx_tone = ALINCO_TONES.index(mem.ctone)+1
|
867
|
except ValueError:
|
868
|
raise errors.UnsupportedToneError(
|
869
|
"This radio does not support tone %.1fHz" % mem.ctone)
|
870
|
elif mem.tmode == "TSQL":
|
871
|
_mem.squelch_type = self.TMODES.index("TSQL")
|
872
|
# Note how the same TSQL tone is copied to both memory
|
873
|
# locaations
|
874
|
try:
|
875
|
_mem.tx_tone = ALINCO_TONES.index(mem.ctone)+1
|
876
|
_mem.rx_tone = ALINCO_TONES.index(mem.ctone)+1
|
877
|
except ValueError:
|
878
|
raise errors.UnsupportedToneError(
|
879
|
"This radio does not support tone %.1fHz" % mem.ctone)
|
880
|
else:
|
881
|
_mem.squelch_type = self.TMODES.index(mem.tmode)
|
882
|
try:
|
883
|
_mem.tx_tone = ALINCO_TONES.index(mem.rtone)+1
|
884
|
except ValueError:
|
885
|
raise errors.UnsupportedToneError(
|
886
|
"This radio does not support tone %.1fHz" % mem.rtone)
|
887
|
try:
|
888
|
_mem.rx_tone = ALINCO_TONES.index(mem.ctone)+1
|
889
|
except ValueError:
|
890
|
raise errors.UnsupportedToneError(
|
891
|
"This radio does not support tone %.1fHz" % mem.ctone)
|
892
|
_mem.dcs = DCS_CODES[self.VENDOR].index(mem.dtcs)
|
893
|
_mem.skip = (mem.skip == "S")
|
894
|
_mem.name = "\x00".join(mem.name).ljust(32, "\x00")
|
895
|
_mem.unknown1 = 0x3e001c
|
896
|
_mem.unknown2 = 0x0000000a
|
897
|
_mem.unknown3 = 0x00000000
|
898
|
_mem.unknown4 = 0x00000000
|