Command line tool cleanup.
@@ -13,6 +13,18 @@ __version__ = '13.0.0'
RE_CANDUMP = re.compile(r'^.* ([0-9A-F]+) \[\d\]\s*([0-9A-F ]*)$')
+def _mo_unpack(mo):
+ frame_id = mo.group(1)
+ frame_id = '0' * (8 - len(frame_id)) + frame_id
+ frame_id = binascii.unhexlify(frame_id)
+ frame_id = struct.unpack('>I', frame_id)[0]
+ data = mo.group(2)
+ data = data.replace(' ', '')
+ data = binascii.unhexlify(data)
+
+ return frame_id, data
+
+
def _do_decode(args):
dbf = db.load_file(args.dbfile)
decode_choices = not args.no_decode_choices
@@ -27,14 +39,10 @@ def _do_decode(args):
line = line.strip('\r\n')
mo = RE_CANDUMP.match(line)
- if mo:
- frame_id = mo.group(1)
- frame_id = '0' * (8 - len(frame_id)) + frame_id
- frame_id = binascii.unhexlify(frame_id)
- frame_id = struct.unpack('>I', frame_id)[0]
- data = mo.group(2)
- data = data.replace(' ', '')
- data = binascii.unhexlify(data)
+ if not mo:
+ continue
+
+ frame_id, data = _mo_unpack(mo)
line += ' :: '
try:
@@ -54,7 +62,7 @@ def _do_decode(args):
value = decoded_signals[signal.name]
if isinstance(value, str):
- value = "'" + value + "'"
+ value = "'{}'".format(value)
formatted_signals.append(
'{}: {}{}'.format(signal.name,
