Skip to content

Commit

Permalink
fix bug in log2csv where there is unknown packets, bump version number
Browse files Browse the repository at this point in the history
  • Loading branch information
natronics committed Jul 9, 2014
1 parent 32b8af6 commit 253f876
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion psas_packet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__version__ = '0.1.14'
__version__ = '0.1.15'
43 changes: 36 additions & 7 deletions psas_packet/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,40 @@ def decode_block(block):
# figure out what type it is based on FOURCC, and get that message class
message_cls = PSAS.get(info['fourcc'], None)

if message_cls is None:
print("Unknown header!", info['fourcc'])
return HEADER.size + info['length'], {'fourcc': info['fourcc']}

# Yay! We know about this type, lets unpack it
if message_cls is not None:
if len(block) < HEADER.size+message_cls.size:
raise(BlockSize)
return
unpacked = message_cls.decode(block[HEADER.size:HEADER.size+message_cls.size])
return HEADER.size+message_cls.size, {info['fourcc']: dict({'timestamp': info['timestamp']}, **unpacked)}

if len(block) < HEADER.size+message_cls.size:
raise(BlockSize)
return
unpacked = message_cls.decode(block[HEADER.size:HEADER.size+message_cls.size])
return HEADER.size+message_cls.size, {info['fourcc']: dict({'timestamp': info['timestamp']}, **unpacked)}


class Network(object):

def __init__(self, listener):
self.listener = listener

def listen(self):
with self.listener(35001) as listen:
buff = listen.listen()
if buff is not None:
seq = 0
for i, b in enumerate(buff[:4]):
seq = seq + (ord(b) << (3-i))
yield seq
buff = buff[4:]
entries = []
while buff != '':
try:
bytes_read, data = decode_block(buff)
buff = buff[bytes_read:]
yield data
except:
pass

class BinFile(object):
"""Read from a binary log file
Expand Down Expand Up @@ -101,3 +127,6 @@ def read(self):
if b == b'':
break
buff += b
except:
#print(buff[:100])
pass
2 changes: 1 addition & 1 deletion psas_packet/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, listen_port, bind=''):

self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.socket.bind((self.bind_addr, self.listen_port))
self.socket.settimeout(0.01)
self.socket.settimeout(1)

def __enter__(self):
return self
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='psas_packet',
version='0.1.14',
version='0.1.15',
description='serializer for PSAS data standards',
long_description=open('README.rst').read(),
author='Nathan Bergey',
Expand Down

0 comments on commit 253f876

Please sign in to comment.