[chirp_devel] [PATCH 01/24] Fix style issues in some drivers (#2355)
Zach Welch
Tue Mar 3 00:37:56 PST 2015
# HG changeset patch
# User Zach Welch <zach at mandolincreekfarm.com>
# Fake Node ID 9859baf4234e7136fcafc090adcfc88d3340b285
Fix style issues in some drivers (#2355)
diff --git a/chirp/drivers/alinco.py b/chirp/drivers/alinco.py
index 9c70125..31bbbea 100644
--- a/chirp/drivers/alinco.py
+++ b/chirp/drivers/alinco.py
@@ -19,6 +19,7 @@ from chirp.settings import RadioSettingValueBoolean, RadioSettings
import time
+
DRX35_MEM_FORMAT = """
#seekto 0x0120;
u8 used_flags[25];
@@ -67,6 +68,7 @@ RLENGTH = 2 + 5 + 32 + 2
STEPS = [5.0, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0]
+
def isascii(data):
for byte in data:
if (ord(byte) < ord(" ") or ord(byte) > ord("~")) and \
@@ -74,6 +76,7 @@ def isascii(data):
return False
return True
+
def tohex(data):
if isascii(data):
return repr(data)
@@ -82,6 +85,7 @@ def tohex(data):
string += "%02X" % ord(byte)
return string
+
class AlincoStyleRadio(chirp_common.CloneModeRadio):
"""Base class for all known Alinco radios"""
_memsize = 0
@@ -204,12 +208,13 @@ class AlincoStyleRadio(chirp_common.CloneModeRadio):
def get_raw_memory(self, number):
return repr(self._memobj.memory[number])
+
DUPLEX = ["", "-", "+"]
TMODES = ["", "Tone", "", "TSQL"] + [""] * 12
TMODES[12] = "DTCS"
DCS_CODES = {
- "Alinco" : chirp_common.DTCS_CODES,
- "Jetstream" : [17] + chirp_common.DTCS_CODES,
+ "Alinco": chirp_common.DTCS_CODES,
+ "Jetstream": [17] + chirp_common.DTCS_CODES,
}
CHARSET = (["\x00"] * 0x30) + \
@@ -217,6 +222,7 @@ CHARSET = (["\x00"] * 0x30) + \
[chr(x + ord("A")) for x in range(0, 26)] + [" "] + \
list("\x00" * 128)
+
def _get_name(_mem):
name = ""
for i in _mem.name:
@@ -225,6 +231,7 @@ def _get_name(_mem):
name += CHARSET[i]
return name
+
def _set_name(mem, _mem):
name = [0x00] * 7
j = 0
@@ -251,6 +258,7 @@ ALINCO_TONES.remove(206.5)
ALINCO_TONES.remove(229.1)
ALINCO_TONES.remove(254.1)
+
class DRx35Radio(AlincoStyleRadio):
"""Base class for the DR-x35 radios"""
_range = [(118000000, 155000000)]
@@ -385,6 +393,7 @@ class DRx35Radio(AlincoStyleRadio):
self._set_extra(_mem, mem)
+
@directory.register
class DR03Radio(DRx35Radio):
"""Alinco DR03"""
@@ -400,6 +409,7 @@ class DR03Radio(DRx35Radio):
return len(filedata) == cls._memsize and \
filedata[0x64] == chr(0x00) and filedata[0x65] == chr(0x28)
+
@directory.register
class DR06Radio(DRx35Radio):
"""Alinco DR06"""
@@ -414,7 +424,8 @@ class DR06Radio(DRx35Radio):
def match_model(cls, filedata, filename):
return len(filedata) == cls._memsize and \
filedata[0x64] == chr(0x00) and filedata[0x65] == chr(0x50)
-
+
+
@directory.register
class DR135Radio(DRx35Radio):
"""Alinco DR135"""
@@ -430,6 +441,7 @@ class DR135Radio(DRx35Radio):
return len(filedata) == cls._memsize and \
filedata[0x64] == chr(0x01) and filedata[0x65] == chr(0x44)
+
@directory.register
class DR235Radio(DRx35Radio):
"""Alinco DR235"""
@@ -445,6 +457,7 @@ class DR235Radio(DRx35Radio):
return len(filedata) == cls._memsize and \
filedata[0x64] == chr(0x02) and filedata[0x65] == chr(0x22)
+
@directory.register
class DR435Radio(DRx35Radio):
"""Alinco DR435"""
@@ -460,6 +473,7 @@ class DR435Radio(DRx35Radio):
return len(filedata) == cls._memsize and \
filedata[0x64] == chr(0x04) and filedata[0x65] == chr(0x00)
+
@directory.register
class DJ596Radio(DRx35Radio):
"""Alinco DJ596"""
@@ -477,6 +491,7 @@ class DJ596Radio(DRx35Radio):
return len(filedata) == cls._memsize and \
filedata[0x64] == chr(0x45) and filedata[0x65] == chr(0x01)
+
@directory.register
class JT220MRadio(DRx35Radio):
"""Jetstream JT220"""
@@ -492,6 +507,7 @@ class JT220MRadio(DRx35Radio):
return len(filedata) == cls._memsize and \
filedata[0x60:0x64] == "2009"
+
@directory.register
class DJ175Radio(DRx35Radio):
"""Alinco DJ175"""
diff --git a/chirp/drivers/anytone.py b/chirp/drivers/anytone.py
index b7d722b..8755708 100644
--- a/chirp/drivers/anytone.py
+++ b/chirp/drivers/anytone.py
@@ -27,6 +27,7 @@ from chirp import util
from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings, \
RadioSettingValueList, RadioSettingValueString, RadioSettingValueBoolean
+
LOG = logging.getLogger(__name__)
_mem_format = """
@@ -74,12 +75,12 @@ struct memory {
#seekto 0x0030;
struct {
- char serial[16];
+ char serial[16];
} serial_no;
#seekto 0x0050;
struct {
- char date[16];
+ char date[16];
} version;
#seekto 0x0280;
@@ -110,6 +111,7 @@ struct memory memory[758];
struct memory memblk2[10];
"""
+
class FlagObj(object):
def __init__(self, flagobj, which):
self._flagobj = flagobj
@@ -155,18 +157,22 @@ class FlagObj(object):
def __repr__(self):
return repr(self._flagobj)
+
def _is_loc_used(memobj, loc):
return memobj.flags[loc / 2].get_raw() != "\xFF"
+
def _addr_to_loc(addr):
return (addr - 0x2000) / 32
+
def _should_send_addr(memobj, addr):
if addr < 0x2000 or addr >= 0x7EC0:
return True
else:
return _is_loc_used(memobj, _addr_to_loc(addr))
+
def _echo_write(radio, data):
try:
radio.pipe.write(data)
@@ -175,6 +181,7 @@ def _echo_write(radio, data):
print "Error writing to radio: %s" % e
raise errors.RadioError("Unable to write to radio")
+
def _read(radio, length):
try:
data = radio.pipe.read(length)
@@ -191,6 +198,7 @@ def _read(radio, length):
valid_model = ['QX588UV', 'HR-2040', 'DB-50M\x00', 'DB-750X']
+
def _ident(radio):
radio.pipe.setTimeout(1)
_echo_write(radio, "PROGRAM")
@@ -205,6 +213,7 @@ def _ident(radio):
print "Response was:\n%s" % util.hexprint(response)
raise errors.RadioError("Unsupported model")
+
def _finish(radio):
endframe = "\x45\x4E\x44"
_echo_write(radio, endframe)
@@ -213,12 +222,14 @@ def _finish(radio):
print "Got:\n%s" % util.hexprint(result)
raise errors.RadioError("Radio did not finish cleanly")
+
def _checksum(data):
cs = 0
for byte in data:
cs += ord(byte)
return cs % 256
+
def _send(radio, cmd, addr, length, data=None):
frame = struct.pack(">cHb", cmd, addr, length)
if data:
@@ -231,8 +242,8 @@ def _send(radio, cmd, addr, length, data=None):
result = radio.pipe.read(1)
if result != "\x06":
print "Ack was: %s" % repr(result)
- raise errors.RadioError("Radio did not accept block at %04x" % \
- addr)
+ raise errors.RadioError(
+ "Radio did not accept block at %04x" % addr)
return
result = _read(radio, length + 6)
LOG.debug("Got:\n%s" % util.hexprint(result))
@@ -255,6 +266,7 @@ def _send(radio, cmd, addr, length, data=None):
raise errors.RadioError("Block at 0x%04x failed checksum" % addr)
return data
+
def _download(radio):
_ident(radio)
@@ -282,6 +294,7 @@ def _download(radio):
return memmap.MemoryMap(data)
+
def _upload(radio):
_ident(radio)
@@ -302,6 +315,7 @@ def _upload(radio):
_finish(radio)
+
TONES = [62.5] + list(chirp_common.TONES)
TMODES = ['', 'Tone', 'DTCS', '']
DUPLEXES = ['', '-', '+', '']
@@ -527,6 +541,7 @@ class AnyTone5888UVRadio(chirp_common.CloneModeRadio,
def match_model(cls, filedata, filename):
return cls._file_ident in filedata[0x20:0x40]
+
@directory.register
class IntekHR2040Radio(AnyTone5888UVRadio):
"""Intek HR-2040"""
@@ -534,6 +549,7 @@ class IntekHR2040Radio(AnyTone5888UVRadio):
MODEL = "HR-2040"
_file_ident = "HR-2040"
+
@directory.register
class PolmarDB50MRadio(AnyTone5888UVRadio):
"""Polmar DB-50M"""
@@ -541,6 +557,7 @@ class PolmarDB50MRadio(AnyTone5888UVRadio):
MODEL = "DB-50M"
_file_ident = "DB-50M"
+
@directory.register
class PowerwerxDB750XRadio(AnyTone5888UVRadio):
"""Powerwerx DB-750X"""
diff --git a/tools/cpep8.blacklist b/tools/cpep8.blacklist
index d877a24..b90eb3f 100644
--- a/tools/cpep8.blacklist
+++ b/tools/cpep8.blacklist
@@ -1,8 +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/alinco.py
-./chirp/drivers/anytone.py
./chirp/drivers/ap510.py
./chirp/drivers/baofeng_uv3r.py
./chirp/drivers/bjuv55.py
More information about the chirp_devel
mailing list