diff options
| author | Dave Hibberd <hibby@debian.org> | 2025-05-04 23:46:09 +0100 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2025-05-04 23:46:09 +0100 |
| commit | 812534848086446daa2e57bf2ec8db45e82fea18 (patch) | |
| tree | 0ab5d2a7c06f656465a648d72e3fbaa0349c5e78 | |
| parent | f6b2e6e7159906b8b3204dca3a9e58e42c36ccbb (diff) | |
New upstream version 20250502upstream/20250502
55 files changed, 2395 insertions, 397 deletions
@@ -1,6 +1,6 @@ -Metadata-Version: 2.2 +Metadata-Version: 2.4 Name: chirp -Version: 20250221 +Version: 20250502 Summary: A cross-platform cross-radio programming tool Home-page: https://chirp.danplanet.com Requires-Python: >=3.10,<4 @@ -13,6 +13,7 @@ Requires-Dist: lark Provides-Extra: wx Requires-Dist: wxPython; extra == "wx" Dynamic: home-page +Dynamic: license-file Dynamic: provides-extra Dynamic: requires-dist Dynamic: requires-python diff --git a/chirp.egg-info/PKG-INFO b/chirp.egg-info/PKG-INFO index 85945e1..5bef572 100644 --- a/chirp.egg-info/PKG-INFO +++ b/chirp.egg-info/PKG-INFO @@ -1,6 +1,6 @@ -Metadata-Version: 2.2 +Metadata-Version: 2.4 Name: chirp -Version: 20250221 +Version: 20250502 Summary: A cross-platform cross-radio programming tool Home-page: https://chirp.danplanet.com Requires-Python: >=3.10,<4 @@ -13,6 +13,7 @@ Requires-Dist: lark Provides-Extra: wx Requires-Dist: wxPython; extra == "wx" Dynamic: home-page +Dynamic: license-file Dynamic: provides-extra Dynamic: requires-dist Dynamic: requires-python diff --git a/chirp.egg-info/SOURCES.txt b/chirp.egg-info/SOURCES.txt index 08042f8..cd03bcd 100644 --- a/chirp.egg-info/SOURCES.txt +++ b/chirp.egg-info/SOURCES.txt @@ -104,6 +104,7 @@ chirp/drivers/icm710.py chirp/drivers/icomciv.py chirp/drivers/icp7.py chirp/drivers/icq7.py +chirp/drivers/ict10.py chirp/drivers/ict70.py chirp/drivers/ict7h.py chirp/drivers/ict8.py @@ -223,6 +224,7 @@ 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 +chirp/locale/ro_RO/LC_MESSAGES/CHIRP.mo chirp/locale/ru/LC_MESSAGES/CHIRP.mo chirp/locale/tr_TR/LC_MESSAGES/CHIRP.mo chirp/locale/uk_UA/LC_MESSAGES/CHIRP.mo @@ -240,6 +242,7 @@ chirp/share/welcome_screen_bg.png chirp/share/welcome_screen_es.png chirp/share/welcome_screen_fr.png chirp/share/welcome_screen_it.png +chirp/share/welcome_screen_ro_RO.png chirp/share/welcome_screen_zh_CN.png chirp/sources/__init__.py chirp/sources/base.py @@ -366,6 +369,7 @@ tests/images/Baofeng_BF-T20FRS.img tests/images/Baofeng_BF-T8.img tests/images/Baofeng_F-11.img tests/images/Baofeng_GM-5RH.img +tests/images/Baofeng_K6.img tests/images/Baofeng_UV-13Pro.img tests/images/Baofeng_UV-17.img tests/images/Baofeng_UV-17Pro.img @@ -399,6 +403,7 @@ tests/images/Icom_IC-F621-2.img tests/images/Icom_IC-M710.img tests/images/Icom_IC-P7.img tests/images/Icom_IC-Q7A.img +tests/images/Icom_IC-T10.img tests/images/Icom_IC-T70.img tests/images/Icom_IC-T7H.img tests/images/Icom_IC-T8A.img @@ -456,6 +461,7 @@ tests/images/Puxing_PX-777.img tests/images/Puxing_PX-888K.img tests/images/Q-MAC_HF-90_v300_or_earlier.img tests/images/Q-MAC_HF-90_v301_or_later.img +tests/images/QYT_KT-5000.img tests/images/QYT_KT-8R.img tests/images/QYT_KT-WP12.img tests/images/QYT_KT7900D.img @@ -573,10 +579,12 @@ tests/images/Vertex_Standard_VXA-700.img tests/images/WACCOM_MINI-8900.img tests/images/Wouxun_KG-1000G.img tests/images/Wouxun_KG-1000G_Plus.img +tests/images/Wouxun_KG-805G.img tests/images/Wouxun_KG-816.img tests/images/Wouxun_KG-818.img tests/images/Wouxun_KG-935G.img tests/images/Wouxun_KG-935G_Plus.img +tests/images/Wouxun_KG-935H.img tests/images/Wouxun_KG-UV6.img tests/images/Wouxun_KG-UV8D.img tests/images/Wouxun_KG-UV8D_Plus.img diff --git a/chirp/__init__.py b/chirp/__init__.py index 560165c..91b58cc 100644 --- a/chirp/__init__.py +++ b/chirp/__init__.py @@ -1 +1 @@ -CHIRP_VERSION = "next-20250221" +CHIRP_VERSION = "next-20250502" diff --git a/chirp/bandplan.py b/chirp/bandplan.py index 30b940e..76d87f1 100644 --- a/chirp/bandplan.py +++ b/chirp/bandplan.py @@ -69,7 +69,7 @@ class Band(object): return self limits = (self.limits[0] + self.offset, self.limits[1] + self.offset) offset = -1 * self.offset - if self.duplex in '+-': + if self.duplex and self.duplex in '+-': duplex = '+' if self.duplex == '-' else '-' return Band(limits, self.name, self.mode, self.step_khz, input_offset=offset, tones=self.tones, duplex=duplex) diff --git a/chirp/chirp_common.py b/chirp/chirp_common.py index b867952..2a7d6f7 100644 --- a/chirp/chirp_common.py +++ b/chirp/chirp_common.py @@ -417,7 +417,7 @@ class Memory: if callable(valid): if not valid(val): raise ValueError("`%s' is not a valid value for `%s'" % ( - val, name)) + val, name)) elif val not in self._valid_map[name]: raise ValueError("`%s' is not in valid list: %s" % (val, self._valid_map[name])) @@ -769,6 +769,7 @@ class StaticBankModel(BankModel): channelAlwaysHasBank = True """A BankModel that shows a static mapping but does not allow changes.""" + def __init__(self, radio, name='Banks', banks=10): super().__init__(radio, name=name) self._num_banks = banks @@ -796,10 +797,10 @@ class StaticBankModel(BankModel): return [self._banks[(memory.number - lo) // count]] def remove_memory_from_mapping(self, memory, mapping): - raise NotImplementedError(self.MSG) + raise errors.RadioFixedBanks() def add_memory_to_mapping(self, memory, mapping): - raise NotImplementedError(self.MSG) + raise errors.RadioFixedBanks() class MappingModelIndexInterface: @@ -1772,88 +1773,65 @@ def make_is(stephz): def required_step(freq, allowed=None): """Returns the simplest tuning step that is required to reach @freq""" if allowed is None: - allowed = [5.0, 10.0, 12.5, 6.25, 2.5, 8.33] - - # These should be in order of most common to least common - steps = { - 5.0: make_is(5000), - 10.0: make_is(10000), - 12.5: make_is(12500), - 6.25: make_is(6250), - 2.5: make_is(2500), - 1.0: make_is(1000), - 0.5: make_is(500), - 0.25: make_is(250), - 8.33: is_8_33, - } - - # Try the above "standard" steps first in order - required_step = None - for step, validate in steps.items(): - if step in allowed and validate(freq): - return step - elif validate(freq) and required_step is None: - required_step = step + allowed = [5.0, 10.0, 12.5, 6.25, 2.5, 1.0, 0.5, 8.33, 0.25] - # Try any additional steps in the allowed list + special = {8.33: is_8_33} for step in allowed: - if step in steps: - # Already tried - continue - if make_is(int(step * 1000))(freq): - LOG.debug('Chose non-standard step %s for %s' % ( - step, format_freq(freq))) + if step in special: + validate = special[step] + else: + validate = make_is(int(step * 1000)) + if validate(freq): + LOG.debug('Chose step %s for %s' % (step, format_freq(freq))) return step - if required_step is not None: - raise errors.InvalidDataError(( - 'Frequency %s requires step %.2f, ' - 'which is not supported') % ( - format_freq(freq), required_step)) - else: - raise errors.InvalidDataError("Unable to find a supported " + - "tuning step for %s" % format_freq(freq)) + raise errors.InvalidDataError("Unable to find a supported " + + "tuning step for %s" % format_freq(freq)) def fix_rounded_step(freq): """Some radios imply the last bit of 12.5 kHz and 6.25 kHz step frequencies. Take the base @freq and return the corrected one""" - try: - required_step(freq) - return freq - except errors.InvalidDataError: - pass + allowed = [12.5, 6.25] try: - required_step(freq + 500) + required_step(freq + 500, allowed=allowed) return freq + 500 except errors.InvalidDataError: pass try: - required_step(freq + 250) + required_step(freq + 250, allowed=allowed) return freq + 250 except errors.InvalidDataError: pass try: - required_step(freq + 750) + required_step(freq + 750, allowed=allowed) return float(freq + 750) except errors.InvalidDataError: pass try: - required_step(freq + 330) + required_step(freq + 330, allowed=allowed) return float(freq + 330) except errors.InvalidDataError: pass try: - required_step(freq + 660) + required_step(freq + 660, allowed=allowed) return float(freq + 660) except errors.InvalidDataError: pass + # These radios can all resolve 5kHz, so make sure what we are left with + # is 5kHz-aligned, else we refuse below. + try: + required_step(freq, allowed=[5.0]) + return freq + except errors.InvalidDataError: + pass + raise errors.InvalidDataError("Unable to correct rounded frequency " + format_freq(freq)) @@ -1914,8 +1892,9 @@ def split_to_offset(mem, rxfreq, txfreq): """Set the freq, offset, and duplex fields of a memory based on a separate rx/tx frequency. """ + mem.freq = rxfreq + if abs(txfreq - rxfreq) > to_MHz(70): - mem.freq = rxfreq mem.offset = txfreq mem.duplex = 'split' else: diff --git a/chirp/directory.py b/chirp/directory.py index 0c029ee..42871aa 100644 --- a/chirp/directory.py +++ b/chirp/directory.py @@ -16,6 +16,7 @@ import glob import os +import inspect import logging import sys @@ -36,6 +37,18 @@ def radio_class_id(cls): return ident +def registered_class(cls): + """Find the first parent of @cls that is registered""" + bases = inspect.getmro(cls) + for base in bases: + try: + return get_driver(base) + except Exception: + pass + else: + raise KeyError('No parent radio class of %s is registered' % cls) + + ALLOW_DUPS = False @@ -51,7 +64,6 @@ def enable_reregistrations(): def register(cls): """Register radio @cls with the directory""" - global DRV_TO_RADIO ident = radio_class_id(cls) if ident in list(DRV_TO_RADIO.keys()): if ALLOW_DUPS: diff --git a/chirp/drivers/__init__.py b/chirp/drivers/__init__.py index ad2b12b..1c9d70a 100644 --- a/chirp/drivers/__init__.py +++ b/chirp/drivers/__init__.py @@ -159,20 +159,21 @@ from chirp.drivers import iradio_uv_5118plus from chirp.drivers import ksun_m6 from chirp.drivers import retevis_ra87 from chirp.drivers import uvk5_egzumer +from chirp.drivers import tk481 +from chirp.drivers import yaesu_clone +from chirp.drivers import ict10 +from chirp.drivers import tdh8 +from chirp.drivers import tk280 from chirp.drivers import uvk5 from chirp.drivers import radtel_rt620 from chirp.drivers import radtel_rt490 from chirp.drivers import baofeng_digital -from chirp.drivers import tdh8 from chirp.drivers import ts790e from chirp.drivers import baofeng_uv17 -from chirp.drivers import alinco_dr735t from chirp.drivers import icf520 from chirp.drivers import icm710 -from chirp.drivers import mml_jc8810 -from chirp.drivers import tk280 from chirp.drivers import tk690 -from chirp.drivers import yaesu_clone -from chirp.drivers import tk481 +from chirp.drivers import mml_jc8810 from chirp.drivers import baofeng_uv17Pro -__all__ = ['anytone', 'btech', 'anytone778uv', 'anytone_ht', 'anytone_iii', 'baofeng_common', 'baofeng_uv3r', 'baofeng_wp970i', 'bf_t1', 'bf_t8', 'boblov_x3plus', 'fake', 'fd268', 'ft1500m', 'ft1802', 'ft1d', 'ft2800', 'ft2900', 'ft4', 'ft450d', 'ft50', 'ft2d', 'ft60', 'ft70', 'ft7100', 'ft7800', 'ft8100', 'ft817', 'ft818', 'ft857', 'ft90', 'ftlx011', 'ftm3200d', 'ftm350', 'ftm7250d', 'ga510', 'generic_csv', 'generic_tpe', 'gmrsuv1', 'gmrsv2', 'h777', 'hf90', 'hg_uv98', 'alinco', 'bj9900', 'ic2100', 'hobbypcb', 'ic208', 'ic2300', 'ic2720', 'ic2200', 'ic2730', 'ic2820', 'ic9x_ll', 'ic9x', 'ic9x_icf', 'icf', 'ic9x_icf_ll', 'icomciv', 'icp7', 'icq7', 'ict8', 'icv80', 'ict70', 'ict7h', 'icv86', 'id51', 'icx90', 'icw32', 'icx8x', 'id31', 'id5100', 'id51plus', 'id800', 'id880', 'idrp', 'kg935g', 'kguv8d', 'iradio_uv_5118', 'kenwood_hmk', 'kenwood_itm', 'kenwood_live', 'kguv8e', 'kyd', 'kguv8dplus', 'kguv920pa', 'kguv980p', 'kguv9dplus', 'lt725uv', 'kyd_IP620', 'leixen', 'mursv1', 'puxing', 'ap510', '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', '__init__', 'bjuv55', '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', 'iradio_uv_5118plus', 'ksun_m6', 'retevis_ra87', 'uvk5_egzumer', 'uvk5', 'radtel_rt620', 'radtel_rt490', 'baofeng_digital', 'tdh8', 'ts790e', 'baofeng_uv17', 'alinco_dr735t', 'icf520', 'icm710', 'mml_jc8810', 'tk280', 'tk690', 'yaesu_clone', 'tk481', 'baofeng_uv17Pro'] +from chirp.drivers import alinco_dr735t +__all__ = ['anytone', 'btech', 'anytone778uv', 'anytone_ht', 'anytone_iii', 'baofeng_common', 'baofeng_uv3r', 'baofeng_wp970i', 'bf_t1', 'bf_t8', 'boblov_x3plus', 'fake', 'fd268', 'ft1500m', 'ft1802', 'ft1d', 'ft2800', 'ft2900', 'ft4', 'ft450d', 'ft50', 'ft2d', 'ft60', 'ft70', 'ft7100', 'ft7800', 'ft8100', 'ft817', 'ft818', 'ft857', 'ft90', 'ftlx011', 'ftm3200d', 'ftm350', 'ftm7250d', 'ga510', 'generic_csv', 'generic_tpe', 'gmrsuv1', 'gmrsv2', 'h777', 'hf90', 'hg_uv98', 'alinco', 'bj9900', 'ic2100', 'hobbypcb', 'ic208', 'ic2300', 'ic2720', 'ic2200', 'ic2730', 'ic2820', 'ic9x_ll', 'ic9x', 'ic9x_icf', 'icf', 'ic9x_icf_ll', 'icomciv', 'icp7', 'icq7', 'ict8', 'icv80', 'ict70', 'ict7h', 'icv86', 'id51', 'icx90', 'icw32', 'icx8x', 'id31', 'id5100', 'id51plus', 'id800', 'id880', 'idrp', 'kg935g', 'kguv8d', 'iradio_uv_5118', 'kenwood_hmk', 'kenwood_itm', 'kenwood_live', 'kguv8e', 'kyd', 'kguv8dplus', 'kguv920pa', 'kguv980p', 'kguv9dplus', 'lt725uv', 'kyd_IP620', 'leixen', 'mursv1', 'puxing', 'ap510', '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', '__init__', 'bjuv55', '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', 'iradio_uv_5118plus', 'ksun_m6', 'retevis_ra87', 'uvk5_egzumer', 'tk481', 'yaesu_clone', 'ict10', 'tdh8', 'tk280', 'uvk5', 'radtel_rt620', 'radtel_rt490', 'baofeng_digital', 'ts790e', 'baofeng_uv17', 'icf520', 'icm710', 'tk690', 'mml_jc8810', 'baofeng_uv17Pro', 'alinco_dr735t'] diff --git a/chirp/drivers/alinco_dr735t.py b/chirp/drivers/alinco_dr735t.py index 19306b1..17351ad 100644 --- a/chirp/drivers/alinco_dr735t.py +++ b/chirp/drivers/alinco_dr735t.py @@ -371,7 +371,7 @@ class AlincoDR735T(chirp_common.CloneModeRadio): "heterodyne_mode", "Heterodyne Mode", RadioSettingValueList( self.HET_MODE_MAP, - current=self.HET_MODE_MAP[int(_mem.heterodyne_mode)])) + current_index=int(_mem.heterodyne_mode))) het_mode.set_doc("Heterodyne Mode") bcl = RadioSetting("bcl", "BCL", @@ -391,21 +391,21 @@ class AlincoDR735T(chirp_common.CloneModeRadio): "stby_screen", "Standby Screen Color", RadioSettingValueList( self.SCREEN_COLOR_MAP, - current=self.SCREEN_COLOR_MAP[int(_mem.standby_screen_color)])) + current_index=int(_mem.standby_screen_color))) stby_screen.set_doc("Standby Screen Color") rx_screen = RadioSetting( "rx_screen", "RX Screen Color", RadioSettingValueList( self.SCREEN_COLOR_MAP, - current=self.SCREEN_COLOR_MAP[int(_mem.rx_screen_color)])) + current_index=int(_mem.rx_screen_color))) rx_screen.set_doc("RX Screen Color") tx_screen = RadioSetting( "tx_screen", "TX Screen Color", RadioSettingValueList( self.SCREEN_COLOR_MAP, - current=self.SCREEN_COLOR_MAP[int(_mem.tx_screen_color)])) + current_index=int(_mem.tx_screen_color))) tx_screen.set_doc("TX Screen Color") mem.extra.append(het_mode) diff --git a/chirp/drivers/baofeng_uv17Pro.py b/chirp/drivers/baofeng_uv17Pro.py index 550a5fc..a2a6d5f 100644 --- a/chirp/drivers/baofeng_uv17Pro.py +++ b/chirp/drivers/baofeng_uv17Pro.py @@ -35,14 +35,16 @@ MSTRING_UV17PROGPS = b"PROGRAMCOLORPROU" MSTRING_GM5RH = b"PROGRAMBFGMRS05U" # BTECH BF-F8HP Pro magic string MSTRING_BFF8HPPRO = b"PROGRAMBF5RTECHU" +# Baofeng BF-K6 magic string +MSTRING_BFK6 = b"PROGRAMBF-K6PROU" -DTMF_CHARS = "0123456789 *#ABCD" +DTMF_CHARS = list("0123456789ABCD*#") +NUMERIC_CHARS = list("0123456789") 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_SIDE_TONE = ["Off", "KB Side Tone", "ANI Side Tone", "KB + ANI Side Tone"] 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"] @@ -58,6 +60,12 @@ 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)] LIST_SHIFTS = ["Off", "+", "-"] +LIST_OFF_AB = ["Off"] + LIST_AB +LIST_POWERON_TONE = ["Off", "Tone", "Voice"] +LIST_LCD_CONTRAST = ["%s" % x for x in range(1, 6, 1)] +LIST_MODES = ["Factory mode", "FCC amateur", "IC amateur", "CE amateur", + "Indonesian amateur", "Chinese amateur"] + CHARSET_GB2312 = chirp_common.CHARSET_ASCII for x in range(0xB0, 0xD7): for y in range(0xA1, 0xFF): @@ -147,7 +155,10 @@ def _download(radio): d = bfc._rawrecv(radio, radio.BLOCK_SIZE + 4) LOG.debug("Response Data= " + util.hexprint(d)) - d = _crypt(radio._encrsym, d[4:]) + if radio._uses_encr: + d = _crypt(radio._encrsym, d[4:]) + else: + d = d[4:] # Aggregate the data data += d @@ -168,7 +179,7 @@ def _upload(radio): status = chirp_common.Status() status.cur = 0 status.max = radio.MEM_TOTAL // radio.BLOCK_SIZE - status.msg = "Cloning from radio..." + status.msg = "Cloning to radio..." radio.status_fn(status) data_addr = 0x00 @@ -179,7 +190,8 @@ def _upload(radio): 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(radio._encrsym, data) + if radio._uses_encr: + data = _crypt(radio._encrsym, data) data_addr += radio.BLOCK_SIZE frame = radio._make_frame(b"W", addr, radio.BLOCK_SIZE, data) @@ -247,7 +259,13 @@ class UV17Pro(bfc.BaofengCommonHT): _scode_offset = 0 _encrsym = 1 _has_voice = True - _mem_positions = (0x8080, 0x80A0, 0x8280) + _uses_encr = True + _mem_params = { + 'mems': 1000, + 'ani': 0x8080, + 'pttid': 0x80A0, + 'names': 0x8280, + } MODES = ["NFM", "FM"] VALID_CHARS = chirp_common.CHARSET_ALPHANUMERIC + \ @@ -279,6 +297,7 @@ class UV17Pro(bfc.BaofengCommonHT): PTTID_LIST = LIST_PTTID SCODE_LIST = ["%s" % x for x in range(1, 21)] SQUELCH_LIST = ["Off"] + list("12345") + SCRAMBLE_LIST = ["Off"] + ["SCR%s" % x for x in list("123")] LIST_POWERON_DISPLAY_TYPE = ["LOGO", "BATT voltage"] LIST_TIMEOUT = ["Off"] + ["%s sec" % x for x in range(15, 195, 15)] LIST_VOICE = ["English", "Chinese"] @@ -291,18 +310,23 @@ class UV17Pro(bfc.BaofengCommonHT): LIST_SEPARATE_CODE = ["A", "B", "C", "D", "*", "#"] LIST_GROUP_CALL_CODE = ["Off"] + LIST_SEPARATE_CODE LIST_SKEY2_SHORT = ["FM", "Scan", "Search", "Vox"] + LIST_DTMFSPEED = ["%s ms" % x for x in [50, 100, 200, 300, 500]] + LIST_DUAL_WATCH = ["Off", "On"] CHANNELS = 1000 - MEM_FORMAT = """ - struct { + _mem_format = """ + struct memory_obj { lbcd rxfreq[4]; lbcd txfreq[4]; ul16 rxtone; ul16 txtone; u8 scode; u8 pttid; - u8 lowpower; + u8 unknown7:2, + scramble:2, + unknown8:2, + lowpower:2; u8 unknown1:1, wide:1, sqmode:2, @@ -315,8 +339,9 @@ class UV17Pro(bfc.BaofengCommonHT): u8 unknown5; u8 unknown6; char name[12]; - } memory[1000]; - + }; + """ + _common_defns = """ struct vfo_entry { u8 freq[8]; ul16 rxtone; @@ -338,14 +363,19 @@ class UV17Pro(bfc.BaofengCommonHT): u8 sqmode; u8 unknown6[3]; }; - - #seekto 0x8000; - struct { - struct vfo_entry a; - struct vfo_entry b; - } vfo; - - struct { + struct ani_obj { + u8 code[5]; + u8 unknown[1]; + u8 unused1:6, + aniid:2; + u8 dtmfon; + u8 dtmfoff; + u8 separatecode; + u8 groupcallcode; + }; + """ + _settings_format = """ + struct settings_obj { u8 squelch; u8 savemode; u8 vox; @@ -403,22 +433,23 @@ class UV17Pro(bfc.BaofengCommonHT): u8 inputdtmf; u8 gpsunits; u8 pontime; - char stationid[8]; - } settings; + }; + """ - #seekto 0x%04X; + MEM_FORMAT = """ + struct memory_obj memory[%(mems)i]; + + #seekto 0x8000; struct { - u8 code[5]; - u8 unknown[1]; - u8 unused1:6, - aniid:2; - u8 dtmfon; - u8 dtmfoff; - u8 separatecode; - u8 groupcallcode; - } ani; + struct vfo_entry a; + struct vfo_entry b; + } vfo; - #seekto 0x%04X; + struct settings_obj settings; + #seekto 0x%(ani)X; + struct ani_obj ani; + + #seekto 0x%(pttid)04X; struct { u8 code[5]; char name[10]; @@ -433,8 +464,10 @@ class UV17Pro(bfc.BaofengCommonHT): struct { u8 code[16]; } downcode; + """ - #seekto 0x%04X; + _end_fmt = """ + #seekto 0x%(names)04X; struct { char name[16]; } bank_name[10]; @@ -481,7 +514,9 @@ class UV17Pro(bfc.BaofengCommonHT): def process_mmap(self): """Process the mem map into the mem object""" # make lines shorter for style check. - fmt = self.MEM_FORMAT % self._mem_positions + fmt = (self._mem_format + self._common_defns + + self._settings_format + self.MEM_FORMAT + + self._end_fmt) % self._mem_params self._memobj = bitwise.parse(fmt, self._mmap) # DTMF settings @@ -556,7 +591,7 @@ class UV17Pro(bfc.BaofengCommonHT): else: val = _mem.ani.dtmfon rs = RadioSetting("ani.dtmfon", "DTMF Speed (on)", - RadioSettingValueList(LIST_DTMFSPEED, + RadioSettingValueList(self.LIST_DTMFSPEED, current_index=val)) dtmfe.append(rs) @@ -565,7 +600,7 @@ class UV17Pro(bfc.BaofengCommonHT): else: val = _mem.ani.dtmfoff rs = RadioSetting("ani.dtmfoff", "DTMF Speed (off)", - RadioSettingValueList(LIST_DTMFSPEED, + RadioSettingValueList(self.LIST_DTMFSPEED, current_index=val)) dtmfe.append(rs) @@ -604,8 +639,13 @@ class UV17Pro(bfc.BaofengCommonHT): self.LIST_TIMEOUT, current_index=val)) basic.append(rs) + if _mem.settings.dualstandby >= len(self.LIST_DUAL_WATCH): + val = 0x01 + else: + val = _mem.settings.dualstandby rs = RadioSetting("settings.dualstandby", "Dual Watch", - RadioSettingValueBoolean(_mem.settings.dualstandby)) + RadioSettingValueList( + self.LIST_DUAL_WATCH, current_index=val)) basic.append(rs) if _mem.settings.powerondistype >= len(self.LIST_POWERON_DISPLAY_TYPE): @@ -646,6 +686,10 @@ class UV17Pro(bfc.BaofengCommonHT): RadioSettingValueBoolean(_mem.settings.autolock)) basic.append(rs) + if _mem.settings.beep >= len(self.LIST_BEEP): + val = 0x01 + else: + val = _mem.settings.beep rs = RadioSetting("settings.beep", "Beep", RadioSettingValueList( self.LIST_BEEP, @@ -1106,6 +1150,9 @@ class UV17Pro(bfc.BaofengCommonHT): if element.has_apply_callback(): LOG.debug("Using apply callback") element.run_apply_callback() + elif setting == "pwronpwd": + numstr = self._num2bbcd(element.value) + setattr(self._memobj.settings, setting, numstr) elif element.value.get_mutable(): LOG.debug("Setting %s = %s" % (setting, element.value)) setattr(obj, setting, element.value) @@ -1298,7 +1345,7 @@ class UV17Pro(bfc.BaofengCommonHT): current_index=scode)) mem.extra.append(rs) - if self.MODEL == "BF-F8HP-PRO": + if self.MODEL in ["BF-F8HP-PRO", "K6"]: rs = RadioSetting("sqmode", "RX DTMF", RadioSettingValueBoolean(_mem.sqmode)) mem.extra.append(rs) @@ -1307,6 +1354,13 @@ class UV17Pro(bfc.BaofengCommonHT): RadioSettingValueBoolean(_mem.fhss)) mem.extra.append(rs) + if self.MODEL == "K6": + rs = RadioSetting("scramble", "Scramble", + RadioSettingValueList( + self.SCRAMBLE_LIST, + current_index=_mem.scramble)) + mem.extra.append(rs) + mem.name = str(name).replace('\xFF', ' ').replace('\x00', ' ').rstrip() def _get_raw_memory(self, number): @@ -1387,6 +1441,27 @@ class UV17Pro(bfc.BaofengCommonHT): @directory.register +class UV21ProV2(UV17Pro): + VENDOR = "Baofeng" + MODEL = "UV-21ProV2" + + _airband_rx = (108000000, 135999999) + _vhf_range = (136000000, 174000000) + _vhf2_range = (220000000, 260000000) + _uhf_rx1_range = (350000000, 390000000) + _uhf_range = (400000000, 479999999) + _uhf_rx2_range = (480000000, 520000000) + + VALID_BANDS = [_airband_rx, + _vhf_range, + _vhf2_range, + _uhf_rx1_range, + _uhf_range, + _uhf_rx2_range] + MODES = UV17Pro.MODES + ['AM'] + + +@directory.register class UV25(UV17Pro): VENDOR = "Baofeng" MODEL = "UV-25" @@ -1426,6 +1501,15 @@ class UV17ProGPS(UV17Pro): @directory.register +class UV21ProGPS(UV17ProGPS): + VENDOR = "Baofeng" + MODEL = "UV-21ProGPS" + + VALID_BANDS = UV21ProV2.VALID_BANDS + MODES = UV21ProV2.MODES + + +@directory.register class BF5RM(UV17Pro): VENDOR = "Baofeng" MODEL = "5RM" @@ -1538,7 +1622,75 @@ class F8HPPro(UV17Pro): MEM_SIZES = [0x8040, 0x0080, 0x02C0, 0x00C0] MEM_TOTAL = 0x8440 - _mem_positions = (0x80C0, 0x80E0, 0x8380) + _mem_params = { + 'mems': 1000, + 'ani': 0x80C0, + 'pttid': 0x80E0, + 'names': 0x8380, + } + + _settings_format = """ + struct settings_obj { + 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 a_or_b_selected; // a=0, b=1 + u8 fmenable; + u8 chbworkmode:4, + chaworkmode:4; + u8 keylock; + u8 powerondistype; + u8 tone; + u8 unknown4[2]; + u8 voxdlytime; + u8 menuquittime; + u8 unknown5[2]; + u8 dispani; + u8 unknown11[3]; + u8 totalarm; + u8 unknown6[2]; + u8 ctsdcsscantype; + ul16 vfoscanmin; + ul16 vfoscanmax; + u8 gpsw; + u8 gpsmode; + u8 key1short; + u8 unknown7; + u8 key2short; + u8 unknown8[2]; + u8 rstmenu; + u8 singlewatch; + u8 hangup; + u8 voxsw; + u8 gpstimezone; + u8 unknown10; + u8 inputdtmf; + u8 gpsunits; + u8 pontime; + char stationid[8]; + }; + """ def get_settings_pro_dtmf(self, dtmfe, _mem): super().get_settings_pro_dtmf(dtmfe, _mem) @@ -1546,13 +1698,13 @@ class F8HPPro(UV17Pro): rs = RadioSetting("ani.separatecode", "Separate Code", RadioSettingValueList( self.LIST_SEPARATE_CODE, - self.LIST_SEPARATE_CODE[_mem.ani.separatecode])) + current_index=_mem.ani.separatecode)) dtmfe.append(rs) rs = RadioSetting("ani.groupcallcode", "Group Call Code", RadioSettingValueList( self.LIST_GROUP_CALL_CODE, - self.LIST_GROUP_CALL_CODE[_mem.ani.groupcallcode])) + current_index=_mem.ani.groupcallcode)) dtmfe.append(rs) _codeobj = self._memobj.upcode.code @@ -1581,13 +1733,13 @@ class F8HPPro(UV17Pro): rs = RadioSetting("settings.pontime", "Power on Time", RadioSettingValueList( self.LIST_POWER_ON_TIME, - self.LIST_POWER_ON_TIME[_mem.settings.pontime])) + current_index=_mem.settings.pontime)) basic.append(rs) rs = RadioSetting("settings.gpsunits", "GPS Speed Units", RadioSettingValueList( self.LIST_GPS_UNITS, - self.LIST_GPS_UNITS[_mem.settings.gpsunits])) + current_index=_mem.settings.gpsunits)) basic.append(rs) rs = RadioSetting("settings.inputdtmf", "Input DTMF", @@ -1644,3 +1796,295 @@ class UV5RH(UV17Pro): LIST_PW_SAVEMODE = ["Off", "1:1", "1:2", "1:4"] MODES = UV17Pro.MODES + ['AM'] _has_workmode_support = True + + +@directory.register +class BFK6(UV17Pro): + VENDOR = "Baofeng" + MODEL = "K6" + + _magic = MSTRING_BFK6 + _magics = [(b"\x46", 16), + ] + _uses_encr = False + + LIST_DTMFSPEED = ["%s ms" % x for x in [50, 100, 200, 300, 400, 500]] + + _uhf_range = (400000000, 600000000) + + VALID_BANDS = [UV17Pro._airband, UV17Pro._vhf_range, (UV17Pro._vhf2_range), + _uhf_range, UV17Pro._uhf2_range] + MODES = UV17Pro.MODES + ['AM'] + POWER_LEVELS = [chirp_common.PowerLevel("High", watts=5.00), + chirp_common.PowerLevel("Low", watts=1.00)] + LIST_PW_SAVEMODE = ["Off", "1:1", "1:2", "1:4"] + LIST_POWERON_DISPLAY_TYPE = ["LOGO", "Message", "BATT voltage"] + LIST_BEEP = ["Off", "On"] + LIST_ID_DELAY = ["Off", "100 ms", "200 ms"] + ["%s ms" % x for x in range( + 400, 1200, 200)] + LIST_SKEYS = ["Off", "Flashlight", "TX Power", "Scan", "VOX", "SOS", + "FM Radio"] + LIST_DUAL_WATCH = ["Single Display", "Dual Display, Dual Watch", + "Dual Display, Single Watch"] + + _has_voxsw = True + _has_pilot_tone = True + _has_send_id_delay = True + _has_when_to_send_aniid = False + + MEM_STARTS = [0x0000, 0x9000, 0xA000, 0xC000, 0xD000] + MEM_SIZES = [0x8040, 0x0080, 0x02C0, 0x0040, 0x0040] + + MEM_TOTAL = 0x8400 + _mem_params = { + 'mems': 999, + 'ani': 0x80C0, + 'pttid': 0x80E0, + } + CHANNELS = 999 + + _settings_format = """ + struct settings_obj { + 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 tdr_tx; + u8 tailclear; + u8 rpttailclear; + u8 rpttaildet; + u8 roger; + u8 a_or_b_selected; // a=0, b=1 + u8 fmenable; + u8 chbworkmode:4, + chaworkmode:4; + u8 keylock; + u8 unknown2:4, + powerontone:2, + powerondistype:2; + u8 tone; + u8 unknown4[2]; + u8 voxdlytime; + u8 menuquittime; + u8 unknown5[2]; + u8 dispani; + u8 unknown11[3]; + u8 totalarm; + u8 lcdcontrast; + u8 invertlcd; + u8 ctsdcsscantype; + ul16 vfoscanmin; + ul16 vfoscanmax; + u8 fminterrupt; + u8 txdisable; + u8 key1short; + u8 key1long; + u8 key2short; + u8 unknown8[2]; + u8 rstmenu; + u8 singlewatch; + u8 hangup; + u8 voxsw; + u8 gpstimezone; + u8 pwronpwdsw; + u8 pwronpwd[3]; + char stationid[16]; + }; + """ + + _end_fmt = """ + #seekto 0x83C0; + struct { + u8 unknown1:4, + modetype:4; + u8 tx_220mhz; + u8 unknown2; + u8 tx_520mhz; + u8 rx_am; + } modes; + """ + + def _bbcd2num(self, bcdarr, strlen=6): + # doing bbcd + LOG.debug(bcdarr.get_value()) + string = ''.join("%02X" % b for b in bcdarr) + LOG.debug("@_bbcd2num, received: %s" % string) + if strlen <= 6: + string = string[:strlen] + return string + + def _num2bbcd(self, value): + numstr = value.get_value() + numstr = str.ljust(numstr.strip(), 6, "F") + bcdarr = list(bytearray.fromhex(numstr)) + LOG.debug("@_num2bbcd, sending: %s" % bcdarr) + return bcdarr + + def get_settings_pro_basic(self, basic, _mem): + super().get_settings_pro_basic(basic, _mem) + + if _mem.settings.tdr_tx >= len(LIST_OFF_AB): + val = 0x00 + else: + val = _mem.settings.tdr_tx + rs = RadioSetting("settings.tdr_tx", "TDR TX", + RadioSettingValueList( + LIST_OFF_AB, current_index=val)) + basic.append(rs) + + if _mem.settings.powerontone >= len(LIST_POWERON_TONE): + val = 0x00 + else: + val = _mem.settings.powerontone + rs = RadioSetting("settings.powerontone", "Power On Tone", + RadioSettingValueList( + LIST_POWERON_TONE, current_index=val)) + basic.append(rs) + + if _mem.settings.lcdcontrast >= len(LIST_LCD_CONTRAST): + val = 0x03 + else: + val = _mem.settings.lcdcontrast + rs = RadioSetting("settings.lcdcontrast", "LCD Contrast", + RadioSettingValueList( + LIST_LCD_CONTRAST, current_index=val)) + basic.append(rs) + + rs = RadioSetting("settings.invertlcd", "Invert LCD", + RadioSettingValueBoolean(_mem.settings.invertlcd)) + basic.append(rs) + + rs = RadioSetting("settings.key1short", "PF1", + RadioSettingValueList( + self.LIST_SKEYS, + current_index=_mem.settings.key1short)) + basic.append(rs) + + rs = RadioSetting("settings.key1long", "PF1 Long", + RadioSettingValueList( + self.LIST_SKEYS, + current_index=_mem.settings.key1long)) + basic.append(rs) + + rs = RadioSetting("settings.key2short", "PF2", + RadioSettingValueList( + self.LIST_SKEYS, + current_index=_mem.settings.key2short)) + basic.append(rs) + + rs = RadioSetting("settings.fminterrupt", "FM Interrupt", + RadioSettingValueBoolean(_mem.settings.fminterrupt)) + basic.append(rs) + + rs = RadioSetting("settings.txdisable", "Disable TX", + RadioSettingValueBoolean(_mem.settings.txdisable)) + basic.append(rs) + + rs = RadioSetting("settings.pwronpwdsw", "Power On Password Switch", + RadioSettingValueBoolean(_mem.settings.pwronpwdsw)) + basic.append(rs) + + def _filter(name): + filtered = "" + for char in str(name): + if char in NUMERIC_CHARS: + filtered += char + else: + filtered += " " + return filtered + + # setup power on password entry + codesetting = getattr(_mem.settings, "pwronpwd") + codestr = self._bbcd2num(codesetting, 6) + code = RadioSettingValueString(0, 6, _filter(codestr)) + code.set_charset(NUMERIC_CHARS + list(" ")) + rs = RadioSetting("settings.pwronpwd", "Power On Password", code) + basic.append(rs) + + def _filterStationID(name): + fname = b"" + for char in name: + if ord(str(char)) in [0, 255]: + break + fname += int(char).to_bytes(1, 'big') + return fname.decode('gb2312').strip() + + def apply_stationid(setting, obj): + stationid = (str(setting.value).encode('gb2312')[:16].ljust(16, + b"\xFF")) + obj.stationid = stationid + + _nameobj = self._memobj.settings + rs = RadioSetting("settings.stationid", + "StationID", + RadioSettingValueString( + 0, 16, _filterStationID(_nameobj.stationid), + False, CHARSET_GB2312)) + rs.set_apply_callback(apply_stationid, _nameobj) + basic.append(rs) + + rs = RadioSetting("modes.modetype", "Factory Modes", + RadioSettingValueList( + LIST_MODES, + current_index=_mem.modes.modetype)) + basic.append(rs) + + rs = RadioSetting("modes.tx_220mhz", "220M TX", + RadioSettingValueBoolean(_mem.modes.tx_220mhz)) + basic.append(rs) + + rs = RadioSetting("modes.tx_520mhz", "520M TX", + RadioSettingValueBoolean(_mem.modes.tx_520mhz)) + basic.append(rs) + + rs = RadioSetting("modes.rx_am", "AM RX", + RadioSettingValueBoolean(_mem.modes.rx_am)) + basic.append(rs) + + def get_settings_pro_dtmf(self, dtmfe, _mem): + super().get_settings_pro_dtmf(dtmfe, _mem) + + rs = RadioSetting("ani.separatecode", "Separate Code", + RadioSettingValueList( + self.LIST_SEPARATE_CODE, + current_index=_mem.ani.separatecode)) + dtmfe.append(rs) + + rs = RadioSetting("ani.groupcallcode", "Group Call Code", + RadioSettingValueList( + self.LIST_GROUP_CALL_CODE, + current_index=_mem.ani.groupcallcode)) + dtmfe.append(rs) + + _codeobj = self._memobj.upcode.code + _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) + < 0x1F]) + val = RadioSettingValueString(0, 16, _code, False) + val.set_charset(DTMF_CHARS) + rs = RadioSetting("upcode.code", "Up Code", val) + rs.set_apply_callback(self.apply_code, self._memobj.upcode, 16) + dtmfe.append(rs) + + _codeobj = self._memobj.downcode.code + _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) + < 0x1F]) + val = RadioSettingValueString(0, 16, _code, False) + val.set_charset(DTMF_CHARS) + rs = RadioSetting("downcode.code", "Down Code", val) + rs.set_apply_callback(self.apply_code, self._memobj.downcode, 16) + dtmfe.append(rs) diff --git a/chirp/drivers/btech.py b/chirp/drivers/btech.py index 468bb05..d0cb0b1 100644 --- a/chirp/drivers/btech.py +++ b/chirp/drivers/btech.py @@ -302,6 +302,9 @@ KTWP12_fp = b"WP3094" # Anysecu WP-9900 WP9900_fp = b"WP3094" +# QYT KT-5000 +KT5000_fp = b"WP9114" + # ### MAGICS # for the Waccom Mini-8900 @@ -327,6 +330,8 @@ MSTRING_GMRS20V2 = b"\x55\x20\x21\x03\x27\xFF\xDC\x02" MSTRING_KT8R = b"\x55\x20\x17\x07\x03\xFF\xDC\x02" # for the QYT KT-WP12, KT-9900 and Anysecu WP-9900 MSTRING_KTWP12 = b"\x55\x20\x18\x11\x02\xFF\xDC\x02" +# for the QYT KT-5000 +MSTRING_KT5000 = b"\x55\x20\x21\x01\x23\xFF\xDC\x02" def _clean_buffer(radio): @@ -5754,6 +5759,37 @@ class WP9900(BTechColorWP): @directory.register +class KT5000(BTechColorWP): + """QYT KT-5000""" + # TODO: memory map is not EXACTLY the same as in WP12. E.g. setting + # "C display mode" overwrites VOX setting + VENDOR = "QYT" + MODEL = "KT-5000" + BANDS = 2 + UPLOAD_MEM_SIZE = 0X3100 + _power_levels = [chirp_common.PowerLevel("High", watts=25), + chirp_common.PowerLevel("Low", watts=5)] + _upper = 199 + _magic = MSTRING_KT5000 + _fileid = [KT5000_fp] + _gmrs = False + + def process_mmap(self): + """Process the mem map into the mem object""" + + # Get it + self._memobj = bitwise.parse(COLOR9900_MEM_FORMAT, self._mmap) + + # load specific parameters from the radio image + self.set_options() + + def get_features(self): + rf = super().get_features() + rf.has_settings = False + return rf + + +@directory.register class GMRS20V2(BTechColorWP): """Baofeng Tech GMRS-20V2""" MODEL = "GMRS-20V2" diff --git a/chirp/drivers/generic_csv.py b/chirp/drivers/generic_csv.py index e19e4f8..ed1de4d 100644 --- a/chirp/drivers/generic_csv.py +++ b/chirp/drivers/generic_csv.py @@ -13,6 +13,7 @@ # 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 io import os import csv import logging @@ -61,6 +62,7 @@ class CSVRadio(chirp_common.FileBackedRadio): NEEDS_COMPAT_SERIAL = True FILE_EXTENSION = "csv" FORMATS = [directory.register_format('CSV', '*.csv')] + SEPCHAR = ',' ATTR_MAP = { "Location": (int, "number"), @@ -91,6 +93,9 @@ class CSVRadio(chirp_common.FileBackedRadio): # Default to 50W self.memories[0].power = DEFAULT_POWER_LEVEL + def clear(self): + self.memories = [] + def __init__(self, pipe): chirp_common.FileBackedRadio.__init__(self, None) self.memories = [] @@ -191,6 +196,9 @@ class CSVRadio(chirp_common.FileBackedRadio): return self._clean(headers, line, mem) + def load_from(self, string): + self._load(io.StringIO(string, newline='')) + def load(self, filename=None): if filename is None and self._filename is None: raise errors.RadioError("Need a location to load from") @@ -204,7 +212,7 @@ class CSVRadio(chirp_common.FileBackedRadio): return self._load(f) def _load(self, f): - reader = csv.reader(f, delimiter=chirp_common.SEPCHAR, quotechar='"') + reader = csv.reader(f, delimiter=self.SEPCHAR, quotechar='"') self._comments = [] good = 0 @@ -226,7 +234,8 @@ class CSVRadio(chirp_common.FileBackedRadio): self.file_has_cTone = "cToneFreq" in header continue - if len(header) > len(line): + # Spreadsheets like to omit trailing empty columns in TSV + if len(header) > len(line) and not self.SEPCHAR.isspace(): LOG.error("Line %i has %i columns, expected %i", lineno, len(line), len(header)) self.errors.append("Column number mismatch on line %i" % @@ -235,7 +244,7 @@ class CSVRadio(chirp_common.FileBackedRadio): try: mem = self._parse_csv_data_line(header, line) - if mem is None: + if mem is None or mem.freq == 0: LOG.debug('Line %i did not contain a valid memory', lineno) continue @@ -262,24 +271,32 @@ class CSVRadio(chirp_common.FileBackedRadio): self._filename = filename with open(self._filename, "w", newline='', encoding='utf-8') as f: - comments = list(self._comments) - writer = csv.writer(f, delimiter=chirp_common.SEPCHAR) + self._write_to(f) + + def _write_to(self, f): + comments = list(self._comments) + writer = csv.writer(f, delimiter=self.SEPCHAR) + + for index, comment in comments[:]: + if index >= 0: + break + writer.writerow([comment]) + comments.pop(0) + writer.writerow(chirp_common.Memory.CSV_FORMAT) + + for mem in self.memories: for index, comment in comments[:]: - if index >= 0: + if index >= mem.number: break writer.writerow([comment]) comments.pop(0) + write_memory(writer, mem) - writer.writerow(chirp_common.Memory.CSV_FORMAT) - - for mem in self.memories: - for index, comment in comments[:]: - if index >= mem.number: - break - writer.writerow([comment]) - comments.pop(0) - write_memory(writer, mem) + def as_string(self): + string = io.StringIO(newline='') + self._write_to(string) + return string.getvalue() # MMAP compatibility def save_mmap(self, filename): @@ -332,7 +349,7 @@ class CSVRadio(chirp_common.FileBackedRadio): def get_raw_memory(self, number): return ",".join(chirp_common.Memory.CSV_FORMAT) + \ os.linesep + \ - ",".join(self.memories[number].to_csv()) + self.SEPCHAR.join(self.memories[number].to_csv()) @classmethod def match_model(cls, filedata, filename): @@ -566,3 +583,7 @@ class RTCSVRadio(CSVRadio): return filename.lower().endswith("." + cls.FILE_EXTENSION) and \ 'Receive Frequency' in firstline_fields + + +class TSVRadio(CSVRadio): + SEPCHAR = '\t' diff --git a/chirp/drivers/icomciv.py b/chirp/drivers/icomciv.py index ea87a63..799cac7 100644 --- a/chirp/drivers/icomciv.py +++ b/chirp/drivers/icomciv.py @@ -655,6 +655,10 @@ class IcomCIVRadio(icf.IcomLiveRadio): loc = "number %i" % ch self._send_frame(f) f.read(self.pipe) + try: + self.get_memory(number) + except Exception as e: + LOG.exception('Failed to get/parse test memory: %s', e) if f.get_data() and f.get_data()[-1] == "\xFF": return "Memory " + loc + " empty." else: @@ -757,7 +761,7 @@ class IcomCIVRadio(icf.IcomLiveRadio): mem.name = str(memobj.name).rstrip() if self._rf.valid_tmodes: - mem.tmode = self._rf.valid_tmodes[memobj.tmode] + self._decode_tmode(mem, memobj) if self._rf.has_dtcs_polarity: if memobj.dtcs_polarity == 0x11: @@ -883,7 +887,7 @@ class IcomCIVRadio(icf.IcomLiveRadio): memobj.name = mem.name.ljust(name_length)[:name_length] if self._rf.valid_tmodes: - memobj.tmode = self._rf.valid_tmodes.index(mem.tmode) + self._encode_tmode(mem, memobj) if self._rf.has_ctone: memobj.ctone = int(mem.ctone * 10) @@ -930,6 +934,12 @@ class IcomCIVRadio(icf.IcomLiveRadio): f = self._recv_frame() LOG.debug("Result:\n%s" % util.hexprint(bytes(f.get_data()))) + def _encode_tmode(self, mem, memobj): + memobj.tmode = self._rf.valid_tmodes.index(mem.tmode) + + def _decode_tmode(self, mem, memobj): + mem.tmode = self._rf.valid_tmodes[memobj.tmode] + @directory.register class Icom7200Radio(IcomCIVRadio): @@ -1338,6 +1348,12 @@ class Icom9700Radio(IcomCIVRadio): "RTTY-R", None, None, None, None, None, None, None, None, None, "DV", None, None, None, None, "DD", None, None, None, None, None, ] + _CROSS_MODES = { + 4: 'DTCS->', + 5: 'Tone->DTCS', + 6: 'DTCS->Tone', + 7: 'Tone->Tone', + } def get_sub_devices(self): return [Icom9700RadioBand(self, 1), @@ -1351,6 +1367,21 @@ class Icom9700Radio(IcomCIVRadio): self._rf.memory_bounds = (1, 99) self._classes['mem'] = IC9700MemFrame + def _decode_tmode(self, mem, memobj): + if int(memobj.tmode) in self._CROSS_MODES: + mem.tmode = 'Cross' + mem.cross_mode = self._CROSS_MODES[int(memobj.tmode)] + else: + return super()._decode_tmode(mem, memobj) + + def _encode_tmode(self, mem, memobj): + cmr = {v: k for k, v in self._CROSS_MODES.items()} + if mem.tmode == 'Cross': + memobj.tmode = cmr[mem.cross_mode] + print('Setting tmode to %s for %s' % (memobj.tmode, mem.tmode)) + else: + return super()._encode_tmode(mem, memobj) + class Icom9700RadioBand(Icom9700Radio): _SPECIAL_CHANNELS = { @@ -1397,7 +1428,8 @@ class Icom9700RadioBand(Icom9700Radio): def _initialize(self): super()._initialize() self._rf.has_name = True - self._rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS'] + self._rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS', 'Cross'] + self._rf.valid_cross_modes = list(self._CROSS_MODES.values()) self._rf.has_dtcs = True self._rf.has_dtcs_polarity = True self._rf.has_bank = True @@ -1433,6 +1465,7 @@ class Icom9700SatelliteBand(Icom9700Radio): super()._initialize() self._rf.has_name = True self._rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS'] + self._rf.has_ctone = True self._rf.has_dtcs = True self._rf.has_dtcs_polarity = True self._rf.has_bank = False diff --git a/chirp/drivers/ict10.py b/chirp/drivers/ict10.py new file mode 100644 index 0000000..a9b073f --- /dev/null +++ b/chirp/drivers/ict10.py @@ -0,0 +1,577 @@ +# Copyright 2008 Dan Smith <dsmith@danplanet.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/>. + +import logging + +from chirp.drivers import icf +from chirp import chirp_common, bitwise, errors, directory +from chirp.settings import RadioSetting, RadioSettingGroup, \ + RadioSettingValueInteger, RadioSettingValueList, \ + RadioSettingValueBoolean, RadioSettingValueString, \ + RadioSettings + +LOG = logging.getLogger(__name__) + + +ICV86_MEM_FORMAT = """ +#seekto 0x020; +lbit pskips[208]; + +#seekto 0x040; +lbit skips[208]; + +#seekto 0x060; +lbit used[208]; + +struct { + #seekto 0x010; + char comment[16]; + + #seekto 0x0FD; + u8 wx_channel; + + #seekto 0x100; + u8 reserved1:6, + beep:2; + u8 reserved2:3, + tot:5; + u8 reserved3; + u8 reserved4:6, + auto_pwr:2; + u8 reserved5:6, + lockout:2; + u8 reserved6:7, + sql_delay:1; + u8 reserved7; + u8 reserved8:6, + disp_type:2; + u8 reserved9; + u8 reserved10:5, + pwr_save:3; + u8 reserved11:7, + dial_speedup:1; + u8 reserved12:6, + simple_mode:2; + u8 reserved13:7, + ant:1; + u8 reserved14:7, + monitor:1; + u8 reserved15; + u8 reserved16; + u8 reserved17:6, + pause_timer:2; + u8 reserved18; + u8 reserved19:7, + skip_scan:1; + u8 reserved20:6, + lcd:2; + u8 reserved21:7, + wx:1; + u8 reserved22:6, + mic:2; + u8 reserved23:4, + vox_gain:4; + u8 reserved24:5, + vox_delay:3; + u8 reserved25:5, + vox_tot:3; + u8 reserved26; + u8 reserved27; + u8 reserved28:5, + edge:3; + u8 reserved29; + u8 reserved30:7, + auto_low:1; + u8 reserved31:7, + volt:1; + u8 reserved32:7, + ctcss_burst:1; + u8 reserved33; + u8 reserved34; + u8 reserved35; + u8 reserved36:7, + vox:1; + u8 reserved37; + u8 reserved38; + u8 reserved39:6, + p_short:2; + u8 reserved40:6, + p_long:2; +} settings; + +#seekto 0x0240; +struct { + ul32 freq; + ul32 offset; + char name[6]; + u8 reserved1:2, + rtone:6; + u8 reserved2:2, + ctone:6; + u8 reserved3:1, + dtcs:7; + u8 reserved4:4, + tuning_step:4; + u8 reserved5:2, + mode:1, + rev:1, + duplex:2, + reserved6:2; + u8 reserved7:2, + dtcs_polarity:2, + tmode:4; + u8 reserved8:5, + tx_inhibit:1, + power:2; + u8 reserved9; + u8 reserved10; + u8 reserved11; +} memory[208]; + +""" + +SPECIAL = { + "1A": 200, "1B": 201, + "2A": 202, "2B": 203, + "3A": 204, "3B": 205, + "C0": 206, "C1": 207, +} + +TMODES = ["", "Tone", "TSQL", "DTCS"] +MODES = ["FM", "NFM"] +SKIPS = ["", "S", "P"] +DUPLEXES = ["", "-", "+"] +DTCS_POLARITY = ["NN", "NR", "RN", "RR"] +TUNING_STEPS = [5., 10., 12.5, 15., 20., 25., 30., 50., 100., 125., 200.] +POWER_LEVELS = [ + chirp_common.PowerLevel("High", watts=5.0), + chirp_common.PowerLevel("Low", watts=0.5), + chirp_common.PowerLevel("Mid", watts=2.5), +] + + +@directory.register +class ICVT10Radio(icf.IcomCloneModeRadio): + """Icom IC-T10""" + VENDOR = "Icom" + MODEL = "IC-T10" + + _model = "\x43\x28\x00\x01" + _memsize = 5888 + _endframe = "Icom Inc\x2eB8" + + _ranges = [(0x0000, 5888, 32)] + + def get_features(self): + rf = chirp_common.RadioFeatures() + + rf.memory_bounds = (0, 199) + rf.valid_modes = MODES + rf.valid_tmodes = TMODES + rf.valid_duplexes = DUPLEXES + rf.valid_tuning_steps = TUNING_STEPS + rf.valid_power_levels = POWER_LEVELS + rf.valid_skips = SKIPS + rf.valid_name_length = 6 + rf.valid_special_chans = list(SPECIAL.keys()) + rf.valid_bands = [(136000000, 174000000), (400000000, 479000000)] + rf.has_ctone = True + rf.has_offset = True + rf.has_bank = False + rf.has_settings = True + + return rf + + def __init__(self, pipe): + icf.IcomCloneModeRadio.__init__(self, pipe) + + def sync_in(self): + icf.IcomCloneModeRadio.sync_in(self) + + def sync_out(self): + icf.IcomCloneModeRadio.sync_out(self) + + def process_mmap(self): + self._memobj = bitwise.parse(ICV86_MEM_FORMAT, self._mmap) + + def get_settings(self): + _settings = self._memobj.settings + + setmode = RadioSettingGroup("setmode", "Set Mode") + assign = RadioSettingGroup("assign", "Key Assign") + display = RadioSettingGroup("display", "Display") + sounds = RadioSettingGroup("sounds", "Sounds") + scan = RadioSettingGroup("Scan", "Scan") + fm = RadioSettingGroup("fm", "FM Radio") + wx = RadioSettingGroup("wx", "WX") + + settings = RadioSettings( + setmode, assign, display, sounds, scan, fm, wx) + + # Timeout Timer + opts = ["Off"] + ["%s min" % x for x in range(1, 31)] + setmode.append( + RadioSetting( + "tot", "Timeout Timer", + RadioSettingValueList(opts, current_index=_settings.tot))) + + # Auto Power Off + opts = ["Off", "30 min", "1 hr", "2 hrs"] + setmode.append( + RadioSetting( + "auto_pwr", "Auto Power Off", + RadioSettingValueList(opts, current_index=_settings.auto_pwr))) + + # Lockout + opts = ["Off", "Rpt", "Busy"] + setmode.append( + RadioSetting( + "lockout", "Lockout", + RadioSettingValueList(opts, current_index=_settings.lockout))) + + # Squelch Delay + opts = ["Short", "Long"] + setmode.append( + RadioSetting( + "sql_delay", "Squelch Delay", + RadioSettingValueList( + opts, current_index=_settings.sql_delay))) + + # Power Save + opts = ["Off", "1:2", "1:8", "1:16", "Auto"] + setmode.append( + RadioSetting( + "pwr_save", "Power Save", + RadioSettingValueList(opts, current_index=_settings.pwr_save))) + + # Dial Speed-up + setmode.append( + RadioSetting( + "dial_speedup", "Dial Speed-Up", + RadioSettingValueBoolean(bool(_settings.dial_speedup)))) + + # Mic Simple Mode + opts = ["Simple", "Normal-1", "Normal-2"] + setmode.append( + RadioSetting( + "simple_mode", "Mic Simple Mode", + RadioSettingValueList( + opts, current_index=_settings.simple_mode))) + + # Mic Gain + rs = RadioSetting( + "mic", "Mic Gain", + RadioSettingValueInteger(1, 4, _settings.mic + 1)) + rs.set_apply_callback( + lambda s, obj: setattr(obj, s.get_name(), int(s.value) - 1), + self._memobj.settings) + setmode.append(rs) + + # Auto Low Power + setmode.append( + RadioSetting( + "auto_low", "Auto Low Power", + RadioSettingValueBoolean(bool(_settings.auto_low)))) + + # Vox Function + setmode.append( + RadioSetting( + "vox", "Vox Function", + RadioSettingValueBoolean(bool(_settings.vox)))) + + # Vox Gain + opts = ["Off"] + ["%s" % x for x in range(1, 11)] + setmode.append( + RadioSetting( + "vox_gain", "Vox Gain", + RadioSettingValueList( + opts, current_index=_settings.vox_gain))) + + # Vox Delay + opts = ["0.5 seconds", "1.0 seconds", "1.5 seconds", "2.0 seconds", + "2.5 seconds", "3.0 seconds"] + setmode.append( + RadioSetting( + "vox_delay", "Vox Delay", + RadioSettingValueList( + opts, current_index=_settings.vox_delay))) + + # VOX Time out Timer + opts = ["Off", "1 min", "2 min", "3 min", "4 min", "5 min", + "10 min", "15 min"] + setmode.append( + RadioSetting( + "vox_tot", "VOX Time-Out Timer", + RadioSettingValueList(opts, current_index=_settings.vox_tot))) + + # CTCSS Burst + setmode.append( + RadioSetting( + "ctcss_burst", "CTCSS Burst", + RadioSettingValueBoolean(bool(_settings.ctcss_burst)))) + + # Monitor + opts = ["Push", "Hold"] + setmode.append( + RadioSetting( + "monitor", "Monitor", + RadioSettingValueList(opts, current_index=_settings.monitor))) + + # Comment + setmode.append( + RadioSetting( + "comment", "Comment", + RadioSettingValueString( + 0, 16, str(_settings.comment).rstrip(), autopad=False))) + + # P (Short) + opts = ["Null", "TS", "MHz", "T-CALL"] + assign.append( + RadioSetting( + "p_short", "P (Short)", + RadioSettingValueList(opts, current_index=_settings.p_short))) + + # P (Long) + opts = ["Null", "TS", "MHz", "T-CALL"] + assign.append( + RadioSetting( + "p_long", "P (Short)", + RadioSettingValueList(opts, current_index=_settings.p_long))) + + # Backlight + opts = ["Off", "On", "Auto"] + display.append( + RadioSetting( + "lcd", "Backlight", + RadioSettingValueList(opts, current_index=_settings.lcd))) + + # Display Type + opts = ["Frequency", "Channel", "Name"] + display.append( + RadioSetting( + "disp_type", "Display Type", + RadioSettingValueList( + opts, current_index=_settings.disp_type))) + + # Voltage Indicator + opts = ["Off", "On"] + display.append( + RadioSetting( + "volt", "Voltage Indicator", + RadioSettingValueList(opts, current_index=_settings.volt))) + + # Timeout Timer + opts = ["Off"] + ["%d" % x for x in range(1, 4)] + sounds.append( + RadioSetting( + "beep", "Beep Level", + RadioSettingValueList(opts, current_index=_settings.beep))) + + # Program Skip Scan + scan.append( + RadioSetting( + "skip_scan", "Program Skip Scan", + RadioSettingValueBoolean(bool(_settings.skip_scan)))) + + # Edge + opts = ["All", "Band", "P1", "P2", "P3"] + scan.append( + RadioSetting( + "edge", "Edge", + RadioSettingValueList(opts, current_index=_settings.edge))) + + # Pause Timer + opts = ["T-5", "T-10", "T-15", "P-2"] + scan.append( + RadioSetting( + "pause_timer", "Pause Timer", + RadioSettingValueList( + opts, current_index=_settings.pause_timer))) + + # Earphone Antenna + opts = ["Not Used", "Use"] + fm.append( + RadioSetting( + "ant", "Earphone Antenna", + RadioSettingValueList(opts, current_index=_settings.ant))) + + # WX Alert + wx.append( + RadioSetting( + "wx", "WX Alert", + RadioSettingValueBoolean(bool(_settings.wx)))) + + # Mic Gain + rs = RadioSetting( + "wx_channel", "WX Channel", + RadioSettingValueInteger(1, 10, _settings.wx_channel + 1)) + rs.set_apply_callback( + lambda s, obj: setattr(obj, s.get_name(), int(s.value) - 1), + self._memobj.settings) + wx.append(rs) + + return settings + + def set_settings(self, settings): + _settings = self._memobj.settings + for element in settings: + if not isinstance(element, RadioSetting): + self.set_settings(element) + continue + if not element.changed(): + continue + + try: + if element.has_apply_callback(): + LOG.debug("Using apply callback") + element.run_apply_callback() + else: + setting = element.get_name() + LOG.debug("Setting %s = %s" % (setting, element.value)) + setattr(_settings, setting, element.value) + except Exception: + LOG.debug(element.get_name()) + raise + + def _get_extra(self, mem): + ext = RadioSettingGroup("extra", "Extra") + + rev = RadioSetting("rev", "Reverse duplex", + RadioSettingValueBoolean(bool(mem.rev))) + rev.set_doc("Reverse duplex") + ext.append(rev) + + tx_inhibit = RadioSetting("tx_inhibit", "Tx inhibit", + RadioSettingValueBoolean( + bool(mem.tx_inhibit))) + tx_inhibit.set_doc("Tx inhibit") + ext.append(tx_inhibit) + + return ext + + def _get_memory(self, number, extd_number): + mem = chirp_common.Memory() + mem.number = number + + _mem = self._memobj.memory[number] + + if extd_number is None: + _usd = self._memobj.used[number] + _skp = self._memobj.skips[number] + _psk = self._memobj.pskips[number] + else: + mem.extd_number = extd_number + mem.immutable = ["number", "extd_number"] + if (number >= 206): + mem.immutable.append("skip") + _usd = self._memobj.used[number] if (number < 206) else None + _skp = self._memobj.skips[number] if (number < 206) else None + _psk = self._memobj.pskips[number] if (number < 206) else None + + if _usd is not None and _usd: + mem.empty = True + return mem + + mem.freq = _mem.freq + mem.offset = int(_mem.offset) + mem.name = str(_mem.name).rstrip() + mem.rtone = chirp_common.TONES[_mem.rtone] + mem.ctone = chirp_common.TONES[_mem.ctone] + mem.dtcs = chirp_common.DTCS_CODES[_mem.dtcs] + mem.tuning_step = TUNING_STEPS[_mem.tuning_step] + mem.mode = MODES[_mem.mode] + mem.duplex = DUPLEXES[_mem.duplex] + mem.dtcs_polarity = DTCS_POLARITY[_mem.dtcs_polarity] + mem.tmode = TMODES[_mem.tmode] + mem.power = POWER_LEVELS[_mem.power] + + mem.extra = self._get_extra(_mem) + + if _skp is not None: + mem.skip = (_psk and "P") or (_skp and "S") or "" + + return mem + + def get_memory(self, number): + extd_number = None + if isinstance(number, str): + try: + extd_number = number + number = dict(SPECIAL)[number] + except KeyError: + raise errors.InvalidMemoryLocation( + "Unknown channel %s" % number) + + return self._get_memory(number, extd_number) + + def _fill_memory(self, number): + _mem = self._memobj.memory[number] + + # Default values + _mem.fill_raw(b'\x00') + _mem.freq = 146010000 + _mem.offset = 146010000 + _mem.name = str("").ljust(6) + _mem.rtone = 0x8 + _mem.ctone = 0x8 + + def _set_memory(self, mem): + _mem = self._memobj.memory[mem.number] + _usd = self._memobj.used[mem.number] if mem.number < 206 else None + _skp = self._memobj.skips[mem.number] if mem.number < 206 else None + _psk = self._memobj.pskips[mem.number] if mem.number < 206 else None + + if mem.empty: + self._fill_memory(mem.number) + if _usd is not None: + _usd |= 1 + return + + if _usd is None or _usd: + self._fill_memory(mem.number) + + _mem.freq = mem.freq + _mem.offset = int(mem.offset) + _mem.name = str(mem.name).ljust(6) + _mem.rtone = chirp_common.TONES.index(mem.rtone) + _mem.ctone = chirp_common.TONES.index(mem.ctone) + _mem.dtcs = chirp_common.DTCS_CODES.index(mem.dtcs) + _mem.tuning_step = TUNING_STEPS.index(mem.tuning_step) + _mem.mode = MODES.index(mem.mode) + _mem.duplex = DUPLEXES.index(mem.duplex) + _mem.dtcs_polarity = DTCS_POLARITY.index(mem.dtcs_polarity) + _mem.tmode = TMODES.index(mem.tmode) + _mem.power = 0 if mem.power is None else POWER_LEVELS.index(mem.power) + + for setting in mem.extra: + setattr(_mem, setting.get_name(), setting.value) + + if _usd is not None: + _usd &= 0 + + if _skp is not None: + _skp &= 0 + _psk &= 0 + if mem.skip == "S": + _skp |= 1 + elif mem.skip == "P": + _psk |= 1 + + def set_memory(self, mem): + return self._set_memory(mem) + + def get_raw_memory(self, number): + return repr(self._memobj.memory[number]) + \ + repr(self._memobj.used[(number)]) diff --git a/chirp/drivers/kg935g.py b/chirp/drivers/kg935g.py index a2c8deb..51157de 100644 --- a/chirp/drivers/kg935g.py +++ b/chirp/drivers/kg935g.py @@ -74,6 +74,22 @@ config_map_935G = ( # map address, write size, write count (0x4780, 32, 375), # Memory Names 0-999 (0x7670, 8, 125), # Ch Valid bytes 0-999 ) +config_map_935H = ( # map address, write size, write count + # (0x00, 64, 512), #- Use for full upload testing + (0x14, 1, 1), # Tx Range Lock + (0x44, 32, 1), # Freq Limits + (0x440, 8, 1), # Area Message + (0x480, 8, 5), # Scan Groups + (0x500, 8, 15), # Call Codes + (0x580, 8, 15), # Call Names + (0x600, 8, 5), # FM Presets + (0x800, 64, 2), # settings + (0x880, 16, 1), # VFO A + (0x8C0, 16, 1), # VFO B + (0x900, 64, 250), # Channel Memory 0-999 + (0x4780, 32, 375), # Memory Names 0-999 + (0x7670, 8, 125), # Ch Valid bytes 0-999 + ) AB_LIST = ["A", "B"] STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 25.0, 50.0, 100.0] @@ -969,6 +985,283 @@ _MEM_FORMAT_UV8H = """ u8 valid[1000]; """ +_MEM_FORMAT_935H = """ + #seekto 0x0014; + struct { + u8 txlocked; + } lock; + + #seekto 0x0044; + struct { + u32 rx_start; + u32 rx_stop; + u32 tx_start; + u32 tx_stop; + } uhf_limits; + + #seekto 0x0054; + struct { + u32 rx_start; + u32 rx_stop; + u32 tx_start; + u32 tx_stop; + } vhf_limits; + + #seekto 0x0400; + struct { + char oem1[8]; + char unknown[2]; + u8 unknown2[10]; + u8 unknown3[10]; + u8 unknown4[8]; + char oem2[10]; + u8 version[6]; + char date[8]; + u8 unknown5[2]; + char model[8]; + } oem_info; + + #seekto 0x0480; + struct { + u16 Group_lower1; + u16 Group_upper1; + u16 Group_lower2; + u16 Group_upper2; + u16 Group_lower3; + u16 Group_upper3; + u16 Group_lower4; + u16 Group_upper4; + u16 Group_lower5; + u16 Group_upper5; + u16 Group_lower6; + u16 Group_upper6; + u16 Group_lower7; + u16 Group_upper7; + u16 Group_lower8; + u16 Group_upper8; + u16 Group_lower9; + u16 Group_upper9; + u16 Group_lower10; + u16 Group_upper10; + } scan_groups; + + #seekto 0x0500; + struct { + u8 cid[6]; + } call_ids[20]; + + #seekto 0x0580; + struct { + char call_name1[6]; + char call_name2[6]; + char call_name3[6]; + char call_name4[6]; + char call_name5[6]; + char call_name6[6]; + char call_name7[6]; + char call_name8[6]; + char call_name9[6]; + char call_name10[6]; + char call_name11[6]; + char call_name12[6]; + char call_name13[6]; + char call_name14[6]; + char call_name15[6]; + char call_name16[6]; + char call_name17[6]; + char call_name18[6]; + char call_name19[6]; + char call_name20[6]; + } call_names; + + + #seekto 0x0600; + struct { + u16 FM_radio1; + u16 FM_radio2; + u16 FM_radio3; + u16 FM_radio4; + u16 FM_radio5; + u16 FM_radio6; + u16 FM_radio7; + u16 FM_radio8; + u16 FM_radio9; + u16 FM_radio10; + u16 FM_radio11; + u16 FM_radio12; + u16 FM_radio13; + u16 FM_radio14; + u16 FM_radio15; + u16 FM_radio16; + u16 FM_radio17; + u16 FM_radio18; + u16 FM_radio19; + u16 FM_radio20; + u16 unknown_pad_x0640[235]; + u8 unknown07fe; + u8 unknown07ff; + u8 ponmsg; + char dispstr[15]; + u8 unknown0810; + u8 unknown0811; + u8 unknown0812; + u8 unknown0813; + u8 unknown0814; + u8 voice; + u8 timeout; + u8 toalarm; + u8 channel_menu; + u8 power_save; + u8 autolock; + u8 keylock; + u8 beep; + u8 stopwatch; + u8 vox; + u8 scan_rev; + u8 backlight; + u8 roger_beep; + char mode_sw_pwd[6]; + char reset_pwd[6]; + u16 pri_ch; + u8 ani_sw; + u8 ptt_delay; + u8 ani_code[6]; + u8 dtmf_st; + u8 BCL_A; + u8 BCL_B; + u8 ptt_id; + u8 prich_sw; + u8 rpttype; + u8 rptspk; + u8 rptptt; + u8 alert; + u8 pf1_shrt; + u8 pf1_long; + u8 pf2_shrt; + u8 pf2_long; + u8 unknown0845; + u8 work_mode_a; + u8 work_mode_b; + u8 dtmf_tx_time; + u8 dtmf_interval; + u8 main_band; + u16 work_ch_a; + u16 work_ch_b; + u8 unknown084f; + u8 unknown0850; + u8 unknown0851; + u8 unknown0852; + u8 unknown0853; + u8 unknown0854; + u8 unknown0855; + u8 unknown0856; + u8 unknown0857; + u8 unknown0858; + u8 unknown0859; + u8 unknown085a; + u8 unknown085b; + u8 unknown085c; + u8 unknown085d; + u8 unknown085e; + u8 unknown085f; + u8 unknown0860; + u8 TDR_single_mode; + u8 ring_time; + u8 ScnGrpA_Act; + u8 ScnGrpB_Act; + u8 unknown0865; + u8 rpt_tone; + u8 unknown0867; + u8 scan_det; + u8 ToneScnSave; + u8 unknown086a; + u8 smuteset; + u8 cur_call_grp; + u8 DspBrtAct; + u8 DspBrtSby; + u8 unknown086f; + u8 theme; + u8 batt_ind; + u8 wxalert; + u8 wxalert_type; + u8 VFO_repeater_a; + u8 VFO_repeater_b; + u8 sim_rec; + u8 unknown0877; + u8 unknown0878; + u8 unknown0879; + u8 unknown087a; + u8 unknown087b; + u8 unknown087c; + u8 unknown087d; + u8 unknown087e; + u8 unknown087f; + } settings; + + #seekto 0x0880; + struct { + u32 rxfreq; + u32 unknown0; + u16 rxtone; + u16 txtone; + u8 scrambler:4, + power:4; + u8 unknown3:1, + unknown5:2, + unknown4:1, + cmpndr:1, + mute_mode:2, + iswide:1; + u8 step; + u8 squelch; + } vfoa; + + #seekto 0x08c0; + struct { + u32 rxfreq; + u32 unknown0; + u16 rxtone; + u16 txtone; + u8 scrambler:4, + power:4; + u8 unknown3:1, + unknown5:2, + unknown4:1, + cmpndr:1, + mute_mode:2, + iswide:1; + u8 step; + u8 squelch; + } vfob; + + #seekto 0x0900; + struct { + u32 rxfreq; + u32 txfreq; + u16 rxtone; + u16 txtone; + u8 scrambler:4, + power:4; + u8 unknown3:2, + scan_add:1, + unknown4:1, + compander:1, + mute_mode:2, + iswide:1; + u8 unknown5; + u8 unknown6; + } memory[1000]; + + #seekto 0x4780; + struct { + u8 name[8]; + u8 unknown[4]; + } names[1000]; + + #seekto 0x7670; + u8 valid[1000]; + """ + # Support for the Wouxun KG-935G radio # Serial coms are at 19200 baud @@ -1035,6 +1328,7 @@ class KG935GRadio(chirp_common.CloneModeRadio, chirp_common.PowerLevel("M", watts=4.5), chirp_common.PowerLevel("H", watts=5.5)] _record_start = 0x7C + config_map = config_map_935G def _checksum(self, data): cs = 0 @@ -1178,7 +1472,7 @@ class KG935GRadio(chirp_common.CloneModeRadio, return def _do_upload(self): - cfgmap = config_map_935G + cfgmap = self.config_map for start, blocksize, count in cfgmap: end = start + (blocksize * count) @@ -1466,6 +1760,7 @@ class KG935GRadio(chirp_common.CloneModeRadio, def _get_settings(self): _settings = self._memobj.settings + # _txlock = self._memobj.lock _vfoa = self._memobj.vfoa _vfob = self._memobj.vfob _scan = self._memobj.scan_groups @@ -1497,7 +1792,8 @@ class KG935GRadio(chirp_common.CloneModeRadio, ani_msg = "ANI-ID Switch (ANI-SW)" pttdly_msg = "PTT-DLY" idtx_msg = "PTT-ID" - elif self.MODEL == "KG-935G Plus": + elif (self.MODEL == "KG-935G Plus" or + self.MODEL == "KG-935H"): themelist = THEME_LIST_935GPLUS vfoa_grp_label = "Freq Mode A Settings" vfob_grp_label = "Freq Mode B Settings" @@ -1578,7 +1874,7 @@ class KG935GRadio(chirp_common.CloneModeRadio, RadioSettingValueBoolean(_settings.wxalert)) cfg_grp.append(rs) - if self.MODEL == "KG-935G Plus": + if (self.MODEL == "KG-935G Plus" or self.MODEL == "KG-935H"): rs = RadioSetting("wxalert_type", "Weather Alert Notification", RadioSettingValueList(WX_TYPE, current_index=_settings. @@ -1705,6 +2001,18 @@ class KG935GRadio(chirp_common.CloneModeRadio, HOLD_TIMES, current_index=_settings.rpt_hold)) cfg_grp.append(rs) + if self.MODEL == "KG-935H": + rs = RadioSetting("rpttype", "Repeater Type", + RadioSettingValueMap(RPTTYPE_MAP, + _settings.rpttype)) + cfg_grp.append(rs) + rs = RadioSetting("rptspk", "Repeater Speaker", + RadioSettingValueBoolean(_settings.rptspk)) + cfg_grp.append(rs) + rs = RadioSetting("rptptt", "Repeater PTT", + RadioSettingValueBoolean(_settings.rptptt)) + cfg_grp.append(rs) + rs = RadioSetting("rpt_tone", "Repeater Tone", RadioSettingValueBoolean(_settings.rpt_tone)) cfg_grp.append(rs) @@ -1730,7 +2038,7 @@ class KG935GRadio(chirp_common.CloneModeRadio, _settings.dtmf_interval)) cfg_grp.append(rs) - if self.MODEL == "KG-935G Plus": + if (self.MODEL == "KG-935G Plus" or self.MODEL == "KG-935H"): rs = RadioSetting("batt_ind", "Battery Indicator", RadioSettingValueList( BATT_DISP_LIST, @@ -2062,6 +2370,12 @@ class KG935GRadio(chirp_common.CloneModeRadio, (self._memobj.uhf_limits.tx_stop / 100000.0), 0.000001, 6)) lmt_grp.append(rs) + if self.MODEL == "KG-935H": + val = self._memobj.lock.txlocked + rs = RadioSetting("lock.txlocked", + "Locked - Limits Tx to Factory Range", + RadioSettingValueBoolean(val)) + lmt_grp.append(rs) # OEM info def _decode(lst): @@ -2209,3 +2523,18 @@ class KGUV8HRadio(KG935GRadio): def process_mmap(self): self._memobj = bitwise.parse(_MEM_FORMAT_UV8H, self._mmap) + + +@directory.register +class KG935HRadio(KG935GRadio): + + """Wouxun KG-935H""" + VENDOR = "Wouxun" + MODEL = "KG-935H" + POWER_LEVELS = [chirp_common.PowerLevel("L", watts=2.0), + chirp_common.PowerLevel("M", watts=5.0), + chirp_common.PowerLevel("H", watts=8.0)] + config_map = config_map_935H + + def process_mmap(self): + self._memobj = bitwise.parse(_MEM_FORMAT_935H, self._mmap) diff --git a/chirp/drivers/mml_jc8810.py b/chirp/drivers/mml_jc8810.py index f21eeee..033ec87 100644 --- a/chirp/drivers/mml_jc8810.py +++ b/chirp/drivers/mml_jc8810.py @@ -32,6 +32,7 @@ from chirp.settings import ( RadioSettingValueInteger, RadioSettingValueList, RadioSettingValueString, + RadioSettingValueMap, ) LOG = logging.getLogger(__name__) @@ -46,7 +47,7 @@ struct { scode:4; // Signaling u8 unknown2:6, // D pttid:2; // PTT-ID - u8 unknown3:6, // E + u8 scramble:6, // Scramble txpower:2; // Power Level 0 = H, 1 = L, 2 = M u8 unknown4:1, // F narrow:1, // Bandwidth 0 = Wide, 1 = Narrow @@ -269,6 +270,8 @@ ALL_SKEY_VALUES = [0xFF, 0x2D, 0x23] +SCRAMBLE_VALUEMAP = [("Off", 0x00), ("SCRAM1", 0x04), ("SCRAM2", 0x08)] + def _enter_programming_mode(radio): serial = radio.pipe @@ -628,6 +631,16 @@ class JC8810base(chirp_common.CloneModeRadio): mem.extra = RadioSettingGroup("Extra", "extra") + # Encryption + rs = RadioSettingValueList(ENCRYPT_LIST, current_index=_mem.encrypt) + rset = RadioSetting("encrypt", "Encryption", rs) + mem.extra.append(rset) + + # Scramble + rs = RadioSettingValueMap(SCRAMBLE_VALUEMAP, _mem.scramble) + rset = RadioSetting("scramble", "Scramble", rs) + mem.extra.append(rset) + # BCL (Busy Channel Lockout) rs = RadioSettingValueBoolean(_mem.bcl) rset = RadioSetting("bcl", "BCL", rs) @@ -1364,24 +1377,27 @@ class RT470XRadio(RT470LRadio): def get_features(self): rf = super().get_features() rf.valid_modes.append('AM') + rf.valid_modes.append('NAM') rf.valid_bands = [(18000000, 1000000000)] return rf def validate_memory(self, mem): msgs = [] in_range = chirp_common.in_range - if in_range(mem.freq, [self._AIRBAND]) and not mem.mode == 'AM': + AM_mode = mem.mode == 'AM' or mem.mode == "NAM" + if in_range(mem.freq, [self._AIRBAND]) and not AM_mode: msgs.append(chirp_common.ValidationWarning( _('Frequency in this range requires AM mode'))) - if not in_range(mem.freq, [self._AIRBAND]) and mem.mode == 'AM': + if not in_range(mem.freq, [self._AIRBAND]) and AM_mode: msgs.append(chirp_common.ValidationWarning( _('Frequency in this range must not be AM mode'))) return msgs + super().validate_memory(mem) def get_memory(self, number): mem = super().get_memory(number) + _mem = self._memobj.memory[mem.number - 1] if chirp_common.in_range(mem.freq, [self._AIRBAND]): - mem.mode = 'AM' + mem.mode = _mem.narrow and "NAM" or "AM" return mem diff --git a/chirp/drivers/tdh8.py b/chirp/drivers/tdh8.py index ccaa2ff..2fb1505 100644 --- a/chirp/drivers/tdh8.py +++ b/chirp/drivers/tdh8.py @@ -702,7 +702,6 @@ MDFB_LIST = ["Frequency", "Name"] HOP_LIST = ["A", "B", "C", "D"] SYNC_LIST = ["ON", "OFF"] LANG_LIST = ["Chinese", "English"] -BTV_SAVER_LIST = ["OFF", "1:1", "1:2", "1:3", "1:4"] SCAN_MODE_LIST = ["TO", "CO", "SE"] PRIO_LIST = ["Edit", "Busy"] SHORT_KEY_LIST = ["None", "FM Radio", "Lamp", "Monitor", @@ -806,7 +805,6 @@ RTONE_LIST = ["1000 Hz", "1450 Hz", "1750 Hz", "2100 Hz"] RESUME_LIST = ["TO", "CO", "SE"] ROGERRX_LIST = ["Off"] + AB_LIST RPSTE_LIST = ["OFF"] + ["%s" % x for x in range(1, 11)] -SAVE_LIST = ["Off", "1:1", "1:2", "1:3", "1:4"] SCODE_LIST = ["%s" % x for x in range(1, 16)] SHIFTD_LIST = ["Off", "+", "-"] STEDELAY_LIST = ["OFF"] + ["%s ms" % x for x in range(100, 1100, 100)] @@ -828,7 +826,7 @@ MIC_GAIN_LIST_H8 = ['%s' % x for x in range(0, 33)] H8_LIST = ["TD-H8", "TD-H8-HAM", "TD-H8-GMRS"] H3_LIST = ["TD-H3", "TD-H3-HAM", "TD-H3-GMRS"] -GMRS_FREQS = bandplan_na.GMRS_HIRPT +GMRS_FREQS = bandplan_na.ALL_GMRS_FREQS NOAA_FREQS = [162550000, 162400000, 162475000, 162425000, 162450000, 162500000, 162525000, 161650000, 161775000, 161750000, @@ -1049,6 +1047,8 @@ class TDH8(chirp_common.CloneModeRadio): chirp_common.PowerLevel("Mid", watts=4.00), chirp_common.PowerLevel("High", watts=8.00)] _ponmsg_list = ["Full", "Message", "Icon"] + _save_list = ["Off", "1:1", "1:2", "1:3", "1:4"] + _save_shortname = "Battery Save" @classmethod def detect_from_serial(cls, pipe): @@ -1247,8 +1247,6 @@ class TDH8(chirp_common.CloneModeRadio): mem.immutable = ['freq', 'mode', 'power', 'duplex', 'offset'] elif mem.number >= 31 and mem.number <= 54: - # mem.immutable = ['duplex', 'offset'] - mem.duplex = '+' mem.offset = 5000000 elif mem.number >= 189 and mem.number <= 199: ham_freqs = NOAA_FREQS[mem.number - 189] @@ -1477,12 +1475,14 @@ class TDH8(chirp_common.CloneModeRadio): RadioSettingValueList( SYNC_LIST, current_index=_settings.sync)) + basic.append(rs) - rs = RadioSetting("save", "Battery Save", + rs = RadioSetting("save", self._save_shortname, RadioSettingValueList( - BTV_SAVER_LIST, + self._save_list, current_index=_settings.save)) + basic.append(rs) rs = RadioSetting("dbrx", "Double Rx", @@ -1519,12 +1519,20 @@ class TDH8(chirp_common.CloneModeRadio): basic.append(rs) if self.MODEL != "RT-730": - rs = RadioSetting("rogerprompt", "Roger", - RadioSettingValueBoolean(_settings.rogerprompt)) + if self.MODEL in H3_LIST: + # H3 uses roger-beep list + rs = RadioSetting("rogerprompt", "Roger", + RadioSettingValueList( + self._roger_list, + current_index=_settings.rogerprompt)) + else: + # H8 uses roger-beep bool + rs = RadioSetting("rogerprompt", "Roger", + RadioSettingValueBoolean( + _settings.rogerprompt)) basic.append(rs) rs = RadioSetting("txled", "Disp Lcd(TX)", - RadioSettingValueBoolean(_settings.txled)) basic.append(rs) @@ -2638,10 +2646,16 @@ class TDH8_GMRS(TDH8): 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.")) + if 31 <= mem.number <= 54: + if mem.freq not in GMRS_FREQS: + msgs.append(chirp_common.ValidationError( + "The frequency in channels 31-54 must be between " + "462.55000-467.71250 in 0.025 increments.")) + if mem.duplex not in ('', '+', 'off') or ( + mem.duplex == '+' and mem.offset != 5000000): + msgs.append(chirp_common.ValidationError( + "Channels in this range must be GMRS frequencies and " + "either simplex or +5MHz offset")) return msgs @@ -2668,6 +2682,9 @@ class TDH3(TDH8): _tx_power = [chirp_common.PowerLevel("Low", watts=2.00), chirp_common.PowerLevel("High", watts=5.00)] _ponmsg_list = ["Off", "Message", "Icon"] + _roger_list = ["Off", "TONE1", "TONE2"] + _save_list = ["Off", "1:1", "1:2", "1:3", "1:4", "1:8"] + _save_shortname = "Power Save" def process_mmap(self): self._memobj = bitwise.parse(MEM_FORMAT_H3, self._mmap) diff --git a/chirp/drivers/th9000.py b/chirp/drivers/th9000.py index e56de60..859e599 100644 --- a/chirp/drivers/th9000.py +++ b/chirp/drivers/th9000.py @@ -58,6 +58,12 @@ TIMEOUT_LIST = ["Off"] + ["%s min" % x for x in range(1, 30)] TXPWR_LIST = ["60W", "25W"] # maximum power for Hi setting TBSTFREQ_LIST = ["1750 Hz", "2100 Hz", "1000 Hz", "1450 Hz"] BEEP_LIST = ["Off", "On"] +VFO_LIST = ["VFO", "MEM"] +BUTTONS_LIST = ["Off", "Call", "VFO/MEM", "CTCSS/DCS", "MHz Step", "Squelch", + "Transmit Power", "Repeater Shift", "Scan", "Lock", "Monitor", + "Copy Channel", "Delete Channel", "Reverse", + "Display Brightness", "Compander", "Priority", + "DTMF Autodialer", "Show Voltage", "Clone"] MEM_FORMAT = """ #seekto 0x0000; @@ -77,7 +83,7 @@ struct { # 1 Channel Set Flag 0100 011F 20 # 2 Channel Skip Flag 0120 013F 20 # 3 Blank/Unknown 0140 01EF B0 -# 4 Unknown 01F0 01FF 10 +# 4 Button Functions 01F0 01FF 10 # 5 TX/RX Range 0200 020F 10 # 6 Bootup Passwd 0210 021F 10 # 7 Options, Radio 0220 023F 20 @@ -130,6 +136,57 @@ struct { } ropt0120; """ # TH9000 memory map +# section: 4 Programmable Buttons +# used to configure the functions of the programmable buttons +# +# bytes:bit type description +# --------------------------------------------------------------------------- +# 1 u8 btn_p3; Function for P3 press, range 0-19 +# 1 u8 btn_p4; Function for P4 press, range 0-19 +# 1 u8 btn_p5; Function for P5 press, range 0-19 +# 1 u8 btn_p1; Function for P1 press, range 0-19 +# 1 u8 btn_p2; Function for P2 press, range 0-19 +# 1 u8 btn_p3_long; Function for P3 long press, range 0-19 +# 1 u8 btn_p4_long; Function for P4 long press, range 0-19 +# 1 u8 btn_p5_long; Function for P5 long press, range 0-19 +# 1 u8 btn_p1_long; Function for P1 long press, range 0-19 +# 1 u8 btn_p2_long; Function for P2 long press, range 0-19 +# 1 u8 btn_p3_func; Function for F + P3 press, range 0-19 +# 1 u8 btn_p4_func; Function for F + P4 press, range 0-19 +# 1 u8 btn_p5_func; Function for F + P5 press, range 0-19 +# 1 u8 btn_p1_func; Function for F + P1 press, range 0-19 +# 1 u8 btn_p2_func; Function for F + P2 press, range 0-19 +# 1 u8 unknown01FF; +# +# Button Functions: +# 0=Off, 1=Call, 2=VFO/MEM, 3=CTCSS/DCS +# 4=MHz Step, 5=Squelch, 6=TX Power, 7=Repeater Shift +# 8=Scan, 9=Lock, 10=Monitor, 11=Copy CH +# 12=Delete CH, 13=Reverse, 14=Brightness, 15=Compander +# 16=Priority, 17=DTMF Dialer, 18=Show Voltage, 19=Clone +# +MEM_FORMAT = MEM_FORMAT + """ +#seekto 0x01F0; +struct { + u8 btn_p3; + u8 btn_p4; + u8 btn_p5; + u8 btn_p1; + u8 btn_p2; + u8 btn_p3_long; + u8 btn_p4_long; + u8 btn_p5_long; + u8 btn_p1_long; + u8 btn_p2_long; + u8 btn_p3_func; + u8 btn_p4_func; + u8 btn_p5_func; + u8 btn_p1_func; + u8 btn_p2_func; + u8 unknown01FF; +} buttons; +""" +# TH9000 memory map # section: 5 TX/RX Range # used to set the TX/RX range of the radio (e.g. 222-228 MHz for 220 meter) # possible to set range for tx/rx @@ -711,10 +768,13 @@ class Th9000Radio(chirp_common.CloneModeRadio, _settings = self._memobj.settings _freqrange = self._memobj.freqrange _slabel = self._memobj.slabel + _buttons = self._memobj.buttons basic = RadioSettingGroup("basic", "Global Settings") freqrange = RadioSettingGroup("freqrange", "Frequency Ranges") - top = RadioSettingGroup("top", "All Settings", basic, freqrange) + buttons = RadioSettingGroup("buttons", "Programmable Buttons") + top = RadioSettingGroup("top", "All Settings", basic, freqrange, + buttons) settings = RadioSettings(top) def _filter(name): @@ -807,6 +867,96 @@ class Th9000Radio(chirp_common.CloneModeRadio, int(_freqrange.rxrangehi) / 10)) freqrange.append(rs) + rs = RadioSetting( + "btn_p1", "P1 Short Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p1)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p2", "P2 Short Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p2)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p3", "P3 Short Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p3)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p4", "P4 Short Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p4)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p5", "P5 Short Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p5)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p1_long", "P1 Long Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p1_long)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p2_long", "P2 Long Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p2_long)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p3_long", "P3 Long Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p3_long)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p4_long", "P4 Long Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p4_long)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p5_long", "P5 Long Press", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p5_long)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p1_func", "Function + P1", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p1_func)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p2_func", "Function + P2", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p2_func)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p3_func", "Function + P3", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p3_func)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p4_func", "Function + P4", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p4_func)) + buttons.append(rs) + + rs = RadioSetting( + "btn_p5_func", "Function + P5", + RadioSettingValueList( + BUTTONS_LIST, current_index=_buttons.btn_p5_func)) + buttons.append(rs) + return settings def get_settings(self): @@ -841,6 +991,15 @@ class Th9000Radio(chirp_common.CloneModeRadio, setattr(self._memobj.slabel, name, element.value) continue + if name in ["btn_p3", "btn_p4", "btn_p5", "btn_p1", + "btn_p2", "btn_p3_long", "btn_p4_long", + "btn_p5_long", "btn_p1_long", "btn_p2_long", + "btn_p3_func", "btn_p4_func", "btn_p5_func", + "btn_p1_func", "btn_p2_func"]: + LOG.debug("setting %s = %s" % (name, element.value)) + setattr(self._memobj.buttons, name, element.value) + continue + obj = _settings setting = element.get_name() diff --git a/chirp/drivers/tk280.py b/chirp/drivers/tk280.py index 75ac12e..e798fca 100644 --- a/chirp/drivers/tk280.py +++ b/chirp/drivers/tk280.py @@ -764,8 +764,8 @@ def do_upload(radio): class TKx80SubdevMeta(type): """Metaclass for generating subdevice subclasses""" - def __new__(cls, name, parent, dct): - return super(TKx80SubdevMeta, cls).__new__(cls, name, (parent,), dct) + def __new__(cls, name, bases, dct): + return super(TKx80SubdevMeta, cls).__new__(cls, name, bases, dct) @staticmethod def make_subdev(parent_dev, child_cls, key, to_copy, **args): @@ -776,7 +776,7 @@ class TKx80SubdevMeta(type): args: Class variables to set on the new class """ return TKx80SubdevMeta('%s_%s' % (child_cls.__name__, key), - child_cls, + (child_cls, parent_dev.__class__), dict({k: getattr(parent_dev, k) for k in to_copy}, **args)) @@ -870,10 +870,11 @@ class KenwoodTKx80(chirp_common.CloneModeRadio): return rf def get_sub_devices(self): - if not self._memobj: - return [TKx80Group(self, 1)] to_copy = ('MODEL', 'TYPE', 'POWER_LEVELS', '_range', '_steps', '_freqmult') + if not self._memobj: + return [TKx80SubdevMeta.make_subdev( + self, TKx80Group, 1, to_copy)(self, 1)] return sorted([ TKx80SubdevMeta.make_subdev( self, TKx80Group, i, @@ -1652,20 +1653,20 @@ class KenwoodTKx80(chirp_common.CloneModeRadio): _mem.txfreq = mem.freq // self._freqmult step_lookup = { - 2.5: 0x0, - 6.25: 0x2, 12.5: 0x5, + 6.25: 0x2, 5.0: 0x1, + 2.5: 0x0, } try: _mem.rx_step = step_lookup[chirp_common.required_step( - int(_mem.rxfreq) * 10)] + int(_mem.rxfreq) * 10, allowed=step_lookup.keys())] except errors.InvalidDataError: LOG.warning('Unknown step for rx freq, defaulting to 5kHz') _mem.rx_step = 0x1 try: _mem.tx_step = step_lookup[chirp_common.required_step( - int(_mem.txfreq) * 10)] + int(_mem.txfreq) * 10, allowed=step_lookup.keys())] except errors.InvalidDataError: LOG.warning('Unknown step for tx freq, defaulting to 5kHz') _mem.tx_step = 0x1 @@ -1685,7 +1686,7 @@ class KenwoodTKx80(chirp_common.CloneModeRadio): _mem.power = self.POWER_LEVELS[0] -class TKx80Group(KenwoodTKx80): +class TKx80Group: def __init__(self, parent, group): self._parent = parent self._group = int(group) diff --git a/chirp/drivers/tk481.py b/chirp/drivers/tk481.py index f03cd74..b421f45 100644 --- a/chirp/drivers/tk481.py +++ b/chirp/drivers/tk481.py @@ -237,11 +237,12 @@ class TKx80_Trunked(tk280.KenwoodTKx80): return rf def get_sub_devices(self): - # For the uninitialized case of just surveying the features - if not self._memobj: - return [TKx80System(self, 1)] to_copy = ('MODEL', 'TYPE', 'POWER_LEVELS', '_range', '_steps', '_freqmult') + if not self._memobj: + # For the uninitialized case of just surveying the features + return [tk280.TKx80SubdevMeta.make_subdev( + self, TKx80System, 1, to_copy)(self, 1)] return [ tk280.TKx80SubdevMeta.make_subdev( self, TKx80System, i, @@ -366,7 +367,7 @@ class TKx80_Trunked(tk280.KenwoodTKx80): return -class TKx80System(TKx80_Trunked): +class TKx80System: def __init__(self, parent, system): self._system = system self._parent = parent @@ -375,6 +376,14 @@ class TKx80System(TKx80_Trunked): def _memobj(self): return self._parent._memobj + def get_sub_devices(self): + return [] + + def get_features(self): + rf = self._parent.get_features() + rf.has_sub_devices = False + return rf + @directory.register class TK481(TKx80_Trunked): diff --git a/chirp/drivers/tk8180.py b/chirp/drivers/tk8180.py index b439f8c..132ce50 100644 --- a/chirp/drivers/tk8180.py +++ b/chirp/drivers/tk8180.py @@ -20,6 +20,7 @@ from collections import OrderedDict from chirp import chirp_common, directory, memmap, errors, util from chirp import bitwise +from chirp.drivers import tk280 from chirp.settings import MemSetting, RadioSettingValueInvertedBoolean from chirp.settings import RadioSettingGroup, RadioSetting from chirp.settings import RadioSettingValueBoolean, RadioSettingValueList @@ -259,7 +260,7 @@ BATTWARN_SETTINGS = { # The buttons in memory are not logically arranged for display and sorting # would do weird things, so map them manually here BUTTONS = { - 'Side 1': 0, + 'Side 1 / Triangle': 0, 'Side 2': 5, 'S': 1, 'A': 2, @@ -308,6 +309,7 @@ BUTTON_FUNCTIONS = { 'Display Character': 0x1E, 'Fixed Volume': 0x20, 'Function': 0x21, + 'LCD Brightness': 0x27, 'Monitor': 0x2A, 'Monitor Momentary': 0x2B, 'Transceiver Password': 0x32, @@ -328,6 +330,7 @@ PORTABLE_BUTTON_FUNCTIONS = { } # These are only available on the mobile transceiver MOBILE_BUTTON_FUNCTIONS = { + 'Zone Down': 0x4A, # Different on mobile? } KNOB_MODE = { 'None': 0xFF, @@ -988,21 +991,24 @@ class KenwoodTKx180Radio(chirp_common.CloneModeRadio): else: raise errors.RadioError('Unsupported duplex mode %r' % mem.duplex) + step_lookup = { + 12.5: 0x6, + 10.0: 0x5, + 6.25: 0x3, + 5: 0x2, + 2.5: 0x1, + } try: - tx_step = chirp_common.required_step(int(_mem.tx_freq) * 10) + tx_step = chirp_common.required_step(int(_mem.tx_freq) * 10, + allowed=step_lookup.keys()) except errors.InvalidDataError: tx_step = 5 try: - rx_step = chirp_common.required_step(int(_mem.rx_freq) * 10) + rx_step = chirp_common.required_step(int(_mem.rx_freq) * 10, + allowed=step_lookup.keys()) except errors.InvalidDataError: rx_step = 5 - step_lookup = { - 2.5: 0x1, - 6.25: 0x3, - 12.5: 0x3, - 5: 0x2, - } # Default to 5kHz if we don't know any better _mem.rx_step = step_lookup.get(rx_step, 0x2) _mem.tx_step = step_lookup.get(tx_step, 0x2) @@ -1412,7 +1418,7 @@ class KenwoodTKx180Radio(chirp_common.CloneModeRadio): else: model_functions = PORTABLE_BUTTON_FUNCTIONS - pri_functions = model_functions | BUTTON_FUNCTIONS + pri_functions = BUTTON_FUNCTIONS | model_functions sec_functions = ( {k: v for k, v in (model_functions | BUTTON_FUNCTIONS).items() if v not in PRIMARY_ONLY}) @@ -1486,22 +1492,20 @@ class KenwoodTKx180Radio(chirp_common.CloneModeRadio): def get_sub_devices(self): zones = [] + to_copy = ('VENDOR', 'MODEL', 'VALID_BANDS', '_model') for i, _ in enumerate(self._zones): zone = getattr(self._memobj, 'zone%i' % i) - class _Zone(KenwoodTKx180RadioZone): - VENDOR = self.VENDOR - MODEL = self.MODEL - VALID_BANDS = self.VALID_BANDS - VARIANT = 'Zone %s' % ( - str(zone.zoneinfo.name).rstrip('\x00').rstrip()) - _model = self._model + zone_cls = tk280.TKx80SubdevMeta.make_subdev( + self, KenwoodTKx180RadioZone, zone, to_copy, + VARIANT='Zone %s' % ( + str(zone.zoneinfo.name).rstrip('\x00').rstrip())) - zones.append(_Zone(self, i)) + zones.append(zone_cls(self, i)) return zones -class KenwoodTKx180RadioZone(KenwoodTKx180Radio): +class KenwoodTKx180RadioZone: _zone = None def __init__(self, parent, zone=0): diff --git a/chirp/drivers/uvb5.py b/chirp/drivers/uvb5.py index bd89e1a..b212d8b 100644 --- a/chirp/drivers/uvb5.py +++ b/chirp/drivers/uvb5.py @@ -678,20 +678,23 @@ class BaofengUVB5(chirp_common.CloneModeRadio, rs.set_apply_callback(apply_limit, self._memobj.limits) basic.append(rs) - fm_preset = RadioSettingGroup("fm_preset", "FM Radio Presets") - group.append(fm_preset) - - for i in range(0, 16): - if self._memobj.fm_presets[i] < 0x01AF: - used = True - preset = self._memobj.fm_presets[i] / 10.0 + 65 - else: - used = False - preset = 65 - rs = RadioSetting("fm_presets_%1i" % i, "FM Preset %i" % (i + 1), - RadioSettingValueBoolean(used), - RadioSettingValueFloat(65, 108, preset, 0.1, 1)) - fm_preset.append(rs) + if 'fm_presets' in self._memobj: + fm_preset = RadioSettingGroup("fm_preset", "FM Radio Presets") + group.append(fm_preset) + + for i in range(0, 16): + if self._memobj.fm_presets[i] < 0x01AF: + used = True + preset = self._memobj.fm_presets[i] / 10.0 + 65 + else: + used = False + preset = 65 + rs = RadioSetting("fm_presets_%1i" % i, + "FM Preset %i" % (i + 1), + RadioSettingValueBoolean(used), + RadioSettingValueFloat(65, 108, preset, + 0.1, 1)) + fm_preset.append(rs) testmode = RadioSettingGroup("testmode", "Test Mode Settings") group.append(testmode) diff --git a/chirp/drivers/wouxun.py b/chirp/drivers/wouxun.py index 1e87d83..3d0b170 100644 --- a/chirp/drivers/wouxun.py +++ b/chirp/drivers/wouxun.py @@ -60,7 +60,7 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, MODEL = "KG-UVD1P" _model = b"KG669V" - _querymodel = (b"HiWOUXUN\x02", b"PROGUV6X\x02") + _querymodels = (b"HiWOUXUN\x02", b"PROGUV6X\x02") CHARSET = list("0123456789") + \ [chr(x + ord("A")) for x in range(0, 26)] + list("?+-") @@ -227,22 +227,11 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, "6. Click OK to upload image to device.\n") return rp - @classmethod - def _get_querymodel(cls): - if isinstance(cls._querymodel, str): - while True: - yield cls._querymodel - else: - i = 0 - while True: - yield cls._querymodel[i % len(cls._querymodel)] - i += 1 - def _identify(self): """Do the original Wouxun identification dance""" - query = self._get_querymodel() for _i in range(0, 10): - self.pipe.write(next(query)) + model = self._querymodels[_i % len(self._querymodels)] + self.pipe.write(model) resp = self.pipe.read(9) if len(resp) != 9: LOG.debug("Got:\n%s" % util.hexprint(resp)) @@ -341,6 +330,64 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, rf.can_odd_split = True return rf + @property + def transmit_time_out_setting(self): + options = ["%s" % x for x in range(15, 615, 15)] + rs = RadioSetting( + "transmit_time_out", + "TX Time-out Timer", + RadioSettingValueList( + options, + current_index=self._memobj.settings.transmit_time_out)) + return rs + + @property + def transmit_time_out_alert_setting(self): + options = ["OFF"] + ["%s" % x for x in range(1, 11)] + rs = RadioSetting( + "tx_time_out_alert", + "TX Time-out Alert", + RadioSettingValueList( + options, + current_index=self._memobj.settings.tx_time_out_alert)) + return rs + + @property + def roger_beep_setting(self): + options = ["Off", "Begin", "End", "Both"] + rs = RadioSetting( + "roger_beep", + "Roger beep select", + RadioSettingValueList( + options, + current_index=self._memobj.settings.roger_beep)) + return rs + + @property + def power_save_setting(self): + rs = RadioSetting("power_save", "Power save", + RadioSettingValueBoolean( + self._memobj.settings.power_save)) + return rs + + @property + def vox_setting(self): + options = ["OFF"] + ["%s" % x for x in range(1, 11)] + rs = RadioSetting( + "vox", + "Vox", + RadioSettingValueList( + options, + current_index=self._memobj.settings.vox)) + return rs + + @property + def beep_setting(self): + rs = RadioSetting("beep", "Beep", + RadioSettingValueBoolean( + self._memobj.settings.beep)) + return rs + def get_settings(self): freq_ranges = RadioSettingGroup("freq_ranges", "Freq Ranges") fm_preset = RadioSettingGroup("fm_preset", "FM Presets") @@ -469,10 +516,7 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, RadioSettingValueInteger( 0, 199, self._memobj.settings.priority_chan)) cfg_s.append(rs) - rs = RadioSetting("power_save", "Power save", - RadioSettingValueBoolean( - self._memobj.settings.power_save)) - cfg_s.append(rs) + cfg_s.append(self.power_save_setting) options = ["Off", "Scan", "Lamp", "SOS", "Radio"] rs = RadioSetting( "pf1_function", "PF1 Function select", @@ -480,34 +524,15 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, options, current_index=self._memobj.settings.pf1_function)) cfg_s.append(rs) - options = ["Off", "Begin", "End", "Both"] - rs = RadioSetting("roger_beep", "Roger beep select", - RadioSettingValueList( - options, - current_index=self._memobj.settings.roger_beep)) - cfg_s.append(rs) - options = ["%s" % x for x in range(15, 615, 15)] - transmit_time_out = options[self._memobj.settings.transmit_time_out] - rs = RadioSetting("transmit_time_out", "TX Time-out Timer", - RadioSettingValueList( - options, transmit_time_out)) - cfg_s.append(rs) - rs = RadioSetting("tx_time_out_alert", "TX Time-out Alert", - RadioSettingValueInteger( - 0, 10, self._memobj.settings.tx_time_out_alert)) - cfg_s.append(rs) - rs = RadioSetting("vox", "Vox", - RadioSettingValueInteger( - 0, 10, self._memobj.settings.vox)) - cfg_s.append(rs) + cfg_s.append(self.roger_beep_setting) + cfg_s.append(self.transmit_time_out_setting) + cfg_s.append(self.transmit_time_out_alert_setting) + cfg_s.append(self.vox_setting) options = ["Off", "Chinese", "English"] rs = RadioSetting("voice", "Voice", RadioSettingValueList( options, current_index=self._memobj.settings.voice)) cfg_s.append(rs) - rs = RadioSetting("beep", "Beep", - RadioSettingValueBoolean( - self._memobj.settings.beep)) - cfg_s.append(rs) + cfg_s.append(self.beep_setting) rs = RadioSetting("ani_id_enable", "ANI id enable", RadioSettingValueBoolean( self._memobj.settings.ani_id_enable)) @@ -747,17 +772,7 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, def _is_txinh(self, _mem): return _mem.tx_freq.get_raw() == b"\xFF\xFF\xFF\xFF" - def get_memory(self, number): - _mem = self._memobj.memory[number - 1] - _nam = self._memobj.names[number - 1] - - mem = chirp_common.Memory() - mem.number = number - - if _mem.get_raw() == (b"\xff" * 16): - mem.empty = True - return mem - + def _set_duplex_offset_freq(self, _mem, mem): mem.freq = int(_mem.rx_freq) * 10 if _mem.splitdup: mem.duplex = "split" @@ -775,6 +790,19 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, else: mem.offset = abs(int(_mem.tx_freq) - int(_mem.rx_freq)) * 10 + def get_memory(self, number): + _mem = self._memobj.memory[number - 1] + _nam = self._memobj.names[number - 1] + + mem = chirp_common.Memory() + mem.number = number + + if _mem.get_raw() == (b"\xff" * 16): + mem.empty = True + return mem + + self._set_duplex_offset_freq(_mem, mem) + if not _mem.skip: mem.skip = "S" if not _mem.iswide: @@ -842,6 +870,9 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, LOG.debug("Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, rx_mode, _mem.rx_tone)) + def _set_split_duplex(self, _mem, mem): + _mem.splitdup = mem.duplex == "split" + def set_memory(self, mem): _mem = self._memobj.memory[mem.number - 1] _nam = self._memobj.names[mem.number - 1] @@ -864,7 +895,8 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, _mem.tx_freq = int(mem.freq / 10) - int(mem.offset / 10) else: _mem.tx_freq = int(mem.freq / 10) - _mem.splitdup = mem.duplex == "split" + + self._set_split_duplex(_mem, mem) _mem.skip = mem.skip != "S" _mem.iswide = mem.mode != "NFM" @@ -909,7 +941,7 @@ class KGUV6DRadio(KGUVD1PRadio): """Wouxun KG-UV6 (D and X variants)""" MODEL = "KG-UV6" - _querymodel = (b"HiWXUVD1\x02", b"HiKGUVD1\x02") + _querymodels = (b"HiWXUVD1\x02", b"HiKGUVD1\x02") _MEM_FORMAT = """ #seekto 0x0010; @@ -1436,7 +1468,7 @@ class KG816Radio(KGUVD1PRadio, chirp_common.ExperimentalRadio): """Wouxun KG-816""" MODEL = "KG-816" - _querymodel = b"HiWOUXUN\x02" + _querymodels = (b"HiWOUXUN\x02", ) _MEM_FORMAT = """ #seekto 0x0010; @@ -1566,3 +1598,118 @@ class KG818Radio(KG816Radio): @classmethod def match_model(cls, filedata, filename): return False + + +@directory.register +class KG805GRadio(KGUVD1PRadio): + """Wouxun KG-805G""" + MODEL = "KG-805G" + + _querymodels = (b"HiWOUXUN\x02", ) + valid_freq = [(400000000, 470987500)] + + _MEM_FORMAT = """ + #seekto 0x0010; + struct { + lbcd rx_freq[4]; + lbcd tx_freq[4]; + ul16 rx_tone; + ul16 tx_tone; + u8 _3_unknown_1:4, + bcl:1, + _3_unknown_2:3; + u8 _2_unknown_1:1, + skip:1, + power_high:1, + iswide:1, + _2_unknown_2:4; + u8 unknown; + u8 _0_unknown_1:3, + iswidex:1, + _0_unknown_2:4; + } memory[128]; + + #seekto 0x0E20; + struct { + u8 unknown_setting_01[2]; + u8 unknown_setting_02:4, + squelch:4; + u8 unknown_setting_03:7, + power_save:1; + u8 unknown_setting_04; + u8 unknown_setting_05:6, + roger_beep:2; + u8 unknown_setting_06:2, + transmit_time_out:6; + u8 unknown_setting_07:4, + vox:4; + u8 unknown_setting_08[5]; + u8 unknown_setting_09:7, + beep:1; + u8 unknown_setting_10[8]; + u8 unknown_setting_11:4, + tx_time_out_alert:4; + u8 unknown_setting_12[9]; + u8 unknown_setting_13; + u8 unknown_setting_14:7, + auto_lock:1; + } settings; + + + #seekto 0x1010; + struct { + u8 name[6]; + u8 pad[10]; + } names[128]; + """ + + def process_mmap(self): + self._memobj = bitwise.parse(self._MEM_FORMAT, self._mmap) + # This sets our frequency ranges, so run it once after we process the + # mmap to make sure they're set for later + self.get_settings() + + def get_settings(self): + cfg_s = RadioSettingGroup("cfg_settings", "Configuration Settings") + group = RadioSettings(cfg_s) + + cfg_s.append(self.power_save_setting) + + options = ["%s" % x for x in range(0, 10)] + rs = RadioSetting( + "squelch", + "Squelch", + RadioSettingValueList( + options, + current_index=self._memobj.settings.squelch)) + cfg_s.append(rs) + + cfg_s.append(self.roger_beep_setting) + cfg_s.append(self.transmit_time_out_setting) + cfg_s.append(self.transmit_time_out_alert_setting) + cfg_s.append(self.vox_setting) + cfg_s.append(self.beep_setting) + + rs = RadioSetting("auto_lock", "Auto lock", + RadioSettingValueBoolean( + self._memobj.settings.auto_lock)) + cfg_s.append(rs) + + return group + + def _set_duplex_offset_freq(self, _mem, mem): + if self._is_txinh(_mem): + # TX freq not set + mem.duplex = "off" + mem.offset = 0 + mem.freq = int(_mem.rx_freq) * 10 + else: + chirp_common.split_to_offset( + mem, int(_mem.rx_freq) * 10, int(_mem.tx_freq) * 10) + + def _set_split_duplex(self, _mem, mem): + pass + + @classmethod + def match_model(cls, filedata, filename): + return False diff --git a/chirp/drivers/yaesu_clone.py b/chirp/drivers/yaesu_clone.py index b719a14..c434ed0 100644 --- a/chirp/drivers/yaesu_clone.py +++ b/chirp/drivers/yaesu_clone.py @@ -148,14 +148,12 @@ def __clone_out(radio): for block in radio._block_lengths: blocks += 1 if blocks != len(radio._block_lengths): + LOG.debug("Sending %i-%i" % (pos, pos+block)) pipe.write(mmap[pos:pos+block]) - echo = pipe.read(block) - if len(echo) != block: - LOG.error('Expected %i bytes of echo, got %i', block, - len(echo)) buf = pipe.read(1) - if not buf or buf[0] != CMD_ACK: - LOG.error('Expected ack but got %r', buf) + if buf and buf[0] != CMD_ACK: + buf = pipe.read(block) + if not buf or buf[-1] != CMD_ACK: raise Exception("Radio did not ack block %i" % blocks) else: _chunk_write(pipe, mmap[pos:], diff --git a/chirp/errors.py b/chirp/errors.py index 0d9d85b..a2dc82f 100644 --- a/chirp/errors.py +++ b/chirp/errors.py @@ -18,6 +18,7 @@ import enum class Reasons(enum.Enum): NO_CONNECTION_K1 = "No response from radio. Check connector and cabling!" + FIXED_BANKS = "This radio has fixed banks and does not allow reassignment" class InvalidDataError(Exception): @@ -73,3 +74,8 @@ class SpecificRadioError(RadioError): class RadioNoContactLikelyK1(SpecificRadioError): """A radio that uses a K1 connector likely to have fitment issues.""" CODE = Reasons.NO_CONNECTION_K1 + + +class RadioFixedBanks(SpecificRadioError): + """A radio that has fixed banks and cannot be changed.""" + CODE = Reasons.FIXED_BANKS diff --git a/chirp/import_logic.py b/chirp/import_logic.py index 51704c5..6455690 100644 --- a/chirp/import_logic.py +++ b/chirp/import_logic.py @@ -71,7 +71,7 @@ def ensure_has_calls(radio, memory): def _import_freq(dst_radio, _srcrf, mem): dst_bands = dst_radio.get_features().valid_bands - if not any(lo < mem.freq <= hi for (lo, hi) in dst_bands): + if not any(lo <= mem.freq <= hi for (lo, hi) in dst_bands): raise DestNotCompatible( _('Frequency %s is out of supported range') % ( chirp_common.format_freq(mem.freq))) diff --git a/chirp/locale/bg_BG/LC_MESSAGES/CHIRP.mo b/chirp/locale/bg_BG/LC_MESSAGES/CHIRP.mo Binary files differindex 3369823..c0511d9 100644 --- a/chirp/locale/bg_BG/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/bg_BG/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 379edd6..be359ff 100644 --- a/chirp/locale/es/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/es/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 348cc55..58f1bb1 100644 --- a/chirp/locale/it/LC_MESSAGES/CHIRP.mo +++ b/chirp/locale/it/LC_MESSAGES/CHIRP.mo diff --git a/chirp/locale/ro_RO/LC_MESSAGES/CHIRP.mo b/chirp/locale/ro_RO/LC_MESSAGES/CHIRP.mo Binary files differnew file mode 100644 index 0000000..57288bf --- /dev/null +++ b/chirp/locale/ro_RO/LC_MESSAGES/CHIRP.mo diff --git a/chirp/share/welcome_screen_ro_RO.png b/chirp/share/welcome_screen_ro_RO.png Binary files differnew file mode 100644 index 0000000..c953a9c --- /dev/null +++ b/chirp/share/welcome_screen_ro_RO.png diff --git a/chirp/sources/repeaterbook.py b/chirp/sources/repeaterbook.py index 879388a..0260cb2 100644 --- a/chirp/sources/repeaterbook.py +++ b/chirp/sources/repeaterbook.py @@ -184,8 +184,11 @@ class RepeaterBook(base.NetworkResultRadio): LOG.debug('Loading %i cached entries from %s for proximity search', d['count'], os.path.basename(fn)) - def item_to_memory(self, item): - if item.get('D-Star') == 'Yes': + def item_to_memory(self, item, fmconv): + should_dstar = ( + item.get('D-Star') == 'Yes' and not ( + item.get('FM Analog') == 'Yes' and fmconv)) + if should_dstar: m = chirp_common.DVMemory() m.dv_urcall = 'CQCQCQ'.ljust(8) m.dv_rpt1call = item.get('Callsign')[:8].ljust(8) @@ -304,7 +307,7 @@ class RepeaterBook(base.NetworkResultRadio): if not included_band(item): continue try: - m = self.item_to_memory(item) + m = self.item_to_memory(item, fmconv) except Exception as e: LOG.warning('Unable to convert repeater %s: %s', item['Rptr ID'], e) diff --git a/chirp/stock_configs/US MURS Channels.csv b/chirp/stock_configs/US MURS Channels.csv index e6fed17..9830fb8 100644 --- a/chirp/stock_configs/US MURS Channels.csv +++ b/chirp/stock_configs/US MURS Channels.csv @@ -1,6 +1,6 @@ -Location,Name,Frequency,Duplex,Offset,Tone,rToneFreq,cToneFreq,DtcsCode,DtcsPolarity,Mode,TStep,Skip,Comment,URCALL,RPT1CALL,RPT2CALL
-1,MURS 1,151.820000,,0.000000,,88.5,88.5,023,NN,NFM,5.00,,,,,
-2,MURS 2,151.880000,,0.000000,,88.5,88.5,023,NN,NFM,5.00,,,,,
-3,MURS 3,151.940000,,0.000000,,88.5,88.5,023,NN,NFM,5.00,,,,,
-4,Blue Dot,154.570000,,0.000000,,88.5,88.5,023,NN,FM,5.00,,,,,
-5,Green Dot,154.600000,,0.000000,,88.5,88.5,023,NN,FM,5.00,,,,,
+Location,Name,Frequency,Duplex,Offset,Tone,rToneFreq,cToneFreq,DtcsCode,DtcsPolarity,RxDtcsCode,CrossMode,Mode,TStep,Skip,Power,Comment,URCALL,RPT1CALL,RPT2CALL,DVCODE
+1,MURS 1,151.820000,,0.000000,,88.5,88.5,023,NN,023,Tone->Tone,NFM,5.00,,2.0W,,,,,
+2,MURS 2,151.880000,,0.000000,,88.5,88.5,023,NN,023,Tone->Tone,NFM,5.00,,2.0W,,,,,
+3,MURS 3,151.940000,,0.000000,,88.5,88.5,023,NN,023,Tone->Tone,NFM,5.00,,2.0W,,,,,
+4,Blue Dot,154.570000,,0.000000,,88.5,88.5,023,NN,023,Tone->Tone,FM,5.00,,2.0W,,,,,
+5,Green Dot,154.600000,,0.000000,,88.5,88.5,023,NN,023,Tone->Tone,FM,5.00,,2.0W,,,,,
diff --git a/chirp/wxui/clone.py b/chirp/wxui/clone.py index 21af53e..2e58ed2 100644 --- a/chirp/wxui/clone.py +++ b/chirp/wxui/clone.py @@ -178,6 +178,7 @@ def open_serial(port, rclass): class ChirpRadioPromptDialog(wx.Dialog): def __init__(self, *a, **k): self.radio = k.pop('radio') + self.rconfig = config.get_for_radio(self.radio) self.prompt = k.pop('prompt') buttons = k.pop('buttons', wx.OK | wx.CANCEL) super().__init__(*a, **k) @@ -208,12 +209,19 @@ class ChirpRadioPromptDialog(wx.Dialog): self.Centre() def persist_flag(self, radio, flag): - key = '%s_%s' % (flag, directory.radio_class_id(radio)) - CONF.set_bool(key.lower(), not self.cb.IsChecked(), 'clone_prompts') + key = 'prompt_%s' % flag.lower() + self.rconfig.set_bool(key, not self.cb.IsChecked()) + oldkey = '%s_%s' % (flag, directory.radio_class_id(radio)) + if CONF.is_defined(oldkey, 'clone_prompts'): + CONF.remove_option(oldkey, 'clone_prompts') def check_flag(self, radio, flag): - key = '%s_%s' % (flag, directory.radio_class_id(radio)) - return CONF.get_bool(key.lower(), 'clone_prompts', True) + key = 'prompt_%s' % flag.lower() + if not self.rconfig.is_defined(key): + # FIXME: Remove this compatibility at some point + oldkey = '%s_%s' % (flag, directory.radio_class_id(radio)) + return CONF.get_bool(oldkey.lower(), 'clone_prompts', True) + return self.rconfig.get_bool(key, default=True) def ShowModal(self): if not self.message: @@ -224,7 +232,7 @@ class ChirpRadioPromptDialog(wx.Dialog): return wx.ID_OK LOG.debug('Showing %s prompt' % self.prompt) status = super().ShowModal() - if status == wx.ID_OK: + if status in (wx.ID_OK, wx.ID_YES): LOG.debug('Setting flag for prompt %s' % self.prompt) self.persist_flag(self.radio, self.prompt) else: @@ -639,20 +647,23 @@ class ChirpCloneDialog(wx.Dialog): def _select_port_for_model(self): vendor = self._vendor.GetStringSelection() model = self._model.GetStringSelection() - modelstr = '%s:%s' % (vendor, model) - last_port = CONF.get(modelstr, 'port_recall') + + rclass = self.get_selected_rclass() + rconfig = config.get_for_radio(rclass) + last_port = rconfig.get('last_port') if last_port and self.set_selected_port(last_port): - LOG.debug('Automatically chose port %s as it is last-used for %s', - last_port, modelstr) + LOG.debug('Automatically chose last-used port %s for %s %s', + last_port, vendor, model) else: - LOG.debug('No recent/available port for %s', modelstr) + LOG.debug('No recent/available port for %s %s', vendor, model) def _remember_port_for_selected(self): - modelstr = '%s:%s' % (self._vendor.GetStringSelection(), - self._model.GetStringSelection()) + rclass = self.get_selected_rclass() + rconfig = config.get_for_radio(rclass) port = self.get_selected_port() - CONF.set(modelstr, port, 'port_recall') - LOG.debug('Recorded last-used port %s for %s', port, modelstr) + rconfig.set('last_port', port) + LOG.debug('Recorded last-used port %s for %s %s', + port, rclass.VENDOR, rclass.MODEL) def _status(self, status): def _safe_status(): @@ -667,28 +678,10 @@ class ChirpCloneDialog(wx.Dialog): wx.CallAfter(self.EndModal, wx.ID_OK) def fail(self, error): - if isinstance(error, errors.SpecificRadioError): - link = error.get_link() - message = str(error) - else: - link = None - message = str(error) - def safe_fail(): - if link: - buttons = wx.YES_NO | wx.NO_DEFAULT - else: - buttons = wx.OK - d = wx.MessageDialog(self, message, - _('Error communicating with radio'), - wx.ICON_ERROR | buttons) - if link: - d.SetYesNoLabels(_('More Info'), wx.ID_OK) - r = d.ShowModal() - if r == wx.ID_YES: - webbrowser.open(link) - - self.cancel_action() + common.error_proof.show_error( + error, parent=self, + title=_('Error communicating with radio')) wx.CallAfter(safe_fail) def cancel_action(self): @@ -729,6 +722,8 @@ class ChirpDownloadDialog(ChirpCloneDialog): if (CONF.get_bool('always_start_recent', 'state') and CONF.get('recent_models', 'state')): self._do_recent() + # Clean up old-style port recall + CONF.remove_section('port_recall') def _selected_model(self, event): super(ChirpDownloadDialog, self)._selected_model(event) diff --git a/chirp/wxui/common.py b/chirp/wxui/common.py index 8c94221..a66d0de 100644 --- a/chirp/wxui/common.py +++ b/chirp/wxui/common.py @@ -23,6 +23,7 @@ import platform import shutil import tempfile import threading +import webbrowser import wx @@ -163,10 +164,15 @@ class EditorMenuItem(wx.MenuItem): self.SetAccel(accel) -class EditorMenuItemToggle(EditorMenuItem): +class EditorMenuItemToggleStateless(EditorMenuItem): + def __init__(self, cls, callback_name, *a, **k): + k['kind'] = wx.ITEM_CHECK + super().__init__(cls, callback_name, *a, **k) + + +class EditorMenuItemToggle(EditorMenuItemToggleStateless): """An EditorMenuItem that manages boolean/check state in CONF""" def __init__(self, cls, callback_name, conf_tuple, *a, **k): - k['kind'] = wx.ITEM_CHECK super().__init__(cls, callback_name, *a, **k) self._conf_key, self._conf_section = conf_tuple @@ -608,54 +614,44 @@ class ChirpSettingGrid(wx.Panel): prop.SetModifiedStatus(False) -def _error_proof(*expected_errors): - """Decorate a method and display an error if it raises. - - If the method raises something in expected_errors, then - log an error, otherwise log exception. - """ - - def show_error(msg): - d = wx.MessageDialog(None, str(msg), _('An error has occurred'), - style=wx.OK | wx.ICON_ERROR) - d.ShowModal() - - def wrap(fn): - @functools.wraps(fn) - def inner(*args, **kwargs): - try: - return fn(*args, **kwargs) - except expected_errors as e: - LOG.error('%s: %s' % (fn, e)) - show_error(e) - except Exception as e: - LOG.exception('%s raised unexpected exception' % fn) - show_error(e) - - return inner - return wrap - - class error_proof(object): - def __init__(self, *expected_exceptions): + def __init__(self, *expected_exceptions, title=None): self._expected = expected_exceptions self.fn = None + self.title = title @staticmethod - def show_error(msg): - d = wx.MessageDialog(None, str(msg), _('An error has occurred'), - style=wx.OK | wx.ICON_ERROR) - d.ShowModal() + def show_error(error, parent=None, title=None): + title = title or _('An error has occurred') + + if isinstance(error, errors.SpecificRadioError): + link = error.get_link() + message = str(error) + else: + link = None + message = str(error) + + if link: + buttons = wx.YES_NO | wx.NO_DEFAULT + else: + buttons = wx.OK + d = wx.MessageDialog(parent, message, title, + wx.ICON_ERROR | buttons) + if link: + d.SetYesNoLabels(_('More Info'), wx.ID_OK) + r = d.ShowModal() + if r == wx.ID_YES: + webbrowser.open(link) def run_safe(self, fn, args, kwargs): try: return fn(*args, **kwargs) except self._expected as e: LOG.error('%s: %s' % (fn, e)) - self.show_error(e) + self.show_error(e, title=self.title) except Exception as e: LOG.exception('%s raised unexpected exception' % fn) - self.show_error(e) + self.show_error(e, title=self.title) def __call__(self, fn): self.fn = fn @@ -764,20 +760,57 @@ class MultiErrorDialog(wx.Dialog): @contextlib.contextmanager -def expose_logs(level, root, label, maxlen=128, parent=None): +def expose_logs(level, root, label, maxlen=128, parent=None, + show_on_raise=True): if not isinstance(root, tuple): root = (root,) + error = None + mgrs = (logger.log_history(level, x) for x in root) with contextlib.ExitStack() as stack: histories = [stack.enter_context(m) for m in mgrs] try: yield + except Exception as e: + LOG.warning('Failure while capturing logs (showing=%s): %s', + show_on_raise, e) + error = e finally: lines = list(itertools.chain.from_iterable(x.get_history() for x in histories)) - if lines: + if lines and (show_on_raise or not error): + LOG.warning('Showing %i lines of logs', len(lines)) d = MultiErrorDialog(parent) d.SetTitle(label) d.set_errors(lines) d.ShowModal() + else: + LOG.warning('Not showing %i lines of logs (error=%s,show=%s)', + len(lines), bool(error), show_on_raise) + if error: + raise error + + +def mems_from_clipboard(string, maxlen=128, parent=None): + label = _('Paste external memories') + radio = generic_csv.TSVRadio(None) + radio.clear() + # Try to load the whole thing as a full TSV with header row + try: + with expose_logs(logging.WARNING, 'chirp.drivers', label, + parent=parent, show_on_raise=False): + radio.load_from(string) + return [x for x in radio.get_memories() if not x.empty] + except errors.InvalidDataError: + LOG.debug('No header information found in TSV paste') + except RuntimeError: + pass + + # If we got no memories, try prefixing the default header row and repeat + header = generic_csv.TSVRadio.SEPCHAR.join(chirp_common.Memory.CSV_FORMAT) + string = os.linesep.join([header, string]) + with expose_logs(logging.WARNING, 'chirp.drivers', label, parent=parent): + radio.load_from(string) + + return [x for x in radio.get_memories() if not x.empty] diff --git a/chirp/wxui/config.py b/chirp/wxui/config.py index 0da3a12..73948ab 100644 --- a/chirp/wxui/config.py +++ b/chirp/wxui/config.py @@ -17,6 +17,7 @@ import base64 import binascii import logging +from chirp import directory from chirp import platform from configparser import ConfigParser import os @@ -71,12 +72,19 @@ class ChirpConfig: if not self.__config.items(section): self.__config.remove_section(section) + def remove_section(self, section): + return self.__config.remove_section(section) + class ChirpConfigProxy: def __init__(self, config, section="global"): self._config = config self._section = section + @property + def section(self): + return self._section + def get(self, key, section=None, raw=False): return self._config.get(key, section or self._section, raw=raw) @@ -161,8 +169,11 @@ class ChirpConfigProxy: def is_defined(self, key, section=None): return self._config.is_defined(key, section or self._section) - def remove_option(self, key, section): - self._config.remove_option(section, key) + def remove_option(self, key, section=None): + self._config.remove_option(section or self._section, key) + + def remove_section(self, section=None): + return self._config.remove_section(section or self._section) _CONFIG = None @@ -177,3 +188,22 @@ def get(section="global"): _CONFIG = ChirpConfig(p.config_dir()) return ChirpConfigProxy(_CONFIG, section) + + +def get_for_radio(radio): + if isinstance(radio, type): + rclass = radio + else: + rclass = radio.__class__ + try: + registered_id = directory.registered_class(rclass) + except KeyError: + # Network sources and any other special cases where a radio is not + # registered. Try to get a driver id if possible, otherwise combine + # into a single config blob + try: + registered_id = directory.radio_class_id(rclass) + except Exception: + LOG.warning('Unable to get radio-specific config for %s', rclass) + registered_id = 'other' + return get(section='radio_%s' % registered_id) diff --git a/chirp/wxui/developer.py b/chirp/wxui/developer.py index f9aa1b3..31c4889 100644 --- a/chirp/wxui/developer.py +++ b/chirp/wxui/developer.py @@ -396,9 +396,6 @@ class ChirpBrowserPanel(wx.lib.scrolledpanel.ScrolledPanel): editor = ChirpStringEditor(self, obj) elif isinstance(obj[0], bitwise.bcdDataElement): editor = ChirpBCDEditor(self, obj) - elif (isinstance(obj[0], bitwise.intDataElement) and - not isinstance(obj[0], bitwise.bitDataElement)): - self._initialize(obj, labelfmt='%s[%%s]' % name) else: self._parent.add_sub_panel(name, obj, self) editor = ChirpEditor(self, obj) diff --git a/chirp/wxui/main.py b/chirp/wxui/main.py index f0521a7..ccc846f 100644 --- a/chirp/wxui/main.py +++ b/chirp/wxui/main.py @@ -2034,6 +2034,7 @@ GNU General Public License for more details.""" for shortname, name in plans: CONF.set_bool(shortname, shortname == selected, 'bandplan') + @common.error_proof() def _do_network_query(self, query_cls): self.enable_bugreport() d = query_cls(self, title=_('Query %s') % query_cls.NAME) diff --git a/chirp/wxui/memedit.py b/chirp/wxui/memedit.py index 4e166e7..1e6d987 100644 --- a/chirp/wxui/memedit.py +++ b/chirp/wxui/memedit.py @@ -42,6 +42,7 @@ _ = wx.GetTranslation LOG = logging.getLogger(__name__) CONF = config.get() WX_GTK = 'gtk' in wx.version().lower() +TX_WORKFLOW_ID = wx.NewId() class ChirpGridTable(wx.grid.GridStringTable): @@ -189,7 +190,7 @@ class ChirpMemoryColumn(object): @property def valid(self): - if self._name in ['freq', 'rtone']: + if self._name in ['freq', 'rtone', 'txfreq']: return True to_try = ['has_%s', 'valid_%ss', 'valid_%ses', 'valid_%s_levels'] for thing in to_try: @@ -246,8 +247,11 @@ class ChirpMemoryColumn(object): raise ValueError( _('Unable to set %s on this memory') % self._name) else: - setattr(memory, self._name, self._digest_value(memory, - input_value)) + self._set_mem_value(memory, + self._digest_value(memory, input_value)) + + def _set_mem_value(self, memory, value): + setattr(memory, self._name, value) def get_editor(self): return wx.grid.GridCellTextEditor() @@ -289,19 +293,48 @@ class ChirpFrequencyColumn(ChirpMemoryColumn): super().__init__(*a, **k) self._wants_split = set() + def value(self, memory): + if self._name == 'txfreq': + if memory.duplex == 'split': + return memory.offset + elif memory.duplex == '-': + mult = -1 + else: + mult = 1 + + return memory.freq + (memory.offset * mult) + return super().value(memory) + @property def label(self): if self._name == 'offset': return (_('Offset/\nTX Freq') if 'split' in self._features.valid_duplexes else _('Offset')) + elif self._name == 'txfreq': + return _('TX Frequency') else: return _('Frequency') def hidden_for(self, memory): - return (self._name == 'offset' and - memory.duplex in ('', 'off') and - memory.number not in self._wants_split) + if self._name == 'offset': + return (memory.duplex in ('', 'off') and + memory.number not in self._wants_split) + else: + return False + + def _set_mem_value(self, memory, value): + if self._name == 'txfreq': + if 'split' in self._features.valid_duplexes: + # Always in split mode + memory.duplex = 'split' + memory.offset = value + else: + # This radio does not support proper split, so try to fake it + chirp_common.split_to_offset(memory, + memory.freq, value) + else: + return super()._set_mem_value(memory, value) def _render_value(self, memory, value): if not value: @@ -864,6 +897,7 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): self.SetDropTarget(ChirpMemoryDropTarget(self)) self._radio = radio + self._rconfig = config.get_for_radio(radio) self._features = self._radio.get_features() # Cache of memories by *row* @@ -942,13 +976,14 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): self._dc = wx.ScreenDC() self.set_cell_attrs() - def _update_undo(self): + def _update_menu(self): + menubar = self.GetTopLevelParent().GetMenuBar() items = { wx.ID_UNDO: (_('Undo'), self._undo_queue), wx.ID_REDO: (_('Redo'), self._redo_queue), } for ident, (label, queue) in items.items(): - item = self.GetTopLevelParent().GetMenuBar().FindItemById(ident) + item = menubar.FindItemById(ident) accel = item.GetAccel() if queue: item.SetItemLabel('%s %s' % (label, queue[0].name)) @@ -958,6 +993,9 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): item.Enable(False) item.SetAccel(accel) + workflow = menubar.FindItemById(TX_WORKFLOW_ID) + workflow.Check(self._has_coldef('txfreq')) + @contextlib.contextmanager def undo_context(self, name, actiontype=MemeditUndoContext): """Record changes made to memories as a single undo item""" @@ -982,7 +1020,7 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): # After we do another thing, the items in the redo queue are no longer # valid self._redo_queue = [] - self._update_undo() + self._update_menu() def _undo(self, event): """Undo the latest change.""" @@ -994,7 +1032,7 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): self._redo_queue.insert(0, undo_item) self._redo_queue = self._redo_queue[:50] self.refresh() - self._update_undo() + self._update_menu() wx.PostEvent(self, common.EditorChanged(self.GetId())) def _redo(self, event): @@ -1006,7 +1044,7 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): undo_item.redo_changes() self._undo_queue.insert(0, undo_item) self.refresh() - self._update_undo() + self._update_menu() wx.PostEvent(self, common.EditorChanged(self.GetId())) @property @@ -1239,6 +1277,10 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): cls, '_set_hide_empty', ('hide_empty', 'memedit'), _('Hide empty memories')) + use_txfreq = common.EditorMenuItemToggleStateless( + cls, '_set_use_txfreq', + _('Use TX Frequency Workflow'), id=TX_WORKFLOW_ID) + return { common.EditorMenuItem.MENU_EDIT: [ redo, # First so Undo gets inserted at zero @@ -1250,6 +1292,7 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): common.EditorMenuItem.MENU_VIEW: [ expand_extra, hide_empty, + use_txfreq, ] } @@ -1259,6 +1302,21 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): def _set_hide_empty(self, event): self.refresh() + def _set_use_txfreq(self, event): + wx.MessageBox(_('The memory editor requires a reload in order to ' + 'change the workflow. That will happen now. Any ' + 'other open tabs will be updated the next time they ' + 'are loaded.'), + _('Reload required'), + parent=self) + + self._rconfig.set_bool( + 'use_txfreq_workflow', + not self._rconfig.get_bool('use_txfreq_workflow')) + event = common.EditorRefresh(self.GetId()) + event.SetEventObject(self) + wx.PostEvent(self, event) + def _goto(self, event): l, u = self._features.memory_bounds a = wx.GetNumberFromUser(_('Goto Memory:'), _('Number'), @@ -1291,6 +1349,16 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): valid_power_levels = self._features.valid_power_levels power_column = ChirpChoiceColumn('power', self._radio, valid_power_levels) + + if self._rconfig.get_bool('use_txfreq_workflow'): + tx_cols = [ChirpFrequencyColumn('txfreq', self._radio),] + else: + tx_cols = [ + ChirpDuplexColumn('duplex', self._radio, + valid_duplexes), + ChirpFrequencyColumn('offset', self._radio), + ] + defs = [ ChirpFrequencyColumn('freq', self._radio), ChirpMemoryColumn('name', self._radio), @@ -1302,10 +1370,8 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): ChirpDTCSColumn('dtcs', self._radio), ChirpDTCSColumn('rx_dtcs', self._radio), ChirpDTCSPolColumn('dtcs_polarity', self._radio), + *tx_cols, ChirpCrossModeColumn('cross_mode', self._radio), - ChirpDuplexColumn('duplex', self._radio, - valid_duplexes), - ChirpFrequencyColumn('offset', self._radio), ChirpChoiceColumn('mode', self._radio, valid_modes), ChirpChoiceColumn('tuning_step', self._radio, @@ -1324,6 +1390,12 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): return coldef LOG.error('No column definition for %s' % name) + def _has_coldef(self, name): + for coldef in self._col_defs: + if coldef._name == name: + return True + return False + def mem2row(self, number): if isinstance(number, str): row = self._special_rows[number] @@ -1392,10 +1464,11 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): hide_empty = CONF.get_bool('hide_empty', 'memedit', False) if memory.empty: # Reset our "wants split" flags if the memory is empty - offset_col = self._col_def_by_name('offset') - duplex_col = self._col_def_by_name('duplex') - offset_col.wants_split(memory, False) - duplex_col.wants_split(memory, False) + if self._has_coldef('duplex'): + offset_col = self._col_def_by_name('offset') + duplex_col = self._col_def_by_name('duplex') + offset_col.wants_split(memory, False) + duplex_col.wants_split(memory, False) if hide_empty: self._grid.HideRow(row) else: @@ -1413,13 +1486,18 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): self._memory_cache[row] = memory + # Build a list of coldef names that are immutable extras for this + # memory + immutable_extras = ['extra.%s' % setting.get_name() + for setting in memory.extra + if not setting.value.get_mutable()] with wx.grid.GridUpdateLocker(self._grid): self.set_row_finished(row) for col, col_def in enumerate(self._col_defs): self._grid.SetCellValue(row, col, col_def.render_value(memory)) - immutable = col_def.name in memory.immutable or ( - 'extra' in col_def.name and 'extra' in memory.immutable) + immutable = (col_def.name in memory.immutable or + col_def.name in immutable_extras) self._grid.SetReadOnly(row, col, immutable or not self.editable) if immutable: @@ -2028,14 +2106,21 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): cut_item = wx.MenuItem(menu, wx.NewId(), _('Cut')) self.Bind(wx.EVT_MENU, lambda e: self.cb_copy(cut=True), cut_item) menu.Append(cut_item) + cut_item.Enable(self.editable) copy_item = wx.MenuItem(menu, wx.NewId(), _('Copy')) self.Bind(wx.EVT_MENU, lambda e: self.cb_copy(cut=False), copy_item) menu.Append(copy_item) + copy_item = wx.MenuItem(menu, wx.NewId(), _('Copy portable')) + self.Bind(wx.EVT_MENU, lambda e: self.cb_copy( + cut=False, portable=True), copy_item) + menu.Append(copy_item) + paste_item = wx.MenuItem(menu, wx.NewId(), _('Paste')) self.Bind(wx.EVT_MENU, lambda e: self.cb_paste(), paste_item) menu.Append(paste_item) + paste_item.Enable(self.editable) delete_menu = wx.Menu() delete_menu_item = menu.AppendSubMenu(delete_menu, _('Delete')) @@ -2254,9 +2339,9 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): def selected(self): self._grid.SetFocus() - self._update_undo() + self._update_menu() - def cb_copy_getdata(self, cut=False): + def cb_copy_getdata(self, cut=False, portable=False): rows = self.get_selected_rows_safe() mems = [] for row in rows: @@ -2271,9 +2356,20 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): memdata = wx.CustomDataObject(common.CHIRP_DATA_MEMORY) data.Add(memdata) memdata.SetData(pickle.dumps(payload)) - strfmt = chirp_common.mem_to_text(mems[0]) - textdata = wx.TextDataObject(strfmt) - data.Add(textdata) + if portable: + strfmt = chirp_common.mem_to_text(mems[0]) + textdata = wx.TextDataObject(strfmt) + data.Add(textdata) + else: + try: + r = generic_csv.TSVRadio(None) + r.clear() + for m in mems: + r.set_memory(m.dupe()) + textdata = wx.TextDataObject(r.as_string()) + data.Add(textdata) + except Exception as e: + LOG.exception('Failed to get TSV format for paste: %s', e) if cut: if any('empty' in mem.immutable for mem in mems): raise errors.InvalidMemoryLocation( @@ -2289,8 +2385,8 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): return data - def cb_copy(self, cut=False): - self.cb_copy_data(self.cb_copy_getdata(cut=cut)) + def cb_copy(self, cut=False, portable=False): + self.cb_copy_data(self.cb_copy_getdata(cut=cut, portable=portable)) def memedit_import_all(self, source_radio): if self.is_sorted: @@ -2456,18 +2552,25 @@ class ChirpMemEdit(common.ChirpEditor, common.ChirpSyncEditor): self._cb_paste_memories(payload) elif wx.DF_UNICODETEXT in data.GetAllFormats(): try: - mems = [chirp_common.mem_from_text(line) - for line in data.GetText().split('\n') - if line.strip()] + if data.GetText().count('\t') > 10: + # This looks plausibly like a TSV paste from a spreadsheet + mems = common.mems_from_clipboard(data.GetText(), + parent=self) + if not mems: + raise ValueError('No channels extracted from paste') + else: + mems = [chirp_common.mem_from_text(line) + for line in data.GetText().split('\n') + if line.strip()] + # Since matching the offset is kinda iffy, set our band + # plan set the offset, if a rule exists. + for mem in mems: + if mem.duplex in ('-', '+') and not mem.offset: + self._set_memory_defaults(mem, 'offset') except Exception as e: LOG.warning('Failed to parse pasted data %r: %s' % ( data.GetText(), e)) return - # Since matching the offset is kinda iffy, set our band plan - # set the offset, if a rule exists. - for mem in mems: - if mem.duplex in ('-', '+'): - self._set_memory_defaults(mem, 'offset') LOG.debug('Generic text paste %r: %s' % ( data.GetText(), mems)) self._cb_paste_memories({'mems': mems, diff --git a/chirp/wxui/radioinfo.py b/chirp/wxui/radioinfo.py index abf99f0..db4f24c 100644 --- a/chirp/wxui/radioinfo.py +++ b/chirp/wxui/radioinfo.py @@ -59,6 +59,7 @@ class ChirpRadioInfo(common.ChirpEditor, common.ChirpSyncEditor): def _add_driver(self): pg = wx.propgrid.PropertyGrid( self, style=wx.propgrid.PG_SPLITTER_AUTO_CENTER) + pg.EnableScrolling(True, True) self._group_control.AddPage(pg, _('Driver')) try: @@ -84,6 +85,7 @@ class ChirpRadioInfo(common.ChirpEditor, common.ChirpSyncEditor): pg = wx.propgrid.PropertyGrid( self, style=wx.propgrid.PG_SPLITTER_AUTO_CENTER) + pg.EnableScrolling(True, True) self._group_control.AddPage(pg, 'Icom') attrs = dict(self._radio._icf_data) @@ -110,6 +112,7 @@ class ChirpRadioInfo(common.ChirpEditor, common.ChirpSyncEditor): pg = wx.propgrid.PropertyGrid( self, style=wx.propgrid.PG_SPLITTER_AUTO_CENTER) + pg.EnableScrolling(True, True) self._group_control.AddPage(pg, 'Image Metadata') # Don't show the icom fields which are displayed elsewhere, and # don't dump the whole mem_extra blob in here diff --git a/chirp/wxui/report.py b/chirp/wxui/report.py index 9d6534b..c42dfd4 100644 --- a/chirp/wxui/report.py +++ b/chirp/wxui/report.py @@ -81,8 +81,6 @@ def with_session(fn): @functools.wraps(fn) def wrapper(*args, **kwargs): - global DISABLED - if DISABLED: return @@ -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='20250221', + version='20250502', url='https://chirp.danplanet.com', python_requires=">=3.10,<4", install_requires=[ 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 47421f6..aaa4514 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/images/Baofeng_K6.img b/tests/images/Baofeng_K6.img Binary files differnew file mode 100644 index 0000000..3309aec --- /dev/null +++ b/tests/images/Baofeng_K6.img diff --git a/tests/images/Icom_IC-T10.img b/tests/images/Icom_IC-T10.img Binary files differnew file mode 100644 index 0000000..23abac2 --- /dev/null +++ b/tests/images/Icom_IC-T10.img diff --git a/tests/images/QYT_KT-5000.img b/tests/images/QYT_KT-5000.img Binary files differnew file mode 100644 index 0000000..2fc7b1c --- /dev/null +++ b/tests/images/QYT_KT-5000.img diff --git a/tests/images/Wouxun_KG-805G.img b/tests/images/Wouxun_KG-805G.img Binary files differnew file mode 100644 index 0000000..967bde5 --- /dev/null +++ b/tests/images/Wouxun_KG-805G.img diff --git a/tests/images/Wouxun_KG-935H.img b/tests/images/Wouxun_KG-935H.img Binary files differnew file mode 100644 index 0000000..01cfbbd --- /dev/null +++ b/tests/images/Wouxun_KG-935H.img diff --git a/tests/py3-untested-drivers.txt b/tests/py3-untested-drivers.txt index ae81485..6d8ff38 100644 --- a/tests/py3-untested-drivers.txt +++ b/tests/py3-untested-drivers.txt @@ -1,6 +1,5 @@ # These drivers have not been converted (or confirmed working) for python3 ARRL_Travel_Plus -Baofeng_K5-Plus Baojie_BJ-9900 Baojie_BJ-UV55 Boblov_X3Plus @@ -36,7 +35,6 @@ Kenwood_TS-850 Puxing_PX-2R RT_Systems_CSV Sainsonic_AP510 -TYT_TH-350 TYT_TH-7800_File TYT_TH-9800_File TYT_TH-UV3R diff --git a/tests/py3_driver_testers.txt b/tests/py3_driver_testers.txt index 2925741..53bee81 100644 --- a/tests/py3_driver_testers.txt +++ b/tests/py3_driver_testers.txt @@ -375,6 +375,7 @@ Wouxun_KG-UV9G_Pro,@mrtjr1,25-Apr-2023 Wouxun_KG-UV9K,@mrtjr1,14-Apr-2023 Wouxun_KG-935G,@mrtjr1,4-Jan-2022 Wouxun_KG-935G_Plus,@mrtjr1,7-Feb-2023 +Wouxun_KG-935H,@mrtjr1,14-Mar-2025 Yaesu_FT-1500M,@f3sty,05-Dec-2022 Yaesu_FT-2800M,#10616,05-Jun-2023 Yaesu_FT-2900R_1900R,#10274,14-Jan-2023 diff --git a/tests/test_edges.py b/tests/test_edges.py index c5c0775..92498ff 100644 --- a/tests/test_edges.py +++ b/tests/test_edges.py @@ -3,11 +3,20 @@ from unittest import mock from chirp import bitwise from chirp import chirp_common +from chirp import directory from chirp import errors from tests import base class TestCaseEdges(base.DriverTest): + def test_inherits_from_registered(self): + if self.rf.has_sub_devices: + devs = self.radio.get_sub_devices() + else: + devs = [self.radio] + for dev in devs: + directory.registered_class(dev.__class__) + def test_longname(self): m = self.get_mem() m.name = ("X" * 256) # Should be longer than any radio can handle 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 43d12a0..95787cc 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_csv.cpython-310-pytest-7.1.3.pyc b/tests/unit/__pycache__/test_csv.cpython-310-pytest-7.1.3.pyc Binary files differindex 3ba6d7a..64c8587 100644 --- a/tests/unit/__pycache__/test_csv.cpython-310-pytest-7.1.3.pyc +++ b/tests/unit/__pycache__/test_csv.cpython-310-pytest-7.1.3.pyc diff --git a/tests/unit/test_chirp_common.py b/tests/unit/test_chirp_common.py index facdbed..0edce51 100644 --- a/tests/unit/test_chirp_common.py +++ b/tests/unit/test_chirp_common.py @@ -504,7 +504,7 @@ class TestStepFunctions(base.BaseTest): 6.25: self._625, 12.5: self._125, } - allowed = [6.25, 12.5] + allowed = [12.5, 6.25] for step, freqs in list(steps.items()): for freq in freqs: # We don't support 5.0, so any of the frequencies in that @@ -520,7 +520,7 @@ class TestStepFunctions(base.BaseTest): def test_required_step_finds_suitable(self): # If we support 5.0, we should get it as the step for those self.assertEqual(5.0, chirp_common.required_step(self._005[0], - allowed=[2.5, 5.0])) + allowed=[5.0, 2.5])) # If we support 2.5 and not 5.0, then we should find 2.5 as a suitable # alternative self.assertEqual(2.5, chirp_common.required_step(self._005[0], @@ -534,7 +534,7 @@ class TestStepFunctions(base.BaseTest): def test_required_step_fail(self): self.assertRaises(errors.InvalidDataError, chirp_common.required_step, - 146520500) + 146520500, allowed=[5.0, 10.0, 12.5]) def test_fix_rounded_step_250(self): self.assertEqual(146106250, @@ -548,6 +548,10 @@ class TestStepFunctions(base.BaseTest): self.assertEqual(146118750, chirp_common.fix_rounded_step(146118000)) + def test_fix_rounded_step_no_change(self): + self.assertEqual(146520000, + chirp_common.fix_rounded_step(146520000)) + class TestImageMetadata(base.BaseTest): def test_make_metadata(self): diff --git a/tests/unit/test_csv.py b/tests/unit/test_csv.py index 60ee8cc..7974cec 100644 --- a/tests/unit/test_csv.py +++ b/tests/unit/test_csv.py @@ -28,6 +28,16 @@ CHIRP_CSV_MODERN_QUOTED_HEADER = ( 0,Nat Simplex,146.520000,,0.600000,TSQL,88.5,88.5,023,NN,023,Tone->Tone,FM,5.00,,50W,This is the national calling frequency on 2m,,,, 1,"National Simp",446.000000,-,5.000000,DTCS,88.5,88.5,023,NN,023,Tone->Tone,FM,5.00,,5.0W,This is NOT the UHF calling frequency,,,, """) # noqa +CHIRP_TSV = ( + """Location Name Frequency Duplex Offset Tone rToneFreq cToneFreq DtcsCode DtcsPolarity RxDtcsCode CrossMode Mode TStep Skip Power Comment URCALL RPT1CALL RPT2CALL DVCODE +8 Mt Scott 147.280000 + 0.600000 TSQL 88.5 167.9 023 NN 023 Tone->Tone FM 5.00 50W TayDan Emergency Step #2\t\t\t\t +9 Mt Tabor 145.390000 - 0.600000 TSQL 88.5 100.0 023 NN 023 Tone->Tone FM 5.00 50W TayDan Emergency Step #1\t\t\t\t +10 Timberline V 147.120000 + 0.600000 TSQL 103.5 100.0 023 NN 023 Tone->Tone FM 5.00 50W TayDan Emergency Step #4\t\t\t\t +11 Timberline U 444.225000 + 5.000000 TSQL 88.5 100.0 023 NN 023 Tone->Tone FM 5.00 50W K7RPT Timberline, Linked to VHF side, AC7QE-R echolink\t\t\t\t +12 GovtCamp 443.875000 + 5.000000 TSQL 88.5 103.5 023 NN 023 Tone->Tone FM 5.00 50W\t\t\t\t +13 GoatMtn 443.700000 + 5.000000 TSQL 88.5 103.5 023 NN 023 Tone->Tone FM 5.00 50W SW Corner of Clackamas, Co.\t\t\t\t +14 TyghRdge 147.260000 + 0.600000 TSQL 103.5 82.5 023 NN 023 Tone->Tone FM 5.00 50W\t\t\t\t +""") # noqa class TestCSV(unittest.TestCase): @@ -182,6 +192,7 @@ class TestCSV(unittest.TestCase): def test_escaped_string_chars(self): m = chirp_common.Memory() + m.freq = 146520000 m.number = 1 m.name = 'This is "The one"' m.comment = 'Wow, a \nMulti-line comment!' @@ -191,6 +202,7 @@ class TestCSV(unittest.TestCase): def test_unicode_comment_chars(self): m = chirp_common.Memory() + m.freq = 146520000 m.number = 1 m.name = 'This is "The one"' m.comment = b'This is b\xc9\x90d news'.decode() @@ -200,6 +212,7 @@ class TestCSV(unittest.TestCase): def test_cross_dtcs(self): m = chirp_common.Memory() + m.freq = 146520000 m.number = 1 m.tmode = 'Cross' m.cross_mode = 'DTCS->DTCS' @@ -231,3 +244,11 @@ class RTCSV(unittest.TestCase): @ddt.data('ft3d', 'ftm400', 'ftm500') def test_sample_file(self, arg): self._test_open('rtcsv_%s.csv' % arg) + + +class TestTSV(unittest.TestCase): + def test_parse_tsv(self): + radio = generic_csv.TSVRadio(None) + radio.load_from(CHIRP_TSV) + m = radio.get_memory(8) + self.assertEqual('Mt Scott', m.name) |
