max_ble_hci.hci_packets
Contains objects used for the creation of HCI packets.
- class AsyncPacket(handle: int, pb_flag: int, bc_flag: int, length: int, data: bytes)[source]
Bases:
object
Deserializer for HCI ACL packets.
Object defines a deserializer/data container for HCI Asynchronous Connection-Less packets. To create an instance directly from bytes, use the static function from_bytes.
- Parameters:
handle (int) – Packet handle value.
pb_flag (int) – Packet PB flag.
bc_flag (int) – Packet BC flag.
length (int) – Packet data length.
data (bytes) – Packet data.
- handle
Packet handle value.
- Type:
int
- pb_flag
Packet PB flag.
- Type:
int
- bc_flag
Packet BC flag.
- Type:
int
- length
Packet data length.
- Type:
int
- data
Packet data.
- Type:
bytes
- static from_bytes(pkt: bytes) AsyncPacket [source]
Deserialize an HCI ACL packet.
Deserializes an HCI Asynchronous Connection-Less packet from a bytes object.
- Parameters:
pkt (bytes) – Serialized async packet.
- Returns:
The deserialized packet.
- Return type:
- class CommandPacket(ogf: OGF | int, ocf: OCF | int, params: List[int] | int | None = None)[source]
Bases:
object
Serializer for HCI command packets.
Object defines a container/serializer for HCI command packets. Initializing an instance of the object creates a container which stores the desired command opcode and parameters. A serialized command can then be generated through the use of the to_bytes function. In the event that an opcode is needed but a full packet is not, the static method make_hci_opcode can be called without initializing an instance of the object.
- Parameters:
- length
Total length of command parameters.
- Type:
int
- opcode
Command opcode.
- Type:
int
- params
Command parameters, if any.
- Type:
Union[List[int], int], optional
- static from_bytes(command: bytearray) CommandPacket [source]
Convert command from byte array to command packet
- Parameters:
command (bytearray) – raw command in bytes
- Returns:
Decoded command packet
- Return type:
- static get_ogf_ocf(opcode) tuple[OGF, ControllerOCF | LEControllerOCF] [source]
Get OGF and OCF from opcode of command packet
- Parameters:
opcode (int) – 2 Bytes opcode
- Returns:
OGF, OCF
- Return type:
tuple
- static make_hci_opcode(ogf: OGF | int, ocf: OCF | int) int [source]
Make an HCI opcode.
Creates an HCI opcode from the given Opcode Group Field (OGF) and Opcode Command Field (OCF) values.
- to_bytes(endianness: Endian = Endian.LITTLE) bytearray [source]
Serialize a command packet.
Serializes a command packets from the stored attribute values into a command data byte array.
- Parameters:
endianness (Endian) – Endian byte order to apply during serialization.
- Returns:
The serialized command.
- Return type:
bytearray
- class EventPacket(evt_code: int, length: int, status: int, evt_params: bytes, evt_subcode: int | None = None)[source]
Bases:
object
Deserializer for HCI event packets.
Object defines a deserializer/data container for HCI event packets. To create an instance directly from bytes, use the static function from_bytes. Event packet return parameters can be retrieved by calling the get_return_params function once an instance of the object has been created.
- Parameters:
evt_code (int) – Packet event code.
length (int) – Packet data length.
status (int) – Packet status code.
evt_params (bytes) – Packet return parameters.
evt_subcode (int, optional) – Packet event subcode.
- length
Packet data length.
- Type:
int
- status
Packet status code.
- Type:
- evt_subcode
Packet event subcode
- Type:
EventSubcode, optional
- evt_params
Packet return parameters.
- Type:
bytes
- decode() dict [source]
Decode parameters from EventPacket
- Returns:
Decoded event parameters
- Return type:
dict
- static from_bytes(serialized_event: bytes) EventPacket [source]
Deserialize an HCI event packet.
Deserializes an HCI event packet from a bytes object.
- Parameters:
serialized_event (bytes) – Serialized event packet.
- Returns:
The deserialized packet.
- Return type:
- get_return_params(param_lens: List[int] | None = None, endianness: Endian = Endian.LITTLE, signed: bool = False) List[int] | int [source]
Retrieve packet return parameters.
Parses the packet return parameters from the bytes stored in the evt_params attribute in accordance with the given lengths and deserialization parameters.
- Parameters:
param_lens (List[int], optional) – The length values of each expected return parameter. If only 1 return is expected, this value does not need to be provided.
endianness (Endian) – Endian byte order to apply during deserialization.
signed (bool) – Are the return values signed integers?
- Returns:
The parsed return parameter(s).
- Return type:
Union[List[int], int]
- class ExtendedPacket(ogf: OGF | int, ocf: OCF | int, payload: List[int] | int | None = None)[source]
Bases:
object
Serializer for HCI extended command packets.
Object defines a container/serializer for HCI extended command packets. Initializing an instance of the object creates a container which stores the desired extended command opcode and payload. A serialized command can then be generated through the use of the to_bytes function. In the event that an opcode is needed but a full packet is not, the static method make_hci_opcode can be used without initializing an instance of the object.
- Parameters:
- length
Total length of command parameters.
- Type:
int
- opcode
Command opcode.
- Type:
int
- payload
Command parameters, if any.
- Type:
Union[List[int], int], optional
- static make_hci_opcode(ogf: OGF | int, ocf: OCF | int) int [source]
Make an HCI opcode.
Creates an HCI opcode from the given Opcode Group Field (OGF) and Opcode Command Field (OCF) values.
- to_bytes(endianness: Endian = Endian.LITTLE) bytearray [source]
Serialize a command packet.
Serializes a command packets from the stored attribute values into a command data byte array.
- Parameters:
endianness (Endian) – Endian byte order to apply during serialization.
- Returns:
The serialized command.
- Return type:
bytearray