Skip to content

Commit

Permalink
Fix th7800 for chirp-next
Browse files Browse the repository at this point in the history
Fixes #10585
  • Loading branch information
kk7ds committed Jul 5, 2023
1 parent 11f6285 commit aacf795
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
34 changes: 17 additions & 17 deletions chirp/drivers/th7800.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:]
Expand All @@ -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):
Expand All @@ -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),
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/Python3_Driver_Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
| <a name="TID_TD-M8"></a> TID_TD-M8 | [Implied by Retevis_RT22](#user-content-Retevis_RT22) | 9-Dec-2022 | Yes | 0.04% |
| <a name="TID_TD-UV68"></a> TID_TD-UV68 | [@Sandmann34](https://github.com/Sandmann34) | 7-Feb-2023 | Yes | |
| <a name="TYT_TH-350"></a> TYT_TH-350 | | | Yes | 0.07% |
| <a name="TYT_TH-7800"></a> TYT_TH-7800 | | | | 0.13% |
| <a name="TYT_TH-7800"></a> TYT_TH-7800 | [Reported working](https://chirp.danplanet.com/issues/10585) | 4-Jul-2023 | Yes | 0.13% |
| <a name="TYT_TH-7800_File"></a> TYT_TH-7800_File | | | | 0.00% |
| <a name="TYT_TH-9800"></a> TYT_TH-9800 | Unit tested; needs confirm | 24-Dec-2022 | Yes | 0.65% |
| <a name="TYT_TH-9800_File"></a> TYT_TH-9800_File | | | Yes | 0.00% |
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tests/py3_driver_testers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aacf795

Please sign in to comment.