From 5637a7ead8fab94498d37327996129adfce48e5a Mon Sep 17 00:00:00 2001 From: Pontus Nyman Date: Fri, 10 Mar 2023 15:15:35 +0100 Subject: [PATCH] Bug fix. --- src/puslib/__init__.py | 2 +- src/puslib/packet.py | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/puslib/__init__.py b/src/puslib/__init__.py index 8e9ba8d..affd4d8 100644 --- a/src/puslib/__init__.py +++ b/src/puslib/__init__.py @@ -10,7 +10,7 @@ if sys.version_info < _MIN_PYTHON: sys.exit(f"Python {_MIN_PYTHON[0]}.{_MIN_PYTHON[1]} or later is required.\n", 1) -__version__ = "0.2.3" +__version__ = "0.2.4" class PusPolicy: diff --git a/src/puslib/packet.py b/src/puslib/packet.py index b7b1b7c..6599420 100644 --- a/src/puslib/packet.py +++ b/src/puslib/packet.py @@ -252,19 +252,20 @@ def app_data(self): def serialize(self): ccsds_header = super().serialize() - # First static part of secondary header - tmp = self.secondary_header.pus_version << 4 | self.secondary_header.ack_flags - values = [tmp, self.secondary_header.service_type, self.secondary_header.service_subtype] - ccsds_sec_header_static = _COMMON_SEC_HDR_STRUCT.pack(*values) + if self.header.secondary_header_flag: + # First static part of secondary header + tmp = self.secondary_header.pus_version << 4 | self.secondary_header.ack_flags + values = [tmp, self.secondary_header.service_type, self.secondary_header.service_subtype] + ccsds_sec_header_static = _COMMON_SEC_HDR_STRUCT.pack(*values) - # Last "optional" part of secondary header - if self.secondary_header.source is not None: - ccsds_sec_header_source = self.secondary_header.source.to_bytes(self._SOURCE_FIELD_SIZE, byteorder='big') - else: - ccsds_sec_header_source = bytes() + # Last "optional" part of secondary header + if self.secondary_header.source is not None: + ccsds_sec_header_source = self.secondary_header.source.to_bytes(self._SOURCE_FIELD_SIZE, byteorder='big') + else: + ccsds_sec_header_source = bytes() # Packet error control - packet_without_pec = ccsds_header + ccsds_sec_header_static + ccsds_sec_header_source + self.payload + packet_without_pec = ccsds_header + (ccsds_sec_header_static + ccsds_sec_header_source if self.header.secondary_header_flag else bytes()) + (self.payload if self.header.secondary_header_flag else bytes()) if self.has_pec: mem_view = memoryview(packet_without_pec) pec = crc_ccitt_calculate(mem_view)