Skip to content

Commit

Permalink
closing files correctly in log2csv, debug for missing message types
Browse files Browse the repository at this point in the history
  • Loading branch information
natronics committed Jul 28, 2014
1 parent 50c4a49 commit 77383c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 13 additions & 2 deletions psas_packet/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,23 @@ def read(self):
while buff != b'':
try:
bytes_read, data = messages.decode(buff)

buff = buff[bytes_read:]
yield data

# check boundary
if len(buff) < 4:
b = self.fh.read(1 << 20) # 1 MB
# Check that we didn't actually hit the end of the file
if b == b'':
print('boundary?')
break
buff += b
except (messages.MessageSizeError):
b = self.fh.read(1 << 20) # 1 MB
# Check that we didn't actually hit the end of the file
if b == b'':
print('end?')
break
buff += b

Expand Down Expand Up @@ -209,5 +220,5 @@ def log2csv(f_in):
f_out.write(","+str(data[member['key']]))
f_out.write('\n')

for f_out in files:
f_out.close()
for fourcc, fh in files.items():
fh.close()
5 changes: 3 additions & 2 deletions psas_packet/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def decode(buff):
# Don't recognize it. Skip it but make a record that we tried to unpack
if message_cls is None:
# Debug
print(printable(fourcc), length)
#print("Skipped unknown header!", fourcc)
print('')
print("Skipped unknown header: "+printable(fourcc))
print('')
return HEADER.size + length, (printable(fourcc), {'timestamp': timestamp})

unpacked = message_cls.decode(buff[HEADER.size:HEADER.size+length])
Expand Down

0 comments on commit 77383c6

Please sign in to comment.