本篇博文最后修改时间:2017年01月06日,10:07。
一、简介
本文介绍如何在SimpleBLEPeripheral工程中,删除simpleGATTprofile服务。
二、实验平台
协议栈版本:BLE-CC254x-1.4.0
编译软件: IAR 8.20.2
硬件平台: Smart RF开发板(主芯片CC2541)
手机型号: 小米4S
安卓版本:安卓5.1
安卓app:TruthBlue
三、版权声明
博主:甜甜的大香瓜
声明:喝水不忘挖井人,转载请注明出处。
原文地址:http://blog.csdn.NET/feilusia
联系方式:897503845@qq.com
香瓜BLE之CC2541群:127442605
香瓜BLE之CC2640群:557278427
五、基础知识
1、为什么要删除服务?
答:由于做OAD时对代码量有限制,因此需要将没用的代码删除。
当你添加过一个香瓜服务时,原先的simpleGATTprofile服务可能就用不到了,因此可以删除。
六、代码修改
1、工程中删除simpleGATTprofile服务文件
右键,Remove。
2、删除simpleGATTprofile服务的头文件引用(SimpleBLEPeripheral.c中)
//#include "simpleGATTprofile.h"
3、删除添加simpleGATTprofile服务的代码(SimpleBLEPeripheral.c的SimpleBLEPeripheral_Init中)
//SimpleProfile_AddService( GATT_ALL_SERVICES );
/*
// Setup the SimpleProfile Characteristic Values
{
uint8 charValue1 = 1;
uint8 charValue2 = 2;
uint8 charValue3 = 3;
uint8 charValue4 = 4;
uint8 charValue5[SIMPLEPROFILE_CHAR5_LEN] = { 1, 2, 3, 4, 5 };
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR1, sizeof ( uint8 ), &charValue1 );
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR2, sizeof ( uint8 ), &charValue2 );
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR3, sizeof ( uint8 ), &charValue3 );
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, sizeof ( uint8 ), &charValue4 );
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5 );
}
VOID SimpleProfile_RegisterAppCBs( &simpleBLEPeripheral_SimpleProfileCBs );
*/
4、修改广播数据中的服务UUID(SimpleBLEPeripheral.c中)
static uint8 advertData[] =
{
// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
// service UUID, to notify central devices what services are included
// in this peripheral
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
//LO_UINT16( SIMPLEPROFILE_SERV_UUID ),
//HI_UINT16( SIMPLEPROFILE_SERV_UUID ),
LO_UINT16( GUAPROFILE_SERV_UUID ), //香瓜服务的UUID
HI_UINT16( GUAPROFILE_SERV_UUID ), //香瓜服务的UUID
};
更换为已添加的香瓜服务的UUID。
5、删除simpleGATTprofile服务相关的回调函数(SimpleBLEPeripheral.c中)
/*
static simpleProfileCBs_t simpleBLEPeripheral_SimpleProfileCBs = // Simple GATT Profile Callbacks
{
simpleProfileChangeCB // Charactersitic value change callback
};*/
/*
static void simpleProfileChangeCB( uint8 paramID )
{
uint8 newValue;
switch( paramID )
{
case SIMPLEPROFILE_CHAR1:
SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR1, &newValue );
break;
case SIMPLEPROFILE_CHAR3:
SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR3, &newValue );
break;
default:
break;
}
}
*/
6、删除simpleGATTprofile服务的调用(修改SimpleBLEPeripheral.c中的performPeriodicTask)
static void performPeriodicTask( void )
{
uint8 valueToCopy;
uint8 stat;
// Call to retrieve the value of the third characteristic in the profile
//stat = SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR3, &valueToCopy);
//if( stat == SUCCESS )
//{
/*
* Call to set that value of the fourth characteristic in the profile. Note
* that if notifications of the fourth characteristic have been enabled by
* a GATT client device, then a notification will be sent every time this
* function is called.
*/
//SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, sizeof(uint8), &valueToCopy);
//}
}
手机可能缓存了之前的代码(在更新过CC2541的代码之后,都需要清除手机端的缓存!!!),因此要清除缓存,清除缓存的方法如下:
方法一:关闭app、关闭蓝牙总开关、打开蓝牙总开关、打开app。
方法二:手机重启。
注:如果是已绑定的,需要先解除绑定。(群友31958357提供,待测试)
八、实验结果
此时就搜不到UUID为FFF0的simpleGATTprofile了,只能搜到UUID为FFE0的香瓜服务。
因此实验成功。