max_ble_hci.hci_packets — MAX BLE HCI 0.1.0 documentation

# 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)

  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

    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:

      AsyncPacket

class CommandPacket(ogf: OGF | int, ocf: OCF | int, params: List[int] | int | None = None)

  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:

    - ogf (Union[OGF, int]) – Opcode group field.

    - ocf (Union[OCF, int]) – Opcode command field.

    - params (Union[List[int], int], optional) – Command parameters, if any.

  ogf

    Opcode group field.

    Type:

      OGF

  ocf

    Opcode command field.

    Type:

      OCF

  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 make_hci_opcode(ogf: OGF | int, ocf: OCF | int) → int

    Make an HCI opcode.

    Creates an HCI opcode from the given Opcode Group Field (OGF) and Opcode Command Field (OCF) values.

    Parameters:

      - ogf (Union[OGF, int]) – Opcode group field.

      - ocf (Union[OCF, int]) – Opcode command field.

    Returns:

      The generated HCI opcode.

    Return type:

      int

  to_bytes(endianness: Endian = Endian.LITTLE) → bytearray

    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)

  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.

  evt_code

    Packet event code.

    Type:

      EventCode

  length

    Packet data length.

    Type:

      int

  status

    Packet status code.

    Type:

      StatusCode

  evt_subcode

    Packet event subcode

    Type:

      EventSubcode, optional

  evt_params

    Packet return parameters.

    Type:

      bytes

  static from_bytes(serialized_event: bytes) → EventPacket

    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:

      EventPacket

  get_return_params(param_lens: List[int] | None = None, endianness: Endian = Endian.LITTLE, signed: bool = False) → List[int] | int

    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)

  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:

    - ogf (Union[OGF, int]) – Opcode group field.

    - ocf (Union[OCF, int]) – Opcode command field.

    - payload (Union[List[int], int], optional) – Command parameters, if any.

  ogf

    Opcode group field.

    Type:

      OGF

  ocf

    Opcode command field.

    Type:

      OCF

  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

    Make an HCI opcode.

    Creates an HCI opcode from the given Opcode Group Field (OGF) and Opcode Command Field (OCF) values.

    Parameters:

      - ogf (Union[OGF, int]) – Opcode group field.

      - ocf (Union[OCF, int]) – Opcode command field.

    Returns:

      The generated HCI opcode.

    Return type:

      int

  to_bytes(endianness: Endian = Endian.LITTLE) → bytearray

    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

byte_length(num: int)

  Calculate the length of an integer in bytes.

  PRIVATE