digi.xbee.packets.base module¶
-
class
digi.xbee.packets.base.
DictKeys
[source]¶ Bases:
enum.Enum
This enumeration contains all keys used in dictionaries returned by to_dict() method of
XBeePacket
.
-
class
digi.xbee.packets.base.
XBeePacket
(op_mode=<OperatingMode.API_MODE: (1, 'API mode')>)[source]¶ Bases:
object
This abstract class represents the basic structure of an XBee packet. Derived classes should implement their own payload generation depending on their type.
Generic actions like checksum compute or packet length calculation is performed here.
Class constructor. Instantiates a new
XBeePacket
object.Parameters: op_mode ( OperatingMode
, optional, default=`OperatingMode.API_MODE`) – The mode in which the frame was captured.-
op_mode
¶ Retrieves the operating mode in which this packet was read.
Returns: The operating mode. Return type: OperatingMode
-
get_checksum
()[source]¶ Returns the checksum value of this XBeePacket. The checksum is the last 8 bits of the sum of the bytes between the length field and the checksum field.
Returns: checksum value of this XBeePacket. Return type: Integer See also
-
output
(escaped=False)[source]¶ Returns the raw bytearray of this XBeePacket, ready to be send by the serial port.
Parameters: escaped (Boolean) – indicates if the raw bytearray must be escaped. Returns: raw bytearray of the XBeePacket. Return type: Bytearray
-
to_dict
()[source]¶ Returns a dictionary with all information of the XBeePacket fields.
Returns: dictionary with all info of the XBeePacket fields. Return type: Dictionary
-
static
create_packet
(raw, operating_mode)[source]¶ Abstract method. Creates a full XBeePacket with the given parameters. This function ensures that the XBeePacket returned is valid and is well built (if not exceptions are raised).
If _OPERATING_MODE is API2 (API escaped) this method des-escape ‘raw’ and build the XBeePacket. Then, you can use
XBeePacket.output()
to get the escaped bytearray or not escaped.Parameters: - raw (Bytearray) – bytearray with which the frame will be built. Must be a full frame represented by a bytearray.
- operating_mode (
OperatingMode
) – The mode in which the frame (‘byteArray’) was captured.
Returns: the XBee packet created.
Return type: Raises: InvalidPacketException
– if something is wrong with raw and the packet cannot be built well.
-
-
class
digi.xbee.packets.base.
XBeeAPIPacket
(api_frame_type, op_mode=<OperatingMode.API_MODE: (1, 'API mode')>)[source]¶ Bases:
digi.xbee.packets.base.XBeePacket
This abstract class provides the basic structure of a API frame. Derived classes should implement their own methods to generate the API data and frame ID in case they support it.
Basic operations such as frame type retrieval are performed in this class.
See also
Class constructor. Instantiates a new
XBeeAPIPacket
object with the provided parameters.Parameters: - api_frame_type (
ApiFrameType
or Integer) – The API frame type. - op_mode (
OperatingMode
, optional, default=`OperatingMode.API_MODE`) – The mode in which the frame was captured.
See also
-
get_frame_type
()[source]¶ Returns the frame type of this packet.
Returns: the frame type of this packet. Return type: ApiFrameType
See also
-
get_frame_type_value
()[source]¶ Returns the frame type integer value of this packet.
Returns: the frame type integer value of this packet. Return type: Integer See also
-
is_broadcast
()[source]¶ Returns whether this packet is broadcast or not.
Returns: True if this packet is broadcast, False otherwise. Return type: Boolean
-
frame_id
¶ Returns the frame ID of the packet.
Returns: the frame ID of the packet. Return type: Integer
-
needs_id
()[source]¶ Returns whether the packet requires frame ID or not.
Returns: True if the packet needs frame ID, False otherwise. Return type: Boolean
-
static
create_packet
(raw, operating_mode)¶ Abstract method. Creates a full XBeePacket with the given parameters. This function ensures that the XBeePacket returned is valid and is well built (if not exceptions are raised).
If _OPERATING_MODE is API2 (API escaped) this method des-escape ‘raw’ and build the XBeePacket. Then, you can use
XBeePacket.output()
to get the escaped bytearray or not escaped.Parameters: - raw (Bytearray) – bytearray with which the frame will be built. Must be a full frame represented by a bytearray.
- operating_mode (
OperatingMode
) – The mode in which the frame (‘byteArray’) was captured.
Returns: the XBee packet created.
Return type: Raises: InvalidPacketException
– if something is wrong with raw and the packet cannot be built well.
-
get_checksum
()¶ Returns the checksum value of this XBeePacket. The checksum is the last 8 bits of the sum of the bytes between the length field and the checksum field.
Returns: checksum value of this XBeePacket. Return type: Integer See also
-
op_mode
¶ Retrieves the operating mode in which this packet was read.
Returns: The operating mode. Return type: OperatingMode
-
output
(escaped=False)¶ Returns the raw bytearray of this XBeePacket, ready to be send by the serial port.
Parameters: escaped (Boolean) – indicates if the raw bytearray must be escaped. Returns: raw bytearray of the XBeePacket. Return type: Bytearray
-
to_dict
()¶ Returns a dictionary with all information of the XBeePacket fields.
Returns: dictionary with all info of the XBeePacket fields. Return type: Dictionary
-
static
unescape_data
(data)¶ Un-escapes the provided bytearray data.
Parameters: data (Bytearray) – the bytearray to unescape. Returns: data unescaped. Return type: Bytearray
- api_frame_type (
-
class
digi.xbee.packets.base.
GenericXBeePacket
(data, op_mode=<OperatingMode.API_MODE: (1, 'API mode')>)[source]¶ Bases:
digi.xbee.packets.base.XBeeAPIPacket
This class represents a basic and Generic XBee packet.
See also
Class constructor. Instantiates a
GenericXBeePacket
object with the provided parameters.Parameters: - data (bytearray) – the frame specific data without frame type and frame ID.
- op_mode (
OperatingMode
, optional, default=`OperatingMode.API_MODE`) – The mode in which the frame was captured.
See also
-
static
create_packet
(raw, operating_mode=<OperatingMode.API_MODE: (1, 'API mode')>)[source]¶ Override method.
Returns: the GenericXBeePacket generated.
Return type: Raises: InvalidPacketException
– if the bytearray length is less than 5. (start delim. + length (2 bytes) + frame type + checksum = 5 bytes).InvalidPacketException
– if the length field of ‘raw’ is different from its real length. (length field: bytes 2 and 3)InvalidPacketException
– if the first byte of ‘raw’ is not the header byte. SeeSpecialByte
.InvalidPacketException
– if the calculated checksum is different from the checksum field value (last byte).InvalidPacketException
– if the frame type is different fromApiFrameType.GENERIC
.InvalidOperatingModeException
– if operating_mode is not supported.
See also
XBeeAPIPacket._check_api_packet()
-
frame_id
¶ Returns the frame ID of the packet.
Returns: the frame ID of the packet. Return type: Integer
-
get_checksum
()¶ Returns the checksum value of this XBeePacket. The checksum is the last 8 bits of the sum of the bytes between the length field and the checksum field.
Returns: checksum value of this XBeePacket. Return type: Integer See also
-
get_frame_spec_data
()¶ Override method.
See also
-
get_frame_type
()¶ Returns the frame type of this packet.
Returns: the frame type of this packet. Return type: ApiFrameType
See also
-
get_frame_type_value
()¶ Returns the frame type integer value of this packet.
Returns: the frame type integer value of this packet. Return type: Integer See also
-
is_broadcast
()¶ Returns whether this packet is broadcast or not.
Returns: True if this packet is broadcast, False otherwise. Return type: Boolean
-
op_mode
¶ Retrieves the operating mode in which this packet was read.
Returns: The operating mode. Return type: OperatingMode
-
output
(escaped=False)¶ Returns the raw bytearray of this XBeePacket, ready to be send by the serial port.
Parameters: escaped (Boolean) – indicates if the raw bytearray must be escaped. Returns: raw bytearray of the XBeePacket. Return type: Bytearray
-
to_dict
()¶ Returns a dictionary with all information of the XBeePacket fields.
Returns: dictionary with all info of the XBeePacket fields. Return type: Dictionary
-
static
unescape_data
(data)¶ Un-escapes the provided bytearray data.
Parameters: data (Bytearray) – the bytearray to unescape. Returns: data unescaped. Return type: Bytearray
-
class
digi.xbee.packets.base.
UnknownXBeePacket
(api_frame, data, op_mode=<OperatingMode.API_MODE: (1, 'API mode')>)[source]¶ Bases:
digi.xbee.packets.base.XBeeAPIPacket
This class represents an unknown XBee packet.
See also
Class constructor. Instantiates a
UnknownXBeePacket
object with the provided parameters.Parameters: - api_frame (Integer) – the API frame integer value of this packet.
- data (bytearray) – the frame specific data without frame type and frame ID.
- op_mode (
OperatingMode
, optional, default=`OperatingMode.API_MODE`) – The mode in which the frame was captured.
See also
-
static
create_packet
(raw, operating_mode=<OperatingMode.API_MODE: (1, 'API mode')>)[source]¶ Override method.
Returns: the UnknownXBeePacket generated.
Return type: Raises: InvalidPacketException
– if the bytearray length is less than 5. (start delim. + length (2 bytes) + frame type + checksum = 5 bytes).InvalidPacketException
– if the length field of ‘raw’ is different its real length. (length field: bytes 2 and 3)InvalidPacketException
– if the first byte of ‘raw’ is not the header byte. SeeSpecialByte
.InvalidPacketException
– if the calculated checksum is different from the checksum field value (last byte).InvalidOperatingModeException
– if operating_mode is not supported.
See also
XBeeAPIPacket._check_api_packet()
-
frame_id
¶ Returns the frame ID of the packet.
Returns: the frame ID of the packet. Return type: Integer
-
get_checksum
()¶ Returns the checksum value of this XBeePacket. The checksum is the last 8 bits of the sum of the bytes between the length field and the checksum field.
Returns: checksum value of this XBeePacket. Return type: Integer See also
-
get_frame_spec_data
()¶ Override method.
See also
-
get_frame_type
()¶ Returns the frame type of this packet.
Returns: the frame type of this packet. Return type: ApiFrameType
See also
-
get_frame_type_value
()¶ Returns the frame type integer value of this packet.
Returns: the frame type integer value of this packet. Return type: Integer See also
-
is_broadcast
()¶ Returns whether this packet is broadcast or not.
Returns: True if this packet is broadcast, False otherwise. Return type: Boolean
-
op_mode
¶ Retrieves the operating mode in which this packet was read.
Returns: The operating mode. Return type: OperatingMode
-
output
(escaped=False)¶ Returns the raw bytearray of this XBeePacket, ready to be send by the serial port.
Parameters: escaped (Boolean) – indicates if the raw bytearray must be escaped. Returns: raw bytearray of the XBeePacket. Return type: Bytearray
-
to_dict
()¶ Returns a dictionary with all information of the XBeePacket fields.
Returns: dictionary with all info of the XBeePacket fields. Return type: Dictionary
-
static
unescape_data
(data)¶ Un-escapes the provided bytearray data.
Parameters: data (Bytearray) – the bytearray to unescape. Returns: data unescaped. Return type: Bytearray