space_packet_parser.packets
Packet containers and parsing utilities for space packets.
Attributes
Classes
Mixin class for storing access to the raw value of a parsed data item. |
|
A class to represent a binary data item. |
|
A class to represent a parsed boolean data item. |
|
A class to represent a float data item. |
|
A class to represent a integer data item. |
|
A class to represent a string data item. |
|
A class to represent raw packet data as bytes but whose length is represented by bit length. |
|
CCSDS Packet |
|
Defines an object that can be parsed from packet data. |
|
<xtce:SequenceContainer> |
Functions
|
Extract nbits from the data starting from the least significant end. |
Module Contents
- space_packet_parser.packets.BuiltinDataTypes
- class space_packet_parser.packets._Parameter
Mixin class for storing access to the raw value of a parsed data item.
The raw value is the closest representation of the data item as it appears in the packet. e.g. bytes for binary data, int for integer data, etc. It has not been calibrated or adjusted in any way and is an easy way for user’s to debug the transformations that happened after the fact.
Notes
We need to override the __new__ method to store the raw value of the data item on immutable built-in types. So this is just a way of allowing us to inject our own attribute into the built-in types.
- class space_packet_parser.packets.BinaryParameter
Bases:
_Parameter,bytesA class to represent a binary data item.
- class space_packet_parser.packets.BoolParameter
Bases:
_Parameter,intA class to represent a parsed boolean data item.
- __repr__() str
Return repr(self).
- class space_packet_parser.packets.FloatParameter
Bases:
_Parameter,floatA class to represent a float data item.
- class space_packet_parser.packets.IntParameter
Bases:
_Parameter,intA class to represent a integer data item.
- class space_packet_parser.packets.StrParameter
Bases:
_Parameter,strA class to represent a string data item.
- space_packet_parser.packets.ParameterDataTypes
- class space_packet_parser.packets.RawPacketData(data: bytes, *, pos: int = 0)
Bases:
bytesA class to represent raw packet data as bytes but whose length is represented by bit length.
This class is a subclass of bytes and is used to represent the raw packet data in a more readable way. It is used to store the raw packet data in the Packet class and used to keep track of the current parsing position.
- Parameters:
data (bytes) – Raw packet data. Full CCSDS packets are always an integer number of bytes.
- pos
- _nbits
- __len__()
Return len(self).
- __repr__()
Return repr(self).
- read_as_bytes(nbits: int) bytes
Read a number of bits from the packet data as bytes. Reads minimum number of complete bytes required to capture nbits. Moves pos cursor nbits forward, even if nbits is not an integer number of bytes.
- Parameters:
nbits (int) – Number of bits to read
- Returns:
Raw bytes from the packet data
- Return type:
bytes
- read_as_int(nbits: int) int
Read a number of bits from the packet data as an integer.
- Parameters:
nbits (int) – Number of bits to read
- Returns:
Integer representation of the bits read from the packet
- Return type:
int
- class space_packet_parser.packets.CCSDSPacket(*args, raw_data: bytes = b'', **kwargs)
Bases:
dictCCSDS Packet
Container that stores the raw packet data (bytes) as an instance attribute and the parsed data items in a dict interface. A
CCSDSPacketgenerally begins as an empty dictionary that gets filled as the packet is parsed. The first 7 items in the dictionary make up the packet header (accessed withCCSDSPacket.header), and the rest of the items make up the user data (accessed withCCSDSPacket.user_data). To access the raw bytes of the packet, use theCCSDSPacket.raw_dataattribute.- Parameters:
*args (Mapping or Iterable) – Initial items to store in the packet, passed to the dict() constructor.
raw_data (bytes, optional) – The binary data for a single packet.
**kwargs (dict) – Additional packet items to store, passed to the dict() constructor.
- raw_data
- property header: dict
The header content of the packet.
- property user_data: dict
The user data content of the packet.
- class space_packet_parser.packets.Parseable
Bases:
ProtocolDefines an object that can be parsed from packet data.
- parse(packet: CCSDSPacket, **parse_value_kwargs) None
Parse this entry from the packet data and add the necessary items to the packet.
- class space_packet_parser.packets.SequenceContainer
Bases:
Parseable<xtce:SequenceContainer>
- Parameters:
name (str) – Container name
entry_list (list) – List of Parameter objects
long_description (str) – Long description of the container
base_container_name (str) – Name of the base container from which this may inherit if restriction criteria are met.
restriction_criteria (list) – A list of MatchCriteria elements that evaluate to determine whether the SequenceContainer should be included.
abstract (bool) – True if container has abstract=true attribute. False otherwise.
inheritors (list, Optional) – List of SequenceContainer objects that may inherit this one’s entry list if their restriction criteria are met. Any SequenceContainers with this container as base_container_name should be listed here.
- name: str
- entry_list: list
- short_description: str | None = None
- long_description: str | None = None
- base_container_name: str | None = None
- restriction_criteria: list | None
- abstract: bool = False
- inheritors: List[SequenceContainer] | None
- __post_init__()
- parse(packet: CCSDSPacket, **parse_value_kwargs) None
Parse the entry list of parameters/containers in the order they are expected in the packet.
This could be recursive if the entry list contains SequenceContainers.
- space_packet_parser.packets._extract_bits(data: bytes, start_bit: int, nbits: int)
Extract nbits from the data starting from the least significant end.
If data = 00110101 11001010, start_bit = 2, nbits = 9, then the bits extracted are “110101110”. Those bits are turned into a Python integer and returned.
- Parameters:
data (bytes) – Data to extract bits from
start_bit (int) – Starting bit location within the data
nbits (int) – Number of bits to extract
- Returns:
Extracted bits as an integer
- Return type:
int