digi.xbee.packets.network module

class digi.xbee.packets.network.RXIPv4Packet(src_address, dest_port, src_port, ip_protocol, data=None, op_mode=OperatingMode.API_MODE)[source]

Bases: XBeeAPIPacket

This class represents an RX (Receive) IPv4 packet. Packet is built using the parameters of the constructor or providing a valid byte array.

Class constructor. Instantiates a new RXIPv4Packet object with the provided parameters.

Parameters:
  • src_address (IPv4Address) – IPv4 address of the source device.

  • dest_port (Integer) – destination port number.

  • src_port (Integer) – source port number.

  • ip_protocol (IPProtocol) – IP protocol used for transmitted data.

  • data (Bytearray, optional) – data that is sent to the destination device.

  • op_mode (OperatingMode, optional, default=`OperatingMode.API_MODE`) – The mode in which the frame was captured.

Raises:
  • ValueError – if dest_port is less than 0 or greater than 65535 or

  • ValueError – if source_port is less than 0 or greater than 65535.

See also

static create_packet(raw, operating_mode)[source]

Override method.

Returns:

class: .RXIPv4Packet.

Raises:
  • InvalidPacketException – if the bytearray length is less than 15. (start delim + length (2 bytes) + frame type + source address(4 bytes) + dest port (2 bytes) + source port (2 bytes) + network protocol + status + checksum = 15 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 SPECIAL_BYTE.

  • InvalidPacketException – if the calculated checksum is different from the checksum field value (last byte).

  • InvalidPacketException – if the frame type is not ApiFrameType.RX_IPV4.

  • InvalidOperatingModeException – if operating_mode is not supported.

See also

XBeeAPIPacket._check_api_packet()
needs_id()[source]

Override method.

property source_address

Returns the IPv4 address of the source device.

Returns:

the IPv4 address of the source device.

Return type:

ipaddress.IPv4Address

property dest_port

Returns the destination port.

Returns:

the destination port.

Return type:

Integer

property source_port

Returns the source port.

Returns:

the source port.

Return type:

Integer

property ip_protocol

Returns the IP protocol used for transmitted data.

Returns:

the IP protocol used for transmitted data.

Return type:

IPProtocol

property data

Returns the data of the packet.

Returns:

the data of the packet.

Return type:

Bytearray

property effective_len

Returns the effective length of the packet.

Returns:

Effective length of the packet.

Return type:

Integer

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.

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

property 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.network.TXIPv4Packet(frame_id, dest_address, dest_port, src_port, ip_protocol, tx_opts, data=None, op_mode=OperatingMode.API_MODE)[source]

Bases: XBeeAPIPacket

This class represents an TX (Transmit) IPv4 packet. Packet is built using the parameters of the constructor or providing a valid byte array.

Class constructor. Instantiates a new TXIPv4Packet object with the provided parameters.

Parameters:
  • frame_id (Integer) – the frame ID. Must be between 0 and 255.

  • dest_address (IPv4Address) – IPv4 address of the destination device.

  • dest_port (Integer) – destination port number.

  • src_port (Integer) – source port number.

  • ip_protocol (IPProtocol) – IP protocol used for transmitted data.

  • tx_opts (Integer) – the transmit options of the packet.

  • data (Bytearray, optional) – data that is sent to the destination device.

  • op_mode (OperatingMode, optional, default=`OperatingMode.API_MODE`) – The mode in which the frame was captured.

Raises:
  • ValueError – if frame_id is less than 0 or greater than 255.

  • ValueError – if dest_port is less than 0 or greater than 65535.

  • ValueError – if source_port is less than 0 or greater than 65535.

See also

OPTIONS_CLOSE_SOCKET = 2

This option will close the socket after the transmission.

OPTIONS_LEAVE_SOCKET_OPEN = 0

This option will leave socket open after the transmission.

static create_packet(raw, operating_mode)[source]

Override method.

Returns:

TXIPv4Packet.

Raises:
  • InvalidPacketException – if the bytearray length is less than 16. (start delim + length (2 bytes) + frame type + frame id + dest address (4 bytes) + dest port (2 bytes) + source port (2 bytes) + network protocol + transmit options + checksum = 16 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 SPECIAL_BYTE.

  • InvalidPacketException – if the calculated checksum is different from the checksum field value (last byte).

  • InvalidPacketException – if the frame type is not ApiFrameType.TX_IPV4.

  • InvalidOperatingModeException – if operating_mode is not supported.

See also

XBeeAPIPacket._check_api_packet()
needs_id()[source]

Override method.

property dest_address

Returns the IPv4 address of the destination device.

Returns:

the IPv4 address of the destination device.

Return type:

ipaddress.IPv4Address

property effective_len

Returns the effective length of the packet.

Returns:

Effective length of the packet.

Return type:

Integer

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.

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

property 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

property dest_port

Returns the destination port.

Returns:

the destination port.

Return type:

Integer

property source_port

Returns the source port.

Returns:

the source port.

Return type:

Integer

property ip_protocol

Returns the IP protocol used for transmitted data.

Returns:

the IP protocol used for transmitted data.

Return type:

IPProtocol

property transmit_options

Returns the transmit options of the packet.

Returns:

the transmit options of the packet.

Return type:

Integer

property data

Returns the data of the packet.

Returns:

the data of the packet.

Return type:

Bytearray