Bluetooth technical courses
UUID,就是用来唯一识别一个特征值的ID.
handle,就是对应的attribute的一个句柄。
所有对特征值的操作,都是通过对UUID的搜索得到对应的handle之后,通过handle来操作特征值的。
添加新的特征值CHAR6
下面对主要几个文件进行修改
simpleGATTprofile.h文件添加以下定义
#define SIMPLEPROFILE_CHAR6
#define SIMPLEPROFILE_CHAR6_UUID
#define SIMPLEPROFILE_CHAR6_LEN
SIMPLEPROFILE_CHAR6
在simpleGATTprofile.c
1、
// Characteristic 6 UUID: 0xFFF6
CONST uint8 simpleProfilechar6UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR6_UUID),
HI_UINT16(SIMPLEPROFILE_CHAR6_UUID) };
/**************#define HI_UINT16(a)
/**************#define LO_UINT16(a)
2、
// Simple Profile Characteristic 6 Properties
static
// Characteristic 6 Value
static uint8simpleProfileChar6[SIMPLEPROFILE_CHAR6_LEN] = { 0, 0, 0, 0, 0 };
// Simple Profile Characteristic 6 User Description
static uint8 simpleProfileChar6UserDe
3、
static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED]
这里要把数组改为
#define SERVAPP_NUM_ATTR_SUPPORTED
simpleProfileAttrTbl表中,可读可写属性都是3个数组,只有char4的通知是4组,多了个// Characteristic 4 configuration
并把CHAR6添加进去
// Characteristic Value 6
能列出来了但是 点进去会报错,还没设置读写参数simpleProfile_WriteAttrCB,
simpleProfile_ReadAttrCB
4、设置参数函数
bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )中:
//即修改SimpleProfile_SetParameter();函数
添加以下代码:
case SIMPLEPROFILE_CHAR6:
4、
在bStatus_tSimpleProfile_GetParameter( uint8 param, void *value )中添加:
case
break;
//读取simpleProfileChar6的值放到*value中,char1是单个字节读取,为
*((uint8*)value) = simpleProfileChar1;
·
·
每当GATT层有数据发过来的时候,会调用simpleProfile_WriteAttrCB,
每当GATT层收到对方读取数据请求的时候,会调用simpleProfile_ReadAttrCB
这两个函数包含在gattServiceCBs_t类型的结构体里CONST gattServiceCBs_t simpleProfileCBs,
读simpleProfile_ReadAttrCB
这个设置后就能在lightblue里读出值,值为
simpleProfileChar6[SIMPLEPROFILE_CHAR6_LEN]={数组的数值(16进制显示)}
写simpleProfile_WriteAttrCB
读取被写进去的值
)
在static uint8 simpleProfile_ReadAttrCB( uint16 connHandle,
添加
添加单字节char7要在接char1或3后面,不能加break
在simpleProfile_WriteAttrCB()中添加(添加后发送过去就不会提示出错了)
(下面没用到)osal_memset为字符串集体赋同一数值
void
{
Return
}
if ( status == SUCCESS )
uint8 *pCurValue = (uint8 *)pAttr->pValue;
osal_memset(pCurValue, 0, SIMPLEPROFILE_CHAR6_LEN );
VOID osal_memcpy(pCurValue, pValue, SIMPLEPROFILE_CHAR6_LEN );
7 .在simpleBLEperipheral.c添加初始化值
在void SimpleBLEPeripheral_Init( uint8 task_id )函数中初始化参数
现在可以在手机设备中读取CHAR6的值为0x0102030405;
向char6写进0x3344556677
下载链接
The parameter dataIdentifier (DID) logically represents an object (e.g., Air Inlet Door Position) or collection of objects. This parameter shall be available in the server's memory. The dataIdentifier value shall either exist in fixed memory or temporarily stored in RAM if defined dynamically by the service dynamicallyDefineDataIdentifier. In general, a dataIdentifier is capable of being utilized in many diagnostic service requests including 0x22 (readDataByIdentifier), 0x2E (writeDataByIdentifier), and 0x2F (inputOutputControlByIdentifier). A dataIdentifier is also used in various diagnostic service responses (e.g., positive response to service 0x19 subfunction readDTCSnapshotRecordByDTCNumber).
IMPORTANT — Regardless of which service a dataIdentifier is used with, it shall consistently
represent the same thing (i.e., a given object with a given size / meaning / etc.) on a given ECU.