From aacf79520fb31221660d2a60f9544808e97cde9a Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 8 Jun 2023 18:44:20 -0700 Subject: [PATCH] Fix th7800 for chirp-next Fixes #10585 --- chirp/drivers/th7800.py | 34 ++++++++++++++++----------------- tests/Python3_Driver_Testing.md | 6 +++--- tests/py3_driver_testers.txt | 1 + 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/chirp/drivers/th7800.py b/chirp/drivers/th7800.py index 608c717d6..f0618152b 100644 --- a/chirp/drivers/th7800.py +++ b/chirp/drivers/th7800.py @@ -570,21 +570,20 @@ def match_model(cls, filedata, filename): def _identify(radio): """Do identify handshake with TYT""" try: - radio.pipe.write("\x02SPECPR") + radio.pipe.write(b"\x02SPECPR") ack = radio.pipe.read(1) - if ack != "A": + if ack != b"A": util.hexprint(ack) - raise errors.RadioError("Radio did not ACK first command: %x" - % ord(ack)) + raise errors.RadioError("Radio did not ACK first command: %r" + % ack) except: - LOG.debug(util.hexprint(ack)) raise errors.RadioError("Unable to communicate with the radio") - radio.pipe.write("G\x02") + radio.pipe.write(b"G\x02") ident = radio.pipe.read(16) - radio.pipe.write("A") + radio.pipe.write(b"A") r = radio.pipe.read(2) - if r != "A": + if r != b"A": raise errors.RadioError("Ack failed") return ident @@ -595,15 +594,15 @@ def _download(radio, memsize=0x10000, blocksize=0x80): LOG.info("ident:", util.hexprint(data)) offset = 0x100 for addr in range(offset, memsize, blocksize): - msg = struct.pack(">cHB", "R", addr, blocksize) + msg = struct.pack(">cHB", b"R", addr, blocksize) radio.pipe.write(msg) block = radio.pipe.read(blocksize + 4) if len(block) != (blocksize + 4): LOG.debug(util.hexprint(block)) raise errors.RadioError("Radio sent a short block") - radio.pipe.write("A") + radio.pipe.write(b"A") ack = radio.pipe.read(1) - if ack != "A": + if ack != b"A": LOG.debug(util.hexprint(ack)) raise errors.RadioError("Radio NAKed block") data += block[4:] @@ -615,9 +614,9 @@ def _download(radio, memsize=0x10000, blocksize=0x80): status.msg = "Cloning from radio" radio.status_fn(status) - radio.pipe.write("ENDR") + radio.pipe.write(b"ENDR") - return memmap.MemoryMap(data) + return memmap.MemoryMapBytes(data) def _upload(radio, memsize=0xF400, blocksize=0x80): @@ -626,7 +625,7 @@ def _upload(radio, memsize=0xF400, blocksize=0x80): radio.pipe.timeout = 1 - if data != radio._mmap[:radio._mmap_offset]: + if data != radio._mmap[0:radio._mmap_offset]: raise errors.RadioError( "Model mismatch: \n%s\n%s" % (util.hexprint(data), @@ -653,12 +652,12 @@ def _upload(radio, memsize=0xF400, blocksize=0x80): for addr in range(offset, memsize, blocksize): mapaddr = addr + radio._mmap_offset - offset LOG.debug("addr: 0x%04X, mmapaddr: 0x%04X" % (addr, mapaddr)) - msg = struct.pack(">cHB", "W", addr, blocksize) + msg = struct.pack(">cHB", b"W", addr, blocksize) msg += radio._mmap[mapaddr:(mapaddr + blocksize)] LOG.debug(util.hexprint(msg)) radio.pipe.write(msg) ack = radio.pipe.read(1) - if ack != "A": + if ack != b"A": LOG.debug(util.hexprint(ack)) raise errors.RadioError("Radio did not ack block 0x%04X" % addr) @@ -670,7 +669,7 @@ def _upload(radio, memsize=0xF400, blocksize=0x80): radio.status_fn(status) # End of clone - radio.pipe.write("ENDW") + radio.pipe.write(b"ENDW") # Checksum? final_data = radio.pipe.read(3) @@ -683,6 +682,7 @@ class TYTTH7800Radio(TYTTH7800Base, chirp_common.CloneModeRadio, VENDOR = "TYT" MODEL = "TH-7800" BAUD_RATE = 38400 + NEEDS_COMPAT_SERIAL = False _memsize = 65296 _mmap_offset = 0x0010 diff --git a/tests/Python3_Driver_Testing.md b/tests/Python3_Driver_Testing.md index 16ea439e2..54c5f476e 100644 --- a/tests/Python3_Driver_Testing.md +++ b/tests/Python3_Driver_Testing.md @@ -325,7 +325,7 @@ | TID_TD-M8 | [Implied by Retevis_RT22](#user-content-Retevis_RT22) | 9-Dec-2022 | Yes | 0.04% | | TID_TD-UV68 | [@Sandmann34](https://github.com/Sandmann34) | 7-Feb-2023 | Yes | | | TYT_TH-350 | | | Yes | 0.07% | -| TYT_TH-7800 | | | | 0.13% | +| TYT_TH-7800 | [Reported working](https://chirp.danplanet.com/issues/10585) | 4-Jul-2023 | Yes | 0.13% | | TYT_TH-7800_File | | | | 0.00% | | TYT_TH-9800 | Unit tested; needs confirm | 24-Dec-2022 | Yes | 0.65% | | TYT_TH-9800_File | | | Yes | 0.00% | @@ -415,9 +415,9 @@ **Drivers:** 410 -**Tested:** 86% (354/56) (93% of usage stats) +**Tested:** 86% (355/55) (93% of usage stats) -**Byte clean:** 90% (369/41) +**Byte clean:** 90% (370/40) ## Meaning of this testing diff --git a/tests/py3_driver_testers.txt b/tests/py3_driver_testers.txt index dddb37107..ec326c7ce 100644 --- a/tests/py3_driver_testers.txt +++ b/tests/py3_driver_testers.txt @@ -298,6 +298,7 @@ TYT_TH-UVF1,@kk7ds,13-Dec-2022 TYT_TH-UVF8D,@MELERIX,2-Feb-2023 TYT_TH-UV8000,@KC9HI,6-Jan-2023 TYT_TH-UV88,@KC9HI,5-Dec-2022 +TYT_TH-7800,#10585,4-Jul-2023 TYT_TH9000_144,+Retevis_RT9000D_136-174,8-Dec-2022 TYT_TH9000_220,+Retevis_RT9000D_220-260,8-Dec-2022 TYT_TH9000_440,+Retevis_RT9000D_400-490,8-Dec-2022