Skip to content

Commit

Permalink
Fixes and testing: th9000.py & update Python3 Driver Testing matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
KC9HI authored and kk7ds committed Dec 8, 2022
1 parent 8c648b4 commit 4c70adc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 35 deletions.
58 changes: 34 additions & 24 deletions chirp/drivers/th9000.py
Expand Up @@ -392,8 +392,8 @@ def _echo_write(radio, data):
def _checksum(data):
cs = 0
for byte in data:
cs += ord(byte)
return cs % 256
cs = (cs + byte) & 0xFF
return cs


def _read(radio, length):
Expand All @@ -413,15 +413,24 @@ def _read(radio, length):

def _ident(radio):
radio.pipe.timeout = 1
_echo_write(radio, "PROGRAM")
response = radio.pipe.read(3)
if response != "QX\06":
LOG.debug("Response was :\n%s" % util.hexprint(response))
raise errors.RadioError("Unsupported model")
_echo_write(radio, "\x02")
exito = False
for i in range(0, 5):
_echo_write(radio, b"PROGRAM")
response = radio.pipe.read(3)

if response == b"QX\06":
exito = True

# check if we had EXITO
if exito is False:
msg = "The radio did not accept program mode after five tries.\n"
msg += "Check you interface cable and power cycle your radio."
raise errors.RadioError(msg)

_echo_write(radio, b"\x02")
response = radio.pipe.read(16)
LOG.debug(util.hexprint(response))
if response[1:8] != "TH-9000":
if response[1:8] != b"TH-9000":
LOG.error("Looking for:\n%s" % util.hexprint("TH-9000"))
LOG.error("Response was:\n%s" % util.hexprint(response))
raise errors.RadioError("Unsupported model")
Expand All @@ -431,23 +440,23 @@ def _send(radio, cmd, addr, length, data=None):
frame = struct.pack(">cHb", cmd, addr, length)
if data:
frame += data
frame += chr(_checksum(frame[1:]))
frame += "\x06"
cs = _checksum(c for c in cmd[1:])
frame += struct.pack('>BB', cs, 0x06)
_echo_write(radio, frame)
LOG.debug("Sent:\n%s" % util.hexprint(frame))
if data:
result = radio.pipe.read(1)
if result != "\x06":
if result != b"\x06":
LOG.debug("Ack was: %s" % repr(result))
raise errors.RadioError(
"Radio did not accept block at %04x" % addr)
return
result = _read(radio, length + 6)
LOG.debug("Got:\n%s" % util.hexprint(result))
header = result[0:4]
header = result[:4]
data = result[4:-2]
ack = result[-1]
if ack != "\x06":
ack = result[-1:]
if ack != b"\x06":
LOG.debug("Ack was: %s" % repr(ack))
raise errors.RadioError("Radio NAK'd block at %04x" % addr)
_cmd, _addr, _length = struct.unpack(">cHb", header)
Expand All @@ -456,20 +465,20 @@ 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])
if cs != ord(result[-2]):
cs = _checksum(d for d in result[1:-2])
if cs != result[-2]:
LOG.debug("Calculated: %02x" % cs)
LOG.debug("Actual: %02x" % ord(result[-2]))
LOG.debug("Actual: %02x" % result[-2])
raise errors.RadioError("Block at 0x%04x failed checksum" % addr)
return data


def _finish(radio):
endframe = "\x45\x4E\x44"
endframe = b"\x45\x4E\x44"
_echo_write(radio, endframe)
result = radio.pipe.read(1)
# TYT radios acknowledge the "endframe" command, Luiton radios do not.
if result != "" and result != "\x06":
if result != b"" and result != b"\x06":
LOG.error("Got:\n%s" % util.hexprint(result))
raise errors.RadioError("Radio did not finish cleanly")

Expand All @@ -479,11 +488,11 @@ def do_download(radio):
_ident(radio)

_memobj = None
data = ""
data = b""

for start, end in radio._ranges:
for addr in range(start, end, 0x10):
block = _send(radio, 'R', addr, 0x10)
block = _send(radio, b'R', addr, 0x10)
data += block
status = chirp_common.Status()
status.cur = len(data)
Expand All @@ -493,7 +502,7 @@ def do_download(radio):

