From 8439e0e5f3720be63ad6790be11b3ce438de6471 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Sat, 7 Jul 2012 11:04:49 -0700 Subject: [PATCH] Parser and error-handling changes. --- apps/modes_rx | 2 +- python/modes_parse.py | 11 ++++++++--- python/modes_print.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/modes_rx b/apps/modes_rx index bd3899e..cdcf7ad 100755 --- a/apps/modes_rx +++ b/apps/modes_rx @@ -227,7 +227,7 @@ if __name__ == '__main__': for out in outputs: try: out(msg.to_string()) - except ADSBError: + except air_modes.ADSBError: pass elif runner.done: diff --git a/python/modes_parse.py b/python/modes_parse.py index f628af2..cc445a2 100644 --- a/python/modes_parse.py +++ b/python/modes_parse.py @@ -75,9 +75,14 @@ class data_field: def get_bits(self, *args): startbit = args[0] num = args[1] - bits = (self.data \ - >> (self.get_numbits() - startbit - num + self.offset)) \ - & ((1 << num) - 1) + bits = 0 + try: + bits = (self.data \ + >> (self.get_numbits() - startbit - num + self.offset)) \ + & ((1 << num) - 1) + except ValueError: + #pass + print "Got short packet but expected long retrieving bits (%i, %i) with type %i" % (startbit, num, self.get_type()) return bits class bds09_reply(data_field): diff --git a/python/modes_print.py b/python/modes_print.py index 31deb98..94d19a1 100644 --- a/python/modes_print.py +++ b/python/modes_print.py @@ -217,7 +217,7 @@ class modes_output_print(modes_parse.modes_parse): retstr = "No handler for BDS1 == %i from %x" % (bds1, ecc) if(msgtype == 20): - retstr += " at %ift" % altitude + retstr += " at %ift" % alt else: retstr += " ident %x" % ident