[chirp_devel] [PATCH] [ft4] add progress bar cleanly [#6573]

DanClemmensen
Sun Mar 10 14:45:38 PDT 2019


# HG changeset patch
# User DanClemmensen <DanClemmensen at gmail.com>
# Date 1552254145 25200
#      Sun Mar 10 14:42:25 2019 -0700
# Node ID 019f22714b41afb5cb4c96fdd48335547a34a204
# Parent  8de0c148e8283dab86bfe8610fa4b4543784a503
[ft4] add progress bar cleanly [#6573]
add the bar but without the gratuitous change to
run_tests ;-)

diff -r 8de0c148e828 -r 019f22714b41 chirp/drivers/ft4.py
--- a/chirp/drivers/ft4.py	Fri Mar 08 10:38:00 2019 -0800
+++ b/chirp/drivers/ft4.py	Sun Mar 10 14:42:25 2019 -0700
@@ -237,7 +237,7 @@
             i += 1
             if i > toolong:
                 LOG.debug("Response too long. got" + util.hexprint(response))
-                raise errors.RadioError("Response too long.")
+                raise errors.RadioError("Response from radio too long.")
     return(response)
 
 
@@ -273,14 +273,18 @@
     return response
 
 
-def startcomms(radio):
+def startcomms(radio, way):
     """
     For either upload or download, put the radio into PROGRAM mode
     and check the radio's ID. In this preliminary version of the driver,
     the exact nature of the ID has been inferred from a single test case.
+        set up the progress bar
         send "PROGRAM" to command the radio into clone mode
         read the initial string (version?)
     """
+    progressbar = chirp_common.Status()
+    progressbar.msg = "Cloning " + way + " radio"
+    progressbar.max = radio.numblocks
     if b"QX" != sendcmd(radio.pipe, b"PROGRAM", 2):
         raise errors.RadioError("expected QX from radio.")
     id_response = sendcmd(radio.pipe, b'\x02', None)
@@ -290,11 +294,12 @@
             msg = "ID mismatch. Expected" + util.hexprint(radio.id_str)
             msg += ", Received:" + util.hexprint(id_response)
             LOG.warning(msg)
-            raise errors.RadioError("Incorrect ID.")
+            raise errors.RadioError("Incorrect ID read from radio.")
         else:
             msg = "ID suspect. Expected" + util.hexprint(radio.id_str)
             msg += ", Received:" + util.hexprint(id_response)
             LOG.warning(msg)
+    return progressbar
 
 
 def getblock(pipe, addr, image):
@@ -312,7 +317,7 @@
         raise errors.RadioError("Incorrect response to read.")
     if checkSum8(response[1:20]) != bytearray(response)[20]:
         LOG.debug(b"Bad checksum: " + util.hexprint(response))
-        raise errors.RadioError("bad block checksum.")
+        raise errors.RadioError("bad block checksum on read from radio.")
     image[addr:addr+16] = response[4:20]
 
 
@@ -326,9 +331,11 @@
     """
     image = bytearray(radio.get_memsize())
     pipe = radio.pipe  # Get the serial port connection
-    startcomms(radio)
+    progressbar = startcomms(radio, "from")
     for _i in range(radio.numblocks):
         getblock(pipe, 16 * _i, image)
+        progressbar.cur = _i
+        radio.status_fn(progressbar)
     sendcmd(pipe, b"END", 0)
     return memmap.MemoryMap(bytes(image))
 
@@ -351,10 +358,12 @@
       send "END"
     """
     pipe = radio.pipe  # Get the serial port connection
-    startcomms(radio)
+    progressbar = startcomms(radio, "to")
     data = get_mmap_data(radio)
     for _i in range(1, radio.numblocks):
         putblock(pipe, 16*_i, data[16*_i:16*(_i+1)])
+        progressbar.cur = _i
+        radio.status_fn(progressbar)
     sendcmd(pipe, b"END", 0)
     return
 # End serial transfer utilities



More information about the chirp_devel mailing list