Skip to content

Commit

Permalink
Bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pontus Nyman committed Mar 10, 2023
1 parent ae9b97b commit 5637a7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/puslib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 11 additions & 10 deletions src/puslib/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5637a7e

Please sign in to comment.