Friday, October 22, 2021

Add write capability to Characteristics 5 in TI CC26xx BLE simple_peripheral example

The following steps show you how to add write capability to Characteristics 5 in TI CC26xx BLE simple_peripheral example. In simple_gatt_profile.c

1. Revise "static uint8 simpleProfileChar5Props = GATT_PROP_READ;" to "static uint8 simpleProfileChar5Props = GATT_PROP_READ | GATT_PROP_WRITE;"

2. Revise the following code in simpleProfileAttrTbl

      // Characteristic Value 5
      {
        { ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
        GATT_PERMIT_AUTHEN_READ,
        0,
        simpleProfileChar5
      },

to

      // Characteristic Value 5
      {
        { ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
        GATT_PERMIT_AUTHEN_READ | GATT_PERMIT_WRITE,
        0,
        simpleProfileChar5
      },

3. Add the following code into simpleProfile_WriteAttrCB

      case SIMPLEPROFILE_CHAR5_UUID:

      //Validate the value
      // Make sure it's not a blob oper
      if ( offset == 0 )
      {
        if ( len > SIMPLEPROFILE_CHAR5_LEN )
        {
          status = ATT_ERR_INVALID_VALUE_SIZE;
        }
      }
      else
      {
        status = ATT_ERR_ATTR_NOT_LONG;
      }

      //Write the value
      if ( status == SUCCESS )
      {
        uint8 *pCurValue = (uint8 *)pAttr->pValue;
        memcpy(pCurValue,pValue,len);
        if( pAttr->pValue == &simpleProfileChar5 )
        {
          notifyApp = SIMPLEPROFILE_CHAR5;
        }
      }

      break;

Build the project and you can use TI SimpleLink Starter App or LightBlue App to test Characteristics 5 with write capability.

No comments:

Post a Comment