Skip to content

Commit

Permalink
tmd710: Fix some non-byteclean serial activity
Browse files Browse the repository at this point in the history
Fixes #10775
  • Loading branch information
kk7ds committed Nov 19, 2023
1 parent 7fd60d4 commit 0065834
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions chirp/drivers/tmd710.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ def _read_mem(radio):
resp0 = _command(radio.pipe, cmc, 260, W8S)
junk = _command(radio.pipe, ACK, 1, W8S)
if len(resp0) < 260:
junk = _command(radio.pipe, "E", 2, W8S)
junk = _command(radio.pipe, b"E", 2, W8S)
sx = "Block 0x%x read error: " % bkx
sx += "Got %i bytes, expected 260." % len(resp0)
LOG.error(sx)
Expand All @@ -1588,7 +1588,7 @@ def _read_mem(radio):
junk = _command(radio.pipe, ACK, 1, W8S)
_update_status(radio, status)
# Exit Prog mode, no TERM
resp = _command(radio.pipe, "E", 2, W8S) # Rtns 06 0d
resp = _command(radio.pipe, b"E", 2, W8S) # Rtns 06 0d
radio.pipe.baudrate = BAUD
return data

Expand All @@ -1607,27 +1607,27 @@ def _write_mem(radio):

imgadr = 0
radio.pipe.baudrate = BAUD
resp0 = _command(radio.pipe, "0M PROGRAM" + TERM, 3, W8S)
resp0 = _command(radio.pipe, b"0M PROGRAM" + TERM, 3, W8S)
# Read block 0 magic header thingy, save it
cmc = "R" + chr(0) + chr(0) + chr(4)
cmc = b"R" + bytes([0, 0, 4])
resp0 = _command(radio.pipe, cmc, 8, W8S)
mht0 = resp0[4:] # Expecting [57 00 00 04] 03 4b 01 ff
junk = _command(radio.pipe, ACK, 1, W8S)
cmc = "W" + chr(0) + chr(0) + chr(1) + chr(0x0ff)
cmc = b"W" + bytes([0, 0, 1, 0xff])
junk = _command(radio.pipe, cmc, 1, W8S) # responds ACK
cmc = "R" + chr(0x080) + chr(0) + chr(3)
cmc = b"R" + bytes([0x80, 0, 3])
resp = _command(radio.pipe, cmc, 7, W8S) # [57 80 00 03] 00 33 00
mht1 = resp[4:]
junk = _command(radio.pipe, ACK, 1, W8S)
cmc = "W" + chr(0x080) + chr(0) + chr(1) + chr(0x0ff)
cmc = b"W" + bytes([0x80, 0, 1, 0xff])
junk = _command(radio.pipe, cmc, 1, W8S)
imgadr = 4 # After 03 4b 01 ff
for bkx in range(0, radio._num_packets[0]):
cmc = "W" + chr(bkx) + chr(0) + chr(0)
cmc = b"W" + bytes([bkx, 0, 0])
imgstep = 256
if bkx == 0:
imgstep = 0x0fc
cmc = "W" + chr(0) + chr(4) + chr(imgstep)
cmc = b"W" + bytes([0, 4, imgstep])
cmc += radio.get_mmap()[imgadr:imgadr + imgstep]
else: # after first packet
cmc += radio.get_mmap()[imgadr:imgadr + imgstep]
Expand All @@ -1640,37 +1640,37 @@ def _write_mem(radio):
imgadr += imgstep
_update_status(radio, status) # UI Update
# write fe and ff blocks
cmc = "W" + chr(0x0fe) + chr(0x0f0) + chr(16)
cmc = b"W" + bytes([0xfe, 0xf0, 16])
cmc += radio.get_mmap()[imgadr:imgadr + 16]
resp0 = _command(radio.pipe, cmc, 1, W8S)
if resp0 != ACK:
LOG.error("Packet 0xfe Write error, no ACK.")
sx = "Radio failed to acknowledge upload packet!"
raise errors.RadioError(sx)
imgadr += 16
cmc = "W" + chr(0x0ff) + chr(0) + chr(0x090)
cmc = b"W" + bytes([0xff, 0, 0x90])
cmc += radio.get_mmap()[imgadr:imgadr + 0x090]
resp0 = _command(radio.pipe, cmc, 1, W8S)
if resp0 != ACK:
LOG.error("Packet 0xff Write error, no ACK.")
sx = "Radio failed to acknowledge upload packet!"
raise errors.RadioError(sx)
# Write mht1
cmc = "W" + chr(0x080) + chr(0) + chr(3) + mht1
cmc = b"W" + bytes([0x80, 0, 3]) + mht1
resp0 = _command(radio.pipe, cmc, 1, W8S)
if resp0 != ACK:
LOG.error("Mht1 Write error at 0x080 00 03 , no ACK.")
sx = "Radio failed to acknowledge upload packet!"
raise errors.RadioError(sx)
# and mht0
cmc = "W" + chr(0) + chr(0) + chr(4) + mht0
cmc = b"W" + bytes([0, 0, 4]) + mht0
resp0 = _command(radio.pipe, cmc, 1, W8S)
if resp0 != ACK:
LOG.error("Mht0 Write error at 00 00 04 , no ACK.")
sx = "Radio failed to acknowledge upload packet!"
raise errors.RadioError(sx)
# Write E to Exit PROG mode
resp = _command(radio.pipe, "E", 2, W8S)
resp = _command(radio.pipe, b"E", 2, W8S)
return

