在 Profiles 中添加特征值

1、add in simpleGATTprofile.h:
添加定义
#define SIMPLEPROFILE_CHAR6                                       5            //Proflie Prarameters,   Proflie Characteristic 6 value
#define SIMPLEPROFILE_CHAR6_UUID                         0xFFF6
#define SIMPLEPROFILE_CHAR6_LEN                            5           //Length of Characteristic6 in bytes

2、add in simpleGATTprofile.c
添加特征值UUID
//UUID: 0xFFF6
CONST uint8 simpleProfilechar6UUID[ATT_BT_UUID_SIZE] = {LO_UINT(SIMPLEPROFILE),HI_UINT(SIMPLEPROFILE_CHAR_UUID)};//0xFFF6分到两个数组中,高低位,0xFF,0xF6


3、add in simpleGATTprofile.c
设置属性,分别有读/写,value值,User Description

//Simple Profile Characterstic 6 Properties(属性)     可读可写
static uint8 simpleProfileChar6Props = GATT_PROP_READ | GATT_PROP_WRITE;

//Characteristic 6 Value
static uint8 simpleProfileChar6[SIMPLEPROFILE_CHAR6_LEN] = {0,0,0,0,0};// value 值是[0,0,0,0,0]?

//Simple Profile Charcteristic 6 User Description
static uint8 simpleProfileChar6UserDesp[17] = "Characteristic 6\0"; 

4、add in simpleGATTprofile.c,-》static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED]
属性表
先介绍,分别有
gattAttrType_t type; //!< Attribute type (2 or 16 octet UUIDs)
  uint8 permissions;   //!< Attribute permissions
  uint16 handle;       //!< Attribute handle - assigned internally by attribute server   内部分配
  uint8* const pValue; //!< Attribute value - encoding of the octet array is defined in 
                       //!< the applicable profile. The maximum length of an attribute 
                       //!< value shall be 512 octets.
{
type:1、len;  UUID的长度                                              2、*uuid; //  UUID指针
permissions       属性权限
handle                属性服务内部分配的handle
pValue               属性value 
}

开始添加属性表
先在simpleGATTprofile.c 中把SERVAPP_NUM_ATTR_SUPPORTED  //  attr 支持的数量,改成 20

然后在  static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =       数组中添加值 , 这个数组的作用不详
" 添加的分别有Declaration,value,user description,和Declaration,value,configuration,user description 和新定义的 value,user description "
其中: 1、Characteristic123456 的 Declaration的 UUID值是一样的,Declaration 的 Value值 是属性的值,跟属性的permissions       (权限)有时不一样
     2、 Characteristic123456 的  Value 的 UUID 不一样(0xFFF5),Value 的 Value值(有的是变量,有的是数组), 找不到赋值的地方, bStatus_t SimpleProfile_SetParameter
     3、 Characteristic123456  的 Description 的 UUID 是一样的 0x2901,Description 的 Value 是 不同的字符串

// Characteristic Value 6
{ ATT_BT_UUID_SIZE, simpleProfilechar6UUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE, 
0, 
simpleProfileChar6 // 哪里给了Value值? 在前面定义了static 00000,后面在设置参数函数bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value ) 赋值
},
// Characteristic 6 User Description
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ, 
0, 
simpleProfileChar6UserDesp 
},


5、设置参数函数  // 给 Value 赋值,跟对Value取值
bStatus_t SimpleProfile_ SetParameter( uint8 param, uint8 len, void *value )      // 给 Value 赋值
case SIMPLEPROFILE_CHAR6:
if ( len == SIMPLEPROFILE_CHAR6_LEN ) 
{
VOID  osal_memcpy(  simpleProfileChar6,  value, 
SIMPLEPROFILE_CHAR6_LEN );
}
else
{
ret = bleInvalidRange;
}
break;

bStatus_t SimpleProfile_ GetParameter( uint8 param, void *value )                   // 跟对Value取值
case SIMPLEPROFILE_CHAR6:
VOID  osal_memcpy(  value,  simpleProfileChar6, 
SIMPLEPROFILE_CHAR6_LEN ); 
209
break; 


6、读写特征值函数
读:static uint8 simpleProfile_ReadAttrCB // 把特征值的Value值读取出来,但不知道什么时候调用,是个call back 函数,有个
// Simple Profile Service Callbacks
CONST gattServiceCBs_t simpleProfileCBs =
{
  simpleProfile_ReadAttrCB,  // Read callback function pointer
  simpleProfile_WriteAttrCB, // Write callback function pointer
  NULL                       // Authorization callback function pointer
};                                                                                                                     不知道什么时候会用到 ,估计是某些情况下的call back

读value 在,simpleProfile_ReadAttrCB ,添加case 用memcpy函数读取 value


写: static bStatus_t simpleProfile_WriteAttrCB// 验证属性数据之前要先写
Offset // offset - offset of the first octet to be written 不知道干嘛的
添加:
case SIMPLEPROFILE_CASE6_UUID:
if( offset == 0)//干嘛的?
{
if( len != SIMPLEPOFILE_CHAR6_LEn)
{
status = ATT_ERR_INVALID_VALUE_SIZE
}
}
else
[
status = ATT_ERR_ATTR_NOT_LONG
}
//正式 Write value
if( status == SUCCESS )
{
VOID osal_memcpy( pAttr->pValue, pValue, SIMPLEPOFILE_CHAR6_LEN);
notifyApp = SIMPLEPOFILE_HCAR6;
}
break;


7、在 void SimpleBLEPeripheral_Init( uint8 task_id )              初始化参数

uint8 charValue6[SIMPLEPROFILE_CHAR6_LEN] = { 1, 2, 3, 4, 5 };

SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR6, SIMPLEPROFILE_CHAR6_LEN, charValue6 );
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值