您的位置:首页 > 其它

CC2640例程2

2015-11-14 23:14 375 查看
修改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]


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: