bleRegisterAdvRaw (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 the raw advertising data as it is received. To receive the parsed advertising data, use bleRegisterAdvData 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.

 

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 bleRegisterAdvRaw : INT;
VAR_INPUT
  ev_type   : UINT  := 0;
  ev_mask   : UINT  := 0;
  cb_adv    : CALLBACK;
  cb_arg    : DINT;
END_VAR;
 

Callback declaration:

FUNCTION CALLBACK cbAdvRaw : INT;
VAR_INPUT
  mac       : STRING; // MAC address for the sender
  ev_type   : UINT;  // Event type for the data
  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 cbAdvRaw;
VAR_INPUT
   mac      : STRING;
   ev_type  : UINT;
   data     : PTR;
   len      : INT;
   rssi     : SINT;
   arg      : DINT;
END_VAR;
VAR 
   i        : INT :=0;
   adv_type : USINT;
   adv_len  : USINT;
END_VAR;
   DebugFmt(message:=mac+" RSSI: \2, Len: \3, Type: "+intToHex(v:=ev_type), v2:=rssiv3:=len);
   // Print out the size and type of the contained advertising data
   WHILE i < len DO
      memcpy(dst := ADDR(adv_len), src:=data+ilen:=1);
      IF adv_len > 0 THEN
         memcpy(dst:=ADDR(adv_type), src:=data+i+1len:=1);
         DebugFmt(message:="  Len: \1, Type: "+sintToHex(v:=adv_type), v1:=adv_len);
         
         := i+1+adv_len;
      ELSE
         // Empty
         := i+1;
      END_IF;
   END_WHILE;
END_FUNCTION;
 
 
...
   rc := bleRegisterAdvRaw(cb_Adv:=@cbAdvRawev_type := 16#0010ev_mask := 16#0010);
   DebugFmt(message := "BleRegisterAdvRaw: \1", v1 := rc);
...