Class Advertisement

extends Object
Advertisement data as either sent by advertising or received through scanning.
The size of an advertisement packet is limited to 31 bytes. This includes the name and bytes that are required to structure the packet.

Class summary


constructor data-blocks/List --check-size/bool=
Constructs an advertisement data packet with the given data blocks.
constructor --name/string= --services/List= --manufacturer-specific/Data= --flags/int= --check-size/bool=
Constructs an advertisement packet.

Constructors

constructor data-blocks/List --check-size/bool=true
Constructs an advertisement data packet with the given data blocks.
Advertisement packets are limited to 31 data bytes. If check-size is true, then the size of the data blocks is checked to ensure that the packet size does not exceed 31 bytes.

constructor --name/string=null --services/List=[] --manufacturer-specific/Data=null --flags/int=null --check-size/bool=true
Constructs an advertisement packet.
If the services parameter is not empty, then the list is split into 16-bit, 32-bit, and 128-bit UUIDs. Each of the lists that isn't empty is then encoded into the advertisement data.

Statics

Constructs an advertisement data packet from the raw data.
Advertisement packets are limited to 31 data bytes.

Methods

Whether this advertisement contains the given service UUID.

Advertise flags. This must be a bitwise 'or' of the BLE-ADVERTISE-FLAG_* constants (see BLE-ADVERTISE-FLAGS-GENERAL-DISCOVERY and similar).
For backwards compatibility, returns 0 if no flags are present.

manufacturer-specific [block] -> any
Calls the given block with the first field of manufacturer specific data.
Calls the block with the company ID and manufacturer specific data.
If no manufacturer specific data is present, the block is not called.
Returns the result of calling the block, or null if no manufacturer specific data is present.

The advertised name of the device.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

Advertised services as a list of BleUuid.
Returns the empty list if no services are present.

The size of the advertisement data packet.
Returns the size of all the data blocks.

Encodes the advertisement data into a byte array.
Does not check if the size of the advertisement data exceeds 31 bytes.

The transmit power level.

Fields

The DataBlock fields of this instance.