# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 3ea42ad77e56174f669e7f4ea0502435fec77e04
Fix style issues in ft50_ll.py (#2355)
diff --git a/chirp/drivers/ft50_ll.py b/chirp/drivers/ft50_ll.py index c38b4f9..7d93d62 100644 --- a/chirp/drivers/ft50_ll.py +++ b/chirp/drivers/ft50_ll.py @@ -22,34 +22,36 @@ MEM_LOC_BASE = 0x00AB MEM_LOC_SIZE = 16
POS_DUPLEX = 1 -POS_TMODE = 2 -POS_TONE = 2 -POS_DTCS = 3 -POS_MODE = 4 -POS_FREQ = 5 +POS_TMODE = 2 +POS_TONE = 2 +POS_DTCS = 3 +POS_MODE = 4 +POS_FREQ = 5 POS_OFFSET = 9 -POS_NAME = 11 +POS_NAME = 11
-POS_USED = 0x079C +POS_USED = 0x079C
CHARSET = [str(x) for x in range(0, 10)] + \ [chr(x) for x in range(ord("A"), ord("Z")+1)] + \ list(" ()+--*/???|0123456789")
+ def send(s, data): s.write(data) r = s.read(len(data)) if len(r) != len(data): raise errors.RadioError("Failed to read echo")
+ def read_exact(s, count): data = "" i = 0 while len(data) < count: if i == 3: print util.hexprint(data) - raise errors.RadioError("Failed to read %i (%i) from radio" % (count, - len(data))) + raise errors.RadioError("Failed to read %i (%i) from radio" % + (count, len(data))) elif i > 0: print "Retry %i" % i data += s.read(count - len(data)) @@ -57,6 +59,7 @@ def read_exact(s, count):
return data
+ def download(radio): data = ""
@@ -69,7 +72,7 @@ def download(radio): else: step = block for i in range(0, block, step): - #data += read_exact(radio.pipe, step) + # data += read_exact(radio.pipe, step) chunk = radio.pipe.read(step*2) print "Length of chunk: %i" % len(chunk) data += chunk @@ -92,102 +95,117 @@ def download(radio):
return memmap.MemoryMap(data)
+ def get_mem_offset(number): return MEM_LOC_BASE + (number * MEM_LOC_SIZE)
+ def get_raw_memory(map, number): pos = get_mem_offset(number) return memmap.MemoryMap(map[pos:pos+MEM_LOC_SIZE])
+ def get_freq(mmap): khz = (int("%02x" % (ord(mmap[POS_FREQ])), 10) * 100000) + \ (int("%02x" % ord(mmap[POS_FREQ+1]), 10) * 1000) + \ (int("%02x" % ord(mmap[POS_FREQ+2]), 10) * 10) return khz / 10000.0
+ def set_freq(mmap, freq): val = util.bcd_encode(int(freq * 1000), width=6)[:3] mmap[POS_FREQ] = val
+ def get_tmode(mmap): val = ord(mmap[POS_TMODE]) & 0xC0
tmodemap = { - 0x00 : "", - 0x40 : "Tone", - 0x80 : "TSQL", - 0xC0 : "DTCS", + 0x00: "", + 0x40: "Tone", + 0x80: "TSQL", + 0xC0: "DTCS", } - + return tmodemap[val]
+ def set_tmode(mmap, tmode): val = ord(mmap[POS_TMODE]) & 0x3F
tmodemap = { - "" : 0x00, - "Tone" : 0x40, - "TSQL" : 0x80, - "DTCS" : 0xC0, + "": 0x00, + "Tone": 0x40, + "TSQL": 0x80, + "DTCS": 0xC0, }
val |= tmodemap[tmode]
mmap[POS_TMODE] = val
+ def get_tone(mmap): val = ord(mmap[POS_TONE]) & 0x3F
return chirp_common.TONES[val]
+ def set_tone(mmap, tone): val = ord(mmap[POS_TONE]) & 0xC0
mmap[POS_TONE] = val | chirp_common.TONES.index(tone)
+ def get_dtcs(mmap): val = ord(mmap[POS_DTCS])
return chirp_common.DTCS_CODES[val]
+ def set_dtcs(mmap, dtcs): mmap[POS_DTCS] = chirp_common.DTCS_CODES.index(dtcs)
+ def get_offset(mmap): khz = (int("%02x" % ord(mmap[POS_OFFSET]), 10) * 10) + \ (int("%02x" % (ord(mmap[POS_OFFSET+1]) >> 4), 10) * 1)
return khz / 1000.0
+ def set_offset(mmap, offset): val = util.bcd_encode(int(offset * 1000), width=4)[:3] - print "Offfset:\n%s"% util.hexprint(val) + print "Offfset:\n%s" % util.hexprint(val) mmap[POS_OFFSET] = val
+ def get_duplex(mmap): val = ord(mmap[POS_DUPLEX]) & 0x03
dupmap = { - 0x00 : "", - 0x01 : "-", - 0x02 : "+", - 0x03 : "split", + 0x00: "", + 0x01: "-", + 0x02: "+", + 0x03: "split", }
return dupmap[val]
+ def set_duplex(mmap, duplex): val = ord(mmap[POS_DUPLEX]) & 0xFC
dupmap = { - "" : 0x00, - "-" : 0x01, - "+" : 0x02, - "split" : 0x03, + "": 0x00, + "-": 0x01, + "+": 0x02, + "split": 0x03, } - + mmap[POS_DUPLEX] = val | dupmap[duplex]
+ def get_name(mmap): name = "" for x in mmap[POS_NAME:POS_NAME+4]: @@ -196,44 +214,50 @@ def get_name(mmap): name += CHARSET[ord(x)] return name
+ def set_name(mmap, name): val = "" for i in name[:4].ljust(4): val += chr(CHARSET.index(i)) mmap[POS_NAME] = val
+ def get_mode(mmap): val = ord(mmap[POS_MODE]) & 0x03
modemap = { - 0x00 : "FM", - 0x01 : "AM", - 0x02 : "WFM", - 0x03 : "WFM", + 0x00: "FM", + 0x01: "AM", + 0x02: "WFM", + 0x03: "WFM", }
return modemap[val]
+ def set_mode(mmap, mode): val = ord(mmap[POS_MODE]) & 0xCF
modemap = { - "FM" : 0x00, - "AM" : 0x01, - "WFM" : 0x02, + "FM": 0x00, + "AM": 0x01, + "WFM": 0x02, }
mmap[POS_MODE] = val | modemap[mode]
+ def get_used(mmap, number): return ord(mmap[POS_USED + number]) & 0x01
+ def set_used(mmap, number, used): val = ord(mmap[POS_USED + number]) & 0xFC if used: val |= 0x03 mmap[POS_USED + number] = val - + + def get_memory(map, number): index = number - 1 mmap = get_raw_memory(map, index) @@ -255,6 +279,7 @@ def get_memory(map, number):
return mem
+ def set_memory(_map, mem): index = mem.number - 1 mmap = get_raw_memory(_map, index) @@ -276,10 +301,12 @@ def set_memory(_map, mem):
return _map
+ def erase_memory(map, number): set_used(map, number-1, False) return map
+ def update_checksum(map): cs = 0 for i in range(0, 3722): diff --git a/tools/cpep8.blacklist b/tools/cpep8.blacklist index 81065eb..c584806 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/ft50_ll.py ./chirp/drivers/ft60.py ./chirp/drivers/ft7800.py ./chirp/drivers/ft90.py