CC2640例程2

修改simpleBLEPeripheral,主要修改特性。例如需要一個特性可讀可寫做控制,另一個特性支持通知notification用來傳輸ADC值。基本上修改的部分就是如果自己添加服務特性需要添加的內容。
1、在哪修改? simpleGATTProfile.c文件實現了characteristic部分。
1.1 默認是有5個特性。開始變量申明部分有5個特性的UUID,可以註釋掉235。

/*********************************************************************
 * GLOBAL VARIABLES
 */
// Simple GATT Profile Service UUID: 0xFFF0
CONST uint8 simpleProfileServUUID[ATT_BT_UUID_SIZE] =
{ 
  LO_UINT16(SIMPLEPROFILE_SERV_UUID), HI_UINT16(SIMPLEPROFILE_SERV_UUID)
};

// Characteristic 1 UUID: 0xFFF1
CONST uint8 simpleProfilechar1UUID[ATT_BT_UUID_SIZE] =
{ 
  LO_UINT16(SIMPLEPROFILE_CHAR1_UUID), HI_UINT16(SIMPLEPROFILE_CHAR1_UUID)
};

//// Characteristic 2 UUID: 0xFFF2
//CONST uint8 simpleProfilechar2UUID[ATT_BT_UUID_SIZE] =
//{ 
//  LO_UINT16(SIMPLEPROFILE_CHAR2_UUID), HI_UINT16(SIMPLEPROFILE_CHAR2_UUID)
//};
//
//// Characteristic 3 UUID: 0xFFF3
//CONST uint8 simpleProfilechar3UUID[ATT_BT_UUID_SIZE] =
//{ 
//  LO_UINT16(SIMPLEPROFILE_CHAR3_UUID), HI_UINT16(SIMPLEPROFILE_CHAR3_UUID)
//};

// Characteristic 4 UUID: 0xFFF4
CONST uint8 simpleProfilechar4UUID[ATT_BT_UUID_SIZE] =
{ 
  LO_UINT16(SIMPLEPROFILE_CHAR4_UUID), HI_UINT16(SIMPLEPROFILE_CHAR4_UUID)
};

//// Characteristic 5 UUID: 0xFFF5
//CONST uint8 simpleProfilechar5UUID[ATT_BT_UUID_SIZE] =
//{ 
//  LO_UINT16(SIMPLEPROFILE_CHAR5_UUID), HI_UINT16(SIMPLEPROFILE_CHAR5_UUID)
//};

1.2、屬性變量。每個特性都有句柄,權限,值和描述。下面顯示了特性1的相關信息,同樣註釋掉235。

/*********************************************************************
 * Profile Attributes - variables
 */

// Simple Profile Service attribute
static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE, simpleProfileServUUID };


// Simple Profile Characteristic 1 Properties
static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE;

// Characteristic 1 Value
static uint8 simpleProfileChar1 = 0;

// Simple Profile Characteristic 1 User Description
static uint8 simpleProfileChar1UserDesp[10] = "Control 1";

1.3 接下來是屬性列表(attrtbl或者database)用來打包服務包含的所有特性。同樣註釋掉235部分。

static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] = 
{
  // Simple Profile Service
  { 
    { ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
    GATT_PERMIT_READ,                         /* permissions */
    0,                                        /* handle */
    (uint8 *)&simpleProfileService            /* pValue */
  },

    // Characteristic 1 Declaration
    { 
      { ATT_BT_UUID_SIZE, characterUUID },
      GATT_PERMIT_READ, 
      0,
      &simpleProfileChar1Props 
    },

1.4 設置參數和獲取參數,在應用層用於設置或獲取特性中的value。

bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;
  switch ( param )
  {
    case SIMPLEPROFILE_CHAR1:
      if ( len == sizeof ( uint8 ) ) 
      {
        simpleProfileChar1 = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

1.5 在把235全部註釋完後編譯運行,會發現還是有幾個多餘的UUID。屬性表的數量宏定義需要由17修改到最終的數量即可。app顯示只有兩個特性了。

gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED]

這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章