added try except block

This commit is contained in:
Robin Müller 2021-12-15 11:19:19 +01:00
parent f6a3f79220
commit eca5bba1d8
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -26,17 +26,21 @@ def ccsds_tm_handler(apid: int, raw_tm_packet: bytearray, tmtc_printer: TmTcPrin
def pus_factory_hook(raw_tm_packet: bytearray, tmtc_printer: TmTcPrinter): def pus_factory_hook(raw_tm_packet: bytearray, tmtc_printer: TmTcPrinter):
service_type = raw_tm_packet[7] service_type = raw_tm_packet[7]
tm_packet = None tm_packet = None
if service_type == 1: try:
tm_packet = Service1TMExtended.unpack(raw_telemetry=raw_tm_packet) if service_type == 1:
if service_type == 3: tm_packet = Service1TMExtended.unpack(raw_telemetry=raw_tm_packet)
tm_packet = Service3TM.unpack(raw_telemetry=raw_tm_packet, custom_hk_handling=False) if service_type == 3:
if service_type == 5: tm_packet = Service3TM.unpack(raw_telemetry=raw_tm_packet, custom_hk_handling=False)
tm_packet = Service5TM.unpack(raw_telemetry=raw_tm_packet) if service_type == 5:
if service_type == 8: tm_packet = Service5TM.unpack(raw_telemetry=raw_tm_packet)
tm_packet = Service8TM.unpack(raw_telemetry=raw_tm_packet) if service_type == 8:
if service_type == 17: tm_packet = Service8TM.unpack(raw_telemetry=raw_tm_packet)
tm_packet = Service17TMExtended.unpack(raw_telemetry=raw_tm_packet) if service_type == 17:
if tm_packet is None: tm_packet = Service17TMExtended.unpack(raw_telemetry=raw_tm_packet)
LOGGER.info(f'The service {service_type} is not implemented in Telemetry Factory') if tm_packet is None:
tm_packet = PusTelemetry.unpack(raw_telemetry=raw_tm_packet) LOGGER.info(f'The service {service_type} is not implemented in Telemetry Factory')
tmtc_printer.print_telemetry(packet_if=tm_packet, info_if=tm_packet, print_raw_tm=False) tm_packet = PusTelemetry.unpack(raw_telemetry=raw_tm_packet)
tmtc_printer.print_telemetry(packet_if=tm_packet, info_if=tm_packet, print_raw_tm=False)
except ValueError:
# TODO: Log faulty packet
LOGGER.warning("Invalid packet format detected")