[chirp_devel] [PATCH 1 of 4] [RT22] Retevis RT22 Driver Cleanup for better PEP8 Compliance
# HG changeset patch # User Jim Unroe rock.unroe@gmail.com # Date 1608175030 18000 # Wed Dec 16 22:17:10 2020 -0500 # Node ID 7f25fd339d4e4f7a4cbc9925a2e1c6ce6bf28b9d # Parent 8d906ccd00db039eee18a8af23c87ed4d2d6f127 [RT22] Retevis RT22 Driver Cleanup for better PEP8 Compliance
Clean up driver before adding another radio ID and support for additional radio models.
related to #6467
diff -r 8d906ccd00db -r 7f25fd339d4e chirp/drivers/retevis_rt22.py --- a/chirp/drivers/retevis_rt22.py Thu Nov 26 21:59:58 2020 -0500 +++ b/chirp/drivers/retevis_rt22.py Wed Dec 16 22:17:10 2020 -0500 @@ -30,32 +30,32 @@ MEM_FORMAT = """ #seekto 0x0010; struct { - lbcd rxfreq[4]; - lbcd txfreq[4]; - ul16 rx_tone; - ul16 tx_tone; - u8 unknown1; - u8 unknown3:2, - highpower:1, // Power Level - wide:1, // Bandwidth - unknown4:4; + lbcd rxfreq[4]; + lbcd txfreq[4]; + ul16 rx_tone; + ul16 tx_tone; + u8 unknown1; + u8 unknown3:2, + highpower:1, // Power Level + wide:1, // Bandwidth + unknown4:4; u8 unknown5[2]; } memory[16];
#seekto 0x012F; struct { u8 voice; // Voice Annunciation - u8 tot; // Time-out Timer + u8 tot; // Time-out Timer u8 unknown1[3]; u8 squelch; // Squelch Level - u8 save; // Battery Saver - u8 beep; // Beep + u8 save; // Battery Saver + u8 beep; // Beep u8 unknown2[2]; u8 vox; // VOX u8 voxgain; // VOX Gain - u8 voxdelay; // VOX Delay + u8 voxdelay; // VOX Delay u8 unknown3[2]; - u8 pf2key; // PF2 Key + u8 pf2key; // PF2 Key } settings;
#seekto 0x017E; @@ -617,7 +617,7 @@ # testing the file data size if len(filedata) in [0x0408, ]: match_size = True - + # testing the model fingerprint match_model = model_match(cls, filedata)
@@ -626,24 +626,28 @@ else: return False
+ @directory.register class KDC1(RT22Radio): """WLN KD-C1""" VENDOR = "WLN" MODEL = "KD-C1"
+ @directory.register class ZTX6(RT22Radio): """Zastone ZT-X6""" VENDOR = "Zastone" MODEL = "ZT-X6"
+ @directory.register class LT316(RT22Radio): """Luiton LT-316""" VENDOR = "LUITON" MODEL = "LT-316"
+ @directory.register class TDM8(RT22Radio): VENDOR = "TID" diff -r 8d906ccd00db -r 7f25fd339d4e tools/cpep8.manifest --- a/tools/cpep8.manifest Thu Nov 26 21:59:58 2020 -0500 +++ b/tools/cpep8.manifest Wed Dec 16 22:17:10 2020 -0500 @@ -70,6 +70,7 @@ ./chirp/drivers/leixen.py ./chirp/drivers/puxing.py ./chirp/drivers/radioddity_r2.py +./chirp/drivers/retevis_rt22.py ./chirp/drivers/rfinder.py ./chirp/drivers/template.py ./chirp/drivers/th350.py
# HG changeset patch # User Jim Unroe rock.unroe@gmail.com # Date 1608176614 18000 # Wed Dec 16 22:43:34 2020 -0500 # Node ID b319dbfce8f53701c67a1ed51202c16c2343698d # Parent 7f25fd339d4e4f7a4cbc9925a2e1c6ce6bf28b9d [RT22] Add Radio ID to Retevis RT22 Driver
Add additional radio ID and supporting code that is required to support currently shipping Retevis RT22 models and other similar variants.
related to #6467
diff -r 7f25fd339d4e -r b319dbfce8f5 chirp/drivers/retevis_rt22.py --- a/chirp/drivers/retevis_rt22.py Wed Dec 16 22:17:10 2020 -0500 +++ b/chirp/drivers/retevis_rt22.py Wed Dec 16 22:43:34 2020 -0500 @@ -61,6 +61,11 @@ #seekto 0x017E; u8 skipflags[2]; // SCAN_ADD
+#seekto 0x0200; +struct { + char id_0x200[8]; // Radio ID @ 0x0200 +} radio; + #seekto 0x0300; struct { char line1[32]; @@ -93,6 +98,21 @@ "`{|}!"#$%&'()*+,-./:;<=>?@[]^_"
+def _ident_from_data(data): + return data[0x1B8:0x1C0] + + +def _ident_from_image(radio): + return _ident_from_data(radio.get_mmap()) + + +def _get_radio_model(radio): + block = _rt22_read_block(radio, 0x360, 0x10) + block = _rt22_read_block(radio, 0x1B8, 0x10) + version = block[0:8] + return version + + def _rt22_enter_programming_mode(radio): serial = radio.pipe
@@ -160,6 +180,8 @@ _rt22_exit_programming_mode(radio) raise errors.RadioError("Radio refused to enter programming mode")
+ return ident +
def _rt22_exit_programming_mode(radio): serial = radio.pipe @@ -201,11 +223,23 @@ return block_data
-def _rt22_write_block(radio, block_addr, block_size): +def _rt22_write_block(radio, block_addr, block_size, _requires_patch=False, + _radio_id=""): serial = radio.pipe
cmd = struct.pack(">cHb", 'W', block_addr, block_size) - data = radio.get_mmap()[block_addr:block_addr + block_size] + if _requires_patch: + mmap = radio.get_mmap() + data = mmap[block_addr:block_addr + block_size] + + # For some radios (RT-622 & RT22FRS) memory at 0x1b8 reads as 0, but + # radio ID should be written instead + if block_addr == 0x1b8: + for fp in _radio_id: + if fp in mmap[0:len(_radio_id)]: + data = mmap[0:len(_radio_id)] + data[len(_radio_id):] + else: + data = radio.get_mmap()[block_addr:block_addr + block_size]
LOG.debug("Writing Data:") LOG.debug(util.hexprint(cmd + data)) @@ -227,7 +261,8 @@
def do_download(radio): LOG.debug("download") - _rt22_enter_programming_mode(radio) + radio_ident = _rt22_enter_programming_mode(radio) + LOG.info("Radio Ident is %s" % repr(radio_ident))
data = ""
@@ -258,7 +293,17 @@ status = chirp_common.Status() status.msg = "Uploading to radio"
- _rt22_enter_programming_mode(radio) + radio_ident = _rt22_enter_programming_mode(radio) + LOG.info("Radio Ident is %s" % repr(radio_ident)) + + image_ident = _ident_from_image(radio) + LOG.info("Image Ident is %s" % repr(image_ident)) + + # Determine if upload requires patching + if image_ident == "\x00\x00\x00\x00\x00\x00\xFF\xFF": + patch_block = True + else: + patch_block = False
status.cur = 0 status.max = radio._memsize @@ -267,7 +312,8 @@ for addr in range(start_addr, end_addr, block_size): status.cur = addr + block_size radio.status_fn(status) - _rt22_write_block(radio, addr, block_size) + _rt22_write_block(radio, addr, block_size, patch_block, + radio_ident)
_rt22_exit_programming_mode(radio)
@@ -297,7 +343,7 @@ ] _memsize = 0x0400 _block_size = 0x40 - _fileid = ["P32073", "P3" + "\x00\x00\x00" + "3"] + _fileid = ["P32073", "P3" + "\x00\x00\x00" + "3", "P3207!"]
def get_features(self): rf = chirp_common.RadioFeatures() @@ -574,15 +620,17 @@ filtered += " " return filtered
- rs = RadioSetting("embedded_msg.line1", "Embedded Message 1", - RadioSettingValueString(0, 32, _filter( - _message.line1))) - basic.append(rs) + val = str(self._memobj.radio.id_0x200) + if val == "\xFF" * 8: + rs = RadioSetting("embedded_msg.line1", "Embedded Message 1", + RadioSettingValueString(0, 32, _filter( + _message.line1))) + basic.append(rs)
- rs = RadioSetting("embedded_msg.line2", "Embedded Message 2", - RadioSettingValueString(0, 32, _filter( - _message.line2))) - basic.append(rs) + rs = RadioSetting("embedded_msg.line2", "Embedded Message 2", + RadioSettingValueString(0, 32, _filter( + _message.line2))) + basic.append(rs)
return top
# HG changeset patch # User Jim Unroe rock.unroe@gmail.com # Date 1608177235 18000 # Wed Dec 16 22:53:55 2020 -0500 # Node ID 12fa9403476f300d87cca6b92102f51d4a8349d6 # Parent b319dbfce8f53701c67a1ed51202c16c2343698d [RT22] Add Retevis RT22FRS Model
This patch adds support for the Retevis RT22 FRS version.
related to #6467
diff -r b319dbfce8f5 -r 12fa9403476f chirp/drivers/retevis_rt22.py --- a/chirp/drivers/retevis_rt22.py Wed Dec 16 22:43:34 2020 -0500 +++ b/chirp/drivers/retevis_rt22.py Wed Dec 16 22:53:55 2020 -0500 @@ -81,10 +81,16 @@ RT22_DTCS = sorted(chirp_common.DTCS_CODES + [645])
PF2KEY_LIST = ["Scan", "Local Alarm", "Remote Alarm"] -TIMEOUTTIMER_LIST = [""] + ["%s seconds" % x for x in range(15, 615, 15)] +TIMEOUTTIMER_LIST = ["Off"] + ["%s seconds" % x for x in range(15, 615, 15)] VOICE_LIST = ["Off", "Chinese", "English"] VOX_LIST = ["OFF"] + ["%s" % x for x in range(1, 17)] -VOXDELAY_LIST = ["0.5", "1.0", "1.5", "2.0", "2.5", "3.0"] +VOXDELAY_LIST = ["0.5 | Off", + "1.0 | 0", + "1.5 | 1", + "2.0 | 2", + "2.5 | 3", + "3.0 | 4", + "--- | 5"]
SETTING_LISTS = { "pf2key": PF2KEY_LIST, @@ -97,6 +103,11 @@ VALID_CHARS = chirp_common.CHARSET_ALPHANUMERIC + \ "`{|}!"#$%&'()*+,-./:;<=>?@[]^_"
+FRS_FREQS = [462.5625, 462.5875, 462.6125, 462.6375, + 462.6625, 462.6250, 462.7250, 462.6875, + 462.7125, 462.5500, 462.5750, 462.6000, + 462.6500, 462.6750, 462.7000, 462.7250] +
def _ident_from_data(data): return data[0x1B8:0x1C0] @@ -533,7 +544,14 @@ _skp = self._memobj.skipflags[bytepos]
if mem.empty: - _mem.set_raw("\xFF" * (_mem.size() / 8)) + _mem.set_raw("\xFF" * 13 + "\x00" * 3) + if self.MODEL == "RT22FRS": + FRS_FREQ = int(FRS_FREQS[mem.number - 1] * 100000) + _mem.rxfreq = _mem.txfreq = FRS_FREQ + _mem.wide = False + _mem.highpower = True + else: + _mem.set_raw("\xFF" * (_mem.size() / 8)) return
_mem.rxfreq = mem.freq / 10 @@ -597,7 +615,7 @@ VOX_LIST, VOX_LIST[_settings.voxgain])) basic.append(rs)
- rs = RadioSetting("voxdelay", "VOX Delay Time", + rs = RadioSetting("voxdelay", "VOX Delay Time (Old | New)", RadioSettingValueList( VOXDELAY_LIST, VOXDELAY_LIST[_settings.voxdelay])) @@ -700,3 +718,11 @@ class TDM8(RT22Radio): VENDOR = "TID" MODEL = "TD-M8" + + +@directory.register +class RT22FRS(RT22Radio): + VENDOR = "Retevis" + MODEL = "RT22FRS" + + _fileid = ["P3207!", ]
# HG changeset patch # User Jim Unroe rock.unroe@gmail.com # Date 1608177632 18000 # Wed Dec 16 23:00:32 2020 -0500 # Node ID 16374d1150ae44d39f45b1bb11314bb99f1ccb4b # Parent 12fa9403476f300d87cca6b92102f51d4a8349d6 [RT22] Add Retevis RT622 Model
This patch adds support for the Retevis RT622 PMR446 version.
related to #6467
diff -r 12fa9403476f -r 16374d1150ae chirp/drivers/retevis_rt22.py --- a/chirp/drivers/retevis_rt22.py Wed Dec 16 22:53:55 2020 -0500 +++ b/chirp/drivers/retevis_rt22.py Wed Dec 16 23:00:32 2020 -0500 @@ -1,4 +1,4 @@ -# Copyright 2016 Jim Unroe rock.unroe@gmail.com +# Copyright 2016-2020 Jim Unroe rock.unroe@gmail.com # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -108,6 +108,11 @@ 462.7125, 462.5500, 462.5750, 462.6000, 462.6500, 462.6750, 462.7000, 462.7250]
+PMR_FREQS = [446.00625, 446.01875, 446.03125, 446.04375, + 446.05625, 446.06875, 446.08125, 446.09375, + 446.10625, 446.11875, 446.13125, 446.14375, + 446.15625, 446.16875, 446.18125, 446.19375] +
def _ident_from_data(data): return data[0x1B8:0x1C0] @@ -550,6 +555,11 @@ _mem.rxfreq = _mem.txfreq = FRS_FREQ _mem.wide = False _mem.highpower = True + elif self.MODEL == "RT622": + PMR_FREQ = int(PMR_FREQS[mem.number - 1] * 100000) + _mem.rxfreq = _mem.txfreq = PMR_FREQ + _mem.wide = False + _mem.highpower = False else: _mem.set_raw("\xFF" * (_mem.size() / 8)) return @@ -726,3 +736,11 @@ MODEL = "RT22FRS"
_fileid = ["P3207!", ] + + +@directory.register +class RT622(RT22Radio): + VENDOR = "Retevis" + MODEL = "RT622" + + _fileid = ["P3207!", ]
participants (1)
-
Jim Unroe