Go to the documentation of this file. 1 """High level object-oriented API for elements that can exist in a packet.
4 - packet_types.FixedLength
5 - packet_types.VariableLength
8 __author__ =
"Daniel da Silva <mail@danieldasilva.org>"
12 from .converters
import Converter
16 """A field contained in a packet."""
18 def __init__(self, name, data_type, bit_length, bit_offset=None, byte_order="big"):
23 String identifier for the field. The name specified how you may
24 call upon this data later.
25 data_type : {'uint', 'int', 'float', 'str', 'fill'}
26 Data type of the field.
28 Number of bits contained in the field.
29 bit_offset : int, optional
30 Bit offset into packet, including the primary header which is 48 bits long.
31 If this is not specified, than the bit offset will the be calculated automatically
32 from its position inside the packet definition.
33 byte_order : {'big', 'little'}, optional
34 Byte order of the field. Defaults to big endian.
39 If one of the arguments is not of the correct type.
41 data_type or byte_order is invalid
43 if not isinstance(name, str):
44 raise TypeError(
"name parameter must be a str")
45 if not isinstance(data_type, str):
46 raise TypeError(
"data_type parameter must be a str")
47 if not isinstance(bit_length, (int, np.integer)):
48 raise TypeError(
"bit_length parameter must be an int")
49 if not (bit_offset
is None or isinstance(bit_offset, (int, np.integer))):
50 raise TypeError(
"bit_offset parameter must be an int")
52 valid_data_types = (
"uint",
"int",
"float",
"str",
"fill")
53 if data_type
not in valid_data_types:
54 raise ValueError(f
"data_type must be one of {valid_data_types}")
56 valid_byte_orders = (
"big",
"little")
57 if byte_order
not in valid_byte_orders:
58 raise ValueError(f
"byte_order must be one of {valid_byte_orders}")
71 values = {k: repr(v)
for (k, v)
in self.__dict__.items()}
72 values[
"cls_name"] = self.__class__.__name__
74 if values[
"cls_name"] ==
"PacketArray":
76 "{cls_name}(name={_name}, data_type={_data_type}, "
77 "bit_length={_bit_length}, bit_offset={_bit_offset}, "
78 "byte_order={_byte_order}, array_shape={_array_shape}, "
79 "array_order={_array_order})".format(**values)
83 "{cls_name}(name={_name}, data_type={_data_type}, "
84 "bit_length={_bit_length}, bit_offset={_bit_offset}, "
85 "byte_order={_byte_order})".format(**values)
101 """An array contained in a packet, similar to :py:class:`~ccsdspy.PacketField` but with multiple
102 elements of the same size (e.g. image).
105 def __init__(self, *args, array_shape=None, array_order="C", **kwargs):
110 String identifier for the field. The name specified how you may
111 call upon this data later.
112 data_type : {'uint', 'int', 'float', 'str', 'fill'}
113 Data type of the field.
115 Number of bits contained in the field.
116 array_shape : int, tuple of ints, str, 'expand'
117 Shape of the array as a tuple. For a 1-dimensional array, a single integer
118 can be supplied. To use another field's value, pass the name of that field. To
119 grow to fill the packet, use "expand". For details on variable length fields, see
120 the :py:class:`~ccsdspy.VariableLength` class.
121 array_order {'C', 'F'}
122 Row-major (C-style) or column-major (Fortran-style) order.
123 bit_offset : int, optional
124 Bit offset into packet, including the primary header which is 48 bits long.
125 If this is not specified, than the bit offset will the be calculated automatically
126 from its position inside the packet definition.
127 byte_order : {'big', 'little'}, optional
128 Byte order of the field. Defaults to big endian.
133 If one of the arguments is not of the correct type.
135 array_shape, array_order, data_type, or byte_order is invalid
137 if isinstance(array_shape, str):
138 if "data_type" not in kwargs:
139 kwargs[
"data_type"] =
"uint"
140 elif kwargs[
"data_type"] !=
"uint":
141 raise ValueError(
"Expanding arrays must be data_type='uint'")
143 if isinstance(array_shape, int):
144 array_shape = (array_shape,)
145 if not isinstance(array_shape, tuple):
146 raise TypeError(
"array_shape parameter must be a tuple of ints")
147 if not all(isinstance(dim, int)
for dim
in array_shape):
148 raise TypeError(
"array_shape parameter must be a tuple of ints")
150 if not all(dim >= 0
for dim
in array_shape):
151 raise TypeError(
"array_shape parameter dimensions must be >= 0")
152 if sum(array_shape) == 0:
153 raise TypeError(
"array must have at least one element")
155 if not isinstance(array_order, str):
156 raise TypeError(
"array_order parameter must be string")
157 if array_order
not in {
"C",
"F"}:
158 raise TypeError(
"array_order parameter must be either 'C' or 'F'")
def __init__(self, name, data_type, bit_length, bit_offset=None, byte_order="big")
def __init__(self, *args, array_shape=None, array_order="C", **kwargs)