From 9aa76d51a01d419d30e16a8b6dd9ce1a8dda55cb Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 14 Mar 2018 17:05:10 +0100 Subject: [PATCH] tool/create_packet_log: report parsing error and continue --- tool/create_packet_log.py | 81 +++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/tool/create_packet_log.py b/tool/create_packet_log.py index 14b36322f..3fbfd8b97 100755 --- a/tool/create_packet_log.py +++ b/tool/create_packet_log.py @@ -104,41 +104,48 @@ if len(sys.argv) > 2: with open (outfile, 'wb') as fout: with open (infile, 'rt') as fin: packet_counter = 0 + line_conter = 0 for line in fin: - timestamp = None - # strip newlines - line = line.strip("\n\r") - # skip empyt lines - if len(line) == 0: - continue - parts = re.match('\[(.*)\] (.*)', line) - if parts and len(parts.groups()) == 2: - (timestamp, line) = parts.groups() - rest = chop(line,'CMD => ') - if rest: - handleHexPacket(fout, timestamp, 0, rest) - continue - rest = chop(line,'EVT <= ') - if rest: - handleHexPacket(fout, timestamp, 1, rest) - continue - rest = chop(line,'ACL => ') - if rest: - handleHexPacket(fout, timestamp, 2, rest) - continue - rest = chop(line,'ACL <= ') - if rest: - handleHexPacket(fout, timestamp, 3, rest) - continue - rest = chop(line,'SCO => ') - if rest: - handleHexPacket(fout, timestamp, 8, rest) - continue - rest = chop(line,'SCO <= ') - if rest: - handleHexPacket(fout, timestamp, 9, rest) - continue - rest = chop(line,'LOG -- ') - if rest: - line = rest - dumpPacket(fout, timestamp, 0xfc, line.encode('ascii')) + try: + line_conter += 1 + timestamp = None + # strip newlines + line = line.strip("\n\r") + # skip empyt lines + if len(line) == 0: + continue + parts = re.match('\[(.*)\] (.*)', line) + if parts and len(parts.groups()) == 2: + (timestamp, line) = parts.groups() + rest = chop(line,'CMD => ') + if rest: + handleHexPacket(fout, timestamp, 0, rest) + continue + rest = chop(line,'EVT <= ') + if rest: + handleHexPacket(fout, timestamp, 1, rest) + continue + rest = chop(line,'ACL => ') + if rest: + handleHexPacket(fout, timestamp, 2, rest) + continue + rest = chop(line,'ACL <= ') + if rest: + handleHexPacket(fout, timestamp, 3, rest) + continue + rest = chop(line,'SCO => ') + if rest: + handleHexPacket(fout, timestamp, 8, rest) + continue + rest = chop(line,'SCO <= ') + if rest: + handleHexPacket(fout, timestamp, 9, rest) + continue + rest = chop(line,'LOG -- ') + if rest: + line = rest + dumpPacket(fout, timestamp, 0xfc, line.encode('ascii')) + except: + print("Error in line %u: '%s'" % (line_conter, line)) + +print("\nPacket Log: %s" % outfile)