From ba42d0f63bbd3f420b91343d6cd74048b9c45fd7 Mon Sep 17 00:00:00 2001 From: Yahya Al-Shamali Date: Sat, 21 Oct 2023 03:32:14 -0600 Subject: [PATCH] optimize beaconDecoder --- src/beaconDecoder.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/beaconDecoder.py b/src/beaconDecoder.py index fa98601..4a05ee1 100644 --- a/src/beaconDecoder.py +++ b/src/beaconDecoder.py @@ -54,18 +54,15 @@ def beaconBase64Decode(self): def beaconParseData(self): packet_num_offset = 4 beacon_ID = 99 - beacon_port = 1 + beacon_port = 1 try: - if self.decoded_data[packet_num_offset] == 1: - self.decoded_data[:0] = (1).to_bytes(1,'big') - return self.parser.parseReturnValue(beacon_ID, beacon_port, self.decoded_data) - elif self.decoded_data[packet_num_offset] == 2: - self.decoded_data[:0] = (2).to_bytes(1,'big') + if self.decoded_data[packet_num_offset] in {1, 2}: + self.decoded_data[:0] = self.decoded_data[packet_num_offset].to_bytes(1,'big') return self.parser.parseReturnValue(beacon_ID, beacon_port, self.decoded_data) else: print("Invalid beacon packet number") - except: + except Exception: print("Unable to parse packet data") return None