其他分享
首页 > 其他分享> > CH579-BLE

CH579-BLE

作者:互联网

 

Peripheral

 

\EVT\EXAM\BLE\Peripheral\Profile\include\gattprofile.h

1 gattprofile.h  //重要 因为只读 需要重新生成一次
2 
3 #define SIMPLEPROFILE_CHAR1_LEN               10  
4 #define SIMPLEPROFILE_CHAR2_LEN               10  
5 #define SIMPLEPROFILE_CHAR3_LEN               10  
6 #define SIMPLEPROFILE_CHAR4_LEN               10  

 

EVT\EXAM\BLE\Peripheral\Profile\gattprofile.c

 1 // Simple Profile Characteristic 1 Properties
 2 static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE; //支持读写
 3 
 4 // Characteristic 1 Value
 5 static uint8 simpleProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = { 0 }; //初始化
 6 
 7 // Simple Profile Characteristic 1 User Description
 8 static uint8 simpleProfileChar1UserDesp[] = "Characteristic 1\0"; //描述
 9 
10 
11 
12 // Simple Profile Characteristic 4 Properties
13 static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;
14 
15 //安卓点击接收
16 static bStatus_t simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 
17                             uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen,uint8 method  )
18   ...
19   if ( pAttr->type.len == ATT_BT_UUID_SIZE )
20   {
21     // 16-bit UUID
22     uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
23     switch ( uuid )
24     {
25       case SIMPLEPROFILE_CHAR1_UUID: //根据UUID
26         *pLen = SIMPLEPROFILE_CHAR1_LEN;
27                 PRINT("simpleProfile_ReadAttrCB 1 len=%d\n");
28                 pAttr->pValue[0]='A'; //填入要发送的数据
29                 pAttr->pValue[1]='B';
30                 pAttr->pValue[2]='C';
31                 pAttr->pValue[3]='D';                    
32                 tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN ); //发送函数    
33         break;
34         
35 //安卓写入函数        
36 static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
37                                  uint8 *pValue, uint16 len, uint16 offset,uint8 method  )
38                                  
39   if ( pAttr->type.len == ATT_BT_UUID_SIZE )
40   {
41     // 16-bit UUID
42     uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
43     switch ( uuid )
44     {
45       case SIMPLEPROFILE_CHAR1_UUID:
46         //Validate the value
47         // Make sure it's not a blob oper
48         if ( offset == 0 )
49         {
50           if ( len > SIMPLEPROFILE_CHAR1_LEN )
51           {
52             status = ATT_ERR_INVALID_VALUE_SIZE;
53           }
54         }
55         else
56         {
57           status = ATT_ERR_ATTR_NOT_LONG;
58         }
59         
60         //Write the value
61         if ( status == SUCCESS )
62         {
63           
64         PRINT("simpleProfile_WriteAttrCB 1=%c,%c,%c,%c,%c,%c\n",pValue[0],pValue[1],pValue[2],pValue[3],pValue[4],pValue[5]);//显示安卓发来的数据
65         tmos_memcpy( pAttr->pValue, pValue, SIMPLEPROFILE_CHAR1_LEN );
66          notifyApp = SIMPLEPROFILE_CHAR1;        
67         }            
68         break;                                 
69         

 

标签:CH579,CHAR1,LEN,SIMPLEPROFILE,uint16,pAttr,BLE,pValue
来源: https://www.cnblogs.com/kingboy100/p/12912414.html