[chirp_devel] [PATCH] [TK-270] Refactor for simplicity and readability. #4731

Tom Hayward
Thu Apr 13 17:32:55 PDT 2017


# HG changeset patch
# User Tom Hayward <tom at tomh.us>
# Date 1492129914 25200
#      Thu Apr 13 17:31:54 2017 -0700
# Node ID 8dfb3497b058935076b04e0b7926046d4190bf74
# Parent  de0318acd4a4dc92fa1e16c2d86bab03fa97beed
[TK-270] Refactor for simplicity and readability. #4731

- Rename radio ID function of obviousness.
- Use standard string reversal trick instead of for loop.

diff -r de0318acd4a4 -r 8dfb3497b058 chirp/drivers/tk270.py
--- a/chirp/drivers/tk270.py	Thu Apr 13 17:26:54 2017 -0700
+++ b/chirp/drivers/tk270.py	Thu Apr 13 17:31:54 2017 -0700
@@ -292,21 +292,16 @@
         handshake(radio, "Rx error in block %03i" % addr)
 
 
-def get_rid(data):
+def get_radio_id(data):
     """Extract the radio identification from the firmware"""
-    rid = data[0x03d0:0x03d8]
-    # we have to invert rid
-    nrid = ""
-    for i in range(1, len(rid) + 1):
-        nrid += rid[-i]
-    rid = nrid
-
-    return rid
+    # Reverse the radio id string. MemoryMap does not support the step/stride
+    # slice argument, so it is first sliced to a str then reversed.
+    return data[0x03d0:0x03d8][::-1]
 
 
 def model_match(cls, data):
     """Match the opened/downloaded image to the correct version"""
-    rid = get_rid(data)
+    rid = get_radio_id(data)
 
     # DEBUG
     #print("Full ident string is %s" % util.hexprint(rid))
@@ -408,7 +403,7 @@
     def set_variant(self):
         """Select and set the correct variables for the class acording
         to the correct variant of the radio"""
-        rid = get_rid(self._mmap)
+        rid = get_radio_id(self._mmap)
 
         # indentify the radio variant and set the enviroment to it's values
         try:



More information about the chirp_devel mailing list