Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
Removing unused fields and extra whitespace.
  • Loading branch information
bcwaldon committed Sep 20, 2024
1 parent 179b51a commit fa05d52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions satcom/openlst/client_packet_lib.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pydantic import BaseModel

from satcom.utils import utils

CLIENT_PACKET_ASM = [0x22, 0x69]

CLIENT_PACKET_HEADER_LENGTH = 7


class ClientPacketHeader(BaseModel):
length: int = 0
hardware_id: int = 0
Expand All @@ -27,7 +29,7 @@ def err(self):

def to_bytes(self):
"""Packs client packet header metadata into a bytearray"""
bs = bytearray(CLIENT_PACKET_HEADER_LENGTH) # Create empty bytearray of header length
bs = bytearray(CLIENT_PACKET_HEADER_LENGTH) # Create empty bytearray of header length

bs[0] = self.length
bs[1:3] = utils.pack_ushort_little_endian(self.hardware_id)
Expand All @@ -42,7 +44,7 @@ def from_bytes(cls, bs: bytearray):
"""Hydrates the client packet header metadata from a bytearray"""
if len(bs) != CLIENT_PACKET_HEADER_LENGTH:
raise ValueError('unexpected header length')

obj = cls(
length = bs[0],
hardware_id = utils.unpack_ushort_little_endian(bs[1:3]),
Expand Down
10 changes: 5 additions & 5 deletions satcom/openlst/space_packet_lib.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from satcom.utils import utils
from pydantic import BaseModel, ConfigDict

SPACE_PACKET_PREAMBLE = [0xAA, 0xAA, 0xAA, 0xAA]
SPACE_PACKET_ASM = [0xD3, 0x91, 0xD3, 0x91]

SPACE_PACKET_HEADER_LENGTH = 6
SPACE_PACKET_FOOTER_LENGTH = 4
CRC16_CHECKSUM_LENGTH_BYTES = 2


class SpacePacketHeader(BaseModel):
length: int = 0
Expand Down Expand Up @@ -120,7 +120,7 @@ def _verify_crc16(self):

if got[0] != want[0] or got[1] != want[1]:
return ValueError(f'checksum mismatch: got={got} want={want}')

def _make_packet_checksum(self) -> bytearray:
"""Creates checksum of packet from candidate bytes"""
bs = self.to_bytes()
Expand All @@ -141,7 +141,7 @@ def _make_packet_checksum(self) -> bytearray:
ckb = utils.pack_ushort_big_endian(ck)

return ckb

def err(self):
"""Throws an error if any parameters are out of bounds"""
if self.header.err() is not None:
Expand Down Expand Up @@ -178,4 +178,4 @@ def from_bytes(cls, bs: bytearray):
footer=ftr
)

return obj
return obj

0 comments on commit fa05d52

Please sign in to comment.