@directory.register
Expand Down Expand Up @@ -1976,7 +1976,7 @@ class KenwoodTMD710GRadio(KenwoodTMx710Radio):

def _make_command(self, cmd, addr, length, data=b''):
cmc = struct.pack('>IB', addr, length)
return cmd.encode() + cmc[1:] + data
return cmd + cmc[1:] + data

def _read_mem(radio):
""" Load the memory map """
Expand Down Expand Up @@ -2005,7 +2005,7 @@ def _read_mem(radio):
for bkx in range(0, radio._num_packets[blkn]):
addr = (radio._block_addr[blkn] << 8) | (bkx << 8)
resp0 = _command(radio.pipe,
radio._make_command('R', addr, 0),
radio._make_command(b'R', addr, 0),
radio._packet_size[blkn], W8S)
if len(resp0) < radio._packet_size[blkn]:
junk = _command(radio.pipe, b"E", 0, W8S)
Expand Down Expand Up @@ -2051,13 +2051,13 @@ def _write_mem(radio):
# Read block 0 magic header thingy, save it
addr = radio._block_addr[0] << 8
resp0 = _command(radio.pipe,
radio._make_command('R', addr, 4),
radio._make_command(b'R', addr, 4),
16, W8S)
mht0 = resp0[5:]
# Now get block 1 mht
addr = radio._block_addr[1] << 8
resp0 = _command(radio.pipe,
radio._make_command('R', addr, 5),
radio._make_command(b'R', addr, 5),
16, W8S)
mht1 = resp0[5:]
for blkn in range(0, radio._num_blocks):
Expand All @@ -2073,7 +2073,7 @@ def _write_mem(radio):
256]
else: # after first packet
data = radio.get_mmap()[imgadr:imgadr + 256]
cmc = radio._make_command('W', addr, 0, data)
cmc = radio._make_command(b'W', addr, 0, data)

resp0 = _command(radio.pipe, cmc, 6, W8S)
if bkx > 0 and resp0 != ACK:
Expand All @@ -2084,12 +2084,12 @@ def _write_mem(radio):
imgadr += 256
_update_status(radio, status) # UI Update
# Re-write magic headers
cmc = radio._make_command('W', (radio._block_addr[0] << 8) | 1, 3,
cmc = radio._make_command(b'W', (radio._block_addr[0] << 8) | 1, 3,
mht0[1:3] + b'\x32')
resp0 = _command(radio.pipe, cmc, 1, W8S)
cmc = radio._make_command('W', radio._block_addr[1] << 8, 5, mht1)
cmc = radio._make_command(b'W', radio._block_addr[1] << 8, 5, mht1)
resp0 = _command(radio.pipe, cmc, 1, W8S)
cmc = radio._make_command('Z', radio._block_addr[0], 1, mht0[0:1])
cmc = radio._make_command(b'Z', radio._block_addr[0], 1, mht0[0:1])
resp0 = _command(radio.pipe, cmc, 16, W8S)
# Write E to Exit PROG mode
resp = _command(radio.pipe, b"E", 0, W8S)
Expand Down

0 comments on commit 0065834

Please sign in to comment.