digi.xbee.packets.bluetooth module

class digi.xbee.packets.bluetooth.BluetoothGAPScanRequestPacket(start_command, scan_duration, scan_window, scan_interval, filter_type, filter_data, op_mode=OperatingMode.API_MODE)[source]

Bases: XBeeAPIPacket

This class represents a Bluetooth GAP scan request packet. Packet is built using the parameters of the constructor or providing a valid byte array.

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

Parameters:
  • start_command (Integer) – To start scan set to 1. To stop scan set to 0.

  • scan_duration (Integer) – Scan duration in seconds. Value must be between 0 and 0xFFFF.

  • indefinitely. (A value of 0 indicates the scan will run)

  • scan_window (Integer) – Scan window in microseconds.

  • and (Value must be between 0x9C4 and 0x270FD8F)

  • scan_interval. (value can't be larger than the)

  • scan_interval (Integer) – Scan interval in microseconds. Value must be between 0x9C4 and 0x270FD8F and value can’t be smaller than the scan_window.

  • filter_type (Integer) – Value of 0 disables filter. Value of 1 enables filter looking for Complete Local Name (0x09) and Short Local Name (0x08) types.

  • filter_data (String or bytearray) – The size of the filter_data is from 0-22 bytes.

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

Raises:
  • ValueError – if start_command is not 0 nor 1.

  • ValueError – if scan_duration is not between 0 and 0xFFFF.

  • ValueError – if scan_window is not between 0x9C4 and 0x270FD8F or larger than the scan_interval.

  • ValueError – if scan_interval is not between 0x9C4 and 0x270FD8F or smaller than the scan_window.

  • ValueError – if filter_type is not 0 nor 1.

See also

STOP_SCAN = 0

Constant value used to stop the scan

START_SCAN = 1

Constant value used to start the scan

INDEFINITE_SCAN_DURATION = 0

Constant value for an indefinite scan

static create_packet(raw, operating_mode)[source]

Override method.

Returns:

BluetoothGAPScanRequestPacket

Raises:
  • InvalidPacketException – if the bytearray length is less than 17. (start delim, length (2 bytes), frame type, start_command, scan_duration (2 bytes), scan_window (4 bytes), scan_interval (4 bytes), filter_type, checksum = 17 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 different from ApiFrameType.BLUETOOTH_GAP_SCAN_REQUEST.

  • InvalidOperatingModeException – if operating_mode is not supported.

needs_id()[source]

Override method.

property start_command

Returns the start_command.

Returns:

the start_command.

Return type:

Integer

property scan_duration

Returns the scan duration.

Returns:

the scan duration.

Return type:

Integer

property scan_window

Returns the scan window.

Returns:

the scan window.

Return type:

Integer

property scan_interval

Returns the scan interval.

Returns:

the scan interval.

Return type:

Integer

property filter_type

Returns the filter_type.

Returns:

the filter_type.

Return type:

Integer

property filter_data

Returns the filter data.

Returns:

packet’s filter data.

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.bluetooth.BluetoothGAPScanLegacyAdvertisementResponsePacket(address, address_type, advertisement_flags, rssi, payload, op_mode=OperatingMode.API_MODE)[source]

Bases: XBeeAPIPacket

This class represents a Bluetooth GAP scan legacy advertisement response packet. Packet is built using the parameters of the constructor or providing a valid byte array.

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

Parameters:
  • address (XBeeBLEAddress) – The Bluetooth MAC address of the received advertisement

  • address_type (Integer) – Indicates whether the Bluetooth address is a public address or a randomly generated address.

  • advertisement_flags (Integer) – bitfield structure where bit0 indicates whether the advertisement is connectable. Other bits are reserved.

  • rssi (Integer) – The received signal strength of the advertisement, in dBm.

  • payload (bytearray) – The actual data payload of the advertisement which can contain various information elements, manufacturer-specific data, or other relevant details about the advertising device.

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

Raises:

ValueError – if length of payload is less than 16 or greater than 255.

See also

static create_packet(raw, operating_mode)[source]

Override method.

Returns:

BluetoothGAPScanLegacyAdvertisementResponsePacket

Raises:
  • InvalidPacketException – if the bytearray length is less than 32. (start delim + length (2 bytes) + frame type + address (6 bytes) + address_type + advertisement_flags + rssi + reserved + payload_length + 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 different from ApiFrameType.BluetoothGAPScanLegacyAdvertisementResponsePacket.

  • InvalidPacketException – if the payload_length field does not match the actual length of the payload.

  • InvalidOperatingModeException – if operating_mode is not supported.

needs_id()[source]

Override method.

property address

Returns the Bluetooth MAC address of the received advertisement.

Returns:

returns the Bluetooth

MAC address.

Return type:

address (XBeeBLEAddress)

property address_type

Returns the address type of the received advertisement.

Returns:

the address type.

Return type:

Integer

property advertisement_flags

Returns the advertisement flags.

Returns:

the advertisement flags.

Return type:

Integer

property rssi

Returns the RSSI of the advertisement.

Returns:

the RSSI.

Return type:

Integer

property payload

Returns the payload that was received.

Returns:

the payload that was received.

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.bluetooth.BluetoothGAPScanExtendedAdvertisementResponsePacket(address, address_type, advertisement_flags, rssi, advertisement_set_id, primary_phy, secondary_phy, tx_power, periodic_interval, data_completeness, payload, op_mode=OperatingMode.API_MODE)[source]

Bases: XBeeAPIPacket

This class represents a Bluetooth GAP scan extended advertisement response packet. Packet is built using the parameters of the constructor or providing a valid byte array.

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

Parameters:
  • address (XBeeBLEAddress) – The Bluetooth MAC address of the received advertisement

  • address_type (Integer) – Indicates whether the Bluetooth address is a public address or a randomly generated address.

  • advertisement_flags (Integer) – bitfield structure where bit0 indicates whether the advertisement is connectable. Other bits are reserved.

  • rssi (Integer) – in dBm.

  • advertisement_set_id (Integer) – A device can broadcast multiple advertisements at a time. The set identifier will help identify which advertisement you received.

  • primary_phy (Integer) – This is the preferred PHY for connecting with this device. Values are: 0x1 : 1M PHY 0x2 : 2M PHY 0x4 : LE Coded PHY 125k 0x8 : LE Coded PHY 500k 0xFF : Any PHY supported

  • secondary_phy (Integer) – This is the secondary PHY for connecting with this device. This has the same values as primary_phy.

  • tx_power (Integer) – Transmission power of received advertisement. This is a signed value.

  • periodic_interval (Integer) – Interval for periodic advertising. 0 indicates no periodic advertising. Interval value is in increments of 1.25 ms.

  • data_completeness (Integer) – Values are 0x0 indicates all data of the advertisement has been reported. 0x1 : Data is incomplete, but more data will follow. 0x2 : Data is incomplete, but no more data is following. Data has be truncated.

  • payload (bytearray) – The actual data payload of the advertisement which can contain various information elements, manufacturer-specific data, or other relevant details about the advertising device.

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

Raises:

ValueError – if length of payload is less than 22 or greater than 255.

static create_packet(raw, operating_mode)[source]

Override method.

Returns:

BluetoothGAPScanExtendedAdvertisementResponsePacket

Raises:
  • InvalidPacketException – if the bytearray length is less than 45. (start delim + length (2 bytes) + frame type + address (6 bytes) + address_type + advertisement_flags + rssi + reserved + advertisement_set_id + primary_phy + secondary_phy + tx_power + periodic_interval (2 bytes) + data_completeness + payload_length + checksum = 23 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 different from ApiFrameType.BluetoothGAPScanExtendedAdvertisementResponsePacket.

  • InvalidOperatingModeException – if operating_mode is not supported.

needs_id()[source]

Override method.

property address

Returns the Bluetooth MAC address of the received advertisement.

Returns:

returns the Bluetooth

MAC address.

Return type:

address (XBeeBLEAddress)

property address_type

Returns the address type

Returns:

the address type.

Return type:

Integer

property advertisement_flags

Returns the Advertisement flags

Returns:

the advertisement flags.

Return type:

Integer

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 rssi

Returns the RSSI of the advertisement.

Returns:

the RSSI.

Return type:

Integer

property advertisement_set_id

Returns the advertisement set identifier used to help identify which advertisement you received.

Returns:

the advertisement set identifier.

Return type:

Integer

property primary_phy

Returns the preferred PHY for connecting this device.

Returns:

the primary PHY

Return type:

Integer

property secondary_phy

Returns the secondary PHY for connecting this device.

Returns:

the secondary PHY.

Return type:

Integer

property tx_power

Returns the transmission power of received advertisement. This is a signed value.

Returns:

transmission power.

Return type:

Integer

property periodic_interval

Returns the interval for periodic advertising. 0 indicates no periodic advertising.

Returns:

periodic interval.

Return type:

Integer

property data_completeness

Returns the data completeness field.

Returns:

data completeness field.

Return type:

Integer

property payload

Returns the payload that was received.

Returns:

the payload that was received.

Return type:

Bytearray

class digi.xbee.packets.bluetooth.BluetoothGAPScanStatusPacket(scan_status, op_mode=OperatingMode.API_MODE)[source]

Bases: XBeeAPIPacket

This class represents a Bluetooth GAP scan status packet. Packet is built using the parameters of the constructor or providing a valid byte array.

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

Parameters:

scan_status – Reflects the status of the Bluetooth scanner. Values are: 0x00: Scanner has successfully started. 0x01: Scanner is currently running. 0x02: Scanner has successfully stopped. 0x03: Scanner was unable to start or stop. 0x04: Invalid parameters.

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

static create_packet(raw, operating_mode)[source]

Override method.

Returns:

BluetoothGAPScanStatusPacket

Raises:
needs_id()[source]

Override method.

property scan_status

Returns the scan status of the Bluetooth scanner.

Returns:

scan status

Return type:

Integer