digi.xbee.packets.base module¶
-
class
digi.xbee.packets.base.DictKeys(value)[source]¶ Bases:
enum.EnumThis enumeration contains all keys used in dictionaries returned by to_dict() method of
XBeePacket.
-
class
digi.xbee.packets.base.XBeePacket[source]¶ Bases:
objectThis 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
XBeePacketobject.-
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)[source]¶ Bases:
digi.xbee.packets.base.XBeePacketThis 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
XBeeAPIPacketobject with the provided parameters.- Parameters
api_frame_type (
ApiFrameTypeor Integer) – The API frame type.
See also
-
get_frame_type()[source]¶ Returns the frame type of this packet.
- Returns
the frame type of this packet.
- Return type
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
-
property
frame_id¶ Returns the frame ID of the packet.
- Returns
the frame ID of the packet.
- Return type
Integer
-
abstract
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
-
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.GenericXBeePacket(rf_data)[source]¶ Bases:
digi.xbee.packets.base.XBeeAPIPacketThis class represents a basic and Generic XBee packet.
See also
Class constructor. Instantiates a
GenericXBeePacketobject with the provided parameters.- Parameters
rf_data (bytearray) – the frame specific data without frame type and frame ID.
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. See
SpecialByte.InvalidPacketException – if the calculated checksum is different from the checksum field value (last byte).
InvalidPacketException – if the frame type is different from
ApiFrameType.GENERIC.InvalidOperatingModeException – if operating_mode is not supported.
See also
XBeeAPIPacket._check_api_packet()
-
property
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
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
-
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, rf_data)[source]¶ Bases:
digi.xbee.packets.base.XBeeAPIPacketThis class represents an unknown XBee packet.
See also
Class constructor. Instantiates a
UnknownXBeePacketobject with the provided parameters.- Parameters
api_frame (Integer) – the API frame integer value of this packet.
rf_data (bytearray) – the frame specific data without frame type and frame ID.
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. See
SpecialByte.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()
-
property
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
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
-
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