%% Decode BLE GAP AD Blocks
% Decode two unique BLE GAP AD blocks: one with AD types 'Flags' and 'Tx power level' and the other with AD types 'Advertising interval' and 'Local name'.
% Create a configuration object for a BLE GAP AD block. Specify the AD types as 'Flags' and 'Tx power level'. Set the values of LE discoverability as 'Limited' and Tx power level to 45. View the properties of the configuration object 'cfgGAP'.

cfgGAP = bleGAPDataBlockConfig;
cfgGAP.AdvertisingDataTypes = {'Flags'; 'Tx power level'};
cfgGAP.LEDiscoverability = 'Limited';
cfgGAP.TxPowerLevel = 45

% Generate a BLE GAP AD block from the corresponding configuration object.

dataBlock = bleGAPDataBlock(cfgGAP);

% Decode the generated BLE GAP AD block. The returned status indicates decoding was successful. View the output of 'status' and 'cfgGAP'.

[status, cfgGAP] = bleGAPDataBlockDecode(dataBlock)

% Create another BLE GAP AD block configuration object, this time specifying AD types 'Advertising interval' and 'Local name'. Set the values of advertising interval as 48, local name as 'MathWorks', and local name shortening as true. View the properties of the configuration object 'cfgGAP'.

cfgGAP = bleGAPDataBlockConfig('AdvertisingDataTypes', ...
    {'Advertising interval','Local name'});
cfgGAP.AdvertisingInterval = 48;
cfgGAP.LocalName = 'MathWorks';
cfgGAP.LocalNameShortening = true

% Generate the BLE GAP AD block from the corresponding configuration object.

dataBlock = bleGAPDataBlock(cfgGAP);

% Decode the generated BLE GAP AD block. The returned status indicates decoding was successful. View the output of 'status' and 'cfgGAP'.

[status, cfgGAP] = bleGAPDataBlockDecode(dataBlock)

% Copyright 2019 The MathWorks, Inc.