【BLE】CC2541之删除服务

本篇博文最后修改时间: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

香瓜BLE之Android群:541462902

香瓜单片机之STM8/STM32群:164311667
甜甜的大香瓜的小店(淘宝店):https://shop217632629.taobao.com/?spm=2013.1.1000126.d21.hd2o8i

四、 实验前提
1、在进行本文步骤前,请先 阅读 以下博文:
暂无

2、在进行本文步骤前,请先 实现以下博文:
1、《CC2541之添加自定义服务》:http://blog.youkuaiyun.com/feilusia/article/details/50723016


五、基础知识

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的香瓜服务。

因此实验成功。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

甜甜的大香瓜

谢谢你的支持^_^

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值