From 5f4fe8ab00a12060662e5df0fc8855f0488de35d Mon Sep 17 00:00:00 2001 From: Dave Hibberd Date: Thu, 20 Aug 2026 23:11:02 +0100 Subject: New upstream version 20260814 --- PKG-INFO | 2 +- chirp.egg-info/PKG-INFO | 2 +- chirp.egg-info/SOURCES.txt | 71 +- chirp/__init__.py | 2 +- chirp/bandplan_iaru_r1.py | 33 +- chirp/bitwise.py | 176 +- chirp/bitwise_grammar.py | 6 +- chirp/checksum.py | 64 + chirp/chirp_common.py | 147 +- chirp/cli/main.py | 2 + chirp/directory.py | 15 + chirp/drivers/__init__.py | 52 +- chirp/drivers/alinco.py | 10 +- chirp/drivers/alinco_dr735t.py | 6 +- chirp/drivers/anytone.py | 12 +- chirp/drivers/anytone778uv.py | 30 +- chirp/drivers/anytone_ht.py | 16 +- chirp/drivers/anytone_iii.py | 14 +- chirp/drivers/ap510.py | 2 +- chirp/drivers/ar8200.py | 1695 +++++ chirp/drivers/baofeng_common.py | 27 +- chirp/drivers/baofeng_digital.py | 65 + chirp/drivers/baofeng_uv17.py | 2 +- chirp/drivers/baofeng_uv17Pro.py | 510 +- chirp/drivers/bf_t1.py | 6 +- chirp/drivers/bf_t8.py | 8 +- chirp/drivers/boblov_x3plus.py | 2 +- chirp/drivers/btech.py | 729 ++- chirp/drivers/ft1d.py | 421 +- chirp/drivers/ft4.py | 26 +- chirp/drivers/ft450d.py | 56 +- chirp/drivers/ft50.py | 12 +- chirp/drivers/ft60.py | 10 +- chirp/drivers/ft7100.py | 2 +- chirp/drivers/ft7800.py | 275 +- chirp/drivers/ft817.py | 6 +- chirp/drivers/ft90.py | 10 + chirp/drivers/ftlx011.py | 775 --- chirp/drivers/ftm350.py | 8 +- chirp/drivers/ga510.py | 30 +- chirp/drivers/generic_csv.py | 14 +- chirp/drivers/h777.py | 145 +- chirp/drivers/hf90.py | 6 +- chirp/drivers/hg_uv98.py | 88 +- chirp/drivers/hobbypcb.py | 2 +- chirp/drivers/ic2730.py | 26 + chirp/drivers/ic9x.py | 2 +- chirp/drivers/ic9x_ll.py | 12 +- chirp/drivers/icf.py | 45 +- chirp/drivers/icomciv.py | 8 +- chirp/drivers/icq7.py | 5 +- chirp/drivers/ict8.py | 2 +- chirp/drivers/iradio_common.py | 56 + chirp/drivers/iradio_uv_5118.py | 88 +- chirp/drivers/iradio_uv_5118plus.py | 81 +- chirp/drivers/kenwood_d7.py | 16 +- chirp/drivers/kenwood_live.py | 12 +- chirp/drivers/kg935g.py | 270 +- chirp/drivers/kguv8d.py | 111 +- chirp/drivers/kguv8dplus.py | 113 +- chirp/drivers/kguv8e.py | 116 +- chirp/drivers/kguv920pa.py | 120 +- chirp/drivers/kguv980p.py | 118 +- chirp/drivers/kguv9dplus.py | 111 +- chirp/drivers/kyd.py | 93 +- chirp/drivers/kyd_IP620.py | 93 +- chirp/drivers/leixen.py | 11 +- chirp/drivers/lt725uv.py | 37 +- chirp/drivers/mml_jc8810.py | 23 +- chirp/drivers/puxing.py | 4 +- chirp/drivers/radioddity_db40g.py | 476 ++ chirp/drivers/radioddity_gm30.py | 165 +- chirp/drivers/radioddity_r2.py | 6 +- chirp/drivers/radtel_rt490.py | 2 + chirp/drivers/radtel_rt880g.py | 2315 +++++++ chirp/drivers/radtel_rt900.py | 2429 +++++++ chirp/drivers/radtel_t18.py | 68 +- chirp/drivers/retevis_c2.py | 1349 ++++ chirp/drivers/retevis_h777v4.py | 350 +- chirp/drivers/retevis_ha1g.py | 1779 ++++++ chirp/drivers/retevis_ha2.py | 1290 ++++ chirp/drivers/retevis_ra25.py | 49 +- chirp/drivers/retevis_ra86.py | 21 +- chirp/drivers/retevis_ra87.py | 12 +- chirp/drivers/retevis_rb15.py | 38 +- chirp/drivers/retevis_rb17p.py | 2 +- chirp/drivers/retevis_rb28.py | 6 +- chirp/drivers/retevis_rt1.py | 2 +- chirp/drivers/retevis_rt21.py | 154 +- chirp/drivers/retevis_rt22.py | 143 +- chirp/drivers/retevis_rt23.py | 23 +- chirp/drivers/retevis_rt26.py | 2 +- chirp/drivers/retevis_rt76p.py | 48 +- chirp/drivers/retevis_rt87.py | 29 +- chirp/drivers/retevis_rt98.py | 58 +- chirp/drivers/tdh8.py | 436 +- chirp/drivers/tdm11.py | 921 +++ chirp/drivers/tdxone_tdq8a.py | 34 +- chirp/drivers/th7800.py | 10 +- chirp/drivers/th9000.py | 14 +- chirp/drivers/th9800.py | 861 ++- chirp/drivers/th_uv3r.py | 6 +- chirp/drivers/th_uv8000.py | 18 +- chirp/drivers/th_uv88.py | 21 +- chirp/drivers/thd72.py | 21 +- chirp/drivers/thd74.py | 21 +- chirp/drivers/thuv1f.py | 4 +- chirp/drivers/tk11.py | 2563 ++++++++ chirp/drivers/tk270.py | 10 +- chirp/drivers/tk280.py | 21 +- chirp/drivers/tk690.py | 20 +- chirp/drivers/tk760.py | 14 +- chirp/drivers/tk760g.py | 88 +- chirp/drivers/tk8102.py | 88 +- chirp/drivers/tk8160.py | 203 +- chirp/drivers/tk8180.py | 324 +- chirp/drivers/tmd710.py | 68 +- chirp/drivers/tmv71.py | 8 +- chirp/drivers/tmv71_ll.py | 19 +- chirp/drivers/ts2000.py | 1 + chirp/drivers/ts480.py | 11 +- chirp/drivers/ts590.py | 11 +- chirp/drivers/ts850.py | 4 + chirp/drivers/uv5r.py | 312 +- chirp/drivers/uvb5.py | 5 + chirp/drivers/uvk5.py | 76 +- chirp/drivers/uvk5_egzumer.py | 4 +- chirp/drivers/vgc.py | 22 +- chirp/drivers/vx1.py | 1271 ++++ chirp/drivers/vx150.py | 778 +++ chirp/drivers/vx3.py | 9 +- chirp/drivers/vx8.py | 12 +- chirp/drivers/vxa700.py | 319 - chirp/drivers/wouxun.py | 117 +- chirp/drivers/yaesu_clone.py | 41 +- chirp/errors.py | 11 + chirp/import_logic.py | 26 +- chirp/kenwood_tone.py | 251 + chirp/locale/bg_BG/LC_MESSAGES/CHIRP.mo | Bin 50740 -> 50611 bytes chirp/locale/cs/LC_MESSAGES/CHIRP.mo | Bin 0 -> 89208 bytes chirp/locale/de/LC_MESSAGES/CHIRP.mo | Bin 1798 -> 41447 bytes chirp/locale/el/LC_MESSAGES/CHIRP.mo | Bin 14848 -> 14846 bytes chirp/locale/es/LC_MESSAGES/CHIRP.mo | Bin 90737 -> 94528 bytes chirp/locale/fr/LC_MESSAGES/CHIRP.mo | Bin 92790 -> 90475 bytes chirp/locale/it/LC_MESSAGES/CHIRP.mo | Bin 90821 -> 94556 bytes chirp/locale/ja_JP/LC_MESSAGES/CHIRP.mo | Bin 15414 -> 100001 bytes chirp/locale/pl/LC_MESSAGES/CHIRP.mo | Bin 27170 -> 27168 bytes chirp/locale/pt_BR/LC_MESSAGES/CHIRP.mo | Bin 1700 -> 87696 bytes chirp/locale/ro_RO/LC_MESSAGES/CHIRP.mo | Bin 89721 -> 87412 bytes chirp/locale/ru/LC_MESSAGES/CHIRP.mo | Bin 121285 -> 118093 bytes chirp/locale/tr_TR/LC_MESSAGES/CHIRP.mo | Bin 83608 -> 90833 bytes chirp/locale/zh_CN/LC_MESSAGES/CHIRP.mo | Bin 75039 -> 72931 bytes chirp/platform.py | 45 + chirp/settings.py | 36 +- chirp/share/chirp.desktop | 1 + chirp/share/welcome_screen_de.png | Bin 0 -> 27839 bytes chirp/share/welcome_screen_pt_BR.png | Bin 0 -> 28143 bytes chirp/sources/amsats.py | 281 + chirp/sources/base.py | 2 +- chirp/sources/fips.py | 6620 ++++++++++++++++++++ chirp/sources/repeaterbook.py | 93 +- chirp/stock_configs/US Aviation Frequencies.csv | 56 +- chirp/wxui/__init__.py | 13 +- chirp/wxui/accessibility.py | 429 ++ chirp/wxui/bugreport.py | 65 +- chirp/wxui/clone.py | 5 +- chirp/wxui/common.py | 172 +- chirp/wxui/config.py | 2 +- chirp/wxui/developer.py | 18 +- chirp/wxui/fips.py | 6620 -------------------- chirp/wxui/main.py | 19 +- chirp/wxui/memedit.py | 136 +- chirp/wxui/query_sources.py | 94 + chirp/wxui/radioinfo.py | 5 + chirp/wxui/report.py | 3 + chirp/wxui/serialtrace.py | 57 + requirements.txt | 7 + setup.py | 2 +- tests/__pycache__/base.cpython-310.pyc | Bin 5375 -> 5465 bytes .../test_brute_force.cpython-310-pytest-7.1.3.pyc | Bin 6661 -> 6686 bytes .../test_clone.cpython-310-pytest-7.1.3.pyc | Bin 5451 -> 6003 bytes .../test_edges.cpython-310-pytest-7.1.3.pyc | Bin 8248 -> 8482 bytes tests/base.py | 10 + tests/driver_xfails.yaml | 36 - tests/images/Bajeton_BJ7800.img | Bin 0 -> 62433 bytes tests/images/Baofeng_BF-V12D.img | Bin 0 -> 1221 bytes tests/images/Baofeng_GM-21.img | Bin 0 -> 33841 bytes tests/images/Baofeng_MP31.img | Bin 0 -> 1577 bytes tests/images/Baofeng_UV-28Plus.img | Bin 0 -> 33845 bytes tests/images/Baofeng_UV-5G_Mini.img | Bin 0 -> 33537 bytes tests/images/Baofeng_UV-5RM_Plus.img | Bin 0 -> 33857 bytes tests/images/Icom_IC-2730E.img | Bin 0 -> 21493 bytes tests/images/Kenwood_TK-7162.img | Bin 0 -> 16573 bytes tests/images/Quansheng_TK11.img | Bin 0 -> 143529 bytes tests/images/Radioddity_DB40-G.img | Bin 0 -> 6589 bytes tests/images/Radioddity_GM-30_Plus.img | Bin 0 -> 33861 bytes tests/images/Radioddity_GM-30_Pro.img | Bin 0 -> 33861 bytes tests/images/Radioddity_GS-10B.img | Bin 0 -> 62269 bytes tests/images/Radioddity_MU-5.img | Bin 0 -> 41145 bytes tests/images/Radtel_RT-880G.img | Bin 0 -> 879789 bytes tests/images/Radtel_RT-900.img | Bin 0 -> 62249 bytes tests/images/Radtel_RT-900_BT.img | Bin 0 -> 62257 bytes tests/images/Radtel_RT-910.img | Bin 0 -> 62249 bytes tests/images/Radtel_RT-910_BT.img | Bin 0 -> 62257 bytes tests/images/Radtel_RT-920.img | Bin 0 -> 62433 bytes tests/images/Retevis_C2.img | Bin 0 -> 17593 bytes tests/images/Retevis_HA1G.img | Bin 0 -> 55545 bytes tests/images/Retevis_HA1UV.img | Bin 0 -> 55569 bytes tests/images/Retevis_HA2.img | Bin 0 -> 72265 bytes tests/images/Retevis_MA1.img | Bin 0 -> 65485 bytes tests/images/Retevis_RB626.img | Bin 969 -> 2245 bytes tests/images/Retevis_RT21H.img | Bin 0 -> 401 bytes tests/images/TIDRADIO_TD-H8-HAM_G3.img | Bin 0 -> 8393 bytes tests/images/TIDRADIO_TD-M11_16_PMR.img | Bin 0 -> 1289 bytes tests/images/TIDRADIO_TD-M11_22_FRS.img | Bin 0 -> 1289 bytes tests/images/Vertex_Standard_FTL-2011.img | Bin 589 -> 0 bytes tests/images/Vertex_Standard_VXA-700.img | Bin 4096 -> 0 bytes tests/images/Wouxun_KG-XS20G.img | Bin 0 -> 32949 bytes tests/images/Wouxun_KG-XS20G_Plus.img | Bin 0 -> 32973 bytes tests/images/Wouxun_KG-XS20H.img | Bin 0 -> 32949 bytes tests/images/Yaesu_VX-1.img | Bin 0 -> 5079 bytes tests/images/Yaesu_VX-150.img | Bin 0 -> 5538 bytes tests/test_brute_force.py | 4 +- tests/test_clone.py | 14 +- tests/test_edges.py | 4 + .../test_amsats.cpython-310-pytest-7.1.3.pyc | Bin 0 -> 3222 bytes .../test_bitwise.cpython-310-pytest-7.1.3.pyc | Bin 18843 -> 22655 bytes .../test_btech_docs.cpython-310-pytest-7.1.3.pyc | Bin 0 -> 1925 bytes .../test_checksum.cpython-310-pytest-7.1.3.pyc | Bin 0 -> 1252 bytes .../test_chirp_common.cpython-310-pytest-7.1.3.pyc | Bin 33055 -> 34551 bytes .../test_crc.cpython-310-pytest-7.1.3.pyc | Bin 0 -> 895 bytes .../test_import_logic.cpython-310-pytest-7.1.3.pyc | Bin 14847 -> 15823 bytes .../test_kenwood_tone.cpython-310-pytest-7.1.3.pyc | Bin 0 -> 60864 bytes .../test_repeaterbook.cpython-310-pytest-7.1.3.pyc | Bin 8070 -> 9294 bytes .../test_retevis_ra25.cpython-310-pytest-7.1.3.pyc | Bin 0 -> 5240 bytes .../test_serialtrace.cpython-310-pytest-7.1.3.pyc | Bin 2863 -> 5311 bytes tests/unit/test_amsats.py | 112 + tests/unit/test_bitwise.py | 114 + tests/unit/test_btech_docs.py | 26 + tests/unit/test_checksum.py | 25 + tests/unit/test_chirp_common.py | 85 +- tests/unit/test_import_logic.py | 46 +- tests/unit/test_kenwood_tone.py | 2187 +++++++ tests/unit/test_repeaterbook.py | 54 +- tests/unit/test_retevis_ra25.py | 132 + tests/unit/test_serialtrace.py | 45 + tools/check_commit.sh | 27 +- 247 files changed, 33735 insertions(+), 11022 deletions(-) create mode 100644 chirp/checksum.py create mode 100644 chirp/drivers/ar8200.py delete mode 100644 chirp/drivers/ftlx011.py create mode 100644 chirp/drivers/iradio_common.py create mode 100644 chirp/drivers/radioddity_db40g.py create mode 100644 chirp/drivers/radtel_rt880g.py create mode 100644 chirp/drivers/radtel_rt900.py create mode 100644 chirp/drivers/retevis_c2.py create mode 100644 chirp/drivers/retevis_ha1g.py create mode 100644 chirp/drivers/retevis_ha2.py create mode 100644 chirp/drivers/tdm11.py create mode 100644 chirp/drivers/tk11.py create mode 100644 chirp/drivers/vx1.py create mode 100644 chirp/drivers/vx150.py delete mode 100644 chirp/drivers/vxa700.py create mode 100644 chirp/kenwood_tone.py create mode 100644 chirp/locale/cs/LC_MESSAGES/CHIRP.mo create mode 100644 chirp/share/welcome_screen_de.png create mode 100644 chirp/share/welcome_screen_pt_BR.png create mode 100644 chirp/sources/amsats.py create mode 100644 chirp/sources/fips.py create mode 100644 chirp/wxui/accessibility.py delete mode 100644 chirp/wxui/fips.py create mode 100644 tests/images/Bajeton_BJ7800.img create mode 100644 tests/images/Baofeng_BF-V12D.img create mode 100644 tests/images/Baofeng_GM-21.img create mode 100644 tests/images/Baofeng_MP31.img create mode 100644 tests/images/Baofeng_UV-28Plus.img create mode 100644 tests/images/Baofeng_UV-5G_Mini.img create mode 100644 tests/images/Baofeng_UV-5RM_Plus.img create mode 100644 tests/images/Icom_IC-2730E.img create mode 100644 tests/images/Kenwood_TK-7162.img create mode 100644 tests/images/Quansheng_TK11.img create mode 100644 tests/images/Radioddity_DB40-G.img create mode 100644 tests/images/Radioddity_GM-30_Plus.img create mode 100644 tests/images/Radioddity_GM-30_Pro.img create mode 100644 tests/images/Radioddity_GS-10B.img create mode 100644 tests/images/Radioddity_MU-5.img create mode 100644 tests/images/Radtel_RT-880G.img create mode 100644 tests/images/Radtel_RT-900.img create mode 100644 tests/images/Radtel_RT-900_BT.img create mode 100644 tests/images/Radtel_RT-910.img create mode 100644 tests/images/Radtel_RT-910_BT.img create mode 100644 tests/images/Radtel_RT-920.img create mode 100644 tests/images/Retevis_C2.img create mode 100644 tests/images/Retevis_HA1G.img create mode 100644 tests/images/Retevis_HA1UV.img create mode 100644 tests/images/Retevis_HA2.img create mode 100644 tests/images/Retevis_MA1.img create mode 100644 tests/images/Retevis_RT21H.img create mode 100644 tests/images/TIDRADIO_TD-H8-HAM_G3.img create mode 100644 tests/images/TIDRADIO_TD-M11_16_PMR.img create mode 100644 tests/images/TIDRADIO_TD-M11_22_FRS.img delete mode 100644 tests/images/Vertex_Standard_FTL-2011.img delete mode 100644 tests/images/Vertex_Standard_VXA-700.img create mode 100644 tests/images/Wouxun_KG-XS20G.img create mode 100644 tests/images/Wouxun_KG-XS20G_Plus.img create mode 100644 tests/images/Wouxun_KG-XS20H.img create mode 100644 tests/images/Yaesu_VX-1.img create mode 100644 tests/images/Yaesu_VX-150.img create mode 100644 tests/unit/__pycache__/test_amsats.cpython-310-pytest-7.1.3.pyc create mode 100644 tests/unit/__pycache__/test_btech_docs.cpython-310-pytest-7.1.3.pyc create mode 100644 tests/unit/__pycache__/test_checksum.cpython-310-pytest-7.1.3.pyc create mode 100644 tests/unit/__pycache__/test_crc.cpython-310-pytest-7.1.3.pyc create mode 100644 tests/unit/__pycache__/test_kenwood_tone.cpython-310-pytest-7.1.3.pyc create mode 100644 tests/unit/__pycache__/test_retevis_ra25.cpython-310-pytest-7.1.3.pyc create mode 100644 tests/unit/test_amsats.py create mode 100644 tests/unit/test_btech_docs.py create mode 100644 tests/unit/test_checksum.py create mode 100644 tests/unit/test_kenwood_tone.py create mode 100644 tests/unit/test_retevis_ra25.py diff --git a/PKG-INFO b/PKG-INFO index bf281ef..61f065e 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.4 Name: chirp -Version: 20250912 +Version: 20260814 Summary: A cross-platform cross-radio programming tool Home-page: https://chirp.danplanet.com Requires-Python: >=3.10,<4 diff --git a/chirp.egg-info/PKG-INFO b/chirp.egg-info/PKG-INFO index bf281ef..61f065e 100644 --- a/chirp.egg-info/PKG-INFO +++ b/chirp.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.4 Name: chirp -Version: 20250912 +Version: 20260814 Summary: A cross-platform cross-radio programming tool Home-page: https://chirp.danplanet.com Requires-Python: >=3.10,<4 diff --git a/chirp.egg-info/SOURCES.txt b/chirp.egg-info/SOURCES.txt index 8ec7a33..bdec280 100644 --- a/chirp.egg-info/SOURCES.txt +++ b/chirp.egg-info/SOURCES.txt @@ -14,10 +14,12 @@ chirp/bandplan_iaru_r3.py chirp/bandplan_na.py chirp/bitwise.py chirp/bitwise_grammar.py +chirp/checksum.py chirp/chirp_common.py chirp/directory.py chirp/errors.py chirp/import_logic.py +chirp/kenwood_tone.py chirp/logger.py chirp/memmap.py chirp/platform.py @@ -41,6 +43,7 @@ chirp/drivers/anytone778uv.py chirp/drivers/anytone_ht.py chirp/drivers/anytone_iii.py chirp/drivers/ap510.py +chirp/drivers/ar8200.py chirp/drivers/baofeng_common.py chirp/drivers/baofeng_digital.py chirp/drivers/baofeng_uv17.py @@ -73,7 +76,6 @@ chirp/drivers/ft817.py chirp/drivers/ft818.py chirp/drivers/ft857.py chirp/drivers/ft90.py -chirp/drivers/ftlx011.py chirp/drivers/ftm3200d.py chirp/drivers/ftm350.py chirp/drivers/ftm7250d.py @@ -119,6 +121,7 @@ chirp/drivers/id51plus.py chirp/drivers/id800.py chirp/drivers/id880.py chirp/drivers/idrp.py +chirp/drivers/iradio_common.py chirp/drivers/iradio_uv_5118.py chirp/drivers/iradio_uv_5118plus.py chirp/drivers/kenwood_d7.py @@ -141,12 +144,18 @@ chirp/drivers/mml_jc8810.py chirp/drivers/mursv1.py chirp/drivers/puxing.py chirp/drivers/puxing_px888k.py +chirp/drivers/radioddity_db40g.py chirp/drivers/radioddity_gm30.py chirp/drivers/radioddity_r2.py chirp/drivers/radtel_rt490.py chirp/drivers/radtel_rt620.py +chirp/drivers/radtel_rt880g.py +chirp/drivers/radtel_rt900.py chirp/drivers/radtel_t18.py +chirp/drivers/retevis_c2.py chirp/drivers/retevis_h777v4.py +chirp/drivers/retevis_ha1g.py +chirp/drivers/retevis_ha2.py chirp/drivers/retevis_ra25.py chirp/drivers/retevis_ra86.py chirp/drivers/retevis_ra87.py @@ -163,6 +172,7 @@ chirp/drivers/retevis_rt87.py chirp/drivers/retevis_rt98.py chirp/drivers/rh5r_v2.py chirp/drivers/tdh8.py +chirp/drivers/tdm11.py chirp/drivers/tdxone_tdq8a.py chirp/drivers/template.py chirp/drivers/tg_uv2p.py @@ -178,6 +188,7 @@ chirp/drivers/th_uvf8d.py chirp/drivers/thd72.py chirp/drivers/thd74.py chirp/drivers/thuv1f.py +chirp/drivers/tk11.py chirp/drivers/tk270.py chirp/drivers/tk280.py chirp/drivers/tk3140.py @@ -203,6 +214,8 @@ chirp/drivers/uvb5.py chirp/drivers/uvk5.py chirp/drivers/uvk5_egzumer.py chirp/drivers/vgc.py +chirp/drivers/vx1.py +chirp/drivers/vx150.py chirp/drivers/vx170.py chirp/drivers/vx2.py chirp/drivers/vx3.py @@ -211,11 +224,11 @@ chirp/drivers/vx510.py chirp/drivers/vx6.py chirp/drivers/vx7.py chirp/drivers/vx8.py -chirp/drivers/vxa700.py chirp/drivers/wouxun.py chirp/drivers/wouxun_common.py chirp/drivers/yaesu_clone.py chirp/locale/bg_BG/LC_MESSAGES/CHIRP.mo +chirp/locale/cs/LC_MESSAGES/CHIRP.mo chirp/locale/de/LC_MESSAGES/CHIRP.mo chirp/locale/el/LC_MESSAGES/CHIRP.mo chirp/locale/en_US/LC_MESSAGES/CHIRP.mo @@ -242,14 +255,18 @@ chirp/share/com.chirpmyradio.CHIRP.metainfo.xml chirp/share/plus-icon.png chirp/share/welcome_screen.png chirp/share/welcome_screen_bg.png +chirp/share/welcome_screen_de.png chirp/share/welcome_screen_es.png chirp/share/welcome_screen_fr.png chirp/share/welcome_screen_it.png +chirp/share/welcome_screen_pt_BR.png chirp/share/welcome_screen_ro_RO.png chirp/share/welcome_screen_zh_CN.png chirp/sources/__init__.py +chirp/sources/amsats.py chirp/sources/base.py chirp/sources/dmrmarc.py +chirp/sources/fips.py chirp/sources/mapy73pl.py chirp/sources/przemienniki_eu.py chirp/sources/przemienniki_net.py @@ -277,13 +294,13 @@ chirp/stock_configs/US Marine VHF Channels.csv chirp/stock_configs/US NOAA Weather Alert.csv chirp/wxui/__init__.py chirp/wxui/__main__.py +chirp/wxui/accessibility.py chirp/wxui/bankedit.py chirp/wxui/bugreport.py chirp/wxui/clone.py chirp/wxui/common.py chirp/wxui/config.py chirp/wxui/developer.py -chirp/wxui/fips.py chirp/wxui/main.py chirp/wxui/memedit.py chirp/wxui/memquery.py @@ -360,6 +377,7 @@ tests/images/BTECH_UV-50X2.img tests/images/BTECH_UV-50X2_G2.img tests/images/BTECH_UV-50X3.img tests/images/BTECH_UV-5X3.img +tests/images/Bajeton_BJ7800.img tests/images/Baofeng_5RM.img tests/images/Baofeng_5RX.img tests/images/Baofeng_BF-1904.img @@ -371,16 +389,22 @@ tests/images/Baofeng_BF-T1.img tests/images/Baofeng_BF-T20.img tests/images/Baofeng_BF-T20FRS.img tests/images/Baofeng_BF-T8.img +tests/images/Baofeng_BF-V12D.img tests/images/Baofeng_F-11.img +tests/images/Baofeng_GM-21.img tests/images/Baofeng_GM-5RH.img tests/images/Baofeng_K6.img +tests/images/Baofeng_MP31.img tests/images/Baofeng_UV-13Pro.img tests/images/Baofeng_UV-17.img tests/images/Baofeng_UV-17Pro.img tests/images/Baofeng_UV-17ProGPS.img +tests/images/Baofeng_UV-28Plus.img tests/images/Baofeng_UV-3R.img +tests/images/Baofeng_UV-5G_Mini.img tests/images/Baofeng_UV-5G_Pro.img tests/images/Baofeng_UV-5R.img +tests/images/Baofeng_UV-5RM_Plus.img tests/images/Baofeng_UV-5R_Mini.img tests/images/Baofeng_UV-6R.img tests/images/Baofeng_UV-9G.img @@ -403,6 +427,7 @@ tests/images/Icom_IC-2200H.img tests/images/Icom_IC-2300H.img tests/images/Icom_IC-2720H.img tests/images/Icom_IC-2730A.img +tests/images/Icom_IC-2730E.img tests/images/Icom_IC-2820H.img tests/images/Icom_IC-E90.img tests/images/Icom_IC-F621-2.img @@ -445,6 +470,7 @@ tests/images/Kenwood_TK-3140K.img tests/images/Kenwood_TK-3180K2.img tests/images/Kenwood_TK-481.img tests/images/Kenwood_TK-7160K.img +tests/images/Kenwood_TK-7162.img tests/images/Kenwood_TK-760G.img tests/images/Kenwood_TK-8102.img tests/images/Kenwood_TK-8180.img @@ -474,12 +500,18 @@ tests/images/QYT_KT-WP12.img tests/images/QYT_KT7900D.img tests/images/QYT_KT8900D.img tests/images/Quansheng_TG-UV2+.img +tests/images/Quansheng_TK11.img tests/images/Quansheng_UV-K5.img tests/images/Quansheng_UV-K5_egzumer.img +tests/images/Radioddity_DB40-G.img tests/images/Radioddity_GA-510.img tests/images/Radioddity_GA-510_V2.img tests/images/Radioddity_GM-30.img +tests/images/Radioddity_GM-30_Plus.img +tests/images/Radioddity_GM-30_Pro.img +tests/images/Radioddity_GS-10B.img tests/images/Radioddity_GS-5B.img +tests/images/Radioddity_MU-5.img tests/images/Radioddity_R2.img tests/images/Radioddity_UV-5G.img tests/images/Radtel_RT-470.img @@ -491,10 +523,21 @@ tests/images/Radtel_RT-495.img tests/images/Radtel_RT-620.img tests/images/Radtel_RT-630.img tests/images/Radtel_RT-730.img +tests/images/Radtel_RT-880G.img +tests/images/Radtel_RT-900.img +tests/images/Radtel_RT-900_BT.img +tests/images/Radtel_RT-910.img +tests/images/Radtel_RT-910_BT.img +tests/images/Radtel_RT-920.img tests/images/Radtel_T18.img +tests/images/Retevis_C2.img tests/images/Retevis_H777H_FRS.img tests/images/Retevis_H777S.img tests/images/Retevis_H777_V4.img +tests/images/Retevis_HA1G.img +tests/images/Retevis_HA1UV.img +tests/images/Retevis_HA2.img +tests/images/Retevis_MA1.img tests/images/Retevis_P2.img tests/images/Retevis_P62.img tests/images/Retevis_RA25.img @@ -539,6 +582,7 @@ tests/images/Retevis_RT16.img tests/images/Retevis_RT19.img tests/images/Retevis_RT20.img tests/images/Retevis_RT21.img +tests/images/Retevis_RT21H.img tests/images/Retevis_RT22.img tests/images/Retevis_RT22FRS.img tests/images/Retevis_RT22S.img @@ -573,7 +617,10 @@ tests/images/TDXone_TD-Q8A.img tests/images/TIDRADIO_TD-H3.img tests/images/TIDRADIO_TD-H8-GMRS.img tests/images/TIDRADIO_TD-H8-HAM.img +tests/images/TIDRADIO_TD-H8-HAM_G3.img tests/images/TIDRADIO_TD-H8.img +tests/images/TIDRADIO_TD-M11_16_PMR.img +tests/images/TIDRADIO_TD-M11_22_FRS.img tests/images/TYT_TH-350.img tests/images/TYT_TH-7800.img tests/images/TYT_TH-9800.img @@ -586,8 +633,6 @@ tests/images/TYT_TH-UVF8D.img tests/images/TYT_TH9000_144.img tests/images/Talkpod_A36plus.img tests/images/Talkpod_A36plus_8w.img -tests/images/Vertex_Standard_FTL-2011.img -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 @@ -610,6 +655,9 @@ tests/images/Wouxun_KG-UV9G_Pro.img tests/images/Wouxun_KG-UV9K.img tests/images/Wouxun_KG-UV9PX.img tests/images/Wouxun_KG-UVD1P.img +tests/images/Wouxun_KG-XS20G.img +tests/images/Wouxun_KG-XS20G_Plus.img +tests/images/Wouxun_KG-XS20H.img tests/images/Yaesu_FT-1500M.img tests/images/Yaesu_FT-1802M.img tests/images/Yaesu_FT-1D_R.img @@ -643,6 +691,8 @@ tests/images/Yaesu_FT3D_R.img tests/images/Yaesu_FTM-3200D_R.img tests/images/Yaesu_FTM-350.img tests/images/Yaesu_FTM-7250D_R.img +tests/images/Yaesu_VX-1.img +tests/images/Yaesu_VX-150.img tests/images/Yaesu_VX-177.img tests/images/Yaesu_VX-2.img tests/images/Yaesu_VX-3.img @@ -659,9 +709,12 @@ tests/unit/rtcsv_ft3d.csv tests/unit/rtcsv_ftm400.csv tests/unit/rtcsv_ftm500.csv tests/unit/test_alinco_clone.py +tests/unit/test_amsats.py tests/unit/test_bandplan.py tests/unit/test_baofeng_fmradio.py tests/unit/test_bitwise.py +tests/unit/test_btech_docs.py +tests/unit/test_checksum.py tests/unit/test_chirp_common.py tests/unit/test_cli.py tests/unit/test_csv.py @@ -669,12 +722,14 @@ tests/unit/test_directory.py tests/unit/test_icf.py tests/unit/test_icom_clone.py tests/unit/test_import_logic.py +tests/unit/test_kenwood_tone.py tests/unit/test_kguv8d.py tests/unit/test_kguv920.py tests/unit/test_logger.py tests/unit/test_mappingmodel.py tests/unit/test_network_sources.py tests/unit/test_repeaterbook.py +tests/unit/test_retevis_ra25.py tests/unit/test_serialtrace.py tests/unit/test_settings.py tests/unit/test_th9800.py @@ -685,22 +740,28 @@ tests/unit/test_yaesu_clone.py tests/unit/__pycache__/__init__.cpython-310.pyc tests/unit/__pycache__/base.cpython-310.pyc tests/unit/__pycache__/test_alinco_clone.cpython-310-pytest-7.1.3.pyc +tests/unit/__pycache__/test_amsats.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_bandplan.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_baofeng_fmradio.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_bitwise.cpython-310-pytest-7.1.3.pyc +tests/unit/__pycache__/test_btech_docs.cpython-310-pytest-7.1.3.pyc +tests/unit/__pycache__/test_checksum.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_chirp_common.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_cli.cpython-310-pytest-7.1.3.pyc +tests/unit/__pycache__/test_crc.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_csv.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_directory.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_icf.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_icom_clone.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_import_logic.cpython-310-pytest-7.1.3.pyc +tests/unit/__pycache__/test_kenwood_tone.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_kguv8d.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_kguv920.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_logger.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_mappingmodel.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_network_sources.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_repeaterbook.cpython-310-pytest-7.1.3.pyc +tests/unit/__pycache__/test_retevis_ra25.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_serialtrace.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_settings.cpython-310-pytest-7.1.3.pyc tests/unit/__pycache__/test_th9800.cpython-310-pytest-7.1.3.pyc diff --git a/chirp/__init__.py b/chirp/__init__.py index 31b111c..91f0eb5 100644 --- a/chirp/__init__.py +++ b/chirp/__init__.py @@ -1 +1 @@ -CHIRP_VERSION = "next-20250912" +CHIRP_VERSION = "next-20260814" diff --git a/chirp/bandplan_iaru_r1.py b/chirp/bandplan_iaru_r1.py index 4aecc54..02502bf 100644 --- a/chirp/bandplan_iaru_r1.py +++ b/chirp/bandplan_iaru_r1.py @@ -143,9 +143,40 @@ BANDS_10M = ( bandplan.Band((29520000, 29700000), "Wide band", step_khz=10, mode="NFM"), ) +BANDS_6M = ( + bandplan.Band((50000000, 54000000), "6 Meter Band"), + bandplan.Band((50000000, 50300000), "SSB", mode="USB"), + bandplan.Band((50300000, 50500000), "Narrow band modes, beacons"), + bandplan.Band((50500000, 52000000), "All modes"), + bandplan.Band((50500000, 50700000), "Digital communications", mode="DV"), + bandplan.Band((50700000, 50900000), "FM/DV repeater outputs", + input_offset=+500000, mode="FM"), + bandplan.Band((52000000, 54000000), "All modes"), +) + +BANDS_4M = ( + bandplan.Band((70000000, 70500000), "4 Meter Band"), +) + +BANDS_2M = ( + bandplan.Band((144000000, 146000000), "2 Meter Band"), + bandplan.Band((144100000, 144150000), "CW", mode="CW"), + bandplan.Band((144150000, 144400000), "SSB", mode="USB"), + bandplan.Band((144975000, 145806000), "FM", mode="FM"), + bandplan.Band((144975000, 145194000), "Repeater inputs", mode="FM"), + bandplan.Band((144575000, 145793500), "Repeater outputs", mode="FM", + input_offset=-600000), + ) + +BANDS_70CM = ( + bandplan.Band((430000000, 440000000), "70 Centimeter Band"), + bandplan.Band((434594000, 434981000), "Repeater outputs", mode="FM", + input_offset=-16000000), + ) + BANDS = BANDS_2100M + BANDS_160M + BANDS_80M + BANDS_40M + BANDS_30M + \ BANDS_20M + BANDS_17M + BANDS_15M + BANDS_12M + BANDS_10M + \ - bandplan.BANDS_AIR + BANDS_6M + BANDS_4M + BANDS_2M + BANDS_70CM + bandplan.BANDS_AIR # EU Analogue/DMR PMR446 Frequencies diff --git a/chirp/bitwise.py b/chirp/bitwise.py index e595f1b..a8e69ad 100644 --- a/chirp/bitwise.py +++ b/chirp/bitwise.py @@ -41,6 +41,10 @@ # u8 foo; # u16 bar; # } baz; /* Structure with u8 and u16 */ +# union { +# u16 whole; +# bbcd digits[2]; +# }; /* Union where all elements occupy the same memory */ # # Example directives: # @@ -111,12 +115,11 @@ def string_straight_decode(string): return ''.join(chr(b) for b in string) -def format_binary(nbits, value, pad=8): - s = "" - for i in range(0, nbits): - s = "%i%s" % (value & 0x01, s) - value >>= 1 - return "%s%s" % ((pad - len(s)) * ".", s) +def format_binary(nbits, value, width=8, shift=0, padchar='.'): + padleft = width - shift + padright = width - padleft - nbits + bits = f'{value << shift:0{nbits}b}'[:nbits] + return f'{padleft * padchar}{bits}{padright * padchar}' def bits_between(start, end): @@ -147,21 +150,36 @@ def array_copy(dst, src): dst[i].set_value(src[i]) -def bcd_to_int(bcd_array): - """Convert an array of bcdDataElement like \x12\x34 - into an int like 1234""" - value = 0 - for bcd in bcd_array: - a, b = bcd.get_value() - value = (value * 100) + (a * 10) + b - return value +def bbcd_to_dec(bbcd: int, packed=True) -> int: + """Convert a BE BCD int to decimal int. Usually for getting + user-friendly value from raw data. + For packed, 0x243 (0d579) -> 243. + For unpacked, 0x020403 (0d132099) -> 243.""" + result = 0 + bit_shift = 4 if packed else 8 + dec_shift = 0 + while bbcd > 0: + result += (bbcd & 0xF) * (10**dec_shift) + bbcd >>= bit_shift + dec_shift += 1 + return result -def int_to_bcd(bcd_array, value): - """Convert an int like 1234 into bcdDataElements like "\x12\x34" """ - for i in reversed(range(0, len(bcd_array))): - bcd_array[i].set_value(value % 100) - value //= 100 + +def dec_to_bbcd(dec: int, packed=True) -> int: + """Convert a decimal int to BE BCD int. Usually to set raw data from + user-friendly value. + + For packed, 243 -> 0x243 (0d579). + For unpacked, 243 -> 0x020403 (0d132099).""" + result = 0 + bit_shift_amount = 4 if packed else 8 + bcd_shift = 0 + while dec > 0: + result += (dec % 10) << bcd_shift + dec //= 10 + bcd_shift += bit_shift_amount + return result def numeric_str_to_bcd(bcdel, string, pad='0'): @@ -288,7 +306,8 @@ class DataElement: class arrayDataElement(DataElement): def __repr__(self): if isinstance(self.__items[0], bcdDataElement): - return "%i:[(%i)]" % (len(self.__items), int(self)) + hex = self.get_raw().hex().upper() + return "%i:[0x%s (%i)]" % (len(self.__items), hex, int(self)) if isinstance(self.__items[0], charDataElement): return "%i:[(%s)]" % (len(self.__items), repr(str(self))[1:-1]) @@ -337,6 +356,8 @@ class arrayDataElement(DataElement): # for non-ASCII values. On py2 we can just coerce all of these # types to a string for compatibility. return "".join([str(x.get_value()) for x in self.__items]) + elif isinstance(self.__items[0], bcdDataElement): + return str(int(self)) else: return str(self.__items) @@ -348,8 +369,7 @@ class arrayDataElement(DataElement): else: items = reversed(self.__items) for i in items: - tens, ones = i.get_value() - val = (val * 100) + (tens * 10) + ones + val = (val * 100) + int(i) return val else: raise ValueError("Cannot coerce this to int") @@ -706,8 +726,7 @@ class bcdDataElement(DataElement): self._ignoremask = 0x00 def __int__(self): - tens, ones = self.get_value() - return (tens * 10) + ones + return bbcd_to_dec(self.get_value()) def set_bits(self, mask): self._data[self._offset] = ord(self._data[self._offset]) | int(mask) @@ -737,13 +756,17 @@ class bcdDataElement(DataElement): def set_value(self, value): preserve = self._data[self._offset][0] & self._ignoremask self._data[self._offset] = ( - int("%02i" % value, 16) & ~self._ignoremask) | preserve + dec_to_bbcd(int(value) & 0xFF) & ~self._ignoremask) | preserve def _get_value(self, data): - data = data[0] & ~self._ignoremask - a = (data & 0xF0) >> 4 - b = data & 0x0F - return (a, b) + return data[0] & ~self._ignoremask + + def __str__(self): + return str(int(self)) + + def __repr__(self): + hex = self.get_raw().hex().upper() + return f'0x{hex} ({int(self)})' class lbcdDataElement(bcdDataElement): @@ -760,8 +783,10 @@ class bitDataElement(intDataElement): _subgen = u8DataElement # Default to a byte def __repr__(self): - fmt = "0x%%0%iX (%%sb)" % (self._size * 2) - return fmt % (int(self), format_binary(self._nbits, self.get_value())) + size = self._subgen._size * 8 + hex_len = size // 4 + bits = format_binary(self._nbits, self.get_value(), size, self._shift) + return f'0x{int(self):0{hex_len}X} ({bits}b)' def get_value(self): data = self._subgen(self._data, self._offset).get_value() @@ -779,13 +804,24 @@ class bitDataElement(intDataElement): self._subgen(self._data, self._offset).set_value(value) + def get_bbcd(self) -> int: + """Get BE BCD as a user-friendly decimal. e.g. 0x243 (0d579) -> 243.""" + return bbcd_to_dec(int(self)) + + def set_bbcd(self, decimal: int): + """Set decimal as stored BE BCD. e.g. 243 -> 0x243 (0d579).""" + self.set_value(dec_to_bbcd(int(decimal))) + def size(self): return int(self._nbits) class structDataElement(DataElement): def __repr__(self): - s = "struct {" + os.linesep + return self._make_repr('struct') + + def _make_repr(self, typename): + s = typename + " {" + os.linesep for prop in self._keys: s += " %15s: %s%s" % (prop, repr(self._generators[prop]), os.linesep) @@ -887,6 +923,20 @@ class structDataElement(DataElement): yield key, self._generators[key] +class unionDataElement(structDataElement): + def __repr__(self): + return self._make_repr('union') + + def set_union_size(self, size): + # We don't know the size of the union until we have processed the first + # member, so allow this to be set after creation. + assert (size % 8 == 0) + self.__dict__['_size'] = size + + def size(self): + return self._size + + def parse_count(string): if string.startswith('0x'): return int(string, 16) @@ -1073,6 +1123,51 @@ class Processor: else: raise Exception("Internal error: What is `%s'?" % struct[0][0]) + def parse_union(self, union): + deftype = union[-1] + block = union[:-1] + union_size = 0 + tmp = self._generators + + if deftype[0] == "array": + name = deftype[1][0][1] + count = parse_count(deftype[1][1][1]) + elif deftype[0] == "symbol": + name = deftype[1] + count = 1 + + result = arrayDataElement(self._offset) + for i in range(0, count): + start_of_union_offset = self._offset + self._generators = element = unionDataElement( + self._data, + start_of_union_offset, + name=name) + for t, d in block: + self._offset = start_of_union_offset + if t not in ("definition", "struct", "union"): + raise ParseError("Not supported in union: %s" % t) + self.parse_statement(t, d) + size = self._offset - start_of_union_offset + if union_size == 0: + union_size = size + elif union_size != size: + LOG.error('Union member size mismatch parsing %s', name) + raise ParseError('Union members must be the same size ' + '(found %i, expected %i)' % (size, + union_size)) + element.set_union_size(union_size * 8) + if union_size == 0: + raise ParseError('Empty union %r is not valid' % name) + # Increment the offset only past the end of the union + self._offset = start_of_union_offset + union_size + result.append(element) + + self._generators = tmp + if count == 1: + result = result[0] + self._generators[name] = result + def assert_negative_seek(self, message): warnings.warn(message, DeprecationWarning, stacklevel=6) @@ -1097,14 +1192,19 @@ class Processor: LOG.debug("%s: %i (0x%08X)" % (value[1:-1], self._offset, self._offset)) + def parse_statement(self, type_, data): + if type_ == "struct": + self.parse_struct(data) + elif type_ == "definition": + self.parse_defn(data) + elif type_ == "directive": + self.parse_directive(data) + elif type_ == "union": + self.parse_union(data) + def parse_block(self, lang): for t, d in lang: - if t == "struct": - self.parse_struct(d) - elif t == "definition": - self.parse_defn(d) - elif t == "directive": - self.parse_directive(d) + self.parse_statement(t, d) def parse(self, lang): self._lines = {} diff --git a/chirp/bitwise_grammar.py b/chirp/bitwise_grammar.py index 934efa9..0500a64 100644 --- a/chirp/bitwise_grammar.py +++ b/chirp/bitwise_grammar.py @@ -75,7 +75,7 @@ def directive(): def _block_inner(): - return -2, [definition, struct, directive] + return -2, [definition, struct, union, directive] def _block(): @@ -94,6 +94,10 @@ def struct(): return keyword("struct"), [struct_defn, struct_decl], ";" +def union(): + return keyword("union"), _block, [array, symbol], ";" + + def _language(): return _block_inner diff --git a/chirp/checksum.py b/chirp/checksum.py new file mode 100644 index 0000000..cd4d0d6 --- /dev/null +++ b/chirp/checksum.py @@ -0,0 +1,64 @@ +# Copyright 2008 Dan Smith +# Copyright 2023 Jacek Lipkowski +# Copyright 2025 Thibaut Berg +# +# 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 . + +# This is commonly called "xmodem CRC16" +CRC_POLY_CCITT = 0x1021 +CRC_POLY_IBM_REV = 0xA001 + + +def crc16(data, poly, reverse=False): + crc = 0x0 + for byte in data: + if reverse: + crc ^= byte + else: + crc ^= (byte << 8) + for _ in range(8): + if reverse: + if crc & 0x0001: + crc = (crc >> 1) ^ poly + else: + crc >>= 1 + else: + crc = crc << 1 + if crc & 0x10000: + crc = (crc ^ poly) & 0xFFFF + return crc & 0xFFFF + + +def crc16_xmodem(data: bytes): + return crc16(data, CRC_POLY_CCITT) + + +def crc16_ibm_rev(data): + return crc16(data, CRC_POLY_IBM_REV, reverse=True) + + +def checksum_8bit(data, modulo=256): + """Calculate 8-bit checksum as sum of all bytes""" + cs = 0 + for byte in data: + cs += byte + return cs % modulo + + +def checksum_xor(data): + """Calculate checksum using XOR of all bytes""" + cs = 0 + for byte in data: + cs ^= byte + return cs & 0xFF diff --git a/chirp/chirp_common.py b/chirp/chirp_common.py index 2a7d6f7..324abdf 100644 --- a/chirp/chirp_common.py +++ b/chirp/chirp_common.py @@ -644,14 +644,17 @@ class DVMemory(Memory): self.dv_code = 0 -def FrozenMemory(source): +def FrozenMemory(source, strict=True): class _FrozenMemory(source.__class__): def __init__(self, source): self.__dict__['_frozen'] = False for k, v in source.__dict__.items(): if k == '_frozen': continue - setattr(self, k, v) + try: + setattr(self, k, v) + except ValueError: + pass self.__dict__['_frozen'] = True for i in self.extra: @@ -660,13 +663,17 @@ def FrozenMemory(source): def __setattr__(self, k, v): if self._frozen: # This should really be an error, but we have a number of - # drivers that make modifications during set_memory(). So this - # just has to be a warning for now. Later it could turn into - # a TypeError. + # drivers that make modifications during set_memory(). If we + # are not being strict, then we just log a warning. caller = inspect.getframeinfo(inspect.stack()[1][0]) LOG.warning( '%s@%i: Illegal set on attribute %s - Fix this driver!' % ( caller.filename, caller.lineno, k)) + if strict: + raise errors.FrozenMemoryError( + _('Internal driver error: Attempt to modify ' + 'frozen memory; Please report this as a bug using ' + '"Report or update a bug" in the Help menu')) super().__setattr__(k, v) def dupe(self): @@ -1067,9 +1074,32 @@ class RadioFeatures: def __getitem__(self, name): return self.__dict__[name] + @property + def concise_bands(self): + pp_range_strings = [ + format_freq(lo).rstrip('0').rstrip('.') + + '-' + + format_freq(hi).rstrip('0').rstrip('.') + + 'MHz' + for lo, hi in self.valid_bands] + return ', '.join(pp_range_strings) + def validate_memory(self, mem): """Return a list of warnings and errors that will be encountered - if trying to set @mem on the current radio""" + if trying to set @mem on the current radio. + + An Error will abort the edit, while a Warning will allow it. Both + will show a message to the user. Use Errors to reject things that + need to be. A Warning is useful to alert the user that something + will be fixed/changed/coerced by the driver and that they should + expect it to look different than what they entered. Use these + sparingly as they can be very annoying to the user if they happen + on every edit. + + NOTE: This method MAY NOT modify @mem in any way. It is not a hook + to make changes, it is for _validation_ of the memory before it is + sent to the driver's set_memory() method. + """ msgs = [] lo, hi = self.memory_bounds @@ -1138,7 +1168,9 @@ class RadioFeatures: if not valid: msg = ValidationError( ("Frequency {freq} is out " - "of supported range").format(freq=format_freq(mem.freq))) + "of supported ranges {ranges}").format( + freq=format_freq(mem.freq), + ranges=self.concise_bands)) msgs.append(msg) if self.valid_bands and \ @@ -1188,6 +1220,13 @@ class RadioFeatures: " not supported")) break + if is_airband(mem.freq): + try: + fix_rounded_step(mem.freq) + except errors.InvalidDataError as e: + msgs.append(ValidationError( + '%s: %s' % (format_freq(mem.freq), e))) + return msgs @@ -1468,6 +1507,10 @@ class DetectableInterface: extra = [] return extra + list(detected) + @classmethod + def is_detected(cls): + return getattr(cls, '_DETECTED_BY', None) is not None + @classmethod def detect_model(cls, detected_cls): detected_attr = class_detected_models_attribute(cls) @@ -1475,6 +1518,10 @@ class DetectableInterface: setattr(cls, detected_attr, []) getattr(cls, detected_attr).append(detected_cls) + @classmethod + def is_minor_variant(cls): + return getattr(cls, '_MINOR_VARIANT', False) + class CloneModeRadio(FileBackedRadio, ExternalMemoryProperties, DetectableInterface): @@ -1751,7 +1798,7 @@ def is_2_5(freq): def is_8_33(freq): """Returns True if @freq is reachable by a 8.33 kHz step""" - return (freq % 25000) in [0, 8330, 16660] + return (freq % 25000) in [8330, 8333, 16660, 16666] def is_1_0(freq): @@ -1789,11 +1836,67 @@ def required_step(freq, allowed=None): "tuning step for %s" % format_freq(freq)) +def is_airband(freq): + """Returns True if @freq is in the airband range""" + return in_range(freq, [(to_MHz(108), to_MHz(137))]) + + 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""" allowed = [12.5, 6.25] + if is_airband(freq): + # Airband can be 25kHz or 8.33kHz (25k / 3) steps + # https://en.wikipedia.org/wiki/Airband + if freq % 25000: + # This must be 8.33kHz. The goal here is to find the closest + # 8.33k-aligned channel and return that. + # In the 8.33kHz channel scheme, there are "channel names" that + # look like 5kHz-aligned frequencies within the 25kHz regular + # channels, which don't match the actual frequency being used + # (which is 8.33kHz-aligned). We need to be able to detect those + # and return the correct actual frequency, as well as allow + # matching the actual frequencies themselves. + + # The "base frequency" is the 25kHz-aligned channel frequency that + # has been divided into three 8.33kHz channels. + base = freq // 25000 * 25000 + orig = freq + + # This is a channel name if it is 5kHz-aligned and equal-or-above + # the base frequency. Adjust down for the lower channel and up for + # the upper (no adjustment for the middle one) so that the channel + # matching below will find the right closest option. + ch_index = (freq - base) / 5000 + if ch_index == 1.0: + # Lower of the three, bump down + freq -= (25000 // 3) + elif ch_index == 3.0: + # Upper of the three, bump up + freq += (25000 // 3) + elif ch_index >= 4.0 and ch_index == int(ch_index): + # This is 5kHz-aligned but not one of the three sub-channels, + # thus this is one of the gaps in the channel numbers. Refuse + # it so that it's clear to the user. + raise errors.InvalidDataError( + _('Aircraft frequencies must be aligned to 25kHz, 8.33kHz' + ', be or a valid channel')) + + # These are the three possible 8.33kHz-aligned channels within + # this 25kHz block. + channels = [base + (25000 // 3) * i for i in range(0, 3)] + + # Find the closest one to the original frequency + best = min(channels, key=lambda x: abs(x - freq)) + LOG.debug('833: Orig %s Channels %s best %s adjusted %s diffs %s ' + 'chindex %s' % ( + orig, channels, best, freq, + [x - freq for x in channels], ch_index)) + return best + else: + return freq + try: required_step(freq + 500, allowed=allowed) return freq + 500 @@ -1860,32 +1963,32 @@ def name16(name, just_upper=False): def to_GHz(val): """Convert @val in GHz to Hz""" - return val * 1000000000 + return int(val * 1000000000) def to_MHz(val): """Convert @val in MHz to Hz""" - return val * 1000000 + return int(val * 1000000) def to_kHz(val): """Convert @val in kHz to Hz""" - return val * 1000 + return int(val * 1000) def from_GHz(val): """Convert @val in Hz to GHz""" - return val // 100000000 + return val // 1000000000 def from_MHz(val): """Convert @val in Hz to MHz""" - return val // 100000 + return val // 1000000 def from_kHz(val): """Convert @val in Hz to kHz""" - return val // 100 + return val // 1000 def split_to_offset(mem, rxfreq, txfreq): @@ -2137,3 +2240,19 @@ def in_range(freq, ranges): if lo <= freq <= hi: return True return False + + +def is_split(bands, freq1, freq2): + """Check if two freqs are in the same band from a list of bands + Returns False if the two freqs are in the same band (not split) + or True if they are in separate bands (split)""" + + # determine if the two freqs are in the same band + for low, high in bands: + if freq1 >= low and freq1 <= high and \ + freq2 >= low and freq2 <= high: + # if the two freqs are on the same Band this is not a split + return False + + # if you get here is because the freq pairs are split + return True diff --git a/chirp/cli/main.py b/chirp/cli/main.py index 473ceee..9dd0d0b 100644 --- a/chirp/cli/main.py +++ b/chirp/cli/main.py @@ -24,6 +24,8 @@ import logging from chirp import logger from chirp import chirp_common, errors, directory, util +sys.modules['builtins']._ = lambda x: x # type: ignore[attr-defined] + directory.import_drivers() LOG = logging.getLogger("chirpc") diff --git a/chirp/directory.py b/chirp/directory.py index 42871aa..f7685ec 100644 --- a/chirp/directory.py +++ b/chirp/directory.py @@ -77,6 +77,8 @@ def register(cls): if not hasattr(cls, '_DETECTED_BY'): cls._DETECTED_BY = None + if not hasattr(cls, '_MINOR_VARIANT'): + cls._MINOR_VARIANT = False return cls @@ -100,6 +102,19 @@ def detected_by(manager_class): return wrapper +def minorvariant(cls): + """Mark a class as too minor to distinguish from its parent. + + Use this on registered classes that are very minor and used for + organization, but need not be exposed to the user as a separate offering. + Minor version differences of the same model, for example. + """ + assert issubclass(cls, chirp_common.CloneModeRadio) + + cls._MINOR_VARIANT = True + return cls + + DRV_TO_RADIO = {} RADIO_TO_DRV = {} AUX_FORMATS = set() diff --git a/chirp/drivers/__init__.py b/chirp/drivers/__init__.py index e6073f5..59a764a 100644 --- a/chirp/drivers/__init__.py +++ b/chirp/drivers/__init__.py @@ -23,13 +23,13 @@ from chirp.drivers import ft2d from chirp.drivers import ft60 from chirp.drivers import ft70 from chirp.drivers import ft7100 -from chirp.drivers import ft7800 +from chirp.drivers import tk760g from chirp.drivers import ft8100 from chirp.drivers import ft817 from chirp.drivers import ft818 from chirp.drivers import ft857 from chirp.drivers import ft90 -from chirp.drivers import ftlx011 +from chirp.drivers import ft7800 from chirp.drivers import ftm3200d from chirp.drivers import ftm350 from chirp.drivers import ftm7250d @@ -41,7 +41,7 @@ from chirp.drivers import gmrsv2 from chirp.drivers import h777 from chirp.drivers import hf90 from chirp.drivers import hg_uv98 -from chirp.drivers import alinco +from chirp.drivers import tk11 from chirp.drivers import bj9900 from chirp.drivers import ic2100 from chirp.drivers import hobbypcb @@ -106,7 +106,7 @@ from chirp.drivers import retevis_rt26 from chirp.drivers import retevis_rt76p from chirp.drivers import retevis_rt87 from chirp.drivers import retevis_rt98 -from chirp.drivers import __init__ +from chirp.drivers import tdh8 from chirp.drivers import bjuv55 from chirp.drivers import rh5r_v2 from chirp.drivers import tdxone_tdq8a @@ -127,7 +127,7 @@ from chirp.drivers import thuv1f from chirp.drivers import tk270 from chirp.drivers import tk3140 from chirp.drivers import tk760 -from chirp.drivers import tk760g +from chirp.drivers import alinco from chirp.drivers import tk8102 from chirp.drivers import tk8160 from chirp.drivers import tk8180 @@ -151,33 +151,43 @@ from chirp.drivers import vx510 from chirp.drivers import vx6 from chirp.drivers import vx7 from chirp.drivers import vx8 -from chirp.drivers import vxa700 +from chirp.drivers import __init__ from chirp.drivers import wouxun from chirp.drivers import wouxun_common -from chirp.drivers import kenwood_d7 +from chirp.drivers import baofeng_uv17Pro from chirp.drivers import iradio_uv_5118plus +from chirp.drivers import retevis_ha1g 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 ict10 -from chirp.drivers import radioddity_gm30 -from chirp.drivers import mml_jc8810 +from chirp.drivers import retevis_ra25 from chirp.drivers import icf520 -from chirp.drivers import tdh8 +from chirp.drivers import retevis_ra86 +from chirp.drivers import retevis_ra87 from chirp.drivers import tk280 -from chirp.drivers import baofeng_uv17 from chirp.drivers import uvk5 -from chirp.drivers import retevis_ra25 -from chirp.drivers import radtel_rt620 +from chirp.drivers import ar8200 +from chirp.drivers import baofeng_uv17 +from chirp.drivers import yaesu_clone +from chirp.drivers import tdm11 from chirp.drivers import radtel_rt490 -from chirp.drivers import baofeng_digital +from chirp.drivers import uvk5_egzumer +from chirp.drivers import radtel_rt620 +from chirp.drivers import retevis_c2 from chirp.drivers import ts790e +from chirp.drivers import retevis_ha2 from chirp.drivers import icm710 -from chirp.drivers import tk690 +from chirp.drivers import vx1 +from chirp.drivers import baofeng_digital from chirp.drivers import alinco_dr735t -from chirp.drivers import yaesu_clone +from chirp.drivers import mml_jc8810 +from chirp.drivers import tk690 +from chirp.drivers import vx150 +from chirp.drivers import radioddity_db40g +from chirp.drivers import radioddity_gm30 +from chirp.drivers import kenwood_d7 +from chirp.drivers import radtel_rt880g from chirp.drivers import retevis_h777v4 -from chirp.drivers import baofeng_uv17Pro -from chirp.drivers import retevis_ra86 -__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', 'ict10', 'radioddity_gm30', 'mml_jc8810', 'icf520', 'tdh8', 'tk280', 'baofeng_uv17', 'uvk5', 'retevis_ra25', 'radtel_rt620', 'radtel_rt490', 'baofeng_digital', 'ts790e', 'icm710', 'tk690', 'alinco_dr735t', 'yaesu_clone', 'retevis_h777v4', 'baofeng_uv17Pro', 'retevis_ra86'] +from chirp.drivers import iradio_common +from chirp.drivers import radtel_rt900 +__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', 'tk760g', 'ft8100', 'ft817', 'ft818', 'ft857', 'ft90', 'ft7800', 'ftm3200d', 'ftm350', 'ftm7250d', 'ga510', 'generic_csv', 'generic_tpe', 'gmrsuv1', 'gmrsv2', 'h777', 'hf90', 'hg_uv98', 'tk11', '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', 'tdh8', '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', 'alinco', 'tk8102', 'tk8160', 'tk8180', 'tmd710', 'tmv71', 'tmv71_ll', 'ts2000', 'ts480', 'ts590', 'ts850', 'uv5r', 'uv5x3', 'uv6r', 'uvb5', 'vgc', 'vx170', 'vx2', 'vx3', 'vx5', 'vx510', 'vx6', 'vx7', 'vx8', '__init__', 'wouxun', 'wouxun_common', 'baofeng_uv17Pro', 'iradio_uv_5118plus', 'retevis_ha1g', 'ksun_m6', 'tk481', 'ict10', 'retevis_ra25', 'icf520', 'retevis_ra86', 'retevis_ra87', 'tk280', 'uvk5', 'ar8200', 'baofeng_uv17', 'yaesu_clone', 'tdm11', 'radtel_rt490', 'uvk5_egzumer', 'radtel_rt620', 'retevis_c2', 'ts790e', 'retevis_ha2', 'icm710', 'vx1', 'baofeng_digital', 'alinco_dr735t', 'mml_jc8810', 'tk690', 'vx150', 'radioddity_db40g', 'radioddity_gm30', 'kenwood_d7', 'radtel_rt880g', 'retevis_h777v4', 'iradio_common', 'radtel_rt900'] diff --git a/chirp/drivers/alinco.py b/chirp/drivers/alinco.py index a53eaf1..02809b7 100644 --- a/chirp/drivers/alinco.py +++ b/chirp/drivers/alinco.py @@ -99,7 +99,7 @@ class AlincoStyleRadio(chirp_common.CloneModeRadio): resp = self._read(RLENGTH).strip() if len(resp) == 0: - raise errors.RadioError("No response from radio") + raise errors.RadioNoResponse() if b":" not in resp: raise errors.RadioError("Unexpected response from radio") addr, _data = resp.split(b":", 1) @@ -156,7 +156,7 @@ class AlincoStyleRadio(chirp_common.CloneModeRadio): def _upload(self, limit): if not self._identify(): - raise Exception("I can't talk to this model") + raise errors.RadioError("I can't talk to this model") for addr in range(0x100, limit, 16): time.sleep(0.1) @@ -426,7 +426,7 @@ class DR135Radio(DRx35Radio): _model = b"DR135" _memsize = 4096 - _range = [(118000000, 173000000)] + _range = [(118000000, 174000000)] @classmethod def match_model(cls, filedata, filename): @@ -541,7 +541,7 @@ class DJ175Radio(DRx35Radio): _data = self._read(34).strip() if len(_data) == 0: - raise errors.RadioError("No response from radio") + raise errors.RadioNoResponse() data = codecs.decode(_data, 'hex') @@ -649,7 +649,7 @@ class AlincoDJG7(AlincoStyleRadio): # data is encoded in hex, hence we read two chars per byte _data = self._read(2+2*64+2).strip() if len(_data) == 0: - raise errors.RadioError("No response from radio") + raise errors.RadioNoResponse() data = codecs.decode(_data, "hex") diff --git a/chirp/drivers/alinco_dr735t.py b/chirp/drivers/alinco_dr735t.py index 17351ad..2fbb1eb 100644 --- a/chirp/drivers/alinco_dr735t.py +++ b/chirp/drivers/alinco_dr735t.py @@ -128,7 +128,7 @@ class AlincoDR735T(chirp_common.CloneModeRadio): # expect DR735TN\r\n radio_id = self.pipe.read(9).strip() if not radio_id: - raise errors.RadioError("No response from radio") + raise errors.RadioNoResponse() LOG.debug('Model string is %s' % util.hexprint(radio_id)) return radio_id in (b"DR735TN", b"DR735TE") @@ -199,6 +199,8 @@ class AlincoDR735T(chirp_common.CloneModeRadio): def sync_in(self): try: self._mmap = self.do_download() + except errors.RadioError: + raise except Exception as exc: raise errors.RadioError(f"Failed to download from radio: {exc}") self.process_mmap() @@ -206,6 +208,8 @@ class AlincoDR735T(chirp_common.CloneModeRadio): def sync_out(self): try: self.do_upload() + except errors.RadioError: + raise except Exception as exc: raise errors.RadioError(f"Failed to download from radio: {exc}") diff --git a/chirp/drivers/anytone.py b/chirp/drivers/anytone.py index 8ae7a39..16021bc 100644 --- a/chirp/drivers/anytone.py +++ b/chirp/drivers/anytone.py @@ -18,6 +18,7 @@ import logging from chirp import bitwise from chirp import chirp_common +from chirp import checksum from chirp import directory from chirp import errors from chirp import memmap @@ -269,18 +270,11 @@ def _finish(radio): raise errors.RadioError("Radio did not finish cleanly") -def _checksum(data): - cs = 0 - for byte in data: - cs += byte - return cs % 256 - - def _send(radio, cmd, addr, length, data=None): frame = struct.pack(">cHb", cmd, addr, length) if data: frame += data - frame += struct.pack('BB', _checksum(frame[1:]), 0x06) + frame += struct.pack('BB', checksum.checksum_8bit(frame[1:]), 0x06) _echo_write(radio, frame) LOG.debug("Sent:\n%s" % util.hexprint(frame)) if data: @@ -304,7 +298,7 @@ def _send(radio, cmd, addr, length, data=None): LOG.debug(" Length: %02x/%02x" % (length, _length)) LOG.debug(" Addr: %04x/%04x" % (addr, _addr)) raise errors.RadioError("Radio send unexpected block") - cs = _checksum(result[1:-2]) + cs = checksum.checksum_8bit(result[1:-2]) if cs != result[-2]: LOG.debug("Calculated: %02x" % cs) LOG.debug("Actual: %02x" % result[-2]) diff --git a/chirp/drivers/anytone778uv.py b/chirp/drivers/anytone778uv.py index c09af07..56196cd 100644 --- a/chirp/drivers/anytone778uv.py +++ b/chirp/drivers/anytone778uv.py @@ -39,7 +39,7 @@ # * probably other things too - like things encoded by the unknown bits in the # memory struct -from chirp import chirp_common, directory, memmap, errors, util +from chirp import chirp_common, directory, memmap, errors, util, checksum from chirp import bitwise from chirp.settings import RadioSettingGroup, RadioSetting, \ RadioSettingValueBoolean, RadioSettingValueList, \ @@ -328,12 +328,6 @@ def get_band_limits_Hz(limit_value): # Calculate the checksum used in serial packets -def checksum(message_bytes): - mask = 0xFF - checksum = 0 - for b in message_bytes: - checksum = (checksum + b) & mask - return checksum # Send a command to the radio, return any reply stripping the echo of the @@ -404,6 +398,9 @@ def enter_program_mode(serial): # place the radio in program mode, and confirm program_response = send_serial_command(serial, b'PROGRAM') + if not program_response: + raise errors.RadioNoResponse() + if program_response != b'QX\x06': raise errors.RadioError('No initial response from radio.') LOG.debug('entered program mode') @@ -434,9 +431,13 @@ def exit_program_mode(serial): # Parse a packet from the radio returning the header (R/W, address, data, and # checksum valid def parse_read_response(resp): + if not resp: + raise errors.RadioNoResponse() + if len(resp) < 6: + raise errors.RadioError('Short read response from radio') addr = resp[:4] data = bytes(resp[4:-2]) - cs = checksum(d for d in resp[1:-2]) + cs = checksum.checksum_8bit(d for d in resp[1:-2]) valid = cs == resp[-2] if not valid: LOG.error('checksumfail: %02x, expected %02x' % (cs, resp[-2])) @@ -498,7 +499,7 @@ def do_download(radio): def make_write_data_cmd(addr, data, datalen): cmd = struct.pack('>BHB', 0x57, addr, datalen) cmd += data - cs = checksum(c for c in cmd[1:]) + cs = checksum.checksum_8bit(c for c in cmd[1:]) cmd += struct.pack('>BB', cs, 0x06) return cmd @@ -966,6 +967,7 @@ class AnyTone778UVBase(chirp_common.CloneModeRadio, _mem.name = mem.name.ljust(self.NAME_LENGTH)[:self.NAME_LENGTH] # Set duplex bitfields + _mem.tx_off = 0 if mem.duplex == '+': _mem.duplex = DUPLEX_POSSPLIT elif mem.duplex == '-': @@ -975,15 +977,13 @@ class AnyTone778UVBase(chirp_common.CloneModeRadio, elif mem.duplex == 'split': # TODO: this is an unverified punt! _mem.duplex = DUPLEX_ODDSPLIT + elif mem.duplex == 'off': + # handle tx off + _mem.tx_off = 1 else: LOG.error('%s: set_mem: unhandled duplex: %s' % (mem.name, mem.duplex)) - # handle tx off - _mem.tx_off = 0 - if mem.duplex == 'off': - _mem.tx_off = 1 - # Set the channel width - remember we promote 20 kHz channels to FM # on import # , so don't handle them here @@ -1075,7 +1075,7 @@ class AnyTone778UVBase(chirp_common.CloneModeRadio, else: LOG.error('%s: unhandled cross RX mode: %s' % ( mem.name, mem.cross_mode)) - else: + elif mem.tmode: LOG.error('%s: Unhandled tmode/cross %s/%s.' % (mem.name, mem.tmode, mem.cross_mode)) LOG.debug('%s: tmode=%s, cross=%s, rtone=%f, ctone=%f' % ( diff --git a/chirp/drivers/anytone_ht.py b/chirp/drivers/anytone_ht.py index 1775553..a3eefd6 100644 --- a/chirp/drivers/anytone_ht.py +++ b/chirp/drivers/anytone_ht.py @@ -18,6 +18,7 @@ import logging from chirp import bitwise from chirp import chirp_common +from chirp import checksum from chirp import directory from chirp import errors from chirp import memmap @@ -258,9 +259,11 @@ def _ident(radio): radio.pipe.timeout = 1 _echo_write(radio, b"PROGRAM") response = radio.pipe.read(3) + if not response: + raise errors.RadioNoResponse() if response != b"QX\x06": LOG.debug("Response was:\n%s" % util.hexprint(response)) - raise errors.RadioError("Radio did not respond. Check connection.") + raise errors.RadioError("Unexpected response from radio") _echo_write(radio, b"\x02") response = radio.pipe.read(16) LOG.debug(util.hexprint(response)) @@ -278,18 +281,11 @@ def _finish(radio): raise errors.RadioError("Radio did not finish cleanly") -def _checksum(data): - cs = 0 - for byte in data: - cs += byte - return cs % 256 - - def _send(radio, cmd, addr, length, data=None): frame = struct.pack(">cHb", cmd, addr, length) if data: frame += data - frame += bytes([_checksum(frame[1:])]) + frame += bytes([checksum.checksum_8bit(frame[1:])]) frame += b"\x06" _echo_write(radio, frame) LOG.debug("Sent:\n%s" % util.hexprint(frame)) @@ -314,7 +310,7 @@ def _send(radio, cmd, addr, length, data=None): LOG.debug(" Length: %02x/%02x" % (length, _length)) LOG.debug(" Addr: %04x/%04x" % (addr, _addr)) raise errors.RadioError("Radio send unexpected block") - cs = _checksum(result[1:-2]) + cs = checksum.checksum_8bit(result[1:-2]) if cs != result[-2]: LOG.debug("Calculated: %02x" % cs) LOG.debug("Actual: %02x" % result[-2]) diff --git a/chirp/drivers/anytone_iii.py b/chirp/drivers/anytone_iii.py index 4f33d26..d4024a6 100644 --- a/chirp/drivers/anytone_iii.py +++ b/chirp/drivers/anytone_iii.py @@ -19,6 +19,7 @@ import string from chirp import bitwise from chirp import chirp_common +from chirp import checksum from chirp import directory from chirp import errors from chirp import memmap @@ -567,18 +568,11 @@ def _finish(radio): raise errors.RadioError("Radio did not finish cleanly") -def _checksum(data): - cs = 0 - for byte in data: - cs += byte - return cs % 256 - - def _send(radio, cmd, addr, length, data=None): frame = struct.pack(">cHb", cmd, addr, length) if data: frame += data - frame += bytes([_checksum(frame[1:])]) + frame += bytes([checksum.checksum_8bit(frame[1:])]) frame += b"\x06" _echo_write(radio, frame) LOG.debug("Sent:\n%s" % util.hexprint(frame)) @@ -603,7 +597,7 @@ def _send(radio, cmd, addr, length, data=None): LOG.debug(" Length: %02x/%02x" % (length, _length)) LOG.debug(" Addr: %04x/%04x" % (addr, _addr)) raise errors.RadioError("Radio send unexpected block") - cs = _checksum(result[1:-2]) + cs = checksum.checksum_8bit(result[1:-2]) if cs != result[-2]: LOG.debug("Calculated: %02x" % cs) LOG.debug("Actual: %02x" % result[-2]) @@ -1127,7 +1121,7 @@ class AnyTone5888UVIIIRadio(chirp_common.CloneModeRadio, _mem.offset = mem.offset / 100 if is_hyper_chan: - mem.name = SEVEN_SPACES + _mem.name = SEVEN_SPACES else: _mem.name = mem.name.ljust(7) diff --git a/chirp/drivers/ap510.py b/chirp/drivers/ap510.py index 6cf9347..81dee46 100644 --- a/chirp/drivers/ap510.py +++ b/chirp/drivers/ap510.py @@ -63,7 +63,7 @@ def enter_setup(pipe): return True elif s and "SETUP" in s: return False - raise errors.RadioError('Radio did not respond.') + raise errors.RadioNoResponse() def download(radio): diff --git a/chirp/drivers/ar8200.py b/chirp/drivers/ar8200.py new file mode 100644 index 0000000..44747ff --- /dev/null +++ b/chirp/drivers/ar8200.py @@ -0,0 +1,1695 @@ +# Copyright 2026 Darius Rad +# +# 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 . + +import logging +import re +import threading +import time + +from chirp import chirp_common, errors, directory +from chirp.settings import RadioSetting, RadioSettingGroup, \ + RadioSettingSubGroup, RadioSettingValueBoolean, RadioSettingValueFloat, \ + RadioSettingValueInteger, RadioSettingValueList, RadioSettingValueMap, \ + RadioSettingValueString, RadioSettings + +LOG = logging.getLogger(__name__) + +# CHANNEL NUMBERING +# +# CHIRP identifies memories with sequentially numbered indices. The +# memory locations in the AR8200 are mapped to CHIRP memories as +# follows. +# +# Memories 0 through 999 +# +# Scan memories by bank: A, a, B, b, ... J, j. Each pair of banks +# (A and a, B and b, etc.) occupies 100 channels. The split between +# the banks in the pair is determined by the bank size configured +# under settings. +# +# Memories 1000 through 1999 +# +# Scan pass frequencies by bank: A, a, B, b, ... J, j. There are 50 +# pass frequencies per bank. +# +# Memories 2000 through 2099 +# +# VFO pass frequencies. +# +# Memories 2100 through 2139 +# +# One channel per search bank: A through T, then a through t. +# +# Special channels +# +# VFO: Single VFO mode channel configuration +# VFO-A and VFO-B: Twin VFO mode channel configuration +# QM0 through QM9: VFO quick memories + +# ISSUES AND LIMITATIONS +# +# After adjusting any of the following settings, it is necessary to +# refresh certain other memory locations: +# +# - Bank split size +# - Add or remove search pass frequencies +# - Change offset frequencies +# - Removing channels from select scan list +# +# The radio supports three AM modes, but CHIRP only knows about two. +# Mode is set to AM for all, and an extra field specifies which AM +# mode is used. +# +# Search pass frequencies cannot be modified, they can only be added +# or removed. When a pass frequency is removed, all others in the +# same search bank are moved up. +# +# This driver does not provide a bank model because (1) CHIRP does not +# support banks for live radios, and (2) the banks on the radio don't +# easily map to the bank model provided by CHIRP. +# +# Quick memory channel details beyond the frequency are not available, +# as reading this from the serial port is not supported. +# +# Adding to the select scan list is not supported over the serial +# port. +# +# Auto mode also lets the radio control duplex and offset, tuning +# step, and step adjust. +# +# Radio must be power cycled after using CHIRP. The serial protocol +# supports a command to terminate the session and release the keypad, +# but there is no suitable place in CHIRP to make this call. By the +# time the __del__ method is called, the serial port is already +# closed. +# +# Radio supports additional characters not presently reflected in the +# valid character set, including arrows, Japanese characters (yen, +# katakana), Greek letters, other European letters and accents, and +# math symbols. + + +@directory.register +class AR8200Radio(chirp_common.LiveRadio): + """AOR AR8200""" + BAUD_RATE = 19200 + VENDOR = "AOR" + MODEL = "AR8200" + + # These need to match the indices of the MD command. + _MODES = [('WFM', 0), ('FM', 1), ('AM', 2), ('USB', 3), ('LSB', 4), + ('CW', 5), ('NFM', 6), ('WAM', 7), ('NAM', 8), ('Auto', 0xf)] + + _AM_MODES = ['AM', 'WAM', 'NAM'] + + _SCAN_MEMORIES = 1000 + _SEARCH_PASS_MEMORIES = 1100 + _SCAN_BANKS = 'AaBbCcDdEeFfGgHhIiJj' + _SEARCH_BANKS = 'ABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrst' + + _SPECIAL_CHANS = { + 'VFO': -13, + 'VFO-A': -12, + 'VFO-B': -11, + 'QM0': -10, + 'QM1': -9, + 'QM2': -8, + 'QM3': -7, + 'QM4': -6, + 'QM5': -5, + 'QM6': -4, + 'QM7': -3, + 'QM8': -2, + 'QM9': -1} + + # Skip reading settings that require selecting each stored memory + # channel, which significantly slows download time. + _SKIP_SELECT = False + + _upper = _SCAN_MEMORIES + _SEARCH_PASS_MEMORIES + len(_SEARCH_BANKS) - 1 + + _scan_bank_sizes = {} + _GS = None + _OL_LIST = None + _GR_LIST = None + _command_cache = {} + + _rf = None + + def __init__(self, *args, **kwargs): + chirp_common.LiveRadio.__init__(self, *args, **kwargs) + + self._memcache = {} + self.LOCK = threading.Lock() + + if self.pipe: + self.pipe.timeout = 2 + self.pipe.stopbits = 2 + self._pipe_reset() + if not self._connect(): + raise Exception("Error connecting to radio") + + # set VFO mode because documentation says not to run MX + # command (write data) while scanning or searching + self._command('VF') + + # set squelch closed to avoid noise while changing channels + self._command('MC1') + + def get_features(self): + if self._rf: + return self._rf + + rf = chirp_common.RadioFeatures() + rf.has_dtcs = False + rf.has_dtcs_polarity = False + rf.has_bank = False + rf.has_ctone = False + rf.has_cross = False + rf.has_nostep_tuning = True + rf.has_settings = True + + rf.valid_modes = ['WFM', 'FM', 'AM', 'USB', 'LSB', 'CW', 'NFM', 'Auto'] + rf.valid_bands = [(100000, 2040000000)] + rf.valid_skips = ['', 'S'] + rf.valid_characters = chirp_common.CHARSET_ASCII + rf.valid_name_length = 12 + rf.valid_special_chans = list(self._SPECIAL_CHANS.keys()) + rf.valid_tones = [] + + rf.memory_bounds = (0, self._upper) + + self._rf = rf + return rf + + def _decode_number(self, number): + if number < -10: + if number in list(self._SPECIAL_CHANS.values()): + return ('vfo', None, number) + + return (None, None, None) + + if number < 0: + return ('qm', None, number + 10) + + if number < self._SCAN_MEMORIES: + bank = (number // 100) * 2 + chan = number % 100 + + if chan >= self._scan_bank_size(self._SCAN_BANKS[bank]): + chan = chan - self._scan_bank_size(self._SCAN_BANKS[bank]) + bank += 1 + + return ('scan', self._SCAN_BANKS[bank], chan) + + number -= self._SCAN_MEMORIES + + if number < self._SEARCH_PASS_MEMORIES: + if number > len(self._SEARCH_BANKS) * 50: + bank = 'V' + chan = number - len(self._SEARCH_BANKS) * 50 + else: + bank = self._SEARCH_BANKS[number // 50] + chan = number % 50 + return ('pass', bank, chan) + + number -= self._SEARCH_PASS_MEMORIES + + if number < len(self._SEARCH_BANKS): + return ('search', self._SEARCH_BANKS[number], None) + + return (None, None, None) + + def _encode_number(self, region, bank, chan): + + if region == 'vfo': + return self._SPECIAL_CHANS.get(chan, None) + + elif region == 'qm': + return chan - 10 if chan < 10 else None + + elif region == 'scan': + if bank not in self._SCAN_BANKS or \ + chan >= self._scan_bank_size(bank): + return None + + offset = 100 * (self._SCAN_BANKS.index(bank) // 2) + if bank.islower(): + offset += self._scan_bank_size(bank.upper()) + + return offset + chan + + elif region == 'pass': + if bank == 'V': + offset = self._SCAN_MEMORIES + len(self._SEARCH_BANKS) * 50 + size = 100 + elif bank in self._SEARCH_BANKS: + offset = self._SCAN_MEMORIES + \ + self._SEARCH_BANKS.index(bank) * 50 + size = 50 + + return offset + chan if chan < size else None + + elif region == 'search': + if bank not in self._SEARCH_BANKS: + return None + + return self._SCAN_MEMORIES + self._SEARCH_PASS_MEMORIES + \ + self._SEARCH_BANKS.index(bank) + + return None + + def _connect(self): + """Connect to the radio""" + bauds = [19200, 9600, 4800] + + for b in bauds: + self.pipe.baudrate = b + + self._command('', '[?]') + + # no real detection mechanism, to just try the VR command + res = self._command('VR', 'VR([0-9]+)') + if res: + return True + + raise errors.RadioError("No response from radio") + + def _pipe_reset(self): + self.pipe.reset_input_buffer() + self.pipe.reset_output_buffer() + self.pipe.write('\r'.encode('ascii')) + self.pipe.readline() + + def _command(self, cmd, pattern='$', lines=1, cache=False, + varlist=False, retries=5, timeout=None): + retry_wait = .25 + cmd += '\r' + old_timeout = None + + if timeout is not None: + old_timeout = self.pipe.timeout + self.pipe.timeout = timeout + + if cache: + pattern = '([A-Za-z0-9]+) (?:(?P---)$|.*)' + + for retry in range(retries): + self.pipe.write(cmd.encode('ascii')) + LOG.debug("tx {}".format(cmd.strip())) + + for n in range(lines if cache else 1): + res = self.pipe.readline().decode('ascii', errors='replace') + res = res.strip() + LOG.debug("rx {}".format(res)) + + m = re.match(pattern, res) + if not m: + LOG.error("Unexpected response from radio: {} -> {}" + "".format(cmd.strip(), res)) + break + + if cache: + if varlist and m['empty']: + m = True + break + + if m.lastindex > 0: + LOG.debug("command cache {} -> {}".format(m[1], m[0])) + self._command_cache[m[1]] = m[0] + else: + if cache: + m = True + + else: + for n in range(lines - 1): + res = self.pipe.readline().strip() + LOG.debug("rx {}".format(res)) + + if m: + break + + LOG.debug("Retrying...") + time.sleep(retry_wait) + retry_wait *= 2 + retry_wait = min(retry_wait, 5) + self._pipe_reset() + else: + m = None + + if old_timeout is not None: + self.pipe.timeout = old_timeout + + return m + + def _command_read_WM(self, bank, retries=5): + retry_wait = .25 + + cmd = 'WM{}\r'.format(bank) + + for n in range(retries): + self.pipe.write(cmd.encode('ascii')) + LOG.debug("tx {}".format(cmd.strip())) + + ret = () + for b in (bank, bank.lower()): + res = self.pipe.readline().decode('ascii', errors='replace') + res = res.strip() + LOG.debug("rx {}".format(res)) + + mat = re.match('WM ([A-Ja-j])([01])', res) + if not mat or mat[1] != b: + LOG.error("Unexpected response from radio: {} -> {}" + "".format(cmd.strip(), res)) + break + + ret += (bool(int(mat[2])),) + else: + return ret + + LOG.debug("Retrying...") + time.sleep(retry_wait) + retry_wait *= 2 + retry_wait = min(retry_wait, 5) + self._pipe_reset() + + return None + + def _command_update_cache(self, cmd, lines=10, varlist=False, retries=5): + return self._command(cmd=cmd, lines=lines, cache=True, + varlist=varlist, retries=retries) + + def _command_delete_cache(self, key, pattern=False): + if not pattern: + self._command_cache.pop(key, None) + + else: + r = re.compile(key) + for k in list(filter(r.match, self._command_cache.keys())): + self._command_cache.pop(k, None) + + def _command_cached(self, key, pattern, retries=5): + retry_wait = .25 + + for n in range(retries): + if key not in self._command_cache: + cmd = re.match('(OL|MX|QM|GM|GS|PR|GR)', key) + if not cmd: + LOG.debug("Response not found in cache: {}".format(key)) + return None + + if cmd[1] == 'OL': + for n in range(5): + self._command_update_cache('OL') + + elif cmd[1] == 'MX': + bank = key[2] + size = self._scan_bank_size(bank) + self._command_update_cache('MA{}'.format(bank)) + for n in range(-(size // -10) - 1): + self._command_update_cache('MA') + + elif cmd[1] == 'QM': + self._command_update_cache('QM') + + elif cmd[1] in ('GM', 'GS'): + self._command_update_cache(cmd[1], 2) + + elif cmd[1] == 'PR': + for n in range(100 if key[2] == 'V' else 50): + cachekey = '{}{:02d}'.format(key[:3], n) + val = '{} ---'.format(cachekey) + self._command_cache[cachekey] = val + + self._command_update_cache( + key[:3], 100 if key[2] == 'V' else 50, varlist=True) + + elif cmd[1] == 'GR': + self._command_update_cache('GR', 100, varlist=True) + + else: + LOG.debug("Response not found in cache: {}".format(key)) + return None + + if key in self._command_cache: + res = re.match(pattern, self._command_cache[key]) + if res: + return res + + LOG.debug("Unexpected result from radio {}" + "".format(self._command_cache[key])) + del self._command_cache[key] + else: + LOG.debug("Response not found in cache: {}".format(key)) + + LOG.debug("Retrying...") + time.sleep(retry_wait) + retry_wait *= 2 + + return None + + def _scan_bank_size(self, bank): + if bank not in self._SCAN_BANKS: + return None + + if bank.upper() not in self._scan_bank_sizes: + res = self._command('MW{}'.format(bank.upper()), + 'MW [A-J]:([1-9]0) [a-j]:([1-9]0)') + self._scan_bank_sizes[bank.upper()] = int(res[1]) + + if bank.isupper(): + return self._scan_bank_sizes[bank] + else: + return 100 - self._scan_bank_sizes[bank.upper()] + + def _get_ol_list_uncached(self): + self._OL_LIST = [0] + for n in range(1, 48): + res = self._command_cached('OL{:02d}'.format(n), + 'OL([0-4][0-9]) RF(0[0-9]{7}00)') + + if n != int(res[1]): + raise errors.RadioError( + "Unexpected result returned from radio") + + self._OL_LIST.append(int(res[2])) + LOG.info("Offset frequency {} is {}".format(n, res[2])) + + return self._OL_LIST + + def _get_ol_list(self, locked=False): + if self._OL_LIST: + return self._OL_LIST + + if locked: + with self.LOCK: + return self._get_ol_list_uncached() + else: + return self._get_ol_list_uncached() + + def _set_pp(self, number): + (region, bank, chan) = self._decode_number(number) + self._command('PP{}{:02d}'.format(bank, chan)) + + def _get_gr_list(self): + if isinstance(self._GR_LIST, list): + return self._GR_LIST + + self._GR_LIST = [] + + for n in range(100): + res = self._command_cached( + 'GR{:02d}'.format(n), + ('GR(?P[0-9]{2}) (?:(?P---)$|' + 'MX(?P[A-Ja-j])(?P[0-9]{2}))')) + if not res: + break + + if n != int(res['num']): + raise errors.RadioError( + "Unexpected result returned from radio") + + self._GR_LIST.append((res['bank'], int(res['chan']))) + LOG.info("Select scan entry {} is {}{:02d}" + "".format(n, res['bank'], int(res['chan']))) + + return self._GR_LIST + + def _save_gs(self): + if self._GS: + return + + res = self._command('GS', 'GS([0-9])', 2) + self._GS = int(res[1]) + + def _restore_gs(self): + self._command('GS{}'.format(self._GS)) + + def _invalidate_scan_bank_size(self): + self._scan_bank_sizes = {} + + def _invalidate_ol_list(self): + self._OL_LIST = None + self._command_delete_cache('OL([0-9]{2})', True) + + def _invalidate_gr_list(self): + self._GR_LIST = None + self._command_delete_cache('GR([0-9]{2})', True) + + def _invalidate_memory(self, region=None, bank=None, chan=None, + number=None, emptyonly=False): + + if number is not None: + (region, bank, chan) = self._decode_number(number) + else: + number = self._encode_number(region, bank, chan) + + if number in self._memcache: + if emptyonly and not self._memcache[number].empty: + return + del self._memcache[number] + + if region == 'qm': + self._command_delete_cache('QM{:1d}'.format(chan), True) + + elif region == 'scan': + self._command_delete_cache('MX{}{:02d}'.format(bank, chan), True) + + elif region == 'pass': + self._command_delete_cache('PR{}{:02d}'.format(bank, chan), True) + + elif region == 'search': + # commands not cached + pass + + def get_memory(self, number): + if number in self._memcache: + return self._memcache[number] + + with self.LOCK: + return self._get_memory_unlocked(number) + + def _get_memory_unlocked(self, number): + mem = chirp_common.Memory() + + mem.extra = RadioSettingGroup('extra', 'Extra') + + AM_LIST = ['AM', 'NAM', 'WAM'] + extra_am = RadioSettingValueList(AM_LIST) + rs = RadioSetting('am', 'AM Mode', extra_am) + mem.extra.append(rs) + + lv = min(list(zip(*self._rf.valid_bands))[0]) / 1000000 + uv = max(list(zip(*self._rf.valid_bands))[1]) / 1000000 + extra_upper = RadioSettingValueFloat(lv, uv, lv, 0.00005, 5) + rs = RadioSetting('upper', 'Upper Frequency', extra_upper) + mem.extra.append(rs) + + extra_adjust = RadioSettingValueFloat(0, 999.95, 0, 0.05, 2) + rs = RadioSetting('adjust', 'Step Adjust', extra_adjust) + mem.extra.append(rs) + + extra_att = RadioSettingValueBoolean(False) + rs = RadioSetting('att', 'Attenuator', extra_att) + mem.extra.append(rs) + + extra_limit = RadioSettingValueBoolean(False) + rs = RadioSetting('limit', 'Noise Limiter', extra_limit) + mem.extra.append(rs) + + extra_protect = RadioSettingValueBoolean(False) + rs = RadioSetting('protect', 'Protect', extra_protect) + mem.extra.append(rs) + + extra_select = RadioSettingValueBoolean(False) + rs = RadioSetting('select', 'Select Scan', extra_select) + mem.extra.append(rs) + + extra_selectindex = RadioSettingValueInteger(0, 99, 0) + rs = RadioSetting('selectindex', 'Select Scan Index', + extra_selectindex) + mem.extra.append(rs) + + if isinstance(number, str): + mem.number = self._SPECIAL_CHANS[number] + mem.extd_number = number + else: + mem.number = number + + (region, bank, chan) = self._decode_number(mem.number) + if region is None: + raise errors.InvalidMemoryLocation( + "No such memory {}".format(number)) + + if region == 'vfo': + if chan == self._SPECIAL_CHANS['VFO']: + self._command('VF') + mem.name = 'VFO' + elif chan == self._SPECIAL_CHANS['VFO-A']: + self._command('VA') + mem.name = 'VFO-A' + elif chan == self._SPECIAL_CHANS['VFO-B']: + self._command('VB') + mem.name = 'VFO-B' + + ol_list = self._get_ol_list() + + res = self._command( + 'RX', + ('V[ABF] RF(?P[0-9]{10}) ' + 'ST(?P[0-9]{6})(?P[+]?) AU(?P[01]) ' + 'MD(?P[0-8]) AT(?P[01])')) + if not res: + pass + else: + mem.freq = int(res['freq']) + + if int(res['auto']): + mem.mode = 'Auto' + else: + radio_mode = [mode[0] for mode in self._MODES + if mode[1] == int(res['mode'])][0] + if radio_mode in self._AM_MODES: + mem.mode = 'AM' + extra_am.set_value(radio_mode) + else: + mem.mode = radio_mode + + mem.tuning_step = float(res['step']) / 1000 + + extra_att.set_value(int(res['att'])) + + res = self._command('OF', 'OF([0-4][0-9])([ +-])') + mem.offset = ol_list[int(res[1])] if res else 0 + mem.duplex = res[2] if res and res[2] in ('+', '-') else '' + + res = self._command('SH', 'SH([0-9]{6})([+]?)') + if res: + extra_adjust.set_value( + int(res[1]) / 1000 if res[2] == '+' else 0) + + res = self._command('NL', 'NL([01])') + if res: + extra_limit.set_value(int(res[1])) + + extra_protect.set_mutable(False) + extra_upper.set_mutable(False) + + mem.immutable += ['name', 'skip', 'extra.upper', 'extra.protect', + 'extra.select'] + + elif region == 'qm': + res = self._command_cached('QM{:1d}'.format(chan), + 'QM([0-9]) RF([0-9]{10})') + if not res: + mem.empty = True + else: + if chan != int(res[1]): + raise errors.RadioError( + "Unexpected result returned from radio") + + mem.freq = int(res[2]) + mem.name = 'QM{:1d}'.format(chan) + + extra_am.set_mutable(False) + extra_upper.set_mutable(False) + extra_adjust.set_mutable(False) + extra_att.set_mutable(False) + extra_limit.set_mutable(False) + extra_protect.set_mutable(False) + + mem.immutable += ['empty', 'freq', 'name', 'offset', 'mode', + 'tuning_step', 'skip', 'duplex', 'extra.upper', + 'extra.adjust', 'extra.att', 'extra.limit', + 'extra.protect', 'extra.select'] + + elif region == 'scan': + ol_list = self._get_ol_list() + gr_list = self._get_gr_list() + + res = self._command_cached( + 'MX{}{:02d}'.format(bank, chan), + ('MX(?P[A-Ja-j])(?P[0-9]{2}) ' + '(?:(?P---)$|MP(?P[01]) RF(?P[0-9]{10}) ' + 'ST(?P[0-9]{6})(?P[+]?) AU(?P[01]) ' + 'MD(?P[0-8]) AT(?P[01]) TM(?P.{0,12}))')) + if not res: + pass + elif res['empty']: + mem.empty = True + else: + if res['bank'] != bank or int(res['chan']) != chan: + raise errors.RadioError( + "Unexpected result returned from radio") + + mem.freq = int(res['freq']) + mem.name = res['name'] + + if int(res['auto']): + mem.mode = 'Auto' + else: + radio_mode = [mode[0] for mode in self._MODES + if mode[1] == int(res['mode'])][0] + if radio_mode in self._AM_MODES: + mem.mode = 'AM' + extra_am.set_value(radio_mode) + else: + mem.mode = radio_mode + + mem.tuning_step = float(res['step']) / 1000 + mem.skip = 'S' if int(res['pass']) else '' + + extra_att.set_value(int(res['att'])) + + if not self._SKIP_SELECT: + self._command('MR{}{:02d}'.format(bank, chan)) + + res = self._command('OF', 'OF([0-4][0-9])([ +-])') + mem.offset = ol_list[int(res[1])] if res else 0 + mem.duplex = res[2] if res and res[2] in ('+', '-') else '' + + res = self._command('SH', 'SH([0-9]{6})([+]?)') + if res: + extra_adjust.set_value( + int(res[1]) / 1000 if res[2] == '+' else 0) + + res = self._command('NL', 'NL([01])') + if res: + extra_limit.set_value(int(res[1])) + + res = self._command('PC', 'PC([01])') + if res: + extra_protect.set_value(int(res[1])) + + if (bank, chan) in gr_list: + extra_select.set_value(True) + extra_selectindex.set_value( + gr_list.index((bank, chan))) + else: + mem.immutable += ['extra.select'] + + else: + extra_adjust.set_mutable(False) + extra_limit.set_mutable(False) + extra_protect.set_mutable(False) + + mem.immutable += ['offset', 'duplex', 'extra.adjust', + 'extra.limit', 'extra.protect', + 'extra.select'] + + extra_upper.set_mutable(False) + + mem.immutable += ['extra.upper'] + + elif region == 'pass': + res = self._command_cached( + 'PR{}{:02d}'.format(bank, chan), + ('PR(?P[A-Ta-tV])(?P[0-9]{2}) ' + '(?:(?P---)$|(?P[0-9]{10}))')) + if not res or res['empty']: + mem.empty = True + else: + if res['bank'] != bank or int(res['chan']) != chan: + raise errors.RadioError( + "Unexpected result returned from radio") + + mem.freq = int(res['freq']) + mem.name = 'PR{}{:02d}'.format(bank, chan) + mem.immutable += ['freq'] + + mem.tuning_step = 20.0 + mem.skip = 'S' + + extra_am.set_mutable(False) + extra_upper.set_mutable(False) + extra_adjust.set_mutable(False) + extra_att.set_mutable(False) + extra_limit.set_mutable(False) + extra_protect.set_mutable(False) + + mem.immutable += ['name', 'offset', 'mode', 'tuning_step', 'skip', + 'duplex', 'extra.upper', 'extra.adjust', + 'extra.att', 'extra.limit', 'extra.protect', + 'extra.select'] + + elif region == 'search': + ol_list = self._get_ol_list() + + res = self._command( + 'SR{}'.format(bank), + ('SR(?P[A-Ta-t]) (?:(?P---)$|' + 'SL(?P[0-9]{10}) SU(?P[0-9]{10}) ' + 'ST(?P[0-9]{6})(?P[+]?) AU(?P[01]) ' + 'MD(?P[0-8]) AT(?P[01]) TT(?P.{0,12}))')) + if not res: + pass + elif res['empty']: + mem.empty = True + else: + if res['bank'] != bank: + raise errors.RadioError( + "Unexpected result returned from radio") + + mem.freq = int(res['lower']) + mem.name = res['name'] + + if int(res['auto']): + mem.mode = 'Auto' + else: + radio_mode = [mode[0] for mode in self._MODES + if mode[1] == int(res['mode'])][0] + if radio_mode in self._AM_MODES: + mem.mode = 'AM' + extra_am.set_value(radio_mode) + else: + mem.mode = radio_mode + + mem.tuning_step = float(res['step']) / 1000 + + extra_upper.set_value(int(res['upper']) / 1000000) + extra_att.set_value(int(res['att'])) + + self._save_gs() + + self._command('GS0') + self._command('SS{}'.format(bank)) + + res = self._command('OF', 'OF([0-4][0-9])([ +-])') + mem.offset = ol_list[int(res[1])] if res else 0 + mem.duplex = res[2] if res and res[2] in ('+', '-') else '' + + res = self._command('SH', 'SH([0-9]{6})([+]?)') + if res: + v = int(res[1]) / 1000 if res[2] == '+' else 0 + extra_adjust.set_value(v) + + res = self._command('NL', 'NL([01])') + if res: + extra_limit.set_value(int(res[1])) + + res = self._command('BP', 'BP([01])') + if res: + extra_protect.set_value(int(res[1])) + + self._restore_gs() + self._command('VF') + + mem.immutable += ['skip', 'extra.select'] + + else: + mem.empty = True + + extra_select.set_mutable(False) + + mem.immutable += ['extra.selectindex', 'tmode', 'rtone'] + + self._memcache[mem.number] = mem + return mem + + def validate_memory(self, memory): + msgs = [] + + ol_list = self._get_ol_list(True) + (region, bank, chan) = self._decode_number(memory.number) + + if region in ('scan', 'search'): + if memory.offset not in ol_list: + msg = chirp_common.ValidationWarning( + "Offset frequency is not valid, see table in settings " + "for valid values") + msgs.append(msg) + + if memory.tuning_step == 0.0 or memory.tuning_step >= 1000.0 or \ + (int(memory.tuning_step * 1000) % 50) != 0: + msg = chirp_common.ValidationWarning( + "Tuning step must be non-zero, less than 1000 kHz, and " + "divisible by 0.05 kHz") + msgs.append(msg) + + if 'adjust' in memory.extra: + if float(memory.extra['adjust'].value) >= memory.tuning_step: + msg = chirp_common.ValidationWarning( + "Step adjust must be smaller than tuning step") + msgs.append(msg) + + if region == 'search' and 'upper' in memory.extra: + upper = int(float(memory.extra['upper'].value) * 1000000) + if memory.freq > upper: + msg = chirp_common.ValidationWarning( + "Upper search frequency is not greater than lower " + "frequency") + msgs.append(msg) + + valid = False + for (lv, uv) in self._rf.valid_bands: + if upper >= lv and upper <= uv: + valid = True + break + + if not valid: + msg = chirp_common.ValidationError( + "Upper search frequency {} is not in a valid band" + "".format(float(memory.extra['upper'].value))) + msgs.append(msg) + + if region == 'pass': + if memory.skip != 'S': + msg = chirp_common.ValidationWarning( + "Search pass frequencies must be marked skip") + msgs.append(msg) + + msg = chirp_common.ValidationWarning( + "Memories must be refreshed after modifying pass channels") + msgs.append(msg) + + return msgs + super().validate_memory(memory) + + def set_memory(self, memory): + with self.LOCK: + return self._set_memory_unlocked(memory) + + def _set_memory_unlocked(self, memory): + self._invalidate_memory(number=memory.number) + + (region, bank, chan) = self._decode_number(memory.number) + if region is None: + raise errors.InvalidMemoryLocation( + "No such memory {}".format(memory.number)) + + if region == 'vfo': + if chan == self._SPECIAL_CHANS['VFO']: + self._command('VF') + elif chan == self._SPECIAL_CHANS['VFO-A']: + self._command('VA') + elif chan == self._SPECIAL_CHANS['VFO-B']: + self._command('VB') + + ol_list = self._get_ol_list() + + freq = memory.freq + auto = int(memory.mode == 'Auto') + step = int(memory.tuning_step * 1000) + + if memory.mode == 'Auto': + mode = 0 + elif memory.mode == 'AM': + mode = [mode[1] for mode in self._MODES + if mode[0] == memory.extra['am']][0] + else: + mode = [mode[1] for mode in self._MODES + if mode[0] == memory.mode][0] + + att = int(memory.extra['att'].value) \ + if 'att' in memory.extra else 0 + duplex = memory.duplex if memory.duplex in ('+', '-') else '' + offset = ol_list.index(memory.offset) \ + if duplex and memory.offset in ol_list else 0 + adjust = float(memory.extra['adjust'].value) \ + if 'adjust' in memory.extra else 0 + limit = int(memory.extra['limit'].value) \ + if 'limit' in memory.extra else 0 + + self._command('RF{:010d}'.format(freq)) + self._command('AT{:1d}'.format(att)) + self._command('AU{:1d}'.format(auto)) + + if not auto: + self._command('MD{:1d}'.format(mode)) + self._command('ST{:06d}'.format(step)) + self._command('OF{:02d}{}'.format(offset, duplex)) + + # step tuning enable can only be toggled, so get the + # current value first + toggle = '' + res = self._command('SH', 'SH([0-9]{6})([+]?)') + if res: + toggle = '+' if (res[2] == '+') != (adjust > 0) else '' + + self._command('SH{:06d}{}'.format(int(adjust * 1000), toggle)) + + self._command('NL{:1d}'.format(limit)) + + elif region == 'qm': + raise errors.InvalidDataError( + "Quick memory locations are read-only") + + elif region == 'scan': + self._command_delete_cache('MX{:1}{:02d}'.format(bank, chan)) + ol_list = self._get_ol_list() + gr_list = self._get_gr_list() + + freq = memory.freq + auto = int(memory.mode == 'Auto') + step = int(memory.tuning_step * 1000) + + if memory.mode == 'Auto': + mode = 0 + elif memory.mode == 'AM': + mode = [mode[1] for mode in self._MODES + if mode[0] == memory.extra['am']][0] + else: + mode = [mode[1] for mode in self._MODES + if mode[0] == memory.mode][0] + + att = int(memory.extra['att'].value) \ + if 'att' in memory.extra else 0 + duplex = memory.duplex if memory.duplex in ('+', '-') else '' + offset = ol_list.index(memory.offset) \ + if duplex and memory.offset in ol_list else 0 + adjust = float(memory.extra['adjust'].value) \ + if 'adjust' in memory.extra else 0 + limit = int(memory.extra['limit'].value) \ + if 'limit' in memory.extra else 0 + protect = int(memory.extra['protect'].value) \ + if 'protect' in memory.extra else 0 + select = int(memory.extra['select'].value) \ + if 'select' in memory.extra else 0 + name = memory.name + mp = 1 if memory.skip == 'S' else 0 + + offsetstr = 'OF{:02d}{} '.format(offset, duplex) \ + if not self._SKIP_SELECT else '' + res = self._command( + ('MX{}{:02d} RF{:010d} MP{:1d} ST{:06d} MD{:1d} AT{:1d} ' + '{}AU{:1d} TM{:12}'.format(bank, chan, freq, mp, step, mode, + att, offsetstr, auto, name)), + '(?:$|{:c}{:c})'.format(0x13, 0x11)) + if not res: + raise errors.InvalidDataError( + "Radio refused {}".format(memory.number)) + + if not self._SKIP_SELECT: + self._command('MR{}{:02d}'.format(bank, chan)) + + if not auto: + # step tuning enable can only be toggled, so get + # the current value first + toggle = '' + res = self._command('SH', 'SH([0-9]{6})([+]?)') + if res: + toggle = '+' if (res[2] == '+') != (adjust > 0) else '' + + self._command( + 'SH{:06d}{}'.format(int(adjust * 1000), toggle)) + + self._command('NL{:1d}'.format(limit)) + self._command('PC{:1d}'.format(protect)) + + if not select and (bank, chan) in gr_list: + self._command( + 'GD{:02d}'.format(gr_list.index((bank, chan)))) + self._invalidate_gr_list() + + elif region == 'pass': + self._command_delete_cache('PR{}[0-9]{{2}}'.format(bank), True) + + freq = memory.freq + + res = self._command('PW{}{:010d}'.format(bank, freq)) + if not res: + raise errors.InvalidDataError( + "Radio refused {}".format(memory.number)) + + for n in range(100 if bank == 'V' else 50): + self._invalidate_memory(region, bank, n, emptyonly=True) + + elif region == 'search': + self._command_delete_cache('SR{}'.format(bank)) + ol_list = self._get_ol_list() + + lower = memory.freq + upper = int(float(memory.extra['upper'].value) * 1000000) \ + if 'upper' in memory.extra else lower + auto = int(memory.mode == 'Auto') + step = int(memory.tuning_step * 1000) + + if memory.mode == 'Auto': + mode = 0 + elif memory.mode == 'AM': + mode = [mode[1] for mode in self._MODES + if mode[0] == memory.extra['am']][0] + else: + mode = [mode[1] for mode in self._MODES + if mode[0] == memory.mode][0] + + att = int(memory.extra['att'].value) \ + if 'att' in memory.extra else 0 + duplex = memory.duplex if memory.duplex in ('+', '-') else '' + offset = ol_list.index(memory.offset) \ + if duplex and memory.offset in ol_list else 0 + adjust = float(memory.extra['adjust'].value) \ + if 'adjust' in memory.extra else 0 + limit = int(memory.extra['limit'].value) \ + if 'limit' in memory.extra else 0 + protect = int(memory.extra['protect'].value) \ + if 'protect' in memory.extra else 0 + name = memory.name + + # correct lower/upper out of order + if lower > upper: + (lower, upper) = (upper, lower) + + # fix out of range + lower = max(lower, min(list(zip(*self._rf.valid_bands))[0])) + upper = min(upper, max(list(zip(*self._rf.valid_bands))[1])) + + res = self._command( + 'SE{} SL{:010d} SU{:010d} ST{:06d} MD{:1d} AT{:1d} ' + 'OF{:02d}{:1} AU{:1d} TT{:12}'.format(bank, lower, upper, step, + mode, att, offset, + duplex, auto, name)) + if not res: + raise errors.InvalidDataError( + "Radio refused {}".format(memory.number)) + + self._save_gs() + + self._command('GS0') + self._command('SS{}'.format(bank)) + + if not auto: + # step tuning enable can only be toggled, so get the + # current value first + toggle = '' + res = self._command('SH', 'SH([0-9]{6})([+]?)') + if res: + toggle = '+' if (res[2] == '+') != (adjust > 0) else '' + + self._command('SH{:06d}{}'.format(int(adjust * 1000), toggle)) + + self._command('NL{:1d}'.format(limit)) + self._command('BP{:1d}'.format(protect)) + + self._restore_gs() + self._command('VF') + + def erase_memory(self, number): + with self.LOCK: + return self._erase_memory_unlocked(number) + + def _erase_memory_unlocked(self, number): + if isinstance(number, str): + if number not in self._SPECIAL_CHANS: + return + + number = self._SPECIAL_CHANS[number] + + if number not in self._memcache: + return + + (region, bank, chan) = self._decode_number(number) + + if region == 'qm': + raise errors.InvalidDataError( + "Quick memory locations are read-only") + + elif region == 'scan': + self._command_delete_cache('MX{}{:02d}'.format(bank, chan)) + self._command('MR{}{:02d}'.format(bank, chan)) + self._command('MQ{:02d}'.format(chan)) + + elif region == 'pass': + self._command_delete_cache('PR{}[0-9]{{2}}'.format(bank), True) + self._command('PD{}{:02d}'.format(bank, chan)) + + for n in range(chan, 100 if bank == 'V' else 50): + self._invalidate_memory(region, bank, n) + + elif region == 'search': + self._command_delete_cache('SR{}'.format(bank)) + self._command('QS{}'.format(bank)) + + del self._memcache[number] + + def get_settings(self): + with self.LOCK: + return self._get_settings_unlocked() + + def _get_settings_unlocked(self): + main = RadioSettingGroup('main', 'Main') + vfo = RadioSettingGroup('vfo', 'VFO') + freq = RadioSettingGroup('freq', 'Offset') + scan = RadioSettingGroup('scan', 'Scan') + search = RadioSettingGroup('search', 'Search') + scanbankprotect = RadioSettingGroup('scanbankprotect', + 'Scan Bank Protect') + top = RadioSettings(main, vfo, freq, scan, search, scanbankprotect) + + res = self._command('VR', 'VR([0-9]+)') + rs = RadioSetting('VR', 'Firmware Version', + RadioSettingValueString(0, 4, res[1])) + rs.value.set_mutable(False) + main.append(rs) + + res = self._command('AF', 'AF([01])') + rs = RadioSetting('AF', 'Automatic Frequency Control', + RadioSettingValueBoolean(int(res[1]))) + rs.set_apply_callback( + lambda x: self._command('AF{}'.format(int(x.value)))) + main.append(rs) + + res = self._command('AP', 'AP([0-9][.][0-9])') + rs = RadioSetting( + 'AP', 'Automatic Power Off (hours)', + RadioSettingValueFloat(0, 9.5, float(res[1]), 0.5, 1)) + rs.set_apply_callback( + lambda x: self._command('AP{}'.format(int(x.value)))) + main.append(rs) + + res = self._command('DT', 'DT([01])') + rs = RadioSetting('DT', 'Display Frequency Text', + RadioSettingValueBoolean(int(res[1]))) + rs.set_apply_callback( + lambda x: self._command('DT{}'.format(int(x.value)))) + main.append(rs) + + res = self._command('LB', 'LB([0-9]{2})') + rs = RadioSetting('LB', 'LCD Contrast', + RadioSettingValueInteger(0, 31, res[1])) + rs.set_apply_callback( + lambda x: self._command('LB{:02d}'.format(int(x.value)))) + main.append(rs) + + # OM supports options for standard, no, and custom message, + # but the code here always sets the configured text as a + # custom message. + res = self._command('OM', 'OM([012]) (.{0,48})') + rs = RadioSetting('OM', 'Opening Message', + RadioSettingValueString(0, 48, res[2])) + rs.set_apply_callback( + lambda x: self._command('OM2 {}'.format(str(x.value)))) + main.append(rs) + + res = self._command('PA', 'PA([0-9]{2})') + rs = RadioSetting('PA', 'Power Save Delay (seconds)', + RadioSettingValueInteger(0, 99, res[1])) + rs.set_apply_callback( + lambda x: self._command('PA{:02d}'.format(int(x.value)))) + main.append(rs) + + res = self._command('PI', 'PI([1-9].[05])') + rs = RadioSetting( + 'PI', 'Power Save Interval (seconds)', + RadioSettingValueFloat(1.0, 9.5, float(res[1]), 0.5, 1)) + rs.set_apply_callback( + lambda x: self._command( + 'PI{:02d}'.format(int(float(x.value) * 10)))) + main.append(rs) + + res = self._command('PP', 'PP([A-Ja-j])([0-9]{2})') + rs = RadioSetting( + 'PP', 'Priority Scan Channel', + RadioSettingValueInteger( + 0, self._SCAN_MEMORIES - 1, + self._encode_number('scan', res[1], int(res[2])))) + rs.set_apply_callback(lambda x: self._set_pp(int(x.value))) + main.append(rs) + + res = self._command('TI', 'TI([01][0-9])') + rs = RadioSetting('TI', 'Priority Interval (seconds)', + RadioSettingValueInteger(1, 19, res[1])) + rs.set_apply_callback( + lambda x: self._command('TI{:02d}'.format(int(x.value)))) + main.append(rs) + + res = self._command('VL', 'VL([0-9])') + rs = RadioSetting('VL', 'Beep Volume', + RadioSettingValueInteger(0, 9, res[1])) + rs.set_apply_callback( + lambda x: self._command('VL{}'.format(int(x.value)))) + main.append(rs) + + res = self._command('WP', 'WP([01])') + rs = RadioSetting('WP', 'Write Protect', + RadioSettingValueBoolean(int(res[1]))) + rs.set_apply_callback( + lambda x: self._command('WP{}'.format(int(x.value)))) + main.append(rs) + + # vfo settings + + res = self._command('DA', 'DA[ +]([012][0-9]{2})') + rs = RadioSetting('DA', 'Dial Audio Squelch', + RadioSettingValueInteger(0, 255, res[1])) + rs.set_apply_callback( + lambda x: self._command('DA{:03d}'.format(int(x.value)))) + vfo.append(rs) + + res = self._command('DB', 'DB[ +]([012][0-9]{2})') + rs = RadioSetting('DB', 'Dial Level Squelch', + RadioSettingValueInteger(0, 255, res[1])) + rs.set_apply_callback( + lambda x: self._command('DB{:03d}'.format(int(x.value)))) + vfo.append(rs) + + res = self._command('DD', 'DD([0-9][.][0-9])') + + rs = RadioSetting('DDFF', 'Dial Search Hold', + RadioSettingValueBoolean(res[1] == 'FF')) + vfo.append(rs) + + value = float(res[1]) if res[1] != 'FF' else 0 + rs = RadioSetting('DD', 'Dial Delay (seconds)', + RadioSettingValueFloat(0, 9.9, value, 0.1, 1)) + vfo.append(rs) + + res = self._command('DP', 'DP([0-9]{2})') + rs = RadioSetting('DP', 'Dial Pause (seconds)', + RadioSettingValueInteger(0, 60, res[1])) + rs.set_apply_callback( + lambda x: self._command('DP{:02d}'.format(int(x.value)))) + vfo.append(rs) + + VT_MAP = [('Off', 0), ('On, auto-store to bank J', 1), + ('On, erase bank J', 2)] + res = self._command('VT', 'VT([012])') + rs = RadioSetting('VT', 'VFO Auto-store', + RadioSettingValueMap(VT_MAP, int(res[1]))) + rs.set_apply_callback( + lambda x: self._command('VT{}'.format(int(x.value)))) + vfo.append(rs) + + # frequency offsets + + # 0 means off, 20-47 are read-only + ol_list = self._get_ol_list() + for n in range(0, 48): + rs = RadioSetting( + 'OL{:02d}'.format(n), + 'Offset Frequency {} (MHz)'.format(n), + RadioSettingValueFloat( + 0.0, 999.9999, ol_list[n] / 1000000, 0.0001, 4)) + rs.value.set_mutable(n > 0 and n < 20) + rs.set_apply_callback( + lambda x, y: self._command( + ('OL{:02d} {:010d}' + ''.format(y, int(float(x.value) * 1000000)))), n) + rs.set_warning("Memories must be refreshed after changing " + "offset frequencies.") + freq.append(rs) + + # scan settings + + grp = RadioSettingSubGroup('scan general', 'Scan General') + scan.append(grp) + + res = self._command('GM', 'GM([0-9])', 2) + sel = int(res[1]) + rs = RadioSetting('GM', 'Selected Scan Group', + RadioSettingValueInteger(0, 9, sel)) + rs.set_apply_callback( + lambda x: self._command('GM{}'.format(int(x.value)))) + grp.append(rs) + + grp = RadioSettingSubGroup('TB', 'Scan Bank Name') + scan.append(grp) + + for bank in self._SCAN_BANKS: + res = self._command('TB{}'.format(bank), 'TB([A-Ja-j])(.{0,8})') + rs = RadioSetting('TB{}'.format(bank), 'Bank {} Name'.format(bank), + RadioSettingValueString(0, 8, res[2])) + rs.set_apply_callback( + lambda x, y: self._command( + 'TB{}{:8}'.format(y, str(x.value))), bank) + grp.append(rs) + + grp = RadioSettingSubGroup('MW', 'Scan Bank Size') + scan.append(grp) + + MW_MAP = [('10/90', 10), ('20/80', 20), ('30/70', 30), ('40/60', 40), + ('50/50', 50), ('60/40', 60), ('70/30', 70), ('80/20', 80), + ('90/10', 90)] + + for bank in self._SCAN_BANKS[::2]: + rs = RadioSetting( + 'MW{}'.format(bank), 'Bank {}/{}'.format(bank, bank.lower()), + RadioSettingValueMap(MW_MAP, self._scan_bank_size(bank))) + rs.set_apply_callback( + lambda x, y: self._command( + 'MW{}{:2d}'.format(y, int(x.value)), timeout=600), bank) + rs.set_warning("Resizing scan banks takes a significant amount of " + "time (one minute or longer). Memories must be " + "refreshed after changing scan bank size.") + grp.append(rs) + + for group in range(10): + grp = RadioSettingSubGroup( + 'GM{}'.format(group), 'Scan Group {}'.format(group)) + scan.append(grp) + + self._command('GM{}'.format(group)) + + res = self._command_cached( + 'GM{:1d}'.format(group), + ('GM(?P[0-9]) XD(?P[0-9][.][0-9]) ' + 'XB (?P[012][0-9]{2}) XA (?P