# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 604a5b1688d04c6379f025c5f13423ad256cfabe
Fix style issues in ic9x_ll.py (#2355)
diff --git a/chirp/drivers/ic9x_ll.py b/chirp/drivers/ic9x_ll.py index 42a40ed..c23ab10 100644 --- a/chirp/drivers/ic9x_ll.py +++ b/chirp/drivers/ic9x_ll.py @@ -30,20 +30,26 @@ DTCS_POL = ["NN", "NR", "RN", "RR"] MEM_LEN = 34 DV_MEM_LEN = 60
+ # Dirty hack until I clean up this IC9x mess class IC9xMemory(chirp_common.Memory): """A dirty hack to stash bank information in a memory""" _bank = None _bank_index = 0 + def __init__(self): chirp_common.Memory.__init__(self) + + class IC9xDVMemory(chirp_common.DVMemory): """See above dirty hack""" _bank = None _bank_index = 0 + def __init__(self): chirp_common.DVMemory.__init__(self)
+ def _ic9x_parse_frames(buf): frames = []
@@ -65,10 +71,11 @@ def _ic9x_parse_frames(buf): except errors.InvalidDataError, e: print "Broken frame: %s" % e
- #print "Parsed %i frames" % len(frames) + # print "Parsed %i frames" % len(frames)
return frames
+ def ic9x_send(pipe, buf): """Send @buf to @pipe, wrapped in a header and trailer. Attempt to read any response frames, which are returned as a list""" @@ -76,7 +83,7 @@ def ic9x_send(pipe, buf): # Add header and trailer realbuf = "\xfe\xfe" + buf + "\xfd"
- #print "Sending:\n%s" % util.hexprint(realbuf) + # print "Sending:\n%s" % util.hexprint(realbuf)
pipe.write(realbuf) pipe.flush() @@ -91,6 +98,7 @@ def ic9x_send(pipe, buf):
return _ic9x_parse_frames(data)
+ class IC92Frame: """IC9x frame base class""" def get_vfo(self): @@ -149,7 +157,8 @@ class IC92Frame:
def __getslice__(self, start, end): return self._map[start+4:end+4] - + + class IC92GetBankFrame(IC92Frame): """A frame for requesting bank information""" def __init__(self): @@ -163,6 +172,7 @@ class IC92GetBankFrame(IC92Frame):
return rframes
+ class IC92BankFrame(IC92Frame): """A frame for bank information""" def __init__(self): @@ -186,6 +196,7 @@ class IC92BankFrame(IC92Frame): """Set the letter for the bank (A-Z)""" self[0] = ident[0]
+ class IC92MemClearFrame(IC92Frame): """A frame for clearing (erasing) a memory""" def __init__(self, loc): @@ -195,6 +206,7 @@ class IC92MemClearFrame(IC92Frame):
self[0] = struct.pack(">BHB", 1, int("%i" % loc, 16), 0xFF)
+ class IC92MemGetFrame(IC92Frame): """A frame for requesting a memory""" def __init__(self, loc, iscall=False): @@ -208,6 +220,7 @@ class IC92MemGetFrame(IC92Frame):
self[0] = struct.pack(">BH", call, int("%i" % loc, 16))
+ class IC92GetCallsignFrame(IC92Frame): """A frame for getting callsign information""" def __init__(self, calltype, number): @@ -215,9 +228,10 @@ class IC92GetCallsignFrame(IC92Frame):
self[0] = chr(number)
+ class IC92CallsignFrame(IC92Frame): """A frame to communicate callsign information""" - command = 0 # Invalid + command = 0 # Invalid width = 8
def __init__(self, number=0, callsign=""): @@ -231,18 +245,21 @@ class IC92CallsignFrame(IC92Frame): """Return the actual callsign""" return self[1:self.width+1].rstrip()
+ class IC92YourCallsignFrame(IC92CallsignFrame): """URCALL frame""" - command = 6 # Your + command = 6 # Your +
class IC92RepeaterCallsignFrame(IC92CallsignFrame): """RPTCALL frame""" - command = 7 # Repeater + command = 7 # Repeater +
class IC92MyCallsignFrame(IC92CallsignFrame): """MYCALL frame""" - command = 8 # My - width = 12 # 4 bytes for /STID + command = 8 # My + width = 12 # 4 bytes for /STID
MEMORY_FRAME_FORMAT = """ struct { @@ -276,6 +293,7 @@ struct { } mem[1]; """
+ class IC92MemoryFrame(IC92Frame): """A frame for communicating memory information""" def __init__(self): @@ -393,6 +411,7 @@ class IC92MemoryFrame(IC92Frame):
return mem
+ def _send_magic_4800(pipe): cmd = "\x01\x80\x19" magic = ("\xFE" * 25) + cmd @@ -402,9 +421,10 @@ def _send_magic_4800(pipe): return resp[0].get_raw()[0] == "\x80" return True
+ def _send_magic_38400(pipe): cmd = "\x01\x80\x19" - #rsp = "\x80\x01\x19" + # rsp = "\x80\x01\x19" magic = ("\xFE" * 400) + cmd for _i in [0, 1]: resp = ic9x_send(pipe, magic) @@ -412,6 +432,7 @@ def _send_magic_38400(pipe): return resp[0].get_raw()[0] == "\x80" return False
+ def send_magic(pipe): """Send the magic incantation to wake up an ic9x radio""" if pipe.getBaudrate() == 38400: @@ -437,8 +458,9 @@ def send_magic(pipe): pipe.setBaudrate(4800) raise errors.RadioError("Radio not responding") else: - raise errors.InvalidDataError("Radio in unknown state (%i)" % \ - pipe.getBaudrate()) + raise errors.InvalidDataError("Radio in unknown state (%i)" % + pipe.getBaudrate()) +
def get_memory_frame(pipe, vfo, number): """Get the memory frame for @vfo and @number via @pipe""" @@ -453,6 +475,7 @@ def get_memory_frame(pipe, vfo, number):
return frame.send(pipe)
+ def get_memory(pipe, vfo, number): """Get a memory object for @vfo and @number via @pipe""" rframe = get_memory_frame(pipe, vfo, number) @@ -468,20 +491,22 @@ def get_memory(pipe, vfo, number):
return mf.get_memory()
+ def set_memory(pipe, vfo, memory): """Set memory @memory on @vfo via @pipe""" frame = IC92MemoryFrame() frame.set_memory(memory) frame.set_vfo(vfo)
- #print "Sending (%i):" % (len(frame.get_raw())) - #print util.hexprint(frame.get_raw()) + # print "Sending (%i):" % (len(frame.get_raw())) + # print util.hexprint(frame.get_raw())
rframe = frame.send(pipe)
if rframe.get_raw()[2] != "\xfb": - raise errors.InvalidDataError("Radio reported error:\n%s" %\ - util.hexprint(rframe.get_payload())) + raise errors.InvalidDataError("Radio reported error:\n%s" % + util.hexprint(rframe.get_payload())) +
def erase_memory(pipe, vfo, number): """Erase memory @number on @vfo via @pipe""" @@ -492,6 +517,7 @@ def erase_memory(pipe, vfo, number): if rframe.get_raw()[2] != "\xfb": raise errors.InvalidDataError("Radio reported error")
+ def get_banks(pipe, vfo): """Get banks for @vfo via @pipe""" frame = IC92GetBankFrame() @@ -511,9 +537,10 @@ def get_banks(pipe, vfo): bframe.from_frame(rframes[i])
banks.append(bframe.get_name().rstrip()) - + return banks
+ def set_banks(pipe, vfo, banks): """Set banks for @vfo via @pipe""" for i in range(0, 26): @@ -526,6 +553,7 @@ def set_banks(pipe, vfo, banks): if rframe.get_payload() != "\xfb": raise errors.InvalidDataError("Radio reported error")
+ def get_call(pipe, cstype, number): """Get @cstype callsign @number via @pipe""" cframe = IC92GetCallsignFrame(cstype.command, number) @@ -537,6 +565,7 @@ def get_call(pipe, cstype, number):
return cframe.get_callsign()
+ def set_call(pipe, cstype, number, call): """Set @cstype @call at position @number via @pipe""" cframe = cstype(number, call) diff --git a/tools/cpep8.blacklist b/tools/cpep8.blacklist index 6cca27c..f88f718 100644 --- a/tools/cpep8.blacklist +++ b/tools/cpep8.blacklist @@ -1,7 +1,6 @@ # cpep8.blacklist: The list of files that do not meet PEP8 standards. # DO NOT ADD NEW FILES!! Instead, fix the code to be compliant. # Over time, this list should shrink and (eventually) be eliminated. -./chirp/drivers/ic9x_ll.py ./chirp/drivers/icf.py ./chirp/drivers/icq7.py ./chirp/drivers/ict70.py