_finish(radio)

return memmap.MemoryMap(data)
return memmap.MemoryMapBytes(data)


def do_upload(radio):
Expand All @@ -505,7 +514,7 @@ def do_upload(radio):
if addr < 0x0100:
continue
block = radio._mmap[addr:addr + 0x10]
_send(radio, 'W', addr, len(block), block)
_send(radio, b'W', addr, len(block), block)
status = chirp_common.Status()
status.cur = addr
status.max = end
Expand All @@ -524,6 +533,7 @@ class Th9000Radio(chirp_common.CloneModeRadio,
VENDOR = "TYT"
MODEL = "TH9000 Base"
BAUD_RATE = 9600
NEEDS_COMPAT_SERIAL = False
valid_freq = [(900000000, 999000000)]

_memsize = MMAPSIZE
Expand Down
22 changes: 11 additions & 11 deletions tests/Python3_Driver_Testing.md
Expand Up @@ -187,8 +187,8 @@
| <a name="Kenwood_TS-590S_SG_LiveMode"></a> Kenwood_TS-590S_SG_LiveMode | | | Yes |
| <a name="Kenwood_TS-850"></a> Kenwood_TS-850 | | | Yes |
| <a name="LUITON_LT-316"></a> LUITON_LT-316 | | | |
| <a name="LUITON_LT-580_UHF"></a> LUITON_LT-580_UHF | | | |
| <a name="LUITON_LT-580_VHF"></a> LUITON_LT-580_VHF | | | |
| <a name="LUITON_LT-580_UHF"></a> LUITON_LT-580_UHF | [@KC9HI](https://github.com/KC9HI) | 8-Dec-2022 | Yes |
| <a name="LUITON_LT-580_VHF"></a> LUITON_LT-580_VHF | [@KC9HI](https://github.com/KC9HI) | 8-Dec-2022 | Yes |
| <a name="LUITON_LT-588UV"></a> LUITON_LT-588UV | [@KC9HI](https://github.com/KC9HI) | 11-Nov-2022 | Yes |
| <a name="LUITON_LT-725UV"></a> LUITON_LT-725UV | | | |
| <a name="Lanchonlh_HG-UV98"></a> Lanchonlh_HG-UV98 | | | Yes |
Expand Down Expand Up @@ -267,10 +267,10 @@
| <a name="Retevis_RT76P"></a> Retevis_RT76P | | | |
| <a name="Retevis_RT85"></a> Retevis_RT85 | [@KC9HI](https://github.com/KC9HI) | 5-Dec-2022 | Yes |
| <a name="Retevis_RT87"></a> Retevis_RT87 | | | |
| <a name="Retevis_RT9000D_136-174"></a> Retevis_RT9000D_136-174 | | | |
| <a name="Retevis_RT9000D_220-260"></a> Retevis_RT9000D_220-260 | | | |
| <a name="Retevis_RT9000D_400-490"></a> Retevis_RT9000D_400-490 | | | |
| <a name="Retevis_RT9000D_66-88"></a> Retevis_RT9000D_66-88 | | | |
| <a name="Retevis_RT9000D_136-174"></a> Retevis_RT9000D_136-174 | [@KC9HI](https://github.com/KC9HI) | 8-Dec-2022 | Yes |
| <a name="Retevis_RT9000D_220-260"></a> Retevis_RT9000D_220-260 | [@KC9HI](https://github.com/KC9HI) | 8-Dec-2022 | Yes |
| <a name="Retevis_RT9000D_400-490"></a> Retevis_RT9000D_400-490 | [@KC9HI](https://github.com/KC9HI) | 8-Dec-2022 | Yes |
| <a name="Retevis_RT9000D_66-88"></a> Retevis_RT9000D_66-88 | [@KC9HI](https://github.com/KC9HI) | 8-Dec-2022 | Yes |
| <a name="Retevis_RT95"></a> Retevis_RT95 | [@KC9HI](https://github.com/KC9HI) | 13-Nov-2022 | Yes |
| <a name="Retevis_RT95_VOX"></a> Retevis_RT95_VOX | [Implied by Retevis_RT95](#user-content-Retevis_RT95) | 13-Nov-2022 | Yes |
| <a name="Retevis_RT98"></a> Retevis_RT98 | | | |
Expand All @@ -290,9 +290,9 @@
| <a name="TYT_TH-UV88"></a> TYT_TH-UV88 | [@KC9HI](https://github.com/KC9HI) | 5-Dec-2022 | Yes |
| <a name="TYT_TH-UVF1"></a> TYT_TH-UVF1 | | | |
| <a name="TYT_TH-UVF8D"></a> TYT_TH-UVF8D | | | |
| <a name="TYT_TH9000_144"></a> TYT_TH9000_144 | | | |
| <a name="TYT_TH9000_220"></a> TYT_TH9000_220 | | | |
| <a name="TYT_TH9000_440"></a> TYT_TH9000_440 | | | |
| <a name="TYT_TH9000_144"></a> TYT_TH9000_144 | [Implied by Retevis_RT9000D_136-174](#user-content-Retevis_RT9000D_136-174) | 8-Dec-2022 | Yes |
| <a name="TYT_TH9000_220"></a> TYT_TH9000_220 | [Implied by Retevis_RT9000D_220-260](#user-content-Retevis_RT9000D_220-260) | 8-Dec-2022 | Yes |
| <a name="TYT_TH9000_440"></a> TYT_TH9000_440 | [Implied by Retevis_RT9000D_400-490](#user-content-Retevis_RT9000D_400-490) | 8-Dec-2022 | Yes |
| <a name="Vertex_Standard_FTL-1011"></a> Vertex_Standard_FTL-1011 | | | |
| <a name="Vertex_Standard_FTL-2011"></a> Vertex_Standard_FTL-2011 | | | |
| <a name="Vertex_Standard_FTL-7011"></a> Vertex_Standard_FTL-7011 | | | |
Expand Down Expand Up @@ -360,9 +360,9 @@

**Drivers:** 355

**Tested:** 49% (175/180)
**Tested:** 51% (184/171)

**Byte clean:** 65% (233/122)
**Byte clean:** 68% (242/113)

## Minimal test prodecure
For the purposes of the Python 3 effort, a "tested" radio means
Expand Down
9 changes: 9 additions & 0 deletions tests/py3_driver_testers.txt
Expand Up @@ -102,6 +102,8 @@ Kenwood_TK-768,+Kenwood_TK-760,5-Dec-2022
Kenwood_TK-860,+Kenwood_TK-760,5-Dec-2022
Kenwood_TK-862,+Kenwood_TK-760,5-Dec-2022
Kenwood_TK-868,+Kenwood_TK-760,5-Dec-2022
LUITON_LT-580_UHF,@KC9HI,8-Dec-2022
LUITON_LT-580_VHF,@KC9HI,8-Dec-2022
LUITON_LT-588UV,@KC9HI,11-Nov-2022
Midland_DBR2500,+Retevis_RT95,13-Nov-2022
QYT_KT-8R,@KC9HI,11-Nov-2022
Expand Down Expand Up @@ -158,8 +160,15 @@ Retevis_RT76,@KC9HI,30-Nov-2022
Retevis_RT85,@KC9HI,5-Dec-2022
Retevis_RT95,@KC9HI,13-Nov-2022
Retevis_RT95_VOX,+Retevis_RT95,13-Nov-2022
Retevis_RT9000D_136-174,@KC9HI,8-Dec-2022
Retevis_RT9000D_220-260,@KC9HI,8-Dec-2022
Retevis_RT9000D_400-490,@KC9HI,8-Dec-2022
Retevis_RT9000D_66-88,@KC9HI,8-Dec-2022
TIDRADIO_TD-H6,@kk7ds,21-Oct-2022
TYT_TH-UV88,@KC9HI,5-Dec-2022
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
WACCOM_MINI-8900,@KC9HI,11-Nov-2022
Yaesu_FT-1500M,@f3sty,05-Dec-2022
Yaesu_FT-70D,@n8sqt,05-Dec-2022
Expand Down

0 comments on commit 4c70adc

Please sign in to comment.