Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduction of debug output and parsing of all package formats #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
output invalid data in aggregated form
successive messags of invalid frames are aggregated, and output at the
latest possible time (before something else is printed), possibly in
truncated form.
chrysn committed Dec 17, 2014
commit ebb931f13fa2177d82c3566773692cf7a5f2db47
39 changes: 30 additions & 9 deletions swodecoder.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import os
import sys
import struct
import itertools

class ITMDWTPacket(object):
pass
@@ -134,16 +135,35 @@ def InsaneVerbosePacketReceiver():

@coroutine
def PacketReceiverConsolePrinter(valid_address=-1):
while True:
f = yield
if not hasattr(f, "address"):
# Skip things like synchro packets
continue
if f.address == valid_address or valid_address == -1:
if (f.size == 1):
print(chr(f.data), end='')
invalid_buffer = []

def flush():
if invalid_buffer:
allinvalid = list(itertools.chain(*[x.bytes for x in invalid_buffer]))
if len(allinvalid) > 80:
print("Invalid data (%d byte): %r..%r"%(len(allinvalid), allinvalid[:40], allinvalid[-40:]))
else:
print("Channel %d: %d byte value: %d : %#x : %d" % (f.address, f.size, f.data, f.data, f.sdata))
print("Invalid data (%d byte): %r"%(len(allinvalid), allinvalid))
invalid_buffer[:] = []

try:
while True:
f = yield
if isinstance(f, InvalidData):
invalid_buffer.append(f)
continue
if not hasattr(f, "address"):
# Skip things like synchro packets
continue
if f.address == valid_address or valid_address == -1:
flush()
if (f.size == 1):
print(chr(f.data), end='')
else:
print("Channel %d: %d byte value: %d : %#x : %d" % (f.address, f.size, f.data, f.data, f.sdata))
#except GeneratorExit:
finally:
flush()



@@ -196,6 +216,7 @@ def chunker(ll, n):
if opts.follow:
time.sleep(0.5)
else:
parser.close()
print("# All finished!")
break