bleRegisterAdvData(Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

LX2

Firmware version:

2.20.00


 

This function registers a callback function to handle incoming advertising data.

This callback will be provided with each individual piece of advertising data as it is received. To receive the raw advertising data, use bleRegisterAdvRaw instead.

 

Input:

ev_type: UINT (default 0)

The type of advertising events to handle. This value is combined with ev_mask to find matching events.

Bitmask:

Bit 0

-

Connectable advertising


It is allowed to connect to this device.

Bit 1

-

Scannable advertising


The device can provide additional data as a scan response when using active scanning.

Bit 2

-

Directed advertising


The advertising is directed at a specific device.

Bit 3

-

Scan response


This is a response to an active scan.

Bit 4

-

Legacy advertising.


If set to 0, the device uses extended advertising.

 

 

Remaining bits: Reserved



 

ev_mask: UINT (default 0)

Bitmask determining how ev_type should be used. If a bit is set in this mask, it must match the same bit in ev_type.

Setting ev_mask to 0 will handle all events.

Setting ev_mask to 16#FFFF will require that ev_type matches on all defined bits.

To receive scannable and scan response legacy advertising, set ev_mask to 16#0017 and ev_type to 16#0012.

To receive only non connectable legacy advertising, set ev_mask to 16#001F and ev_type to 16#0010.

 

adv_type: INT (-1, 0..256) (default -1)

The type of advertising data to handle. Use -1 to handle all data types.

See 2.3 Common Data Types in the Assigned Numbers Document at https://www.bluetooth.com/specifications/assigned-numbers/

 

Examples:

16#01

-

Flags

16#03

-

Complete list of 16-bit Service Class UUIDs

16#09

-

Complete local name

16#FF

-

Manufacturer specific data.

 

cb_adv: CALLBACK

The function to call when advertising data is received. See the callback declaration below.

 

cb_arg: DINT

User argument to pass on to the callback.

 

Returns: INT

1

-

_BLE_OK


Success

0

-

_BLE_ERR_NOT_SUPPORTED


The API is not supported.

-1

-

_BLE_ERR_NOT_OPEN


The interface is not powered(see blePower).

-7

 

_BLE_ERR_NO_RES


Too many callbacks have been registered.

-8

-

_BLE_ERR_INVAL


Invalid parameter.

 

 

Declaration:

FUNCTION bleRegisterAdvData : INT;
VAR_INPUT
  ev_type   : DINT  := -1;
  adv_type  : INT  := -1;
  cb_adv    : CALLBACK;
  cb_arg    : DINT;
END_VAR;
 

Callback declaration:

FUNCTION CALLBACK cbAdvData : INT;
VAR_INPUT
  mac       : STRING; // MAC address for the sender
  ev_type   : UINT;  // Event type for the data
  adv_type  : INT;   // Advertising data type.
  data      : PTR;    // The advertising data. This pointer may not be used outside the callback.
  len       : INT;    // The size of the advertising data.
  rssi      : SINT;   // The RSSI of the packet.
  arg       : DINT;   // The user argument.
END_VAR;

 

 

 

 

Example:

FUNCTION CALLBACK cbAdvName;
VAR_INPUT
  mac      : STRING;
  ev_type  : UINT;
  adv_type : USINT;
  data     : PTR;
  len      : INT;
  rssi     : SINT;
  arg      : DINT;
END_VAR;
VAR
  str     : STRING;
END_VAR;
  str:=strFromMemory(src:=data, len:=len);
  DebugFmt(message:=mac+"(\1): "+str, v1:=rssi);
END_FUNCTION;
 
...
// Register callback to show complete local name
rc := bleRegisterAdvData(cb_Adv:=@cbAdvName, adv_type := 9);
...