Main Content

bleATTPDU

Generate BLE ATT PDU

Download Required: To use bleATTPDU, first download Communications Toolbox™ Library for the Bluetooth® Protocol. For more information, see Get and Manage Add-Ons. Alternatively, see Communications Toolbox Library for the Bluetooth Protocol File Exchange.

Description

example

attPDU = bleATTPDU(cfgATT) generates a Bluetooth low energy (BLE) attribute protocol data unit (ATT PDU) corresponding to the BLE ATT PDU configuration object cfgATT.

Examples

collapse all

Generate two unique BLE ATT PDUs of type 'Read by type request' and 'Error response'.

Create a BLE ATT PDU configuration object with default settings.

cfgATT = bleATTPDUConfig;

Change the BLE ATT PDU opcode as 'Read by type request'. View the applicable properties of the opcode 'Read by type request'.

cfgATT.Opcode = 'Read by type request'
cfgATT = 
  bleATTPDUConfig with properties:

           Opcode: 'Read by type request'
      StartHandle: '0001'
        EndHandle: 'FFFF'
    AttributeType: '2800'

Generate a BLE ATT PDU using the corresponding configuration object.

attPDU = bleATTPDU(cfgATT)
attPDU = 7x2 char array
    '08'
    '01'
    '00'
    'FF'
    'FF'
    '00'
    '28'

Create another BLE ATT PDU configuration object, this time using the name-value pairs. Change the BLE ATT PDU opcode to 'Error response'. View the applicable properties of the opcode 'Error response'.

cfgATT = bleATTPDUConfig('Opcode','Error response')
cfgATT = 
  bleATTPDUConfig with properties:

             Opcode: 'Error response'
    RequestedOpcode: 'Read request'
    AttributeHandle: '0001'
       ErrorMessage: 'Invalid handle'

Generate a BLE ATT PDU corresponding to this configuration object.

attPDU = bleATTPDU(cfgATT)
attPDU = 5x2 char array
    '01'
    '0A'
    '01'
    '00'
    '01'

Input Arguments

collapse all

BLE ATT PDU configuration object, specified as a bleATTPDUConfig object. This value defines the type of BLE ATT PDU and its applicable properties.

Output Arguments

collapse all

Generated BLE ATT PDU, returned as a character array. Each row in this array is the hexadecimal representation of an octet.

References

[1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed November 22, 2019. https://www.bluetooth.com/.

[2] Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification." Version 5.1. https://www.bluetooth.com/.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2019b