diff options
| author | Dave Hibberd <d@vehibberd.com> | 2024-01-23 00:30:05 +0000 |
|---|---|---|
| committer | Dave Hibberd <d@vehibberd.com> | 2024-01-23 00:30:05 +0000 |
| commit | 691b1b410562075e0d76033f5c8ddaf1da7344d0 (patch) | |
| tree | f183304481dc93719dec8c121cd1280822b2da4e | |
| parent | aed54358fee5927f9b4913566d84b92255e08e12 (diff) | |
| parent | ac8027c43c9df4431092d633a06bd5bd92341247 (diff) | |
Merge branch 'upstream' into 'upstream'
New upstream version 1:20240117
See merge request debian-hamradio-team/chirp!5
194 files changed, 6022 insertions, 1390 deletions
@@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: chirp -Version: 20231027 +Version: 20240117 Summary: A cross-platform cross-radio programming tool Home-page: https://chirp.danplanet.com Requires-Python: >=3.7,<4 diff --git a/chirp.egg-info/PKG-INFO b/chirp.egg-info/PKG-INFO index 29943d4..4c5ee89 100644 --- a/chirp.egg-info/PKG-INFO +++ b/chirp.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: chirp -Version: 20231027 +Version: 20240117 Summary: A cross-platform cross-radio programming tool Home-page: https://chirp.danplanet.com Requires-Python: >=3.7,<4 diff --git a/chirp.egg-info/SOURCES.txt b/chirp.egg-info/SOURCES.txt index e476990..9e4ab7d 100644 --- a/chirp.egg-info/SOURCES.txt +++ b/chirp.egg-info/SOURCES.txt @@ -41,6 +41,8 @@ chirp/drivers/anytone_ht.py chirp/drivers/anytone_iii.py chirp/drivers/ap510.py chirp/drivers/baofeng_common.py +chirp/drivers/baofeng_uv17.py +chirp/drivers/baofeng_uv17Pro.py chirp/drivers/baofeng_uv3r.py chirp/drivers/baofeng_wp970i.py chirp/drivers/bf_t1.py @@ -134,6 +136,7 @@ chirp/drivers/mursv1.py chirp/drivers/puxing.py chirp/drivers/puxing_px888k.py chirp/drivers/radioddity_r2.py +chirp/drivers/radtel_rt490.py chirp/drivers/radtel_t18.py chirp/drivers/retevis_rb15.py chirp/drivers/retevis_rb17p.py @@ -202,6 +205,7 @@ chirp/locale/es/LC_MESSAGES/CHIRP.mo chirp/locale/fr/LC_MESSAGES/CHIRP.mo chirp/locale/hu/LC_MESSAGES/CHIRP.mo chirp/locale/it/LC_MESSAGES/CHIRP.mo +chirp/locale/ja_JP/LC_MESSAGES/CHIRP.mo chirp/locale/nl/LC_MESSAGES/CHIRP.mo chirp/locale/pl/LC_MESSAGES/CHIRP.mo chirp/locale/pt_BR/LC_MESSAGES/CHIRP.mo @@ -257,6 +261,7 @@ chirp/wxui/settingsedit.py tests/Python3_Driver_Testing.md tests/__init__.py tests/base.py +tests/conftest.py tests/icom_clone_simulator.py tests/model_stats.tsv tests/py3_driver_testers.txt @@ -269,8 +274,10 @@ tests/test_drivers.py tests/test_edges.py tests/test_features.py tests/test_settings.py +tests/xfails.txt tests/__pycache__/__init__.cpython-310.pyc tests/__pycache__/base.cpython-310.pyc +tests/__pycache__/conftest.cpython-310-pytest-7.1.3.pyc tests/__pycache__/icom_clone_simulator.cpython-310.pyc tests/__pycache__/test_banks.cpython-310-pytest-7.1.3.pyc tests/__pycache__/test_brute_force.cpython-310-pytest-7.1.3.pyc @@ -315,12 +322,19 @@ tests/images/BTECH_UV-50X2.img tests/images/BTECH_UV-50X2_G2.img tests/images/BTECH_UV-50X3.img tests/images/BTECH_UV-5X3.img +tests/images/Baofeng_5RM.img +tests/images/Baofeng_5RX.img tests/images/Baofeng_BF-1904.img tests/images/Baofeng_BF-888.img tests/images/Baofeng_BF-A58S.img tests/images/Baofeng_BF-T1.img +tests/images/Baofeng_BF-T20.img +tests/images/Baofeng_BF-T20FRS.img tests/images/Baofeng_BF-T8.img tests/images/Baofeng_F-11.img +tests/images/Baofeng_UV-17.img +tests/images/Baofeng_UV-17Pro.img +tests/images/Baofeng_UV-17ProGPS.img tests/images/Baofeng_UV-3R.img tests/images/Baofeng_UV-5R.img tests/images/Baofeng_UV-6R.img @@ -389,6 +403,7 @@ tests/images/LUITON_LT-725UV.img tests/images/Lanchonlh_HG-UV98.img tests/images/Leixen_VV-898.img tests/images/Leixen_VV-898S.img +tests/images/MMLradio_JC-8629.img tests/images/Midland_DBR2500.img tests/images/Polmar_DB-50M.img tests/images/Puxing_PX-2R.img @@ -409,10 +424,13 @@ tests/images/Radioddity_UV-5G.img tests/images/Radtel_RT-470.img tests/images/Radtel_RT-470L.img tests/images/Radtel_RT-470X.img +tests/images/Radtel_RT-490.img tests/images/Radtel_T18.img tests/images/Retevis_H777S.img tests/images/Retevis_RA685.img +tests/images/Retevis_RA79.img tests/images/Retevis_RA85.img +tests/images/Retevis_RA89.img tests/images/Retevis_RB15.img tests/images/Retevis_RB17.img tests/images/Retevis_RB17A.img @@ -475,6 +493,7 @@ tests/images/Rugged_RH5R-V2.img tests/images/Ruyage_UV58Plus.img tests/images/SenhaiX_8800.img tests/images/TDXone_TD-Q8A.img +tests/images/TIDRADIO_TD-H3.img tests/images/TIDRADIO_TD-H8-GMRS.img tests/images/TIDRADIO_TD-H8-HAM.img tests/images/TIDRADIO_TD-H8.img @@ -517,6 +536,7 @@ tests/images/Yaesu_FT-1D_R.img tests/images/Yaesu_FT-25R.img tests/images/Yaesu_FT-2800M.img tests/images/Yaesu_FT-2900R_1900R.img +tests/images/Yaesu_FT-450.img tests/images/Yaesu_FT-450D.img tests/images/Yaesu_FT-4VR.img tests/images/Yaesu_FT-4XE.img diff --git a/chirp/__init__.py b/chirp/__init__.py index 47569c8..b1c982e 100644 --- a/chirp/__init__.py +++ b/chirp/__init__.py @@ -1 +1 @@ -CHIRP_VERSION = "next-20231027" +CHIRP_VERSION = "next-20240117" diff --git a/chirp/bitwise.py b/chirp/bitwise.py index f004449..98720a1 100644 --- a/chirp/bitwise.py +++ b/chirp/bitwise.py @@ -60,6 +60,7 @@ import struct import os import logging +import warnings import six from builtins import bytes @@ -197,6 +198,14 @@ class DataElement: self._offset = int(offset) self._count = count + def _compat_bytes(self, bs, asbytes): + if asbytes: + return bytes(bs) + else: + warnings.warn('Driver is using non-byte-native get_raw()', + DeprecationWarning, stacklevel=3) + return string_straight_decode(bs) + def size(self): return int(self._size * 8) @@ -213,15 +222,14 @@ class DataElement: def set_value(self, value): raise Exception("Not implemented for %s" % self.__class__) - def get_raw(self, asbytes=False): + def get_raw(self, asbytes=True): raw = self._data[self._offset:self._offset+self._size] - if asbytes: - return bytes(raw) - else: - return string_straight_decode(raw) + return self._compat_bytes(raw, asbytes) def set_raw(self, data): if isinstance(data, str): + warnings.warn('Driver is using non-byte-native set_raw()', + DeprecationWarning, stacklevel=2) data = string_straight_encode(data) self._data[self._offset] = data[:self._size] @@ -258,12 +266,9 @@ class arrayDataElement(DataElement): def get_value(self): return list(self.__items) - def get_raw(self, asbytes=False): - raw = [item.get_raw(asbytes=asbytes) for item in self.__items] - if asbytes: - return bytes(b''.join(raw)) - else: - return "".join(raw) + def get_raw(self, asbytes=True): + raw = [item.get_raw(asbytes=True) for item in self.__items] + return self._compat_bytes(bytes(b''.join(raw)), asbytes) def __setitem__(self, index, val): self.__items[index].set_value(val) @@ -665,6 +670,8 @@ class bcdDataElement(DataElement): if isinstance(data, int): self._data[self._offset] = data & 0xFF elif isinstance(data, str): + warnings.warn('Driver is using non-byte-native set_raw()', + DeprecationWarning, stacklevel=2) self._data[self._offset] = string_straight_encode(data[0]) elif isinstance(data, bytes) and len(data) == 1: self._data[self._offset] = int(data[0]) & 0xFF @@ -725,7 +732,7 @@ class structDataElement(DataElement): s += " %15s: %s%s" % (prop, repr(self._generators[prop]), os.linesep) s += "} %s (%i bytes at 0x%04X)%s" % (self._name, - self.size() / 8, + self.size() // 8, self._offset, os.linesep) return s @@ -792,18 +799,17 @@ class structDataElement(DataElement): size += el.size() return int(size) - def get_raw(self, asbytes=False): + def get_raw(self, asbytes=True): size = self.size() // 8 raw = self._data[self._offset:self._offset+size] - if asbytes: - return bytes(raw) - else: - return string_straight_decode(raw) + return self._compat_bytes(raw, asbytes) def set_raw(self, buffer): if len(buffer) != (self.size() // 8): raise ValueError("Struct size mismatch during set_raw()") if isinstance(buffer, str): + warnings.warn('Driver is using non-byte-native set_raw()', + DeprecationWarning, stacklevel=2) buffer = string_straight_encode(buffer) self._data[self._offset] = buffer @@ -817,7 +823,6 @@ class structDataElement(DataElement): class Processor: - _types = { "u8": u8DataElement, "u16": u16DataElement, @@ -852,7 +857,7 @@ class Processor: self._generators[name] = gen def do_bitfield(self, dtype, bitfield): - bytes = self._types[dtype](self._data, 0).size() / 8 + bytes = self._types[dtype](self._data, 0).size() // 8 bitsleft = bytes * 8 for _bitdef, defn in bitfield: @@ -909,7 +914,7 @@ class Processor: self._offset += int((i+1) % 8 == 0) else: gen = self._types[dtype](self._data, self._offset) - self._offset += (gen.size() / 8) + self._offset += (gen.size() // 8) res.append(gen) if count == 1: @@ -958,11 +963,24 @@ class Processor: else: raise Exception("Internal error: What is `%s'?" % struct[0][0]) + def assert_negative_seek(self, message): + warnings.warn(message, DeprecationWarning, stacklevel=6) + + def assert_unnecessary_seek(self, message): + warnings.warn(message, DeprecationWarning, stacklevel=6) + def parse_directive(self, directive): name = directive[0][0] value = directive[0][1][0][1] if name == "seekto": - self._offset = int(value, 0) + target = int(value, 0) + if self._offset == target: + self.assert_unnecessary_seek('Unnecessary #seekto %s' % value) + elif target < self._offset: + self.assert_negative_seek( + 'Invalid negative seek from 0x%04x to 0x%04x' % ( + self._offset, target)) + self._offset = target elif name == "seek": self._offset += int(value, 0) elif name == "printoffset": @@ -992,10 +1010,11 @@ def parse(spec, data, offset=0): if __name__ == "__main__": defn = """ +// comment struct mytype { u8 foo; }; struct mytype bar; struct { - u8 foo; + u8 foo; // inline u8 highbit:1, sixzeros:6, lowbit:1; @@ -1003,7 +1022,7 @@ struct { bbcd fourdigits[2]; } mystruct; """ - data = "\xab\x7F\x81abc\x12\x34" + data = b"\xab\x7F\x81abc\x12\x34" tree = parse(defn, data) print(repr(tree)) diff --git a/chirp/bitwise_grammar.py b/chirp/bitwise_grammar.py index c61eda2..fd49b24 100644 --- a/chirp/bitwise_grammar.py +++ b/chirp/bitwise_grammar.py @@ -35,7 +35,7 @@ def count(): def bitdef(): - return symbol, ":", count, -1 + return symbol, ":", count def _bitdeflist(): @@ -43,7 +43,7 @@ def _bitdeflist(): def bitfield(): - return -2, _bitdeflist + return _bitdeflist def array(): diff --git a/chirp/chirp_common.py b/chirp/chirp_common.py index 12bd1b7..e737401 100644 --- a/chirp/chirp_common.py +++ b/chirp/chirp_common.py @@ -356,7 +356,37 @@ class Memory: } def __repr__(self): - return str(self) + ident, vals = self.debug_dump() + return '<Memory %s: %s>' % ( + ident, ','.join('%s=%r' % item for item in vals)) + + def debug_diff(self, other, delim='/'): + my_ident, my_vals = self.debug_dump() + my_vals = dict(my_vals) + + om_ident, om_vals = other.debug_dump() + om_vals = dict(om_vals) + + diffs = [] + if my_ident != om_ident: + diffs.append('ident=%s%s%s' % (my_ident, delim, om_ident)) + for k in sorted(my_vals.keys() | om_vals.keys()): + myval = my_vals.get(k, '<missing>') + omval = om_vals.get(k, '<missing>') + if myval != omval: + diffs.append('%s=%r%s%r' % (k, myval, delim, omval)) + return ','.join(diffs) + + def debug_dump(self): + vals = [(k, v) for k, v in self.__dict__.items() + if k not in ('extra', 'number', 'extd_number')] + for extra in self.extra: + vals.append(('extra.%s' % extra.get_name(), str(extra.value))) + if self.extd_number: + ident = '%s(%i)' % (self.extd_number, self.number) + else: + ident = str(self.number) + return ident, vals def dupe(self): """Return a deep copy of @self""" @@ -628,6 +658,8 @@ def FrozenMemory(source): setattr(self, k, v) self.__dict__['_frozen'] = True + for i in self.extra: + i.set_frozen() def __setattr__(self, k, v): if self._frozen: diff --git a/chirp/drivers/__init__.py b/chirp/drivers/__init__.py index 846e04e..fcb714e 100644 --- a/chirp/drivers/__init__.py +++ b/chirp/drivers/__init__.py @@ -154,10 +154,13 @@ from chirp.drivers import vx8 from chirp.drivers import vxa700 from chirp.drivers import wouxun from chirp.drivers import wouxun_common -from chirp.drivers import yaesu_clone -from chirp.drivers import iradio_uv_5118plus from chirp.drivers import kenwood_d7 +from chirp.drivers import yaesu_clone +from chirp.drivers import radtel_rt490 +from chirp.drivers import tdh8 +from chirp.drivers import baofeng_uv17 +from chirp.drivers import baofeng_uv17Pro from chirp.drivers import mml_jc8810 from chirp.drivers import uvk5 -from chirp.drivers import tdh8 -__all__ = ['__init__', 'bj9900', 'anytone', 'anytone778uv', 'anytone_ht', 'anytone_iii', 'ap510', 'baofeng_common', 'baofeng_uv3r', 'baofeng_wp970i', 'bjuv55', 'boblov_x3plus', 'btech', 'fake', 'fd268', 'ft1500m', 'ft1802', 'ft1d', 'ft2900', 'ft2d', 'ft4', 'ft2800', 'ft450d', 'ft50', 'ft60', 'ft70', 'ft7100', 'ft7800', 'ft8100', 'ft817', 'ft818', 'ft857', 'ft90', 'ftlx011', 'ftm3200d', 'ftm350', 'ftm7250d', 'ga510', 'generic_csv', 'generic_tpe', 'gmrsuv1', 'gmrsv2', 'h777', 'hf90', 'bf_t1', 'ic208', 'hg_uv98', 'hobbypcb', 'ic2300', 'ic2100', 'ic2200', 'ic2720', 'ic2730', 'ic9x_icf', 'ic2820', 'ic9x', 'ic9x_ll', 'ic9x_icf_ll', 'icf', 'icomciv', 'icp7', 'ict8', 'icq7', 'ict70', 'ict7h', 'icv80', 'id31', 'icv86', 'icw32', 'icx8x', 'icx90', 'id5100', 'id51', 'id51plus', 'id880', 'id800', 'idrp', 'kg935g', 'iradio_uv_5118', 'kenwood_hmk', 'kenwood_itm', 'kenwood_live', 'kguv8d', 'kguv980p', 'kguv8dplus', 'kguv8e', 'kguv920pa', 'kguv9dplus', 'leixen', 'kyd', 'kyd_IP620', 'lt725uv', 'mursv1', 'alinco', 'puxing', 'puxing_px888k', 'radioddity_r2', 'radtel_t18', 'retevis_rb15', 'retevis_rb17p', 'retevis_rb28', 'retevis_rt1', 'retevis_rt21', 'retevis_rt22', 'retevis_rt23', 'retevis_rt26', 'retevis_rt76p', 'retevis_rt87', 'retevis_rt98', 'bf_t8', 'rh5r_v2', 'tdxone_tdq8a', 'template', 'tg_uv2p', 'th350', 'th7800', 'th9000', 'th9800', 'th_uv3r', 'th_uv3r25', 'th_uv8000', 'th_uv88', 'th_uvf8d', 'thd72', 'thd74', 'thuv1f', 'tk270', 'tk3140', 'tk760', 'tk760g', 'tk8102', 'tk8160', 'tk8180', 'tmd710', 'tmv71', 'tmv71_ll', 'ts2000', 'ts480', 'ts590', 'ts850', 'uv5r', 'uv5x3', 'uv6r', 'uvb5', 'vgc', 'vx170', 'vx2', 'vx3', 'vx5', 'vx510', 'vx6', 'vx7', 'vx8', 'vxa700', 'wouxun', 'wouxun_common', 'yaesu_clone', 'iradio_uv_5118plus', 'kenwood_d7', 'mml_jc8810', 'uvk5', 'tdh8'] +from chirp.drivers import iradio_uv_5118plus +__all__ = ['__init__', 'bj9900', 'anytone', 'anytone778uv', 'anytone_ht', 'anytone_iii', 'ap510', 'baofeng_common', 'baofeng_uv3r', 'baofeng_wp970i', 'bjuv55', 'boblov_x3plus', 'btech', 'fake', 'fd268', 'ft1500m', 'ft1802', 'ft1d', 'ft2900', 'ft2d', 'ft4', 'ft2800', 'ft450d', 'ft50', 'ft60', 'ft70', 'ft7100', 'ft7800', 'ft8100', 'ft817', 'ft818', 'ft857', 'ft90', 'ftlx011', 'ftm3200d', 'ftm350', 'ftm7250d', 'ga510', 'generic_csv', 'generic_tpe', 'gmrsuv1', 'gmrsv2', 'h777', 'hf90', 'bf_t1', 'ic208', 'hg_uv98', 'hobbypcb', 'ic2300', 'ic2100', 'ic2200', 'ic2720', 'ic2730', 'ic9x_icf', 'ic2820', 'ic9x', 'ic9x_ll', 'ic9x_icf_ll', 'icf', 'icomciv', 'icp7', 'ict8', 'icq7', 'ict70', 'ict7h', 'icv80', 'id31', 'icv86', 'icw32', 'icx8x', 'icx90', 'id5100', 'id51', 'id51plus', 'id880', 'id800', 'idrp', 'kg935g', 'iradio_uv_5118', 'kenwood_hmk', 'kenwood_itm', 'kenwood_live', 'kguv8d', 'kguv980p', 'kguv8dplus', 'kguv8e', 'kguv920pa', 'kguv9dplus', 'leixen', 'kyd', 'kyd_IP620', 'lt725uv', 'mursv1', 'alinco', 'puxing', 'puxing_px888k', 'radioddity_r2', 'radtel_t18', 'retevis_rb15', 'retevis_rb17p', 'retevis_rb28', 'retevis_rt1', 'retevis_rt21', 'retevis_rt22', 'retevis_rt23', 'retevis_rt26', 'retevis_rt76p', 'retevis_rt87', 'retevis_rt98', 'bf_t8', 'rh5r_v2', 'tdxone_tdq8a', 'template', 'tg_uv2p', 'th350', 'th7800', 'th9000', 'th9800', 'th_uv3r', 'th_uv3r25', 'th_uv8000', 'th_uv88', 'th_uvf8d', 'thd72', 'thd74', 'thuv1f', 'tk270', 'tk3140', 'tk760', 'tk760g', 'tk8102', 'tk8160', 'tk8180', 'tmd710', 'tmv71', 'tmv71_ll', 'ts2000', 'ts480', 'ts590', 'ts850', 'uv5r', 'uv5x3', 'uv6r', 'uvb5', 'vgc', 'vx170', 'vx2', 'vx3', 'vx5', 'vx510', 'vx6', 'vx7', 'vx8', 'vxa700', 'wouxun', 'wouxun_common', 'kenwood_d7', 'yaesu_clone', 'radtel_rt490', 'tdh8', 'baofeng_uv17', 'baofeng_uv17Pro', 'mml_jc8810', 'uvk5', 'iradio_uv_5118plus'] diff --git a/chirp/drivers/alinco.py b/chirp/drivers/alinco.py index 5313b7d..b5a839b 100644 --- a/chirp/drivers/alinco.py +++ b/chirp/drivers/alinco.py @@ -787,7 +787,7 @@ class AlincoDJG7(AlincoStyleRadio): if _mem.skip: mem.skip = "S" # FIXME find out what every other byte is used for. Japanese? - mem.name = str(_mem.name.get_raw()[::2]).rstrip('\0') + mem.name = str(_mem.name.get_raw(asbytes=False)[::2]).rstrip('\0') return mem def set_memory(self, mem): diff --git a/chirp/drivers/anytone.py b/chirp/drivers/anytone.py index e99b5d7..d8e7027 100644 --- a/chirp/drivers/anytone.py +++ b/chirp/drivers/anytone.py @@ -192,7 +192,7 @@ class FlagObj(object): def _is_loc_used(memobj, loc): - return memobj.flags[loc / 2].get_raw() != "\xFF" + return memobj.flags[loc / 2].get_raw(asbytes=False) != "\xFF" def _addr_to_loc(addr): diff --git a/chirp/drivers/anytone_ht.py b/chirp/drivers/anytone_ht.py index 69fdda4..754157e 100644 --- a/chirp/drivers/anytone_ht.py +++ b/chirp/drivers/anytone_ht.py @@ -557,7 +557,7 @@ class AnyToneTERMN8RRadio(chirp_common.CloneModeRadio, return _usd &= ~bitpos - if _mem.get_raw() == ("\xFF" * 32): + if _mem.get_raw(asbytes=False) == ("\xFF" * 32): LOG.debug("Initializing empty memory") _mem.set_raw("\x00" * 32) _mem.squelch = 3 diff --git a/chirp/drivers/anytone_iii.py b/chirp/drivers/anytone_iii.py index 48a74a1..8b4f4be 100644 --- a/chirp/drivers/anytone_iii.py +++ b/chirp/drivers/anytone_iii.py @@ -154,7 +154,7 @@ struct memory { pttid:2, // [Off, Begin, End, Begin&End] unknown6:2, bclo:2; // [Off, Repeater, Busy] - u8 unknown7:6 + u8 unknown7:6, band:2; // [2m, 1-1/4m, 350+ MHz, 70cm] u8 unknown8:5, sql_mode:3; // [Carrier, CTCSS/DCS Tones, Opt Sig Only, @@ -238,7 +238,7 @@ struct { clk_shift:1, // CLK Shift: 0=off 1=on ext_spk_on:1, // Enable the external speaker alt_key_mode:1, // Use Alt Keypad Mode: 0=off 1=on - beep_on:1 // Enable beep + beep_on:1, // Enable beep no_tone_elim_tail:1, // Elim squelch tail when no CTCSS/DCS signaling sql_key_mode:1; // SQL Key Function: [Momentary, Toggle] u8 unknown16:5, diff --git a/chirp/drivers/baofeng_common.py b/chirp/drivers/baofeng_common.py index 072d4e6..ec4f811 100644 --- a/chirp/drivers/baofeng_common.py +++ b/chirp/drivers/baofeng_common.py @@ -95,37 +95,92 @@ def _recv(radio, addr, length): return data +def _read_from_data(data, data_start, data_stop): + data = data[data_start:data_stop] + return data + + +def _get_data_from_image(radio, _data_start, _data_stop): + image_data = _read_from_data( + radio.get_mmap().get_byte_compatible(), + _data_start, + _data_stop) + return image_data + + +def _read_block(radio, start, size, first_command=False): + msg = struct.pack(">BHB", ord("S"), start, size) + radio.pipe.write(msg) + + if radio._ack_block and first_command is False: + ack = radio.pipe.read(1) + if ack != b"\x06": + raise errors.RadioError( + "Radio refused to send second block 0x%04x" % start) + + answer = radio.pipe.read(4) + if len(answer) != 4: + raise errors.RadioError("Radio refused to send block 0x%04x" % start) + + cmd, addr, length = struct.unpack(">BHB", answer) + if cmd != ord("X") or addr != start or length != size: + LOG.error("Invalid answer for block 0x%04x:" % start) + LOG.debug("CMD: %s ADDR: %04x SIZE: %02x" % (cmd, addr, length)) + raise errors.RadioError("Unknown response from radio") + + chunk = radio.pipe.read(size) + if not chunk: + raise errors.RadioError("Radio did not send block 0x%04x" % start) + elif len(chunk) != size: + LOG.error("Chunk length was 0x%04i" % len(chunk)) + raise errors.RadioError("Radio sent incomplete block 0x%04x" % start) + + radio.pipe.write(b"\x06") + time.sleep(0.05) + + return chunk + + +def _get_aux_data_from_radio(radio): + block0 = _read_block(radio, 0x1E80, 0x40, True) + block1 = _read_block(radio, 0x1EC0, 0x40, False) + block2 = _read_block(radio, 0x1F00, 0x40, False) + block3 = _read_block(radio, 0x1F40, 0x40, False) + block4 = _read_block(radio, 0x1F80, 0x40, False) + block5 = _read_block(radio, 0x1FC0, 0x40, False) + version = block1[48:62] + area1 = block2 + block3[0:32] + area2 = block3[48:64] + area3 = block4[16:64] + # check for dropped byte + dropped_byte = block5[15:16] == b"\xFF" # True/False + return version, area1, area2, area3, dropped_byte + + def _get_radio_firmware_version(radio): - # There is a problem in new radios where a different firmware version is - # received when directly reading a single block as compared to what is - # received when reading sequential blocks. This causes a mismatch between - # the image firmware version and the radio firmware version when uploading - # an image that came from the same radio. The workaround is to read 1 or - # more consecutive blocks prior to reading the block with the firmware - # version. - # - # Read 2 consecutive blocks to get the radio firmware version. - for addr in range(0x1E80, 0x1F00, radio._recv_block_size): - frame = _make_frame("S", addr, radio._recv_block_size) - - # sending the read request - _rawsend(radio, frame) - - if radio._ack_block and addr != 0x1E80: - ack = _rawrecv(radio, 1) - if ack != b"\x06": - raise errors.RadioError( - "Radio refused to send block 0x%04x" % addr) + # New radios will reply with 'alternative' (aka: bad) data if the Aux + # memory area is read without first reading a block from another area + # of memory. Reading any block that is outside of the Aux memory area + # (which starts at 0x1EC0) prior to reading blocks in the Aux mem area + # turns out to be a workaround for this problem. + + # read and disregard block0 + block0 = _read_block(radio, 0x1E80, 0x40, True) + block1 = _read_block(radio, 0x1EC0, 0x40, False) + block2 = _read_block(radio, 0x1FC0, 0x40, False) - # now we read - block = _recv(radio, addr, radio._recv_block_size) + # get firmware version + version = block1[48:62] # firmware version - _rawsend(radio, b"\x06") - time.sleep(0.05) + # Some new radios will drop the byte at 0x1FCF when read in 0x40 byte + # blocks. This results in the next 0x30 bytes being moved forward one + # position (putting 0xFF in position 0x1FCF and pads the now missing byte + # at the end, 0x1FFF, with 0x80). - # get firmware version from the last block read - version = block[48:64] - return version + # detect dropped byte + dropped_byte = (block2[15:16] == b"\xFF") # dropped byte? + + return version, dropped_byte def _image_ident_from_data(data, start, stop): @@ -134,7 +189,7 @@ def _image_ident_from_data(data, start, stop): def _get_image_firmware_version(radio): return _image_ident_from_data(radio.get_mmap(), radio._fw_ver_start, - radio._fw_ver_start + 0x10) + radio._fw_ver_start + 0x0E) def _do_ident(radio, magic): @@ -204,9 +259,10 @@ def _download(radio): ident = _ident_radio(radio) # identify radio - radio_ident = _get_radio_firmware_version(radio) + radio_ident, has_dropped_byte = _get_radio_firmware_version(radio) LOG.info("Radio firmware version:") LOG.debug(util.hexprint(radio_ident)) + LOG.info("Radio has dropped byte issue: %s" % repr(has_dropped_byte)) if radio_ident == "\xFF" * 16: ident += radio.MODEL.ljust(8) @@ -225,35 +281,49 @@ def _download(radio): status.msg = "Cloning from radio..." radio.status_fn(status) - data = b"" - for addr in range(0, radio._mem_size, radio._recv_block_size): - frame = _make_frame("S", addr, radio._recv_block_size) - # DEBUG - LOG.info("Request sent:") - LOG.debug(util.hexprint(frame)) + start = 0 + end = radio._mem_size + blocksize = radio._recv_block_size + passes = 1 + if has_dropped_byte: + passes = 2 + end = radio._mem_size - radio._recv_block_size - # sending the read request - _rawsend(radio, frame) + data = b"" + for i in range(0, passes): + if i == 1: + start = radio._mem_size - radio._recv_block_size + end = radio._mem_size + blocksize = 0x10 + + for addr in range(start, end, blocksize): + frame = _make_frame("S", addr, blocksize) + # DEBUG + LOG.info("Request sent:") + LOG.debug(util.hexprint(frame)) + + # sending the read request + _rawsend(radio, frame) - if radio._ack_block: - ack = _rawrecv(radio, 1) - if ack != b"\x06": - raise errors.RadioError( - "Radio refused to send block 0x%04x" % addr) + if radio._ack_block: + ack = _rawrecv(radio, 1) + if ack != b"\x06": + raise errors.RadioError( + "Radio refused to send block 0x%04x" % addr) - # now we read - d = _recv(radio, addr, radio._recv_block_size) + # now we read + d = _recv(radio, addr, blocksize) - _rawsend(radio, b"\x06") - time.sleep(0.05) + _rawsend(radio, b"\x06") + time.sleep(0.05) - # aggregate the data - data += d + # aggregate the data + data += d - # UI Update - status.cur = addr // radio._recv_block_size - status.msg = "Cloning from radio..." - radio.status_fn(status) + # UI Update + status.cur = addr // blocksize + status.msg = "Cloning from radio..." + radio.status_fn(status) data += ident @@ -266,9 +336,11 @@ def _upload(radio): _ident_radio(radio) # identify radio - radio_ident = _get_radio_firmware_version(radio) + radio_ident, aux_r1, aux_r2, aux_r3, \ + has_dropped_byte = _get_aux_data_from_radio(radio) LOG.info("Radio firmware version:") LOG.debug(util.hexprint(radio_ident)) + LOG.info("Radio has dropped byte issue: %s" % repr(has_dropped_byte)) # identify image image_ident = _get_image_firmware_version(radio) LOG.info("Image firmware version:") @@ -282,11 +354,49 @@ def _upload(radio): LOG.debug(msg) raise errors.RadioError("Image not supported by radio") - if radio_ident != b"0xFF" * 16 and image_ident == radio_ident: - _ranges = radio._ranges + aux_i1 = _get_data_from_image(radio, 0x1F00, 0x1F60) + aux_i2 = _get_data_from_image(radio, 0x1F70, 0x1F80) + aux_i3 = _get_data_from_image(radio, 0x1F90, 0x1FC0) + + # check if Aux memory of image matches Aux memory of radio + aux_matched = False + if aux_i1 != aux_r1: + # Area 1 does not match + # The safest thing to do is to skip uploading Aux mem area. + LOG.info("Aux memory mis-match") + LOG.info("Aux area 1 from image is %s" % repr(aux_i1)) + LOG.info("Aux area 1 from radio is %s" % repr(aux_r1)) + elif aux_i2 != aux_r2: + # Area 2 does not match + # The safest thing to do is to skip uploading Aux mem area. + LOG.info("Aux memory mis-match") + LOG.info("Aux area 2 from image is %s" % repr(aux_i2)) + LOG.info("Aux area 2 from radio is %s" % repr(aux_r2)) + elif aux_i3 != aux_r3: + # Area 3 does not match + # The safest thing to do is to skip uploading Aux mem area. + LOG.info("Aux memory mis-match") + LOG.info("Aux area 3 from image is %s" % repr(aux_i3)) + LOG.info("Aux area 3 from radio is %s" % repr(aux_r3)) else: + # All areas matched + # Uploading full Aux mem area is permitted + aux_matched = True + + if has_dropped_byte and not aux_matched: + msg = ("Image not supported by radio. You must...\n" + "1. Download from radio.\n" + "2. Make changes.\n" + "3. Upload back to same radio.") + raise errors.RadioError(msg) + + if has_dropped_byte or (aux_matched and radio.VENDOR != "BTECH"): _ranges = [(0x0000, 0x0DF0), - (0x0E00, 0x1800)] + (0x0E00, 0x1800), + (0x1E80, 0x2000), + ] + else: + _ranges = radio._ranges # UI progress status = chirp_common.Status() @@ -415,10 +525,10 @@ class BaofengCommonHT(chirp_common.CloneModeRadio, return rf def _is_txinh(self, _mem): - raw_tx = "" + raw_tx = b"" for i in range(0, 4): raw_tx += _mem.txfreq[i].get_raw() - return raw_tx == "\xFF\xFF\xFF\xFF" + return raw_tx == b"\xFF\xFF\xFF\xFF" def get_memory(self, number): _mem = self._memobj.memory[number] @@ -427,7 +537,7 @@ class BaofengCommonHT(chirp_common.CloneModeRadio, mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw()[:1] == b"\xff": mem.empty = True return mem diff --git a/chirp/drivers/baofeng_uv17.py b/chirp/drivers/baofeng_uv17.py new file mode 100644 index 0000000..e3f0e21 --- /dev/null +++ b/chirp/drivers/baofeng_uv17.py @@ -0,0 +1,447 @@ +# Copyright 2023: +# * Sander van der Wel, <svdwel@icloud.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 +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import logging + +from chirp import chirp_common, directory +from chirp.settings import RadioSettingGroup, RadioSetting, \ + RadioSettingValueBoolean, RadioSettingValueList, \ + RadioSettings, RadioSettingValueString +import struct +from chirp.drivers import baofeng_common, baofeng_uv17Pro +from chirp import errors, util + +LOG = logging.getLogger(__name__) +LIST_DTMFST = ["Off", "DT-ST", "ANI-ST", "DT+ANI"] +LIST_SAVE = ["Off", "1:1", "1:2", "1:3", "1:4"] +LIST_SCANMODE = ["Time", "Carrier", "Search"] + + +def _sendmagic(radio, magic, response_len): + baofeng_common._rawsend(radio, magic) + baofeng_common._rawrecv(radio, response_len) + + +# Locations of memory may differ each time, so a mapping has to be made first +def _get_memory_map(radio): + # Get memory map + memory_map = [] + for addr in range(0x1FFF, 0x10FFF, 0x1000): + frame = radio._make_frame(b"R", addr, 1) + baofeng_common._rawsend(radio, frame) + blocknr = ord(baofeng_common._rawrecv(radio, 6)[5:]) + blocknr = (blocknr >> 4 & 0xf) * 10 + (blocknr & 0xf) + memory_map += [blocknr] + _sendmagic(radio, b"\x06", 1) + return memory_map + + +def _download(radio): + """Get the memory map""" + baofeng_uv17Pro._do_ident(radio) + + data = b"" + _start_communication(radio) + + memory_map = _get_memory_map(radio) + + status = chirp_common.Status() + status.cur = 0 + status.max = radio.MEM_TOTAL // radio.BLOCK_SIZE + status.msg = "Cloning from radio..." + radio.status_fn(status) + + for block_number in radio.BLOCK_ORDER: + block_index = memory_map.index(block_number) + 1 + start_addr = block_index * 0x1000 + for addr in range(start_addr, start_addr + 0x1000, + radio.BLOCK_SIZE): + frame = radio._make_read_frame(addr, radio.BLOCK_SIZE) + # DEBUG + LOG.debug("Frame=" + util.hexprint(frame)) + + baofeng_common._rawsend(radio, frame) + + d = baofeng_common._rawrecv(radio, radio.BLOCK_SIZE + 5) + + LOG.debug("Response Data= " + util.hexprint(d)) + + data += d[5:] + + status.cur = len(data) // radio.BLOCK_SIZE + status.msg = "Cloning from radio..." + radio.status_fn(status) + + _sendmagic(radio, b"\x06", 1) + data += bytes(radio.MODEL, 'ascii') + return data + + +def _upload(radio): + """Upload procedure""" + baofeng_uv17Pro._do_ident(radio) + + _start_communication(radio) + + memory_map = _get_memory_map(radio) + + status = chirp_common.Status() + status.cur = 0 + status.max = radio.WRITE_MEM_TOTAL // radio.BLOCK_SIZE + status.msg = "Cloning to radio..." + radio.status_fn(status) + + for block_number in radio.BLOCK_ORDER: + # Choose a block number is memory map is corrupt + # This happens when te upload process is interrupted + if block_number not in memory_map: + memory_map[memory_map.index(165)] = block_number + block_index = memory_map.index(block_number) + 1 + start_addr = block_index * 0x1000 + data_start_addr = radio.BLOCK_ORDER.index(block_number) * 0x1000 + for addr in range(start_addr, start_addr + 0x1000, + radio.BLOCK_SIZE): + + # sending the data + data_addr = data_start_addr + addr - start_addr + data = radio.get_mmap()[data_addr:data_addr + radio.BLOCK_SIZE] + frame = radio._make_frame(b"W", addr, radio.BLOCK_SIZE, data) + baofeng_common._rawsend(radio, frame) + + # receiving the response + ack = baofeng_common._rawrecv(radio, 1) + if ack != b"\x06": + msg = "Bad ack writing block 0x%04x" % addr + raise errors.RadioError(msg) + + # UI Update + status.cur = (data_addr) // radio.BLOCK_SIZE + status.msg = "Cloning to radio..." + radio.status_fn(status) + + +def _start_communication(radio): + for magic in radio._magics: + _sendmagic(radio, magic[0], magic[1]) + + +@directory.register +class UV17(baofeng_uv17Pro.UV17Pro): + """Baofeng UV-17""" + VENDOR = "Baofeng" + MODEL = "UV-17" + NEEDS_COMPAT_SERIAL = False + + download_function = _download + upload_function = _upload + + MODES = ["FM", "NFM"] + BLOCK_ORDER = [16, 17, 18, 19, 24, 25, 26, 4, 6] + MEM_TOTAL = 0x9000 + WRITE_MEM_TOTAL = 0x9000 + BLOCK_SIZE = 0x40 + BAUD_RATE = 57600 + _magic = b"PSEARCH" + _magic_response_length = 8 + _magics = [[b"PASSSTA", 3], [b"SYSINFO", 1], + [b"\x56\x00\x00\x0A\x0D", 13], [b"\x06", 1], + [b"\x56\x00\x10\x0A\x0D", 13], [b"\x06", 1], + [b"\x56\x00\x20\x0A\x0D", 13], [b"\x06", 1], + [b"\x56\x00\x00\x00\x0A", 11], [b"\x06", 1], + [b"\xFF\xFF\xFF\xFF\x0C\x55\x56\x31\x35\x39\x39\x39", 1], + [b"\02", 8], [b"\x06", 1]] + _fingerprint = b"\x06" + b"UV15999" + _scode_offset = 1 + + _tri_band = False + POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=1.00), + chirp_common.PowerLevel("High", watts=5.00)] + + LENGTH_NAME = 11 + VALID_BANDS = [baofeng_uv17Pro.UV17Pro._vhf_range, + baofeng_uv17Pro.UV17Pro._uhf_range] + SCODE_LIST = ["%s" % x for x in range(1, 16)] + SQUELCH_LIST = ["Off"] + list("123456789") + LIST_POWERON_DISPLAY_TYPE = ["Full", "Message", "Voltage"] + LIST_TIMEOUT = ["Off"] + ["%s sec" % x for x in range(15, 615, 15)] + LIST_VOICE = ["Chinese", "English"] + LIST_BACKLIGHT_TIMER = ["Always On"] + ["%s sec" % x for x in range(1, 11)] + LIST_MODE = ["Name", "Frequency"] + CHANNELS = 999 + + MEM_FORMAT = """ + #seekto 0x0030; + struct channel { + lbcd rxfreq[4]; + lbcd txfreq[4]; + u8 unused1; + ul16 rxtone; + ul16 txtone; + u8 unknown1:1, + bcl:1, + pttid:2, + unknown2:1, + wide:1, + lowpower:1, + unknown:1; + u8 scode:4, + unknown3:3, + scan:1; + u8 unknown4; + }; + + struct { + struct channel mem[252]; + } mem1; + + #seek 0x10; + struct { + struct channel mem[255]; + } mem2; + + #seek 0x10; + struct { + struct channel mem[255]; + } mem3; + + #seek 0x10; + struct { + struct channel mem[237]; + } mem4; + + #seekto 0x7000; + struct { + u8 powerondistype; + u8 unknown0[15]; + char boottext1[10]; + u8 unknown1[6]; + char boottext2[10]; + u8 unknown2[22]; + u8 tot; + u8 squelch; + u8 vox; + u8 powersave: 4, + unknown3:2, + voice: 1, + voicesw: 1; + u8 backlight; + u8 beep:1, + autolock:1, + unknown4:1, + tail:1, + scanmode:2, + dtmfst:2; + u8 unknown5:1, + dualstandby:1, + roger:1, + unknown6:3, + fmenable:1, + unknown7:1; + u8 unknown8[9]; + u8 unknown9:6, + chbdistype:1, + chadistype:1; + } settings; + + struct vfo { + lbcd rxfreq[4]; + lbcd txfreq[4]; + u8 unused1; + ul16 rxtone; + ul16 txtone; + u8 unknown1:1, + bcl:1, + pttid:2, + unknown2:1, + wide:1, + lowpower:1, + unknown:1; + u8 scode:4, + unknown3:3, + scan:1; + u8 unknown4; + }; + + #seekto 0x0010; + struct { + struct vfo a; + struct vfo b; + } vfo; + + #seekto 0x4000; + struct { + char name[11]; + } names[999]; + + #seekto 0x8000; + struct { + u8 code[5]; + } pttid[15]; + + struct { + u8 unknown[5]; + u8 code[5]; + } ani; + + """ + + def _make_frame(self, cmd, addr, length, data=""): + """Pack the info in the header format""" + frame = struct.pack("<cH", cmd, addr) + struct.pack(">H", length) + # add the data if set + if len(data) != 0: + frame += data + # return the data + return frame + + def get_settings(self): + """Translate the bit in the mem_struct into settings in the UI""" + _mem = self._memobj + basic = RadioSettingGroup("basic", "Basic Settings") + dtmfe = RadioSettingGroup("dtmfe", "DTMF Encode Settings") + top = RadioSettings(basic, dtmfe) + + self.get_settings_common_basic(basic, _mem) + + def _filter(name): + filtered = "" + for char in str(name): + if char in chirp_common.CHARSET_ASCII: + filtered += char + else: + filtered += " " + return filtered + + rs = RadioSetting("settings.boottext1", "Power-On Message 1", + RadioSettingValueString( + 0, 10, _filter(self._memobj.settings.boottext1))) + basic.append(rs) + + rs = RadioSetting("settings.boottext2", "Power-On Message 2", + RadioSettingValueString( + 0, 10, _filter(self._memobj.settings.boottext2))) + basic.append(rs) + + if _mem.settings.powersave > 0x04: + val = 0x00 + else: + val = _mem.settings.powersave + rs = RadioSetting("settings.powersave", "Battery Saver", + RadioSettingValueList( + LIST_SAVE, LIST_SAVE[val])) + basic.append(rs) + + rs = RadioSetting("settings.scanmode", "Scan Mode", + RadioSettingValueList( + LIST_SCANMODE, + LIST_SCANMODE[_mem.settings.scanmode])) + basic.append(rs) + + rs = RadioSetting("settings.dtmfst", "DTMF Sidetone", + RadioSettingValueList(LIST_DTMFST, LIST_DTMFST[ + _mem.settings.dtmfst])) + basic.append(rs) + + rs = RadioSetting("settings.fmenable", "Enable FM radio", + RadioSettingValueBoolean(_mem.settings.fmenable)) + basic.append(rs) + + self.get_settings_common_dtmf(dtmfe) + + return top + + def decode_tone(self, val): + pol = "N" + mode = "" + if val in [0, 0xFFFF]: + xval = 0 + elif (val & 0x8000) > 0: + mode = "DTCS" + xval = (val & 0x0f) + (val >> 4 & 0xf)\ + * 10 + (val >> 8 & 0xf) * 100 + if (val & 0xC000) == 0xC000: + pol = "R" + else: + mode = "Tone" + xval = int((val & 0x0f) + (val >> 4 & 0xf) * 10 + + (val >> 8 & 0xf) * 100 + (val >> 12 & 0xf) + * 1000) / 10.0 + + return mode, xval, pol + + def get_raw_memory(self, number): + # The flash memory contains page_numbers + # This is probably to do wear leveling on the memory + # These numbers are needed, but make the channel memory + # not continuous. + number = number - 1 + if number >= 762: + _mem = self._memobj.mem4.mem[number - 762] + return _mem + if number >= 507: + _mem = self._memobj.mem3.mem[number - 507] + return _mem + if number >= 252: + _mem = self._memobj.mem2.mem[number - 252] + return _mem + _mem = self._memobj.mem1.mem[number] + return _mem + + def get_memory(self, number): + _mem = self.get_raw_memory(number) + _nam = self._memobj.names[number - 1] + + mem = chirp_common.Memory() + mem.number = number + + self.get_memory_common(_mem, _nam.name, mem) + + return mem + + def encode_tone(self, memtone, mode, tone, pol): + if mode == "Tone": + xtone = '%04i' % (tone * 10) + memtone.set_value((int(xtone[0]) << 12) + (int(xtone[1]) << 8) + + (int(xtone[2]) << 4) + int(xtone[3])) + elif mode == "TSQL": + xtone = '%04i' % (tone * 10) + memtone.set_value((int(tone[0]) << 12) + (int(xtone[1]) << 8) + + (int(xtone[2]) << 4) + int(xtone[3])) + elif mode == "DTCS": + xtone = str(int(tone)).rjust(4, '0') + memtone.set_value((0x8000 + (int(xtone[0]) << 12) + + (int(xtone[1]) << 8) + (int(xtone[2]) << 4) + + int(xtone[3]))) + else: + memtone.set_value(0) + + if mode == "DTCS" and pol == "R": + memtone.set_value(memtone + 0x4000) + + def set_memory(self, mem): + _mem = self.get_raw_memory(mem.number) + _nam = self._memobj.names[mem.number - 1] + + if mem.empty: + _mem.set_raw(b"\xff" * 16) + return + + _mem.set_raw(b"\x00" * 16) + + _namelength = self.get_features().valid_name_length + _nam.name = mem.name.ljust(_namelength, '\xFF') + + self.set_memory_common(mem, _mem) diff --git a/chirp/drivers/baofeng_uv17Pro.py b/chirp/drivers/baofeng_uv17Pro.py new file mode 100644 index 0000000..2bf370b --- /dev/null +++ b/chirp/drivers/baofeng_uv17Pro.py @@ -0,0 +1,1080 @@ +# Copyright 2023: +# * Sander van der Wel, <svdwel@icloud.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 +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import logging + +from chirp.drivers import baofeng_common +from chirp import chirp_common, directory, memmap +from chirp import bitwise +from chirp.settings import RadioSetting, \ + RadioSettingValueBoolean, RadioSettingValueList, \ + RadioSettingValueString, \ + RadioSettings, RadioSettingGroup +import struct +from chirp import errors, util + +LOG = logging.getLogger(__name__) + +# Baofeng UV-17L magic string +MSTRING_UV17L = b"PROGRAMBFNORMALU" +MSTRING_UV17PROGPS = b"PROGRAMCOLORPROU" + +DTMF_CHARS = "0123456789 *#ABCD" +STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 20.0, 25.0, 50.0] + +LIST_AB = ["A", "B"] +LIST_BANDWIDTH = ["Wide", "Narrow"] +LIST_DTMFSPEED = ["%s ms" % x for x in [50, 100, 200, 300, 500]] +LIST_HANGUPTIME = ["%s s" % x for x in [3, 4, 5, 6, 7, 8, 9, 10]] +LIST_SIDE_TONE = ["Off", "Side Key", "ID", "Side + ID"] +LIST_PTTID = ["Off", "BOT", "EOT", "Both"] +LIST_TIMEOUT_ALARM = ["Off"] + ["%s sec" % x for x in range(1, 11)] +LIST_PILOT_TONE = ["1000 Hz", "1450 Hz", "1750 Hz", "2100 Hz"] +LIST_VOICE = ["Off", "English", "Chinese"] +LIST_WORKMODE = ["Frequency", "Channel"] +LIST_BEEP = ["Off", "Beep", "Voice", "Both"] +LIST_SCANMODE = ["Time", "Carrier", "Search"] +LIST_ALARMMODE = ["Local", "Send Tone", "Send Code"] +LIST_MENU_QUIT_TIME = ["%s sec" % x for x in range(5, 55, 5)] + ["60 sec"] +LIST_ID_DELAY = ["%s ms" % x for x in range(100, 3100, 100)] +LIST_QT_SAVEMODE = ["Both", "RX", "TX"] +LIST_SKEY2_SHORT = ["FM", "Scan", "Search", "Vox"] +LIST_RPT_TAIL_CLEAR = ["%s ms" % x for x in range(0, 1100, 100)] +LIST_VOX_DELAY_TIME = ["%s ms" % x for x in range(500, 2100, 100)] +LIST_VOX_LEVEL = ["Off"] + ["%s" % x for x in range(1, 10, 1)] +LIST_VOX_LEVEL_ALT = ["%s" % x for x in range(1, 10, 1)] +LIST_GPS_MODE = ["GPS", "Beidou", "GPS + Beidou"] +LIST_GPS_TIMEZONE = ["%s" % x for x in range(-12, 13, 1)] +CHARSET_GB2312 = chirp_common.CHARSET_ASCII +for x in range(0xB0, 0xD7): + for y in range(0xA1, 0xFF): + CHARSET_GB2312 += bytes([x, y]).decode('gb2312') + + +def model_match(cls, data): + """Match the opened image to the correct version""" + return data[cls.MEM_TOTAL:] == bytes(cls.MODEL, 'utf-8') + + +def _crypt(symbol_index, buffer): + # Some weird encryption is used. From the table below, we only use "CO 7". + tblEncrySymbol = [b"BHT ", b"CO 7", b"A ES", b" EIY", b"M PQ", + b"XN Y", b"RVB ", b" HQP", b"W RC", b"MS N", + b" SAT", b"K DH", b"ZO R", b"C SL", b"6RB ", + b" JCG", b"PN V", b"J PK", b"EK L", b"I LZ"] + tbl_encrypt_symbols = tblEncrySymbol[symbol_index] + dec_buffer = b"" + index1 = 0 + for index2 in range(len(buffer)): + bool_encrypt_char = ((tbl_encrypt_symbols[index1] != 32) and + (buffer[index2] != 0) and + (buffer[index2] != 255) and + (buffer[index2] != tbl_encrypt_symbols[index1]) + and (buffer[index2] != + (tbl_encrypt_symbols[index1] ^ 255))) + if (bool_encrypt_char): + dec_byte = buffer[index2] ^ tbl_encrypt_symbols[index1] + dec_buffer += struct.pack('>B', dec_byte) + else: + dec_buffer += struct.pack('>B', buffer[index2]) + index1 = (index1 + 1) % 4 + return dec_buffer + + +def _do_ident(radio): + # Flush input buffer + baofeng_common._clean_buffer(radio) + + # Ident radio + magic = radio._magic + baofeng_common._rawsend(radio, magic) + ack = baofeng_common._rawrecv(radio, radio._magic_response_length) + + if not ack.startswith(radio._fingerprint): + if ack: + LOG.debug(repr(ack)) + raise errors.RadioError("Radio did not respond as expected (A)") + + return True + + +def _download(radio): + """Get the memory map""" + + # Put radio in program mode and identify it + _do_ident(radio) + for index in range(len(radio._magics)): + baofeng_common._rawsend(radio, radio._magics[index]) + baofeng_common._rawrecv(radio, radio._magicResponseLengths[index]) + + data = b"" + + # UI progress + status = chirp_common.Status() + status.cur = 0 + status.max = radio.MEM_TOTAL // radio.BLOCK_SIZE + status.msg = "Cloning from radio..." + radio.status_fn(status) + + for i in range(len(radio.MEM_SIZES)): + MEM_SIZE = radio.MEM_SIZES[i] + MEM_START = radio.MEM_STARTS[i] + for addr in range(MEM_START, MEM_START + MEM_SIZE, + radio.BLOCK_SIZE): + frame = radio._make_read_frame(addr, radio.BLOCK_SIZE) + # DEBUG + LOG.debug("Frame=" + util.hexprint(frame)) + + # Sending the read request + baofeng_common._rawsend(radio, frame) + + # Now we read data + d = baofeng_common._rawrecv(radio, radio.BLOCK_SIZE + 4) + + LOG.debug("Response Data= " + util.hexprint(d)) + d = _crypt(1, d[4:]) + + # Aggregate the data + data += d + + # UI Update + status.cur = len(data) // radio.BLOCK_SIZE + status.msg = "Cloning from radio..." + radio.status_fn(status) + return data + + +def _upload(radio): + # Put radio in program mode and identify it + _do_ident(radio) + for index in range(len(radio._magics)): + baofeng_common._rawsend(radio, radio._magics[index]) + baofeng_common._rawrecv(radio, radio._magicResponseLengths[index]) + + data = b"" + + # UI progress + status = chirp_common.Status() + status.cur = 0 + status.max = radio.MEM_TOTAL // radio.BLOCK_SIZE + status.msg = "Cloning from radio..." + radio.status_fn(status) + + data_addr = 0x00 + radio_mem = radio.get_mmap() + for i in range(len(radio.MEM_SIZES)): + MEM_SIZE = radio.MEM_SIZES[i] + MEM_START = radio.MEM_STARTS[i] + for addr in range(MEM_START, MEM_START + MEM_SIZE, + radio.BLOCK_SIZE): + data = radio_mem[data_addr:data_addr + radio.BLOCK_SIZE] + data = _crypt(1, data) + data_addr += radio.BLOCK_SIZE + + frame = radio._make_frame(b"W", addr, radio.BLOCK_SIZE, data) + # DEBUG + LOG.debug("Frame=" + util.hexprint(frame)) + + # Sending the read request + baofeng_common._rawsend(radio, frame) + + # receiving the response + ack = baofeng_common._rawrecv(radio, 1) + if ack != b"\x06": + msg = "Bad ack writing block 0x%04x" % addr + raise errors.RadioError(msg) + + # UI Update + status.cur = data_addr // radio.BLOCK_SIZE + status.msg = "Cloning to radio..." + radio.status_fn(status) + return data + + +@directory.register +class UV17Pro(baofeng_common.BaofengCommonHT): + """Baofeng UV-17Pro""" + VENDOR = "Baofeng" + MODEL = "UV-17Pro" + NEEDS_COMPAT_SERIAL = False + + MEM_STARTS = [0x0000, 0x9000, 0xA000, 0xD000] + MEM_SIZES = [0x8040, 0x0040, 0x02C0, 0x0040] + + MEM_TOTAL = 0x8380 + BLOCK_SIZE = 0x40 + BAUD_RATE = 115200 + + download_function = _download + upload_function = _upload + + _gmrs = False + _bw_shift = False + _has_support_for_banknames = False + + _tri_band = True + _fileid = [] + _magic = MSTRING_UV17L + _magic_response_length = 1 + _fingerprint = b"\x06" + _magics = [b"\x46", b"\x4d", + b"\x53\x45\x4E\x44\x21\x05\x0D\x01\x01\x01\x04\x11\x08\x05" + + b"\x0D\x0D\x01\x11\x0F\x09\x12\x09\x10\x04\x00"] + _magicResponseLengths = [16, 15, 1] + _fw_ver_start = 0x1EF0 + _recv_block_size = 0x40 + _mem_size = MEM_TOTAL + _ack_block = True + _has_when_to_send_aniid = True + _vfoscan = False + _has_gps = False + _has_voxsw = False + _has_pilot_tone = False + _has_send_id_delay = False + _has_skey2_short = False + _scode_offset = 0 + + MODES = ["NFM", "FM"] + VALID_CHARS = chirp_common.CHARSET_ALPHANUMERIC + \ + "!@#$%^&*()+-=[]:\";'<>?,./" + LENGTH_NAME = 12 + SKIP_VALUES = ["", "S"] + DTCS_CODES = tuple(sorted(chirp_common.DTCS_CODES + (645,))) + RXTX_CODES = ('Off', ) + for code in chirp_common.TONES: + RXTX_CODES = (RXTX_CODES + (str(code), )) + for code in DTCS_CODES: + RXTX_CODES = (RXTX_CODES + ('D' + str(code) + 'N', )) + for code in DTCS_CODES: + RXTX_CODES = (RXTX_CODES + ('D' + str(code) + 'I', )) + POWER_LEVELS = [chirp_common.PowerLevel("High", watts=5.00), + chirp_common.PowerLevel("Low", watts=1.00)] + _airband = (108000000, 136000000) + _vhf_range = (136000000, 174000000) + _vhf2_range = (200000000, 260000000) + _uhf_range = (400000000, 520000000) + _uhf2_range = (350000000, 390000000) + + VALID_BANDS = [_vhf_range, _vhf2_range, + _uhf_range] + PTTID_LIST = LIST_PTTID + SCODE_LIST = ["%s" % x for x in range(1, 21)] + SQUELCH_LIST = ["Off"] + list("12345") + LIST_POWERON_DISPLAY_TYPE = ["LOGO", "BATT voltage"] + LIST_TIMEOUT = ["Off"] + ["%s sec" % x for x in range(15, 195, 15)] + LIST_VOICE = ["English", "Chinese"] + LIST_BACKLIGHT_TIMER = ["Always On"] + ["%s sec" + % x for x in range(5, 25, 5)] + LIST_MODE = ["Name", "Frequency", "Channel Number"] + + CHANNELS = 1000 + + MEM_FORMAT = """ + struct { + lbcd rxfreq[4]; + lbcd txfreq[4]; + ul16 rxtone; + ul16 txtone; + u8 scode; + u8 pttid; + u8 lowpower; + u8 unknown1:1, + wide:1, + sqmode:2, + bcl:1, + scan:1, + unknown2:1, + fhss:1; + u8 unknown3; + u8 unknown4; + u8 unknown5; + u8 unknown6; + char name[12]; + } memory[1000]; + + struct vfo_entry { + u8 freq[8]; + ul16 rxtone; + ul16 txtone; + u8 unknown0; + u8 bcl; + u8 sftd:3, + scode:5; + u8 unknown1; + u8 lowpower; + u8 unknown2:1, + wide:1, + unknown3:5, + fhss:1; + u8 unknown4; + u8 step; + u8 offset[6]; + u8 unknown5[2]; + u8 sqmode; + u8 unknown6[3]; + }; + + #seekto 0x8000; + struct { + struct vfo_entry a; + struct vfo_entry b; + } vfo; + + struct { + u8 squelch; + u8 savemode; + u8 vox; + u8 backlight; + u8 dualstandby; + u8 tot; + u8 beep; + u8 voicesw; + u8 voice; + u8 sidetone; + u8 scanmode; + u8 pttid; + u8 pttdly; + u8 chadistype; + u8 chbdistype; + u8 bcl; + u8 autolock; + u8 alarmmode; + u8 alarmtone; + u8 unknown1; + u8 tailclear; + u8 rpttailclear; + u8 rpttaildet; + u8 roger; + u8 unknown2; + u8 fmenable; + u8 chbworkmode:4, + chaworkmode:4; + u8 keylock; + u8 powerondistype; + u8 tone; + u8 unknown4[2]; + u8 voxdlytime; + u8 menuquittime; + u8 unknown5[6]; + u8 totalarm; + u8 unknown6[2]; + u8 ctsdcsscantype; + ul16 vfoscanmin; + ul16 vfoscanmax; + u8 gpsw; + u8 gpsmode; + u8 unknown7[2]; + u8 key2short; + u8 unknown8[2]; + u8 rstmenu; + u8 unknown9; + u8 hangup; + u8 voxsw; + u8 gpstimezone; + } settings; + + #seekto 0x8080; + struct { + u8 code[5]; + u8 unknown[1]; + u8 unused1:6, + aniid:2; + u8 dtmfon; + u8 dtmfoff; + } ani; + + #seekto 0x80A0; + struct { + u8 code[5]; + u8 name[10]; + u8 unused; + } pttid[20]; + + #seekto 0x8280; + struct { + char name[16]; + } bank_name[10]; + """ + + def _make_read_frame(self, addr, length): + """Pack the info in the header format""" + frame = self._make_frame(b"\x52", addr, length) + # Return the data + return frame + + def _make_frame(self, cmd, addr, length, data=""): + """Pack the info in the header format""" + frame = cmd + struct.pack(">i", addr)[2:] + struct.pack("b", length) + # add the data if set + if len(data) != 0: + frame += data + # return the data + return frame + + @classmethod + def get_prompts(cls): + rp = chirp_common.RadioPrompts() + rp.experimental = \ + ('This driver is a beta version.\n' + '\n' + 'Please save an unedited copy of your first successful\n' + 'download to a CHIRP Radio Images(*.img) file.' + ) + rp.pre_download = _( + "Follow these instructions to download your info:\n" + "1 - Turn off your radio\n" + "2 - Connect your interface cable\n" + "3 - Turn on your radio\n" + "4 - Do the download of your radio data\n") + rp.pre_upload = _( + "Follow this instructions to upload your info:\n" + "1 - Turn off your radio\n" + "2 - Connect your interface cable\n" + "3 - Turn on your radio\n" + "4 - Do the upload of your radio data\n") + return rp + + def process_mmap(self): + """Process the mem map into the mem object""" + # make lines shorter for style check. + self._memobj = bitwise.parse(self.MEM_FORMAT, self._mmap) + + # DTMF settings + def apply_code(self, setting, obj, length): + code = [] + for j in range(0, length): + try: + code.append(DTMF_CHARS.index(str(setting.value)[j])) + except IndexError: + code.append(0xFF) + obj.code = code + + def get_settings_common_dtmf(self, dtmfe): + for i in range(0, len(self.SCODE_LIST)): + _codeobj = self._memobj.pttid[i].code + _code = "".join([ + DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F]) + val = RadioSettingValueString(0, 5, _code, False) + val.set_charset(DTMF_CHARS) + pttid = RadioSetting("pttid/%i.code" % i, + "Signal Code %i" % (i + 1), val) + pttid.set_apply_callback(self.apply_code, self._memobj.pttid[i], 5) + dtmfe.append(pttid) + + _codeobj = self._memobj.ani.code + _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F]) + val = RadioSettingValueString(0, 5, _code, False) + val.set_charset(DTMF_CHARS) + rs = RadioSetting("ani.code", "ANI Code", val) + rs.set_apply_callback(self.apply_code, self._memobj.ani, 5) + dtmfe.append(rs) + + def get_settings_common_basic(self, basic, _mem): + if _mem.settings.squelch >= len(self.SQUELCH_LIST): + val = 0x00 + else: + val = _mem.settings.squelch + rs = RadioSetting("settings.squelch", "Squelch", + RadioSettingValueList( + self.SQUELCH_LIST, self.SQUELCH_LIST[val])) + basic.append(rs) + + if _mem.settings.tot >= len(self.LIST_TIMEOUT): + val = 0x03 + else: + val = _mem.settings.tot + rs = RadioSetting("settings.tot", "Timeout Timer", + RadioSettingValueList( + self.LIST_TIMEOUT, self.LIST_TIMEOUT[val])) + basic.append(rs) + + rs = RadioSetting("settings.dualstandby", "Dual Watch", + RadioSettingValueBoolean(_mem.settings.dualstandby)) + basic.append(rs) + + if _mem.settings.powerondistype >= len(self.LIST_POWERON_DISPLAY_TYPE): + val = 0x00 + else: + rs = RadioSetting("settings.powerondistype", + "Power On Display Type", + RadioSettingValueList( + self.LIST_POWERON_DISPLAY_TYPE, + self.LIST_POWERON_DISPLAY_TYPE[ + _mem.settings.powerondistype])) + basic.append(rs) + + if _mem.settings.voice >= len(self.LIST_VOICE): + val = 0x01 + else: + val = _mem.settings.voice + rs = RadioSetting("settings.voice", "Voice Prompt", + RadioSettingValueList( + self.LIST_VOICE, self.LIST_VOICE[val])) + basic.append(rs) + + rs = RadioSetting("settings.voicesw", "Enable Voice", + RadioSettingValueBoolean(_mem.settings.voicesw)) + basic.append(rs) + + if _mem.settings.backlight >= len(self.LIST_BACKLIGHT_TIMER): + val = 0x00 + else: + val = _mem.settings.backlight + rs = RadioSetting("settings.backlight", "Backlight Timer", + RadioSettingValueList( + self.LIST_BACKLIGHT_TIMER, + self.LIST_BACKLIGHT_TIMER[val])) + basic.append(rs) + + rs = RadioSetting("settings.autolock", "Key Auto Lock", + RadioSettingValueBoolean(_mem.settings.autolock)) + basic.append(rs) + + rs = RadioSetting("settings.beep", "Beep", + RadioSettingValueList( + LIST_BEEP, LIST_BEEP[_mem.settings.beep])) + basic.append(rs) + + rs = RadioSetting("settings.roger", "Roger", + RadioSettingValueBoolean(_mem.settings.roger)) + basic.append(rs) + + rs = RadioSetting("settings.chadistype", "Channel A display type", + RadioSettingValueList( + self.LIST_MODE, + self.LIST_MODE[_mem.settings.chadistype])) + basic.append(rs) + + rs = RadioSetting("settings.chbdistype", "Channel B display type", + RadioSettingValueList( + self.LIST_MODE, + self.LIST_MODE[_mem.settings.chbdistype])) + basic.append(rs) + + def get_settings(self): + """Translate the bit in the mem_struct into settings in the UI""" + _mem = self._memobj + basic = RadioSettingGroup("basic", "Basic Settings") + dtmfe = RadioSettingGroup("dtmfe", "DTMF Encode Settings") + if self._has_support_for_banknames: + bank = RadioSettingGroup("bank", "Bank names") + top = RadioSettings(basic, bank, dtmfe) + else: + top = RadioSettings(basic, dtmfe) + + self.get_settings_common_basic(basic, _mem) + + rs = RadioSetting("settings.savemode", "Save Mode", + RadioSettingValueBoolean(_mem.settings.savemode)) + basic.append(rs) + + rs = RadioSetting("settings.totalarm", "Timeout Timer Alarm", + RadioSettingValueList( + LIST_TIMEOUT_ALARM, + LIST_TIMEOUT_ALARM[_mem.settings.totalarm])) + basic.append(rs) + + if self._has_pilot_tone: + rs = RadioSetting("settings.tone", "Pilot Tone", + RadioSettingValueList( + LIST_PILOT_TONE, + LIST_PILOT_TONE[_mem.settings.tone])) + basic.append(rs) + + rs = RadioSetting("settings.sidetone", "Side Tone", + RadioSettingValueList( + LIST_SIDE_TONE, + LIST_SIDE_TONE[_mem.settings.sidetone])) + basic.append(rs) + + rs = RadioSetting("settings.tailclear", "Tail Clear", + RadioSettingValueBoolean(_mem.settings.tailclear)) + basic.append(rs) + + rs = RadioSetting("settings.scanmode", "Scan Mode", + RadioSettingValueList( + LIST_SCANMODE, + LIST_SCANMODE[_mem.settings.scanmode])) + basic.append(rs) + + rs = RadioSetting("settings.alarmmode", "Alarm Mode", + RadioSettingValueList( + LIST_ALARMMODE, + LIST_ALARMMODE[_mem.settings.alarmmode])) + basic.append(rs) + + rs = RadioSetting("settings.alarmtone", "Sound Alarm", + RadioSettingValueBoolean(_mem.settings.alarmtone)) + basic.append(rs) + + rs = RadioSetting("settings.keylock", "Key Lock", + RadioSettingValueBoolean(_mem.settings.keylock)) + basic.append(rs) + + rs = RadioSetting("settings.menuquittime", "Menu Quit Timer", + RadioSettingValueList( + LIST_MENU_QUIT_TIME, + LIST_MENU_QUIT_TIME[ + _mem.settings.menuquittime])) + basic.append(rs) + + if self._has_send_id_delay: + rs = RadioSetting("settings.pttdly", "Send ID Delay", + RadioSettingValueList( + LIST_ID_DELAY, + LIST_ID_DELAY[_mem.settings.pttdly])) + basic.append(rs) + + rs = RadioSetting("settings.ctsdcsscantype", "QT Save Mode", + RadioSettingValueList( + LIST_QT_SAVEMODE, + LIST_QT_SAVEMODE[_mem.settings.ctsdcsscantype])) + basic.append(rs) + + def getKey2shortIndex(value): + key_to_index = {0x07: 0, + 0x1C: 1, + 0x1D: 2, + 0x2D: 3} + return key_to_index.get(int(value), 0) + + def apply_Key2short(setting, obj): + val = str(setting.value) + key_to_index = {'FM': 0x07, + 'Scan': 0x1C, + 'Search': 0x1D, + 'Vox': 0x2D} + obj.key2short = key_to_index.get(val, 0x07) + + if self._has_skey2_short: + rs = RadioSetting("settings.key2short", "Skey2 Short", + RadioSettingValueList( + LIST_SKEY2_SHORT, + LIST_SKEY2_SHORT[ + getKey2shortIndex( + _mem.settings.key2short)])) + rs.set_apply_callback(apply_Key2short, _mem.settings) + basic.append(rs) + + rs = RadioSetting("settings.chaworkmode", "Channel A work mode", + RadioSettingValueList( + LIST_WORKMODE, + LIST_WORKMODE[_mem.settings.chaworkmode])) + basic.append(rs) + + rs = RadioSetting("settings.chbworkmode", "Channel B work mode", + RadioSettingValueList( + LIST_WORKMODE, + LIST_WORKMODE[_mem.settings.chbworkmode])) + basic.append(rs) + + rs = RadioSetting("settings.rpttailclear", "Rpt Tail Clear", + RadioSettingValueList( + LIST_RPT_TAIL_CLEAR, + LIST_RPT_TAIL_CLEAR[ + _mem.settings.rpttailclear])) + basic.append(rs) + + rs = RadioSetting("settings.rpttaildet", "Rpt Tail Delay", + RadioSettingValueList( + LIST_RPT_TAIL_CLEAR, + LIST_RPT_TAIL_CLEAR[_mem.settings.rpttaildet])) + basic.append(rs) + + rs = RadioSetting("settings.rstmenu", "Enable Menu Rst", + RadioSettingValueBoolean(_mem.settings.rstmenu)) + basic.append(rs) + + if self._has_voxsw: + rs = RadioSetting("settings.voxsw", "Vox Switch", + RadioSettingValueBoolean(_mem.settings.voxsw)) + basic.append(rs) + + rs = RadioSetting("settings.vox", "Vox Level", + RadioSettingValueList( + LIST_VOX_LEVEL_ALT, + LIST_VOX_LEVEL_ALT[_mem.settings.vox])) + basic.append(rs) + else: + rs = RadioSetting("settings.vox", "Vox Level", + RadioSettingValueList( + LIST_VOX_LEVEL, + LIST_VOX_LEVEL[_mem.settings.vox])) + basic.append(rs) + + rs = RadioSetting("settings.voxdlytime", "Vox Delay Time", + RadioSettingValueList( + LIST_VOX_DELAY_TIME, + LIST_VOX_DELAY_TIME[_mem.settings.voxdlytime])) + basic.append(rs) + + if self._has_gps: + rs = RadioSetting("settings.gpsw", "GPS On", + RadioSettingValueBoolean(_mem.settings.gpsw)) + basic.append(rs) + + rs = RadioSetting("settings.gpsmode", "GPS Mode", + RadioSettingValueList( + LIST_GPS_MODE, + LIST_GPS_MODE[_mem.settings.gpsmode])) + basic.append(rs) + + rs = RadioSetting("settings.gpstimezone", "GPS Timezone", + RadioSettingValueList( + LIST_GPS_TIMEZONE, + LIST_GPS_TIMEZONE[_mem.settings.gpstimezone])) + basic.append(rs) + + rs = RadioSetting("settings.fmenable", "Disable FM radio", + RadioSettingValueBoolean(_mem.settings.fmenable)) + basic.append(rs) + + def _filterName(name): + fname = b"" + for char in name: + if ord(str(char)) == 255: + break + fname += int(char).to_bytes(1, 'big') + return fname.decode('gb2312').strip() + + def apply_bankname(setting, obj): + name = str(setting.value).encode('gb2312')[:16].ljust(16, b"\xff") + obj.name = name + + if self._has_support_for_banknames: + for i in range(0, 10): + _nameobj = self._memobj.bank_name[i] + rs = RadioSetting("bank_name/%i.name" % i, + "Bank name %i" % (i + 1), + RadioSettingValueString( + 0, 16, _filterName(_nameobj.name), False, + CHARSET_GB2312)) + rs.set_apply_callback(apply_bankname, _nameobj) + bank.append(rs) + + self.get_settings_common_dtmf(dtmfe) + + if _mem.ani.dtmfon > 0xC3: + val = 0x03 + else: + val = _mem.ani.dtmfon + rs = RadioSetting("ani.dtmfon", "DTMF Speed (on)", + RadioSettingValueList(LIST_DTMFSPEED, + LIST_DTMFSPEED[val])) + dtmfe.append(rs) + + if _mem.ani.dtmfoff > 0xC3: + val = 0x03 + else: + val = _mem.ani.dtmfoff + rs = RadioSetting("ani.dtmfoff", "DTMF Speed (off)", + RadioSettingValueList(LIST_DTMFSPEED, + LIST_DTMFSPEED[val])) + dtmfe.append(rs) + + if self._has_when_to_send_aniid: + rs = RadioSetting("ani.aniid", "When to send ANI ID", + RadioSettingValueList(LIST_PTTID, + LIST_PTTID[ + _mem.ani.aniid])) + dtmfe.append(rs) + + if _mem.settings.hangup >= len(LIST_HANGUPTIME): + val = 0 + else: + val = _mem.settings.hangup + rs = RadioSetting("settings.hangup", "Hang-up time", + RadioSettingValueList(LIST_HANGUPTIME, + LIST_HANGUPTIME[ + val])) + dtmfe.append(rs) + + return top + + def sync_in(self): + """Download from radio""" + try: + data = self.download_function() + except errors.RadioError: + # Pass through any real errors we raise + raise + except Exception: + # If anything unexpected happens, make sure we raise + # a RadioError and log the problem + LOG.exception('Unexpected error during download') + raise errors.RadioError('Unexpected error communicating ' + 'with the radio') + self._mmap = memmap.MemoryMapBytes(data) + + self.process_mmap() + + def sync_out(self): + """Upload to radio""" + try: + self.upload_function() + except errors.RadioError: + raise + except Exception: + # If anything unexpected happens, make sure we raise + # a RadioError and log the problem + LOG.exception('Unexpected error during upload') + raise errors.RadioError('Unexpected error communicating ' + 'with the radio') + + def get_features(self): + """Get the radio's features""" + + rf = chirp_common.RadioFeatures() + rf.has_settings = True + rf.has_bank = False + rf.has_tuning_step = False + rf.can_odd_split = True + rf.has_name = True + rf.has_offset = True + rf.has_mode = True + rf.has_dtcs = True + rf.has_rx_dtcs = True + rf.has_dtcs_polarity = True + rf.has_ctone = True + rf.has_cross = True + rf.valid_modes = self.MODES + rf.valid_characters = self.VALID_CHARS + rf.valid_name_length = self.LENGTH_NAME + if self._gmrs: + rf.valid_duplexes = ["", "+", "off"] + else: + rf.valid_duplexes = ["", "-", "+", "split", "off"] + rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS', 'Cross'] + rf.valid_cross_modes = [ + "Tone->Tone", + "DTCS->", + "->DTCS", + "Tone->DTCS", + "DTCS->Tone", + "->Tone", + "DTCS->DTCS"] + rf.valid_skips = self.SKIP_VALUES + rf.valid_dtcs_codes = self.DTCS_CODES + rf.memory_bounds = (1, self.CHANNELS) + rf.valid_power_levels = self.POWER_LEVELS + rf.valid_bands = self.VALID_BANDS + rf.valid_tuning_steps = STEPS + + return rf + + def decode_tone(self, val): + mode = "" + pol = "N" + if val in [0, 0xFFFF]: + xval = 0 + elif val >= 0x0258: + mode = "Tone" + xval = int(val) / 10.0 + elif val <= 0x0258: + mode = "DTCS" + if val > 0x69: + index = val - 0x6A + pol = "R" + else: + index = val - 1 + xval = self.DTCS_CODES[index] + else: + LOG.warn("Bug: tone is %04x" % val) + return mode, xval, pol + + def encode_tone(self, memtone, mode, tone, pol): + if mode == "Tone": + memtone.set_value(int(tone * 10)) + elif mode == "TSQL": + memtone.set_value(int(tone * 10)) + elif mode == "DTCS": + if pol == 'R': + memtone.set_value(self.DTCS_CODES.index(tone) + 1 + 0x69) + else: + memtone.set_value(self.DTCS_CODES.index(tone) + 1) + else: + memtone.set_value(0) + + def split_txfreq(self, _mem, freq): + if self._is_txinh(_mem): + # TX freq not set + duplex = "off" + offset = 0 + else: + offset = (int(_mem.txfreq) * 10) - freq + if offset != 0: + if baofeng_common._split(self.get_features(), freq, int( + _mem.txfreq) * 10): + duplex = "split" + offset = int(_mem.txfreq) * 10 + elif offset < 0: + offset = abs(offset) + duplex = "-" + elif offset > 0: + duplex = "+" + else: + duplex = "" + offset = 0 + return offset, duplex + + def get_memory_common(self, _mem, name, mem): + if _mem.get_raw()[0] == 255: + mem.empty = True + return mem + + mem.freq = int(_mem.rxfreq) * 10 + + # TX freq set + mem.offset, mem.duplex = self.split_txfreq(_mem, mem.freq) + + txtone = self.decode_tone(_mem.txtone) + rxtone = self.decode_tone(_mem.rxtone) + chirp_common.split_tone_decode(mem, txtone, rxtone) + + if not _mem.scan: + mem.skip = "S" + + levels = self.POWER_LEVELS + try: + mem.power = levels[_mem.lowpower] + except IndexError: + mem.power = levels[0] + + mem.mode = _mem.wide and self.MODES[0] or self.MODES[1] + + mem.extra = RadioSettingGroup("Extra", "extra") + + rs = RadioSetting("bcl", "BCL", + RadioSettingValueBoolean(_mem.bcl)) + mem.extra.append(rs) + + rs = RadioSetting("pttid", "PTT ID", + RadioSettingValueList(self.PTTID_LIST, + self.PTTID_LIST[ + _mem.pttid])) + mem.extra.append(rs) + + scode = (_mem.scode - self._scode_offset) % len(self.SCODE_LIST) + rs = RadioSetting("scode", "S-CODE", + RadioSettingValueList(self.SCODE_LIST, + self.SCODE_LIST[ + scode])) + mem.extra.append(rs) + + mem.name = str(name).replace('\xFF', ' ').replace('\x00', ' ').rstrip() + + def get_raw_memory(self, number): + return self._memobj.memory[number - 1] + + def get_memory(self, number): + _mem = self.get_raw_memory(number) + + mem = chirp_common.Memory() + mem.number = number + + self.get_memory_common(_mem, _mem.name, mem) + + return mem + + def unsplit_txfreq(self, mem): + _mem = self.get_raw_memory(mem.number) + if mem.duplex == "off": + for i in range(0, 4): + _mem.txfreq[i].set_raw(b"\xFF") + elif mem.duplex == "split": + _mem.txfreq = mem.offset / 10 + elif mem.duplex == "+": + _mem.txfreq = (mem.freq + mem.offset) / 10 + elif mem.duplex == "-": + _mem.txfreq = (mem.freq - mem.offset) / 10 + else: + _mem.txfreq = mem.freq / 10 + + def set_memory_common(self, mem, _mem): + _mem.rxfreq = mem.freq / 10 + self.unsplit_txfreq(mem) + + ((txmode, txtone, txpol), (rxmode, rxtone, rxpol)) = \ + chirp_common.split_tone_encode(mem) + self.encode_tone(_mem.txtone, txmode, txtone, txpol) + self.encode_tone(_mem.rxtone, rxmode, rxtone, rxpol) + + _mem.scan = mem.skip != "S" + _mem.wide = mem.mode == self.MODES[0] + + if mem.power: + _mem.lowpower = self.POWER_LEVELS.index(mem.power) + else: + _mem.lowpower = 0 + + # extra settings + if len(mem.extra) > 0: + # there are setting, parse + for setting in mem.extra: + if setting.get_name() == "scode": + setattr(_mem, setting.get_name(), str(int(setting.value) + + self._scode_offset)) + else: + setattr(_mem, setting.get_name(), setting.value) + else: + # there are no extra settings, load defaults + _mem.bcl = 0 + _mem.pttid = 0 + _mem.scode = self._scode_offset + + def set_memory(self, mem): + _mem = self.get_raw_memory(mem.number) + + _mem.set_raw(b"\x00"*16 + b"\xff" * 16) + + if mem.empty: + _mem.set_raw(b"\xff" * 32) + return + + _namelength = self.get_features().valid_name_length + _mem.name = mem.name.ljust(_namelength, '\xFF') + + self.set_memory_common(mem, _mem) + + +@directory.register +class UV17ProGPS(UV17Pro): + VENDOR = "Baofeng" + MODEL = "UV-17ProGPS" + + _has_support_for_banknames = True + _magic = MSTRING_UV17PROGPS + _magics = [b"\x46", b"\x4d", b"\x53\x45\x4E\x44\x21\x05\x0D\x01\x01" + + b"\x01\x04\x11\x08\x05\x0D\x0D\x01\x11\x0F\x09\x12\x09" + + b"\x10\x04\x00"] + _magicResponseLengths = [16, 7, 1] + _has_when_to_send_aniid = False + _vfoscan = True + _has_gps = True + _has_voxsw = True + _has_pilot_tone = True + _has_send_id_delay = True + _has_skey2_short = True + VALID_BANDS = [UV17Pro._airband, UV17Pro._vhf_range, UV17Pro._vhf2_range, + UV17Pro._uhf_range, UV17Pro._uhf2_range] + + +@directory.register +class BF5RM(UV17Pro): + VENDOR = "Baofeng" + MODEL = "5RM" + VALID_BANDS = [UV17Pro._airband, UV17Pro._vhf_range, UV17Pro._vhf2_range, + UV17Pro._uhf_range, UV17Pro._uhf2_range] diff --git a/chirp/drivers/baofeng_uv3r.py b/chirp/drivers/baofeng_uv3r.py index 4ea476d..39e9773 100644 --- a/chirp/drivers/baofeng_uv3r.py +++ b/chirp/drivers/baofeng_uv3r.py @@ -235,7 +235,7 @@ class UV3RRadio(chirp_common.CloneModeRadio): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw(asbytes=False)[0] == "\xff": mem.empty = True return mem diff --git a/chirp/drivers/baofeng_wp970i.py b/chirp/drivers/baofeng_wp970i.py index 4a29c18..447a8f6 100644 --- a/chirp/drivers/baofeng_wp970i.py +++ b/chirp/drivers/baofeng_wp970i.py @@ -237,7 +237,7 @@ class WP970I(baofeng_common.BaofengCommonHT): sftd:2, scode:4; u8 unknown4; - u8 unused3:1 + u8 unused3:1, step:3, unused4:4; u8 unused5:1, @@ -982,6 +982,29 @@ class UVS9X3(BFA58S): @directory.register +class BF5RXRadio(BFA58S): + VENDOR = "Baofeng" + MODEL = "5RX" + ALIASES = [] + _magic = [MSTRING_UVS9X3, ] + + _air_range = (108000000, 136000000) + _vhf_range = (136000000, 174000000) + _vhf2_range = (200000000, 260000000) + _uhf2_range = (350000000, 390000000) + _uhf_range = (400000000, 520000000) + + def get_features(self): + rf = WP970I.get_features(self) + rf.valid_bands = [self._air_range, + self._vhf_range, + self._vhf2_range, + self._uhf2_range, + self._uhf_range] + return rf + + +@directory.register class UV9R(WP970I): """Baofeng UV-9R""" VENDOR = "Baofeng" diff --git a/chirp/drivers/bf_t1.py b/chirp/drivers/bf_t1.py index 496af8d..aab7b03 100644 --- a/chirp/drivers/bf_t1.py +++ b/chirp/drivers/bf_t1.py @@ -634,7 +634,7 @@ class BFT1(chirp_common.CloneModeRadio, chirp_common.ExperimentalRadio): else: mem.number = number - if _mem.get_raw()[0] == "\xFF": + if _mem.get_raw(asbytes=False)[0] == "\xFF": mem.empty = True return mem diff --git a/chirp/drivers/bf_t8.py b/chirp/drivers/bf_t8.py index 88880ff..5dd0336 100644 --- a/chirp/drivers/bf_t8.py +++ b/chirp/drivers/bf_t8.py @@ -37,7 +37,7 @@ from chirp.settings import ( LOG = logging.getLogger(__name__) MEM_FORMAT = """ -#seekto 0x0000; +// #seekto 0x0000; struct { lbcd rxfreq[4]; // RX Frequency lbcd txfreq[4]; // TX Frequency @@ -53,7 +53,7 @@ struct { u8 unknown3[3]; // } memory[%d]; -#seekto 0x0630; +// #seekto 0x0630; struct { u8 squelch; // SQL u8 vox; // Vox Lv @@ -72,8 +72,10 @@ struct { u8 mrb; // MR Channel B u8 disp_ab; // Display A/B Selected } settings; +""" -#seekto 0x063D; +MEM_FORMAT_PT2 = """ +// #seekto 0x063D; struct { u8 workmode; // Work Mode u8 wx; // NOAA WX ch# @@ -88,14 +90,14 @@ struct { """ MEM_FM_U_FORMAT = """ -#seekto 0x063B; +// #seekto 0x063B; struct { u16 fmcur; // Broadcast FM station } fmpreset; """ MEM_FM_UL_FORMAT = """ -#seekto 0x063B; +// #seekto 0x063B; struct { ul16 fmcur; // Broadcast FM station } fmpreset; @@ -359,7 +361,7 @@ class BFT8Radio(chirp_common.CloneModeRadio): return rf def process_mmap(self): - mem_format = MEM_FORMAT + MEM_FM_UL_FORMAT + mem_format = MEM_FORMAT + MEM_FM_UL_FORMAT + MEM_FORMAT_PT2 self._memobj = bitwise.parse(mem_format % self._mem_params, self._mmap) def sync_in(self): @@ -415,10 +417,10 @@ class BFT8Radio(chirp_common.CloneModeRadio): (rx_tmode, rx_tone, rx_pol)) def _is_txinh(self, _mem): - raw_tx = "" + raw_tx = b"" for i in range(0, 4): raw_tx += _mem.txfreq[i].get_raw() - return raw_tx == "\xFF\xFF\xFF\xFF" + return raw_tx == b"\xFF\xFF\xFF\xFF" def _get_mem(self, number): return self._memobj.memory[number - 1] @@ -441,12 +443,12 @@ class BFT8Radio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw() == b"\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem - if _mem.get_raw() == ("\xFF" * 16): + if _mem.get_raw() == (b"\xFF" * 16): LOG.debug("Initializing empty memory") _mem.set_raw("\x00" * 13 + "\xFF" * 3) @@ -891,7 +893,7 @@ class RetevisRB27B(BFT8Radio): _memsize = 0x1040 def process_mmap(self): - mem_format = MEM_FORMAT + MEM_FM_U_FORMAT + mem_format = MEM_FORMAT + MEM_FM_U_FORMAT + MEM_FORMAT_PT2 self._memobj = bitwise.parse(mem_format % self._mem_params, self._mmap) @@ -911,7 +913,7 @@ class RetevisRB27(RetevisRB27B): _frs = _murs = _pmr = False def process_mmap(self): - mem_format = MEM_FORMAT + MEM_FM_U_FORMAT + mem_format = MEM_FORMAT + MEM_FM_U_FORMAT + MEM_FORMAT_PT2 self._memobj = bitwise.parse(mem_format % self._mem_params, self._mmap) @@ -926,7 +928,7 @@ class RetevisRB27V(RetevisRB27B): _frs = _gmrs = _pmr = False def process_mmap(self): - mem_format = MEM_FORMAT + MEM_FM_U_FORMAT + mem_format = MEM_FORMAT + MEM_FM_U_FORMAT + MEM_FORMAT_PT2 self._memobj = bitwise.parse(mem_format % self._mem_params, self._mmap) diff --git a/chirp/drivers/bj9900.py b/chirp/drivers/bj9900.py index 4c278e4..d4f1847 100644 --- a/chirp/drivers/bj9900.py +++ b/chirp/drivers/bj9900.py @@ -84,11 +84,11 @@ class BJ9900Radio(chirp_common.CloneModeRadio, u16 is_txdigtone:1, txdtcs_pol:1, txtone:14; - u8 txdtmf:4 + u8 txdtmf:4, pttid:4; u8 power:1, wide:1, - compandor:1 + compandor:1, unknown3:5; u8 namelen; u8 name[7]; @@ -322,7 +322,7 @@ class BJ9900Radio(chirp_common.CloneModeRadio, mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw(asbytes=False)[0] == "\xff": mem.empty = True return mem diff --git a/chirp/drivers/boblov_x3plus.py b/chirp/drivers/boblov_x3plus.py index ff8cb01..5482a4b 100644 --- a/chirp/drivers/boblov_x3plus.py +++ b/chirp/drivers/boblov_x3plus.py @@ -260,13 +260,14 @@ class BoblovX3Plus(chirp_common.CloneModeRadio, mem.freq = int(rmem.rxfreq) * 10 # A blank (0 MHz) or 0xFFFFFFFF frequency is considered empty - if mem.freq == 0 or rmem.rxfreq.get_raw() == '\xFF\xFF\xFF\xFF': + if mem.freq == 0 or ( + rmem.rxfreq.get_raw(asbytes=False) == '\xFF\xFF\xFF\xFF'): LOG.debug('empty channel %d', number) mem.freq = 0 mem.empty = True return mem - if rmem.txfreq.get_raw() == '\xFF\xFF\xFF\xFF': + if rmem.txfreq.get_raw(asbytes=False) == '\xFF\xFF\xFF\xFF': mem.duplex = 'off' mem.offset = 0 elif int(rmem.rxfreq) == int(rmem.txfreq): diff --git a/chirp/drivers/btech.py b/chirp/drivers/btech.py index 90c13c4..1bbd3f7 100644 --- a/chirp/drivers/btech.py +++ b/chirp/drivers/btech.py @@ -827,14 +827,14 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, # Memory number mem.number = number - if _mem.get_raw()[0] == "\xFF": + if _mem.get_raw()[:1] == b"\xFF": mem.empty = True return mem # Freq and offset mem.freq = int(_mem.rxfreq) * 10 # tx freq can be blank - if _mem.get_raw()[4] == "\xFF": + if _mem.get_raw()[:4] == b"\xFF": # TX freq not set mem.offset = 0 mem.duplex = "off" @@ -1005,7 +1005,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, mem_was_empty = False # same method as used in get_memory for determining if mem is empty # doing this BEFORE overwriting it with new values ... - if _mem.get_raw()[0] == "\xFF": + if _mem.get_raw(asbytes=False)[0] == "\xFF": LOG.debug("This mem was empty before") mem_was_empty = True @@ -3143,7 +3143,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, MEM_FORMAT = """ -#seekto 0x0000; +// #seekto 0x0000; struct { lbcd rxfreq[4]; lbcd txfreq[4]; @@ -3289,7 +3289,7 @@ struct { u8 standard; // one out of LIST_5TONE_STANDARDS } _5tone_codes[15]; -#seekto 0x25F0; +// #seekto 0x25F0; struct { u8 _5tone_delay1; // * 10ms u8 _5tone_delay2; // * 10ms @@ -3316,7 +3316,7 @@ struct { u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B } dtmf_codes[15]; -#seekto 0x29F0; +// #seekto 0x29F0; struct { u8 dtmfspeed_on; //list with 50..2000ms in steps of 10 u8 dtmfspeed_off; //list with 50..2000ms in steps of 10 @@ -3630,7 +3630,7 @@ class LT588UV(BTech): COLOR_MEM_FORMAT = """ -#seekto 0x0000; +// #seekto 0x0000; struct { lbcd rxfreq[4]; lbcd txfreq[4]; @@ -3770,7 +3770,7 @@ struct { struct settings_vfo d; } vfo; -#seekto 0x0F80; +// #seekto 0x0F80; struct { char line1[8]; char line2[8]; @@ -3804,7 +3804,7 @@ struct { u8 standard; // one out of LIST_5TONE_STANDARDS } _5tone_codes[15]; -#seekto 0x25F0; +// #seekto 0x25F0; struct { u8 _5tone_delay1; // * 10ms u8 _5tone_delay2; // * 10ms @@ -3831,7 +3831,7 @@ struct { u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B } dtmf_codes[15]; -#seekto 0x29F0; +// #seekto 0x29F0; struct { u8 dtmfspeed_on; //list with 50..2000ms in steps of 10 u8 dtmfspeed_off; //list with 50..2000ms in steps of 10 @@ -4175,7 +4175,7 @@ class DB25G(BTechColor): GMRS_MEM_FORMAT = """ -#seekto 0x0000; +// #seekto 0x0000; struct { lbcd rxfreq[4]; lbcd txfreq[4]; @@ -4199,7 +4199,7 @@ struct { pttid:2; } memory[256]; -#seekto 0x1000; +// #seekto 0x1000; struct { char name[7]; u8 unknown1[9]; @@ -4221,7 +4221,7 @@ struct { u8 standard; // one out of LIST_5TONE_STANDARDS } _5tone_codes[15]; -#seekto 0x25F0; +// #seekto 0x25F0; struct { u8 _5tone_delay1; // * 10ms u8 _5tone_delay2; // * 10ms @@ -4243,7 +4243,7 @@ struct { u8 decode_reset_time; // * 100 + 100ms } _5tone_settings; -#seekto 0x2900; +// #seekto 0x2900; struct { u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B } dtmf_codes[15]; @@ -4334,7 +4334,9 @@ struct { char broadcast_station_name[6]; u8 unknown[2]; } fm_radio_preset[16]; +""" +GMRS_MEM_FORMAT_PT2 = """ #seekto 0x3280; struct { u8 unknown1; @@ -4388,6 +4390,11 @@ struct { struct settings_vfo d; } vfo; +#seekto 0x33B0; +struct { + char line[16]; +} static_msg; + #seekto 0x3D80; struct { u8 vhf_low[3]; @@ -4406,11 +4413,6 @@ struct { u8 uhf2_high[3]; } ranges; -#seekto 0x33B0; -struct { - char line[16]; -} static_msg; - #seekto 0x3F70; struct { char fp[6]; @@ -4563,7 +4565,8 @@ class BTechGMRS(BTechMobileCommon): """Process the mem map into the mem object""" # Get it - mem_format = GMRS_MEM_FORMAT + GMRS_ORIG_MEM_FORMAT + mem_format = GMRS_MEM_FORMAT + GMRS_ORIG_MEM_FORMAT + \ + GMRS_MEM_FORMAT_PT2 self._memobj = bitwise.parse(mem_format, self._mmap) # load specific parameters from the radio image @@ -4645,7 +4648,8 @@ class GMRS50V2(BTechGMRS): """Process the mem map into the mem object""" # Get it - mem_format = GMRS_MEM_FORMAT + GMRS_V2_MEM_FORMAT + mem_format = GMRS_MEM_FORMAT + GMRS_V2_MEM_FORMAT + \ + GMRS_MEM_FORMAT_PT2 self._memobj = bitwise.parse(mem_format, self._mmap) # load specific parameters from the radio image @@ -4677,7 +4681,7 @@ class GMRS50V2(BTechGMRS): COLORHT_MEM_FORMAT = """ -#seekto 0x0000; +// #seekto 0x0000; struct { lbcd rxfreq[4]; lbcd txfreq[4]; @@ -4844,7 +4848,7 @@ struct { u8 standard; // one out of LIST_5TONE_STANDARDS } _5tone_codes[15]; -#seekto 0x25F0; +// #seekto 0x25F0; struct { u8 _5tone_delay1; // * 10ms u8 _5tone_delay2; // * 10ms @@ -4871,7 +4875,7 @@ struct { u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B } dtmf_codes[15]; -#seekto 0x29F0; +// #seekto 0x29F0; struct { u8 dtmfspeed_on; //list with 50..2000ms in steps of 10 u8 dtmfspeed_off; //list with 50..2000ms in steps of 10 @@ -5045,7 +5049,7 @@ class KT8R(QYTColorHT): COLOR9900_MEM_FORMAT = """ -#seekto 0x0000; +// #seekto 0x0000; struct { lbcd rxfreq[4]; lbcd txfreq[4]; @@ -5185,7 +5189,7 @@ struct { struct settings_vfo d; } vfo; -#seekto 0x0F80; +// #seekto 0x0F80; struct { char line1[8]; char line2[8]; @@ -5224,7 +5228,7 @@ struct { u8 standard; // one out of LIST_5TONE_STANDARDS } _5tone_codes[15]; -#seekto 0x25F0; +// #seekto 0x25F0; struct { u8 _5tone_delay1; // * 10ms u8 _5tone_delay2; // * 10ms @@ -5251,7 +5255,7 @@ struct { u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B } dtmf_codes[15]; -#seekto 0x29F0; +// #seekto 0x29F0; struct { u8 dtmfspeed_on; //list with 50..2000ms in steps of 10 // 9f0 u8 dtmfspeed_off; //list with 50..2000ms in steps of 10 // 9f1 @@ -5358,7 +5362,7 @@ struct { COLOR20V2_MEM_FORMAT = """ -#seekto 0x0000; +// #seekto 0x0000; struct { lbcd rxfreq[4]; lbcd txfreq[4]; @@ -5503,7 +5507,7 @@ struct { struct settings_vfo d; } vfo; -#seekto 0x0F80; +// #seekto 0x0F80; struct { char line1[8]; char line2[8]; @@ -5542,7 +5546,7 @@ struct { u8 standard; // one out of LIST_5TONE_STANDARDS } _5tone_codes[15]; -#seekto 0x25F0; +// #seekto 0x25F0; struct { u8 _5tone_delay1; // * 10ms u8 _5tone_delay2; // * 10ms @@ -5569,7 +5573,7 @@ struct { u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B } dtmf_codes[15]; -#seekto 0x29F0; +// #seekto 0x29F0; struct { u8 dtmfspeed_on; //list with 50..2000ms in steps of 10 // 9f0 u8 dtmfspeed_off; //list with 50..2000ms in steps of 10 // 9f1 diff --git a/chirp/drivers/fd268.py b/chirp/drivers/fd268.py index 5d73d5f..95a114b 100644 --- a/chirp/drivers/fd268.py +++ b/chirp/drivers/fd268.py @@ -379,7 +379,7 @@ class FeidaxinFD2x8yRadio(chirp_common.CloneModeRadio): def _decode_tone(self, val): """Parse the tone data to decode from mem, it returns""" - if val.get_raw() == "\xFF\xFF": + if val.get_raw(asbytes=False) == "\xFF\xFF": return '', None, None val = int(val) @@ -418,7 +418,7 @@ class FeidaxinFD2x8yRadio(chirp_common.CloneModeRadio): mem.number = number # empty - if _mem.get_raw()[0] == "\xFF": + if _mem.get_raw(asbytes=False)[0] == "\xFF": mem.empty = True return mem @@ -427,7 +427,7 @@ class FeidaxinFD2x8yRadio(chirp_common.CloneModeRadio): # checking if tx freq is empty, this is "possible" on the # original soft after a warning, and radio is happy with it - if _mem.tx_freq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.tx_freq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.duplex = "off" mem.offset = 0 else: @@ -448,11 +448,11 @@ class FeidaxinFD2x8yRadio(chirp_common.CloneModeRadio): # Extra setting group, FD-268 don't uset it at all # FD-288's & others do it? mem.extra = RadioSettingGroup("extra", "Extra") - busy = RadioSetting("Busy", "Busy Channel Lockout", + busy = RadioSetting("busy_lock", "Busy Channel Lockout", RadioSettingValueBoolean( bool(_mem.busy_lock))) mem.extra.append(busy) - scramble = RadioSetting("Scrambler", "Scrambler Option", + scramble = RadioSetting("scrambler", "Scrambler Option", RadioSettingValueBoolean( bool(_mem.scrambler))) mem.extra.append(scramble) @@ -567,7 +567,7 @@ class FeidaxinFD2x8yRadio(chirp_common.CloneModeRadio): work.append(active_ch) # vfo rx validation - if _mem.vfo.vrx_freq.get_raw()[0] == "\xFF": + if _mem.vfo.vrx_freq.get_raw(asbytes=False)[0] == "\xFF": # if the vfo is not set, the UI cares about the # length of the field, so set a default LOG.debug("Setting VFO to default %s" % self._VFO_DEFAULT) @@ -601,7 +601,7 @@ class FeidaxinFD2x8yRadio(chirp_common.CloneModeRadio): work.append(shift) # vfo shift validation if none set it to ZERO - if _mem.settings.vfo_shift.get_raw()[0] == "\xFF": + if _mem.settings.vfo_shift.get_raw(asbytes=False)[0] == "\xFF": # if the shift is not set, the UI cares about the # length of the field, so set to zero LOG.debug("VFO shift not set, setting it to zero") diff --git a/chirp/drivers/ft1d.py b/chirp/drivers/ft1d.py index 1cd77c6..f50ed1f 100644 --- a/chirp/drivers/ft1d.py +++ b/chirp/drivers/ft1d.py @@ -49,7 +49,7 @@ struct { u8 lcd_dimmer; // 14 DIMMER u8 dtmf_delay; // 18 DT DLY u8 unknown0[3]; - u8 unknown1:4 + u8 unknown1:4, lcd_contrast:4; u8 lamp; // 28 LAMP u8 lock; // 30 LOCK @@ -76,7 +76,7 @@ struct { u8 busy_led:1, unknown9:2, bclo:1, // 03 BCLO - beep_edge:1 // 06 BEP.EDG + beep_edge:1, // 06 BEP.EDG unknown9_1:3; u8 unknown10:5, password:1, @@ -248,7 +248,7 @@ struct { u8 unknown7:1, aprs_units_wind_mph:1, aprs_units_rain_inch:1, - aprs_units_temperature_f:1 + aprs_units_temperature_f:1, aprs_units_altitude_ft:1, unknown8:1, aprs_units_distance_m:1, @@ -2358,7 +2358,7 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): ssid = int(ssid) % 16 except ValueError: ssid = default_ssid - setattr(obj, "callsign", cls._add_ff_pad(callsign, 6)) + setattr(obj, "callsign", cls._add_ff_pad(callsign.encode(), 6)) if ssid is not None: setattr(obj, "ssid", ssid) diff --git a/chirp/drivers/ft2800.py b/chirp/drivers/ft2800.py index 16dd752..05a7af5 100644 --- a/chirp/drivers/ft2800.py +++ b/chirp/drivers/ft2800.py @@ -286,7 +286,7 @@ class FT2800Radio(YaesuCloneModeRadio): mem.number = number - if _mem.get_raw()[0] == "\xFF": + if _mem.get_raw(asbytes=False)[0] == "\xFF": mem.empty = True return mem @@ -311,10 +311,16 @@ class FT2800Radio(YaesuCloneModeRadio): _mem.set_raw("\xFF" * (_mem.size() // 8)) return - if _mem.get_raw()[0] == "\xFF": + if _mem.get_raw(asbytes=False)[0] == "\xFF": # Empty -> Non-empty, so initialize _mem.set_raw("\x00" * (_mem.size() // 8)) + # initializing unknowns + _mem.unknown1 = (0xFF, 0xFF, 0xFF, 0xFF) + _mem.unknown2 = (0x00, 0x00) + _mem.unknown3 = 0x01 + _mem.unknown4 = 0x3C + _mem.freq = mem.freq / 10 _mem.offset = mem.offset / 100000 _mem.duplex = DUPLEX.index(mem.duplex) diff --git a/chirp/drivers/ft2900.py b/chirp/drivers/ft2900.py index 5ef6a67..1279317 100644 --- a/chirp/drivers/ft2900.py +++ b/chirp/drivers/ft2900.py @@ -212,7 +212,7 @@ struct { unk:2, dtmf_mode:1; u8 unk:1, - ts_mut:1 + ts_mut:1, wires_auto:1, busy_lockout:1, edge_beep:1, @@ -572,7 +572,7 @@ class FT2900Radio(YaesuCloneModeRadio): mem.number = number - if _mem.get_raw()[0] == "\xFF" or not valid or not used: + if _mem.get_raw(asbytes=False)[0] == "\xFF" or not valid or not used: mem.empty = True return mem @@ -710,7 +710,8 @@ class FT2900Radio(YaesuCloneModeRadio): _mem.unknown4 = 0 _mem.unknown5 = 0 - LOG.debug("encoded mem\n%s\n" % (util.hexprint(_mem.get_raw()[0:20]))) + LOG.debug("encoded mem\n%s\n" % (util.hexprint( + _mem.get_raw(asbytes=False)[0:20]))) def get_settings(self): _settings = self._memobj.settings diff --git a/chirp/drivers/ft4.py b/chirp/drivers/ft4.py index cb3f8d4..418f358 100644 --- a/chirp/drivers/ft4.py +++ b/chirp/drivers/ft4.py @@ -246,7 +246,7 @@ def variable_len_resp(pipe): return response -def sendcmd(pipe, cmd, response_len): +def sendcmd(pipe, cmd, response_len, retry=0): """ send a command bytelist to radio,receive and return the resulting bytelist. Input: pipe - serial port object to use @@ -274,8 +274,13 @@ def sendcmd(pipe, cmd, response_len): response = b"" ack = pipe.read(1) if ack != b'\x06': - LOG.debug("missing ack: expected 0x06, got" + util.hexprint(ack)) - raise errors.RadioError("Incorrect ACK on serial port.") + if retry < 5: + LOG.debug("retry: " + str(retry)) + retry += 1 + return sendcmd(pipe, cmd, response_len, retry) + else: + LOG.debug("missing ack: expected 0x06, got" + util.hexprint(ack)) + raise errors.RadioError("Incorrect ACK on serial port.") return response diff --git a/chirp/drivers/ft450d.py b/chirp/drivers/ft450d.py index 9f3fa05..43c6407 100644 --- a/chirp/drivers/ft450d.py +++ b/chirp/drivers/ft450d.py @@ -26,11 +26,14 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ import time import struct import logging +import itertools LOG = logging.getLogger(__name__) CMD_ACK = b'\x06' -EX_MODES = ["USER-L", "USER-U", "LSB+CW", "USB+CW", "RTTY-L", "RTTY-U", "N/A"] +# can't update chirp_common data modes for this radio, so for wierd +# data modes with will use main mode of DIG and then have these sub-modes +DATA_MODES = ["USER-L", "USER-U", "RTTY", "N/A"] T_STEPS = sorted(list(chirp_common.TUNING_STEPS)) T_STEPS.remove(30.0) T_STEPS.remove(100.0) @@ -38,9 +41,48 @@ T_STEPS.remove(125.0) T_STEPS.remove(200.0) +def filters_for_mode(mode): + if mode in ("USB", "LSB"): + return "sb_width", ["1.8 kHz", "2.4 kHz", "3.0 kHz"] + elif mode in ("CW", "CWR"): + return "cw_width", ["300 Hz", "500 kHz", "2.4 kHz"] + elif mode == "DIG": + return "sb_width", ["300 Hz", "2.4 kHz", "3.0 kHz"] + elif mode == "AM": + return "am_width", ["3.0 kHz", "6.0 kHz", "9.0 kHz"] + elif mode in ("NFM", "FM"): + return "fm_width", ["2.5 kHz", "5.0 kHz"] + else: + raise ValueError("Internal error: unknown mode %s" % mode) + + +def filter_to_hz(item): + mag, units = item.split(' ') + return float(mag) * (1000 if units == 'kHz' else 1) + + +def all_filters(): + options = list(itertools.chain.from_iterable( + filterlist for k, filterlist in [ + filters_for_mode('CW'), filters_for_mode('USB'), + filters_for_mode('DIG'), filters_for_mode('FM'), + filters_for_mode('AM')])) + return sorted(set(options), key=filter_to_hz) + + +def closest_filter(options, value): + value = filter_to_hz(value) + dists = [abs(value - filter_to_hz(o)) for o in options] + closest = options[dists.index(min(dists))] + LOG.debug('Chose %s as closest filter to %s from %s', + closest, value, ','.join(options)) + return closest + + @directory.register class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): """Yaesu FT-450D""" + FT450 = False BAUD_RATE = 38400 COM_BITS = 8 # number of data bits COM_PRTY = 'N' # parity checking @@ -49,8 +91,8 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): NEEDS_COMPAT_SERIAL = False DUPLEX = ["", "-", "+"] - MODES = ["LSB", "USB", "CW", "AM", "FM", "RTTY-L", - "USER-L", "USER-U", "NFM", "CWR"] + MODES = ["LSB", "USB", "CW", "AM", "FM", "DIG", + "NFM", "CWR"] TMODES = ["", "Tone", "TSQL"] STEPSFM = [5.0, 6.25, 10.0, 12.5, 15.0, 20.0, 25.0, 50.0] STEPSAM = [2.5, 5.0, 9.0, 10.0, 12.5, 25.0] @@ -92,7 +134,7 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): u8 tunerok:1, // @ Byte 4 ?? Poss tuned ok cnturon:1, unk4b:1, - dnr_on:1 + dnr_on:1, notch:1, unk4c:1, tmode:2; // Tone/Cross/etc as Off/Enc/Enc+Dec @@ -112,6 +154,9 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): u8 name[7]; // @ 14-1A }; + struct model{ + u8 modname[4]; + }; #seekto 0x04; struct { u8 set04; // ?Checksum / Clone counter? @@ -146,7 +191,7 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): set0ea:1, amfmdial:1, // 0= Enabled. 1 = Disabled cwpitch:3; // 0-based index - u8 sql_rfg:1 + u8 sql_rfg:1, set0F:2, cwweigt:5; // Index 1:2.5=0 -> 1:4.5=20 u8 cw_dly; // @x10 ms = val * 10 @@ -157,8 +202,8 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): emergen:1, vox_dly:5; // ms = val * 100 u8 set15a:1, - stby_beep:1 - set15b:1 + stby_beep:1, + set15b:1, mem_grp:1, apo:4; u8 tot; // Byte x16, 1:1 @@ -190,7 +235,7 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): cat_tot:2; // Index 0-3 u8 set2CA:2, rtyrpol:1, - rtytpol:1 + rtytpol:1, rty_sft:2, rty_ton:1, set2CC:1; @@ -369,7 +414,7 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): def get_prompts(cls): rp = chirp_common.RadioPrompts() rp.info = _( - "The FT-450 radio driver loads the 'Special Channels' tab\n" + "The FT-450D radio driver loads the 'Special Channels' tab\n" "with the PMS scanning range memories (group 11), 60meter\n" "channels (group 12), the QMB (STO/RCL) memory, the HF and\n" "50m HOME memories and all the A and B VFO memories.\n" @@ -379,7 +424,9 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): "This driver also populates the 'Other' tab in the channel\n" "memory Properties window. This tab contains values for\n" "those channel memory settings that don't fall under the\n" - "standard Chirp display columns.\n") + "standard Chirp display columns. With FT450 support, the gui now\n" + "uses the mode 'DIG' to represent data modes and a new column\n" + "'DATA MODE' to select USER-U, USER-L and RTTY \n") rp.pre_download = _( "1. Turn radio off.\n" "2. Connect cable to ACC jack.\n" @@ -420,7 +467,26 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): checksum.get_calculated(data), blocknum)) # Remove the block number and checksum data = data[1:block + 1] - else: # Use this info to decode a new Yaesu model + elif self.FT450: + # unique FT450 (and 450AT?) vs D, only 2 bytes in first block + if blocknum == 0 and len(data) == 4: + checksum = yaesu_clone.YaesuChecksum(1, block - 2) + if checksum.get_existing(data) != \ + checksum.get_calculated(data): + raise Exception("Checksum Failed [%02X<>%02X] block %02X" % + (checksum.get_existing(data), + checksum.get_calculated(data), blocknum)) + # Remove the block number and checksum + data = data[1:block - 2 + 1] + # pad the data to the correct 450d size + data += b" " + else: + # FT450, but bad block + raise Exception("Unable to read block %i expected %i got %i" + % (blocknum, block + 2, len(data))) + else: + # Use this info to decode a new Yaesu model + # Not an old FT450 or 450AT raise Exception("Unable to read block %i expected %i got %i" % (blocknum, block + 2, len(data))) return data @@ -477,10 +543,18 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): repeat = 1 for _i in range(0, repeat): time.sleep(0.01) - checksum = yaesu_clone.YaesuChecksum(pos, pos + block - 1) + # If this is a 450 model, we need to send just the first two model bytes + # in block 0 and just checksum that part + if self.FT450 and blocks == 0: + checksum = yaesu_clone.YaesuChecksum(pos, pos + block - 2 - 1) + else: + checksum = yaesu_clone.YaesuChecksum(pos, pos + block - 1) LOG.debug("Sending block %s" % hex(blocks)) self.pipe.write(struct.pack('B', blocks)) - blkdat = self.get_mmap()[pos:pos + block] + if self.FT450 and blocks == 0: + blkdat = self.get_mmap()[pos:pos + block - 2] + else: + blkdat = self.get_mmap()[pos:pos + block] LOG.debug("Sending %d bytes:\n%s" % (len(blkdat), util.hexprint(blkdat))) self.pipe.write(blkdat) @@ -562,6 +636,13 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): return self._get_normal(number) def set_memory(self, memory): + # If this is called due to a delete request on the gui, + # then the memory passed might be passed as a str, + # since the special memories have string tags on the GUI and not + # numbers. Convert these back to the int for the specials + if isinstance(memory.number, str): + memory.number = self.SPECIAL_MEMORIES[memory.number] + return self._set_special(memory) if memory.number < 0: return self._set_special(memory) else: @@ -593,9 +674,21 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): _mem = self._memobj.mtune immutable = ["number", "extd_number", "name", "power"] elif mem.number in self.SPECIAL_PMS.values(): - bitindex = (-self.LAST_PMS_INDEX) + mem.number - used = (self._memobj.pmsvisible >> bitindex) & 0x01 - valid = (self._memobj.pmsfilled >> bitindex) & 0x01 + # ft450 does NOT use the pmsvisible or pmsfilled fields, + # it uses the next 4 bits after the 500 normal memories + # in the main visible and filled settings area. + if self.FT450: + pmsnum = 501 + (-self.LAST_PMS_INDEX) + mem.number + used = (self._memobj.visible[(pmsnum - 1) // 8] >> \ + (pmsnum - 1) % 8) & 0x01 + valid = (self._memobj.filled[(pmsnum - 1) // 8] >> \ + (pmsnum - 1) % 8) & 0x01 + else: + bitindex = (-self.LAST_PMS_INDEX) + mem.number + used = (self._memobj.pmsvisible >> bitindex) & 0x01 + valid = (self._memobj.pmsfilled >> bitindex) & 0x01 + # You can clear the PMS memories on the FT450 + # using the CLAR button and then they do not display. if not used: mem.empty = True if not valid: @@ -625,7 +718,7 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): def _set_special(self, mem): if mem.empty and mem.number not in self.SPECIAL_PMS.values(): - # can't delete special memories! + # can't delete special memories! But can delete PMS mems raise errors.RadioError("Sorry, special memory can't be deleted") cur_mem = self._get_special(self.SPECIAL_MEMORIES_REV[mem.number]) @@ -645,22 +738,44 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): elif mem.number == -1: _mem = self._memobj.mtune elif mem.number in self.SPECIAL_PMS.values(): - bitindex = (-self.LAST_PMS_INDEX) + mem.number - wasused = (self._memobj.pmsvisible >> bitindex) & 0x01 - wasvalid = (self._memobj.pmsfilled >> bitindex) & 0x01 - if mem.empty: - if wasvalid and not wasused: + # ft450 does NOT use the pmsvisible or pmsfilled fields, + # it uses the next 4 bits after the 500 normal memories + # in the main visible and filled settings area. + if self.FT450: + pmsnum = 501 + (-self.LAST_PMS_INDEX) + mem.number + wasused = (self._memobj.visible[(pmsnum - 1) // 8] >> + (pmsnum - 1) % 8) & 0x01 + wasvalid = (self._memobj.filled[(pmsnum - 1) // 8] >> + (pmsnum - 1) % 8) & 0x01 + if mem.empty: + if wasvalid and not wasused: + self._memobj.filled[(pmsnum - 1) // 8] &= \ + ~(1 << (pmsnum - 1) % 8) + self._memobj.visible[(pmsnum - 1) // 8] &= \ + ~(1 << (pmsnum - 1) % 8) + return + self._memobj.visible[(pmsnum - 1) // 8] |= 1 << (pmsnum - 1) \ + % 8 + self._memobj.filled[(pmsnum - 1) // 8] |= 1 << (pmsnum - 1) \ + % 8 + _mem = self._memobj.pms[-self.LAST_PMS_INDEX + mem.number] + else: #self.FT450 + bitindex = (-self.LAST_PMS_INDEX) + mem.number + wasused = (self._memobj.pmsvisible >> bitindex) & 0x01 + wasvalid = (self._memobj.pmsfilled >> bitindex) & 0x01 + if mem.empty: + if wasvalid and not wasused: + # pylint get confused by &= operator + self._memobj.pmsfilled = self._memobj.pmsfilled & \ + ~ (1 << bitindex) # pylint get confused by &= operator - self._memobj.pmsfilled = self._memobj.pmsfilled & \ + self._memobj.pmsvisible = self._memobj.pmsvisible & \ ~ (1 << bitindex) - # pylint get confused by &= operator - self._memobj.pmsvisible = self._memobj.pmsvisible & \ - ~ (1 << bitindex) - return - # pylint get confused by |= operator - self._memobj.pmsvisible = self._memobj.pmsvisible | 1 << bitindex - self._memobj.pmsfilled = self._memobj.pmsfilled | 1 << bitindex - _mem = self._memobj.pms[-self.LAST_PMS_INDEX + mem.number] + return + # pylint get confused by |= operator + self._memobj.pmsvisible = self._memobj.pmsvisible | 1 << bitindex + self._memobj.pmsfilled = self._memobj.pmsfilled | 1 << bitindex + _mem = self._memobj.pms[-self.LAST_PMS_INDEX + mem.number] else: raise errors.RadioError("Sorry, you can't edit" " that special memory.") @@ -670,14 +785,13 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): if cur_mem.__dict__[key] != mem.__dict__[key]: raise errors.RadioError("Editing field `%s' " % key + "is not supported on this channel") - self._set_memory(mem, _mem) def _get_normal(self, number): _mem = self._memobj.memory[number - 1] - used = (self._memobj.visible[(number - 1) / 8] >> (number - 1) % 8) \ + used = (self._memobj.visible[(number - 1) // 8] >> (number - 1) % 8) \ & 0x01 - valid = (self._memobj.filled[(number - 1) / 8] >> (number - 1) % 8) \ + valid = (self._memobj.filled[(number - 1) // 8] >> (number - 1) % 8) \ & 0x01 mem = chirp_common.Memory() @@ -692,9 +806,9 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): def _set_normal(self, mem): _mem = self._memobj.memory[mem.number - 1] - wasused = (self._memobj.visible[(mem.number - 1) / 8] >> + wasused = (self._memobj.visible[(mem.number - 1) // 8] >> (mem.number - 1) % 8) & 0x01 - wasvalid = (self._memobj.filled[(mem.number - 1) / 8] >> + wasvalid = (self._memobj.filled[(mem.number - 1) // 8] >> (mem.number - 1) % 8) & 0x01 if mem.empty: @@ -721,21 +835,62 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): mem.offset = int(_mem.offset) mem.duplex = self.DUPLEX[_mem.duplex] # Mode gets tricky with dual (USB+DATA) options + # WDC on FT450, the high bit of the nybble really + # means something else, but I don't know + # what it is. IE Sometimes LSB comes in as 1, sometime 8... vx = _mem.mode - if vx == 4: # FM or NFM - if _mem.mode2 == 2: - vx = 4 # FM - else: - vx = 8 # NFM - if vx == 10: # CWR - vx = 9 - if vx == 5: # Data/Dual mode - if _mem.mode2 == 0: # RTTY-L - vx = 5 - if _mem.mode2 == 1: # USER-L + vx_data = 3 # Assume N/A unless reset below + if vx == 0: # LSB + pass + elif vx == 1: # USB + pass + elif vx == 2: # USB CW (CW) + pass + elif vx == 3: # AM + pass + elif vx == 4: # FM/NFM + if _mem.mode2 == 1: vx = 6 - if _mem.mode2 == 2: # USER-U - vx = 7 + else: + vx = 4 + pass + elif vx == 5: # USER\L + # This looks different from FT450D + if self.FT450: + vx = 5 # set to new "DIG" + vx_data = 1 + else: + # on 450D only 5 used for dig modes, no 13 + if _mem.mode2 == 0: # RTTY + vx = 5 # Set to new "DIG" + vx_data = 2 # RTTY + elif _mem.mode2 == 1: # USER-L + vx = 5 # set to new "DIG" + vx_data = 0 + elif _mem.mode2 == 2: # USER-U variant + vx = 5 # Set to new "DIG" + vx_data = 1 # USER-U with Split? + elif vx == 8: # LSB + vx = 0 + elif vx == 9: # USB + vx = 1 + elif vx == 10: # LSB CW (CWR) + vx = 7 # CWR + elif vx == 13: + if _mem.mode2 == 0: # RTTY + vx = 5 # Set to new "DIG" + vx_data = 2 # RTTY + elif _mem.mode2 == 1: # USER-L + vx = 5 # set to new "DIG" + vx_data = 0 + elif _mem.mode2 == 2: # USER-U variant + vx = 5 # Set to new "DIG" + vx_data = 1 # USER-U with Split? + else: + LOG.error("unknown combo of mem.mode 13 and mem mode 2: %s %s", + vx,_mem.mode2) + else: + LOG.error("unknown _mem.mode value : %s", vx) try: mem.mode = self.MODES[vx] except ValueError: @@ -770,6 +925,14 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): mem.extra = RadioSettingGroup("extra", "Extra") + # add a new field to handle the new sub-modes if dig + options = DATA_MODES + rs = RadioSetting("data_modes", "DATA MODE", + RadioSettingValueList(options, + options[vx_data])) + rs.set_doc("Extended Data Modes") + mem.extra.append(rs) + rs = RadioSetting("ipo", "IPO", RadioSettingValueBoolean(bool(_mem.ipo))) rs.set_doc("Bypass preamp") @@ -821,29 +984,10 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): rs.set_doc("IF bandpass filter shift") mem.extra.append(rs) - vx = 0 - if mem.mode[1:] == "SB": - options = ["1.8 kHz", "2.4 kHz", "3.0 kHz"] - vx = _mem.sb_width - stx = "sb_width" - elif mem.mode[:1] == "CW": - options = ["300 Hz", "500 kHz", "2.4 kHz"] - vx = _mem.cw_width - stx = "cw_width" - elif mem.mode[:4] == "USER" or mem.mode[:4] == "RTTY": - options = ["300 Hz", "2.4 kHz", "3.0 kHz"] - vx = _mem.sb_width - stx = "sb_width" - elif mem.mode == "AM": - options = ["3.0 kHz", "6.0 kHz", "9.0 kHz"] - vx = _mem.am_width - stx = "am_width" - else: - options = ["2.5 kHz", "5.0 kHz"] - vx = _mem.fm_width - stx = "fm_width" - rs = RadioSetting(stx, "IF Bandpass Filter Width", - RadioSettingValueList(options, options[vx])) + stx, options = filters_for_mode(mem.mode) + vx = getattr(_mem, stx) + rs = RadioSetting("bpfilter", "IF Bandpass Filter Width", + RadioSettingValueList(all_filters(), options[vx])) rs.set_doc("DSP IF bandpass Notch width (Hz)") mem.extra.append(rs) @@ -869,28 +1013,49 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): _mem.tag_on_off = 1 self._set_duplex(mem, _mem) _mem.mode2 = 0 - if mem.mode == "USER-L": - _mem.mode = 5 - _mem.mode2 = 1 - elif mem.mode == "USER-U": - _mem.mode = 5 - _mem.mode2 = 2 - elif mem.mode == "RTTY-L": - _mem.mode = 5 - _mem.mode2 = 0 - elif mem.mode == "CWR": + tmpmemmode = str(mem.mode) + if mem.mode == "DIG": + _mem.mode = 5 # We'll set _mode2 from extra data_modes + elif tmpmemmode == "CWR": _mem.mode = 10 - _mem.mode2 = 0 - elif mem.mode == "CW": + # 450 looks different + if self.FT450: + _mem.mode2 = 2 + else: + _mem.mode2 = 0 + elif tmpmemmode == "CW": _mem.mode = 2 - _mem.mode2 = 0 - elif mem.mode == "NFM": + # 450 looks different + if self.FT450: + _mem.mode2 = 2 + else: + _mem.mode2 = 0 + elif tmpmemmode == "NFM": _mem.mode = 4 _mem.mode2 = 1 - elif mem.mode == "FM": + elif tmpmemmode == "FM": _mem.mode = 4 _mem.mode2 = 2 - else: # LSB, USB, AM + elif tmpmemmode == "LSB": + _mem.mode = 0 + # 450 looks different + if self.FT450: + _mem.mode2 = 2 + else: + _mem.mode2 = 0 + elif tmpmemmode == "USB": + _mem.mode = 1 + if self.FT450: + _mem.mode2 = 2 + else: + _mem.mode2 = 0 + elif tmpmemmode == "AM": + _mem.mode = 3 + if self.FT450: + _mem.mode2 = 2 + else: + _mem.mode2 = 0 + else: # SHOULD NOT OCCUR _mem.mode = self.MODES.index(mem.mode) _mem.mode2 = 0 try: @@ -935,6 +1100,43 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): else: setattr(_mem, "dnr_on", 0) setattr(_mem, setting.get_name(), vx) + elif setting.get_name() == "data_modes": + if tmpmemmode == "DIG": + stx = str(setting.value) + if stx == "USER-L": + if self.FT450: + _mem.mode = 13 + _mem.mode2 = 1 + else: + _mem.mode = 5 + _mem.mode2 = 1 + elif stx == "USER-U": + _mem.mode = 5 + _mem.mode2 = 2 + elif stx == "RTTY": + if self.FT450: + _mem.mode = 13 + _mem.mode2 = 0 + else: + _mem.mode = 5 + _mem.mode2 = 0 + elif stx == "N/A": + _mem.mode = 5 + _mem.mode2 = 2 + else: + LOG.error("In _set_memory invalid digital data type %s", stx) + elif setting.get_name() == "bpfilter": + element, options = filters_for_mode(mem.mode) + if str(setting.value) in options: + setattr(_mem, element, options.index(str(setting.value))) + else: + default = closest_filter(options, str(setting.value)) + LOG.warning('Memory specified filter width of %s for ' + 'mode %s which is not in allowed list of ' + '%s. Defaulting to %s', + str(setting.value), mem.mode, + ','.join(options), default) + setattr(_mem, element, options.index(default)) else: setattr(_mem, setting.get_name(), setting.value) @@ -1262,10 +1464,21 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): RadioSettingValueBoolean(_settings.nb)) pnlcfg.append(rs) - options = ["Auto", "Fast", "Slow", "Auto/Fast", "Auto/Slow", "?5?"] - rs = RadioSetting("agc", "AGC", - RadioSettingValueList(options, - options[_settings.agc])) + # The old FT450 uses different codes for the AGC setting, and only uses the + # last 3 bits of the AGC definition. The two upper bits appear to always be x"11" + # We will mask this in the routine that processes the agc value + if self.FT450: + options = ["Auto", "Fast", "Slow", "UNK3", "UNK4", "UNK5", "OFF", "UNK7"] + # mask off the two upper bits of the agc settings value + FT450agc = _settings.agc & int('0x7',16) + rs = RadioSetting("agc", "AGC", + RadioSettingValueList(options, + options[FT450agc])) + else: + options = ["Auto", "Fast", "Slow", "Auto/Fast", "Auto/Slow", "?5?"] + rs = RadioSetting("agc", "AGC", + RadioSettingValueList(options, + options[_settings.agc])) pnlcfg.append(rs) rs = RadioSetting("keyer", "Keyer", @@ -1489,3 +1702,27 @@ class FT450DRadio(yaesu_clone.YaesuCloneModeRadio): except Exception: LOG.debug(element.get_name()) raise + + def validate_memory(self, mem): + msgs = super().validate_memory(mem) + if 'bpfilter' in mem.extra: + _, options = filters_for_mode(mem.mode) + bpfilter = str(mem.extra['bpfilter'].value) + if bpfilter not in options: + msgs.append(chirp_common.ValidationWarning( + ('Filter width %s is not allowed for mode %s - ' + 'the closest suitable option %s will be used') % ( + bpfilter, mem.mode, + closest_filter(options, bpfilter)))) + return msgs + + +@directory.register +class FT450Radio(FT450DRadio): + """Yaesu FT-450""" + FT450 = True + MODEL = "FT-450" + + @classmethod + def match_model(cls, filedata, filename): + return False diff --git a/chirp/drivers/ft60.py b/chirp/drivers/ft60.py index a1bc2ee..4e4c9bb 100644 --- a/chirp/drivers/ft60.py +++ b/chirp/drivers/ft60.py @@ -194,7 +194,7 @@ struct { x3B_6:2; u8 x3C_0:2, rev_hm:1, - mt_cl:1 + mt_cl:1, resume:2, txsave:1, pag_abk:1; @@ -235,7 +235,7 @@ struct mem { u8 unknown4:1, dtcs:7; u8 unknown5; - u16 unknown5_1:1 + u16 unknown5_1:1, offset:15; u8 unknown6[3]; }; diff --git a/chirp/drivers/ft7100.py b/chirp/drivers/ft7100.py index 9336138..7c6f67c 100644 --- a/chirp/drivers/ft7100.py +++ b/chirp/drivers/ft7100.py @@ -178,7 +178,7 @@ struct mem { u8 dtcs_index; u8 is_mode_am:1, unknown71:2, - is_packet96:1 + is_packet96:1, unknown72:2, power_index:2; u8 unknown81:2, @@ -771,7 +771,8 @@ class FT7100Radio(YaesuCloneModeRadio): else: setattr(_mem, setting.get_name(), setting.value) - LOG.debug("encoded mem\n%s\n", (util.hexprint(_mem.get_raw()[0:25]))) + LOG.debug("encoded mem\n%s\n", + (util.hexprint(_mem.get_raw(asbytes=False)[0:25]))) LOG.debug(repr(_mem)) def get_settings(self): @@ -839,7 +840,7 @@ class FT7100Radio(YaesuCloneModeRadio): RadioSettingValueList(opts, opts[_overlay.cwid]))) # 6 Callsign during ARTS operation. - cwidw = _overlay.cwidw.get_raw() + cwidw = _overlay.cwidw.get_raw(asbytes=False) cwidw = cwidw.rstrip('\x00') val = RadioSettingValueString(0, 6, cwidw) val.set_charset(CHARSET) diff --git a/chirp/drivers/ft7800.py b/chirp/drivers/ft7800.py index 87db278..69b945a 100644 --- a/chirp/drivers/ft7800.py +++ b/chirp/drivers/ft7800.py @@ -30,6 +30,27 @@ LOG = logging.getLogger(__name__) ACK = b'\x06' MEM_FORMAT = """ +struct mem_struct { + u8 used:1, + unknown1:1, + mode:2, + unknown2:1, + duplex:3; + bbcd freq[3]; + u8 clockshift:1, + tune_step:3, + unknown5:1, // TODO: tmode has extended settings, at least 4 bits + tmode:3; + bbcd split[3]; + u8 power:2, + tone:6; + u8 unknown6:1, + dtcs:7; + u8 unknown7[2]; + u8 offset; + u8 unknown9[3]; +}; + #seekto 0x002A; u8 banks_unk2; u8 current_channel; @@ -37,14 +58,6 @@ u8 unk3; u8 unk4; u8 current_menu; -#seekto 0x0035; -u8 banks_unk1; - -#seekto 0x00C8; -struct { - u8 memory[16]; -} dtmf[16]; - #seekto 0x003A; struct { u8 apo; @@ -86,30 +99,14 @@ struct { u8 unk6; } settings; -struct mem_struct { - u8 used:1, - unknown1:1, - mode:2, - unknown2:1, - duplex:3; - bbcd freq[3]; - u8 clockshift:1, - tune_step:3, - unknown5:1, // TODO: tmode has extended settings, at least 4 bits - tmode:3; - bbcd split[3]; - u8 power:2, - tone:6; - u8 unknown6:1, - dtcs:7; - u8 unknown7[2]; - u8 offset; - u8 unknown9[3]; -}; - #seekto 0x0048; struct mem_struct vfos[5]; +#seekto 0x00C8; +struct { + u8 memory[16]; +} dtmf[16]; + #seekto 0x01C8; struct mem_struct homes[5]; @@ -533,7 +530,9 @@ class FT7800Radio(FTx800Radio): TMODES = ["", "Tone", "TSQL", "TSQL-R", "DTCS"] def get_bank_model(self): - return FT7800BankModel(self) + if not hasattr(self, '_banks'): + self._banks = FT7800BankModel(self) + return self._banks def get_features(self): rf = FTx800Radio.get_features(self) @@ -793,6 +792,11 @@ struct { u8 name[6]; } memory[500]; +#seekto 0x%X; +struct { + u32 bitmap[16]; +} bank_channels[10]; + #seekto 0x51C8; struct { u8 skip0:2, @@ -801,12 +805,6 @@ struct { skip3:2; } flags[250]; -#seekto 0x%X; -struct { - u32 bitmap[16]; -} bank_channels[10]; - - #seekto 0x7B48; u8 checksum; """ @@ -868,7 +866,9 @@ class FT8800Radio(FTx800Radio): return [FT8800RadioLeft(self._mmap), FT8800RadioRight(self._mmap)] def get_bank_model(self): - return FT8800BankModel(self) + if not hasattr(self, '_banks'): + self._banks = FT8800BankModel(self) + return self._banks def _checksums(self): return [yaesu_clone.YaesuChecksum(0x0000, 0x56C7)] diff --git a/chirp/drivers/ft857.py b/chirp/drivers/ft857.py index 7b6a96c..24a2b57 100644 --- a/chirp/drivers/ft857.py +++ b/chirp/drivers/ft857.py @@ -160,7 +160,7 @@ class FT857Radio(ft817.FT817Radio): ars_430:1, cw_weight:5; u8 cw_delay; - u8 cw_delay_hi:1 + u8 cw_delay_hi:1, cw_sidetone:7; u8 unknown10:2, cw_speed:6; diff --git a/chirp/drivers/ft90.py b/chirp/drivers/ft90.py index 00f7392..5aed9ff 100644 --- a/chirp/drivers/ft90.py +++ b/chirp/drivers/ft90.py @@ -135,7 +135,7 @@ struct mem_struct { step:3; u8 artsmode:2, unknown2:1, - isUhf2:1 + isUhf2:1, power:2, shift:2; u8 skip:1, diff --git a/chirp/drivers/ftm350.py b/chirp/drivers/ftm350.py index 5151351..e450890 100644 --- a/chirp/drivers/ftm350.py +++ b/chirp/drivers/ftm350.py @@ -84,7 +84,7 @@ struct lab right_label[518]; _TMODES = ["", "Tone", "TSQL", "-RVT", "DTCS", "-PR", "-PAG"] TMODES = ["", "Tone", "TSQL", "", "DTCS", "", ""] MODES = ["FM", "AM", "NFM", "", "WFM"] -DUPLEXES = ["", "", "-", "+", "split"] +DUPLEXES = ["", "", "-", "+", "split", "off"] # TODO: add Japanese characters (viewable in special menu, scroll backwards) CHARSET = \ ('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!"' + @@ -333,21 +333,25 @@ class FTM350Radio(yaesu_clone.YaesuCloneModeRadio): mem.empty = True return mem - mem.freq = get_freq(int(_mem.freq) * 10000) - mem.rtone = chirp_common.TONES[_mem.tone] - mem.tmode = TMODES[_mem.tmode] - - if _mem.oddsplit: + if _mem.offset == 0xFF: + # TX disabled + mem.duplex = "off" + elif _mem.oddsplit: mem.duplex = "split" mem.offset = get_freq(int(_mem.split) * 10000) else: mem.duplex = DUPLEXES[_mem.duplex] mem.offset = int(_mem.offset) * 50000 - mem.dtcs = chirp_common.DTCS_CODES[_mem.dtcs] + mem.freq = get_freq(int(_mem.freq) * 10000) + if mem.duplex != "off": + mem.rtone = chirp_common.TONES[_mem.tone] + mem.dtcs = chirp_common.DTCS_CODES[_mem.dtcs] + mem.power = POWER_LEVELS[_mem.power] + mem.tmode = TMODES[_mem.tmode] + mem.mode = MODES[_mem.mode] mem.skip = SKIPS[_mem.skip] - mem.power = POWER_LEVELS[_mem.power] for char in _lab.string: if char == 0xCA: @@ -373,20 +377,27 @@ class FTM350Radio(yaesu_clone.YaesuCloneModeRadio): return set_freq(mem.freq, _mem, 'freq') + + _mem.oddsplit = 0 _mem.tone = chirp_common.TONES.index(mem.rtone) _mem.dtcs = chirp_common.DTCS_CODES.index(mem.dtcs) _mem.tmode = TMODES.index(mem.tmode) - _mem.mode = MODES.index(mem.mode) - _mem.skip = SKIPS.index(mem.skip) - - _mem.oddsplit = 0 - _mem.duplex = 0 - if mem.duplex == "split": + _mem.duplex = DUPLEXES.index(mem.duplex) + if mem.duplex == "off": + _mem.tone = 0x3F + _mem.dtcs = 0x7F + _mem.offset = 0xFF + _mem.power = 0x03 + _mem.tmode = 0x00 + _mem.duplex = 0x00 + elif mem.duplex == "split": set_freq(mem.offset, _mem, 'split') _mem.oddsplit = 1 else: _mem.offset = mem.offset / 50000 - _mem.duplex = DUPLEXES.index(mem.duplex) + + _mem.mode = MODES.index(mem.mode) + _mem.skip = SKIPS.index(mem.skip) if mem.power: _mem.power = POWER_LEVELS.index(mem.power) diff --git a/chirp/drivers/ga510.py b/chirp/drivers/ga510.py index 27fffa1..58d9b05 100644 --- a/chirp/drivers/ga510.py +++ b/chirp/drivers/ga510.py @@ -18,7 +18,6 @@ import logging import struct -from chirp import bandplan_na from chirp import bitwise from chirp import chirp_common from chirp import directory @@ -493,7 +492,7 @@ class RadioddityGA510Radio(chirp_common.CloneModeRadio): def _is_txinh(self, _mem): raw_tx = "" for i in range(0, 4): - raw_tx += _mem.txfreq[i].get_raw() + raw_tx += _mem.txfreq[i].get_raw(asbytes=False) return raw_tx == "\xFF\xFF\xFF\xFF" def _get_mem(self, num): diff --git a/chirp/drivers/gmrsuv1.py b/chirp/drivers/gmrsuv1.py index 32f72fe..adbab72 100644 --- a/chirp/drivers/gmrsuv1.py +++ b/chirp/drivers/gmrsuv1.py @@ -165,7 +165,7 @@ class GMRSV1(baofeng_common.BaofengCommonHT): return rf MEM_FORMAT = """ - #seekto 0x0000; + // #seekto 0x0000; struct { lbcd rxfreq[4]; lbcd txfreq[4]; @@ -314,7 +314,7 @@ class GMRSV1(baofeng_common.BaofengCommonHT): sftd:2, scode:4; u8 unknown4; - u8 unused3:1 + u8 unused3:1, step:3, unused4:4; u8 txpower:1, @@ -413,13 +413,13 @@ class GMRSV1(baofeng_common.BaofengCommonHT): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw()[:1] == b"\xff": mem.empty = True return mem mem.freq = int(_mem.rxfreq) * 10 - if _mem.txfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.txfreq.get_raw() == b"\xFF\xFF\xFF\xFF": mem.duplex = "off" mem.offset = 0 elif int(_mem.rxfreq) == int(_mem.txfreq): diff --git a/chirp/drivers/gmrsv2.py b/chirp/drivers/gmrsv2.py index 71a4e43..06d6171 100644 --- a/chirp/drivers/gmrsv2.py +++ b/chirp/drivers/gmrsv2.py @@ -143,7 +143,7 @@ class GMRSV2base(baofeng_common.BaofengCommonHT): return rf MEM_FORMAT = """ - #seekto 0x0000; + // #seekto 0x0000; struct { lbcd rxfreq[4]; lbcd txfreq[4]; @@ -168,7 +168,7 @@ class GMRSV2base(baofeng_common.BaofengCommonHT): u8 unused[11]; } pttid[15]; - #seekto 0x0DF0; + // #seekto 0x0DF0; struct { u8 dtmfon; u8 dtmfoff; @@ -286,7 +286,7 @@ class GMRSV2base(baofeng_common.BaofengCommonHT): sftd:2, unused5:4; u8 unknown4; - u8 unused3:1 + u8 unused3:1, step:3, unused4:4; u8 txpower:1, @@ -385,7 +385,7 @@ class GMRSV2base(baofeng_common.BaofengCommonHT): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw()[:1] == b"\xff": mem.empty = True return mem @@ -1107,9 +1107,6 @@ class MURSV2(GMRSV2base): _msg_duplex = 'Duplex must be "off" for this frequency' _msg_offset = 'Only simplex or +5 MHz offset allowed on GMRS' - print('frequency') - print(mem.freq) - print(mem.freq in bandplan_na.ALL_MURS_FREQS) if mem.freq not in bandplan_na.ALL_MURS_FREQS: if mem.duplex != "off": msgs.append(chirp_common.ValidationWarning(_msg_duplex)) diff --git a/chirp/drivers/h777.py b/chirp/drivers/h777.py index f928447..b587221 100644 --- a/chirp/drivers/h777.py +++ b/chirp/drivers/h777.py @@ -291,7 +291,7 @@ class H777Radio(chirp_common.CloneModeRadio): # TODO: Is it 1 watt? POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=1.00), chirp_common.PowerLevel("High", watts=5.00)] - VALID_BANDS = (400000000, 470000000) + VALID_BANDS = (400000000, 490000000) MAX_VOXLEVEL = 5 ALIASES = [ArcshellAR5, ArcshellAR6, GV8SAlias, GV9SAlias, A8SAlias, TenwayTW325Alias, RetevisH777Alias] @@ -399,12 +399,12 @@ class H777Radio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem - if _mem.txfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.txfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.duplex = "off" mem.offset = 0 elif int(_mem.rxfreq) == int(_mem.txfreq): diff --git a/chirp/drivers/hg_uv98.py b/chirp/drivers/hg_uv98.py index 7b14ce1..b70273f 100644 --- a/chirp/drivers/hg_uv98.py +++ b/chirp/drivers/hg_uv98.py @@ -31,20 +31,7 @@ from chirp.settings import RadioSettings LOG = logging.getLogger(__name__) -# Gross hack to handle missing future module on un-updatable -# platforms like MacOS. Just avoid registering these radio -# classes for now. -try: - from builtins import bytes - has_future = True -except ImportError: - has_future = False - LOG.debug('python-future package is not ' - 'available; %s requires it' % __name__) - - MEM_FORMAT = """ -#seekto 0x0000; struct { lbcd rx_freq[4]; lbcd tx_freq[4]; @@ -217,10 +204,8 @@ def do_ident(radio): LOG.debug('ident string was %r' % ident) if ident != radio.IDENT: raise errors.RadioError( - "Incorrect model: {}, expected {!r}".format( - util.hexprint(ident), radio.IDENT, - ) - ) + "Incorrect model: %s, expected %r" % ( + util.hexprint(ident), radio.IDENT)) LOG.info("Model: %s (%s)" % (radio.MODEL, util.hexprint(ident))) radio.pipe.write(b"\x06") ack = radio.pipe.read(1) @@ -261,9 +246,6 @@ def do_upload(radio): do_ident(radio) mmap = radio._mmap - if callable(getattr(mmap, "get_byte_compatible", None)): - # for py3-CHIRP - mmap = mmap.get_byte_compatible() for addr in range(0, MAX_ADDR, CHUNK_SIZE): send(radio, make_frame(b"W", addr, CHUNK_SIZE, mmap[addr:addr + CHUNK_SIZE])) ack = radio.pipe.read(1) @@ -297,27 +279,22 @@ class RadioSettingValueChannel(RadioSettingValueList): current_mem = radio.get_memory(current) options = [ self._format_memory(mem) - for mem in [ - radio.get_memory(n) - for n in range(*radio.get_features().memory_bounds) - ] - ] - RadioSettingValueList.__init__( - self, - options, - self._format_memory(current_mem), - ) + for mem in [radio.get_memory(n) + for n in range(*radio.get_features().memory_bounds)]] + RadioSettingValueList.__init__(self, options, + self._format_memory(current_mem)) @staticmethod def _format_memory(m): if m.empty: return str(int(m.number)) - return "{} {:.4f} {}".format(int(m.number), m.freq / float(1e6), m.name) + return "%i %.4f %s" % (m.number, m.freq / 1e6, m.name) - def __trunc__(self): + def __int__(self): return int(self.get_value().partition(" ")[0]) +@directory.register class LanchonlhHG_UV98(chirp_common.CloneModeRadio, chirp_common.ExperimentalRadio): """ Lanchonlh HG-UV98 @@ -340,8 +317,7 @@ class LanchonlhHG_UV98(chirp_common.CloneModeRadio, chirp_common.ExperimentalRad "This Lanchonlh HG-UV98 driver is an alpha version. " "Proceed with Caution and backup your data. " "Always confirm the correctness of your settings with the " - "official programming tool." - ) + "official programming tool.") return rp def get_features(self): @@ -442,7 +418,7 @@ class LanchonlhHG_UV98(chirp_common.CloneModeRadio, chirp_common.ExperimentalRad mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[:4] == "\xFF\xFF\xFF\xFF": + if _mem.get_raw()[:4] == b"\xFF\xFF\xFF\xFF": mem.empty = True return mem @@ -450,7 +426,8 @@ class LanchonlhHG_UV98(chirp_common.CloneModeRadio, chirp_common.ExperimentalRad mem.name, mem.extd_number = SPECIAL_CHANNELS[mem.number] else: _name = self._memobj.name[number - 1] - mem.name, _, _ = _name.name.get_raw().partition("\xFF") + mem.name, _, _ = _name.name.get_raw().partition(b"\xFF") + mem.name = mem.name.decode('ascii') # XXX: other drivers rstrip the name and test_badname enforces this mem.name = mem.name.rstrip() mem.freq = int(_mem.rx_freq) * 10 @@ -519,7 +496,7 @@ class LanchonlhHG_UV98(chirp_common.CloneModeRadio, chirp_common.ExperimentalRad _mem = self._memobj.memory[mem.number - 1] if mem.empty: - _mem.set_raw("\xFF" * 16) + _mem.set_raw(b"\xFF" * 16) return if mem.number not in SPECIAL_CHANNELS: @@ -567,327 +544,187 @@ class LanchonlhHG_UV98(chirp_common.CloneModeRadio, chirp_common.ExperimentalRad top = RadioSettings(basic, display, scan, buttons, vfo, advanced, aprs) basic.append( - RadioSetting( - "save", - "Power Save", - RadioSettingValueBoolean(_settings.save), - ) - ) + RadioSetting("save", "Power Save", + RadioSettingValueBoolean(_settings.save))) basic.append( - RadioSetting( - "roger", - "Roger Beep", - RadioSettingValueList(ROGER_LIST, ROGER_LIST[_settings.roger]), - ) - ) + RadioSetting("roger", "Roger Beep", + RadioSettingValueList(ROGER_LIST, + ROGER_LIST[_settings.roger]))) basic.append( - RadioSetting( - "beep", - "System Beep", - RadioSettingValueBoolean(_settings.beep), - ) - ) + RadioSetting("beep", "System Beep", + RadioSettingValueBoolean(_settings.beep))) basic.append( - RadioSetting( - "tot", - "Timeout Timer (sec)", - RadioSettingValueList(TOT_LIST, TOT_LIST[_settings.tot]), - ) - ) + RadioSetting("tot", "Timeout Timer (sec)", + RadioSettingValueList(TOT_LIST, + TOT_LIST[_settings.tot]))) basic.append( - RadioSetting( - "toa", - "Timeout Timer Alarm", - RadioSettingValueList(TOA_LIST, TOA_LIST[_settings.toa]), - ) - ) + RadioSetting("toa", "Timeout Timer Alarm", + RadioSettingValueList(TOA_LIST, + TOA_LIST[_settings.toa]))) basic.append( - RadioSetting( - "lockmode", - "Lock Mode", - RadioSettingValueList(LOCKMODE_LIST, LOCKMODE_LIST[_settings.lockmode]), - ) - ) + RadioSetting("lockmode", "Lock Mode", + RadioSettingValueList( + LOCKMODE_LIST, + LOCKMODE_LIST[_settings.lockmode]))) basic.append( - RadioSetting( - "autolock", - "Auto Lock", - RadioSettingValueList(AUTOLOCK_LIST, AUTOLOCK_LIST[_settings.autolock]), - ) - ) + RadioSetting("autolock", "Auto Lock", + RadioSettingValueList( + AUTOLOCK_LIST, + AUTOLOCK_LIST[_settings.autolock]))) basic.append( - RadioSetting( - "auto_lock_dly", - "Auto Lock Delay", - RadioSettingValueList(AUTOLOCK_DLY_LIST, AUTOLOCK_DLY_LIST[_settings.auto_lock_dly]), - ) - ) + RadioSetting("auto_lock_dly", "Auto Lock Delay", + RadioSettingValueList( + AUTOLOCK_DLY_LIST, + AUTOLOCK_DLY_LIST[_settings.auto_lock_dly]))) display.append( - RadioSetting( - "abr", - "Screen Save", - RadioSettingValueList(ABR_LIST, ABR_LIST[_settings.abr]), - ) - ) + RadioSetting("abr", "Screen Save", + RadioSettingValueList(ABR_LIST, + ABR_LIST[_settings.abr]))) display.append( - RadioSetting( - "abr_lv", - "Back Light Brightness", - RadioSettingValueList(ABR_LV_LIST, ABR_LV_LIST[_settings.abr_lv]), - ) - ) + RadioSetting("abr_lv", "Back Light Brightness", + RadioSettingValueList(ABR_LV_LIST, + ABR_LV_LIST[_settings.abr_lv]))) display.append( - RadioSetting( - "night_mode", - "Night Mode (Light on Dark)", - RadioSettingValueBoolean(_settings.night_mode), - ) - ) + RadioSetting("night_mode", "Night Mode (Light on Dark)", + RadioSettingValueBoolean(_settings.night_mode))) display.append( - RadioSetting( - "menu_dly", - "Menu Delay", - RadioSettingValueList(MENU_DLY_LIST, MENU_DLY_LIST[_settings.menu_dly]), - ) - ) + RadioSetting("menu_dly", "Menu Delay", + RadioSettingValueList( + MENU_DLY_LIST, + MENU_DLY_LIST[_settings.menu_dly]))) display.append( - RadioSetting( - "english", - "Language", - RadioSettingValueList(LANG_LIST, LANG_LIST[_settings.english]), - ) - ) + RadioSetting("english", "Language", + RadioSettingValueList(LANG_LIST, + LANG_LIST[_settings.english]))) scan.append( - RadioSetting( - "pri_scn", - "Priority Scan", - RadioSettingValueBoolean(_settings.pri_scn), - ) - ) + RadioSetting("pri_scn", "Priority Scan", + RadioSettingValueBoolean(_settings.pri_scn))) scan.append( - RadioSetting( - "pri_ch", - "Priority Channel", - RadioSettingValueChannel(self, _settings.pri_ch), - ) - ) + RadioSetting("pri_ch", "Priority Channel", + RadioSettingValueChannel(self, _settings.pri_ch))) scan.append( - RadioSetting( - "sc_rev", - "Scan Resume", - RadioSettingValueList(SC_REV_LIST, SC_REV_LIST[_settings.sc_rev]), - ) - ) + RadioSetting("sc_rev", "Scan Resume", + RadioSettingValueList(SC_REV_LIST, + SC_REV_LIST[_settings.sc_rev]))) scan.append( - RadioSetting( - "sc_qt", - "Code Save", - RadioSettingValueList(SC_QT_LIST, SC_QT_LIST[_settings.sc_qt]), - ) - ) + RadioSetting("sc_qt", "Code Save", + RadioSettingValueList(SC_QT_LIST, + SC_QT_LIST[_settings.sc_qt]))) buttons.append( - RadioSetting( - "pf1_short", - "PF1 (Side, Upper) Button Short Press", - RadioSettingValueList(PF1_LIST, PF1_LIST[_settings.pf1_short]), - ) - ) + RadioSetting("pf1_short", "PF1 (Side, Upper) Button Short Press", + RadioSettingValueList(PF1_LIST, + PF1_LIST[_settings.pf1_short]))) buttons.append( - RadioSetting( - "pf1_long", - "PF1 (Side, Upper) Button Long Press", - RadioSettingValueList(PF1_LIST, PF1_LIST[_settings.pf1_long]), - ) - ) + RadioSetting("pf1_long", "PF1 (Side, Upper) Button Long Press", + RadioSettingValueList(PF1_LIST, + PF1_LIST[_settings.pf1_long]))) buttons.append( - RadioSetting( - "pf2_short", - "PF2 (Side, Lower) Button Short Press", - RadioSettingValueList(PF2_LIST, PF2_LIST[_settings.pf2_short]), - ) - ) + RadioSetting("pf2_short", "PF2 (Side, Lower) Button Short Press", + RadioSettingValueList(PF2_LIST, + PF2_LIST[_settings.pf2_short]))) buttons.append( - RadioSetting( - "pf2_long", - "PF2 (Side, Lower) Button Long Press", - RadioSettingValueList(PF2_LIST, PF2_LIST[_settings.pf2_long]), - ) - ) + RadioSetting("pf2_long", "PF2 (Side, Lower) Button Long Press", + RadioSettingValueList(PF2_LIST, + PF2_LIST[_settings.pf2_long]))) buttons.append( - RadioSetting( - "top_short", - "Top Button Short Press", - RadioSettingValueList(TOP_LIST, TOP_LIST[_settings.top_short]), - ) - ) + RadioSetting("top_short", "Top Button Short Press", + RadioSettingValueList(TOP_LIST, + TOP_LIST[_settings.top_short]))) buttons.append( - RadioSetting( - "top_long", - "Top Button Long Press", - RadioSettingValueList(TOP_LIST, TOP_LIST[_settings.top_long]), - ) - ) + RadioSetting("top_long", "Top Button Long Press", + RadioSettingValueList(TOP_LIST, + TOP_LIST[_settings.top_long]))) vfo.append( - RadioSetting( - "tdr", - "VFO B Enabled", - RadioSettingValueBoolean(_settings.tdr), - ) - ) + RadioSetting("tdr", "VFO B Enabled", + RadioSettingValueBoolean(_settings.tdr))) vfo.append( - RadioSetting( - "ch_a_step", - "VFO Frequency Step (A)", - RadioSettingValueList(STEP_LIST, STEP_LIST[_settings.ch_a_step]), - ) - ) + RadioSetting("ch_a_step", "VFO Frequency Step (A)", + RadioSettingValueList( + STEP_LIST, + STEP_LIST[_settings.ch_a_step]))) vfo.append( - RadioSetting( - "ch_b_step", - "VFO Frequency Step (B)", - RadioSettingValueList(STEP_LIST, STEP_LIST[_settings.ch_b_step]), - ) - ) + RadioSetting("ch_b_step", "VFO Frequency Step (B)", + RadioSettingValueList( + STEP_LIST, + STEP_LIST[_settings.ch_b_step]))) vfo.append( - RadioSetting( - "ch_a_sql", - "Squelch (A)", - RadioSettingValueList(SQL_LIST, SQL_LIST[_settings.ch_a_sql]), - ) - ) + RadioSetting("ch_a_sql", "Squelch (A)", + RadioSettingValueList(SQL_LIST, + SQL_LIST[_settings.ch_a_sql]))) vfo.append( - RadioSetting( - "ch_b_sql", - "Squelch (B)", - RadioSettingValueList(SQL_LIST, SQL_LIST[_settings.ch_b_sql]), - ) - ) + RadioSetting("ch_b_sql", "Squelch (B)", + RadioSettingValueList(SQL_LIST, + SQL_LIST[_settings.ch_b_sql]))) vfo.append( - RadioSetting( - "ch_a_mem_ch", - "Memory Channel (A)", - RadioSettingValueChannel(self, _settings.ch_a_mem_ch), - ) - ) + RadioSetting("ch_a_mem_ch", "Memory Channel (A)", + RadioSettingValueChannel(self, + _settings.ch_a_mem_ch))) vfo.append( - RadioSetting( - "ch_b_mem_ch", - "Memory Channel (B)", - RadioSettingValueChannel(self, _settings.ch_b_mem_ch), - ) - ) + RadioSetting("ch_b_mem_ch", "Memory Channel (B)", + RadioSettingValueChannel(self, + _settings.ch_b_mem_ch))) vfo.append( - RadioSetting( - "ch_a_ch_mdf", - "Memory Display Format (A)", - RadioSettingValueList(MDF_LIST, MDF_LIST[_settings.ch_a_ch_mdf]), - ) - ) + RadioSetting("ch_a_ch_mdf", "Memory Display Format (A)", + RadioSettingValueList( + MDF_LIST, + MDF_LIST[_settings.ch_a_ch_mdf]))) vfo.append( - RadioSetting( - "ch_b_ch_mdf", - "Memory Display Format (B)", - RadioSettingValueList(MDF_LIST, MDF_LIST[_settings.ch_b_ch_mdf]), - ) - ) + RadioSetting("ch_b_ch_mdf", "Memory Display Format (B)", + RadioSettingValueList( + MDF_LIST, + MDF_LIST[_settings.ch_b_ch_mdf]))) vfo.append( - RadioSetting( - "ch_a_v_m", - "VFO/MEM (A)", - RadioSettingValueList(VM_LIST, VM_LIST[_settings.ch_a_v_m]), - ) - ) + RadioSetting("ch_a_v_m", "VFO/MEM (A)", + RadioSettingValueList( + VM_LIST, VM_LIST[_settings.ch_a_v_m]))) vfo.append( - RadioSetting( - "ch_b_v_m", - "VFO/MEM (B)", - RadioSettingValueList(VM_LIST, VM_LIST[_settings.ch_b_v_m]), - ) - ) + RadioSetting("ch_b_v_m", "VFO/MEM (B)", + RadioSettingValueList( + VM_LIST, VM_LIST[_settings.ch_b_v_m]))) advanced.append( - RadioSetting( - "vox_grd", - "VOX Sensitivity", - RadioSettingValueList(VOX_LIST, VOX_LIST[_settings.vox_grd]), - ) - ) + RadioSetting("vox_grd", "VOX Sensitivity", + RadioSettingValueList( + VOX_LIST, VOX_LIST[_settings.vox_grd]))) advanced.append( - RadioSetting( - "vox_dly", - "VOX Delay", - RadioSettingValueList(VOX_DLY_LIST, VOX_DLY_LIST[_settings.vox_dly]), - ) - ) + RadioSetting("vox_dly", "VOX Delay", + RadioSettingValueList( + VOX_DLY_LIST, VOX_DLY_LIST[_settings.vox_dly]))) advanced.append( - RadioSetting( - "voice", - "Voice Assist", - RadioSettingValueBoolean(_settings.voice), - ) - ) + RadioSetting("voice", "Voice Assist", + RadioSettingValueBoolean(_settings.voice))) advanced.append( - RadioSetting( - "rpt_rct", - "RPT Roger", - RadioSettingValueBoolean(_settings.rpt_rct), - ) - ) + RadioSetting("rpt_rct", "RPT Roger", + RadioSettingValueBoolean(_settings.rpt_rct))) aprs.append( - RadioSetting( - "aprs_rx_band", - "RX Band", - RadioSettingValueList(APRS_RX_LIST, APRS_RX_LIST[_settings.aprs_rx_band]), - ) - ) + RadioSetting("aprs_rx_band", "RX Band", + RadioSettingValueList( + APRS_RX_LIST, + APRS_RX_LIST[_settings.aprs_rx_band]))) aprs.append( - RadioSetting( - "ch_a_mute", - "Band A Mute", - RadioSettingValueBoolean(_settings.ch_a_mute), - ) - ) + RadioSetting("ch_a_mute", "Band A Mute", + RadioSettingValueBoolean(_settings.ch_a_mute))) aprs.append( - RadioSetting( - "ch_b_mute", - "Band B Mute", - RadioSettingValueBoolean(_settings.ch_b_mute), - ) - ) + RadioSetting("ch_b_mute", "Band B Mute", + RadioSettingValueBoolean(_settings.ch_b_mute))) aprs.append( - RadioSetting( - "tx_priority", - "TX Priority", - RadioSettingValueList(TX_PRIORITY_LIST, TX_PRIORITY_LIST[_settings.tx_priority]), - ) - ) + RadioSetting("tx_priority", "TX Priority", + RadioSettingValueList( + TX_PRIORITY_LIST, + TX_PRIORITY_LIST[_settings.tx_priority]))) aprs.append( - RadioSetting( - "aprs_rx_popup", - "APRS Popup", - RadioSettingValueBoolean(_settings.aprs_rx_popup), - ) - ) + RadioSetting("aprs_rx_popup", "APRS Popup", + RadioSettingValueBoolean(_settings.aprs_rx_popup))) aprs.append( - RadioSetting( - "aprs_rx_tone", - "RX Tone", - RadioSettingValueBoolean(_settings.aprs_rx_tone), - ) - ) + RadioSetting("aprs_rx_tone", "RX Tone", + RadioSettingValueBoolean(_settings.aprs_rx_tone))) aprs.append( - RadioSetting( - "aprs_tx_tone", - "TX Tone", - RadioSettingValueBoolean(_settings.aprs_tx_tone), - ) - ) + RadioSetting("aprs_tx_tone", "TX Tone", + RadioSettingValueBoolean(_settings.aprs_tx_tone))) aprs.append( - RadioSetting( - "beacon_exit_dly", - "Beacon Message Delay", - RadioSettingValueList(BEACON_EXIT_DLY_LIST, BEACON_EXIT_DLY_LIST[_settings.beacon_exit_dly]), - ) - ) + RadioSetting("beacon_exit_dly", "Beacon Message Delay", + RadioSettingValueList( + BEACON_EXIT_DLY_LIST, + BEACON_EXIT_DLY_LIST[_settings.beacon_exit_dly]))) return top @@ -904,7 +741,3 @@ class LanchonlhHG_UV98(chirp_common.CloneModeRadio, chirp_common.ExperimentalRad if hasattr(_settings, name): setattr(_settings, name, value) - - -if has_future: - LanchonlhHG_UV98 = directory.register(LanchonlhHG_UV98) diff --git a/chirp/drivers/ic2100.py b/chirp/drivers/ic2100.py index 0fc2181..631df29 100644 --- a/chirp/drivers/ic2100.py +++ b/chirp/drivers/ic2100.py @@ -14,7 +14,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from chirp.drivers import icf -from chirp import chirp_common, util, directory, bitwise, memmap +from chirp import chirp_common, util, directory, bitwise from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean @@ -132,13 +132,13 @@ def _set_freq(mem, freq): def _get_offset(mem): - raw = memmap.MemoryMap(mem.get_raw()) - if ord(raw[5]) & 0x0A: - raw[5] = ord(raw[5]) & 0xF0 - mem.set_raw(raw.get_packed()) + raw = bytearray(mem.get_raw()) + if raw[5] & 0x0A: + raw[5] = raw[5] & 0xF0 + mem.set_raw(raw) offset = int(mem.offset) * 1000 + 5000 - raw[5] = ord(raw[5]) | 0x0A - mem.set_raw(raw.get_packed()) + raw[5] = raw[5] | 0x0A + mem.set_raw(bytes(raw)) return offset else: return int(mem.offset) * 1000 @@ -152,9 +152,9 @@ def _set_offset(mem, offset): extra = 0x00 mem.offset = offset / 1000 - raw = memmap.MemoryMap(mem.get_raw()) - raw[5] = ord(raw[5]) | extra - mem.set_raw(raw.get_packed()) + raw = bytearray(mem.get_raw()) + raw[5] = raw[5] | extra + mem.set_raw(bytes(raw)) def _wipe_memory(mem, char): diff --git a/chirp/drivers/ic2730.py b/chirp/drivers/ic2730.py index 16036c3..876cb7c 100644 --- a/chirp/drivers/ic2730.py +++ b/chirp/drivers/ic2730.py @@ -27,17 +27,9 @@ from chirp.settings import RadioSettingGroup, RadioSetting, \ LOG = logging.getLogger(__name__) -HAS_FUTURE = True -try: # PY3 compliance - from builtins import bytes -except ImportError: - HAS_FUTURE = False - LOG.debug('python-future package is not ' - 'available; %s requires it' % __name__) - MEM_FORMAT = """ struct { - u24 freq_flags:6 + u24 freq_flags:6, freq:18; u16 offset; u8 tune_step:4, @@ -90,11 +82,11 @@ char nam[6]; #seekto 0x4e80; struct { -u24 loflags:6 +u24 loflags:6, lofreq:18; -u24 hiflags:6 +u24 hiflags:6, hifreq:18; -u8 flag:4 +u8 flag:4, mode:4; u8 tstp; char name[6]; @@ -122,7 +114,7 @@ u8 civbaud; u8 civtcvr; u8 sqlatt; u8 sqldly; -u8 unk5014a:4 +u8 unk5014a:4, fanspeed:4; u8 unk5015; u8 bthvox; @@ -193,8 +185,8 @@ u8 unk505a; u8 unk505b; u8 unk505c; u8 unk505d; -u8 unk505e:6 - rpthangup:1 +u8 unk505e:6, + rpthangup:1, unk505e2:1; u8 unk505f; } settings; diff --git a/chirp/drivers/ic9x_ll.py b/chirp/drivers/ic9x_ll.py index 609099c..1c66e73 100644 --- a/chirp/drivers/ic9x_ll.py +++ b/chirp/drivers/ic9x_ll.py @@ -145,7 +145,7 @@ class IC92Frame: def send(self, pipe, verbose=False): """Send the frame to the radio via @pipe""" - if verbose or True: + if verbose: LOG.debug("Sending:\n%s" % util.hexprint(self.get_raw())) response = ic9x_send(pipe, self.get_raw()) diff --git a/chirp/drivers/icq7.py b/chirp/drivers/icq7.py index 1917655..9dd7ce2 100644 --- a/chirp/drivers/icq7.py +++ b/chirp/drivers/icq7.py @@ -31,7 +31,7 @@ struct { u8 fractional:1, unknown:7; bbcd offset[2]; - u16 ctone:6 + u16 ctone:6, rtone:6, tune_step:4; } memory[200]; diff --git a/chirp/drivers/ict8.py b/chirp/drivers/ict8.py index 6d63ba8..7e3805d 100644 --- a/chirp/drivers/ict8.py +++ b/chirp/drivers/ict8.py @@ -117,7 +117,7 @@ class ICT8ARadio(icf.IcomCloneModeRadio): mem.duplex = DUPLEX[_flg.duplex] mem.tmode = TMODES[_flg.tmode] mem.skip = _flg.skip and "S" or "" - if _name.name.get_raw() != "\xFF\xFF\xFF\xFF": + if _name.name.get_raw(asbytes=False) != "\xFF\xFF\xFF\xFF": mem.name = str(_name.name).rstrip() return mem diff --git a/chirp/drivers/icv80.py b/chirp/drivers/icv80.py index d120247..9747711 100644 --- a/chirp/drivers/icv80.py +++ b/chirp/drivers/icv80.py @@ -101,7 +101,7 @@ struct { vox_gain:4; u8 unknown20:6, mic_gain:2; - u8 unknown21:5 + u8 unknown21:5, vox_delay:3; u8 unknown22:4, vox_tot:4; diff --git a/chirp/drivers/iradio_uv_5118.py b/chirp/drivers/iradio_uv_5118.py index 85b961f..ab7d695 100644 --- a/chirp/drivers/iradio_uv_5118.py +++ b/chirp/drivers/iradio_uv_5118.py @@ -26,23 +26,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ LOG = logging.getLogger(__name__) MEM_FORMAT = """ -struct memory { - ul32 rxfreq; // 00-03 - ul16 rx_tone; // PL/DPL Decode // 04-05 - ul32 txfreq; // 06-09 - ul16 tx_tone; // PL/DPL Encode // 0a-0b - u8 lowpower:1, // Power Level // 0c - isnarrow:1, // Bandwidth - unknown1:1, - unknown2:3, - bcl:1, // Busy Channel Lockout - scan:1; // Scan Add - u8 unknown3[3]; // 0d-0f -}; - -#seekto 0x0050; -struct memory channels[128]; - #seekto 0x0010; struct { u8 range174_180; // 174-180 MHz @@ -100,7 +83,7 @@ struct { save:3; // Power Save u8 dispmode:1, // 0x0042 Display Mode dstandby:1, // Dual Standby - unknown_1:1 + unknown_1:1, standby:1, // Radio Standby squelch:4; // Squelch Level u8 vox_level:4, // 0x0043 VOX Level @@ -131,6 +114,23 @@ struct { u8 tot; // 0x004F } settings; +struct memory { + ul32 rxfreq; // 00-03 + ul16 rx_tone; // PL/DPL Decode // 04-05 + ul32 txfreq; // 06-09 + ul16 tx_tone; // PL/DPL Encode // 0a-0b + u8 lowpower:1, // Power Level // 0c + isnarrow:1, // Bandwidth + unknown1:1, + unknown2:3, + bcl:1, // Busy Channel Lockout + scan:1; // Scan Add + u8 unknown3[3]; // 0d-0f +}; + +// #seekto 0x0050; +struct memory channels[128]; + """ CMD_ACK = b"\x06" @@ -455,12 +455,12 @@ class IradioUV5118(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw() == b"\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem - if _mem.get_raw() == ("\xFF" * 16): + if _mem.get_raw() == (b"\xFF" * 16): LOG.debug("Initializing empty memory") _mem.set_raw("\xFF" * 4 + "\x00\x30" + "\xFF" * 4 + "\x00\x30" + "\x00" * 4) diff --git a/chirp/drivers/iradio_uv_5118plus.py b/chirp/drivers/iradio_uv_5118plus.py index fcd61e2..0666c4f 100644 --- a/chirp/drivers/iradio_uv_5118plus.py +++ b/chirp/drivers/iradio_uv_5118plus.py @@ -26,33 +26,7 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ LOG = logging.getLogger(__name__) MEM_FORMAT = """ -struct memory { - ul32 rxfreq; // RX Frequency 00-03 - ul16 rx_tone; // PL/DPL Decode 04-05 - ul32 txfreq; // TX Frequency 06-09 - ul16 tx_tone; // PL/DPL Encode 0a-0b - ul24 mutecode; // Mute Code 0c-0e - u8 unknown_0:2, // 0f - mutetype:2, // Mute Type - unknown_1:4; // - u8 isnarrow:1, // Bandwidth 00 - lowpower:1, // Power - scan:1, // Scan Add - bcl:2, // Busy Lock - is_airband:1, // Air Band (AM) - unknown_3:1, // - unknown_4:1; // - u8 unknown_5; // 01 - u8 unused_0:4, // 02 - scno:4; // SC No. - u8 unknown_6[3]; // 03-05 - char name[10]; // 06-0f -}; - -#seekto 0x1000; -struct memory channels[999]; - -#seekto 0x0000; +// #seekto 0x0000; struct { char startuplabel[32]; // Startup Label 0000-001f char personalid[16]; // Personal ID 0020-002f @@ -118,6 +92,32 @@ struct { ul16 quickch3; // Quick CH 3 0076-0077 } settings; +struct memory { + ul32 rxfreq; // RX Frequency 00-03 + ul16 rx_tone; // PL/DPL Decode 04-05 + ul32 txfreq; // TX Frequency 06-09 + ul16 tx_tone; // PL/DPL Encode 0a-0b + ul24 mutecode; // Mute Code 0c-0e + u8 unknown_0:2, // 0f + mutetype:2, // Mute Type + unknown_1:4; // + u8 isnarrow:1, // Bandwidth 00 + lowpower:1, // Power + scan:1, // Scan Add + bcl:2, // Busy Lock + is_airband:1, // Air Band (AM) + unknown_3:1, // + unknown_4:1; // + u8 unknown_5; // 01 + u8 unused_0:4, // 02 + scno:4; // SC No. + u8 unknown_6[3]; // 03-05 + char name[10]; // 06-0f +}; + +#seekto 0x1000; +struct memory channels[999]; + #seekto 0x8D20; struct { u8 senddelay; // Send Delay 8d20 @@ -139,7 +139,7 @@ struct { u8 code_len; // DTMF code length } dtmfcode[16]; -#seekto 0x8E30; +// #seekto 0x8E30; struct { char kill[14]; // Remotely Kill 8e30-8e3d u8 unknown_0; // 8e3e @@ -498,7 +498,7 @@ class IradioUV5118plus(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw() == b"\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem diff --git a/chirp/drivers/kenwood_live.py b/chirp/drivers/kenwood_live.py index 9e3db3f..649e7c7 100644 --- a/chirp/drivers/kenwood_live.py +++ b/chirp/drivers/kenwood_live.py @@ -1018,6 +1018,13 @@ class TMV71Radio(TMD710Radio): """Kenwood TM-V71""" MODEL = "TM-V71" + def get_features(self): + rf = super().get_features() + rf.valid_characters = ''.join(c for c in rf.valid_characters + if not c.isalpha() or + c not in rf.valid_characters.lower()) + return rf + @directory.register class TMD710GRadio(TMD710Radio): diff --git a/chirp/drivers/kguv8d.py b/chirp/drivers/kguv8d.py index 490b814..8902d69 100644 --- a/chirp/drivers/kguv8d.py +++ b/chirp/drivers/kguv8d.py @@ -201,7 +201,7 @@ _MEM_FORMAT = """ power:1, unknown2:1; u8 unknown3:1, - shift_dir:2 + shift_dir:2, unknown4:2, mute_mode:2, iswide:1; @@ -219,7 +219,7 @@ _MEM_FORMAT = """ power:1, unknown2:1; u8 unknown3:1, - shift_dir:2 + shift_dir:2, unknown4:2, mute_mode:2, iswide:1; diff --git a/chirp/drivers/kguv8dplus.py b/chirp/drivers/kguv8dplus.py index b80b358..03b5218 100644 --- a/chirp/drivers/kguv8dplus.py +++ b/chirp/drivers/kguv8dplus.py @@ -215,7 +215,7 @@ _MEM_FORMAT = """ power:1, unknown2:1; u8 unknown3:1, - shift_dir:2 + shift_dir:2, unknown4:1, compander:1, mute_mode:2, @@ -235,7 +235,7 @@ _MEM_FORMAT = """ power:1, unknown2:1; u8 unknown3:1, - shift_dir:2 + shift_dir:2, unknown4:1, compander:1, mute_mode:2, diff --git a/chirp/drivers/kguv8e.py b/chirp/drivers/kguv8e.py index b290af7..e342259 100644 --- a/chirp/drivers/kguv8e.py +++ b/chirp/drivers/kguv8e.py @@ -217,7 +217,7 @@ _MEM_FORMAT = """ power:1, unknown2:1; u8 unknown3:1, - shift_dir:2 + shift_dir:2, unknown4:1, compander:1, mute_mode:2, @@ -237,7 +237,7 @@ _MEM_FORMAT = """ power:1, unknown2:1; u8 unknown3:1, - shift_dir:2 + shift_dir:2, unknown4:1, compander:1, mute_mode:2, diff --git a/chirp/drivers/kguv920pa.py b/chirp/drivers/kguv920pa.py index 903ec17..d9ab95f 100644 --- a/chirp/drivers/kguv920pa.py +++ b/chirp/drivers/kguv920pa.py @@ -147,14 +147,14 @@ _MEM_FORMAT = """ mute_mode:2, unknown1_3downto0:3; u8 named:1, - scan_add:1 + scan_add:1, power:2, unknown2_32:2, isnarrow:2; u8 unknown3_7downto2:6, duplex:2; u8 unknown4:3, - compander:1 + compander:1, scrambler:4; } vfoa; @@ -168,14 +168,14 @@ _MEM_FORMAT = """ mute_mode:2, unknown1_3downto0:3; u8 named:1, - scan_add:1 + scan_add:1, power:2, unknown2_3downto2:2, isnarrow:2; u8 unknown3_7downto2:6, duplex:2; u8 unknown4:3, - compander:1 + compander:1, scrambler:4; } vfob; @@ -311,14 +311,14 @@ _MEM_FORMAT = """ mute_mode:2, unknown1_3downto0:3; u8 named:1, - scan_add:1 + scan_add:1, power:2, unknown2_32:2, isnarrow:2; u8 unknown3_7downto2:6, shift_dir:2; u8 unknown4:3, - compander:1 + compander:1, scrambler:4; } memory[999]; diff --git a/chirp/drivers/kguv980p.py b/chirp/drivers/kguv980p.py index 5b23947..f171d35 100644 --- a/chirp/drivers/kguv980p.py +++ b/chirp/drivers/kguv980p.py @@ -556,7 +556,7 @@ _MEM_FORMAT = """ u8 unknown3:6, Unknown4_shft_dir:2; u8 unknown5:3, - compander:1 + compander:1, scrambler:4; } memory[1000]; diff --git a/chirp/drivers/kyd.py b/chirp/drivers/kyd.py index 3542771..b83dff1 100644 --- a/chirp/drivers/kyd.py +++ b/chirp/drivers/kyd.py @@ -312,7 +312,7 @@ class NC630aRadio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem diff --git a/chirp/drivers/kyd_IP620.py b/chirp/drivers/kyd_IP620.py index 01aad36..9a779b5 100644 --- a/chirp/drivers/kyd_IP620.py +++ b/chirp/drivers/kyd_IP620.py @@ -36,10 +36,10 @@ struct { // Channel memory structure lbcd tx_freq[4]; // TX frequency ul16 rx_tone; // RX tone ul16 tx_tone; // TX tone - u8 unknown_1:4 // n-a + u8 unknown_1:4, // n-a busy_loc:2, // NO-00, Crrier wave-01, SM-10 n_a:2; // n-a - u8 unknown_2:1 // n-a + u8 unknown_2:1, // n-a scan_add:1, // Scan add n_a:1, // n-a w_n:1, // Narrow-0 Wide-1 @@ -62,10 +62,10 @@ struct { // Settings memory structure ( A-Frequency mode ) lbcd freq_a_tx[4]; ul16 freq_a_rx_tone; // RX tone ul16 freq_a_tx_tone; // TX tone - u8 unknown_1_5:4 + u8 unknown_1_5:4, freq_a_busy_loc:2, n_a:2; - u8 unknown_1_6:3 + u8 unknown_1_6:3, freq_a_w_n:1, n_a:1, na:1, @@ -372,7 +372,7 @@ class IP620Radio(chirp_common.CloneModeRadio, def _is_empty(): for i in range(0, 4): - if _mem.rx_freq[i].get_raw() != "\xFF": + if _mem.rx_freq[i].get_raw(asbytes=False) != "\xFF": return False return True diff --git a/chirp/drivers/leixen.py b/chirp/drivers/leixen.py index 093e860..777b2be 100644 --- a/chirp/drivers/leixen.py +++ b/chirp/drivers/leixen.py @@ -77,7 +77,7 @@ struct { u8 unknown0x0194; u8 menuen:1, // menu enable absel:1, // a/b select - unknown:2 + unknown:2, keymshort:4; // m key short press u8 unknown:4, dtmfst:1, // dtmf sidetone @@ -474,7 +474,7 @@ class LeixenVV898Radio(chirp_common.CloneModeRadio): def _is_txinh(self, _mem): raw_tx = "" for i in range(0, 4): - raw_tx += _mem.tx_freq[i].get_raw() + raw_tx += _mem.tx_freq[i].get_raw(asbytes=False) return raw_tx == b"\xFF\xFF\xFF\xFF" def _get_memobjs(self, number): @@ -488,7 +488,7 @@ class LeixenVV898Radio(chirp_common.CloneModeRadio): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[:4] == "\xFF\xFF\xFF\xFF": + if _mem.get_raw(asbytes=False)[:4] == "\xFF\xFF\xFF\xFF": mem.empty = True return mem @@ -590,7 +590,7 @@ class LeixenVV898Radio(chirp_common.CloneModeRadio): if mem.empty: _mem.set_raw(b"\xFF" * 16) return - elif _mem.get_raw() == (b"\xFF" * 16): + elif _mem.get_raw(asbytes=False) == (b"\xFF" * 16): _mem.set_raw(b"\xFF" * 8 + b"\xFF\x00\xFF\x00\xFF\xFE\xF0\xFC") _mem.rx_freq = mem.freq / 10 @@ -622,12 +622,8 @@ class LeixenVV898Radio(chirp_common.CloneModeRadio): aliasop = None if mem.name: _mem.aliasop = False - if aliasop and not aliasop.changed(): - aliasop.value = "Name" else: _mem.aliasop = True - if aliasop and not aliasop.changed(): - aliasop.value = "Frequency" for setting in mem.extra: setattr(_mem, setting.get_name(), setting.value) diff --git a/chirp/drivers/lt725uv.py b/chirp/drivers/lt725uv.py index 45804c8..dc939b1 100644 --- a/chirp/drivers/lt725uv.py +++ b/chirp/drivers/lt725uv.py @@ -178,8 +178,8 @@ struct mem { // BJ-318 band power overrides any // individual channel power setting wide:1, - compander:1 - scrambler:1 + compander:1, + scrambler:1, unknown:4; u8 namelen; u8 name[7]; @@ -595,7 +595,7 @@ class LT725UV(chirp_common.CloneModeRadio): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw(asbytes=False)[0] == "\xff": mem.empty = True return mem diff --git a/chirp/drivers/mml_jc8810.py b/chirp/drivers/mml_jc8810.py index c16c36d..a10546a 100644 --- a/chirp/drivers/mml_jc8810.py +++ b/chirp/drivers/mml_jc8810.py @@ -37,7 +37,6 @@ from chirp.settings import ( LOG = logging.getLogger(__name__) MEM_FORMAT = """ -#seekto 0x0000; struct { lbcd rxfreq[4]; // 0-3 lbcd txfreq[4]; // 4-7 @@ -85,7 +84,8 @@ struct { dtmfst:2; // DTMF ST u8 unused_900a:6, // 900A screv:2; // Scan Mode - u8 unknown_900b; // 900B + u8 unused_900B:4, // 900B + pttid:4; // PTT-ID u8 unused_900c:5, // 900C pttlt:3; // PTT Delay u8 unused_900d:6, // 900D @@ -150,22 +150,21 @@ struct { // RX END TAIL (A36plus) } settings; -#seekto 0xA020; -struct { - u8 code[5]; // 5-character DTMF Encoder Groups - u8 unused[11]; -} pttid[15]; - #seekto 0xA006; struct { - u8 unused_a006:4, // A006 - pttid:4; // PTT-ID + u8 unknown_A006; // A006 u8 unused_a007:5, // A007 dtmfon:3; // DTMF Speed (on time) u8 unused_a008:5, // A008 dtmfoff:3; // DTMF Speed (off time) } dtmf; +#seekto 0xA020; +struct { + u8 code[5]; // 5-character DTMF Encoder Groups + u8 unused[11]; +} pttid[15]; + #seekto 0xB000; struct { u8 code[3]; // 3-character ANI Code Groups @@ -177,6 +176,9 @@ struct { u8 unused[6]; } aninames[%d]; +""" + +MEM_FORMAT_A36PLUS = """ #seekto 0xB200; struct { char name[10]; // 10-character Custom CH Names (Talkpod A36plus) @@ -288,6 +290,14 @@ def _enter_programming_mode(radio): LOG.debug(util.hexprint(ident)) raise errors.RadioError("Radio returned unknown identification string") + if radio.MODEL == "RT-470X": + if ident in radio._fingerprint_pcb1: + LOG.info("Radtel RT-470X - original pcb") + radio.RT470X_ORIG = True + elif ident in radio._fingerprint_pcb2: + LOG.info("Radtel RT-470X - pcb2") + radio.RT470X_ORIG = False + def _exit_programming_mode(radio): serial = radio.pipe @@ -456,7 +466,7 @@ class JC8810base(chirp_common.CloneModeRadio): rf.valid_modes = ["FM", "NFM"] # 25 kHz, 12.5 kHz. rf.valid_dtcs_codes = DTCS rf.memory_bounds = (1, self._upper) - rf.valid_tuning_steps = [2.5, 5., 6.25, 10., 12.5, 20., 25., 50.] + rf.valid_tuning_steps = [2.5, 5., 6.25, 8.33, 10., 12.5, 20., 25., 50.] rf.valid_bands = self.VALID_BANDS return rf @@ -490,12 +500,6 @@ class JC8810base(chirp_common.CloneModeRadio): raise errors.RadioError('Unexpected error communicating ' 'with the radio') - def _is_txinh(self, _mem): - raw_tx = "" - for i in range(0, 4): - raw_tx += _mem.txfreq[i].get_raw() - return raw_tx == "\xFF\xFF\xFF\xFF" - def get_memory(self, number): """Get the mem representation from the radio image""" _mem = self._memobj.memory[number - 1] @@ -506,14 +510,14 @@ class JC8810base(chirp_common.CloneModeRadio): # Memory number mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw()[:1] == b"\xFF": mem.empty = True return mem # Freq and offset mem.freq = int(_mem.rxfreq) * 10 # tx freq can be blank - if _mem.get_raw()[4] == "\xFF": + if _mem.get_raw()[:4] == b"\xFF\xFF\xFF\xFF": # TX freq not set mem.offset = 0 mem.duplex = "off" @@ -826,9 +830,7 @@ class JC8810base(chirp_common.CloneModeRadio): val = SKEY2S_VALUES[index] obj.set_value(val) - if self.MODEL in ["RT-470"]: - unwanted = [0, 7, 9, 10, 11, 12] - elif self.MODEL in ["HI-8811", "RT-470L", "RT-470X"]: + if self.MODEL in ["HI-8811", "RT-470L", "RT-470X", "RT-470"]: unwanted = [9, 10, 11, 12] elif self.MODEL in ["UV-A37", "AR-730"]: unwanted = [0, 5, 7, 9, 10, 11, 12] @@ -859,9 +861,7 @@ class JC8810base(chirp_common.CloneModeRadio): val = SKEY2L_VALUES[index] obj.set_value(val) - if self.MODEL in ["RT-470"]: - unwanted = [0, 7, 8, 9, 10, 11, 12] - elif self.MODEL in ["HI-8811", "RT-470L", "RT-470X"]: + if self.MODEL in ["HI-8811", "RT-470L", "RT-470X", "RT-470"]: unwanted = [8, 9, 10, 11, 12] elif self.MODEL in ["UV-A37", "AR-730"]: unwanted = [0, 5, 7, 8, 10, 11, 12] @@ -892,9 +892,7 @@ class JC8810base(chirp_common.CloneModeRadio): val = SKEY3S_VALUES[index] obj.set_value(val) - if self.MODEL in ["RT-470"]: - unwanted = [0, 7, 8, 9, 10, 11, 12] - elif self.MODEL in ["HI-8811", "RT-470L", "RT-470X"]: + if self.MODEL in ["HI-8811", "RT-470L", "RT-470X", "RT-470"]: unwanted = [8, 9, 10, 11, 12] elif self.MODEL in ["UV-A37", "AR-730"]: unwanted = [0, 5, 7, 8, 9, 10, 11, 12] @@ -917,7 +915,7 @@ class JC8810base(chirp_common.CloneModeRadio): rset.set_apply_callback(apply_skey3s_listvalue, _settings.skey3_sp) basic.append(rset) - if self.MODEL in ["HI-8811", "RT-470L", "RT-470X"]: + if self.MODEL in ["HI-8811", "RT-470L", "RT-470X", "RT-470"]: # Menu 24: PF3 LONG PRESS (RT-470L) def apply_skey3l_listvalue(setting, obj): LOG.debug("Setting value: " + str(setting.value) + @@ -927,7 +925,7 @@ class JC8810base(chirp_common.CloneModeRadio): val = SKEY2L_VALUES[index] obj.set_value(val) - if self.MODEL in ["HI-8811", "RT-470L", "RT-470X"]: + if self.MODEL in ["HI-8811", "RT-470L", "RT-470X", "RT-470"]: unwanted = [8, 9, 10, 11, 12] else: unwanted = [] @@ -956,16 +954,7 @@ class JC8810base(chirp_common.CloneModeRadio): val = SKEYTOP_VALUES[index] obj.set_value(val) - if self.MODEL in ["RT-470"]: - # ========== - # Notice to developers: - # The RT-470 v1.22 firmware added 'hidden' support for the - # Top Key (Short Press) feature. RT-470 radios with a firmware - # version prior to v1.22 will not honor the Top Key (Short - # Press) setting in CHIRP. - # ========== - unwanted = [0, 7, 8, 9, 10, 11, 12] - elif self.MODEL in ["HI-8811", "RT-470L", "RT-470X"]: + if self.MODEL in ["HI-8811", "RT-470L", "RT-470X", "RT-470"]: unwanted = [8, 9, 10, 11, 12] elif self.MODEL in ["UV-A37", "AR-730"]: unwanted = [0, 5, 7, 8, 9, 10, 11, 12] @@ -999,7 +988,7 @@ class JC8810base(chirp_common.CloneModeRadio): rset = RadioSetting("ponmsg", "Power On Message", rs) basic.append(rset) - if self.MODEL in ["HI-8811", "RT-470L"]: + if self.MODEL in ["HI-8811", "RT-470L", "RT-470X"]: rs = RadioSettingValueList(TAILCODE_LIST, TAILCODE_LIST[_settings.tailcode]) rset = RadioSetting("tailcode", "Tail Code", rs) @@ -1118,8 +1107,8 @@ class JC8810base(chirp_common.CloneModeRadio): rset = RadioSetting("dtmf.dtmfoff", "DTMF Speed (off)", rs) dtmf.append(rset) - rs = RadioSettingValueList(PTTID_LIST, PTTID_LIST[_dtmf.pttid]) - rset = RadioSetting("dtmf.pttid", "PTT ID", rs) + rs = RadioSettingValueList(PTTID_LIST, PTTID_LIST[_settings.pttid]) + rset = RadioSetting("pttid", "PTT ID", rs) dtmf.append(rset) ani = RadioSettingGroup("ani", "ANI Code List Settings") @@ -1241,14 +1230,23 @@ class RT470Radio(JC8810base): # ========== # Notice to developers: - # The RT-470 support in this driver is currently based upon v1.25 firmware. + # The RT-470 support in this driver is currently based upon... + # - v1.25a firmware (original pcb) + # - v2.11a firmware (pcb2) # ========== - _fingerprint = [b"\x00\x00\x00\x26\x00\x20\xD8\x04", - b"\x00\x00\x00\x42\x00\x20\xF0\x04", - b"\x00\x00\x00\x4A\x00\x20\xF8\x04", - b"\x00\x00\x00\x3A\x00\x20\xE8\x04", # fw 1.25A - ] + # original pcb + _fingerprint_pcb1 = [b"\x00\x00\x00\x26\x00\x20\xD8\x04", + b"\x00\x00\x00\x42\x00\x20\xF0\x04", + b"\x00\x00\x00\x4A\x00\x20\xF8\x04", + b"\x00\x00\x00\x3A\x00\x20\xE8\x04", # fw 1.25A + ] + + # pcb 2 + _fingerprint_pcb2 = [b"\x00\x00\x00\x2C\x00\x20\xD8\x04", # fw v2.11A + ] + + _fingerprint = _fingerprint_pcb1 + _fingerprint_pcb2 VALID_BANDS = [(16000000, 100000000), (100000000, 136000000), @@ -1294,9 +1292,24 @@ class RT470XRadio(RT470LRadio): # ========== # Notice to developers: - # The RT-470 support in this driver is currently based upon v1.18 firmware. + # The RT-470X support in this driver is currently based upon... + # - v1.18a firmware (original pcb) + # - v2.13a firmware (pcb2) # ========== + # original pcb + _fingerprint_pcb1 = [b"\x00\x00\x00\x20\x00\x20\xCC\x04", + ] + + # pcb 2 + _fingerprint_pcb2 = [b"\x00\x00\x00\x2C\x00\x20\xD8\x04", # fw v2.10A + b"\x00\x00\x00\x36\x00\x20\xDC\x04", # fw v2.13A + ] + + _fingerprint = _fingerprint_pcb1 + _fingerprint_pcb2 + + RT470X_ORIG = False + VALID_BANDS = [(100000000, 136000000), (136000000, 200000000), (200000000, 300000000), @@ -1312,10 +1325,23 @@ class HI8811Radio(RT470LRadio): # ========== # Notice to developers: - # The HI-8811 support in this driver is currently based upon v1.17 - # firmware. + # The HI-8811 support in this driver is currently based upon... + # - v1.17 firmware (original pcb) + # - v2.00 firmware (pcb2) # ========== + # original pcb + _fingerprint_pcb1 = [b"\x00\x00\x00\xfe\x00\x20\xAC\x04", + b"\x00\x00\x00\x20\x00\x20\xCC\x04", # fw v1.17 + b"\x00\x00\x00\x20\x00\x20\x07\x00", + ] + + # pcb 2 + _fingerprint_pcb2 = [b"\x00\x00\x00\x28\x00\x20\xD4\x04", # fw v2.00 + ] + + _fingerprint = _fingerprint_pcb1 + _fingerprint_pcb2 + @directory.register class UVA37Radio(JC8810base): @@ -1394,6 +1420,10 @@ class A36plusRadio(JC8810base): _aninames, # number of aninames ) + def process_mmap(self): + mem_format = MEM_FORMAT % self._mem_params + MEM_FORMAT_A36PLUS + self._memobj = bitwise.parse(mem_format, self._mmap) + @directory.register class AR730Radio(UVA37Radio): diff --git a/chirp/drivers/mursv1.py b/chirp/drivers/mursv1.py index f53345a..28e7ba1 100644 --- a/chirp/drivers/mursv1.py +++ b/chirp/drivers/mursv1.py @@ -369,7 +369,7 @@ class MURSV1(baofeng_common.BaofengCommonHT): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw()[:1] == b"\xff": mem.empty = True return mem diff --git a/chirp/drivers/puxing.py b/chirp/drivers/puxing.py index bc0ddc3..3645ad6 100644 --- a/chirp/drivers/puxing.py +++ b/chirp/drivers/puxing.py @@ -218,12 +218,12 @@ class Puxing777Radio(chirp_common.CloneModeRadio): def _is_empty(): for i in range(0, 4): - if _mem.rx_freq[i].get_raw() != "\xFF": + if _mem.rx_freq[i].get_raw(asbytes=False) != "\xFF": return False return True def _is_no_tone(field): - return field.get_raw() in ["\x00\x00", "\xFF\xFF"] + return field.get_raw(asbytes=False) in ["\x00\x00", "\xFF\xFF"] def _get_dtcs(value): # Upper nibble 0x80 -> DCS, 0xC0 -> Inv. DCS @@ -238,12 +238,12 @@ class Puxing777Radio(chirp_common.CloneModeRadio): if int(txfield) < 8000 or int(rxfield) < 8000: raise Exception("Split tone not supported") - if txfield[0].get_raw() == "\xFF": + if txfield[0].get_raw(asbytes=False) == "\xFF": tp, tx = "N", None else: tp, tx = _get_dtcs(int(txfield)) - if rxfield[0].get_raw() == "\xFF": + if rxfield[0].get_raw(asbytes=False) == "\xFF": rp, rx = "N", None else: rp, rx = _get_dtcs(int(rxfield)) @@ -328,8 +328,10 @@ class Puxing777Radio(chirp_common.CloneModeRadio): # Argh. Set the high order two bits to signal DCS or Inv. DCS txm = mem.dtcs_polarity[0] == "N" and 0x80 or 0xC0 rxm = mem.dtcs_polarity[1] == "N" and 0x80 or 0xC0 - _mem.tx_tone[1].set_raw(chr(ord(_mem.tx_tone[1].get_raw()) | txm)) - _mem.rx_tone[1].set_raw(chr(ord(_mem.rx_tone[1].get_raw()) | rxm)) + _mem.tx_tone[1].set_raw( + chr(ord(_mem.tx_tone[1].get_raw(asbytes=False)) | txm)) + _mem.rx_tone[1].set_raw( + chr(ord(_mem.rx_tone[1].get_raw(asbytes=False)) | rxm)) elif mem.tmode: _mem.tx_tone = int(mem.rtone * 10) @@ -459,7 +461,7 @@ class Puxing2RRadio(chirp_common.CloneModeRadio): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0:4] == "\xff\xff\xff\xff": + if _mem.get_raw(asbytes=False)[0:4] == "\xff\xff\xff\xff": mem.empty = True return mem diff --git a/chirp/drivers/puxing_px888k.py b/chirp/drivers/puxing_px888k.py index e4b66d7..a940958 100644 --- a/chirp/drivers/puxing_px888k.py +++ b/chirp/drivers/puxing_px888k.py @@ -174,7 +174,7 @@ struct { // 5 u8 allow_keypad:1, - relay_without_disable_tail:1 + relay_without_disable_tail:1, _unknown_0C65:1, call_channel_active:1, vox_gain:4; @@ -242,8 +242,8 @@ struct { // 1 u8 _unknown_0C91_1:3, channel_stepping:1, - unknown_0C91_2:1 - receive_range:2 + unknown_0C91_2:1, + receive_range:2, unknown_0C91_3:1; // 2-3 @@ -291,7 +291,7 @@ struct { compander:1, txpower:1, modulation_width:1, - txrx_reverse:1 + txrx_reverse:1, bcl:2; // D diff --git a/chirp/drivers/radioddity_r2.py b/chirp/drivers/radioddity_r2.py index 3359fe7..328d5e4 100644 --- a/chirp/drivers/radioddity_r2.py +++ b/chirp/drivers/radioddity_r2.py @@ -399,7 +399,7 @@ class RadioddityR2(chirp_common.CloneModeRadio): def decode_tone(self, val): """Parse the tone data to decode from mem, it returns: Mode (''|DTCS|Tone), Value (None|###), Polarity (None,N,R)""" - if val.get_raw() == "\xFF\xFF": + if val.get_raw(asbytes=False) == "\xFF\xFF": return '', None, None val = int(val) @@ -449,7 +449,7 @@ class RadioddityR2(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rx_freq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rx_freq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem @@ -541,7 +541,7 @@ class RadioddityR2(chirp_common.CloneModeRadio): # Get a low-level memory object mapped to the image _mem = self._memobj.memory[mem.number - 1] - _rsvd = _mem.reserved.get_raw() + _rsvd = _mem.reserved.get_raw(asbytes=False) if mem.empty: _mem.set_raw("\xFF" * 13 + _rsvd) diff --git a/chirp/drivers/radtel_rt490.py b/chirp/drivers/radtel_rt490.py new file mode 100644 index 0000000..6db6391 --- /dev/null +++ b/chirp/drivers/radtel_rt490.py @@ -0,0 +1,1631 @@ +# Copyright 2023 angeof9 angelof9@protonmail.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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# This file is dual-licensed by the copyright holder, under the GPLv3 +# for inclusion in CHIRP here. +# The code is also available under the BSD 2-Clause "Simplified" License +# here: +# https://chirp.danplanet.com/attachments/7833 + +# Python3 byte clean by Darryl Pogue +# Pep8 style compliant by Jim Unroe <rock.unroe@gmail.com> + +import logging +import struct + +from chirp import ( + bitwise, + chirp_common, + directory, + errors, + memmap, + util, +) + +from chirp.settings import ( + RadioSetting, + RadioSettingGroup, + RadioSettings, + RadioSettingValueBoolean, + RadioSettingValueInteger, + RadioSettingValueList, + RadioSettingValueString, + RadioSettingValueMap, + RadioSettingValueFloat, + InvalidValueError +) + +LOG = logging.getLogger(__name__) + +# 'True' or 'False' +# True unlocks: +# - FM preset +# - Channel memory # preset +# - Killswitch (with revive killed radios) +# - Bands settings +# - Disable radio identification string verification +# (good to recover from a bad state) +RT490_EXPERIMENTAL = True + +MEM_FORMAT_RT490 = """ +struct { // Memory settings + lbcd rxfreq[4]; + lbcd txfreq[4]; + ul16 rxtone; + ul16 txtone; + u8 signal; // int 0->14, Signal 1->15 + u8 pttid; // ['OFF', 'BOT', 'EOT', 'Both'] + u8 dcp:4, // What is DCP ? FHSS ? DC-FHSS ??? TODO + power:4; // POWER_LEVELS + u8 unknown3_0:1, // Used by the driver to store AM/NAM flag + // (thank you Radtel for free space) + narrow:1, // bool true=NFM false=FM (col[7] a) + unknown3_1:1, + unknown3_2:1, + bcl:1, // bool (col[9] a2) + scan:1, // bool (col[10] a3) + tx_enable:1, // bool (col[1] a4) + learn:1; // bool ??? TODO (col[14] a5) +} memory[%(memsize)d]; +// #seekto 0x1000; // Memory names (@4096) +struct { + char name[12]; + u8 ffpad[4]; +} memname[%(memsize)d]; +// #seekto 0x2000; // GOOD DCP keys ??? TODO ?? (@8192) +struct { + u8 code[4]; +} memcode[%(memsize)d]; // up to @x2400 + // Filled with xFF during download (=> no need to + // fill with xFF), ready to upload +#seekto 0x3400; // Custom ANI Names (@13312) +struct { + char name[10]; + u8 ffpad[6]; +} custom_ani_names[10]; + // Filled with xFF during download (=> no need to + // fill with xFF), ready to upload +#seekto 0x3500; // ANI Codes (@13568) +struct { + u8 anicode[6]; + u8 ffpad[10]; +} anicodes[60]; + // Filled with xFF during download (=> no need to + // fill with xFF), ready to upload +#seekto 0x3900; // Custom channel names (@14592) +struct { + char name[10]; + u8 ffpad[6]; +} custom_channel_names[10]; + // Filled with xFF during download (=> no need to + // fill with xFF), ready to upload +#seekto 0x3A00; // Settings (@14848) +struct { + u8 squelch; // 0: int 0 -> 9 + u8 savemode; // 1: ['OFF', 'Normal', 'Super', 'Deep'] + u8 vox; // 2: off=0, 1 -> 9 + u8 backlight; // 3: ['OFF', '5s', '15s', '20s', '30s', '1m', + // '2m', '3m'] + u8 tdr; // 4: bool + u8 timeout; // 5: n*30seconds, 0-240s + u8 beep; // 6: bool + u8 voice; // 7: bool + u8 byte_not_used_10; // 8: Allways 1 + u8 dtmfst; // 9: ['OFF', 'KB Side Tone', 'ANI Side Tone', + // 'KB ST + ANI ST'] + u8 scanmode; // 10: ['TO', 'CO', 'SE'] + u8 pttid; // 11: ['OFF', 'BOT', 'EOT', 'Both'] + u8 pttiddelay; // 12: ['0', '100ms', '200ms', '400ms', '600ms', + // '800ms', '1000ms'] + u8 cha_disp; // 13: ['Name', 'Freq', 'Channel ID'] + u8 chb_disp; // 14: ['Name', 'Freq', 'Channel ID'] + u8 bcl; // 15: bool + u8 autolock; // 0: ['OFF', '5s', '10s', 15s'] + u8 alarm_mode; // 1: ['Site', 'Tone', 'Code'] + u8 alarmsound; // 2: bool + u8 txundertdr; // 3: ['OFF', 'A', 'B'] + u8 tailnoiseclear; // 4: [off, on] + u8 rptnoiseclear; // 5: n*100ms, 0-1000 + u8 rptnoisedelay; // 6: n*100ms, 0-1000 + u8 roger; // 7: bool + u8 active_channel; // 8: 0 or 1 + u8 fmradio; // 9: boolean, inverted + u8 workmodeb:4, // 10:up ['VFO', 'CH Mode'] + workmodea:4; // 10:down ['VFO', 'CH Mode'] + u8 kblock; // 11: bool // TODO TEST WITH autolock + u8 powermsg; // 12: 0=Image / 1=Voltage + u8 byte_not_used_21; // 13: Allways 0 + u8 rpttone; // 14: ['1000Hz', '1450Hz', '1750Hz', '2100Hz'] + u8 byte_not_used_22; // 15: pad with xFF + u8 vox_delay; // 0: [str(float(a)/10)+'s' for a in range(5,21)] + // '0.5s' to '2.0s' + u8 timer_menu_quit; // 1: ['5s', '10s', '15s', '20s', '25s', '30s', + // '35s', '40s', '45s', '50s', '60s'] + u8 byte_not_used_30; // 2: pad with xFF + u8 byte_not_used_31; // 3: pad with xFF + u8 enable_killsw; // 4: bool + u8 display_ani; // 5: bool + u8 byte_not_used_32; // 6: pad with xFF + u8 enable_gps; // 7: bool + u8 scan_dcs; // 8: ['All', 'Receive', 'Transmit'] + u8 ani_id; // 9: int 0-59 (ANI 1-60) + u8 rx_time; // 10: bool + u8 ffpad0[5]; // 11: Pad xFF + u8 cha_memidx; // 0: Memory index when channel A use memories + u8 byte_not_used_40; + u8 chb_memidx; // 2: Memory index when channel B use memories + u8 byte_not_used_41; + u8 ffpad1[10]; + ul16 fmpreset; +} settings; + // Filled with xFF during download (=> no need to + // fill with xFF), ready to upload +struct settings_vfo_chan { + u8 rxfreq[8]; // 0 + ul16 rxtone; // 8 + ul16 txtone; // 10 + ul16 byte_not_used0; // 12 Pad xFF + u8 sftd:4, // 14 Shift dir ['OFF', '+', '-'] + signal:4; // 14 int 0->14, Signal 1->15 + u8 byte_not_used1; // 15 Pad xFF + u8 power; // 16:0 POWER_LEVELS + u8 fhss:4, // 17 ['OFF', 'FHSS 1', 'FHSS 2', 'FHSS 3', + // 'FHSS 4'] + narrow:4; // 17 bool true=NFM false=FM + u8 byte_not_used2; // 18 Pad xFF but received 0x00 ??? + u8 freqstep; // 19:3 ['2.5 KHz', '5.0 KHz', '6.25 KHz', + // '10.0 KHz', '12.5 KHz', '20.0 KHz', + // '25.0 KHz', '50.0 KHz'] + u8 byte_not_used3; // 20:4 Pad xFF but received 0x00 ??? TODO + u8 offset[6]; // 21:5 Freq NN.NNNN (without the dot) TEST TEST + u8 byte_not_used4; // 27:11 Pad xFF + u8 byte_not_used5; // 28 Pad xFF + u8 byte_not_used6; // 29 Pad xFF + u8 byte_not_used7; // 30 Pad xFF + u8 byte_not_used8; // 31:15 Pad xFF +}; +// #seekto 0x3A40; // VFO A/B (@14912) +struct { + struct settings_vfo_chan vfo_a; + struct settings_vfo_chan vfo_b; +} settings_vfo; +// #seekto 0x3A80; // Side keys settings (@14976) +struct { // Values from Radio + u8 pf2_short; // { '7': 'FM', '10': 'Tx Power', '28': 'Scan', + // '29': 'Search, '1': 'PPT B' } + u8 pf2_long; // { '7': 'FM', '10': 'Tx Power', '28': 'Scan', + // '29': 'Search' } + u8 pf3_short; // {'7': 'FM', '10': 'Tx Power', '28': 'Scan', + // '29': 'Search'} + u8 ffpad; // Pad xFF +} settings_sidekeys; +struct dtmfcode { + u8 code[5]; // 5 digits DTMF + u8 ffpad[11]; // Pad xFF +}; + // Filled with xFF during download (=> no need to + // fill with xFF), ready to upload +#seekto 0x3B00; // DTMF (@15104) +struct dtmfcode settings_dtmfgroup[15]; +struct { // @15296+3x16 + u8 byte_not_used1; // 0: Pad xFF something here + u8 byte_not_used2; // 1: Pad xFF something here + u8 byte_not_used3; // 2: Pad xFF something here + u8 byte_not_used4; // 3: Pad xFF + u8 byte_not_used5; // 4: Pad xFF + u8 unknown_dtmf; // 5: 0 TODO ???? wtf is alarmcode/alarmcall TODO + u8 pttid; // 6: [off, BOT, EOT, Both] + u8 dtmf_speed_on; // 7: ['50ms', '100ms', '200ms', '300ms', '500ms'] + u8 dtmf_speed_off; // 8:0 ['50ms', '100ms', '200ms', '300ms', '500ms'] +} settings_dtmf; + // Filled with xFF during download (=> no need to + // fill with xFF), ready to upload +#seekto 0x3C00; // DTMF Kill/ReLive Codes (@15360) +struct { + u8 kill_dtmf[6]; // 0: Kill DTMF + u8 ffpad1[2]; // Pad xFF + u8 revive_dtmf[6]; // 8: Revive DTMF + u8 ffpad2[2]; // Pad xFF +} settings_killswitch; + // Some unknown data between 0x3E00 and 0x3F00 +#seekto 0x3F80; // Hmm hmm +struct { + u8 unknown_data_0[16]; + u8 unknown_data_1; + u8 active; // Bool radio killed (killed=0, active=1) + u8 unknown_data_2[46]; +} management_settings; +struct band { + u8 enable; // 0 bool / enable-disable Tx on band + bbcd freq_low[2]; // 1 lowest band frequency + bbcd freq_high[2]; // 3 highest band frequency +}; +// #seekto 0x3FC0; // Bands settings (@16320) +struct { + struct band band136; // 0 Settings for 136MHz band + struct band band400; // 5 Settings for 400MHz band + struct band band200; // 10 Settings for 200MHz band + u8 byte_not_used1; // 15 + struct band band350; // 0 Settings for 350MHz band + u8 byte_not_used2[43]; // 5 +} settings_bands; +""" + +CMD_ACK = b"\x06" + +DTCS_CODES = tuple(sorted(chirp_common.DTCS_CODES + (645,))) + +DTMFCHARS = '0123456789ABCD*#' + + +def _enter_programming_mode(radio): + serial = radio.pipe + + exito = False + for i in range(0, 5): + serial.write(radio._magic) + ack = serial.read(1) + + try: + if ack == CMD_ACK: + exito = True + break + except Exception: + LOG.debug("Attempt #%s, failed, trying again" % i) + pass + + # check if we had EXITO + if exito is False: + msg = "The radio did not accept program mode after five tries.\n" + msg += "Check you interface cable and power cycle your radio." + raise errors.RadioError(msg) + + try: + serial.write(b"F") + ident = serial.read(8) + except Exception: + raise errors.RadioError("Error communicating with radio") + + if not ident.startswith(radio._fingerprint) and not RT490_EXPERIMENTAL: + LOG.debug(util.hexprint(ident)) + raise errors.RadioError("Radio returned unknown identification string") + + +def _exit_programming_mode(radio): + serial = radio.pipe + try: + serial.write(b"E") + except Exception: + raise errors.RadioError("Radio refused to exit programming mode") + + +def _read_block(radio, block_addr, block_size): + serial = radio.pipe + + cmd = struct.pack(">cHb", b'R', block_addr, block_size) + expectedresponse = b"R" + cmd[1:] + LOG.debug("Reading block %04x..." % (block_addr)) + + try: + serial.write(cmd) + response = serial.read(4 + block_size) + if response[:4] != expectedresponse: + raise Exception("Error reading block %04x." % (block_addr)) + + block_data = response[4:] + except Exception: + raise errors.RadioError("Failed to read block at %04x" % block_addr) + + return block_data + + +def _write_block(radio, block_addr, block_size): + serial = radio.pipe + + cmd = struct.pack(">cHb", b'W', block_addr, block_size) + data = radio.get_mmap()[block_addr:block_addr + block_size] + + LOG.debug("Writing Data:") + LOG.debug(util.hexprint(cmd + data)) + + try: + serial.write(cmd + data) + if serial.read(1) != CMD_ACK: + raise Exception("No ACK") + except Exception: + raise errors.RadioError("Failed to send block " + "to radio at %04x" % block_addr) + + +def do_download(radio): + LOG.debug("download") + _enter_programming_mode(radio) + + data = b"" + + status = chirp_common.Status() + status.msg = "Cloning from radio" + + status.cur = 0 + status.max = radio._memsize + + for addr in range(0, radio._memsize, radio.BLOCK_SIZE): + status.cur = addr + radio.BLOCK_SIZE + radio.status_fn(status) + + block = _read_block(radio, addr, radio.BLOCK_SIZE) + data += block + + LOG.debug("Address: %04x" % addr) + LOG.debug(util.hexprint(block)) + + _exit_programming_mode(radio) + + return memmap.MemoryMapBytes(data) + + +def do_upload(radio): + status = chirp_common.Status() + status.msg = "Uploading to radio" + + _enter_programming_mode(radio) + + status.cur = 0 + status.max = radio._memsize + + for start_addr, end_addr in radio._ranges: + for addr in range(start_addr, end_addr, radio.BLOCK_SIZE): + status.cur = addr + radio.BLOCK_SIZE + radio.status_fn(status) + _write_block(radio, addr, radio.BLOCK_SIZE) + + _exit_programming_mode(radio) + + +@directory.register +class RT490Radio(chirp_common.CloneModeRadio): + """RADTEL RT-490""" + VENDOR = "Radtel" + MODEL = "RT-490" + BLOCK_SIZE = 0x40 # 64 bytes + BAUD_RATE = 9600 + NEEDS_COMPAT_SERIAL = False + + POWER_LEVELS = [chirp_common.PowerLevel("H", watts=5.00), + chirp_common.PowerLevel("L", watts=3.00)] + + # magic = progmode + modelType + garbage (works with any last char) + _magic = b"PROGROMJJCCU" + + # fingerprint is default band ranges of the radio + # the driver can change band ranges and fingerprint will + # change accordingly, so it is not used to verify radio id. + _fingerprint = b"\x01\x36\x01\x80\x04\x00\x05\x20" + + # Ranges of memory used when uploading data to radio + # same as official software + _ranges = [ + (0x0000, 0x2400), + (0x3400, 0x3C40), + (0x3FC0, 0x4000) + ] + + if RT490_EXPERIMENTAL: + # Experimental driver (already heavily tested) + _ranges = [(0x0000, 0x2400), (0x3400, 0x3C40), (0x3F80, 0x4000)] + + # Danger zone + # _ranges = [(0x0000, 0x2500), (0x3400, 0x3C40), (0x3E00, 0x4000)] + + # 16KB of memory, download read everything + # same as official software (remark: loops if overread :)) + _memsize = 16384 + + POWER_LEVELS_LIST = [str(i) for i in POWER_LEVELS] + FHSS_LIST = ['OFF', 'ENCRYPT 1', 'ENCRYPT 2', 'ENCRYPT 3', 'ENCRYPT 4'] + DCP_LIST = ['OFF', 'DCP1', 'DCP2', 'DCP3', 'DCP4'] # Same as FHSS ? + # # Seems yes + TUNING_STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 20.0, 25.0, 50.0] + TUNING_STEPS_LIST = [str(i)+' KHz' for i in TUNING_STEPS] + SIGNAL = [str(i) for i in range(1, 16)] + PTTID = ['OFF', 'BOT', 'EOT', 'Both'] + PTTIDDELAYS = ['0', '100ms', '200ms', '400ms', '600ms', '800ms', '1000ms'] + DTMF_SPEEDS = ['50ms', '100ms', '200ms', '300ms', '500ms'] + SIDEKEY_VALUEMAP = [('FM', 7), ('Tx Power', 10), ('Scan', 28), + ('Search', 29), ('PTT B', 1)] + KEY_CHARS = '0123456789ABCDEF' + FULL_CHARSET_ASCII = ("".join([chr(x) for x in range(ord(" "), + ord("~") + 1)] + [chr(x) for x in range(128, 255)] + + [chr(0)])) + VFO_SFTD = ['OFF', '+', '-'] + WORKMODES = ['VFO', 'Memory Mode'] + SAVEMODES = ['OFF', 'Normal', 'Super', 'Deep'] + DISPLAYMODES = ['Name', 'Freq', 'Memory ID'] + SCANMODES = ['TO', 'CO', 'SE'] + ALARMMODES = ['On Site', 'Send Sound', 'Send Code'] + TDRTXMODES = ['OFF', 'A', 'B'] + SCANDCSMODES = ['All', 'Receive', 'Transmit'] + POWERMESSAGES = ['Image', 'Voltage'] + FMRADIO = ['ON', 'OFF'] + ENABLERADIO = ['Killed', 'Active'] + CHANNELS = ['A', 'B'] + TOT_LIST = ['OFF'] + [str(i*30) + "s" for i in range(1, 9)] + VOX_LIST = ['OFF'] + [str(i) for i in range(1, 9)] + BACKLIGHT_TO = ['OFF', '5s', '10s', '15s', '20s', '30s', '1m', '2m', '3m'] + AUTOLOCK_TO = ['OFF', '5s', '10s', '15s'] + MENUEXIT_TO = ['5s', '10s', '15s', '20s', '25s', '30s', '35s', '40s', + '45s', '50s', '60s'] + SQUELCHLVLS = [str(i) for i in range(10)] + ANI_IDS = [str(i+1) for i in range(60)] + VOXDELAYLIST = [str(float(a)/10)+'s' for a in range(5, 21)] + DTMFSTLIST = ['OFF', 'DT Side Tone', 'ANI Side Tone', 'DT ST + ANI ST'] + RPTTONES = ['1000Hz', '1450Hz', '1750Hz', '2100Hz'] + RPTNOISE = [str(a)+'s' for a in range(11)] + _memory_size = _upper = 256 # Number of memory slots + _mem_params = (_upper-1) + _frs = _murs = _pmr = _gmrs = True + + @classmethod + def match_model(cls, filedata, filename): + return False + + def set_settings(self, settings): + for element in settings: + if not isinstance(element, RadioSetting): + self.set_settings(element) + continue + else: + self._set_setting(element) + + def _set_setting(self, setting): # WIP + _mem = self._memobj + key = setting.get_name() + val = setting.value + if key.startswith('dummy'): + return + elif key.startswith('settings_dtmfgroup.'): + if str(val) == "": + setattr(_mem.settings_dtmfgroup[int(key.split('@')[1])-1], + 'code', [0xFF]*5) + else: + tmp = [DTMFCHARS.index(c) for c in str(val)] + tmp += [0xFF] * (5 - len(tmp)) + setattr(_mem.settings_dtmfgroup[int(key.split('@')[1])-1], + 'code', tmp) + elif key.startswith('settings.'): + if key.endswith('_memidx'): + val = int(val) - 1 + if key.endswith('fmpreset'): + tmp = val.get_value() * 10 + setattr(_mem.settings, key.split('.')[1], tmp) + else: + setattr(_mem.settings, key.split('.')[1], int(val)) + elif key.startswith('settings_dtmf.'): + attr = key.split('.')[1] + setattr(_mem.settings_dtmf, attr, int(val)) + if attr.startswith('pttid'): + setattr(_mem.settings, attr, int(val)) + elif key.startswith('settings_sidekeys.'): + setattr(_mem.settings_sidekeys, key.split('.')[1], int(val)) + elif key.startswith('settings_vfo.'): # TODO rx/tx tones + tmp = key.split('.') + attr = tmp[2] + vfo = tmp[1] + # LOG.debug(">>> PRE key '%s'" % key) + # LOG.debug(">>> PRE val '%s'" % val) + if attr.startswith('rxfreq'): + value = chirp_common.parse_freq(str(val)) / 10 + for i in range(7, -1, -1): + _mem.settings_vfo[vfo].rxfreq[i] = value % 10 + value /= 10 + elif attr.startswith('offset'): + value = int(float(str(val)) * 10000) + for i in range(5, -1, -1): + _mem.settings_vfo[vfo].offset[i] = value % 10 + value /= 10 + else: + setattr(_mem.settings_vfo[vfo], attr, int(val)) + elif key.startswith('settings_bands.'): + tmp = key.split('.') + attr = tmp[2] + band = tmp[1] + setattr(_mem.settings_bands[band], attr, int(val)) + elif key.startswith('settings_killswitch.'): + attr = key.split('.')[1] + if attr.endswith('dtmf'): + if str(val) == "": + setattr(_mem.settings_killswitch, attr, + [0x01, 0x02, 0x01, 0x03, 0x01, 0x04]) + else: + setattr(_mem.settings_killswitch, attr, + [DTMFCHARS.index(c) for c in str(val)]) + elif attr.startswith('enable'): + setattr(_mem.settings_killswitch, attr, int(val)) + else: + LOG.debug(">>> TODO key '%s'" % key) + LOG.debug(">>> TODO val '%s'" % val) + elif key.startswith('custom_') or key.startswith('anicode') \ + or key.startswith('memcode'): + tmp = key.split('@') + if key.startswith('anicode'): + val = [DTMFCHARS.index(c) for c in str(val)] + val += [0xFF] * (6 - len(val)) + for i in range(10): + _mem[str(tmp[0])][int(tmp[2])]["ffpad"][i] = 0xFF + elif key.startswith('memcode'): + if len(str(val)) > 0: + tmpp = str(val).zfill(6) + val = self._encode_key(tmpp) + else: + val = (0xFF, 0xFF, 0xFF, 0xFF) + if key.startswith('custom_'): + for i in range(6): + _mem[str(tmp[0])][int(tmp[2])]["ffpad"][i] = 0xFF + setattr(_mem[str(tmp[0])][int(tmp[2])], str(tmp[1]), val) + elif key.startswith('management_settings'): + setattr(_mem.management_settings, key.split('.')[1], int(val)) + else: + LOG.debug(">>> TODO _set_setting key '%s'" % key) + LOG.debug(">>> TODO _set_setting val '%s'" % val) + + def _get_settings_bands(self): + _mem = self._memobj + ret = RadioSettingGroup('bands', 'Bands') + bands = [('136', _mem.settings_bands.band136), + ('200', _mem.settings_bands.band200), + ('350', _mem.settings_bands.band350), + ('400', _mem.settings_bands.band400)] + for label, band in bands: + rs = RadioSetting('settings_bands.band%s.enable' % label, + 'Enable Band %s' % label, + RadioSettingValueBoolean(band.enable)) + ret.append(rs) + rsi = RadioSettingValueInteger(1, 1000, band.freq_low) + # if label == '136' or label == '400': + # rsi.set_mutable(False) + rs = RadioSetting("settings_bands.band%s.freq_low" % label, + "Band %s Lower Limit (MHz) (EXPERIMENTAL)" + % label, rsi) + ret.append(rs) + rsi = RadioSettingValueInteger(1, 1000, band.freq_high) + # if label == '350': + # rsi.set_mutable(False) + rs = RadioSetting("settings_bands.band%s.freq_high" % label, + "Band %s Upper Limit (MHz) (EXPERIMENTAL)" + % label, rsi) + ret.append(rs) + return ret + + def _get_settings_ks(self): + _mem = self._memobj + ret = RadioSettingGroup('killswitch', 'Killswitch') + # Kill Enable/Disable enable_killsw + rsvb = RadioSettingValueBoolean(_mem.settings.enable_killsw) + ret.append(RadioSetting('settings.enable_killsw', + 'Enable Killswitch', rsvb)) + # Kill DTMF + cur = ''.join( + DTMFCHARS[i] + for i in _mem.settings_killswitch.kill_dtmf if int(i) < 0xF) + ret.append( + RadioSetting('settings_killswitch.kill_dtmf', 'DTMF Kill', + RadioSettingValueString(6, 6, cur, + autopad=False, + charset=DTMFCHARS))) + # Revive DTMF + cur = ''.join( + DTMFCHARS[i] + for i in _mem.settings_killswitch.revive_dtmf if int(i) < 0xF) + ret.append( + RadioSetting('settings_killswitch.revive_dtmf', 'DTMF Revive', + RadioSettingValueString(6, 6, cur, + autopad=False, + charset=DTMFCHARS))) + # Enable/Disable entire radio + rs = RadioSettingValueString(0, 255, "Can be used to revive radio") + rs.set_mutable(False) + ret.append(RadioSetting('dummy', 'Factory reserved', rs)) + tmp = 1 if int(_mem.management_settings.active) > 0 else 0 + ret.append(RadioSetting('management_settings.active', 'Radio Status', + RadioSettingValueList(self.ENABLERADIO, + self.ENABLERADIO[tmp]))) + return ret + + def _get_settings_dtmf(self): + _mem = self._memobj + dtmf = RadioSettingGroup('dtmf', 'DTMF') + # DTMF Group + msgs = ["Allowed chars (%s)" % DTMFCHARS, + "Input from 0 to 5 characters." + ] + for msg in msgs: + rsvs = RadioSettingValueString(0, 255, msg, autopad=False) + rsvs.set_mutable(False) + rs = RadioSetting('dummy_dtmf_msg_%i' % msgs.index(msg), + 'Input rule %i' % int(msgs.index(msg)+1), rsvs) + dtmf.append(rs) + for i in range(1, 16): + cur = ''.join( + DTMFCHARS[i] + for i in _mem.settings_dtmfgroup[i - 1].code if int(i) < 0xF) + dtmf.append( + RadioSetting( + 'settings_dtmfgroup.code@%i' % i, 'PTT ID Code %i' % i, + RadioSettingValueString(0, 5, cur, + autopad=False, + charset=DTMFCHARS))) + # DTMF Speed (on time in ms) + dtmf_speed_on = int(_mem.settings_dtmf.dtmf_speed_on) + if dtmf_speed_on > len(self.DTMF_SPEEDS)-1: + _mem.settings_dtmf.dtmf_speed_on = 0 + LOG.debug('DTMF Speed On overflow') + cur = self.DTMF_SPEEDS[dtmf_speed_on] + dtmf.append( + RadioSetting( + 'settings_dtmf.dtmf_speed_on', 'DTMF Speed (on time in ms)', + RadioSettingValueList(self.DTMF_SPEEDS, cur))) + # DTMF Speed (on time in ms) + dtmf_speed_off = int(_mem.settings_dtmf.dtmf_speed_off) + if dtmf_speed_off > len(self.DTMF_SPEEDS)-1: + _mem.settings_dtmf.dtmf_speed_off = 0 + LOG.debug('DTMF Speed Off overflow') + cur = self.DTMF_SPEEDS[dtmf_speed_off] + dtmf.append( + RadioSetting( + 'settings_dtmf.dtmf_speed_off', 'DTMF Speed (off time in ms)', + RadioSettingValueList(self.DTMF_SPEEDS, cur))) + # PTT ID + pttid = int(_mem.settings_dtmf.pttid) + if pttid > len(self.PTTID)-1: + _mem.settings_dtmf.pttid = 0 + LOG.debug('PTT ID overflow') + cur = self.PTTID[pttid] + dtmf.append( + RadioSetting( + 'settings_dtmf.pttid', 'Send DTMF Code (PTT ID)', + RadioSettingValueList(self.PTTID, cur))) + # PTT ID Delay + pttiddelay = int(_mem.settings.pttiddelay) + if pttiddelay > len(self.PTTIDDELAYS)-1: + _mem.settings.pttiddelay = 0 + LOG.debug('PTT ID Delay overflow') + cur = self.PTTIDDELAYS[pttiddelay] + rsvl = RadioSettingValueList(self.PTTIDDELAYS, cur) + dtmf.append(RadioSetting('settings.pttiddelay', + 'PTT ID Delay', rsvl)) + rsvl = RadioSettingValueList(self.DTMFSTLIST, + self.DTMFSTLIST[_mem.settings.dtmfst]) + dtmf.append(RadioSetting('settings.dtmfst', + 'DTMF Side Tone (Required for GPS ID)', rsvl)) + return dtmf + + def _get_settings_sidekeys(self): + _mem = self._memobj + ret = RadioSettingGroup('sidekeys', 'Side Keys') + rsvm = RadioSettingValueMap(self.SIDEKEY_VALUEMAP, + _mem.settings_sidekeys.pf2_short) + ret.append(RadioSetting('settings_sidekeys.pf2_short', + 'Side key 1 (PTT2) Short press', rsvm)) + rsvm = RadioSettingValueMap(self.SIDEKEY_VALUEMAP[:-1], + _mem.settings_sidekeys.pf2_long) + ret.append(RadioSetting('settings_sidekeys.pf2_long', + 'Side key 1 (PTT2) Long press', rsvm)) + rsvm = RadioSettingValueMap(self.SIDEKEY_VALUEMAP[:-1], + _mem.settings_sidekeys.pf3_short) + ret.append(RadioSetting('settings_sidekeys.pf3_short', + 'Side key 2 (PTT3) Short press', rsvm)) + rs = RadioSettingValueString(0, 255, "MONI") + rs.set_mutable(False) + ret.append(RadioSetting('dummy', 'Side key 2 (PTT3) Long press', rs)) + return ret + + def _get_settings_vfo(self, vfo, chan): # WIP TODO Rx/Tx tones + _mem = self._memobj + ret = RadioSettingGroup('settings_vfo@%s' % chan.lower(), + 'VFO %s Settings' % chan) + rsvl = RadioSettingValueList(self.WORKMODES, + self.WORKMODES[_mem.settings[ + 'workmode'+chan.lower()]]) + ret.append(RadioSetting('settings.workmode%s' % chan.lower(), + 'VFO %s Workmode' % chan, rsvl)) + tmp = ''.join(DTMFCHARS[i] for i in _mem.settings_vfo[ + 'vfo_'+chan.lower()].rxfreq if i < 0xFF) + rsvf = RadioSettingValueFloat(66, 550, chirp_common.format_freq( + int(tmp) * 10), resolution=0.00001, + precision=5) + ret.append(RadioSetting('settings_vfo.vfo_%s.rxfreq' % chan.lower(), + 'Rx Frequency', rsvf)) + # TODO Rx/Tx tones + rsvl = RadioSettingValueList(self.VFO_SFTD, + self.VFO_SFTD[_mem.settings_vfo[ + 'vfo_'+chan.lower()].sftd]) + ret.append(RadioSetting('settings_vfo.vfo_%s.sftd' % chan.lower(), + 'Freq offset direction', rsvl)) + tmp = ''.join(DTMFCHARS[i] for i in _mem.settings_vfo[ + 'vfo_'+chan.lower()].offset if i < 0xFF) + rsvf = RadioSettingValueFloat(0, 99.9999, float(tmp) / 10000) + ret.append(RadioSetting('settings_vfo.vfo_%s.offset' % chan.lower(), + 'Tx Offset', rsvf)) + rsvl = RadioSettingValueList(self.SIGNAL, + self.SIGNAL[ + _mem.settings_vfo[ + 'vfo_'+chan.lower()].signal]) + ret.append(RadioSetting('settings_vfo.vfo_%s.signal' % chan.lower(), + 'PTT ID Code (S-Code)', rsvl)) + rsvl = RadioSettingValueList(self.POWER_LEVELS_LIST, + self.POWER_LEVELS_LIST[ + _mem.settings_vfo[ + 'vfo_'+chan.lower()].power]) + ret.append(RadioSetting('settings_vfo.vfo_%s.power' % chan.lower(), + 'Tx Power', rsvl)) + rsvl = RadioSettingValueList(self.FHSS_LIST, + self.FHSS_LIST[ + _mem.settings_vfo[ + 'vfo_'+chan.lower()].fhss]) + ret.append(RadioSetting('settings_vfo.vfo_%s.fhss' % chan.lower(), + 'FHSS (Encryption)', rsvl)) + rsvl = RadioSettingValueList(['Wide', 'Narrow'], + ['Wide', 'Narrow'][ + _mem.settings_vfo[ + 'vfo_'+chan.lower()].narrow]) + ret.append(RadioSetting('settings_vfo.vfo_%s.narrow' % chan.lower(), + 'Wide / Narrow', rsvl)) + rsvl = RadioSettingValueList(self.TUNING_STEPS_LIST, + self.TUNING_STEPS_LIST[ + _mem.settings_vfo[ + 'vfo_'+chan.lower()].freqstep]) + ret.append(RadioSetting('settings_vfo.vfo_%s.freqstep' % chan.lower(), + 'Tuning Step', rsvl)) + return ret + + def _get_custom_channel_names(self): + _mem = self._memobj + ret = RadioSettingGroup('ccn', 'Custom Channel Names') + msgs = ["Add custom chan names to radio", + "-> Menu 09 CH-NAME", + "Allowed chars (ASCII only)", + "Input from 0 to 10 characters." + ] + for msg in msgs: + rsvs = RadioSettingValueString(0, 255, msg, autopad=False) + rsvs.set_mutable(False) + rs = RadioSetting('dummy_cnames_msg_%i' % msgs.index(msg), + 'Input rule %i' % int(msgs.index(msg)+1), rsvs) + ret.append(rs) + for i in range(0, len(_mem.custom_channel_names)): + tmp = ''.join([str(j) for j in _mem.custom_channel_names[i].name + if ord(str(j)) < 0xFF and ord(str(j)) > 0x00]) + rsvs = RadioSettingValueString(0, 10, tmp, autopad=True, + charset=self.FULL_CHARSET_ASCII) + ret.append(RadioSetting('custom_channel_names@name@%i' % i, + 'Custom Channel Name (%i)' % i, rsvs)) + return ret + + def _get_custom_ani_names(self): + _mem = self._memobj + ret = RadioSettingGroup('can', 'Custom ANI Names') + msgs = ["Can be used as radio id in GPS.", + "Allowed chars (ASCII only)", + "Input from 0 to 10 characters." + ] + for msg in msgs: + rsvs = RadioSettingValueString(0, 255, msg, autopad=False) + rsvs.set_mutable(False) + rs = RadioSetting('dummy_caninames_msg_%i' % msgs.index(msg), + 'Input rule %i' % int(msgs.index(msg)+1), rsvs) + ret.append(rs) + for i in range(0, len(_mem.custom_ani_names)): + tmp = ''.join([str(j) for j in + _mem.custom_ani_names[i].name + if ord(str(j)) < 0xFF and ord(str(j)) > 0x00]) + rsvs = RadioSettingValueString(0, 10, tmp, autopad=True, + charset=self.FULL_CHARSET_ASCII) + ret.append(RadioSetting('custom_ani_names@name@%i' % i, + 'Custom ANI Name (%i)' % (i+51), rsvs)) + return ret + + def _get_anicodes(self): + _mem = self._memobj + ret = RadioSettingGroup('ani', 'ANI Codes') + split = len(_mem.anicodes) - len(_mem.custom_ani_names) + msgs = ["Allowed chars (%s)" % DTMFCHARS, + "Input from 0 to 6 characters." + ] + for msg in msgs: + rsvs = RadioSettingValueString(0, 255, msg, autopad=False) + rsvs.set_mutable(False) + rs = RadioSetting('dummy_canic_msg_%i' % msgs.index(msg), + 'Input rule %i' % int(msgs.index(msg)+1), rsvs) + ret.append(rs) + + for i in range(0, split): + tmp = ''.join([DTMFCHARS[int(j)] for j in + _mem.anicodes[i].anicode if int(j) < 0xFF]) + # LOG.debug("ANI Code (%i) '%s'" % (i, tmp)) + rsvs = RadioSettingValueString(0, 6, tmp, autopad=False, + charset=DTMFCHARS) + ret.append(RadioSetting('anicodes@anicode@%i' % i, + 'ANI-ID (%i) Code' % (i+1), rsvs)) + for i in range(split, len(_mem.anicodes)): + tmp = ''.join([DTMFCHARS[int(j)] for j in + _mem.anicodes[i].anicode if int(j) < 0xFF]) + tmp2 = ''.join([str(j) for j in + _mem.custom_ani_names[i-split].name + if ord(str(j)) < 0xFF and ord(str(j)) > 0x00]) + # LOG.debug("ANI Code (%s) (%i) '%s'" % (tmp2, i, tmp)) + rsvs = RadioSettingValueString(0, 6, tmp, autopad=False, + charset=DTMFCHARS) + ret.append(RadioSetting('anicodes@anicode@%i' % i, + 'ANI-ID (%s) (%i) Code' % (tmp2, i+1), rsvs)) + return ret + + def _get_settings_adv(self): + _mem = self._memobj + ret = RadioSettingGroup('advanced', 'Advanced') + if RT490_EXPERIMENTAL: + rsvi = RadioSettingValueInteger( + 1, self._memory_size, int(_mem.settings.cha_memidx)+1) + ret.append(RadioSetting("settings.cha_memidx", + "Channel A Memory index", rsvi)) + rsvi = RadioSettingValueInteger(1, self._memory_size, + int(_mem.settings.chb_memidx)+1) + ret.append(RadioSetting("settings.chb_memidx", + "Channel B Memory index", rsvi)) + ret.append(RadioSetting('settings.vox', 'VOX Sensitivity', + RadioSettingValueList(self.VOX_LIST, + self.VOX_LIST[_mem.settings.vox]))) + ret.append(RadioSetting('settings.vox_delay', 'VOX Delay', + RadioSettingValueList(self.VOXDELAYLIST, + self.VOXDELAYLIST[ + _mem.settings.vox_delay]))) + ret.append(RadioSetting('settings.tdr', 'Dual Receive (TDR)', + RadioSettingValueBoolean(_mem.settings.tdr))) + ret.append(RadioSetting('settings.txundertdr', 'Tx under TDR', + RadioSettingValueList(self.TDRTXMODES, + self.TDRTXMODES[ + _mem.settings.txundertdr]))) + ret.append(RadioSetting('settings.voice', 'Menu Voice Prompts', + RadioSettingValueBoolean(_mem.settings.voice))) + ret.append(RadioSetting('settings.scanmode', 'Scan Mode', + RadioSettingValueList(self.SCANMODES, + self.SCANMODES[ + _mem.settings.scanmode]))) + ret.append(RadioSetting('settings.bcl', 'Busy Channel Lockout', + RadioSettingValueBoolean(_mem.settings.bcl))) + ret.append(RadioSetting('settings.display_ani', 'Display ANI ID', + RadioSettingValueBoolean(_mem.settings.display_ani))) + ret.append(RadioSetting('settings.ani_id', 'ANI ID', + RadioSettingValueList(self.ANI_IDS, + self.ANI_IDS[_mem.settings.ani_id]))) + ret.append(RadioSetting('settings.alarm_mode', 'Alarm Mode', + RadioSettingValueList(self.ALARMMODES, + self.ALARMMODES[ + _mem.settings.alarm_mode]))) + ret.append(RadioSetting('settings.alarmsound', 'Alarm Sound', + RadioSettingValueBoolean(_mem.settings.alarmsound))) + ret.append(RadioSetting('settings.fmradio', 'Enable FM Radio', + RadioSettingValueList(self.FMRADIO, + self.FMRADIO[_mem.settings.fmradio]))) + if RT490_EXPERIMENTAL: + tmp = _mem.settings.fmpreset / 10.0 + if tmp < 65.0 or tmp > 108.0: + tmp = 80.0 + ret.append(RadioSetting("settings.fmpreset", "FM Radio Freq", + RadioSettingValueFloat(65, 108, tmp, resolution=0.1, + precision=1))) + ret.append(RadioSetting('settings.kblock', 'Enable Keyboard Lock', + RadioSettingValueBoolean(_mem.settings.kblock))) + ret.append(RadioSetting('settings.autolock', 'Autolock Keyboard', + RadioSettingValueList(self.AUTOLOCK_TO, + self.AUTOLOCK_TO[ + _mem.settings.autolock]))) + ret.append(RadioSetting('settings.timer_menu_quit', 'Menu Exit Time', + RadioSettingValueList(self.MENUEXIT_TO, + self.MENUEXIT_TO[ + _mem.settings.timer_menu_quit]))) + ret.append(RadioSetting('settings.enable_gps', 'Enable GPS', + RadioSettingValueBoolean(_mem.settings.enable_gps))) + ret.append(RadioSetting('settings.scan_dcs', 'CDCSS Save Modes', + RadioSettingValueList(self.SCANDCSMODES, + self.SCANDCSMODES[ + _mem.settings.scan_dcs]))) + ret.append(RadioSetting('settings.tailnoiseclear', 'Tail Noise Clear', + RadioSettingValueBoolean(_mem.settings.tailnoiseclear))) + ret.append(RadioSetting('settings.rptnoiseclear', 'Rpt Noise Clear', + RadioSettingValueList(self.RPTNOISE, + self.RPTNOISE[ + _mem.settings.rptnoiseclear]))) + ret.append(RadioSetting('settings.rptnoisedelay', 'Rpt Noise Delay', + RadioSettingValueList(self.RPTNOISE, + self.RPTNOISE[ + _mem.settings.rptnoisedelay]))) + ret.append(RadioSetting('settings.rpttone', 'Rpt Tone', + RadioSettingValueList(self.RPTTONES, + self.RPTTONES[ + _mem.settings.rpttone]))) + return ret + + def _get_settings_basic(self): + _mem = self._memobj + ret = RadioSettingGroup('basic', 'Basic') + ret.append(RadioSetting('settings.squelch', 'Carrier Squelch Level', + RadioSettingValueList(self.SQUELCHLVLS, + self.SQUELCHLVLS[ + _mem.settings.squelch]))) + ret.append(RadioSetting('settings.savemode', 'Battery Savemode', + RadioSettingValueList(self.SAVEMODES, + self.SAVEMODES[ + _mem.settings.savemode]))) + ret.append(RadioSetting('settings.backlight', 'Backlight Timeout', + RadioSettingValueList(self.BACKLIGHT_TO, + self.BACKLIGHT_TO[ + _mem.settings.backlight]))) + ret.append(RadioSetting('settings.timeout', 'Timeout Timer (TOT)', + RadioSettingValueList(self.TOT_LIST, + self.TOT_LIST[ + _mem.settings.timeout]))) + ret.append(RadioSetting('settings.beep', 'Beep', + RadioSettingValueBoolean(_mem.settings.beep))) + ret.append(RadioSetting('settings.active_channel', 'Active Channel', + RadioSettingValueList(self.CHANNELS, + self.CHANNELS[ + _mem.settings.active_channel]))) + ret.append(RadioSetting('settings.cha_disp', 'Channel A Display Mode', + RadioSettingValueList(self.DISPLAYMODES, + self.DISPLAYMODES[ + _mem.settings.cha_disp]))) + ret.append(RadioSetting('settings.chb_disp', 'Channel B Display Mode', + RadioSettingValueList(self.DISPLAYMODES, + self.DISPLAYMODES[ + _mem.settings.chb_disp]))) + ret.append(RadioSetting('settings.roger', 'Roger Beep', + RadioSettingValueBoolean(_mem.settings.roger))) + ret.append(RadioSetting('settings.powermsg', 'Power Message', + RadioSettingValueList(self.POWERMESSAGES, + self.POWERMESSAGES[ + _mem.settings.powermsg]))) + ret.append(RadioSetting('settings.rx_time', 'Show RX Time', + RadioSettingValueBoolean(_mem.settings.rx_time))) + return ret + + def _get_memcodes(self): + ret = RadioSettingGroup('mc', 'Memory Channel Privacy Codes') + msgs = ["Only hexadecimal chars accepted.", + "Allowed chars (%s)" % self.KEY_CHARS, + "Input from 0 to 6 characters. If code", + "length is less than 6 chars it will be", + "padded with leading zeros.", + "Ex: 1D32EB or 0F12 or AB521, etc...", + "Enable Code for the Location on the", + "'Other' tab in 'Memory Properties'." + ] + for msg in msgs: + rsvs = RadioSettingValueString(0, 255, msg, autopad=False) + rsvs.set_mutable(False) + rs = RadioSetting('dummy_memcodes_msg_%i' % msgs.index(msg), + 'Input rule %i' % int(msgs.index(msg)+1), rsvs) + ret.append(rs) + for i in range(self._memory_size): + code = "" + if self._memobj.memcode[i].code[3] < 0xFF: + code = self._decode_key(self._memobj.memcode[i].code) + code = code.zfill(6) + rsvs = RadioSettingValueString(0, 6, code, autopad=False, + charset=self.KEY_CHARS) + rs = RadioSetting('memcode@code@%i' % i, + 'Memory Location (%i) Privacy Code' % + int(i+1), rsvs) + ret.append(rs) + return ret + + def get_settings(self): + radio_settings = [] + basic = self._get_settings_basic() + radio_settings.append(basic) + adv = self._get_settings_adv() + radio_settings.append(adv) + vfoa = self._get_settings_vfo(self._memobj.settings_vfo.vfo_a, 'A') + radio_settings.append(vfoa) + vfob = self._get_settings_vfo(self._memobj.settings_vfo.vfo_b, 'B') + radio_settings.append(vfob) + sk = self._get_settings_sidekeys() + radio_settings.append(sk) + dtmf = self._get_settings_dtmf() + radio_settings.append(dtmf) + ccn = self._get_custom_channel_names() + radio_settings.append(ccn) + can = self._get_custom_ani_names() + radio_settings.append(can) + ani = self._get_anicodes() + radio_settings.append(ani) + mcodes = self._get_memcodes() + radio_settings.append(mcodes) + if RT490_EXPERIMENTAL: + ks = self._get_settings_ks() + radio_settings.append(ks) + bands = self._get_settings_bands() + radio_settings.append(bands) + top = RadioSettings(*radio_settings) + return top + + def get_raw_memory(self, number): + return repr(self._memobj.memory[number]) + + # TODO Add Code when RadioSettingValueString is fixed + def _get_extra(self, _mem, num): + group = RadioSettingGroup('extra', 'Extra') + # LOG.debug("Get extra %i" % num) + + s = RadioSetting('bcl', 'Busy Channel Lockout', + RadioSettingValueBoolean(_mem.bcl)) + group.append(s) + + dcp = int(_mem.dcp) + if dcp > len(self.FHSS_LIST)-1: + _mem.dcp = cur = 0 + LOG.debug('DCP ID / FHSS overflow for channel %d' % num) + cur = self.FHSS_LIST[dcp] + s = RadioSetting('dcp', 'FHSS (Encryption)', + RadioSettingValueList(self.FHSS_LIST, cur)) + group.append(s) + + # Does not work, no error, why ??? TODO + """ + code = "" + if self._memobj.memcode[num-1].code[3] < 0xFF: + code = self._decode_key(self._memobj.memcode[num-1].code) + code = code.zfill(6) + LOG.debug('CODE "%s"' % code) + s = RadioSetting('dcp_code', 'DCP code', + RadioSettingValueString(0, 6, code, + autopad=False, + charset=self.KEY_CHARS)) + group.append(s) """ + + pttid = int(_mem.pttid) + if pttid > len(self.PTTID)-1: + _mem.pttid = cur = 0 + LOG.debug('PTTID overflow for channel %d' % num) + cur = self.PTTID[pttid] + s = RadioSetting('pttid', 'Send DTMF Code (PTT ID)', + RadioSettingValueList(self.PTTID, cur)) + group.append(s) + + cur = self.SIGNAL[int(_mem.signal)] + s = RadioSetting('signal', 'PTT ID Code (S-Code)', + RadioSettingValueList(self.SIGNAL, cur)) + group.append(s) + + s = RadioSetting('learn', + 'Use Memory Privacy Code as Tx/Rx DCS (Learn)', + RadioSettingValueBoolean(_mem.learn)) + group.append(s) + + return group + + # TODO Add Code when RadioSettingValueString is fixed + def _set_extra(self, _mem, mem): + # memidx = mem.number - 1 # commented because not used + _mem.bcl = int(mem.extra['bcl'].value) + _mem.dcp = int(mem.extra['dcp'].value) + _mem.pttid = int(mem.extra['pttid'].value) + _mem.signal = int(mem.extra['signal'].value) + # self._memobj.memcode[mem.number].code = \ + # self._encode_key(mem.extra['dcp_code'].value) + if (int(mem.extra['learn'].value) > 0) and \ + (self._memobj.memcode[mem.number-1].code[3] == 0xA0): + _mem.learn = 1 + elif (int(mem.extra['learn'].value) > 0) and \ + (self._memobj.memcode[mem.number-1].code[3] != 0xA0): + _mem.learn = 0 + raise InvalidValueError( + "Use Memory Privacy Code as Tx/Rx DCS (Learn) requires " + "that a memory code has been previously set for this memory." + "Go in 'Settings' -> 'Memory Channel Privacy Codes' and set " + "a code for the current memory before enabling 'Learn'.") + else: + _mem.learn = 0 + + def _is_txinh(self, _mem): + raw_tx = b"" + for i in range(0, 4): + raw_tx += _mem.txfreq[i].get_raw() + return raw_tx == b"\xFF\xFF\xFF\xFF" + + def get_memory(self, num): + memidx = num - 1 + _mem = self._memobj.memory[memidx] + _nam = self._memobj.memname[memidx] + + mem = chirp_common.Memory() + mem.number = num + if int(_mem.rxfreq) == 166666665: + mem.empty = True + return mem + + mem.name = ''.join([str(c) for c in _nam.name + if ord(str(c)) < 127]).rstrip() + mem.freq = int(_mem.rxfreq) * 10 + offset = (int(_mem.txfreq) - int(_mem.rxfreq)) * 10 + if self._is_txinh(_mem) or _mem.tx_enable == 0: + mem.duplex = 'off' + # _mem.txfreq = _mem.rxfreq # TODO REMOVE (force fix broken saves) + elif offset == 0: + mem.duplex = '' + mem.offset = 0 + elif abs(offset) < 100000000: + mem.duplex = offset < 0 and '-' or '+' + mem.offset = abs(offset) + else: + mem.duplex = 'split' + mem.offset = int(_mem.txfreq) * 10 + + mem.power = self.POWER_LEVELS[_mem.power] + + if _mem.unknown3_0 and _mem.narrow: + mem.mode = 'NAM' + elif _mem.unknown3_0 and not _mem.narrow: + mem.mode = 'AM' + elif not _mem.unknown3_0 and _mem.narrow: + mem.mode = 'NFM' + elif not _mem.unknown3_0 and not _mem.narrow: + mem.mode = 'FM' + else: + LOG.exception('Failed to get mode for %i' % num) + + mem.skip = '' if _mem.scan else 'S' + + # LOG.warning('got txtone: %s' % repr(self._decode_tone(_mem.txtone))) + # LOG.warning('got rxtone: %s' % repr(self._decode_tone(_mem.rxtone))) + txtone = self._decode_tone(_mem.txtone) + rxtone = self._decode_tone(_mem.rxtone) + chirp_common.split_tone_decode(mem, txtone, rxtone) + try: + mem.extra = self._get_extra(_mem, num) + except Exception: + LOG.exception('Failed to get extra for %i' % num) + return mem + + def set_memory(self, mem): + memidx = mem.number - 1 + _mem = self._memobj.memory[memidx] + _nam = self._memobj.memname[memidx] + + if mem.empty: + _mem.set_raw(b'\xff' * 16) + _nam.set_raw(b'\xff' * 16) + return + + if int(_mem.rxfreq) == 166666665: + LOG.debug('Initializing new memory %i' % memidx) + _mem.set_raw(b'\x00' * 16) + + _nam.name = mem.name.ljust(12, chr(255)) # with xFF pad (mimic factory + # behavior) + + _mem.rxfreq = mem.freq / 10 + _mem.tx_enable = 1 + if mem.duplex == '': + _mem.txfreq = mem.freq / 10 + elif mem.duplex == 'split': + _mem.txfreq = mem.offset / 10 + elif mem.duplex == 'off': + _mem.tx_enable = 0 + _mem.txfreq = mem.freq / 10 # Optional but keeps compat with + # vendor software + elif mem.duplex == '-': + _mem.txfreq = (mem.freq - mem.offset) / 10 + elif mem.duplex == '+': + _mem.txfreq = (mem.freq + mem.offset) / 10 + else: + raise errors.RadioError('Unsupported duplex mode %r' % mem.duplex) + + txtone, rxtone = chirp_common.split_tone_encode(mem) + # LOG.warning('tx tone is %s' % repr(txtone)) + # LOG.warning('rx tone is %s' % repr(rxtone)) + _mem.txtone = self._encode_tone(*txtone) + _mem.rxtone = self._encode_tone(*rxtone) + + try: + _mem.power = self.POWER_LEVELS.index(mem.power) + except ValueError: + _mem.power = 0 + + if int(_mem.rxfreq) < 30000000: + _mem.unknown3_0 = mem.mode in ['AM', 'NAM'] + else: + _mem.unknown3_0 = 0 + _mem.narrow = mem.mode[0] == 'N' + + _mem.scan = mem.skip != 'S' + + if mem.extra: + self._set_extra(_mem, mem) + + def sync_out(self): + try: + do_upload(self) + except errors.RadioError: + # Pass through any real errors we raise + raise + except Exception: + # If anything unexpected happens, make sure we raise + # a RadioError and log the problem + LOG.exception('Unexpected error during upload') + raise errors.RadioError('Unexpected error communicating ' + 'with the radio') + + def sync_in(self): + """Download from radio""" + try: + data = do_download(self) + except errors.RadioError: + # Pass through any real errors we raise + raise + except Exception: + # If anything unexpected happens, make sure we raise + # a RadioError and log the problem + LOG.exception('Unexpected error during download') + raise errors.RadioError('Unexpected error communicating ' + 'with the radio') + self._mmap = data + self.process_mmap() + + def process_mmap(self): + self._memobj = bitwise.parse(MEM_FORMAT_RT490 % + {"memsize": self._memory_size}, + self._mmap) + + def get_features(self): # GOOD ? + rf = chirp_common.RadioFeatures() + rf.has_settings = True + rf.has_bank = False + rf.has_cross = True + rf.has_rx_dtcs = True + rf.has_dtcs_polarity = True + rf.has_tuning_step = False + rf.can_odd_split = True + rf.has_name = True + rf.valid_name_length = 12 + rf.valid_skips = ["", "S"] + rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"] + rf.valid_cross_modes = ["Tone->Tone", "DTCS->", "->DTCS", "Tone->DTCS", + "DTCS->Tone", "->Tone", "DTCS->DTCS"] + rf.valid_power_levels = self.POWER_LEVELS + rf.valid_duplexes = ["", "+", "-", "split", "off"] + rf.valid_modes = ["FM", "NFM", "AM", "NAM"] + rf.memory_bounds = (1, 256) + rf.valid_tuning_steps = self.TUNING_STEPS + rf.valid_bands = [(108000000, 136000000), + (136000000, 180000000), + (200000000, 260000000), + (350000000, 400000000), + (400000000, 520000000)] + return rf + + @classmethod + def get_prompts(cls): + rp = chirp_common.RadioPrompts() + rp.pre_upload = _("This driver is in development and should be " + "considered as experimental.") + rp.experimental = _("This driver is in development and should be " + "considered as experimental.") + rp.info = _("This driver is in development and should be considered " + "as experimental.") + return rp + + def _encode_key(self, key): + arr = bytearray(4) + arr[3] = 160 + arr[2] = self.KEY_CHARS.index(key[0]) # << 4 + arr[2] = arr[2] << 4 + arr[2] |= self.KEY_CHARS.index(key[1]) + arr[1] = self.KEY_CHARS.index(key[2]) # << 4 + arr[1] = arr[1] << 4 + arr[1] |= self.KEY_CHARS.index(key[3]) + arr[0] = self.KEY_CHARS.index(key[4]) # << 4 + arr[0] = arr[0] << 4 + arr[0] |= self.KEY_CHARS.index(key[5]) + return arr + + def _decode_key(self, key): + ret = "" + if key[3] == 0xA0: + ret += self.KEY_CHARS[key[2] >> 4] + ret += self.KEY_CHARS[key[2] & 0xF] + ret += self.KEY_CHARS[key[1] >> 4] + ret += self.KEY_CHARS[key[1] & 0xF] + ret += self.KEY_CHARS[key[0] >> 4] + ret += self.KEY_CHARS[key[0] & 0xF] + LOG.debug('DCP Code: "%s"' % ret) + return ret + + def _decode_tone(self, toneval): + if toneval in (0, 0xFFFF): + # LOG.debug('no tone value: %s' % toneval) + return None, None, None + elif toneval < 670: + toneval = toneval - 1 + index = toneval % len(DTCS_CODES) + if index != int(toneval): + pol = 'R' + # index -= 1 + else: + pol = 'N' + return 'DTCS', DTCS_CODES[index], pol + else: + return 'Tone', toneval / 10.0, 'N' + + def _encode_tone(self, mode, val, pol): + if not mode: + return 0x0000 + elif mode == 'Tone': + return int(val * 10) + elif mode == 'DTCS': + index = DTCS_CODES.index(val) + if pol == 'R': + index += len(DTCS_CODES) + index += 1 + # LOG.debug('Encoded dtcs %s/%s to %04x' % (val, pol, index)) + return index + else: + raise errors.RadioError('Unsupported tone mode %r' % mode) + + +@directory.register +class MML8629Radio(RT490Radio): + """MMLradio JC-8629""" + VENDOR = "MMLradio" + MODEL = "JC-8629" + + +@directory.register +class JJCC8629Radio(RT490Radio): + """JJCC JC-8629""" + VENDOR = "JJCC" + MODEL = "JC-8629" + + +@directory.register +class SocotranJC8629Radio(RT490Radio): + """Socotran JC-8629""" + VENDOR = "Socotran" + MODEL = "JC-8629" + + +@directory.register +class SocotranFB8629Radio(RT490Radio): + """Socotran FB-8629""" + VENDOR = "Socotran" + MODEL = "FB-8629" + + +@directory.register +class Jianpai8629Radio(RT490Radio): + """Jianpai 8800 Plus""" + VENDOR = "Jianpai" + MODEL = "8800_Plus" + + +@directory.register +class Boristone8RSRadio(RT490Radio): + """Boristone 8RS""" + VENDOR = "Boristone" + MODEL = "8RS" + + +@directory.register +class AbbreeAR869Radio(RT490Radio): + """Abbree AR-869""" + VENDOR = "Abbree" + MODEL = "AR-869" + + +@directory.register +class HamGeekHG590Radio(RT490Radio): + """HamGeek HG-590""" + VENDOR = "HamGeek" + MODEL = "HG-590" + + +IMHEX_DESC = """ +// Perfect tool for binary reverse engineering +// https://github.com/WerWolv/ImHex +// Below is the pattern +""" +IMHEX_PATTERN = """ +struct memory { // Memory settings + u8 rxfreq[4]; + u8 txfreq[4]; + u16 rxtone; + u16 txtone; + u8 signal; // int 0->14, Signal 1->15 + u8 pttid; // ['OFF', 'BOT', 'EOT', 'Both'] + u8 dcp_power; // POWER_LEVELS + u8 unknown3_0_narrow_unknown3_1_bcl_scan_tx_enable_learn; // bool ??? TODO +}; +struct memname { + char name[12]; + padding[4]; +}; +struct memcode { + u8 code[4]; +}; +struct custom_ani_names { + char name[12]; + padding[4]; +}; +struct anicodes { + u8 anicode[6]; + padding[10]; +}; +struct custom_channel_names { + char name[12]; + padding[4]; +}; +bitfield workmode { + b : 4; + a : 4; +}; +struct settings { + u8 squelch; // 0: int 0 -> 9 + u8 savemode; // 1: ['OFF', 'Normal', 'Super', 'Deep'] + u8 vox; // 2: off=0, 1 -> 9 + u8 backlight; // 3: ['OFF', '5s', '15s', '20s', '30s', '1m', '2m', + // '3m'] + u8 tdr; // 4: bool + u8 timeout; // 5: n*30seconds, 0-240s + u8 beep; // 6: bool + u8 voice; // 7: bool + u8 byte_not_used_10; // 8: Allways 1 + u8 dtmfst; // 9: ['OFF', 'KB Side Tone', 'ANI Side Tone', + // 'KB ST + ANI ST'] + u8 scanmode; // 10: ['TO', 'CO', 'SE'] + u8 pttid; // 11: ['OFF', 'BOT', 'EOT', 'Both'] + u8 pttiddelay; // 12: ['0', '100ms', '200ms', '400ms', '600ms', + // '800ms', '1000ms'] + u8 cha_disp; // 13: ['Name', 'Freq', 'Channel ID'] + u8 chb_disp; // 14: ['Name', 'Freq', 'Channel ID'] + u8 bcl; // 15: bool + u8 autolock; // 0: ['OFF', '5s', '10s', 15s'] + u8 alarm_mode; // 1: ['Site', 'Tone', 'Code'] + u8 alarmsound; // 2: bool + u8 txundertdr; // 3: ['OFF', 'A', 'B'] + u8 tailnoiseclear; // 4: [off, on] + u8 rptnoiseclear; // 5: n*100ms, 0-1000 + u8 rptnoisedelay; // 6: n*100ms, 0-1000 + u8 roger; // 7: bool + u8 active_channel; // 8: 0 or 1 + u8 fmradio; // 9: boolean, inverted + workmode _workmode; // 10: up ['VFO', 'CH Mode'] + u8 kblock; // 11: bool // TODO TEST WITH autolock + u8 powermsg; // 12: 0=Image / 1=Voltage + u8 byte_not_used_21; // 13: Allways 0 + u8 rpttone; // 14: ['1000Hz', '1450Hz', '1750Hz', '2100Hz'] + u8 byte_not_used_22; // 15: pad with xFF + u8 vox_delay; // 0: [str(float(a)/10)+'s' for a in range(5,21)] + // '0.5s' to '2.0s' + u8 timer_menu_quit; // 1: ['5s', '10s', '15s', '20s', '25s', '30s', + // '35s', '40s', '45s', '50s', '60s'] + u8 byte_not_used_30; // 2: pad with xFF + u8 byte_not_used_31; // 3: pad with xFF + u8 enable_killsw; // 4: bool + u8 display_ani; // 5: bool + u8 byte_not_used_32; // 6: pad with xFF + u8 enable_gps; // 7: bool + u8 scan_dcs; // 8: ['All', 'Receive', 'Transmit'] + u8 ani_id; // 9: int 0-59 (ANI 1-60) + u8 rx_time; // 10: bool + padding[5]; // 11: Pad xFF + u8 cha_memidx; // 0: Memory index when channel A use memories + u8 byte_not_used_40; + u8 chb_memidx; // 2: Memory index when channel B use memories + u8 byte_not_used_41; + padding[10]; + u16 fmpreset; +}; +struct settings_vfo_chan { + u8 rxfreq[8]; // 0 + u16 rxtone; // 8 + u16 txtone; // 10 + u16 byte_not_used0; // 12 Pad xFF + u8 sftd_signal; // 14 int 0->14, Signal 1->15 + u8 byte_not_used1; // 15 Pad xFF + u8 power; // 16:0 POWER_LEVELS + u8 fhss_narrow; // 17 bool true=NFM false=FM + u8 byte_not_used2; // 18 Pad xFF but received 0x00 ??? + u8 freqstep; // 19:3 ['2.5 KHz', '5.0 KHz', '6.25 KHz', + // '10.0 KHz', '12.5 KHz', '20.0 KHz', + // '25.0 KHz', '50.0 KHz'] + u8 byte_not_used3; // 20:4 Pad xFF but received 0x00 ??? TODO + u8 offset[6]; // 21:5 Freq NN.NNNN (without the dot) TEST TEST + u8 byte_not_used4; // 27:11 Pad xFF + u8 byte_not_used5; // 28 Pad xFF + u8 byte_not_used6; // 29 Pad xFF + u8 byte_not_used7; // 30 Pad xFF + u8 byte_not_used8; // 31:15 Pad xFF +}; +struct settings_vfo { + settings_vfo_chan vfo_a; + settings_vfo_chan vfo_b; +}; +struct settings_sidekeys { // Values from Radio + u8 pf2_short; // { '7': 'FM', '10': 'Tx Power', '28': 'Scan', + // '29': 'Search, '1': 'PPT B' } + u8 pf2_long; // { '7': 'FM', '10': 'Tx Power', '28': 'Scan', + // '29': 'Search' } + u8 pf3_short; // { '7': 'FM', '10': 'Tx Power', '28': 'Scan', + // '29': 'Search' } + u8 ffpad; // Pad xFF +}; +struct dtmfcode { + u8 code[5]; // 5 digits DTMF + padding[11]; // Pad xFF +}; +struct settings_dtmf { // @15296+3x16 + u8 byte_not_used1; // 0: Pad xFF + u8 byte_not_used2; // 1: Pad xFF + u8 byte_not_used3; // 2: Pad xFF + u8 byte_not_used4; // 3: Pad xFF + u8 byte_not_used5; // 4: Pad xFF + u8 unknown_dtmf; // 5: 0 TODO ???? wtf is alarmcode/alarmcall TODO + u8 pttid; // 6: [off, BOT, EOT, Both] + u8 dtmf_speed_on; // 7: ['50ms', '100ms', '200ms', '300ms', '500ms'] + u8 dtmf_speed_off; // 8:0 ['50ms', '100ms', '200ms', '300ms', '500ms'] +}; +struct settings_dtmf_global { + dtmfcode settings_dtmfgroup[15]; + settings_dtmf _settings_dtmf; +}; +struct settings_killswitch { + u8 kill_dtmf[6]; // 0: Kill DTMF + padding[2]; // Pad xFF + u8 revive_dtmf[6]; // 8: Revive DTMF + padding[2]; // Pad xFF +}; +struct management_settings { + u8 unknown_data_0[16]; + u8 unknown_data_1; + u8 active; // Bool radio killed (killed=0, active=1) + padding[46]; +}; +struct band { + u8 enable; // 0 bool / enable-disable Tx on band + u8 freq_low[2]; // 1 lowest band frequency + u8 freq_high[2]; // 3 highest band frequency +}; +struct settings_bands { + band band136; // 0 Settings for 136MHz band + band band400; // 5 Settings for 400MHz band + band band200; // 10 Settings for 200MHz band + padding[1]; // 15 + band band350; // 0 Settings for 350MHz band + padding[43];// 5 +}; + +memory mem[256] @ 0x0000; +memname mname[256] @ 0x1000; +memcode mcode[256] @ 0x2000; +custom_ani_names caninames[10] @ 0x3400; +anicodes anic[60] @ 0x3500; +custom_channel_names ccnames[10] @ 0x3900; +settings _settings @ 0x3A00; +settings_vfo _settings_vfo @ 0x3A40; +settings_sidekeys _settings_sidekeys @ 0x3A80; +settings_dtmf_global _settings_dtmf_global @ 0x3B00; +settings_killswitch _settings_killswitch @ 0x3C00; +management_settings _management_settings @ 0x3F80; +settings_bands _settings_bands @ 0x3FC0; +""" diff --git a/chirp/drivers/radtel_t18.py b/chirp/drivers/radtel_t18.py index 5401511..2dacd11 100644 --- a/chirp/drivers/radtel_t18.py +++ b/chirp/drivers/radtel_t18.py @@ -41,6 +41,18 @@ struct { bcl:1; u8 unknown3[3]; } memory[%d]; +#seekto 0x02B0; +struct { + u8 voicesw; // Voice SW + + u8 voiceselect; // Voice Select + u8 scan; // Scan + + u8 vox; // VOX + + u8 voxgain; // Vox Gain + + u8 voxnotxonrx; // Rx Disable Vox + + u8 hivoltnotx; // High Vol Inhibit TX + + u8 lovoltnotx; // Low Vol Inhibit TX + + u8 rxemergency; // RX Emergency +} settings2; #seekto 0x03C0; struct { u8 codesw:1, // Retevis RB29 code switch @@ -70,19 +82,6 @@ struct { power10w:1; // Retevis RT85 power 10w on/off // Retevis RT75 stop TX with low voltage } settings; - -#seekto 0x02B0; -struct { - u8 voicesw; // Voice SW + - u8 voiceselect; // Voice Select - u8 scan; // Scan + - u8 vox; // VOX + - u8 voxgain; // Vox Gain + - u8 voxnotxonrx; // Rx Disable Vox + - u8 hivoltnotx; // High Vol Inhibit TX + - u8 lovoltnotx; // Low Vol Inhibit TX + - u8 rxemergency; // RX Emergency -} settings2; """ MEM_FORMAT_RB18 = """ @@ -132,6 +131,45 @@ struct { } settings; """ +MEM_FORMAT_T20FRS = """ +// #seekto 0x0000; +struct { + lbcd rxfreq[4]; + lbcd txfreq[4]; + lbcd rxtone[2]; + lbcd txtone[2]; + u8 jumpcode:1, + unknown1:2, + skip:1, + highpower:1, + narrow:1, + unknown2:1, + bcl:1; + u8 unknown3[3]; +} memory[%d]; +#seekto 0x02B0; +struct { + u8 voicesw; // Voice SW + + u8 voiceselect; // Voice Select + u8 scan; // Scan + + u8 vox; // VOX + + u8 voxgain; // Vox Gain + + u8 voxnotxonrx; // Rx Disable Vox + + u8 hivoltnotx; // High Vol Inhibit TX + + u8 lovoltnotx; // Low Vol Inhibit TX + + u8 rxemergency; // RX Emergency +} settings2; +#seekto 0x02C0; +struct { + u8 unk:6, + batterysaver:1, + beep:1; + u8 squelchlevel; + u8 sidekey2; + u8 timeouttimer; +} settings; +""" + CMD_ACK = b"\x06" VOICE_LIST = ["Off", "Chinese", "English"] @@ -485,12 +523,12 @@ class T18Radio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw() == b"\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem - if _mem.txfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.txfreq.get_raw() == b"\xFF\xFF\xFF\xFF": mem.duplex = "off" mem.offset = 0 elif int(_mem.rxfreq) == int(_mem.txfreq): @@ -517,7 +555,8 @@ class T18Radio(chirp_common.CloneModeRadio): mem.extra.append(rs) if self.MODEL != "RB18" and self.MODEL != "RB618" and \ self.MODEL != "FRS-B1" and self.MODEL != "BF-V8A" and \ - self.MODEL != "RB29" and self.MODEL != "RB629": + self.MODEL != "RB29" and self.MODEL != "RB629" and \ + self.MODEL != "BF-T20FRS": if self.MODEL not in ["RB87", "RT47V"]: rs = RadioSetting("scramble", "Scramble", @@ -624,8 +663,10 @@ class T18Radio(chirp_common.CloneModeRadio): return - if self.MODEL == "BF-V8A": + if self.MODEL == "BF-V8A" or self.MODEL == "BF-T20FRS": _mem.set_raw("\x00" * 12 + "\x09\xFF\xFF\xFF") + elif self.MODEL == "RB29" or self.MODEL == "RB629": + _mem.set_raw("\x00" * 12 + "\xF7\xFF\xFF\xFF") else: _mem.set_raw("\x00" * 12 + "\xF9\xFF\xFF\xFF") @@ -659,7 +700,8 @@ class T18Radio(chirp_common.CloneModeRadio): def get_settings(self): _settings = self._memobj.settings - if self.MODEL == "FRS-B1" or self.MODEL == "BF-V8A": + if self.MODEL == "FRS-B1" or self.MODEL == "BF-V8A" or \ + self.MODEL == "BF-T20FRS": _settings2 = self._memobj.settings2 basic = RadioSettingGroup("basic", "Basic Settings") top = RadioSettings(basic) @@ -680,7 +722,8 @@ class T18Radio(chirp_common.CloneModeRadio): rs = RadioSetting("scan", "Scan", RadioSettingValueBoolean(_settings.scan)) basic.append(rs) - elif self.MODEL == "FRS-B1" or self.MODEL == "BF-V8A": + elif self.MODEL == "FRS-B1" or self.MODEL == "BF-V8A" or \ + self.MODEL == "BF-T20FRS": rs = RadioSetting("settings2.scan", "Scan", RadioSettingValueBoolean(_settings2.scan)) basic.append(rs) @@ -705,7 +748,8 @@ class T18Radio(chirp_common.CloneModeRadio): rs = RadioSetting("voice", "Voice prompts", RadioSettingValueBoolean(_settings.voice)) basic.append(rs) - elif self.MODEL == "FRS-B1" or self.MODEL == "BF-V8A": + elif self.MODEL == "FRS-B1" or self.MODEL == "BF-V8A" or \ + self.MODEL == "BF-T20FRS": rs = RadioSetting("settings2.voicesw", "Voice prompts", RadioSettingValueBoolean(_settings2.voicesw)) basic.append(rs) @@ -750,7 +794,8 @@ class T18Radio(chirp_common.CloneModeRadio): if self.MODEL != "RB18" and self.MODEL != "RB618" \ and self.MODEL != "FRS-B1" \ - and self.MODEL != "BF-V8A": + and self.MODEL != "BF-V8A" \ + and self.MODEL != "BF-T20FRS": rs = RadioSetting("voxlevel", "Vox level", RadioSettingValueList( VOXLEVEL_LIST, @@ -921,7 +966,7 @@ class T18Radio(chirp_common.CloneModeRadio): SIDEKEY47_LIST[_settings.sidekey2S])) basic.append(rs) - if self.MODEL == "BF-V8A": + if self.MODEL == "BF-V8A" or self.MODEL == "BF-T20FRS": rs = RadioSetting("sidekey2", "Side key", RadioSettingValueList( SIDEKEYV8A_LIST, @@ -1433,3 +1478,31 @@ class RB87Radio(T18Radio): _mem_params = (_upper # number of channels ) _gmrs = True + + +@directory.register +class BFT20FRSRadio(T18Radio): + """Baofeng BF-T20FRS""" + VENDOR = "Baofeng" + MODEL = "BF-T20FRS" + ACK_BLOCK = True + + POWER_LEVELS = [chirp_common.PowerLevel("High", watts=2.000), + chirp_common.PowerLevel("Low", watts=0.500)] + + _magic = b"PROGRAM" + _fingerprint = [b"P3107" + b"\xF7\x00\x00"] + _upper = 22 + _mem_params = (_upper # number of channels + ) + _frs = False # sold as FRS radio but supports full band TX/RX + + _ranges = [ + (0x0000, 0x0160), + (0x02B0, 0x02D0), + ] + _memsize = 0x03F0 + + def process_mmap(self): + self._memobj = bitwise.parse(MEM_FORMAT_T20FRS % + self._mem_params, self._mmap) diff --git a/chirp/drivers/retevis_rb15.py b/chirp/drivers/retevis_rb15.py index 8318723..a1235da 100644 --- a/chirp/drivers/retevis_rb15.py +++ b/chirp/drivers/retevis_rb15.py @@ -18,7 +18,6 @@ import logging from chirp import chirp_common, directory, memmap from chirp import bitwise, errors, util -from chirp import bandplan_na from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettings @@ -472,19 +471,19 @@ class RB15RadioBase(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem - if _mem.get_raw() == ("\xFF" * 16): + if _mem.get_raw(asbytes=False) == ("\xFF" * 16): LOG.debug("Initializing empty memory") _mem.set_raw("\x00" * 16) # Freq and offset mem.freq = int(_mem.rxfreq) * 10 # tx freq can be blank - if _mem.get_raw()[4] == "\xFF": + if _mem.get_raw(asbytes=False)[4] == "\xFF": # TX freq not set mem.offset = 0 mem.duplex = "off" diff --git a/chirp/drivers/retevis_rb17p.py b/chirp/drivers/retevis_rb17p.py index a59bbf4..04be42a 100644 --- a/chirp/drivers/retevis_rb17p.py +++ b/chirp/drivers/retevis_rb17p.py @@ -325,12 +325,12 @@ class RB17P_Base(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem - if _mem.txfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.txfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.duplex = "off" mem.offset = 0 elif int(_mem.rxfreq) == int(_mem.txfreq): diff --git a/chirp/drivers/retevis_rb28.py b/chirp/drivers/retevis_rb28.py index a12b529..c4bbec0 100644 --- a/chirp/drivers/retevis_rb28.py +++ b/chirp/drivers/retevis_rb28.py @@ -394,7 +394,7 @@ class RB28Radio(chirp_common.CloneModeRadio): _mem = self._memobj.memory[number - 1] if self._reserved: - _rsvd = _mem.reserved.get_raw() + _rsvd = _mem.reserved.get_raw(asbytes=False) mem.freq = int(_mem.rxfreq) * 10 @@ -403,7 +403,7 @@ class RB28Radio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem @@ -511,7 +511,7 @@ class RB28Radio(chirp_common.CloneModeRadio): _mem = self._memobj.memory[mem.number - 1] if self._reserved: - _rsvd = _mem.reserved.get_raw() + _rsvd = _mem.reserved.get_raw(asbytes=False) if mem.empty: if self._reserved: diff --git a/chirp/drivers/retevis_rt1.py b/chirp/drivers/retevis_rt1.py index 7dcbd74..5d44329 100644 --- a/chirp/drivers/retevis_rt1.py +++ b/chirp/drivers/retevis_rt1.py @@ -381,7 +381,7 @@ class RT1Radio(chirp_common.CloneModeRadio): def decode_tone(self, val): """Parse the tone data to decode from mem, it returns: Mode (''|DTCS|Tone), Value (None|###), Polarity (None,N,R)""" - if val.get_raw() == "\xFF\xFF": + if val.get_raw(asbytes=False) == "\xFF\xFF": return '', None, None val = int(val) @@ -426,7 +426,7 @@ class RT1Radio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem diff --git a/chirp/drivers/retevis_rt21.py b/chirp/drivers/retevis_rt21.py index 68205f7..11a5cac 100644 --- a/chirp/drivers/retevis_rt21.py +++ b/chirp/drivers/retevis_rt21.py @@ -338,7 +338,7 @@ struct { u8 unknown_7[2]; // 005E-005F u8 channel_7[13]; // 0060-006C u8 voicel:4, // Voice Level 006D - unknown_9:3 // + unknown_9:3, // warn:1; // Warn Mode } settings; @@ -901,7 +901,7 @@ class RT21Radio(chirp_common.CloneModeRadio): _mem = self._memobj.memory[number - 1] if self._reserved: - _rsvd = _mem.reserved.get_raw() + _rsvd = _mem.reserved.get_raw(asbytes=False) mem.freq = int(_mem.rxfreq) * 10 @@ -910,7 +910,7 @@ class RT21Radio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem @@ -1176,7 +1176,7 @@ class RT21Radio(chirp_common.CloneModeRadio): _mem = self._memobj.memory[mem.number - 1] if self._reserved: - _rsvd = _mem.reserved.get_raw() + _rsvd = _mem.reserved.get_raw(asbytes=False) if self.MODEL == "RT86": _freqhops = self._memobj.freqhops[mem.number - 1] diff --git a/chirp/drivers/retevis_rt22.py b/chirp/drivers/retevis_rt22.py index 4148114..b295871 100644 --- a/chirp/drivers/retevis_rt22.py +++ b/chirp/drivers/retevis_rt22.py @@ -462,7 +462,7 @@ class RT22Radio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw() == b"\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem @@ -740,3 +740,12 @@ class W31E(RT22Radio): ] _memsize = 0x0200 _block_size = 0x40 + + +@directory.register +class BFT20(RT22Radio): + """Baofeng BF-T20""" + VENDOR = "Baofeng" + MODEL = "BF-T20" + + _fileid = [b"P330h33", ] diff --git a/chirp/drivers/retevis_rt23.py b/chirp/drivers/retevis_rt23.py index fc7b928..6c2356c 100644 --- a/chirp/drivers/retevis_rt23.py +++ b/chirp/drivers/retevis_rt23.py @@ -430,7 +430,7 @@ class RT23Radio(chirp_common.CloneModeRadio): def decode_tone(self, val): """Parse the tone data to decode from mem, it returns: Mode (''|DTCS|Tone), Value (None|###), Polarity (None,N,R)""" - if val.get_raw() == "\xFF\xFF": + if val.get_raw(asbytes=False) == "\xFF\xFF": return '', None, None val = int(val) @@ -481,18 +481,18 @@ class RT23Radio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.empty = True return mem - if _mem.get_raw() == ("\xFF" * 16): + if _mem.get_raw(asbytes=False) == ("\xFF" * 16): LOG.debug("Initializing empty memory") _mem.set_raw("\x00" * 16) # Freq and offset mem.freq = int(_mem.rxfreq) * 10 # tx freq can be blank - if _mem.get_raw()[4] == "\xFF": + if _mem.get_raw(asbytes=False)[4] == "\xFF": # TX freq not set mem.offset = 0 mem.duplex = "off" @@ -568,7 +568,7 @@ class RT23Radio(chirp_common.CloneModeRadio): else: _usd |= bitpos - if _mem.get_raw() == ("\xFF" * 16): + if _mem.get_raw(asbytes=False) == ("\xFF" * 16): LOG.debug("Initializing empty memory") _mem.set_raw("\x00" * 16) _scn |= bitpos diff --git a/chirp/drivers/retevis_rt26.py b/chirp/drivers/retevis_rt26.py index 255d80f..b1d5da4 100644 --- a/chirp/drivers/retevis_rt26.py +++ b/chirp/drivers/retevis_rt26.py @@ -393,7 +393,7 @@ class RT26Radio(chirp_common.CloneModeRadio): def decode_tone(self, val): """Parse the tone data to decode from mem, it returns: Mode (''|DTCS|Tone), Value (None|###), Polarity (None,N,R)""" - if val.get_raw() == "\xFF\xFF": + if val.get_raw(asbytes=False) == "\xFF\xFF": return '', None, None val = int(val) @@ -438,7 +438,7 @@ class RT26Radio(chirp_common.CloneModeRadio): mem.empty = True return mem - if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF": + if _mem.rxfreq.get_raw(asbytes=False) == "\xFF\xFF\xFF\xFF": mem.freq = 0 mem.empty = True return mem diff --git a/chirp/drivers/retevis_rt76p.py b/chirp/drivers/retevis_rt76p.py index 18a3dac..e194db0 100644 --- a/chirp/drivers/retevis_rt76p.py +++ b/chirp/drivers/retevis_rt76p.py @@ -411,7 +411,7 @@ class RT76PRadio(chirp_common.CloneModeRadio): def _is_txinh(self, _mem): raw_tx = "" for i in range(0, 4): - raw_tx += _mem.txfreq[i].get_raw() + raw_tx += _mem.txfreq[i].get_raw(asbytes=False) return raw_tx == "\xFF\xFF\xFF\xFF" def get_memory(self, number): @@ -421,7 +421,7 @@ class RT76PRadio(chirp_common.CloneModeRadio): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw(asbytes=False)[0] == "\xff": mem.empty = True return mem diff --git a/chirp/drivers/retevis_rt87.py b/chirp/drivers/retevis_rt87.py index 10ff7f8..606c232 100644 --- a/chirp/drivers/retevis_rt87.py +++ b/chirp/drivers/retevis_rt87.py @@ -81,7 +81,7 @@ struct { unknown_08311:1, chnameshow:1, // Display Channel Names (Off, On) [25] voice:1, // Voice Prompt (Off, On) [19] - beep:1 // Beep (Off, On) [09] + beep:1, // Beep (Off, On) [09] batterysave:1; // Battery Save aka Receiver Saver (Off, On) [16] u8 unknown_0832:3, manual:1, // Manual (Disabled, Enabled) @@ -448,7 +448,7 @@ class Rt87BaseRadio(chirp_common.CloneModeRadio): def _is_txinh(self, _mem): raw_tx = "" for i in range(0, 4): - raw_tx += _mem.tx_freq[i].get_raw() + raw_tx += _mem.tx_freq[i].get_raw(asbytes=False) return raw_tx == "\xFF\xFF\xFF\xFF" def _bbcd2num(self, bcdarr, strlen=8): @@ -478,7 +478,7 @@ class Rt87BaseRadio(chirp_common.CloneModeRadio): else: mem.number = number - if _mem.get_raw().startswith("\xFF\xFF\xFF\xFF"): + if _mem.get_raw(asbytes=False).startswith("\xFF\xFF\xFF\xFF"): mem.empty = True return mem diff --git a/chirp/drivers/retevis_rt98.py b/chirp/drivers/retevis_rt98.py index 697a675..5a22fa2 100644 --- a/chirp/drivers/retevis_rt98.py +++ b/chirp/drivers/retevis_rt98.py @@ -31,6 +31,7 @@ LOG = logging.getLogger(__name__) # # Chirp Driver for Retevis RT98 models: RT98V (136-174 MHz) # RT98U (400-490 MHz) +# RT98W (66-88 MHz) # # # @@ -106,6 +107,7 @@ LIST_TIME46 = LIST_TIME50[4:] LIST_RT98V_MODES = ["FreeNet", "COM", "COMII"] LIST_RT98U_MODES = ["PMR", "COM", "COMII"] +LIST_RT98W_MODES = ["", "", "", "", "", "", "COM"] LIST_RT98V_FREQS = ["Rx(149 - 149.2 MHz) Tx(149 - 149.2 MHz)", "Rx(136 - 174 MHz) Tx(136 - 174 MHz)", @@ -115,6 +117,14 @@ LIST_RT98U_FREQS = ["Rx(446 - 446.2 MHz) Tx(446 - 446.2 MHz)", "Rx(400 - 470 MHz) Tx(400 - 470 MHz)", "Rx(450 - 470 MHz) Tx(450 - 470 MHz)"] +LIST_RT98W_FREQS = ["", + "", + "", + "", + "", + "", + "Rx(66 - 88 MHz) Tx(66 - 88 MHz)"] + # RT98 memory map # section: 1 Channel Bank # description of channel bank (199 channels , range 1-199) @@ -168,7 +178,7 @@ LIST_RT98U_FREQS = ["Rx(446 - 446.2 MHz) Tx(446 - 446.2 MHz)", # 9 u8 unknown7[9] # MEM_FORMAT = """ -#seekto 0x0000; +// #seekto 0x0000; struct { bbcd freq[4]; bbcd offset[4]; @@ -227,7 +237,7 @@ struct { bit c[8]; } csetflag[32]; -#seekto 0x3260; +// #seekto 0x3260; struct { bit c[8]; } cskipflag[32]; @@ -488,6 +498,14 @@ RT98U_BAND_LIMITS = {0x00: [(446000000, 446200000)], 0x01: [(400000000, 470000000)], 0x02: [(450000000, 470000000)]} +RT98W_BAND_LIMITS = {0x00: [(66000000, 88000000)], + 0x01: [(66000000, 88000000)], + 0x02: [(66000000, 88000000)], + 0x03: [(66000000, 88000000)], + 0x04: [(66000000, 88000000)], + 0x05: [(66000000, 88000000)], + 0x06: [(66000000, 88000000)]} + # Get band limits from a band limit value def get_band_limits_Hz(radio_type, limit_value): @@ -501,6 +519,11 @@ def get_band_limits_Hz(radio_type, limit_value): limit_value = 0x01 LOG.warning('Unknown band limit value 0x%02x, default to 0x01') bandlimitfrequencies = RT98V_BAND_LIMITS[limit_value] + elif str(radio_type).rstrip("\00") in ["RT98W", "AT-779W"]: + if limit_value not in RT98W_BAND_LIMITS: + limit_value = 0x06 + LOG.warning('Unknown band limit value 0x%02x, default to 0x06') + bandlimitfrequencies = RT98W_BAND_LIMITS[limit_value] return bandlimitfrequencies @@ -689,10 +712,14 @@ def do_upload(radio): image_band_limits = LIST_RT98U_FREQS[int(_embedded.mode)] if str(_embedded.radio_type).rstrip("\00") in ["RT98V", "AT-779V"]: image_band_limits = LIST_RT98V_FREQS[int(_embedded.mode)] + if str(_embedded.radio_type).rstrip("\00") in ["RT98W", "AT-779W"]: + image_band_limits = LIST_RT98W_FREQS[int(_embedded.mode)] if str(model).rstrip("\00") in ["RT98U", "AT-779U"]: radio_band_limits = LIST_RT98U_FREQS[int(bandlimit)] if str(model).rstrip("\00") in ["RT98V", "AT-779V"]: radio_band_limits = LIST_RT98V_FREQS[int(bandlimit)] + if str(model).rstrip("\00") in ["RT98W", "AT-779W"]: + radio_band_limits = LIST_RT98W_FREQS[int(bandlimit)] LOG.warning('radio and image band limits differ') LOG.warning('image band limits: %s' % image_band_limits) @@ -860,7 +887,7 @@ class Rt98BaseRadio(chirp_common.CloneModeRadio, mem.empty = True return mem - if _mem.get_raw()[0] == "\xFF": + if _mem.get_raw()[0] == b"\xFF": mem.empty = True return mem @@ -1296,6 +1323,8 @@ class Rt98BaseRadio(chirp_common.CloneModeRadio, if str(_embedded.radio_type).rstrip("\00") in ["RT98V", "AT-779V"]: options = LIST_RT98V_MODES + elif str(_embedded.radio_type).rstrip("\00") in ["RT98W", "AT-779W"]: + options = LIST_RT98W_MODES else: options = LIST_RT98U_MODES rs = RadioSettingValueList(options, options[_embedded.mode]) @@ -1306,6 +1335,8 @@ class Rt98BaseRadio(chirp_common.CloneModeRadio, # frequency if str(_embedded.radio_type).rstrip("\00") in ["RT98V", "AT-779V"]: options = LIST_RT98V_FREQS + elif str(_embedded.radio_type).rstrip("\00") in ["RT98W", "AT-779W"]: + options = LIST_RT98W_FREQS else: options = LIST_RT98U_FREQS rs = RadioSettingValueList(options, options[_settings3.bandlimit]) @@ -1385,5 +1416,8 @@ class Rt98Radio(Rt98BaseRadio): # strings ALLOWED_RADIO_TYPES = {'RT98V': ['V100'], 'RT98U': ['V100'], + 'RT98W': ['V100'], 'AT-779V': ['V100'], - 'AT-779U': ['V100']} + 'AT-779U': ['V100'], + 'AT-779W': ['V100'], + } diff --git a/chirp/drivers/rh5r_v2.py b/chirp/drivers/rh5r_v2.py index b297584..f58d03f 100644 --- a/chirp/drivers/rh5r_v2.py +++ b/chirp/drivers/rh5r_v2.py @@ -220,7 +220,7 @@ class TYTTHUVF8_V2(chirp_common.CloneModeRadio): else: mem.number = number - if _mem.get_raw().startswith("\xFF\xFF\xFF\xFF"): + if _mem.get_raw(asbytes=False).startswith("\xFF\xFF\xFF\xFF"): mem.empty = True return mem diff --git a/chirp/drivers/tdh8.py b/chirp/drivers/tdh8.py index 74b89da..7bedcf3 100644 --- a/chirp/drivers/tdh8.py +++ b/chirp/drivers/tdh8.py @@ -83,7 +83,7 @@ struct { fmrec:1, mdfa:1, aworkmode:2; - u8 openmes:2, + u8 ponmsg:2, unused19:1, mdfb:1, unused20:1, @@ -215,6 +215,14 @@ struct{ block1:1; } fmusedflags[4]; +#seekto 0x1c08; +struct { + char msg1[16]; + char msg2[16]; + char msg3[16]; +} poweron_msg; + + #seekto 0x1CC8; struct{ u8 stopkey1; @@ -285,6 +293,285 @@ struct{ struct{ u8 ecode[7]; }endcode; +""" + +MEM_FORMAT_H3 = """ +#seekto 0x0008; +struct { + lbcd rxfreq[4]; + lbcd txfreq[4]; + lbcd rxtone[2]; + lbcd txtone[2]; + u8 unused1; + u8 pttid:2, + freqhop:1, + unused3:1, + unused4:1, + bcl:1, + unused5:1, + unused2:1; + u8 unused6:1, + scramble:1, + lowpower:2, + wide:1, + unused8:1, + offset:2; + u8 unused10; +} memory[200]; + +#seekto 0x0C98; +struct{ + u8 stopkey1; + u8 ssidekey1; + u8 ssidekey2; + u8 ltopkey2; + u8 lsidekey3; + u8 lsidekey4; +} press; + +#seekto 0x0CA8; +struct { + u8 txled:1, + rxled:1, + unused11:1, + ham:1, + gmrs:1, + unused14:1, + unused15:1, + pritx:1; + u8 scanmode:2, + unused16:1, + keyautolock:1, + unused17:1, + btnvoice:1, + unknown18:1, + voiceprompt:1; + u8 fmworkmode:1, + sync:1, + tonevoice:2, + fmrec:1, + mdfa:1, + aworkmode:2; + u8 ponmsg:2, + unused19:1, + mdfb:1, + unused20:1, + dbrx:1, + bworkmode:2; + u8 ablock; + u8 bblock; + u8 fmroad; + u8 unused21:1, + tailclean:1, + rogerprompt_:1, + kill:1, + stun:1, + voxgain:3; + u8 astep:4, + bstep:4; + u8 squelch; + u8 tot; + u8 rogerprompt:2, + unused11_4:4, + lang:1, + unused11_1:1; + u8 save; + u8 ligcon; + u8 voxdelay; + u8 onlychmode:1, + breathled:3, + unused:3, + alarm:1; +} settings; + +#seekto 0x0CB8; +struct { + u8 ofseta[4]; + u8 ununsed26[12]; +} aoffset; + +#seekto 0x0CBC; +struct { + u8 ofsetb[4]; + u8 ununsed27[12]; +} boffset; + +#seekto 0x0CD8; +struct{ + u8 fmblock[4]; +}fmmode[25]; + + +#seekto 0x0D48; +struct { + char name[8]; +} names[200]; + +#seekto 0x1808; +struct{ + u8 stuncode[16]; + u8 killcode[16]; +}skcode; + +#seekto 0x1828; +struct{ + u8 idcode[3]; +}icode; + +#seekto 0x1837; +struct{ + u8 gcode; +}groupcode; + +#seekto 0x1838; +struct{ + u8 group1[7]; +}group1; + +#seekto 0x1848; +struct{ + u8 group2[7]; +}group2; + +#seekto 0x1858; +struct{ + u8 group3[7]; +}group3; + +#seekto 0x1868; +struct{ + u8 group4[7]; +}group4; + +#seekto 0x1878; +struct{ + u8 group5[7]; +}group5; + +#seekto 0x1888; +struct{ + u8 group6[7]; +}group6; + +#seekto 0x1898; +struct{ + u8 group7[7]; +}group7; + +#seekto 0x18A8; +struct{ + u8 group8[7]; +}group8; + +#seekto 0x18C8; +struct{ + u8 scode[7]; +}startcode; + +#seekto 0x18D8; +struct{ + u8 ecode[7]; +}endcode; + +#seekto 0x1908; +struct{ + u8 block8:1, + block7:1, + block6:1, + block5:1, + block4:1, + block3:1, + block2:1, + block1:1; +} usedflags[25]; + +#seekto 0x1928; +struct{ + u8 scan8:1, + scan7:1, + scan6:1, + scan5:1, + scan4:1, + scan3:1, + scan2:1, + scan1:1; +} scanadd[25]; + +#seekto 0x1948; +struct{ + u8 block8:1, + block7:1, + block6:1, + block5:1, + block4:1, + block3:1, + block2:1, + block1:1; +} fmusedflags[4]; + +#seekto 0x1958; +struct { + lbcd rxfreqa[4]; + lbcd txfreq[4]; + u8 rxtone[2]; + u8 txtone[2]; + u8 unused1; + u8 pttid:2, + specialqta:1, + unused3:1, + unused4:1, + bcl:1, + unused5:1, + unused2:1; + u8 unused6:1, + unused7:1, + lowpower:2, + wide:1, + unused8:1, + offset:2; + u8 unused10; +} vfoa; + +#seekto 0x1968; +struct { + lbcd rxfreqb[4]; + lbcd txfreq[4]; + u8 rxtoneb[2]; + u8 txtone[2]; + u8 unused1; + u8 pttid:2, + specialqtb:1, + unused3:1, + unused4:1, + bclb:1, + unused5:1, + unused2:1; + u8 unused6:1, + unused7:1, + lowpowerb:2, + wideb:1, + unused8:1, + offsetb:2; + u8 unused10; +} vfob; + +#seekto 0x1978; +struct{ + u8 vfo[4]; +}fmvfo; + + +#seekto 0x1c08; +struct { + char msg1[16]; + char msg2[16]; + char msg3[16]; +} poweron_msg; + +#seekto 0x1f28; +struct{ + u8 micgain; +} mic; """ @@ -373,7 +660,7 @@ COLOR_LIST = ["Off", "Blue", "Orange", "Purple"] DTMFSPEED_LIST = ["%s ms" % x for x in range(50, 2010, 10)] DTMFST_LIST = ["OFF", "DT-ST", "ANI-ST", "DT+ANI"] MODE_LIST = ["Channel", "Name", "Frequency"] -PONMSG_LIST = ["Full", "Message"] +PONMSG_LIST = ["Full", "Message", "Icon"] PTTID_LIST = ["Off", "BOT", "EOT", "Both"] PTTIDCODE_LIST = ["%s" % x for x in range(1, 16)] RTONE_LIST = ["1000 Hz", "1450 Hz", "1750 Hz", "2100 Hz"] @@ -397,6 +684,10 @@ TXPOWER3_LIST = ["High", "Mid", "Low"] VOICE_LIST = ["Off", "English", "Chinese"] VOX_LIST = ["OFF"] + ["%s" % x for x in range(1, 11)] WORKMODE_LIST = ["Frequency", "Channel"] +# mic +MIC_GAIN_LIST = ['%s' % x for x in range(0, 10)] +MIC_GAIN_LIST_H8 = ['%s' % x for x in range(0, 33)] +H8_LIST = ["TD-H8", "TD-H8-HAM", "TD-H8-GMRS"] GMRS_FREQS = bandplan_na.GMRS_HIRPT @@ -407,9 +698,11 @@ NOAA_FREQS = [162550000, 162400000, 162475000, 162425000, 162450000, HAM_GMRS_NAME = ["NOAA 1", "NOAA 2", "NOAA 3", "NOAA 4", "NOAA 5", "NOAA 6", "NOAA 7", "NOAA 8", "NOAA 9", "NOAA 10", "NOAA 11"] -ALL_MODEL = ["TD-H8", "TD-H8-HAM", "TD-H8-GMRS"] +ALL_MODEL = ["TD-H8", "TD-H8-HAM", "TD-H8-GMRS", "TD-H3", + "TD-H3-HAM", "TD-H3-GMRS"] TD_H8 = b"\x50\x56\x4F\x4A\x48\x1C\x14" +TD_H3 = b"\x50\x56\x4F\x4A\x48\x5C\x14" def _do_status(radio, block): @@ -626,7 +919,7 @@ TX_POWER = [chirp_common.PowerLevel("Low", watts=1.00), chirp_common.PowerLevel("Mid", watts=4.00), chirp_common.PowerLevel("High", watts=8.00)] -TDH8_CHARSET = chirp_common.CHARSET_UPPER_NUMERIC + \ +TDH8_CHARSET = chirp_common.CHARSET_ALPHANUMERIC + \ "!@#$%^&*()+-=[]:\";'<>?,./" @@ -760,7 +1053,10 @@ class TDH8(chirp_common.CloneModeRadio): return self._memobj.memory[number] def _get_nam(self, number): - return self._memobj.names[number] + if self.MODEL in H8_LIST: + return self._memobj.names[number] + else: + return self._memobj.names[number - 1] def _get_fm(self, number): return self._memobj.fmmode[number] @@ -783,7 +1079,7 @@ class TDH8(chirp_common.CloneModeRadio): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw(asbytes=False)[0] == "\xff": mem.empty = True return mem @@ -913,7 +1209,10 @@ class TDH8(chirp_common.CloneModeRadio): return self._memobj.memory[number] def _set_nam(self, number): - return self._memobj.names[number] + if self.MODEL in H8_LIST: + return self._memobj.names[number] + else: + return self._memobj.names[number - 1] def _get_scan_list(self, scan_data): # scan_val_list - Get all scans Add data 1-200 digits @@ -961,7 +1260,10 @@ class TDH8(chirp_common.CloneModeRadio): if mem.empty: _mem.set_raw("\xff" * 16) - _nam.set_raw("\xff" * 16) + if self.MODEL in H8_LIST: + _nam.set_raw("\xff" * 16) + else: + _nam.set_raw("\xff" * 8) return _mem.set_raw("\x00" * 16) @@ -1116,7 +1418,7 @@ class TDH8(chirp_common.CloneModeRadio): _vfoa = self._memobj.vfoa _vfob = self._memobj.vfob _gcode = self._memobj.groupcode - + _msg = self._memobj.poweron_msg basic = RadioSettingGroup("basic", "Basic Settings") abblock = RadioSettingGroup("abblock", "A/B Channel") fmmode = RadioSettingGroup("fmmode", "FM") @@ -1162,15 +1464,6 @@ class TDH8(chirp_common.CloneModeRadio): SYNC_LIST, SYNC_LIST[_settings.sync])) basic.append(rs) - if _settings.lang in (2, 3): - langs = 1 - else: - langs = 0 - rs = RadioSetting("lang", "Language", - RadioSettingValueList( - LANG_LIST, LANG_LIST[langs])) - basic.append(rs) - rs = RadioSetting("save", "Battery Save", RadioSettingValueList( BTV_SAVER_LIST, BTV_SAVER_LIST[_settings.save])) @@ -1222,47 +1515,88 @@ class TDH8(chirp_common.CloneModeRadio): rs = RadioSetting("onlychmode", "Only CH Mode", RadioSettingValueBoolean(_settings.onlychmode)) basic.append(rs) - - rs = RadioSetting("stopkey1", "SHORT_KEY_TOP", - RadioSettingValueList( - SHORT_KEY_LIST, SHORT_KEY_LIST[0])) - basic.append(rs) - rs = RadioSetting("ssidekey1", "SHORT_KEY_PF1", RadioSettingValueList( SHORT_KEY_LIST, SHORT_KEY_LIST[ _press.ssidekey1])) basic.append(rs) - - rs = RadioSetting("ssidekey2", "SHORT_KEY_PF2", + rs = RadioSetting("lsidekey3", "LONG_KEY_PF1", RadioSettingValueList( - SHORT_KEY_LIST, SHORT_KEY_LIST[ - _press.ssidekey2])) + LONG_KEY_LIST, + LONG_KEY_LIST[_press.lsidekey3])) basic.append(rs) + if self.MODEL in H8_LIST: + rs = RadioSetting("stopkey1", "SHORT_KEY_TOP", + RadioSettingValueList(SHORT_KEY_LIST, + SHORT_KEY_LIST[0])) + basic.append(rs) + + rs = RadioSetting("ltopkey2", "LONG_KEY_TOP", + RadioSettingValueList( + LONG_KEY_LIST, + LONG_KEY_LIST[_press.ltopkey2])) + basic.append(rs) + + rs = RadioSetting("ssidekey2", "SHORT_KEY_PF2", + RadioSettingValueList( + SHORT_KEY_LIST, + SHORT_KEY_LIST[_press.ssidekey2])) + basic.append(rs) + + rs = RadioSetting("lsidekey4", "LONG_KEY_PF2", + RadioSettingValueList( + LONG_KEY_LIST, + LONG_KEY_LIST[_press.lsidekey4])) + basic.append(rs) - rs = RadioSetting("ltopkey2", "LONG_KEY_TOP", + rs = RadioSetting("voxgain", "VOX Gain", RadioSettingValueList( - LONG_KEY_LIST, LONG_KEY_LIST[_press.ltopkey2])) + VOX_GAIN, VOX_GAIN[_settings.voxgain])) basic.append(rs) - rs = RadioSetting("lsidekey3", "LONG_KEY_PF1", + rs = RadioSetting("voxdelay", "VOX Delay", RadioSettingValueList( - LONG_KEY_LIST, LONG_KEY_LIST[_press.lsidekey3])) + VOX_DELAY, VOX_DELAY[_settings.voxdelay])) basic.append(rs) - rs = RadioSetting("lsidekey4", "LONG_KEY_PF2", + rs = RadioSetting("ponmsg", "Power-On Message", RadioSettingValueList( - LONG_KEY_LIST, LONG_KEY_LIST[_press.lsidekey4])) + PONMSG_LIST, PONMSG_LIST[_settings.ponmsg])) basic.append(rs) - rs = RadioSetting("voxgain", "VOX Gain", - RadioSettingValueList( - VOX_GAIN, VOX_GAIN[_settings.voxgain])) - basic.append(rs) + # mic gain + if self.MODEL not in H8_LIST: + _mic = self._memobj.mic + rs = RadioSetting("micgain", "MIC GAIN", + RadioSettingValueList( + MIC_GAIN_LIST, MIC_GAIN_LIST[_mic.micgain])) + basic.append(rs) + + if self.MODEL not in H8_LIST: + rs = RadioSetting("kill", "Kill", + RadioSettingValueBoolean(_settings.kill)) + basic.append(rs) + rs = RadioSetting("stun", "Stun", + RadioSettingValueBoolean(_settings.stun)) + basic.append(rs) + + def _filter(name): + filtered = "" + for char in str(name): + if char in chirp_common.CHARSET_ASCII: + filtered += char + else: + filtered += " " + return filtered - rs = RadioSetting("voxdelay", "VOX Delay", - RadioSettingValueList( - VOX_DELAY, VOX_DELAY[_settings.voxdelay])) + rs = RadioSetting("poweron_msg.msg1", "Power-On Message 1", + RadioSettingValueString(0, 16, _filter(_msg.msg1))) + basic.append(rs) + rs = RadioSetting("poweron_msg.msg2", "Power-On Message 2", + RadioSettingValueString(0, 16, _filter(_msg.msg2))) + basic.append(rs) + rs = RadioSetting("poweron_msg.msg3", "Power-On Message 3", + RadioSettingValueString(0, 16, _filter(_msg.msg3))) basic.append(rs) # A channel @@ -1567,6 +1901,28 @@ class TDH8(chirp_common.CloneModeRadio): ecode_val = RadioSettingValueString(0, 7, used_ecode) rs = RadioSetting("ecode", "PTT ID Ending(BOT)", ecode_val) dtmf.append(rs) + # H3 + if self.MODEL not in H8_LIST: + # stuncode + ecode_list = self._memobj.skcode.stuncode + used_ecode = '' + for i in ecode_list: + if i == 0xFF: + continue + used_ecode += str(i)[3] + ecode_val = RadioSettingValueString(0, 16, used_ecode) + rs = RadioSetting("stuncode", "Stun Code", ecode_val) + dtmf.append(rs) + # killcode + ecode_list = self._memobj.skcode.killcode + used_ecode = '' + for i in ecode_list: + if i == 0xFF: + continue + used_ecode += str(i)[3] + ecode_val = RadioSettingValueString(0, 16, used_ecode) + rs = RadioSetting("killcode", "Kill Code", ecode_val) + dtmf.append(rs) return group @@ -1590,6 +1946,7 @@ class TDH8(chirp_common.CloneModeRadio): _vfoa = self._memobj.vfoa _vfob = self._memobj.vfob _fmmode = self._memobj.fmmode + for element in settings: if not isinstance(element, RadioSetting): if element.get_name() == "fm_preset": @@ -1669,11 +2026,18 @@ class TDH8(chirp_common.CloneModeRadio): elif "group8" in name: obj = self._memobj.group8.group8 setting = element.get_name() - + elif "micgain" in name: + obj = self._memobj.mic.micgain + setting = element.get_name() + elif "killcode" in name: + obj = self._memobj.skcode.killcode + setting = element.get_name() + elif "stuncode" in name: + obj = self._memobj.skcode.stuncode + setting = element.get_name() else: obj = _settings setting = element.get_name() - if element.has_apply_callback(): LOG.debug("Using apply callback") element.run_apply_callback() @@ -2006,9 +2370,33 @@ class TDH8(chirp_common.CloneModeRadio): list_val.append(0xFF) lenth_val += 1 self._memobj.group8.group8 = list_val - elif setting == 'lang': - self._memobj.settings.lang = ( - str(element.value) == 'English' and 2 or 1) + elif setting == 'micgain': + self._memobj.mic.micgain = ( + str(element.value)) + elif setting == 'stuncode' and element.value.get_mutable(): + val = str(element.value) + list_val = [] + lenth_val = 0 + while lenth_val < (len(val)): + if val[lenth_val] != ' ': + list_val.append(int(val[lenth_val], 16)) + lenth_val += 1 + else: + list_val.append(0xFF) + lenth_val += 1 + self._memobj.skcode.stuncode = list_val + elif setting == 'killcode' and element.value.get_mutable(): + val = str(element.value) + list_val = [] + lenth_val = 0 + while lenth_val < (len(val)): + if val[lenth_val] != ' ': + list_val.append(int(val[lenth_val], 16)) + lenth_val += 1 + else: + list_val.append(0xFF) + lenth_val += 1 + self._memobj.skcode.killcode = list_val elif element.value.get_mutable(): setattr(obj, setting, element.value) except Exception: @@ -2062,3 +2450,50 @@ class TDH8_GMRS(TDH8): class UV68(TDH8): VENDOR = "TID" MODEL = "TD-UV68" + + +@directory.register +class TDH3(TDH8): + VENDOR = "TIDRADIO" + MODEL = "TD-H3" + _memsize = 0x1fef + _ranges_main = [(0x0000, 0x1fef)] + _idents = [TD_H3] + _vhf_range = (136000000, 175000000) + _uhf_range = (400000000, 521000000) + _aux_block = True + _tri_power = True + _gmrs = False + _ham = False + _mem_params = (0x1F2F) + + def process_mmap(self): + self._memobj = bitwise.parse(MEM_FORMAT_H3, self._mmap) + + +@directory.register +class TDH3_HAM(TDH3): + VENDOR = "TIDRADIO" + MODEL = "TD-H3-HAM" + ident_mode = b'P31185\xff\xff' + _ham = True + _vhf_range = (144000000, 149000000) + _uhf_range = (420000000, 451000000) + + +@directory.register +class TDH3_GMRS(TDH3): + VENDOR = "TIDRADIO" + MODEL = "TD-H3-GMRS" + ident_mode = b'P31184\xff\xff' + _gmrs = True + _vhf_range = (136000000, 175000000) + _uhf_range = (400000000, 521000000) + + def validate_memory(self, mem): + msgs = super().validate_memory(mem) + if 31 <= mem.number <= 54 and mem.freq not in GMRS_FREQS: + msgs.append(chirp_common.ValidationError( + "The frequency in channels 31-54 must be between" + "462.55000-462.72500 in 0.025 increments.")) + return msgs diff --git a/chirp/drivers/tdxone_tdq8a.py b/chirp/drivers/tdxone_tdq8a.py index 56a57ef..fe301ca 100644 --- a/chirp/drivers/tdxone_tdq8a.py +++ b/chirp/drivers/tdxone_tdq8a.py @@ -531,7 +531,7 @@ class TDXoneTDQ8A(chirp_common.CloneModeRadio, def _is_txinh(self, _mem): raw_tx = "" for i in range(0, 4): - raw_tx += _mem.txfreq[i].get_raw() + raw_tx += _mem.txfreq[i].get_raw(asbytes=False) return raw_tx == "\xFF\xFF\xFF\xFF" def _get_mem(self, number): @@ -547,7 +547,7 @@ class TDXoneTDQ8A(chirp_common.CloneModeRadio, mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw(asbytes=False)[0] == "\xff": mem.empty = True return mem diff --git a/chirp/drivers/tg_uv2p.py b/chirp/drivers/tg_uv2p.py index 6d96002..43ef27e 100644 --- a/chirp/drivers/tg_uv2p.py +++ b/chirp/drivers/tg_uv2p.py @@ -352,13 +352,14 @@ class QuanshengTGUV2P(chirp_common.CloneModeRadio, else: mem.number = number - if (_mem.freq.get_raw()[0] == "\xFF") or (_bf.band == "\x0F"): + if ((_mem.freq.get_raw(asbytes=False)[0] == "\xFF") or + (_bf.band == "\x0F")): mem.empty = True return mem mem.freq = int(_mem.freq) * 10 - if _mem.offset.get_raw()[0] == "\xFF": + if _mem.offset.get_raw(asbytes=False)[0] == "\xFF": mem.offset = 0 else: mem.offset = int(_mem.offset) * 10 @@ -701,7 +702,8 @@ class QuanshengTGUV2P(chirp_common.CloneModeRadio, if ch_num == 0xFF: return True _mem, _bf, _nam = self._get_memobjs(ch_num) - if (_mem.freq.get_raw()[0] == "\xFF") or (_bf.band == "\x0F"): + if ((_mem.freq.get_raw(asbytes=False)[0] == "\xFF") or + (_bf.band == "\x0F")): return False elif _bf.band == 0x00: return False diff --git a/chirp/drivers/th7800.py b/chirp/drivers/th7800.py index 58dfd01..a04a4ca 100644 --- a/chirp/drivers/th7800.py +++ b/chirp/drivers/th7800.py @@ -42,7 +42,7 @@ struct mem { u8 fmdev:2, // wide=00, mid=01, narrow=10 scramb:1, compand:1, - emphasis:1 + emphasis:1, unknown1a:2, sqlmode:1; // carrier, tone u8 rptmod:2, // off, -, + @@ -350,12 +350,8 @@ class TYTTH7800Base(chirp_common.Radio): display = None if mem.name: _mem.display = True - if display and not display.changed(): - display.value = "Name" else: _mem.display = False - if display and not display.changed(): - display.value = "Frequency" _mem.scan = SCAN_MODES.index(mem.skip) if mem.skip == "P": diff --git a/chirp/drivers/th9000.py b/chirp/drivers/th9000.py index 6556706..004b6ea 100644 --- a/chirp/drivers/th9000.py +++ b/chirp/drivers/th9000.py @@ -405,6 +405,7 @@ def _ident(radio): if response == b"QX\06": exito = True + break # check if we had EXITO if exito is False: diff --git a/chirp/drivers/th9800.py b/chirp/drivers/th9800.py index 0ea022a..ae6a32e 100644 --- a/chirp/drivers/th9800.py +++ b/chirp/drivers/th9800.py @@ -41,7 +41,7 @@ struct mem { u8 fmdev:2, // wide=00, mid=01, narrow=10 scramb:1, compand:1, - emphasis:1 + emphasis:1, unknown1a:2, sqlmode:1; // carrier, tone u8 rptmod:2, // off, -, + @@ -87,7 +87,7 @@ struct { right_func_key:1; u8 tbst_freq:2, ani_display:1, - unk0xdc25_4:1 + unk0xdc25_4:1, mute_mode:2, unk0xdc25_10:2; u8 auto_xfer:1, @@ -398,12 +398,8 @@ class TYTTH9800Base(chirp_common.Radio): display = None if mem.name: _mem.display = True - if display and not display.changed(): - display.value = "Name" else: _mem.display = False - if display and not display.changed(): - display.value = "Frequency" _mem.scan = SCAN_MODES.index(mem.skip) if mem.skip == "P": diff --git a/chirp/drivers/th_uv8000.py b/chirp/drivers/th_uv8000.py index 220e06e..cdca651 100644 --- a/chirp/drivers/th_uv8000.py +++ b/chirp/drivers/th_uv8000.py @@ -36,17 +36,17 @@ struct chns { ul32 txfreq; u8 rxtone[2]; u8 txtone[2]; - u8 wide:1 // 0x0c - vox_on:1 - chunk01:1 - bcl:1 // inv bool - epilogue:1 - power:1 - chunk02:1 + u8 wide:1, // 0x0c + vox_on:1, + chunk01:1, + bcl:1, // inv bool + epilogue:1, + power:1, + chunk02:1, chunk03:1; - u8 ani:1 // 0x0d inv - chunk08:1 - ptt:2 + u8 ani:1, // 0x0d inv + chunk08:1, + ptt:2, chpad04:4; u8 chunk05; // 0x0e u16 id_code; // 0x0f, 10 @@ -64,22 +64,22 @@ struct fm_chn { struct frqx { ul32 rxfreq; ul24 ofst; - u8 fqunk01:4 // 0x07 - funk10:2 + u8 fqunk01:4, // 0x07 + funk10:2, duplx:2; u8 rxtone[2]; // 0x08, 9 u8 txtone[2]; // 0x0a, b - u8 wide:1 // 0x0c - vox_on:1 - funk11:1 - bcl:1 // inv bool - epilogue:1 - power:1 + u8 wide:1, // 0x0c + vox_on:1, + funk11:1, + bcl:1, // inv bool + epilogue:1, + power:1, fqunk02:2; - u8 ani:1 // 0x0d inv bool - fqunk03:1 - ptt:2 - fqunk12:1 + u8 ani:1, // 0x0d inv bool + fqunk03:1, + ptt:2, + fqunk12:1, fqunk04:3; u8 fqunk07; // 0x0e u16 id_code; // 0x0f, 0x10 @@ -94,13 +94,10 @@ struct bitmap { #seekto 0x0010; struct chns chan_mem[128]; -#seekto 0x1010; struct frqx frq[2]; -#seekto 0x1050; struct fm_chn fm_stations[25]; -#seekto 0x1080; struct { u8 fmunk01[14]; ul16 fmcur; @@ -109,54 +106,51 @@ struct { #seekto 0x1190; struct bitmap chnmap; -#seekto 0x11a0; struct bitmap skpchns; -#seekto 0x011b0; struct { u8 fmset[4]; } fmmap; -#seekto 0x011b4; struct { u8 setunk01[4]; u8 setunk02[3]; - u8 chs_name:1 // 0x11bb - txsel:1 - dbw:1 - setunk05:1 - ponfmchs:2 + u8 chs_name:1, // 0x11bb + txsel:1, + dbw:1, + setunk05:1, + ponfmchs:2, ponchs:2; - u8 voltx:2 // 0x11bc - setunk04:1 - keylok:1 - setunk07:1 + u8 voltx:2, // 0x11bc + setunk04:1, + keylok:1, + setunk07:1, batsav:3; - u8 setunk09:1 // 0x11bd - rxinhib:1 - rgrbeep:1 // inv bool - lampon:2 - voice:2 + u8 setunk09:1, // 0x11bd + rxinhib:1, + rgrbeep:1, // inv bool + lampon:2, + voice:2, beepon:1; - u8 setunk11:1 // 0x11be - manualset:1 - xbandon:1 // inv - xbandenable:1 - openmsg:2 + u8 setunk11:1, // 0x11be + manualset:1, + xbandon:1, // inv + xbandenable:1, + openmsg:2, ledclr:2; - u8 tot:4 // 0x11bf + u8 tot:4, // 0x11bf sql:4; - u8 setunk27:1 // 0x11c0 - voxdelay:2 - setunk28:1 + u8 setunk27:1, // 0x11c0 + voxdelay:2, + setunk28:1, voxgain:4; - u8 fmstep:4 // 0x11c1 + u8 fmstep:4, // 0x11c1 freqstep:4; - u8 scanspeed:4 // 0x11c2 + u8 scanspeed:4, // 0x11c2 scanmode:4; u8 scantmo; // 0x11c3 u8 prichan; // 0x11c4 - u8 setunk12:4 // 0x11c5 + u8 setunk12:4, // 0x11c5 supersave:4; u8 setunk13; u8 fmsclo; // 0x11c7 ??? placeholder @@ -164,26 +158,26 @@ struct { u8 fmschi; // ??? placeholder u8 setunk14[3]; // 0x11d0 u8 setunk17[2]; // 0x011d3, 4 - u8 setunk18:4 + u8 setunk18:4, dtmfspd:4; - u8 dtmfdig1dly:4 // 0x11d6 + u8 dtmfdig1dly:4, // 0x11d6 dtmfdig1time:4; - u8 stuntype:1 - setunk19:1 - dtmfspms:2 + u8 stuntype:1, + setunk19:1, + dtmfspms:2, grpcode:4; - u8 setunk20:1 // 0x11d8 - txdecode:1 - codeabcd:1 - idedit:1 - pttidon:2 + u8 setunk20:1, // 0x11d8 + txdecode:1, + codeabcd:1, + idedit:1, + pttidon:2, setunk40:1, dtmfside:1; u8 setunk50:4, autoresettmo:4; u8 codespctim:4, // 0x11da decodetmo:4; - u8 pttecnt:4 // 0x11db + u8 pttecnt:4, // 0x11db pttbcnt:4; lbcd dtmfdecode[3]; u8 setunk22; @@ -199,11 +193,11 @@ struct { u8 setunk65; u8 setunk66; u8 manfrqyn; // 0x11fd - u8 setunk27:3 - frqr3:1 - setunk28:1 - frqr2:1 - setunk29:1 + u8 setunk27:3, + frqr3:1, + setunk28:1, + frqr2:1, + setunk29:1, frqr1:1; u8 setunk25; ul32 frqr1lo; // 0x1200 @@ -518,21 +512,20 @@ class THUV8000Radio(chirp_common.CloneModeRadio): def get_prompts(cls): rp = chirp_common.RadioPrompts() rp.info = \ - ('Click on the "Special Channels" toggle-button of the memory ' - 'editor to see/set the upper and lower frequency-mode values.\n') + ('Remember the # T-R key is the VFO/MEM toggle.\n') rp.pre_download = _( "Follow these instructions to download the radio memory:\n" "1 - Turn off your radio\n" "2 - Connect your interface cable\n" "3 - Turn on your radio, volume @ 50%\n" - "4 - Radio > Download from radio\n") + "4 - CHIRP Menu - Radio - Download from radio\n") rp.pre_upload = _( "Follow these instructions to upload the radio memory:\n" "1 - Turn off your radio\n" "2 - Connect your interface cable\n" "3 - Turn on your radio, volume @ 50%\n" - "4 - Radio > Upload to radio\n") + "4 - CHIRP Menu - Radio - Upload to radio\n") return rp def get_features(self): @@ -603,7 +596,7 @@ class THUV8000Radio(chirp_common.CloneModeRadio): self._memobj = bitwise.parse(MEM_FORMAT, self._mmap) def get_raw_memory(self, number): - return repr(self._memobj.memory[number - 1]) + return repr(self._memobj.chan_mem[number - 1]) def get_memory(self, number): if isinstance(number, str): @@ -635,7 +628,7 @@ class THUV8000Radio(chirp_common.CloneModeRadio): """Convert raw channel memory data into UI columns""" mem.extra = RadioSettingGroup("extra", "Extra") - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw(asbytes=False)[0] == "\xff": mem.empty = True return mem diff --git a/chirp/drivers/th_uv88.py b/chirp/drivers/th_uv88.py index 3f83f2d..e6632db 100644 --- a/chirp/drivers/th_uv88.py +++ b/chirp/drivers/th_uv88.py @@ -32,24 +32,24 @@ MEM_FORMAT = """ struct chns { ul32 rxfreq; ul32 txfreq; - ul16 scramble:4 + ul16 scramble:4, rxtone:12; //decode:12 - ul16 decodeDSCI:1 - encodeDSCI:1 - unk1:1 - unk2:1 + ul16 decodeDSCI:1, + encodeDSCI:1, + unk1:1, + unk2:1, txtone:12; //encode:12 - u8 power:2 - wide:2 - b_lock:2 + u8 power:2, + wide:2, + b_lock:2, unk3:2; - u8 unk4:3 - signal:2 - displayName:1 + u8 unk4:3, + signal:2, + displayName:1, unk5:2; - u8 unk6:2 - pttid:2 - unk7:1 + u8 unk6:2, + pttid:2, + unk7:1, step:3; // not required u8 name[6]; }; @@ -57,23 +57,23 @@ struct chns { struct vfo { ul32 rxfreq; ul32 txfreq; // displayed as an offset - ul16 scramble:4 + ul16 scramble:4, rxtone:12; //decode:12 - ul16 decodeDSCI:1 - encodeDSCI:1 - unk1:1 - unk2:1 + ul16 decodeDSCI:1, + encodeDSCI:1, + unk1:1, + unk2:1, txtone:12; //encode:12 - u8 power:2 - wide:2 - b_lock:2 + u8 power:2, + wide:2, + b_lock:2, unk3:2; - u8 unk4:3 - signal:2 - displayName:1 + u8 unk4:3, + signal:2, + displayName:1, unk5:2; - u8 unk6:2 - pttid:2 + u8 unk6:2, + pttid:2, step:4; u8 name[6]; }; @@ -82,22 +82,9 @@ struct chname { u8 extra_name[10]; }; -#seekto 0x0000; +// #seekto 0x0000; struct chns chan_mem[199]; -#seekto 0x1960; -struct chname chan_name[199]; - -#seekto 0x1180; -struct { - u8 bitmap[26]; // one bit for each channel marked in use -} chan_avail; - -#seekto 0x11A0; -struct { - u8 bitmap[26]; // one bit for each channel skipped -} chan_skip; - #seekto 0x1140; struct { u8 autoKeylock:1, // 0x1140 [18] *OFF, On @@ -111,7 +98,61 @@ struct { ab:1, // * A, B unk_bit1_0:2; // } workmodesettings; +""" + +MEM_FORMAT_PT2 = """ +// #seekto 0x1180; +struct { + u8 bitmap[26]; // one bit for each channel marked in use +} chan_avail; + +#seekto 0x11A0; +struct { + u8 bitmap[26]; // one bit for each channel skipped +} chan_skip; + +#seekto 0x191E; +struct { + u8 unknown191e:4, // + region:4; // 0x191E Radio Region (read only) + // 0 = Unlocked TX: 136-174 MHz / 400-480 MHz + // 2-3 = Unknown + // 3 = EU TX: 144-146 MHz / 430-440 MHz + // 4 = US TX: 144-148 MHz / 420-450 MHz + // 5-15 = Unknown +} settings2; + +#seekto 0x1940; +struct { + char name1[15]; // Intro Screen Line 1 (16 alpha text characters) + u8 unk1; + char name2[15]; // Intro Screen Line 2 (16 alpha text characters) + u8 unk2; +} openradioname; + +struct fm_chn { + ul32 rxfreq; +}; +// #seekto 0x1960; +struct chname chan_name[199]; + +#seekto 0x2180; +struct fm_chn fm_stations[24]; + +// #seekto 0x021E0; +struct { + u8 fmset[4]; +} fmmap; + +// #seekto 0x21E4; +struct { + ul32 fmcur; +} fmfrqs; + +""" + +THUV88_SETTINGS = """ #seekto 0x1160; struct { u8 introScreen1[12]; // 0x1160 *Intro Screen Line 1(truncated to 12 alpha @@ -120,7 +161,7 @@ struct { // screen unk_bit4 : 1, // sqlLevel : 4; // [05] *OFF, 1-9 - u8 beep : 1 // 0x116D [09] *OFF, On + u8 beep : 1, // 0x116D [09] *OFF, On callKind : 2, // code says 1750,2100,1000,1450 as options // not on screen introScreen: 2, // [20] *OFF, Voltage, Char String @@ -164,43 +205,62 @@ struct { u8 unk4; // 0x1179 u8 name2[6]; // 0x117A unused } basicsettings; +""" -#seekto 0x191E; -struct { - u8 unknown191e:4, // - region:4; // 0x191E Radio Region (read only) - // 0 = Unlocked TX: 136-174 MHz / 400-480 MHz - // 2-3 = Unknown - // 3 = EU TX: 144-146 MHz / 430-440 MHz - // 4 = US TX: 144-148 MHz / 420-450 MHz - // 5-15 = Unknown -} settings2; - -#seekto 0x1940; -struct { - char name1[15]; // Intro Screen Line 1 (16 alpha text characters) - u8 unk1; - char name2[15]; // Intro Screen Line 2 (16 alpha text characters) - u8 unk2; -} openradioname; - -struct fm_chn { - ul32 rxfreq; -}; - -#seekto 0x2180; -struct fm_chn fm_stations[24]; - -#seekto 0x021E0; -struct { - u8 fmset[4]; -} fmmap; - -#seekto 0x21E4; +RA89_SETTINGS = """ +#seekto 0x1160; struct { - ul32 fmcur; -} fmfrqs; - + u8 sideKey2:4, // 0x1160 side key 2 + sideKey1:4; // side key 1 + u8 sideKey2_long:4, // 0x1161 side key 2 Long + sideKey1_long:4; // side key 1 Long + u8 unknownBytes[10]; // 0x1162 - 0x116B + u8 offFreqVoltage : 3, // 0x116C unknown referred to in code but not on + // screen + unk_bit4 : 1, // + sqlLevel : 4; // [05] *OFF, 1-9 + u8 beep : 1, // 0x116D [09] *OFF, On + callKind : 2, // code says 1750,2100,1000,1450 as options + // not on screen + introScreen: 2, // [20] *OFF, Voltage, Char String + unkstr2: 2, // + txChSelect : 1; // [02] *Last CH, Main CH + u8 autoPowOff : 3, // 0x116E not on screen? OFF, 30Min, 1HR, 2HR + unk : 1, // + tot : 4; // [11] *OFF, 30 Second, 60 Second, 90 Second, + // ... , 270 Second + u8 unk_bit7:1, // 0x116F + roger:1, // [14] *OFF, On + dailDef:1, // Unknown - 'Volume, Frequency' + language:1, // English only + endToneElim:2, // *Frequency, 120, 180, 240 (RA89) + unkCheckBox1:1, // + unkCheckBox2:1; // + u8 scanType: 2, // 0x1170 [17] *Off, On, 5s, 10s, 15s, 20s, 25s, 30s + disMode : 2, // [33] *Frequency, Channel, Name + ledMode: 4; // [07] *Off, On, 5s, 10s, 15s, 20s, 25s, 30s + u8 unky; // 0x1171 + u8 str6; // 0x1172 Has flags to do with logging - factory + // enabled (bits 16,64,128) + u8 unk; // 0x1173 + u8 swAudio : 1, // 0x1174 [19] *OFF, On + radioMoni : 1, // [34] *OFF, On + keylock : 1, // [18] *OFF, On + dualWait : 1, // [06] *OFF, On + unk_bit3 : 1, // + light : 3; // [08] *1, 2, 3, 4, 5, 6, 7 + u8 voxSw : 1, // 0x1175 [13] *OFF, On + voxDelay: 4, // *0.5S, 1.0S, 1.5S, 2.0S, 2.5S, 3.0S, 3.5S, + // 4.0S, 4.5S, 5.0S + voxLevel : 3; // [03] *1, 2, 3, 4, 5, 6, 7 + u8 str9 : 4, // 0x1176 + saveMode : 2, // [16] *OFF, 1:1, 1:2, 1:4 + keyMode : 2; // [32] *ALL, PTT, KEY, Key & Side Key + u8 unk2; // 0x1177 + u8 unk3; // 0x1178 + u8 unk4; // 0x1179 + u8 name2[6]; // 0x117A unused +} basicsettings; """ MEM_SIZE = 0x22A0 @@ -561,7 +621,8 @@ class THUV88Radio(chirp_common.CloneModeRadio): def process_mmap(self): """Process the mem map into the mem object""" - self._memobj = bitwise.parse(MEM_FORMAT, self._mmap) + mem_format = MEM_FORMAT + THUV88_SETTINGS + MEM_FORMAT_PT2 + self._memobj = bitwise.parse(mem_format, self._mmap) def get_raw_memory(self, number): return repr(self._memobj.memory[number - 1]) @@ -688,13 +749,20 @@ class THUV88Radio(chirp_common.CloneModeRadio): mem.extra.append(step) scramble_value = _mem.scramble - if scramble_value >= 8: # Looks like OFF is 0x0f ** CONFIRM - scramble_value = 0 - scramble = RadioSetting("scramble", "Scramble", - RadioSettingValueList(SCRAMBLE_LIST, - SCRAMBLE_LIST[ - scramble_value])) - mem.extra.append(scramble) + if self.MODEL == "RA89": + if scramble_value >= 2: + scramble_value = 0 + rs = RadioSetting("scramble", "Scramble", + RadioSettingValueBoolean(_mem.scramble)) + mem.extra.append(rs) + else: + if scramble_value >= 8: # Looks like OFF is 0x0f ** CONFIRM + scramble_value = 0 + scramble = RadioSetting("scramble", "Scramble", + RadioSettingValueList(SCRAMBLE_LIST, + SCRAMBLE_LIST[ + scramble_value])) + mem.extra.append(scramble) optsig = RadioSetting("signal", "Optional signaling", RadioSettingValueList( @@ -819,7 +887,10 @@ class THUV88Radio(chirp_common.CloneModeRadio): basic.append(rset) # Menu 07 - LED Mode - options = ["Off", "On", "Auto"] + if self.MODEL == "RA89": + options = ["Off", "On", "5s", "10s", "15s", "20s", "25s", "30s"] + else: + options = ["Off", "On", "Auto"] rx = RadioSettingValueList(options, options[_settings.ledMode]) rset = RadioSetting("basicsettings.ledMode", "LED Display Mode", rx) basic.append(rset) @@ -880,7 +951,10 @@ class THUV88Radio(chirp_common.CloneModeRadio): basic.append(rset) # Menu 20 - Intro Screen - options = ["Off", "Voltage", "Character String"] + if self.MODEL == "RA89": + options = ["Off", "Voltage", "Character String", "Startup Logo"] + else: + options = ["Off", "Voltage", "Character String"] rx = RadioSettingValueList(options, options[_settings.introScreen]) rset = RadioSetting("basicsettings.introScreen", "Intro Screen", rx) basic.append(rset) @@ -906,7 +980,10 @@ class THUV88Radio(chirp_common.CloneModeRadio): group.append(advanced) # software only - options = ['Off', 'Frequency'] + if self.MODEL == "RA89": + options = ['Frequency', '120', '180', '240'] + else: + options = ['Off', 'Frequency'] rx = RadioSettingValueList(options, options[_settings.endToneElim]) rset = RadioSetting("basicsettings.endToneElim", "End Tone Elim", rx) advanced.append(rset) @@ -958,6 +1035,33 @@ class THUV88Radio(chirp_common.CloneModeRadio): rset = RadioSetting("settings2.region", "Region", rx) advanced.append(rset) + if self.MODEL == "RA89": + options = ["None", "VOX", "Dual Wait", "Scan", "Moni", "1750 Tone", + "Flashlight", "Power Level", "Alarm", + "Noise Cancelaton", "Temp Monitor", "FM Radio", + "Talk Around", "Frequency Reverse"] + rx = RadioSettingValueList(options, options[_settings.sideKey1]) + rset = RadioSetting("basicsettings.sideKey1", "Side Key 1", rx) + advanced.append(rset) + + rx = RadioSettingValueList(options, + options[_settings.sideKey1_long]) + rset = RadioSetting("basicsettings.sideKey1_long", + "Side Key 1 Long", rx) + advanced.append(rset) + + rx = RadioSettingValueList(options, + options[_settings.sideKey2]) + rset = RadioSetting("basicsettings.sideKey2", + "Side Key 2", rx) + advanced.append(rset) + + rx = RadioSettingValueList(options, + options[_settings.sideKey2_long]) + rset = RadioSetting("basicsettings.sideKey2_long", + "Side Key 2 Long", rx) + advanced.append(rset) + workmode = RadioSettingGroup("workmode", "Work Mode Settings") group.append(workmode) @@ -971,7 +1075,7 @@ class THUV88Radio(chirp_common.CloneModeRadio): options = ["Frequency", "Channel"] rx = RadioSettingValueList(options, options[_workmode.vfomrmodeb]) rset = RadioSetting("workmodesettings.vfomrmodeb", - "VFO/MR Mode B (BQ1.41+)", rx) + "VFO/MR Mode B", rx) workmode.append(rset) # Toggle with [A/B] key @@ -1104,6 +1208,23 @@ class RT85(THUV88Radio): @directory.register +class RA89(THUV88Radio): + VENDOR = "Retevis" + MODEL = "RA89" + + _magic0 = b"\xFE\xFE\xEE\xEF\xE0" + b"UV99" + b"\xFD" + _magic2 = b"\xFE\xFE\xEE\xEF\xE2" + b"UV99" + b"\xFD" + _magic3 = b"\xFE\xFE\xEE\xEF\xE3" + b"UV99" + b"\xFD" + _magic5 = b"\xFE\xFE\xEE\xEF\xE5" + b"UV99" + b"\xFD" + _fingerprint = b"\xFE\xFE\xEF\xEE\xE1" + b"UV99" + + def process_mmap(self): + """Process the mem map into the mem object""" + mem_format = MEM_FORMAT + RA89_SETTINGS + MEM_FORMAT_PT2 + self._memobj = bitwise.parse(mem_format, self._mmap) + + +@directory.register class QRZ1(THUV88Radio): VENDOR = "Explorer" MODEL = "QRZ-1" diff --git a/chirp/drivers/th_uvf8d.py b/chirp/drivers/th_uvf8d.py index 32bae59..51881b2 100644 --- a/chirp/drivers/th_uvf8d.py +++ b/chirp/drivers/th_uvf8d.py @@ -367,7 +367,7 @@ class TYTUVF8DRadio(chirp_common.CloneModeRadio): else: mem.number = number - if _mem.get_raw().startswith("\xFF\xFF\xFF\xFF"): + if _mem.get_raw(asbytes=False).startswith("\xFF\xFF\xFF\xFF"): mem.empty = True return mem @@ -447,7 +447,7 @@ class TYTUVF8DRadio(chirp_common.CloneModeRadio): else: e.flags[7 - ((mem.number - 1) % 8)] = True - if _mem.get_raw() == ("\xFF" * 32): + if _mem.get_raw(asbytes=False) == ("\xFF" * 32): LOG.debug("Initializing empty memory") _mem.set_raw("\x00" * 32) @@ -621,12 +621,6 @@ class TYTUVF8DRadio(chirp_common.CloneModeRadio): return top - group.append(RadioSetting( - "disnm", "Display Name", - RadioSettingValueBoolean(_settings.disnm))) - - return group - def set_settings(self, settings): _settings = self._memobj.settings diff --git a/chirp/drivers/thuv1f.py b/chirp/drivers/thuv1f.py index 03990ad..b419820 100644 --- a/chirp/drivers/thuv1f.py +++ b/chirp/drivers/thuv1f.py @@ -286,14 +286,14 @@ class TYTTHUVF1Radio(chirp_common.CloneModeRadio): def _is_txinh(self, _mem): raw_tx = "" for i in range(0, 4): - raw_tx += _mem.tx_freq[i].get_raw() + raw_tx += _mem.tx_freq[i].get_raw(asbytes=False) return raw_tx == "\xFF\xFF\xFF\xFF" def get_memory(self, number): _mem = self._memobj.memory[number - 1] mem = chirp_common.Memory() mem.number = number - if _mem.get_raw().startswith("\xFF\xFF\xFF\xFF"): + if _mem.get_raw(asbytes=False).startswith("\xFF\xFF\xFF\xFF"): mem.empty = True return mem @@ -357,7 +357,7 @@ class TYTTHUVF1Radio(chirp_common.CloneModeRadio): _mem.set_raw(b"\xFF" * 16) return - if _mem.get_raw() == ("\xFF" * 16): + if _mem.get_raw(asbytes=False) == ("\xFF" * 16): LOG.debug("Initializing empty memory") _mem.set_raw(b"\x00" * 16) diff --git a/chirp/drivers/tk270.py b/chirp/drivers/tk270.py index d2cf981..326b411 100644 --- a/chirp/drivers/tk270.py +++ b/chirp/drivers/tk270.py @@ -493,7 +493,7 @@ class Kenwood_P60_Radio(chirp_common.CloneModeRadio, chirp_common.ExperimentalRa def decode_tone(self, val): """Parse the tone data to decode from mem, it returns: Mode (''|DTCS|Tone), Value (None|###), Polarity (None,N,R)""" - if val.get_raw() == "\xFF\xFF": + if val.get_raw(asbytes=False) == "\xFF\xFF": return '', None, None val = int(val) @@ -556,7 +556,7 @@ class Kenwood_P60_Radio(chirp_common.CloneModeRadio, chirp_common.ExperimentalRa # Memory number mem.number = number - if _mem.get_raw()[0] == "\xFF": + if _mem.get_raw(asbytes=False)[0] == "\xFF": mem.empty = True # but is not enough, you have to clear the memory in the mmap # to get it ready for the sync_out process, just in case @@ -568,7 +568,7 @@ class Kenwood_P60_Radio(chirp_common.CloneModeRadio, chirp_common.ExperimentalRa # Freq and offset mem.freq = int(_mem.rxfreq) * 10 # tx freq can be blank - if _mem.get_raw()[4] == "\xFF" or int(_mem.txen) == 255: + if _mem.get_raw(asbytes=False)[4] == "\xFF" or int(_mem.txen) == 255: # TX freq not set mem.offset = 0 mem.duplex = "off" diff --git a/chirp/drivers/tk3140.py b/chirp/drivers/tk3140.py index 580fd16..5e87653 100644 --- a/chirp/drivers/tk3140.py +++ b/chirp/drivers/tk3140.py @@ -505,7 +505,7 @@ class KenwoodTKx140Radio(chirp_common.CloneModeRadio): mask = 1 << (slot % 8) m.freq = int(_mem.rx_freq) * 10 offset = int(_mem.tx_freq) * 10 - m.freq - if _mem.tx_freq.get_raw(asbytes=True) == b'\xFF\xFF\xFF\xFF': + if _mem.tx_freq.get_raw() == b'\xFF\xFF\xFF\xFF': m.offset = 0 m.duplex = 'off' elif offset < 0: @@ -557,7 +557,7 @@ class KenwoodTKx140Radio(chirp_common.CloneModeRadio): elif mem.duplex == 'split': _mem.tx_freq = mem.offset // 10 elif mem.duplex == 'off': - _mem.tx_freq.set_raw(b'\xFF' * 4) + _mem.tx_freq = 0xFFFFFFFF elif mem.duplex == '-': _mem.tx_freq = (mem.freq - mem.offset) // 10 elif mem.duplex == '+': diff --git a/chirp/drivers/tk760.py b/chirp/drivers/tk760.py index f914ab2..b9314dc 100644 --- a/chirp/drivers/tk760.py +++ b/chirp/drivers/tk760.py @@ -470,7 +470,7 @@ class Kenwood_M60_Radio(chirp_common.CloneModeRadio, def decode_tone(self, val): """Parse the tone data to decode from mem, it returns: Mode (''|DTCS|Tone), Value (None|###), Polarity (None,N,R)""" - if val.get_raw() == "\xFF\xFF": + if val.get_raw(asbytes=False) == "\xFF\xFF": return '', None, None val = int(val) @@ -556,7 +556,8 @@ class Kenwood_M60_Radio(chirp_common.CloneModeRadio, # Memory number mem.number = number - if _mem.get_raw()[0] == "\xFF" or not self.get_active(number - 1): + if (_mem.get_raw(asbytes=False)[0] == "\xFF" or + not self.get_active(number - 1)): mem.empty = True # but is not enough, you have to clear the memory in the mmap # to get it ready for the sync_out process @@ -566,7 +567,7 @@ class Kenwood_M60_Radio(chirp_common.CloneModeRadio, # Freq and offset mem.freq = int(_mem.rxfreq) * 10 # tx freq can be blank - if _mem.get_raw()[4] == "\xFF": + if _mem.get_raw(asbytes=False)[4] == "\xFF": # TX freq not set mem.offset = 0 mem.duplex = "off" diff --git a/chirp/drivers/tk760g.py b/chirp/drivers/tk760g.py index 858010b..5ce31e9 100644 --- a/chirp/drivers/tk760g.py +++ b/chirp/drivers/tk760g.py @@ -216,7 +216,7 @@ struct { // -- u8 ptt_id:2, // ??? BOT = 0, EOT = 1, Both = 2, NONE = 3 beat_shift:1, // 1 = off - unknown26:2 // ??? + unknown26:2, // ??? power:1, // power: 0 low / 1 high compander:1, // 1 = off wide:1; // wide 1 / 0 narrow @@ -942,14 +942,14 @@ class Kenwood_Serie_60G(chirp_common.CloneModeRadio, mem.number = number # A "blank" rxfreq is the indication of an empty memory - if _mem.rxfreq[0].get_raw() == '\xFF': + if _mem.rxfreq[0].get_raw(asbytes=False) == '\xFF': mem.empty = True return mem # Freq and offset mem.freq = int(_mem.rxfreq) * 10 # tx freq can be blank - if _mem.get_raw()[16] == "\xFF": + if _mem.get_raw(asbytes=False)[16] == "\xFF": # TX freq not set mem.offset = 0 mem.duplex = "off" diff --git a/chirp/drivers/tk8102.py b/chirp/drivers/tk8102.py index d4434e3..888f015 100644 --- a/chirp/drivers/tk8102.py +++ b/chirp/drivers/tk8102.py @@ -39,7 +39,7 @@ struct { beatshift:1; u8 pttid:2, highpower:1, - scan:1 + scan:1, unknown2:4; u8 unknown3[2]; } memory[8]; @@ -297,7 +297,7 @@ class KenwoodTKx102Radio(chirp_common.CloneModeRadio): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[:4] == "\xFF\xFF\xFF\xFF": + if _mem.get_raw(asbytes=False)[:4] == "\xFF\xFF\xFF\xFF": mem.empty = True return mem diff --git a/chirp/drivers/tk8160.py b/chirp/drivers/tk8160.py index 15d4eb4..94e6bf3 100644 --- a/chirp/drivers/tk8160.py +++ b/chirp/drivers/tk8160.py @@ -492,7 +492,7 @@ class TKx160Radio(chirp_common.CloneModeRadio): m.freq = int(_mem.rx_freq) * 10 offset = int(_mem.tx_freq) * 10 - m.freq - if _mem.tx_freq.get_raw(asbytes=True) == b'\xFF\xFF\xFF\xFF': + if _mem.tx_freq.get_raw() == b'\xFF\xFF\xFF\xFF': m.offset = 0 m.duplex = 'off' elif offset < 0: diff --git a/chirp/drivers/tk8180.py b/chirp/drivers/tk8180.py index 04e2c3e..476df13 100644 --- a/chirp/drivers/tk8180.py +++ b/chirp/drivers/tk8180.py @@ -554,12 +554,12 @@ class KenwoodTKx180Radio(chirp_common.CloneModeRadio): # Copy the zone record from the source, but then update # the count - dest_zoneinfo.set_raw(source_zoneinfo.get_raw()) + dest_zoneinfo.set_raw(source_zoneinfo.get_raw(asbytes=False)) dest_zoneinfo.count = count source_i = 0 for dest_i in range(0, min(count, old_count)): - dest[dest_i].set_raw(source[dest_i].get_raw()) + dest[dest_i].set_raw(source[dest_i].get_raw(asbytes=False)) else: LOG.debug('New zone %i' % zone_number) dest_zone.zoneinfo.number = zone_number + 1 @@ -586,7 +586,8 @@ class KenwoodTKx180Radio(chirp_common.CloneModeRadio): if current == memories: LOG.debug('Shuffle not required') return - raw_data = [raw_memories[i].get_raw() for i, n in memories] + raw_data = [raw_memories[i].get_raw(asbytes=False) + for i, n in memories] for i, raw_mem in enumerate(raw_data): raw_memories[i].set_raw(raw_mem) @@ -712,7 +713,7 @@ class KenwoodTKx180Radio(chirp_common.CloneModeRadio): mem.power = POWER_LEVELS[_mem.highpower] offset = (int(_mem.tx_freq) - int(_mem.rx_freq)) * 10 - if _mem.tx_freq.get_raw(asbytes=True) == b'\xFF\xFF\xFF\xFF': + if _mem.tx_freq.get_raw() == b'\xFF\xFF\xFF\xFF': mem.offset = 0 mem.duplex = 'off' elif offset == 0: diff --git a/chirp/drivers/tmd710.py b/chirp/drivers/tmd710.py index a234189..cd553db 100644 --- a/chirp/drivers/tmd710.py +++ b/chirp/drivers/tmd710.py @@ -1564,7 +1564,7 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant resp0 = _command(radio.pipe, cmc, 260, W8S) junk = _command(radio.pipe, ACK, 1, W8S) if len(resp0) < 260: - junk = _command(radio.pipe, "E", 2, W8S) + junk = _command(radio.pipe, b"E", 2, W8S) sx = "Block 0x%x read error: " % bkx sx += "Got %i bytes, expected 260." % len(resp0) LOG.error(sx) @@ -1588,7 +1588,7 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant junk = _command(radio.pipe, ACK, 1, W8S) _update_status(radio, status) # Exit Prog mode, no TERM - resp = _command(radio.pipe, "E", 2, W8S) # Rtns 06 0d + resp = _command(radio.pipe, b"E", 2, W8S) # Rtns 06 0d radio.pipe.baudrate = BAUD return data @@ -1607,27 +1607,27 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant imgadr = 0 radio.pipe.baudrate = BAUD - resp0 = _command(radio.pipe, "0M PROGRAM" + TERM, 3, W8S) + resp0 = _command(radio.pipe, b"0M PROGRAM" + TERM, 3, W8S) # Read block 0 magic header thingy, save it - cmc = "R" + chr(0) + chr(0) + chr(4) + cmc = b"R" + bytes([0, 0, 4]) resp0 = _command(radio.pipe, cmc, 8, W8S) mht0 = resp0[4:] # Expecting [57 00 00 04] 03 4b 01 ff junk = _command(radio.pipe, ACK, 1, W8S) - cmc = "W" + chr(0) + chr(0) + chr(1) + chr(0x0ff) + cmc = b"W" + bytes([0, 0, 1, 0xff]) junk = _command(radio.pipe, cmc, 1, W8S) # responds ACK - cmc = "R" + chr(0x080) + chr(0) + chr(3) + cmc = b"R" + bytes([0x80, 0, 3]) resp = _command(radio.pipe, cmc, 7, W8S) # [57 80 00 03] 00 33 00 mht1 = resp[4:] junk = _command(radio.pipe, ACK, 1, W8S) - cmc = "W" + chr(0x080) + chr(0) + chr(1) + chr(0x0ff) + cmc = b"W" + bytes([0x80, 0, 1, 0xff]) junk = _command(radio.pipe, cmc, 1, W8S) imgadr = 4 # After 03 4b 01 ff for bkx in range(0, radio._num_packets[0]): - cmc = "W" + chr(bkx) + chr(0) + chr(0) + cmc = b"W" + bytes([bkx, 0, 0]) imgstep = 256 if bkx == 0: imgstep = 0x0fc - cmc = "W" + chr(0) + chr(4) + chr(imgstep) + cmc = b"W" + bytes([0, 4, imgstep]) cmc += radio.get_mmap()[imgadr:imgadr + imgstep] else: # after first packet cmc += radio.get_mmap()[imgadr:imgadr + imgstep] @@ -1640,7 +1640,7 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant imgadr += imgstep _update_status(radio, status) # UI Update # write fe and ff blocks - cmc = "W" + chr(0x0fe) + chr(0x0f0) + chr(16) + cmc = b"W" + bytes([0xfe, 0xf0, 16]) cmc += radio.get_mmap()[imgadr:imgadr + 16] resp0 = _command(radio.pipe, cmc, 1, W8S) if resp0 != ACK: @@ -1648,7 +1648,7 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant sx = "Radio failed to acknowledge upload packet!" raise errors.RadioError(sx) imgadr += 16 - cmc = "W" + chr(0x0ff) + chr(0) + chr(0x090) + cmc = b"W" + bytes([0xff, 0, 0x90]) cmc += radio.get_mmap()[imgadr:imgadr + 0x090] resp0 = _command(radio.pipe, cmc, 1, W8S) if resp0 != ACK: @@ -1656,21 +1656,21 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant sx = "Radio failed to acknowledge upload packet!" raise errors.RadioError(sx) # Write mht1 - cmc = "W" + chr(0x080) + chr(0) + chr(3) + mht1 + cmc = b"W" + bytes([0x80, 0, 3]) + mht1 resp0 = _command(radio.pipe, cmc, 1, W8S) if resp0 != ACK: LOG.error("Mht1 Write error at 0x080 00 03 , no ACK.") sx = "Radio failed to acknowledge upload packet!" raise errors.RadioError(sx) # and mht0 - cmc = "W" + chr(0) + chr(0) + chr(4) + mht0 + cmc = b"W" + bytes([0, 0, 4]) + mht0 resp0 = _command(radio.pipe, cmc, 1, W8S) if resp0 != ACK: LOG.error("Mht0 Write error at 00 00 04 , no ACK.") sx = "Radio failed to acknowledge upload packet!" raise errors.RadioError(sx) # Write E to Exit PROG mode - resp = _command(radio.pipe, "E", 2, W8S) + resp = _command(radio.pipe, b"E", 2, W8S) return @directory.register @@ -1976,7 +1976,7 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant def _make_command(self, cmd, addr, length, data=b''): cmc = struct.pack('>IB', addr, length) - return cmd.encode() + cmc[1:] + data + return cmd + cmc[1:] + data def _read_mem(radio): """ Load the memory map """ @@ -2005,7 +2005,7 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant for bkx in range(0, radio._num_packets[blkn]): addr = (radio._block_addr[blkn] << 8) | (bkx << 8) resp0 = _command(radio.pipe, - radio._make_command('R', addr, 0), + radio._make_command(b'R', addr, 0), radio._packet_size[blkn], W8S) if len(resp0) < radio._packet_size[blkn]: junk = _command(radio.pipe, b"E", 0, W8S) @@ -2051,13 +2051,13 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant # Read block 0 magic header thingy, save it addr = radio._block_addr[0] << 8 resp0 = _command(radio.pipe, - radio._make_command('R', addr, 4), + radio._make_command(b'R', addr, 4), 16, W8S) mht0 = resp0[5:] # Now get block 1 mht addr = radio._block_addr[1] << 8 resp0 = _command(radio.pipe, - radio._make_command('R', addr, 5), + radio._make_command(b'R', addr, 5), 16, W8S) mht1 = resp0[5:] for blkn in range(0, radio._num_blocks): @@ -2073,7 +2073,7 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant 256] else: # after first packet data = radio.get_mmap()[imgadr:imgadr + 256] - cmc = radio._make_command('W', addr, 0, data) + cmc = radio._make_command(b'W', addr, 0, data) resp0 = _command(radio.pipe, cmc, 6, W8S) if bkx > 0 and resp0 != ACK: @@ -2084,12 +2084,12 @@ if HAS_FUTURE: # Only register drivers if environment is PY3 compliant imgadr += 256 _update_status(radio, status) # UI Update # Re-write magic headers - cmc = radio._make_command('W', (radio._block_addr[0] << 8) | 1, 3, + cmc = radio._make_command(b'W', (radio._block_addr[0] << 8) | 1, 3, mht0[1:3] + b'\x32') resp0 = _command(radio.pipe, cmc, 1, W8S) - cmc = radio._make_command('W', radio._block_addr[1] << 8, 5, mht1) + cmc = radio._make_command(b'W', radio._block_addr[1] << 8, 5, mht1) resp0 = _command(radio.pipe, cmc, 1, W8S) - cmc = radio._make_command('Z', radio._block_addr[0], 1, mht0[0:1]) + cmc = radio._make_command(b'Z', radio._block_addr[0], 1, mht0[0:1]) resp0 = _command(radio.pipe, cmc, 16, W8S) # Write E to Exit PROG mode resp = _command(radio.pipe, b"E", 0, W8S) diff --git a/chirp/drivers/uv5r.py b/chirp/drivers/uv5r.py index 4e1601f..a64b5fa 100644 --- a/chirp/drivers/uv5r.py +++ b/chirp/drivers/uv5r.py @@ -24,7 +24,7 @@ from chirp import bitwise from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ - RadioSettingValueFloat, InvalidValueError, RadioSettings + InvalidValueError, RadioSettings LOG = logging.getLogger(__name__) @@ -162,7 +162,7 @@ struct { sftd:2, scode:4; u8 unknown4; - u8 unused3:1 + u8 unused3:1, step:3, unused4:4; u8 txpower:1, @@ -184,7 +184,7 @@ struct { sftd:2, scode:4; u8 unknown4; - u8 unused3:1 + u8 unused3:1, step:3, unused4:4; u8 txpower:1, @@ -220,28 +220,6 @@ struct { char line2[7]; } firmware_msg; -struct limit { - u8 enable; - bbcd lower[2]; - bbcd upper[2]; -}; - -#seekto 0x1908; -struct { - struct limit vhf; - struct limit uhf; -} limits_new; - -#seekto 0x1910; -struct { - u8 unknown1[2]; - struct limit vhf; - u8 unknown2; - u8 unknown3[8]; - u8 unknown4[2]; - struct limit uhf; -} limits_old; - struct squelch { u8 sql0; u8 sql1; @@ -270,6 +248,28 @@ struct { struct squelch uhf; } squelch_old; +struct limit { + u8 enable; + bbcd lower[2]; + bbcd upper[2]; +}; + +#seekto 0x1908; +struct { + struct limit vhf; + struct limit uhf; +} limits_new; + +#seekto 0x1910; +struct { + u8 unknown1[2]; + struct limit vhf; + u8 unknown2; + u8 unknown3[8]; + u8 unknown4[2]; + struct limit uhf; +} limits_old; + """ # 0x1EC0 - 0x2000 @@ -675,12 +675,13 @@ def _do_upload(radio): # Uploading full Aux mem area is permitted aux_matched = True - if has_dropped_byte and not aux_matched: - msg = ("Image not supported by radio. You must...\n" - "1. Download from radio.\n" - "2. Make changes.\n" - "3. Upload back to same radio.") - raise errors.RadioError(msg) + if not radio._all_range_flag: + if has_dropped_byte and not aux_matched: + msg = ("Image not supported by radio. You must...\n" + "1. Download from radio.\n" + "2. Make changes.\n" + "3. Upload back to same radio.") + raise errors.RadioError(msg) # default ranges _ranges_main_default = [ @@ -908,10 +909,10 @@ class BaofengUV5R(chirp_common.CloneModeRadio): return repr(self._memobj.memory[number]) def _is_txinh(self, _mem): - raw_tx = "" + raw_tx = b"" for i in range(0, 4): raw_tx += _mem.txfreq[i].get_raw() - return raw_tx == "\xFF\xFF\xFF\xFF" + return raw_tx == b"\xFF\xFF\xFF\xFF" def _get_mem(self, number): return self._memobj.memory[number] @@ -926,7 +927,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio): mem = chirp_common.Memory() mem.number = number - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw()[:1] == b"\xff": mem.empty = True return mem @@ -1060,7 +1061,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio): was_empty = False # same method as used in get_memory to find # out whether a raw memory is empty - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw(asbytes=False)[0] == "\xff": was_empty = True LOG.debug("UV5R: this mem was empty") else: diff --git a/chirp/drivers/uv6r.py b/chirp/drivers/uv6r.py index 0acca29..64e27ba 100644 --- a/chirp/drivers/uv6r.py +++ b/chirp/drivers/uv6r.py @@ -124,7 +124,7 @@ class UV6R(baofeng_common.BaofengCommonHT): SCODE_LIST = LIST_SCODE MEM_FORMAT = """ - #seekto 0x0000; + // #seekto 0x0000; struct { lbcd rxfreq[4]; lbcd txfreq[4]; @@ -315,7 +315,7 @@ class UV6R(baofeng_common.BaofengCommonHT): char line2[8]; } sixpoweron_msg; - #seekto 0x1FE0; + // #seekto 0x1FE0; struct { char line1[7]; char line2[7]; @@ -853,7 +853,7 @@ class UV6R(baofeng_common.BaofengCommonHT): match_model = False # testing the file data size - if len(filedata) == 0x2008 or 0x2010: + if len(filedata) in (0x2008, 0x2010): match_size = True # testing the firmware model fingerprint diff --git a/chirp/drivers/uvb5.py b/chirp/drivers/uvb5.py index d0ec2c4..87a9e50 100644 --- a/chirp/drivers/uvb5.py +++ b/chirp/drivers/uvb5.py @@ -406,7 +406,7 @@ class BaofengUVB5(chirp_common.CloneModeRadio, else: mem.number = number - if _mem.freq.get_raw(asbytes=True)[0] == 0xff: + if _mem.freq.get_raw()[0] == 0xff: mem.empty = True return mem @@ -462,7 +462,7 @@ class BaofengUVB5(chirp_common.CloneModeRadio, _mem.set_raw("\xFF" * 16) return - if _mem.get_raw() == ("\xFF" * 16): + if _mem.get_raw(asbytes=False) == ("\xFF" * 16): _mem.set_raw("\x00" * 13 + "\xFF" * 3) _mem.freq = mem.freq / 10 diff --git a/chirp/drivers/uvk5.py b/chirp/drivers/uvk5.py index aba8408..f7a1a38 100644 --- a/chirp/drivers/uvk5.py +++ b/chirp/drivers/uvk5.py @@ -495,6 +495,13 @@ def _sayhello(serport): LOG.debug("Sending hello packet") _send_command(serport, hellopacket) o = _receive_reply(serport) + + if o[0] == 0x18 and o[1] == 0x05: + LOG.warning("Radio is in firmware flash mode") + raise errors.RadioError( + "This radio is in firmware flash mode (PTT + turn on). " + "Please do this according to the vendor documentation") + if (o): break tries -= 1 @@ -568,7 +575,7 @@ def do_download(radio): if f: radio.FIRMWARE_VERSION = f else: - return False + raise errors.RadioError('Unable to determine firmware version') addr = 0 while addr < MEM_SIZE: @@ -646,14 +653,14 @@ class UVK5Radio(chirp_common.CloneModeRadio): def get_prompts(x=None): rp = chirp_common.RadioPrompts() - rp.experimental = \ - ('This is an experimental driver for the Quansheng UV-K5. ' - 'It may harm your radio, or worse. Use at your own risk.\n\n' - 'Before attempting to do any changes please download ' - 'the memory image from the radio with chirp ' - 'and keep it. This can be later used to recover the ' - 'original settings. \n\n' - 'some details are not yet implemented') + rp.experimental = _( + 'This is an experimental driver for the Quansheng UV-K5. ' + 'It may harm your radio, or worse. Use at your own risk.\n\n' + 'Before attempting to do any changes please download ' + 'the memory image from the radio with chirp ' + 'and keep it. This can be later used to recover the ' + 'original settings. \n\n' + 'some details are not yet implemented') rp.pre_download = _( "1. Turn radio on.\n" "2. Connect cable to mic/spkr connector.\n" @@ -871,23 +878,30 @@ class UVK5Radio(chirp_common.CloneModeRadio): # set some sane defaults: mem.power = UVK5_POWER_LEVELS[2] mem.extra = RadioSettingGroup("Extra", "extra") - rs = RadioSetting("bclo", "BCLO", RadioSettingValueBoolean(False)) + rs = RadioSetting( + "bclo", "BCLO", + RadioSettingValueBoolean(False)) mem.extra.append(rs) - rs = RadioSetting("frev", "FreqRev", - RadioSettingValueBoolean(False)) + rs = RadioSetting( + "frev", "FreqRev", + RadioSettingValueBoolean(False)) mem.extra.append(rs) - rs = RadioSetting("pttid", "PTTID", RadioSettingValueList( - PTTID_LIST, PTTID_LIST[0])) + rs = RadioSetting( + "pttid", "PTTID", + RadioSettingValueList(PTTID_LIST, PTTID_LIST[0])) mem.extra.append(rs) - rs = RadioSetting("dtmfdecode", "DTMF decode", - RadioSettingValueBoolean(False)) + rs = RadioSetting( + "dtmfdecode", _("DTMF decode"), + RadioSettingValueBoolean(False)) mem.extra.append(rs) - rs = RadioSetting("scrambler", "Scrambler", RadioSettingValueList( - SCRAMBLER_LIST, SCRAMBLER_LIST[0])) + rs = RadioSetting( + "scrambler", _("Scrambler"), + RadioSettingValueList(SCRAMBLER_LIST, SCRAMBLER_LIST[0])) mem.extra.append(rs) - rs = RadioSetting("scanlists", "Scanlists", RadioSettingValueList( - SCANLIST_LIST, SCANLIST_LIST[0])) + rs = RadioSetting( + "scanlists", _("Scanlists"), + RadioSettingValueList(SCANLIST_LIST, SCANLIST_LIST[0])) mem.extra.append(rs) # actually the step and duplex are overwritten by chirp based on @@ -985,7 +999,7 @@ class UVK5Radio(chirp_common.CloneModeRadio): # DTMF DECODE is_dtmf = bool(_mem.dtmf_decode > 0) - rs = RadioSetting("dtmfdecode", "DTMF decode", + rs = RadioSetting("dtmfdecode", _("DTMF decode"), RadioSettingValueBoolean(is_dtmf)) mem.extra.append(rs) tmpcomment += "DTMFdecode:"+(is_dtmf and "ON" or "off")+" " @@ -996,12 +1010,12 @@ class UVK5Radio(chirp_common.CloneModeRadio): else: enc = 0 - rs = RadioSetting("scrambler", "Scrambler", RadioSettingValueList( + rs = RadioSetting("scrambler", _("Scrambler"), RadioSettingValueList( SCRAMBLER_LIST, SCRAMBLER_LIST[enc])) mem.extra.append(rs) tmpcomment += "Scrambler:"+SCRAMBLER_LIST[enc]+" " - rs = RadioSetting("scanlists", "Scanlists", RadioSettingValueList( + rs = RadioSetting("scanlists", _("Scanlists"), RadioSettingValueList( SCANLIST_LIST, tmpscn)) mem.extra.append(rs) @@ -1309,9 +1323,9 @@ class UVK5Radio(chirp_common.CloneModeRadio): dtmfc = RadioSettingGroup("dtmfc", "DTMF Contacts") scanl = RadioSettingGroup("scn", "Scan Lists") unlock = RadioSettingGroup("unlock", "Unlock Settings") - fmradio = RadioSettingGroup("fmradio", "FM Radio") + fmradio = RadioSettingGroup("fmradio", _("FM Radio")) - roinfo = RadioSettingGroup("roinfo", "Driver information") + roinfo = RadioSettingGroup("roinfo", _("Driver information")) top = RadioSettings( basic, keya, dtmf, dtmfc, scanl, unlock, fmradio, roinfo) @@ -1818,14 +1832,14 @@ class UVK5Radio(chirp_common.CloneModeRadio): # Logo string 1 logo1 = str(_mem.logo_line1).strip("\x20\x00\xff") + "\x00" logo1 = _getstring(logo1.encode('ascii', errors='ignore'), 0, 12) - rs = RadioSetting("logo1", "Logo string 1 (12 characters)", + rs = RadioSetting("logo1", _("Logo string 1 (12 characters)"), RadioSettingValueString(0, 12, logo1)) basic.append(rs) # Logo string 2 logo2 = str(_mem.logo_line2).strip("\x20\x00\xff") + "\x00" logo2 = _getstring(logo2.encode('ascii', errors='ignore'), 0, 12) - rs = RadioSetting("logo2", "Logo string 2 (12 characters)", + rs = RadioSetting("logo2", _("Logo string 2 (12 characters)"), RadioSettingValueString(0, 12, logo2)) basic.append(rs) @@ -1939,18 +1953,18 @@ class UVK5Radio(chirp_common.CloneModeRadio): return mem # clean the channel memory, restore some bits if it was used before - if _mem.get_raw()[0] == "\xff": + if _mem.get_raw(asbytes=False)[0] == "\xff": # this was an empty memory _mem.set_raw("\x00" * 16) else: # this memory wasn't empty, save some bits that we don't know the # meaning of, or that we don't support yet - prev_0a = _mem.get_raw(asbytes=True)[0x0a] & SAVE_MASK_0A - prev_0b = _mem.get_raw(asbytes=True)[0x0b] & SAVE_MASK_0B - prev_0c = _mem.get_raw(asbytes=True)[0x0c] & SAVE_MASK_0C - prev_0d = _mem.get_raw(asbytes=True)[0x0d] & SAVE_MASK_0D - prev_0e = _mem.get_raw(asbytes=True)[0x0e] & SAVE_MASK_0E - prev_0f = _mem.get_raw(asbytes=True)[0x0f] & SAVE_MASK_0F + prev_0a = _mem.get_raw()[0x0a] & SAVE_MASK_0A + prev_0b = _mem.get_raw()[0x0b] & SAVE_MASK_0B + prev_0c = _mem.get_raw()[0x0c] & SAVE_MASK_0C + prev_0d = _mem.get_raw()[0x0d] & SAVE_MASK_0D + prev_0e = _mem.get_raw()[0x0e] & SAVE_MASK_0E + prev_0f = _mem.get_raw()[0x0f] & SAVE_MASK_0F _mem.set_raw("\x00" * 10 + chr(prev_0a) + chr(prev_0b) + chr(prev_0c) + chr(prev_0d) + chr(prev_0e) + chr(prev_0f)) @@ -2056,3 +2070,10 @@ class UVK5Radio(chirp_common.CloneModeRadio): _mem4.channel_attributes[number].is_scanlist2 = 0 return mem + + +@directory.register +class RA79Radio(UVK5Radio): + """Retevis RA79""" + VENDOR = "Retevis" + MODEL = "RA79" diff --git a/chirp/drivers/vgc.py b/chirp/drivers/vgc.py index 72e63df..46e0b79 100644 --- a/chirp/drivers/vgc.py +++ b/chirp/drivers/vgc.py @@ -691,7 +691,7 @@ class VGCStyleRadio(chirp_common.CloneModeRadio, def decode_tone(self, val): """Parse the tone data to decode from mem, it returns: Mode (''|DTCS|Tone), Value (None|###), Polarity (None,N,R)""" - if val.get_raw() == "\xFF\xFF": + if val.get_raw(asbytes=False) == "\xFF\xFF": return '', None, None val = int(val) @@ -757,7 +757,7 @@ class VGCStyleRadio(chirp_common.CloneModeRadio, # Freq and offset mem.freq = int(_mem.rxfreq) * 10 # tx freq can be blank - if _mem.get_raw()[4] == "\xFF": + if _mem.get_raw(asbytes=False)[4] == "\xFF": # TX freq not set mem.offset = 0 mem.duplex = "off" diff --git a/chirp/drivers/vx3.py b/chirp/drivers/vx3.py index fcbbd05..6cff083 100644 --- a/chirp/drivers/vx3.py +++ b/chirp/drivers/vx3.py @@ -39,7 +39,7 @@ struct { u8 unk01_1:3, att_broadcast:1, att_marine:1, - unk01_2:2 + unk01_2:2, att_wx:1; u8 unk02; u8 apo; diff --git a/chirp/drivers/vx8.py b/chirp/drivers/vx8.py index 2f6e571..9160847 100644 --- a/chirp/drivers/vx8.py +++ b/chirp/drivers/vx8.py @@ -50,7 +50,7 @@ struct { u8 lcd_dimmer; u8 dtmf_delay; u8 unknown0[3]; - u8 unknown1:4 + u8 unknown1:4, lcd_contrast:4; u8 lamp; u8 unknown2[7]; @@ -201,7 +201,7 @@ struct { u8 unknown7:1, aprs_units_wind_mph:1, aprs_units_rain_inch:1, - aprs_units_temperature_f:1 + aprs_units_temperature_f:1, aprs_units_altitude_ft:1, unknown8:1, aprs_units_distance_m:1, diff --git a/chirp/drivers/vxa700.py b/chirp/drivers/vxa700.py index 604f3d3..78d155a 100644 --- a/chirp/drivers/vxa700.py +++ b/chirp/drivers/vxa700.py @@ -223,7 +223,7 @@ class VXA700Radio(chirp_common.CloneModeRadio): def get_raw_memory(self, number): _mem = self._get_mem(number) - return repr(_mem) + util.hexprint(_mem.get_raw()) + return repr(_mem) + util.hexprint(_mem.get_raw(asbytes=False)) def get_memory(self, number): _mem = self._get_mem(number) diff --git a/chirp/drivers/wouxun.py b/chirp/drivers/wouxun.py index fb3e1f1..a0e2116 100644 --- a/chirp/drivers/wouxun.py +++ b/chirp/drivers/wouxun.py @@ -745,7 +745,7 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, def _is_txinh(self, _mem): raw_tx = "" for i in range(0, 4): - raw_tx += _mem.tx_freq[i].get_raw() + raw_tx += _mem.tx_freq[i].get_raw(asbytes=False) return raw_tx == "\xFF\xFF\xFF\xFF" def get_memory(self, number): @@ -755,7 +755,7 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, mem = chirp_common.Memory() mem.number = number - if _mem.get_raw() == ("\xff" * 16): + if _mem.get_raw(asbytes=False) == ("\xff" * 16): mem.empty = True return mem @@ -851,7 +851,7 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, wipe_memory(_mem, "\xFF") return - if _mem.get_raw() == ("\xFF" * 16): + if _mem.get_raw(asbytes=False) == ("\xFF" * 16): wipe_memory(_mem, "\x00") _mem.rx_freq = int(mem.freq / 10) diff --git a/chirp/drivers/yaesu_clone.py b/chirp/drivers/yaesu_clone.py index b5a8697..a5e7643 100644 --- a/chirp/drivers/yaesu_clone.py +++ b/chirp/drivers/yaesu_clone.py @@ -90,6 +90,8 @@ def __clone_in(radio): pipe.write(bytes([CMD_ACK])) if not chunk: raise errors.RadioError("No response from radio") + if blocks == 1: + LOG.debug('ID block: %s' % util.hexprint(chunk)) if radio.status_fn: status.cur = len(data) radio.status_fn(status) diff --git a/chirp/locale/el/LC_MESSAGES/CHIRP.mo b/chirp/locale/el/LC_MESSAGES/CHIRP.mo Binary files differindex b127b5c..9624ba4 100644 --- a/chirp/locale/el/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/el/LC_MESSAGES/CHIRP.mo diff --git a/chirp/locale/es/LC_MESSAGES/CHIRP.mo b/chirp/locale/es/LC_MESSAGES/CHIRP.mo Binary files differindex ef20806..fb874f9 100644 --- a/chirp/locale/es/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/es/LC_MESSAGES/CHIRP.mo diff --git a/chirp/locale/fr/LC_MESSAGES/CHIRP.mo b/chirp/locale/fr/LC_MESSAGES/CHIRP.mo Binary files differindex 71435f6..5569d58 100644 --- a/chirp/locale/fr/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/fr/LC_MESSAGES/CHIRP.mo diff --git a/chirp/locale/it/LC_MESSAGES/CHIRP.mo b/chirp/locale/it/LC_MESSAGES/CHIRP.mo Binary files differindex bb8e631..20a27c6 100644 --- a/chirp/locale/it/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/it/LC_MESSAGES/CHIRP.mo diff --git a/chirp/locale/ja_JP/LC_MESSAGES/CHIRP.mo b/chirp/locale/ja_JP/LC_MESSAGES/CHIRP.mo Binary files differnew file mode 100644 index 0000000..29b3ae4 --- /dev/null +++ b/chirp/locale/ja_JP/LC_MESSAGES/CHIRP.mo diff --git a/chirp/locale/pl/LC_MESSAGES/CHIRP.mo b/chirp/locale/pl/LC_MESSAGES/CHIRP.mo Binary files differindex f3d9e4f..249f2a1 100644 --- a/chirp/locale/pl/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/pl/LC_MESSAGES/CHIRP.mo diff --git a/chirp/locale/ru/LC_MESSAGES/CHIRP.mo b/chirp/locale/ru/LC_MESSAGES/CHIRP.mo Binary files differindex e75bc04..da0903c 100644 --- a/chirp/locale/ru/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/ru/LC_MESSAGES/CHIRP.mo diff --git a/chirp/locale/tr_TR/LC_MESSAGES/CHIRP.mo b/chirp/locale/tr_TR/LC_MESSAGES/CHIRP.mo Binary files differindex aa6e695..aa358fc 100644 --- a/chirp/locale/tr_TR/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/tr_TR/LC_MESSAGES/CHIRP.mo diff --git a/chirp/settings.py b/chirp/settings.py index 9d9cfe4..3ba8666 100644 --- a/chirp/settings.py +++ b/chirp/settings.py @@ -77,6 +77,9 @@ class RadioSettingValue: def __trunc__(self): return int(self.get_value()) + def __int__(self): + return int(self.get_value()) + def __float__(self): return float(self.get_value()) @@ -203,6 +206,9 @@ class RadioSettingValueList(RadioSettingValue): def __trunc__(self): return self._options.index(self._current) + def __int__(self): + return self._options.index(self._current) + class RadioSettingValueString(RadioSettingValue): @@ -296,6 +302,12 @@ class RadioSettingValueMap(RadioSettingValueList): value = self._mem_vals[index] return value + def __int__(self): + """Return memory value that matches current user option""" + index = self._options.index(self._current) + value = self._mem_vals[index] + return value + def zero_indexed_seq_map(user_options): """RadioSettingValueMap factory method @@ -338,11 +350,18 @@ class RadioSettingGroup(object): self.__doc__ = name # Longer explanation/documentation self._elements = {} self._element_order = [] + self._frozen = False for element in elements: self._validate(element) self.append(element) + def set_frozen(self): + self._frozen = True + for i in self: + if isinstance(i, RadioSettingGroup): + i.set_frozen() + def get_name(self): """Returns the group name""" return self._name @@ -367,6 +386,8 @@ class RadioSettingGroup(object): def append(self, element): """Adds an element to the group""" + if self._frozen: + raise ValueError('Setting is frozen') self[element.get_name()] = element def __iter__(self): @@ -502,6 +523,8 @@ class RadioSetting(RadioSettingGroup): def __setattr__(self, name, value): if name == "value": + if self._frozen: + raise ValueError('Value is frozen') if len(self) == 1: self._elements[self._element_order[0]].set_value(value) else: diff --git a/chirp/share/chirp.desktop b/chirp/share/chirp.desktop index b202e44..bd71605 100644 --- a/chirp/share/chirp.desktop +++ b/chirp/share/chirp.desktop @@ -7,7 +7,7 @@ Comment=Program amateur radios Icon=chirp Exec=chirp %F Terminal=false -MimeType=inode/directory +MimeType=x-scheme-handler/chirp Categories=Utility;HamRadio Keywords=Hamradio;Programming;Handheld;Radio;Amateur;Programmer StartupNotify=true diff --git a/chirp/share/chirp.ico b/chirp/share/chirp.ico Binary files differindex 4006ff9..61aecdf 100755..100644 --- a/chirp/share/chirp.ico +++ b/chirp/share/chirp.ico diff --git a/chirp/share/chirp.png b/chirp/share/chirp.png Binary files differindex fe57c1a..d144e02 100644 --- a/chirp/share/chirp.png +++ b/chirp/share/chirp.png diff --git a/chirp/share/chirp.svg b/chirp/share/chirp.svg index 38d0d05..5d3c9d6 100644 --- a/chirp/share/chirp.svg +++ b/chirp/share/chirp.svg @@ -2,23 +2,23 @@ <!-- Created with Inkscape (http://www.inkscape.org/) --> <svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="256" height="256" id="svg3773" version="1.1" - inkscape:version="0.48.0 r9654" - sodipodi:docname="icon.svg" - inkscape:export-filename="/home/dan/chirp/share/chirp_icon.png" - inkscape:export-xdpi="90" - inkscape:export-ydpi="90"> + inkscape:version="1.3.2 (091e20e, 2023-11-25)" + sodipodi:docname="chirp.svg" + inkscape:export-filename="chirp.png" + inkscape:export-xdpi="96.48922" + inkscape:export-ydpi="96.48922" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/"> <defs id="defs3775"> <linearGradient @@ -92,18 +92,60 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="1.979899" - inkscape:cx="111.6916" - inkscape:cy="154.81709" + inkscape:zoom="3.2435839" + inkscape:cx="161.70385" + inkscape:cy="124.86188" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" - inkscape:window-width="1111" - inkscape:window-height="898" - inkscape:window-x="1" - inkscape:window-y="51" + inkscape:window-width="1800" + inkscape:window-height="1097" + inkscape:window-x="0" + inkscape:window-y="44" inkscape:window-maximized="0" - borderlayer="true" /> + borderlayer="true" + inkscape:showpageshadow="2" + inkscape:pagecheckerboard="0" + inkscape:deskcolor="#d1d1d1" + showguides="true"> + <sodipodi:guide + position="55.910117,91.046225" + orientation="0,-1" + id="guide1" + inkscape:locked="false" /> + <sodipodi:guide + position="51.745255,94.201423" + orientation="0,-1" + id="guide2" + inkscape:locked="false" /> + <sodipodi:guide + position="90.364884,166.13995" + orientation="0,-1" + id="guide3" + inkscape:locked="false" /> + <sodipodi:guide + position="101.09256,163.11096" + orientation="0,-1" + id="guide4" + inkscape:locked="false" /> + <sodipodi:guide + position="94.68792,194.26092" + orientation="1,0" + id="guide5" + inkscape:locked="false" /> + <sodipodi:guide + position="162.82484,219.53236" + orientation="1,0" + id="guide6" + inkscape:locked="false" /> + <sodipodi:guide + position="128,202.25821" + orientation="-1,0" + id="guide7" + inkscape:locked="false" + inkscape:label="" + inkscape:color="rgb(0,134,229)" /> + </sodipodi:namedview> <metadata id="metadata3778"> <rdf:RDF> @@ -112,7 +154,6 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> </cc:Work> </rdf:RDF> </metadata> @@ -139,18 +180,37 @@ ry="15.791736" /> <path inkscape:connector-curvature="0" - style="fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:1.23044455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" - d="m 176.78712,885.35647 c -33.62642,0.1389 -67.25587,-0.18333 -100.880357,0.1862 -10.307609,1.15201 -19.345272,9.79377 -20.699091,20.10844 -0.734857,7.05609 0.897593,14.58458 1.473236,21.58057 0.575642,6.99598 2.096299,13.83094 4.182258,19.70411 3.479417,9.79656 6.451804,11.97487 16.555151,16.29131 7.142428,0.37214 13.943255,0.28453 21.089461,0.46476 27.657372,-0.0642 53.912612,-1.19078 81.567102,-1.59673 10.50595,-5.2167 13.89795,-6.89364 18.02695,-17.49826 1.87897,-7.32651 3.80822,-16.77839 4.02861,-24.11121 0.009,-5.82937 0.31554,-11.74161 -0.81517,-17.4877 -2.45934,-9.1155 -10.69152,-16.42239 -20.14851,-17.42617 -1.43779,-0.21495 -2.92033,-0.22722 -4.37962,-0.21532 z" + style="display:none;fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:1.23044;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + d="m 176.78712,885.35647 c -33.62642,0.1389 -67.25587,-0.18333 -100.880357,0.1862 -10.307609,1.15201 -19.345272,9.79377 -20.699091,20.10844 -0.734857,7.05609 0.897593,14.58458 1.473236,21.58057 0.575642,6.99598 2.096299,13.83094 4.182258,19.70411 3.479417,9.79656 10.366223,14.50071 16.176527,15.15544 34.086267,0.1824 72.380787,-0.1666 102.512007,-0.13666 5.52192,0.15445 13.57715,-7.03431 17.70615,-17.63893 2.47589,-7.79078 3.38622,-14.80909 3.88794,-19.18797 0.71232,-7.23601 1.03035,-17.59782 0.0346,-21.18515 -2.45934,-9.1155 -10.5566,-17.36685 -20.01359,-18.37063 -1.43779,-0.21495 -2.92033,-0.22722 -4.37962,-0.21532 z" id="rect2830" - sodipodi:nodetypes="ccczscccccccc" /> + sodipodi:nodetypes="ccczscccccccc" + inkscape:label="oldouterdsub" /> <path inkscape:connector-curvature="0" - style="fill:#59aab2;fill-opacity:1;stroke:#000000;stroke-width:1.23044455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" - d="m 177.85993,889.75915 c -34.19435,0.32943 -68.39927,-0.43608 -102.586798,0.42688 -6.581373,1.02477 -12.230044,5.96703 -14.624589,12.10443 -1.284683,3.33332 -1.417022,6.99701 -1.014183,10.53154 0.538398,7.49048 1.640967,14.91401 2.648463,22.35103 1.207501,6.2585 2.930373,12.62821 6.648149,17.88864 2.721379,2.88972 6.415636,4.83199 10.246351,5.75465 4.307496,0.36597 8.637278,0.11598 12.951316,0.33184 28.885631,0.36595 57.750051,-1.08191 86.627201,-1.48002 2.83271,-1.09459 5.46743,-2.62236 8.0348,-4.2381 3.3277,-2.36475 5.74082,-5.93039 6.84205,-9.85432 2.19763,-6.55876 3.08044,-13.48374 3.81607,-20.33915 0.52396,-6.74433 0.69701,-13.6319 -0.80149,-20.26168 -2.52836,-7.83335 -10.57852,-13.40621 -18.78734,-13.21574 z" - id="path3672" /> + style="display:none;fill:#59aab2;fill-opacity:1;stroke:#000000;stroke-width:1.23;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + d="m 177.85993,889.75915 c -34.19435,0.32943 -68.39927,-0.43608 -102.586798,0.42688 -6.581373,1.02477 -12.230044,5.96703 -14.624589,12.10443 -1.284683,3.33332 -1.417022,6.99701 -1.014183,10.53154 0.538398,7.49048 1.640967,14.91401 2.648463,22.35103 1.207501,6.2585 2.930373,12.62821 6.648149,17.88864 2.721379,2.88972 4.900502,4.45377 10.120143,4.49257 33.056245,-0.13175 66.522365,0.17621 99.704725,0.1139 2.83271,-1.09459 5.46743,-2.62236 8.0348,-4.2381 3.3277,-2.36475 5.74082,-5.93039 6.84205,-9.85432 2.19763,-6.55876 3.08044,-13.48374 3.81607,-20.33915 0.52396,-6.74433 0.69701,-13.6319 -0.80149,-20.26168 -2.52836,-7.83335 -10.57852,-13.40621 -18.78734,-13.21574 z" + id="path3672" + sodipodi:nodetypes="ccccccccccccc" + inkscape:label="oldinnerdsub" /> + <path + id="path3735" + sodipodi:nodetypes="cccccccccc" + style="display:inline;fill:#999999;stroke:#000000;stroke-width:1.2;stroke-linecap:round;stroke-dasharray:none;fill-opacity:1" + d="M 74.380028,886.453 H 184.79963 c 8.78925,0 15.86496,7.1895 15.86496,16.11969 l -5.0246,42.84021 c -1.20115,9.29053 -8.5943,16.08539 -17.38355,16.08539 l -99.436067,-0.25008 c -8.789255,0 -15.864974,-7.18947 -15.864974,-16.11976 l -4.442222,-42.55671 c 0,-8.93018 7.075718,-16.11966 15.864968,-16.11966 z" + inkscape:label="outerdsub" /> + <path + style="display:inline;fill:#59aab2;stroke:#000000;stroke-width:1.2;stroke-linecap:round;stroke-dasharray:none;fill-opacity:1" + sodipodi:type="inkscape:offset" + inkscape:radius="-5.2141833" + inkscape:original="M 74.378906 886.45117 C 65.589656 886.45117 58.513672 893.64209 58.513672 902.57227 L 62.955078 945.12891 C 62.955078 954.0592 70.031058 961.24805 78.820312 961.24805 L 178.25586 961.49805 C 187.04511 961.49805 194.43947 954.70264 195.64062 945.41211 L 200.66406 902.57227 C 200.66406 893.64208 193.58808 886.45312 184.79883 886.45312 L 74.380859 886.45312 L 74.378906 886.45117 z " + xlink:href="#path3735" + id="path9" + inkscape:href="#path3735" + d="m 74.376953,891.66602 c -5.912661,0.001 -10.581128,4.6876 -10.630859,10.81445 l 4.394531,42.10742 a 5.2147047,5.2147047 0 0 1 0.0293,0.54102 c 0,6.17595 4.70431,10.90429 10.65039,10.90429 a 5.2147047,5.2147047 0 0 1 0.01367,0 l 99.421876,0.25 c 6.10168,0 11.31919,-4.6266 12.21289,-11.53906 l -0.006,0.0606 4.96484,-42.3418 c -0.0592,-6.11821 -4.72064,-10.79492 -10.6289,-10.79492 H 74.380859 a 5.2147047,5.2147047 0 0 1 -0.002,-0.002 z" + inkscape:label="innerdsub" /> <text xml:space="preserve" - style="font-size:17.71840286px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:BankGothic Md BT;-inkscape-font-specification:BankGothic Md BT Bold" + style="font-size:23.7333px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:BankGothic;-inkscape-font-specification:'BankGothic, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;letter-spacing:-1.64px" x="77.551765" y="917.85834" id="text3710"><tspan @@ -159,66 +219,66 @@ x="77.551765" y="917.85834" dx="0 0 -0.70311111 0 4.2186675 0 4.9217787 0 1.0546669" - style="font-size:20.91755867px">c h i r p</tspan></text> + style="font-size:23.73333333px;-inkscape-font-specification:'BankGothic, Bold';font-family:BankGothic;font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;letter-spacing:-1.64px">c h i r p</tspan></text> <path - sodipodi:type="arc" style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" id="path3716" - sodipodi:cx="-634.28571" - sodipodi:cy="583.79077" - sodipodi:rx="74.285713" - sodipodi:ry="74.285713" + transform="matrix(0.12304446,0,0,0.12304446,104.62155,854.11197)" d="m -559.99999,583.79077 a 74.285713,74.285713 0 1 1 -148.57143,0 74.285713,74.285713 0 1 1 148.57143,0 z" - transform="matrix(0.12304446,0,0,0.12304446,104.62155,854.11197)" /> + sodipodi:type="arc" + sodipodi:ry="74.285713" + sodipodi:rx="74.285713" + sodipodi:cy="583.79077" + sodipodi:cx="-634.28571" /> <path transform="matrix(0.12304446,0,0,0.12304446,309.93003,852.31903)" + id="path3718" + style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" d="m -559.99999,583.79077 a 74.285713,74.285713 0 1 1 -148.57143,0 74.285713,74.285713 0 1 1 148.57143,0 z" + sodipodi:type="arc" sodipodi:ry="74.285713" sodipodi:rx="74.285713" sodipodi:cy="583.79077" - sodipodi:cx="-634.28571" - id="path3718" - style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" - sodipodi:type="arc" /> + sodipodi:cx="-634.28571" /> <path - sodipodi:type="arc" style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" id="path3741" - sodipodi:cx="-48.57143" - sodipodi:cy="689.50507" - sodipodi:rx="28.571428" - sodipodi:ry="28.571428" + transform="matrix(0.12304446,0,0,0.12304446,100.75445,851.65107)" d="m -20.000002,689.50507 a 28.571428,28.571428 0 1 1 -57.142857,0 28.571428,28.571428 0 1 1 57.142857,0 z" - transform="matrix(0.12304446,0,0,0.12304446,100.75445,851.65107)" /> + sodipodi:type="arc" + sodipodi:ry="28.571428" + sodipodi:rx="28.571428" + sodipodi:cy="689.50507" + sodipodi:cx="-48.57143" /> <path transform="matrix(0.12304446,0,0,0.12304446,123.39463,851.65107)" + id="path3743" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" d="m -20.000002,689.50507 a 28.571428,28.571428 0 1 1 -57.142857,0 28.571428,28.571428 0 1 1 57.142857,0 z" + sodipodi:type="arc" sodipodi:ry="28.571428" sodipodi:rx="28.571428" sodipodi:cy="689.50507" - sodipodi:cx="-48.57143" - id="path3743" - style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" - sodipodi:type="arc" /> + sodipodi:cx="-48.57143" /> <path transform="matrix(0.12304446,0,0,0.12304446,168.92106,851.65107)" + id="path3747" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" d="m -20.000002,689.50507 a 28.571428,28.571428 0 1 1 -57.142857,0 28.571428,28.571428 0 1 1 57.142857,0 z" + sodipodi:type="arc" sodipodi:ry="28.571428" sodipodi:rx="28.571428" sodipodi:cy="689.50507" - sodipodi:cx="-48.57143" - id="path3747" - style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" - sodipodi:type="arc" /> + sodipodi:cx="-48.57143" /> <path - sodipodi:type="arc" style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" id="path4566" - sodipodi:cx="-48.57143" - sodipodi:cy="689.50507" - sodipodi:rx="28.571428" - sodipodi:ry="28.571428" + transform="matrix(0.12304446,0,0,0.12304446,145.69407,851.65107)" d="m -20.000002,689.50507 a 28.571428,28.571428 0 1 1 -57.142857,0 28.571428,28.571428 0 1 1 57.142857,0 z" - transform="matrix(0.12304446,0,0,0.12304446,145.69407,851.65107)" /> + sodipodi:type="arc" + sodipodi:ry="28.571428" + sodipodi:rx="28.571428" + sodipodi:cy="689.50507" + sodipodi:cx="-48.57143" /> </g> </svg> diff --git a/chirp/sources/repeaterbook.py b/chirp/sources/repeaterbook.py index 63ebca7..3185d8a 100644 --- a/chirp/sources/repeaterbook.py +++ b/chirp/sources/repeaterbook.py @@ -215,6 +215,7 @@ class RepeaterBook(base.NetworkResultRadio): search_filter = params.pop('filter', '') bands = params.pop('bands', []) modes = params.pop('modes', []) + fmconv = params.pop('fmconv', False) data_file = self.get_data(status, params.get('country'), params.pop('state'), @@ -273,6 +274,11 @@ class RepeaterBook(base.NetworkResultRadio): continue if not m: continue + # Convert any non-FM repeater to FM if user requested it + if m.mode != 'FM' and fmconv and item.get('FM Analog') == 'Yes': + LOG.debug('Converting repeater %r from %r to FM: %s', + item['Rptr ID'], m.mode, m.comment) + m.mode = 'FM' if modes and m.mode not in modes: continue self._memories.append(m) diff --git a/chirp/wxui/__init__.py b/chirp/wxui/__init__.py index e2f9a6b..f5b07cc 100644 --- a/chirp/wxui/__init__.py +++ b/chirp/wxui/__init__.py @@ -142,6 +142,7 @@ def chirpmain(): app._lc.Init() app._lc.AddCatalog('CHIRP') builtins._ = wx.GetTranslation + builtins.ngettext = wx.GetTranslation LOG.debug('Using locale: %s (%i)', app._lc.GetCanonicalName(), lang) @@ -164,7 +165,7 @@ def chirpmain(): directory.import_drivers(limit=args.onlydriver) - if CONF.get('developer', 'state'): + if CONF.get_bool('developer', 'state'): from chirp.drivers import fake fake.register_fakes() diff --git a/chirp/wxui/clone.py b/chirp/wxui/clone.py index 35e07e9..fe3c2ee 100644 --- a/chirp/wxui/clone.py +++ b/chirp/wxui/clone.py @@ -15,6 +15,8 @@ import collections import logging +import platform +import re import textwrap import threading @@ -198,14 +200,36 @@ class ChirpRadioPromptDialog(wx.Dialog): def port_label(port): + if platform.system() == 'Windows': + # The OS format for description is "Long Name (COMn)", so use + # port: desc to make the port visible early in the string without + # changing the description format. + label_fmt = '%(dev)s: %(desc)s' + else: + label_fmt = '%(desc)s (%(dev)s)' + dev = port.device + if dev.startswith('/dev/'): + dev = dev.split('/dev/')[1] if not port.description: - return port.device + return dev elif port.description == 'n/a': - return port.device - elif port.device not in port.description: - return '%s (%s)' % (port.description, port.device) + return dev else: - return port.description + return label_fmt % ({'desc': port.description, + 'dev': dev}) + + +def port_sort_key(port): + key = port.device + if platform.system() == 'Windows': + try: + m = re.match('^COM([0-9]+)$', port.device) + if m: + key = 'COM%08i' % int(m.group(1)) + except Exception as e: + LOG.warning('Failed to stable format %s: %s', port.device, e) + + return key # Make this global so it sticks for a session @@ -302,10 +326,11 @@ class ChirpCloneDialog(wx.Dialog): '/dev/cu.Bluetooth-Incoming-Port', ] + LOG.debug('All system ports: %s', [x.__dict__ for x in system_ports]) self.ports = [(port.device, port_label(port)) - for port in system_ports + for port in sorted(system_ports, + key=port_sort_key) if port.device not in filter_ports] - self.ports.sort() favorite_ports = CONF.get('favorite_ports', 'state') or '' for port in favorite_ports.split(','): diff --git a/chirp/wxui/common.py b/chirp/wxui/common.py index eb3c177..7513cc0 100644 --- a/chirp/wxui/common.py +++ b/chirp/wxui/common.py @@ -615,6 +615,8 @@ def reveal_location(path): wx.Execute('explorer %s' % path) elif system == 'Darwin': wx.Execute('open -R %s' % path) + elif system == 'Linux': + wx.Execute('open %s' % path) else: raise Exception(_('Unable to reveal %s on this system') % path) diff --git a/chirp/wxui/developer.py b/chirp/wxui/developer.py index 37e288e..d8047ce 100644 --- a/chirp/wxui/developer.py +++ b/chirp/wxui/developer.py @@ -83,8 +83,10 @@ class MemoryDialog(wx.Dialog): if isinstance(mem, tuple): mem_a, mem_b = mem self._diff_memories(mem_a, mem_b) + self.SetTitle(_('Diff Raw Memories')) else: self._raw_memory(mem) + self.SetTitle(_('Show Raw Memory')) self.SetSize(640, 480) self.Centre() diff --git a/chirp/wxui/main.py b/chirp/wxui/main.py index 7bd3795..df0560f 100644 --- a/chirp/wxui/main.py +++ b/chirp/wxui/main.py @@ -601,14 +601,14 @@ class ChirpMain(wx.Frame): add_stock(fn) found.append(os.path.basename(fn)) - stock.Append(wx.MenuItem(stock, wx.ID_SEPARATOR)) + if user_stock_confs: + stock.Append(wx.MenuItem(stock, wx.ID_SEPARATOR)) - if sys.platform in ('darwin', 'win32'): + if sys.platform in ('darwin', 'linux', 'win32'): reveal = stock.Append(REVEAL_STOCK_DIR, _('Open stock config directory')) self.Bind(wx.EVT_MENU, self._menu_open_stock_config, reveal) - - stock.Append(wx.MenuItem(stock, wx.ID_SEPARATOR)) + stock.Append(wx.MenuItem(stock, wx.ID_SEPARATOR)) for fn, hash in dist_stock_confs: if os.path.basename(fn) in found: @@ -669,7 +669,8 @@ class ChirpMain(wx.Frame): if last_files: submenu_item = self.OPEN_RECENT_MENU.Append( self.restore_tabs_item, - _('Restore %i tabs' % len(last_files))) + ngettext('Restore %i tab', 'Restore %i tabs', len(last_files)) + % len(last_files)) submenu_item.SetAccel(wx.AcceleratorEntry( wx.MOD_CONTROL | wx.ACCEL_SHIFT, ord('T'))) self.Bind(wx.EVT_MENU, self.restore_tabs, submenu_item) @@ -1587,10 +1588,10 @@ class ChirpMain(wx.Frame): self.SetBackgroundColour((0xEA, 0x62, 0x62, 0xFF)) - with open(filename) as module: + with open(filename, 'rb') as module: code = module.read() sha = hashlib.sha256() - sha.update(code.encode()) + sha.update(code) LOG.info('Loading module %s SHA256 %s' % (filename, sha.hexdigest())) import importlib.util diff --git a/chirp/wxui/memedit.py b/chirp/wxui/memedit.py index 45a4304..dab020d 100644 --- a/chirp/wxui/memedit.py +++ b/chirp/wxui/memedit.py @@ -16,7 +16,6 @@ import functools import logging import pickle -import platform import sys import wx @@ -38,6 +37,7 @@ from chirp.wxui import developer LOG = logging.getLogger(__name__) CONF = config.get() +WX_GTK = 'gtk' in wx.version().lower() class ChirpMemoryGrid(wx.grid.Grid, glr.GridWithLabelRenderersMixin): @@ -266,9 +266,6 @@ class ChirpFrequencyColumn(ChirpMemoryColumn): class ChirpVariablePowerColumn(ChirpMemoryColumn): - def __init__(self, name, radio, power_levels): - super().__init__(name, radio) - @property def level(self): return _('Power') @@ -676,6 +673,8 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): self._grid.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK, self._memory_rclick) self._grid.Bind(wx.grid.EVT_GRID_CELL_BEGIN_DRAG, self._memory_drag) + if WX_GTK: + self._grid.Bind(wx.EVT_KEY_DOWN, self._gtk_short_circuit_edit_copy) row_labels = self._grid.GetGridRowLabelWindow() row_labels.Bind(wx.EVT_LEFT_DOWN, self._row_click) row_labels.Bind(wx.EVT_LEFT_UP, self._row_click) @@ -685,6 +684,19 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): self._dc = wx.ScreenDC() self.set_cell_attrs() + def _gtk_short_circuit_edit_copy(self, event): + # wxGTK is broken and does not direct Ctrl-C to the menu items + # because wx.grid.Grid() tries to implement something for it, + # which we don't want. The wxWidgets people say the only way is to + # grab it ourselves and direct it appropriately before wx.grid.Grid() + # can do it. + # https://github.com/wxWidgets/wxWidgets/issues/22625 + if (event.GetKeyCode() == ord('C') and + event.GetModifiers() == wx.MOD_CONTROL): + self.cb_copy(cut=False) + else: + event.Skip() + def _row_click(self, event): # In order to override the drag-to-multi-select behavior of the base # grid, we need to basically reimplement what happens when a user @@ -765,7 +777,7 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): return self._col_defs.index(self._col_def_by_name('comment')) def set_cell_attrs(self): - if platform.system() == 'Linux': + if WX_GTK: minwidth = 100 else: minwidth = 75 @@ -857,12 +869,13 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): valid_modes = filter_unknowns(self._features.valid_modes) valid_skips = filter_unknowns(self._features.valid_skips) valid_duplexes = filter_unknowns(self._features.valid_duplexes) - valid_power_levels = self._features.valid_power_levels valid_tuning_steps = self._features.valid_tuning_steps if self._features.has_variable_power: - power_col_cls = ChirpVariablePowerColumn + power_column = ChirpVariablePowerColumn('power', self._radio) else: - power_col_cls = ChirpChoiceColumn + valid_power_levels = self._features.valid_power_levels + power_column = ChirpChoiceColumn('power', self._radio, + valid_power_levels) defs = [ ChirpFrequencyColumn('freq', self._radio), ChirpMemoryColumn('name', self._radio), @@ -885,8 +898,7 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): label=_('Tuning Step')), ChirpChoiceColumn('skip', self._radio, valid_skips), - power_col_cls('power', self._radio, - valid_power_levels), + power_column, ChirpCommentColumn('comment', self._radio), ] return defs @@ -940,7 +952,7 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): if setting.get_name() not in self._extra_cols: self._expand_extra_col(setting) - def _refresh_memory(self, number, memory): + def _refresh_memory(self, number, memory, orig_mem=None): row = self.mem2row(number) if isinstance(memory, Exception): @@ -974,6 +986,11 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): if memory.extra: self._expand_extra(memory) + if orig_mem: + delta = orig_mem.debug_diff(memory, '->') + if delta: + LOG.debug('Driver refresh delta from set: %s', delta) + self._memory_cache[row] = memory with wx.grid.GridUpdateLocker(self._grid): @@ -1017,14 +1034,14 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): else: self._grid.SetRowLabelValue(row, '*%i' % memory.number) - def refresh_memory(self, number, lazy=False): + def refresh_memory(self, number, lazy=False, orig_mem=None): if lazy: executor = self.do_lazy_radio else: executor = self.do_radio def extra_cb(job): - self._refresh_memory(number, job.result) + self._refresh_memory(number, job.result, orig_mem=orig_mem) def get_cb(job): # If get_memory() failed, just refresh with the exception @@ -1050,12 +1067,13 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): def set_memory(self, mem, refresh=True): """Update a memory in the radio and refresh our view on success""" row = self.mem2row(mem.number) + orig_mem = mem.dupe() if refresh: self.set_row_pending(row) def extra_cb(job): if refresh: - self.refresh_memory(mem.number) + self.refresh_memory(mem.number, orig_mem=orig_mem) def set_cb(job): if isinstance(job.result, Exception): @@ -1068,6 +1086,8 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): else: extra_cb(job) + LOG.debug('Setting memory: %r' % mem) + # Use a FrozenMemory for the actual set to catch potential attempts # to modify the memory during set_memory(). self.do_radio(set_cb, 'set_memory', chirp_common.FrozenMemory(mem)) @@ -1304,7 +1324,7 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): col_def = self._col_defs[col] try: - mem = self._memory_cache[row] + mem = self._memory_cache[row].dupe() except KeyError: # This means we never loaded this memory from the radio in the # first place, likely due to some error. @@ -1312,6 +1332,8 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): event.Veto() return + orig_mem = mem.dupe() + # Filter the name according to the radio's rules before we try to # validate it if col_def.name == 'name': @@ -1395,8 +1417,9 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): _('Warning')) self.set_row_pending(row) + LOG.debug('Memory row %i column %i(%s) edited: %s', + row, col, col_def.name, orig_mem.debug_diff(mem, '->')) self.set_memory(mem) - LOG.debug('Memory %i changed, column: %i:%s' % (row, col, mem)) wx.CallAfter(self._resize_col_after_edit, row, col) @@ -1555,14 +1578,18 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): if len(selected_rows) > 1: del_item = wx.MenuItem( delete_menu, wx.NewId(), - _('%i Memories') % len(selected_rows)) + ngettext('%i Memory', '%i Memories', + len(selected_rows)) % len(selected_rows)) del_block_item = wx.MenuItem( delete_menu, wx.NewId(), - _('%i Memories and shift block up') % ( - len(selected_rows))) + ngettext('%i Memory and shift block up', + '%i Memories and shift block up', + len(selected_rows)) % (len(selected_rows))) del_shift_item = wx.MenuItem( delete_menu, wx.NewId(), - _('%i Memories and shift all up') % len(selected_rows)) + ngettext('%i Memories and shift all up', + '%i Memories and shift all up', + len(selected_rows)) % len(selected_rows)) to_delete = selected_rows else: del_item = wx.MenuItem(delete_menu, wx.NewId(), _('This Memory')) @@ -1603,10 +1630,13 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): sort_menu = wx.Menu() sort_menu_item = menu.AppendSubMenu( sort_menu, - _('Sort %i memories') % len(selected_rows)) + ngettext('Sort %i memory', 'Sort %i memories', + len(selected_rows)) % len(selected_rows)) sortasc_item = wx.MenuItem( sort_menu, wx.NewId(), - _('Sort %i memories ascending') % len(selected_rows)) + ngettext('Sort %i memory ascending', + 'Sort %i memories ascending', + len(selected_rows)) % len(selected_rows)) self.Bind(wx.EVT_MENU, functools.partial(self._sort_memories, selected_rows, False), @@ -1615,7 +1645,8 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): arrange_item = wx.MenuItem( menu, wx.NewId(), - _('Cluster %i memories') % used_selected) + ngettext('Cluster %i memory', 'Cluster %i memories', + used_selected) % used_selected) self.Bind(wx.EVT_MENU, functools.partial(self._arrange_memories, selected_rows), arrange_item) @@ -1625,7 +1656,9 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): sortdesc_item = wx.MenuItem( menu, wx.NewId(), - _('Sort %i memories descending') % len(selected_rows)) + ngettext('Sort %i memory descending', + 'Sort %i memories descending', + len(selected_rows)) % len(selected_rows)) self.Bind(wx.EVT_MENU, functools.partial(self._sort_memories, selected_rows, True), @@ -1647,13 +1680,13 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): raw_item) menu.Append(raw_item) - if len(selected_rows) == 2: - diff_item = wx.MenuItem(menu, wx.NewId(), - _('Diff Raw Memories')) - self.Bind(wx.EVT_MENU, - functools.partial(self._mem_diff, selected_rows), - diff_item) - menu.Append(diff_item) + diff_item = wx.MenuItem(menu, wx.NewId(), + _('Diff Raw Memories')) + self.Bind(wx.EVT_MENU, + functools.partial(self._mem_diff, selected_rows), + diff_item) + menu.Append(diff_item) + menu.Enable(diff_item.GetId(), len(selected_rows) == 2) self.PopupMenu(menu) menu.Destroy() @@ -2184,8 +2217,8 @@ class ChirpMemPropDialog(wx.Dialog): setattr(mem, name, prop.GetValue()) else: setattr(mem, name, value) - LOG.debug('Changed mem %i %s=%r' % (mem.number, name, - value)) + LOG.debug('Properties dialog changed mem %i %s=%r', + mem.number, name, value) if prop.GetName() == 'freq': mem.empty = False diff --git a/chirp/wxui/query_sources.py b/chirp/wxui/query_sources.py index 3d8409c..7aff99e 100644 --- a/chirp/wxui/query_sources.py +++ b/chirp/wxui/query_sources.py @@ -37,7 +37,7 @@ QueryThreadEvent, EVT_QUERY_THREAD = wx.lib.newevent.NewCommandEvent() class NumberValidator(wx.Validator): - THING = 'Number' + THING = _('Number') MIN = 0 MAX = 1 OPTIONAL = True @@ -62,7 +62,7 @@ class NumberValidator(wx.Validator): catalog = {'value': self.THING, 'min': self.MIN, 'max': self.MAX} - wx.MessageBox(msg % catalog, 'Invalid Entry') + wx.MessageBox(msg % catalog, _('Invalid Entry')) return False def Clone(self): @@ -84,19 +84,19 @@ class NumberValidator(wx.Validator): class LatValidator(NumberValidator): - THING = 'Latitude' + THING = _('Latitude') MIN = -90 MAX = 90 class LonValidator(NumberValidator): - THING = 'Longitude' + THING = _('Longitude') MIN = -180 MAX = 180 class DistValidator(NumberValidator): - THING = 'Distance' + THING = _('Distance') MIN = 0 MAX = 7000 @@ -254,7 +254,7 @@ class RepeaterBookQueryDialog(QuerySourceDialog): NAME = 'Repeaterbook' def get_info(self): - return ( + return _( "RepeaterBook is Amateur Radio's most comprehensive,\n" "worldwide, FREE repeater directory.") @@ -328,6 +328,12 @@ class RepeaterBookQueryDialog(QuerySourceDialog): self.Bind(wx.EVT_CHECKBOX, self._select_modes, self._modefilter) self._add_grid(grid, _('Limit Modes'), self._modefilter) + self._fmconv = wx.CheckBox(panel, label=_('Convert to FM')) + self._fmconv.SetValue(CONF.get_bool('fmconv', 'repeaterbook')) + self._fmconv.SetToolTip(_('Dual-mode digital repeaters that support ' + 'analog will be shown as FM')) + self._add_grid(grid, _('Digital Modes'), self._fmconv) + self._state_selected(None) self._service_selected(None) @@ -412,6 +418,7 @@ class RepeaterBookQueryDialog(QuerySourceDialog): CONF.set('state', self._state.GetStringSelection(), 'repeaterbook') CONF.set('country', self._country.GetStringSelection(), 'repeaterbook') CONF.set('service', self._service.GetStringSelection(), 'repeaterbook') + CONF.set_bool('fmconv', self._fmconv.IsChecked(), 'repeaterbook') self.result_radio = repeaterbook.RepeaterBook() super().do_query() @@ -428,6 +435,7 @@ class RepeaterBookQueryDialog(QuerySourceDialog): 'modes': self._limit_modes, 'service': 'gmrs' if service == _('GMRS') else '', 'service_display': self._service.GetStringSelection(), + 'fmconv': self._fmconv.IsChecked(), } @@ -461,7 +469,7 @@ class DMRMARCQueryDialog(QuerySourceDialog): return vbox def get_info(self): - return 'The DMR-MARC Worldwide Network' + return _('The DMR-MARC Worldwide Network') def get_link(self): return 'https://www.dmr-marc.net' @@ -637,7 +645,7 @@ class RRQueryDialog(QuerySourceDialog): NAME = 'RadioReference' def get_info(self): - return ( + return _( "RadioReference.com is the world's largest\n" "radio communications data provider\n" "<small>Premium account required</small>") diff --git a/chirp/wxui/settingsedit.py b/chirp/wxui/settingsedit.py index 24e568d..0b6879c 100644 --- a/chirp/wxui/settingsedit.py +++ b/chirp/wxui/settingsedit.py @@ -124,8 +124,19 @@ class ChirpSettingsEdit(common.ChirpEditor): j, val)) realname, index = name.split(common.INDEX_CHAR) + prop = page.propgrid.GetProperty(name) + if not prop: + LOG.warning('Unable to find property %s in page', + name) + continue if int(index) == j: - setting[j] = val + try: + setting[j] = val + finally: + if setting[j].get_value() != val: + # setting value modified or not accepted in + # validate callback, propagate back to GUI + prop.SetValue(setting[j].get_value()) return True except Exception as e: LOG.exception('Failed to apply settings') @@ -5,7 +5,7 @@ setup(name='chirp', description='A cross-platform cross-radio programming tool', packages=find_packages(include=["chirp*"]), include_package_data=True, - version='20231027', + version='20240117', url='https://chirp.danplanet.com', python_requires=">=3.7,<4", install_requires=[ diff --git a/tests/Python3_Driver_Testing.md b/tests/Python3_Driver_Testing.md index 32a1e86..7002a10 100644 --- a/tests/Python3_Driver_Testing.md +++ b/tests/Python3_Driver_Testing.md @@ -5,6 +5,7 @@ | <a name="Abbree_AR-518"></a> Abbree_AR-518 | [@KC9HI](https://github.com/KC9HI) | 16-Dec-2022 | Yes | 0.24% | | <a name="Abbree_AR-63"></a> Abbree_AR-63 | [@KC9HI](https://github.com/KC9HI) | 30-Nov-2022 | Yes | 0.03% | | <a name="Abbree_AR-730"></a> Abbree_AR-730 | [@KC9HI](https://github.com/KC9HI) | 17-Aug-2023 | Yes | | +| <a name="Abbree_AR-869"></a> Abbree_AR-869 | [Implied by Radtel_RT-490](#user-content-Radtel_RT-490) | 11-Nov-2023 | Yes | 0.01% | | <a name="Abbree_AR-F5"></a> Abbree_AR-F5 | [@KC9HI](https://github.com/KC9HI) | 09-Aug-2023 | Yes | | | <a name="Alinco_DJ-G7EG"></a> Alinco_DJ-G7EG | [@HB9UF](https://github.com/HB9UF) | 09-Dec-2022 | Yes | 0.44% | | <a name="Alinco_DJ-G7T"></a> Alinco_DJ-G7T | [Reported working](https://chirp.danplanet.com/issues/10567) | 09-May-2023 | Yes | | @@ -44,6 +45,8 @@ | <a name="BTECH_UV-50X2_G2"></a> BTECH_UV-50X2_G2 | [@KC9HI](https://github.com/KC9HI) | 30-Nov-2022 | Yes | 0.00% | | <a name="BTECH_UV-50X3"></a> BTECH_UV-50X3 | [@KC9HI](https://github.com/KC9HI) | 10-Dec-2022 | Yes | 0.06% | | <a name="BTECH_UV-5X3"></a> BTECH_UV-5X3 | [@KC9HI](https://github.com/KC9HI) | 9-Dec-2022 | Yes | 0.43% | +| <a name="Baofeng_5RM"></a> Baofeng_5RM | [@vdwel](https://github.com/vdwel) | 7-Dec-2023 | Yes | | +| <a name="Baofeng_5RX"></a> Baofeng_5RX | [@KC9HI](https://github.com/KC9HI) | 16-Jan-2024 | Yes | | | <a name="Baofeng_BF-1901"></a> Baofeng_BF-1901 | [@cetinajero](https://github.com/cetinajero) | 3-Jul-2023 | Yes | | | <a name="Baofeng_BF-1904"></a> Baofeng_BF-1904 | [@cetinajero](https://github.com/cetinajero) | 3-Jul-2023 | Yes | | | <a name="Baofeng_BF-888"></a> Baofeng_BF-888 | [@kk7ds](https://github.com/kk7ds) | 13-Feb-2019 | Yes | **15.53%** | @@ -52,11 +55,16 @@ | <a name="Baofeng_BF-F8HP"></a> Baofeng_BF-F8HP | [@KC9HI](https://github.com/KC9HI) | 18-Nov-2022 | Yes | **6.33%** | | <a name="Baofeng_BF-M4"></a> Baofeng_BF-M4 | [@cetinajero](https://github.com/cetinajero) | 8-May-2023 | Yes | | | <a name="Baofeng_BF-T1"></a> Baofeng_BF-T1 | [@KC9HI](https://github.com/KC9HI) | 10-Dec-2022 | Yes | 0.76% | +| <a name="Baofeng_BF-T20"></a> Baofeng_BF-T20 | [@KC9HI](https://github.com/KC9HI) | 15-Dec-2023 | Yes | | +| <a name="Baofeng_BF-T20FRS"></a> Baofeng_BF-T20FRS | [@KC9HI](https://github.com/KC9HI) | 17-Dec-2023 | Yes | | | <a name="Baofeng_BF-T8"></a> Baofeng_BF-T8 | [@KC9HI](https://github.com/KC9HI) | 30-Nov-2022 | Yes | 0.42% | | <a name="Baofeng_BF-V8A"></a> Baofeng_BF-V8A | [@KC9HI](https://github.com/KC9HI) | 28-Nov-2022 | Yes | 0.03% | | <a name="Baofeng_F-11"></a> Baofeng_F-11 | [Implied by Baofeng_UV-5R](#user-content-Baofeng_UV-5R) | 18-Nov-2022 | Yes | 0.12% | | <a name="Baofeng_GT-3WP"></a> Baofeng_GT-3WP | [@KC9HI](https://github.com/KC9HI) | 3-Dec-2022 | Yes | 0.43% | | <a name="Baofeng_GT-5R"></a> Baofeng_GT-5R | [@KC9HI](https://github.com/KC9HI) | 18-Nov-2022 | Yes | 0.68% | +| <a name="Baofeng_UV-17"></a> Baofeng_UV-17 | [@vdwel](https://github.com/vdwel) | 27-Nov-2023 | Yes | | +| <a name="Baofeng_UV-17Pro"></a> Baofeng_UV-17Pro | [@vdwel](https://github.com/vdwel) | 27-Nov-2023 | Yes | | +| <a name="Baofeng_UV-17ProGPS"></a> Baofeng_UV-17ProGPS | [@vdwel](https://github.com/vdwel) | 27-Nov-2023 | Yes | | | <a name="Baofeng_UV-3R"></a> Baofeng_UV-3R | [@yarda](https://github.com/yarda) | 26-Sep-2022 | Yes | 0.45% | | <a name="Baofeng_UV-5R"></a> Baofeng_UV-5R | [@lekv](https://github.com/lekv) | 23-Oct-2022 | Yes | **28.81%** | | <a name="Baofeng_UV-6"></a> Baofeng_UV-6 | [Implied by Baofeng_UV-5R](#user-content-Baofeng_UV-5R) | 18-Nov-2022 | Yes | 0.46% | @@ -74,6 +82,7 @@ | <a name="Baojie_BJ-9900"></a> Baojie_BJ-9900 | | | | 0.02% | | <a name="Baojie_BJ-UV55"></a> Baojie_BJ-UV55 | | | Yes | 0.03% | | <a name="Boblov_X3Plus"></a> Boblov_X3Plus | | | | 0.02% | +| <a name="Boristone_8RS"></a> Boristone_8RS | [Implied by Radtel_RT-490](#user-content-Radtel_RT-490) | 11-Nov-2023 | Yes | 0.00% | | <a name="CRT_Micron_UV"></a> CRT_Micron_UV | [Implied by Retevis_RT95](#user-content-Retevis_RT95) | 13-Nov-2022 | Yes | 0.08% | | <a name="CRT_Micron_UV_V2"></a> CRT_Micron_UV_V2 | [Implied by Retevis_RT95](#user-content-Retevis_RT95) | 13-Nov-2022 | Yes | 0.10% | | <a name="Cignus_XTR-5"></a> Cignus_XTR-5 | [Implied by Radioddity_GS-5B](#user-content-Radioddity_GS-5B) | 17-Mar-2023 | Yes | | @@ -89,6 +98,7 @@ | <a name="Feidaxin_FD-460A"></a> Feidaxin_FD-460A | | | | 0.01% | | <a name="Feidaxin_FD-460UH"></a> Feidaxin_FD-460UH | | | | 0.01% | | <a name="Generic_CSV"></a> Generic_CSV | [@kk7ds](https://github.com/kk7ds) | 4-Dec-2022 | | | +| <a name="HamGeek_HG-590"></a> HamGeek_HG-590 | [Implied by Radtel_RT-490](#user-content-Radtel_RT-490) | 11-Nov-2023 | Yes | 0.00% | | <a name="Hiroyasu_HI-8811"></a> Hiroyasu_HI-8811 | [@KC9HI](https://github.com/KC9HI) | 4-Jun-2023 | Yes | | | <a name="HobbyPCB_RS-UV3"></a> HobbyPCB_RS-UV3 | [@kk7ds](https://github.com/kk7ds) | 9-Dec-2022 | Yes | 0.02% | | <a name="Icom_IC-208H"></a> Icom_IC-208H | [Probably works](https://github.com/kk7ds/chirp/blob/py3/chirp/drivers/icf.py) | 12-Dec-2022 | Yes | 0.05% | @@ -129,9 +139,11 @@ | <a name="Icom_ID-880H"></a> Icom_ID-880H | [@kk7ds](https://github.com/kk7ds) | 22-Oct-2022 | Yes | 0.02% | | <a name="Intek_HR-2040"></a> Intek_HR-2040 | [Implied by AnyTone_5888UV](#user-content-AnyTone_5888UV) | 9-Dec-2022 | Yes | 0.02% | | <a name="Intek_KT-980HP"></a> Intek_KT-980HP | [Implied by Baofeng_BF-F8HP](#user-content-Baofeng_BF-F8HP) | 18-Nov-2022 | Yes | 0.04% | +| <a name="JJCC_JC-8629"></a> JJCC_JC-8629 | [Implied by Radtel_RT-490](#user-content-Radtel_RT-490) | 11-Nov-2023 | Yes | | | <a name="Jetstream_JT220M"></a> Jetstream_JT220M | [Implied by Alinco_DR235T](#user-content-Alinco_DR235T) | 12-Dec-2022 | Yes | 0.01% | | <a name="Jetstream_JT270M"></a> Jetstream_JT270M | [Implied by Jetstream_JT270M](#user-content-Jetstream_JT270M) | 13-Dec-2022 | Yes | 0.01% | | <a name="Jetstream_JT270MH"></a> Jetstream_JT270MH | [@kk7ds](https://github.com/kk7ds) | 13-Dec-2022 | Yes | 0.01% | +| <a name="Jianpai_8800_Plus"></a> Jianpai_8800_Plus | [Implied by Radtel_RT-490](#user-content-Radtel_RT-490) | 11-Nov-2023 | Yes | 0.01% | | <a name="KYD_IP-620"></a> KYD_IP-620 | | | | 0.02% | | <a name="KYD_NC-630A"></a> KYD_NC-630A | | | | 0.02% | | <a name="Kenwood_HMK"></a> Kenwood_HMK | [Implied by Generic_CSV](#user-content-Generic_CSV) | 4-Dec-2022 | | 0.00% | @@ -220,6 +232,7 @@ | <a name="Lanchonlh_HG-UV98"></a> Lanchonlh_HG-UV98 | | | Yes | 0.00% | | <a name="Leixen_VV-898"></a> Leixen_VV-898 | [Implied by Jetstream_JT270MH](#user-content-Jetstream_JT270MH) | 13-Dec-2022 | Yes | 0.18% | | <a name="Leixen_VV-898S"></a> Leixen_VV-898S | [@READ10](https://github.com/READ10) | 19-Dec-2022 | Yes | 0.10% | +| <a name="MMLradio_JC-8629"></a> MMLradio_JC-8629 | [@KC9HI](https://github.com/KC9HI) | 11-Nov-2023 | Yes | 0.01% | | <a name="MTC_UV-5R-3"></a> MTC_UV-5R-3 | [Implied by BTECH_UV-5X3](#user-content-BTECH_UV-5X3) | 9-Dec-2022 | Yes | 0.02% | | <a name="Maverick_RA-100"></a> Maverick_RA-100 | [@cetinajero](https://github.com/cetinajero) | 7-Jul-2023 | Yes | | | <a name="Maverick_RA-425"></a> Maverick_RA-425 | [@cetinajero](https://github.com/cetinajero) | 7-Jul-2023 | Yes | | @@ -254,11 +267,14 @@ | <a name="Radtel_RT-470"></a> Radtel_RT-470 | [@KC9HI](https://github.com/KC9HI) | 2-Apr-2023 | Yes | 0.00% | | <a name="Radtel_RT-470L"></a> Radtel_RT-470L | [@KC9HI](https://github.com/KC9HI) | 5-May-2023 | Yes | | | <a name="Radtel_RT-470X"></a> Radtel_RT-470X | [@KC9HI](https://github.com/KC9HI) | 10-Aug-2023 | Yes | | +| <a name="Radtel_RT-490"></a> Radtel_RT-490 | [@KC9HI](https://github.com/KC9HI) | 11-Nov-2023 | Yes | 0.08% | | <a name="Radtel_T18"></a> Radtel_T18 | [@KC9HI](https://github.com/KC9HI) | 28-Nov-2022 | Yes | 0.07% | | <a name="Retevis_H777S"></a> Retevis_H777S | [@KC9HI](https://github.com/KC9HI) | 22-Dec-2022 | Yes | | | <a name="Retevis_H777_Plus"></a> Retevis_H777_Plus | [@KC9HI](https://github.com/KC9HI) | 4-Dec-2022 | Yes | 0.06% | | <a name="Retevis_RA685"></a> Retevis_RA685 | [@KC9HI](https://github.com/KC9HI) | 19-Nov-2022 | Yes | 0.25% | +| <a name="Retevis_RA79"></a> Retevis_RA79 | [@KC9HI](https://github.com/KC9HI) | 27-Oct-2023 | Yes | | | <a name="Retevis_RA85"></a> Retevis_RA85 | [@KC9HI](https://github.com/KC9HI) | 19-Nov-2022 | Yes | 0.05% | +| <a name="Retevis_RA89"></a> Retevis_RA89 | [@KC9HI](https://github.com/KC9HI) | 23-Nov-2023 | Yes | | | <a name="Retevis_RB15"></a> Retevis_RB15 | [@KC9HI](https://github.com/KC9HI) | 18-Dec-2022 | Yes | 0.01% | | <a name="Retevis_RB17"></a> Retevis_RB17 | [@KC9HI](https://github.com/KC9HI) | 28-Nov-2022 | Yes | 0.02% | | <a name="Retevis_RB17A"></a> Retevis_RB17A | [@KC9HI](https://github.com/KC9HI) | 30-Nov-2022 | Yes | 0.01% | @@ -327,7 +343,12 @@ | <a name="Ruyage_UV58Plus"></a> Ruyage_UV58Plus | [@KC9HI](https://github.com/KC9HI) | 18-Mar-2023 | Yes | | | <a name="Sainsonic_AP510"></a> Sainsonic_AP510 | | | | 0.00% | | <a name="SenhaiX_8800"></a> SenhaiX_8800 | [Implied by Radioddity_GS-5B](#user-content-Radioddity_GS-5B) | 17-Mar-2023 | Yes | | +| <a name="Socotran_FB-8629"></a> Socotran_FB-8629 | [Implied by Radtel_RT-490](#user-content-Radtel_RT-490) | 11-Nov-2023 | Yes | 0.00% | +| <a name="Socotran_JC-8629"></a> Socotran_JC-8629 | [Implied by Radtel_RT-490](#user-content-Radtel_RT-490) | 11-Nov-2023 | Yes | | | <a name="TDXone_TD-Q8A"></a> TDXone_TD-Q8A | [@KC9HI](https://github.com/KC9HI) | 18-Dec-2022 | | 0.02% | +| <a name="TIDRADIO_TD-H3"></a> TIDRADIO_TD-H3 | [@songjunbiao](https://github.com/songjunbiao) | 1-Dec-2023 | Yes | | +| <a name="TIDRADIO_TD-H3-GMRS"></a> TIDRADIO_TD-H3-GMRS | [@songjunbiao](https://github.com/songjunbiao) | 1-Dec-2023 | Yes | | +| <a name="TIDRADIO_TD-H3-HAM"></a> TIDRADIO_TD-H3-HAM | [@songjunbiao](https://github.com/songjunbiao) | 1-Dec-2023 | Yes | | | <a name="TIDRADIO_TD-H6"></a> TIDRADIO_TD-H6 | [@kk7ds](https://github.com/kk7ds) | 21-Oct-2022 | Yes | 0.43% | | <a name="TIDRADIO_TD-H8"></a> TIDRADIO_TD-H8 | [@Sandmann34](https://github.com/Sandmann34) | 7-Feb-2023 | Yes | | | <a name="TIDRADIO_TD-H8-GMRS"></a> TIDRADIO_TD-H8-GMRS | [@Sandmann34](https://github.com/Sandmann34) | 7-Feb-2023 | Yes | | @@ -382,6 +403,7 @@ | <a name="Yaesu_FT-2800M"></a> Yaesu_FT-2800M | [Reported working](https://chirp.danplanet.com/issues/10616) | 05-Jun-2023 | Yes | 0.03% | | <a name="Yaesu_FT-2900R_1900R"></a> Yaesu_FT-2900R_1900R | [Reported working](https://chirp.danplanet.com/issues/10274) | 14-Jan-2023 | Yes | 0.05% | | <a name="Yaesu_FT-2900R_1900RTXMod_Opened_Xmit"></a> Yaesu_FT-2900R_1900RTXMod_Opened_Xmit | [Implied by Yaesu_FT-2900R_1900R](#user-content-Yaesu_FT-2900R_1900R) | 14-Jan-2023 | Yes | | +| <a name="Yaesu_FT-450"></a> Yaesu_FT-450 | [@WCurlew](https://github.com/WCurlew) | 03-Nov-2023 | Yes | | | <a name="Yaesu_FT-450D"></a> Yaesu_FT-450D | [@Old-Phart](https://github.com/Old-Phart) | 01-Jun-2023 | Yes | 0.01% | | <a name="Yaesu_FT-4VR"></a> Yaesu_FT-4VR | [Implied by Yaesu_FT-4XE](#user-content-Yaesu_FT-4XE) | 24-Dec-2022 | Yes | 0.01% | | <a name="Yaesu_FT-4XE"></a> Yaesu_FT-4XE | Unit tested; needs confirm | 24-Dec-2022 | Yes | 0.14% | @@ -423,11 +445,11 @@ | <a name="Zastone_ZT-X6"></a> Zastone_ZT-X6 | [Implied by Retevis_RT22](#user-content-Retevis_RT22) | 9-Dec-2022 | Yes | 0.11% | ## Stats -**Drivers:** 420 +**Drivers:** 442 -**Tested:** 87% (367/53) (93% of usage stats) +**Tested:** 88% (389/53) (93% of usage stats) -**Byte clean:** 90% (380/40) +**Byte clean:** 90% (402/40) ## Meaning of this testing diff --git a/tests/__init__.py b/tests/__init__.py index 7640296..d076136 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -64,6 +64,7 @@ def _load_tests(loader, tests, pattern, suite=None): pattern = None driver_test_cases = (test_edges.TestCaseEdges, + test_edges.TestBitwiseStrict, test_brute_force.TestCaseBruteForce, test_banks.TestCaseBanks, test_detect.TestCaseDetect, diff --git a/tests/__pycache__/__init__.cpython-310.pyc b/tests/__pycache__/__init__.cpython-310.pyc Binary files differindex 81ff5ea..edcebf1 100644 --- a/tests/__pycache__/__init__.cpython-310.pyc +++ b/tests/__pycache__/__init__.cpython-310.pyc diff --git a/tests/__pycache__/base.cpython-310.pyc b/tests/__pycache__/base.cpython-310.pyc Binary files differindex 2e34e7f..888e3bc 100644 --- a/tests/__pycache__/base.cpython-310.pyc +++ b/tests/__pycache__/base.cpython-310.pyc diff --git a/tests/__pycache__/conftest.cpython-310-pytest-7.1.3.pyc b/tests/__pycache__/conftest.cpython-310-pytest-7.1.3.pyc Binary files differnew file mode 100644 index 0000000..1223caf --- /dev/null +++ b/tests/__pycache__/conftest.cpython-310-pytest-7.1.3.pyc diff --git a/tests/__pycache__/test_brute_force.cpython-310-pytest-7.1.3.pyc b/tests/__pycache__/test_brute_force.cpython-310-pytest-7.1.3.pyc Binary files differindex 31b7705..cebda28 100644 --- a/tests/__pycache__/test_brute_force.cpython-310-pytest-7.1.3.pyc +++ b/tests/__pycache__/test_brute_force.cpython-310-pytest-7.1.3.pyc diff --git a/tests/__pycache__/test_edges.cpython-310-pytest-7.1.3.pyc b/tests/__pycache__/test_edges.cpython-310-pytest-7.1.3.pyc Binary files differindex e98e401..1bcf167 100644 --- a/tests/__pycache__/test_edges.cpython-310-pytest-7.1.3.pyc +++ b/tests/__pycache__/test_edges.cpython-310-pytest-7.1.3.pyc diff --git a/tests/__pycache__/test_settings.cpython-310-pytest-7.1.3.pyc b/tests/__pycache__/test_settings.cpython-310-pytest-7.1.3.pyc Binary files differindex 65c8050..9a323e0 100644 --- a/tests/__pycache__/test_settings.cpython-310-pytest-7.1.3.pyc +++ b/tests/__pycache__/test_settings.cpython-310-pytest-7.1.3.pyc diff --git a/tests/base.py b/tests/base.py index 0f69e67..0cf8d36 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1,5 +1,6 @@ import functools import logging +import os import unittest from chirp import chirp_common @@ -15,6 +16,17 @@ class DriverTest(unittest.TestCase): def setUp(self): super().setUp() + self.patches = [] + + if ('CHIRP_TEST_BITWISE_STRICT_BYTES' in os.environ and + not self.RADIO_CLASS.NEEDS_COMPAT_SERIAL): + self.use_patch(unittest.mock.patch( + 'chirp.bitwise.DataElement._compat_bytes', + side_effect=self._strict_bytes)) + self.use_patch(unittest.mock.patch( + 'chirp.bitwise.string_straight_encode', + side_effect=AssertionError( + 'string_straight_encode not allowed in strict mode'))) self.parent = self.RADIO_CLASS(self.TEST_IMAGE) self.parent_rf = self.parent.get_features() @@ -27,7 +39,6 @@ class DriverTest(unittest.TestCase): else: self.radio = self.parent self.rf = self.parent_rf - self.patches = [] def use_patch(self, patch): self.patches.append(patch) @@ -37,17 +48,18 @@ class DriverTest(unittest.TestCase): for patch in self.patches: patch.stop() + def _strict_bytes(self, bs, asbytes): + """Enforce strict get_raw() behavior returning bytes()""" + assert asbytes, 'asbytes must be True in strict mode' + assert isinstance(bs, bytes), 'Type should be bytes here' + return bs + def get_mem(self): """Attempt to build a suitable memory for testing""" # Check to see if memory #1 has immutable fields, and if so, # use that as our template instead of constructing a memory ourselves try: m = self.radio.get_memory(1) - # Don't return extra because it will never match properly - try: - del m.extra - except AttributeError: - pass # Pre-filter the name so it will match what we expect back if 'name' not in m.immutable: m.name = self.radio.filter_name(m.name) @@ -129,6 +141,8 @@ class DriverTest(unittest.TestCase): continue if k == "power": continue # FIXME + elif k == "extra": + continue elif k == "immutable": continue elif k == "name": @@ -180,6 +194,16 @@ class DriverTest(unittest.TestCase): self.assertEqual(a_vals, b_vals, 'Memories have unexpected differences') + # Consider mem.extra as matching if the structure remains the same. + # Since we don't know anything about model-specific things here we + # can't really assert any more than that, but we can ensure that the + # structure doesn't change due to the contents of the rest of the + # memory. + if a.extra and b.extra: + self.assertEqual([x.get_name() for x in a.extra], + [x.get_name() for x in b.extra], + 'Memories have different mem.extra keys') + def requires_feature(flag): def inner(fn): diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..8026a98 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,15 @@ +import os + +import pytest + + +def pytest_collection_modifyitems(config, items): + xfails = os.path.join(os.path.dirname(__file__), 'xfails.txt') + with open(xfails) as f: + lines = [x.strip() for x in f.readlines() if not x.startswith('#')] + msg = ('Test marked for XFAIL in tests/xfails.txt, but did not fail. ' + 'If this test is now fixed, remove it from the file.') + for item in items: + if item.nodeid in lines: + mark = pytest.mark.xfail(reason=msg) + item.add_marker(mark) diff --git a/tests/images/BTECH_UV-2501+220.img b/tests/images/BTECH_UV-2501+220.img Binary files differindex 8bf021c..8bf021c 100755..100644 --- a/tests/images/BTECH_UV-2501+220.img +++ b/tests/images/BTECH_UV-2501+220.img diff --git a/tests/images/BTECH_UV-25X2.img b/tests/images/BTECH_UV-25X2.img Binary files differindex aec97d8..aec97d8 100755..100644 --- a/tests/images/BTECH_UV-25X2.img +++ b/tests/images/BTECH_UV-25X2.img diff --git a/tests/images/BTECH_UV-25X4.img b/tests/images/BTECH_UV-25X4.img Binary files differindex 12ce9f9..12ce9f9 100755..100644 --- a/tests/images/BTECH_UV-25X4.img +++ b/tests/images/BTECH_UV-25X4.img diff --git a/tests/images/BTECH_UV-5001.img b/tests/images/BTECH_UV-5001.img Binary files differindex 377be8b..377be8b 100755..100644 --- a/tests/images/BTECH_UV-5001.img +++ b/tests/images/BTECH_UV-5001.img diff --git a/tests/images/BTECH_UV-50X2.img b/tests/images/BTECH_UV-50X2.img Binary files differindex 6bac4fb..6bac4fb 100755..100644 --- a/tests/images/BTECH_UV-50X2.img +++ b/tests/images/BTECH_UV-50X2.img diff --git a/tests/images/BTECH_UV-5X3.img b/tests/images/BTECH_UV-5X3.img Binary files differindex aa6ad8a..aa6ad8a 100755..100644 --- a/tests/images/BTECH_UV-5X3.img +++ b/tests/images/BTECH_UV-5X3.img diff --git a/tests/images/Baofeng_5RM.img b/tests/images/Baofeng_5RM.img Binary files differnew file mode 100644 index 0000000..8cff8e8 --- /dev/null +++ b/tests/images/Baofeng_5RM.img diff --git a/tests/images/Baofeng_5RX.img b/tests/images/Baofeng_5RX.img Binary files differnew file mode 100644 index 0000000..c2a604f --- /dev/null +++ b/tests/images/Baofeng_5RX.img diff --git a/tests/images/Baofeng_BF-T20.img b/tests/images/Baofeng_BF-T20.img Binary files differnew file mode 100644 index 0000000..aeb1a02 --- /dev/null +++ b/tests/images/Baofeng_BF-T20.img diff --git a/tests/images/Baofeng_BF-T20FRS.img b/tests/images/Baofeng_BF-T20FRS.img Binary files differnew file mode 100644 index 0000000..5859da0 --- /dev/null +++ b/tests/images/Baofeng_BF-T20FRS.img diff --git a/tests/images/Baofeng_UV-17.img b/tests/images/Baofeng_UV-17.img Binary files differnew file mode 100644 index 0000000..220f797 --- /dev/null +++ b/tests/images/Baofeng_UV-17.img diff --git a/tests/images/Baofeng_UV-17Pro.img b/tests/images/Baofeng_UV-17Pro.img Binary files differnew file mode 100644 index 0000000..69a3735 --- /dev/null +++ b/tests/images/Baofeng_UV-17Pro.img diff --git a/tests/images/Baofeng_UV-17ProGPS.img b/tests/images/Baofeng_UV-17ProGPS.img Binary files differnew file mode 100644 index 0000000..e3ded1f --- /dev/null +++ b/tests/images/Baofeng_UV-17ProGPS.img diff --git a/tests/images/Baofeng_UV-6R.img b/tests/images/Baofeng_UV-6R.img Binary files differindex 32f5c15..32f5c15 100755..100644 --- a/tests/images/Baofeng_UV-6R.img +++ b/tests/images/Baofeng_UV-6R.img diff --git a/tests/images/Feidaxin_FD-268A.img b/tests/images/Feidaxin_FD-268A.img Binary files differindex 52fc11b..52fc11b 100755..100644 --- a/tests/images/Feidaxin_FD-268A.img +++ b/tests/images/Feidaxin_FD-268A.img diff --git a/tests/images/Feidaxin_FD-268B.img b/tests/images/Feidaxin_FD-268B.img Binary files differindex 8de4949..8de4949 100755..100644 --- a/tests/images/Feidaxin_FD-268B.img +++ b/tests/images/Feidaxin_FD-268B.img diff --git a/tests/images/Feidaxin_FD-288B.img b/tests/images/Feidaxin_FD-288B.img Binary files differindex 778ff91..778ff91 100755..100644 --- a/tests/images/Feidaxin_FD-288B.img +++ b/tests/images/Feidaxin_FD-288B.img diff --git a/tests/images/Icom_IC-P7.img b/tests/images/Icom_IC-P7.img Binary files differindex 35a0966..35a0966 100755..100644 --- a/tests/images/Icom_IC-P7.img +++ b/tests/images/Icom_IC-P7.img diff --git a/tests/images/Icom_IC-V80.img b/tests/images/Icom_IC-V80.img Binary files differindex 49af6b5..49af6b5 100755..100644 --- a/tests/images/Icom_IC-V80.img +++ b/tests/images/Icom_IC-V80.img diff --git a/tests/images/Icom_ID-51_Plus.img b/tests/images/Icom_ID-51_Plus.img Binary files differindex 07bdc7e..07bdc7e 100755..100644 --- a/tests/images/Icom_ID-51_Plus.img +++ b/tests/images/Icom_ID-51_Plus.img diff --git a/tests/images/Icom_ID-80H.img b/tests/images/Icom_ID-80H.img Binary files differindex 1c14d84..1c14d84 100755..100644 --- a/tests/images/Icom_ID-80H.img +++ b/tests/images/Icom_ID-80H.img diff --git a/tests/images/KYD_IP-620.img b/tests/images/KYD_IP-620.img Binary files differindex c088dfe..c088dfe 100755..100644 --- a/tests/images/KYD_IP-620.img +++ b/tests/images/KYD_IP-620.img diff --git a/tests/images/KYD_NC-630A.img b/tests/images/KYD_NC-630A.img Binary files differindex 2c627fa..2c627fa 100755..100644 --- a/tests/images/KYD_NC-630A.img +++ b/tests/images/KYD_NC-630A.img diff --git a/tests/images/Kenwood_TH-D74_clone_mode.img b/tests/images/Kenwood_TH-D74_clone_mode.img Binary files differindex 5b1e40a..5b1e40a 100755..100644 --- a/tests/images/Kenwood_TH-D74_clone_mode.img +++ b/tests/images/Kenwood_TH-D74_clone_mode.img diff --git a/tests/images/Kenwood_TK-272G.img b/tests/images/Kenwood_TK-272G.img Binary files differindex bdeed1f..bdeed1f 100755..100644 --- a/tests/images/Kenwood_TK-272G.img +++ b/tests/images/Kenwood_TK-272G.img diff --git a/tests/images/Kenwood_TK-760G.img b/tests/images/Kenwood_TK-760G.img Binary files differindex 23c883a..23c883a 100755..100644 --- a/tests/images/Kenwood_TK-760G.img +++ b/tests/images/Kenwood_TK-760G.img diff --git a/tests/images/LUITON_LT-725UV.img b/tests/images/LUITON_LT-725UV.img Binary files differindex 537e13b..537e13b 100755..100644 --- a/tests/images/LUITON_LT-725UV.img +++ b/tests/images/LUITON_LT-725UV.img diff --git a/tests/images/Leixen_VV-898S.img b/tests/images/Leixen_VV-898S.img Binary files differindex 10a264a..10a264a 100755..100644 --- a/tests/images/Leixen_VV-898S.img +++ b/tests/images/Leixen_VV-898S.img diff --git a/tests/images/MMLradio_JC-8629.img b/tests/images/MMLradio_JC-8629.img Binary files differnew file mode 100644 index 0000000..05e84a1 --- /dev/null +++ b/tests/images/MMLradio_JC-8629.img diff --git a/tests/images/QYT_KT7900D.img b/tests/images/QYT_KT7900D.img Binary files differindex 73bfc37..73bfc37 100755..100644 --- a/tests/images/QYT_KT7900D.img +++ b/tests/images/QYT_KT7900D.img diff --git a/tests/images/QYT_KT8900D.img b/tests/images/QYT_KT8900D.img Binary files differindex e31310f..e31310f 100755..100644 --- a/tests/images/QYT_KT8900D.img +++ b/tests/images/QYT_KT8900D.img diff --git a/tests/images/Radtel_RT-490.img b/tests/images/Radtel_RT-490.img Binary files differnew file mode 100644 index 0000000..b992ee8 --- /dev/null +++ b/tests/images/Radtel_RT-490.img diff --git a/tests/images/Radtel_T18.img b/tests/images/Radtel_T18.img Binary files differindex f508675..f508675 100755..100644 --- a/tests/images/Radtel_T18.img +++ b/tests/images/Radtel_T18.img diff --git a/tests/images/Retevis_RA79.img b/tests/images/Retevis_RA79.img Binary files differnew file mode 100644 index 0000000..41cc21a --- /dev/null +++ b/tests/images/Retevis_RA79.img diff --git a/tests/images/Retevis_RA89.img b/tests/images/Retevis_RA89.img Binary files differnew file mode 100644 index 0000000..a33e97f --- /dev/null +++ b/tests/images/Retevis_RA89.img diff --git a/tests/images/Retevis_RT23.img b/tests/images/Retevis_RT23.img Binary files differindex 2bb0252..2bb0252 100755..100644 --- a/tests/images/Retevis_RT23.img +++ b/tests/images/Retevis_RT23.img diff --git a/tests/images/TDXone_TD-Q8A.img b/tests/images/TDXone_TD-Q8A.img Binary files differindex 6bd3d07..6bd3d07 100755..100644 --- a/tests/images/TDXone_TD-Q8A.img +++ b/tests/images/TDXone_TD-Q8A.img diff --git a/tests/images/TIDRADIO_TD-H3.img b/tests/images/TIDRADIO_TD-H3.img Binary files differnew file mode 100644 index 0000000..e891793 --- /dev/null +++ b/tests/images/TIDRADIO_TD-H3.img diff --git a/tests/images/TYT_TH-UV3R-25.img b/tests/images/TYT_TH-UV3R-25.img Binary files differindex d62a459..d62a459 100755..100644 --- a/tests/images/TYT_TH-UV3R-25.img +++ b/tests/images/TYT_TH-UV3R-25.img diff --git a/tests/images/WACCOM_MINI-8900.img b/tests/images/WACCOM_MINI-8900.img Binary files differindex 9b5737a..9b5737a 100755..100644 --- a/tests/images/WACCOM_MINI-8900.img +++ b/tests/images/WACCOM_MINI-8900.img diff --git a/tests/images/Yaesu_FT-2900R_1900R.img b/tests/images/Yaesu_FT-2900R_1900R.img Binary files differindex ef17a61..ef17a61 100755..100644 --- a/tests/images/Yaesu_FT-2900R_1900R.img +++ b/tests/images/Yaesu_FT-2900R_1900R.img diff --git a/tests/images/Yaesu_FT-450.img b/tests/images/Yaesu_FT-450.img Binary files differnew file mode 100644 index 0000000..7b179c0 --- /dev/null +++ b/tests/images/Yaesu_FT-450.img diff --git a/tests/images/Yaesu_FT-50.img b/tests/images/Yaesu_FT-50.img Binary files differindex 77cffd7..77cffd7 100755..100644 --- a/tests/images/Yaesu_FT-50.img +++ b/tests/images/Yaesu_FT-50.img diff --git a/tests/images/Yaesu_FTM-7250D_R.img b/tests/images/Yaesu_FTM-7250D_R.img Binary files differindex 2ec6832..2ec6832 100755..100644 --- a/tests/images/Yaesu_FTM-7250D_R.img +++ b/tests/images/Yaesu_FTM-7250D_R.img diff --git a/tests/py3_driver_testers.txt b/tests/py3_driver_testers.txt index ceaf190..59f2bb9 100644 --- a/tests/py3_driver_testers.txt +++ b/tests/py3_driver_testers.txt @@ -11,6 +11,7 @@ Abbree_AR-518,@KC9HI,16-Dec-2022 Abbree_AR-63,@KC9HI,30-Nov-2022 Abbree_AR-730,@KC9HI,17-Aug-2023 +Abbree_AR-869,+Radtel_RT-490,11-Nov-2023 Abbree_AR-F5,@KC9HI,09-Aug-2023 Alinco_DJ175,+Alinco_DR235T,12-Dec-2022 Alinco_DJ596,+Alinco_DR235T,12-Dec-2022 @@ -50,6 +51,8 @@ BTECH_UV-50X2,@KC9HI,11-Nov-2022 BTECH_UV-50X2_G2,@KC9HI,30-Nov-2022 BTECH_UV-50X3,@KC9HI,10-Dec-2022 BTECH_UV-5X3,@KC9HI,9-Dec-2022 +Baofeng_5RM,@vdwel,7-Dec-2023 +Baofeng_5RX,@KC9HI,16-Jan-2024 Baofeng_BF-1901,@cetinajero,3-Jul-2023 Baofeng_BF-1904,@cetinajero,3-Jul-2023 Baofeng_BF-888,@kk7ds,13-Feb-2019 @@ -58,6 +61,8 @@ Baofeng_BF-A58S,@KC9HI,3-Dec-2022 Baofeng_BF-F8HP,@KC9HI,18-Nov-2022 Baofeng_BF-M4,@cetinajero,8-May-2023 Baofeng_BF-T1,@KC9HI,10-Dec-2022 +Baofeng_BF-T20,@KC9HI,15-Dec-2023 +Baofeng_BF-T20FRS,@KC9HI,17-Dec-2023 Baofeng_BF-T8,@KC9HI,30-Nov-2022 Baofeng_BF-V8A,@KC9HI,28-Nov-2022 Baofeng_F-11,+Baofeng_UV-5R,18-Nov-2022 @@ -72,16 +77,21 @@ Baofeng_UV-82HP,@KC9HI,18-Nov-2022 Baofeng_UV-82WP,@KC9HI,3-Dec-2022 Baofeng_UV-9G,@KC9HI,3-Dec-2022 Baofeng_UV-9R,@KC9HI,3-Dec-2022 +Baofeng_UV-17,@vdwel,27-Nov-2023 +Baofeng_UV-17Pro,@vdwel,27-Nov-2023 +Baofeng_UV-17ProGPS,@vdwel,27-Nov-2023 Baofeng_UV-B5,@KC9HI,18-Nov-2022 Baofeng_UV-S9X3,@KC9HI,22-Aug-2023 Baofeng_W31E,@KC9HI,14-Aug-2023 Baojie_BJ-218,+LUITON_LT-725UV,16-Feb-2023 Baojie_BJ-318,@KC9HI,2-Jan-2023 +Boristone_8RS,+Radtel_RT-490,11-Nov-2023 Cignus_XTR-5,+Radioddity_GS-5B,17-Mar-2023 CRT_Micron_UV,+Retevis_RT95,13-Nov-2022 CRT_Micron_UV_V2,+Retevis_RT95,13-Nov-2022 Explorer_QRZ-1,+TYT_TH-UV88,5-Dec-2022 Generic_CSV,@kk7ds,4-Dec-2022 +HamGeek_HG-590,+Radtel_RT-490,11-Nov-2023 Hiroyasu_HI-8811,@KC9HI,4-Jun-2023 HobbyPCB_RS-UV3,@kk7ds,9-Dec-2022 Icom_IC-208H,*icf,12-Dec-2022 @@ -125,6 +135,8 @@ Intek_HR-2040,+AnyTone_5888UV,9-Dec-2022 Jetstream_JT220M,+Alinco_DR235T,12-Dec-2022 Jetstream_JT270M,+Jetstream_JT270M,13-Dec-2022 Jetstream_JT270MH,@kk7ds,13-Dec-2022 +Jianpai_8800_Plus,+Radtel_RT-490,11-Nov-2023 +JJCC_JC-8629,+Radtel_RT-490,11-Nov-2023 Kenwood_HMK,+Generic_CSV,4-Dec-2022 Kenwood_TH-D7,*kenwood_live,12-Dec-2022 Kenwood_TH-D7G,*kenwood_live,12-Dec-2022 @@ -196,6 +208,7 @@ LUITON_LT-588UV,@KC9HI,11-Nov-2022 LUITON_LT-725UV,@KC9HI,11-Dec-2022 Maverick_RA-100,@cetinajero,7-Jul-2023 Maverick_RA-425,@cetinajero,7-Jul-2023 +MMLradio_JC-8629,@KC9HI,11-Nov-2023 MTC_UV-5R-3,+BTECH_UV-5X3,9-Dec-2022 Midland_DBR2500,+Retevis_RT95,13-Nov-2022 Polmar_DB-50M,+AnyTone_5888UV,9-Dec-2022 @@ -225,11 +238,14 @@ Radioddity_UV-82X3,@KC9HI,18-Nov-2022 Radtel_RT-470,@KC9HI,2-Apr-2023 Radtel_RT-470L,@KC9HI,5-May-2023 Radtel_RT-470X,@KC9HI,10-Aug-2023 +Radtel_RT-490,@KC9HI,11-Nov-2023 Radtel_T18,@KC9HI,28-Nov-2022 Retevis_H777S,@KC9HI,22-Dec-2022 Retevis_H777_Plus,@KC9HI,4-Dec-2022 Retevis_RA685,@KC9HI,19-Nov-2022 +Retevis_RA79,@KC9HI,27-Oct-2023 Retevis_RA85,@KC9HI,19-Nov-2022 +Retevis_RA89,@KC9HI,23-Nov-2023 Retevis_RB15,@KC9HI,18-Dec-2022 Retevis_RB17,@KC9HI,28-Nov-2022 Retevis_RB17A,@KC9HI,30-Nov-2022 @@ -296,6 +312,8 @@ Retevis_RT9000D_400-490,@KC9HI,8-Dec-2022 Retevis_RT9000D_66-88,@KC9HI,8-Dec-2022 Ruyage_UV58Plus,@KC9HI,18-Mar-2023 SenhaiX_8800,+Radioddity_GS-5B,17-Mar-2023 +Socotran_FB-8629,+Radtel_RT-490,11-Nov-2023 +Socotran_JC-8629,+Radtel_RT-490,11-Nov-2023 Talkpod_A36plus,@KC9HI,12-Jun-2023 TDXone_TD-Q8A,@KC9HI,18-Dec-2022 TIDRADIO_TD-H6,@kk7ds,21-Oct-2022 @@ -304,6 +322,9 @@ TIDRADIO_TD-H8-GMRS,@Sandmann34,7-Feb-2023 TIDRADIO_TD-H8-HAM,@Sandmann34,7-Feb-2023 TID_TD-M8,+Retevis_RT22,9-Dec-2022 TID_TD-UV68,@Sandmann34,7-Feb-2023 +TIDRADIO_TD-H3,@songjunbiao,1-Dec-2023 +TIDRADIO_TD-H3-GMRS,@songjunbiao,1-Dec-2023 +TIDRADIO_TD-H3-HAM,@songjunbiao,1-Dec-2023 TYT_TH-UVF1,@kk7ds,13-Dec-2022 TYT_TH-UVF8D,@MELERIX,2-Feb-2023 TYT_TH-UV8000,@KC9HI,6-Jan-2023 @@ -342,6 +363,7 @@ Yaesu_FT-1D_R,+Yaesu_FT3D_R,30-Dec-2022 Yaesu_FT2D_R,+Yaesu_FT3D_R,30-Dec-2022 Yaesu_FT2D_Rv2,+Yaesu_FT3D_R,30-Dec-2022 Yaesu_FT3D_R,@kk7ds,30-Dec-2022 +Yaesu_FT-450,@WCurlew,03-Nov-2023 Yaesu_FT-450D,@Old-Phart,01-Jun-2023 Yaesu_FT-4XE,Unit tested; needs confirm,24-Dec-2022 Yaesu_FT-4XR,+Yaesu_FT-4XE,24-Dec-2022 diff --git a/tests/test_brute_force.py b/tests/test_brute_force.py index 236e11a..0ab09f7 100644 --- a/tests/test_brute_force.py +++ b/tests/test_brute_force.py @@ -1,4 +1,3 @@ -import copy import logging from chirp import chirp_common @@ -158,7 +157,7 @@ class TestCaseBruteForce(base.DriverTest): for mode in self.rf.valid_modes: self.assertIn(mode, chirp_common.MODES, 'Radio exposes non-standard mode') - tmp = copy.deepcopy(m) + tmp = m.dupe() if mode == "DV" and \ isinstance(self.radio, chirp_common.IcomDstarSupport): diff --git a/tests/test_edges.py b/tests/test_edges.py index e515330..2280819 100644 --- a/tests/test_edges.py +++ b/tests/test_edges.py @@ -1,3 +1,7 @@ +import pytest +from unittest import mock + +from chirp import bitwise from chirp import chirp_common from chirp import errors from tests import base @@ -106,12 +110,21 @@ class TestCaseEdges(base.DriverTest): lo, hi = self.rf.memory_bounds for name in self.rf.valid_special_chans: m1 = self.radio.get_memory(name) + # Flip to non-empty, but only touch it if it's false because some + # radios have empty in the immutable set. + if m1.empty: + m1.empty = False try: del m1.extra except AttributeError: pass if m1.freq > 130000000 and m1.freq < 500000000: m1.freq += 5000 + elif m1.freq == 0: + # If the memory was empty before, we likely need to pick + # a valid frequency. Use the bottom of the first supported + # band. + m1.freq = self.rf.valid_bands[0][0] try: self.radio.set_memory(m1) except errors.RadioError: @@ -154,3 +167,23 @@ class TestCaseEdges(base.DriverTest): self.assertEqual(m2.name.rstrip(), m2.name, 'Radio set and returned a memory with trailing ' 'whitespace in the name') + + +class TestBitwiseStrict(base.DriverTest): + def setUp(self): + pass + + def _raise(self, message): + raise SyntaxError(message) + + @pytest.mark.xfail(strict=False) + @mock.patch.object(bitwise.Processor, 'assert_negative_seek', + side_effect=_raise) + def test_bitwise_negative_seek(self, mock_assert): + super().setUp() + + @pytest.mark.xfail(strict=False) + @mock.patch.object(bitwise.Processor, 'assert_unnecessary_seek', + side_effect=_raise) + def test_bitwise_unnecessary_seek(self, mock_assert): + super().setUp() diff --git a/tests/test_settings.py b/tests/test_settings.py index 83b1db1..45267f0 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,3 +1,4 @@ +from chirp import chirp_common from chirp import settings from tests import base @@ -34,3 +35,26 @@ class TestCaseSettings(base.DriverTest): self.assertEqual(a.get_value(), b.get_value(), 'Setting value changed from %r to %r' % ( a.get_value(), b.get_value())) + + def test_memory_extra_frozen(self): + # Find the first non-empty memory and try to set it back as a + # FrozenMemory to make sure the driver does not try to modify + # any of the settings. + for i in range(*self.rf.memory_bounds): + m = self.radio.get_memory(i) + if not m.empty: + self.radio.set_memory(chirp_common.FrozenMemory(m)) + break + + def test_memory_extra_flat(self): + for i in range(*self.rf.memory_bounds): + m = self.radio.get_memory(i) + if not m.empty: + self.assertIsInstance( + m.extra, + (list, settings.RadioSettingGroup), + 'mem.extra must be a list or RadioSettingGroup') + for e in m.extra: + self.assertIsInstance( + e, settings.RadioSetting, + 'mem.extra items must be RadioSetting objects') diff --git a/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc b/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc Binary files differindex 5066d3a..398ad6b 100644 --- a/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc +++ b/tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc diff --git a/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc b/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc Binary files differindex cd2beb0..3334195 100644 --- a/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc +++ b/tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc diff --git a/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc b/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc Binary files differindex bee4b94..1c758c2 100644 --- a/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc +++ b/tests/unit/__pycache__/test_wxui_radiothread.cpython-310-pytest-7.1.3.pyc diff --git a/tests/unit/test_bitwise.py b/tests/unit/test_bitwise.py index 969622f..f150886 100644 --- a/tests/unit/test_bitwise.py +++ b/tests/unit/test_bitwise.py @@ -251,8 +251,8 @@ class TestBitwiseCharTypes(BaseTest): def test_string_get_raw(self): data = memmap.MemoryMapBytes(bytes(b"foobar")) obj = bitwise.parse("char foo[6];", data) - self.assertEqual('foobar', obj.foo.get_raw()) - self.assertEqual(b'foobar', obj.foo.get_raw(asbytes=True)) + self.assertEqual(b'foobar', obj.foo.get_raw()) + self.assertEqual('foobar', obj.foo.get_raw(asbytes=False)) class TestBitwiseStructTypes(BaseTest): @@ -283,15 +283,24 @@ class TestBitwiseStructTypes(BaseTest): data = memmap.MemoryMapBytes(bytes(b"..")) defn = "struct { u8 bar; u8 baz; } foo;" obj = bitwise.parse(defn, data) - self.assertEqual('..', obj.get_raw()) - self.assertEqual(b'..', obj.get_raw(asbytes=True)) + self.assertEqual(b'..', obj.get_raw()) + self.assertEqual('..', obj.get_raw(asbytes=False)) def test_struct_get_raw_small(self): data = memmap.MemoryMapBytes(bytes(b".")) defn = "struct { u8 bar; } foo;" obj = bitwise.parse(defn, data) - self.assertEqual('.', obj.get_raw()) - self.assertEqual(b'.', obj.get_raw(asbytes=True)) + self.assertEqual(b'.', obj.get_raw()) + self.assertEqual('.', obj.get_raw(asbytes=False)) + + def test_struct_set_raw(self): + data = memmap.MemoryMapBytes(bytes(b".")) + defn = "struct { u8 bar; } foo;" + obj = bitwise.parse(defn, data) + obj.set_raw(b'1') + self.assertEqual(b'1', data.get_packed()) + obj.set_raw('2') + self.assertEqual(b'2', data.get_packed()) class TestBitwiseSeek(BaseTest): diff --git a/tests/unit/test_chirp_common.py b/tests/unit/test_chirp_common.py index 30da2c7..fb880c9 100644 --- a/tests/unit/test_chirp_common.py +++ b/tests/unit/test_chirp_common.py @@ -821,6 +821,15 @@ class TestMemory(base.BaseTest): self.assertNotIsInstance(m, FrozenMemory) self.assertFalse(hasattr(m, '_frozen')) + def test_frozen_modifications(self): + orig = chirp_common.Memory(123) + orig.extra = [settings.RadioSetting( + 'foo', 'Foo', + settings.RadioSettingValueBoolean(False))] + frozen = chirp_common.FrozenMemory(orig) + with self.assertRaises(ValueError): + frozen.extra[0].value = True + def test_tone_validator(self): m = chirp_common.Memory() # 100.0 is a valid tone @@ -843,6 +852,81 @@ class TestMemory(base.BaseTest): with self.assertRaises(ValueError): m.ctone = 300.0 + def test_repr_dump(self): + m = chirp_common.Memory() + self.assertEqual( + "<Memory 0: freq=0,name='',vfo=0,rtone=88.5,ctone=88.5,dtcs=23," + "rx_dtcs=23,tmode='',cross_mode='Tone->Tone',dtcs_polarity='NN'," + "skip='',power=None,duplex='',offset=600000,mode='FM'," + "tuning_step=5.0,comment='',empty=False,immutable=[]>", repr(m)) + + m.freq = 146520000 + m.rtone = 107.2 + m.tmode = 'Tone' + self.assertEqual( + "<Memory 0: freq=146520000,name='',vfo=0,rtone=107.2,ctone=88.5," + "dtcs=23,rx_dtcs=23,tmode='Tone',cross_mode='Tone->Tone'," + "dtcs_polarity='NN',skip='',power=None,duplex='',offset=600000," + "mode='FM',tuning_step=5.0,comment='',empty=False,immutable=[]>", + repr(m)) + + m.number = 101 + m.extd_number = 'Call' + self.assertEqual( + "<Memory Call(101): freq=146520000,name='',vfo=0,rtone=107.2," + "ctone=88.5,dtcs=23,rx_dtcs=23,tmode='Tone'," + "cross_mode='Tone->Tone',dtcs_polarity='NN',skip='',power=None," + "duplex='',offset=600000,mode='FM',tuning_step=5.0,comment=''," + "empty=False,immutable=[]>", repr(m)) + + m.extra = settings.RadioSettingGroup('extra', 'Extra') + m.extra.append( + settings.RadioSetting('test1', 'Test Setting 1', + settings.RadioSettingValueBoolean(False))) + m.extra.append( + settings.RadioSetting('test2', 'Test Setting 2', + settings.RadioSettingValueList( + ['foo', 'bar'], 'foo'))) + self.assertEqual( + "<Memory Call(101): freq=146520000,name='',vfo=0,rtone=107.2," + "ctone=88.5,dtcs=23,rx_dtcs=23,tmode='Tone'," + "cross_mode='Tone->Tone',dtcs_polarity='NN',skip='',power=None," + "duplex='',offset=600000,mode='FM',tuning_step=5.0,comment=''," + "empty=False,immutable=[],extra.test1='False',extra.test2='foo'>", + repr(m)) + + def test_debug_diff(self): + m1 = chirp_common.Memory(1) + m2 = chirp_common.Memory(1) + + m1.freq = 146520000 + m2.freq = 446000000 + self.assertEqual('freq=146520000>446000000', m1.debug_diff(m2, '>')) + + m2.tmode = 'TSQL' + self.assertEqual("freq=146520000/446000000,tmode=''/'TSQL'", + m1.debug_diff(m2)) + + # Make sure ident diffs come first and are noticed + m2.number = 2 + m2.freq = 146520000 + self.assertEqual("ident=1/2,tmode=''/'TSQL'", m1.debug_diff(m2)) + + # Make sure we can diff extras, and amongst heterogeneous formats + m2.number = 1 + m1.extra = settings.RadioSettingGroup('extra', 'Extra') + m2.extra = settings.RadioSettingGroup('extra', 'Extra') + m1.extra.append( + settings.RadioSetting('test1', 'Test Setting 1', + settings.RadioSettingValueBoolean(False))) + m2.extra.append( + settings.RadioSetting('test2', 'Test Setting 2', + settings.RadioSettingValueList( + ['foo', 'bar'], 'foo'))) + self.assertEqual( + "extra.test1='False'/'<missing>',extra.test2='<missing>'/'foo'," + "tmode=''/'TSQL'", m1.debug_diff(m2)) + class TestRadioFeatures(base.BaseTest): def test_valid_tones(self): diff --git a/tests/unit/test_wxui_radiothread.py b/tests/unit/test_wxui_radiothread.py index 99f9438..1088b81 100644 --- a/tests/unit/test_wxui_radiothread.py +++ b/tests/unit/test_wxui_radiothread.py @@ -3,10 +3,17 @@ import time from unittest import mock sys.modules['wx'] = wx = mock.MagicMock() +sys.modules['wx.lib'] = mock.MagicMock() +sys.modules['wx.lib.scrolledpanel'] = mock.MagicMock() +sys.modules['wx.lib.sized_controls'] = mock.MagicMock() +sys.modules['wx.richtext'] = mock.MagicMock() +wx.lib.newevent.NewCommandEvent.return_value = None, None +sys.modules['chirp.wxui.developer'] = mock.MagicMock() # These need to be imported after the above mock so that we don't require # wx to be present for these tests from tests.unit import base # noqa +from chirp.wxui import clone # noqa from chirp.wxui import radiothread # noqa @@ -105,3 +112,42 @@ class TestRadioThread(base.BaseTest): radio.set_memory.assert_not_called() radio.get_features.assert_not_called() wx.PostEvent.assert_not_called() + + +class TestClone(base.BaseTest): + @mock.patch('platform.system', return_value='Linux') + def test_sort_ports_unix(self, system): + ports = [ + mock.MagicMock(device='/dev/cu.zed', + description='My Zed'), + mock.MagicMock(device='/dev/cu.abc', + description='Some device'), + mock.MagicMock(device='/dev/cu.serial', + description='') + ] + self.assertEqual( + ['Some device (cu.abc)', + 'cu.serial', + 'My Zed (cu.zed)'], + [clone.port_label(p) + for p in sorted(ports, key=clone.port_sort_key)]) + + @mock.patch('platform.system', return_value='Windows') + def test_sort_ports_windows(self, system): + ports = [ + mock.MagicMock(device='COM7', + description='Some serial device'), + mock.MagicMock(device='COM17', + description='Some other device'), + mock.MagicMock(device='CNC0', + description='Some weird device'), + mock.MagicMock(device='COM4', + description=''), + ] + self.assertEqual( + ['CNC0: Some weird device', + 'COM4', + 'COM7: Some serial device', + 'COM17: Some other device'], + [clone.port_label(p) + for p in sorted(ports, key=clone.port_sort_key)]) diff --git a/tests/xfails.txt b/tests/xfails.txt new file mode 100644 index 0000000..0b53dbb --- /dev/null +++ b/tests/xfails.txt @@ -0,0 +1,8 @@ +# This is a list of tests that are expected to fail. DO NOT add new things to +# this file without careful consideration and discussion. This is not a tool +# to avoid fixing failures, it is purely a stop-gap to allow temporary +# failures to avoid breaking the build while iterating towards a fix. +# +# One line per test nodeid with a comment above citing a bug number, example: +# Bug #10931: FT-450 mem.extra fields cause UI corruption +# tests/test_drivers.py::TestCaseBruteForce_Yaesu_FT-450D::test_mode diff --git a/tools/check_commit.sh b/tools/check_commit.sh index 6158a47..5a86e33 100755 --- a/tools/check_commit.sh +++ b/tools/check_commit.sh @@ -65,30 +65,35 @@ for file in $(git diff --name-only ${BASE}..); do fi done +#if grep 'def match_model' added_lines; then +# fail 'New drivers should not have match_model() implemented as it is not needed' +#fi + if git log ${BASE}.. --merges | grep .; then fail Please do not include merge commits in your PR fi make -C chirp/locale clean all >/dev/null 2>&1 -if git diff chirp/locale | grep '^\+[^#+]' | grep -v POT-Creation; then +if git diff chirp/locale | grep '^+[^#+]' | grep -v POT-Creation; then fail Locale files need updating fi -added_files=$(git diff --name-only --diff-filter=A ${BASE}.. 2>&1) -if echo $added_files | grep -q chirp.drivers && ! echo $added_files | grep -q tests.images; then +added_files=$(git diff --name-only --diff-filter=A ${BASE}..) +added_py=$(git diff --name-only --diff-filter=A ${BASE}.. | grep '\.py$') +if echo $added_py | grep -q chirp.drivers && ! echo $added_files | grep -q tests.images; then fail All new drivers should include a test image fi existing_drivers=$(git ls-tree --name-only $BASE chirp/drivers/) -limit=20 -for nf in $added_files; do +limit=51 +for nf in $added_py; do for of in $existing_drivers; do - change=$(wdiff -s $of $nf | grep -I $of | sed -r 's/.* ([0-9]+)% changed/\1/') - if [ ! "$change" ]; then + common=$(wdiff -s $of $nf | grep -I $nf | sed -r 's/.* ([0-9]+)% common.*/\1/') + if [ ! "$common" ]; then continue fi - if [ "$change" -lt "$limit" ]; then - fail "New file $nf shares at least $((100 - $change))% with $of!" + if [ "$common" -gt "$limit" ]; then + fail "New file $nf shares at least ${common}% with $of!" fi done done diff --git a/tools/cpep8.py b/tools/cpep8.py index 678281f..a1fde83 100755 --- a/tools/cpep8.py +++ b/tools/cpep8.py @@ -138,7 +138,7 @@ for i in range(0, len(flake8_manifest), 10): files = flake8_manifest[i:i + 10] if args.verbose: print('Checking %s' % files) - r = subprocess.call(['flake8', '--builtins=_'] + files) + r = subprocess.call(['flake8', '--builtins=_,ngettext'] + files) if r != 0: total_errors += r |
