[chirp_devel] [PATCH] [H777] Rework Serial Timeout

Jim Unroe
Sat Dec 19 13:29:01 PST 2020


# HG changeset patch
# User Jim Unroe <rock.unroe at gmail.com>
# Date 1608409102 18000
#      Sat Dec 19 15:18:22 2020 -0500
# Node ID 9bb169015ad5232a1915fe52eef87367ccbd70d1
# Parent  3ecdabd2fa7139961929bdca5060bb79b73a0ac4
[H777] Rework Serial Timeout

The previous patch has broken uploads for the classic BF-888s radios and
newer Retevis H777 models. The constanstant switching of the timeout to .5
before each block is sent and back to .25 after each block is sent on a
Windows computer creates "noise" that causes the apparently "faster"
radios to mis the "ack" returned by the radio which results in the upload
failing.

This patch resolves the issue by setting the serial timeout to .5 and leaving
it remain that way for all serial activity.

fixes #8197

diff -r 3ecdabd2fa71 -r 9bb169015ad5 chirp/drivers/h777.py
--- a/chirp/drivers/h777.py	Thu Dec 17 16:29:18 2020 -0500
+++ b/chirp/drivers/h777.py	Sat Dec 19 15:18:22 2020 -0500
@@ -95,6 +95,8 @@
 
 def _h777_enter_programming_mode(radio):
     serial = radio.pipe
+    # increase default timeout from .25 to .5 for all serial communications
+    serial.timeout = 0.5
 
     try:
         serial.write("\x02")
@@ -109,19 +111,15 @@
     elif ack != CMD_ACK:
         raise errors.RadioError("Radio refused to enter programming mode")
 
-    original_timeout = serial.timeout
     try:
         serial.write("\x02")
         # At least one version of the Baofeng BF-888S has a consistent
         # ~0.33s delay between sending the first five bytes of the
         # version data and the last three bytes. We need to raise the
         # timeout so that the read doesn't finish early.
-        serial.timeout = 0.5
         ident = serial.read(8)
     except:
         raise errors.RadioError("Error communicating with radio")
-    finally:
-        serial.timeout = original_timeout
 
     if not ident.startswith("P3107"):
         LOG.debug(util.hexprint(ident))
@@ -180,20 +178,16 @@
     LOG.debug("Writing Data:")
     LOG.debug(util.hexprint(cmd + data))
 
-    original_timeout = serial.timeout
     try:
         serial.write(cmd + data)
         # Time required to write data blocks varies between individual
         # radios of the Baofeng BF-888S model. The longest seen is
         # ~0.31s.
-        serial.timeout = 0.5
         if serial.read(1) != CMD_ACK:
             raise Exception("No ACK")
     except:
         raise errors.RadioError("Failed to send block "
                                 "to radio at %04x" % block_addr)
-    finally:
-        serial.timeout = original_timeout
 
 
 def do_download(radio):



More information about the chirp_devel mailing list