CC2640之配对与绑定

CC2640之配对与绑定

参考了https://blog.youkuaiyun.com/weixin_43172567/article/details/83617194这篇文章

以下是经过我自己的写的代码实现过程,亲测可用
使用TI官方协议栈里面的程序
主要修改的源程序文件有是simple_gatt_profile.c
主要变量和函数修改:
1、接受和发送数据长度修改
#define Ble_length 20
// Characteristic 3 Value
static uint8 simpleProfileChar3[Ble_length] = {0};
// Characteristic 4 Value
static uint8 simpleProfileChar4[Ble_length] = {0};
这里我们使用Characteristic 3 接收手机APP发送过来的消息,
使用Characteristic 4 给手机APP发送消息
2、修改接收和发送函数
bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
        case SIMPLEPROFILE_CHAR3:
        //if ( len == sizeof ( uint8 ) )
        if ( len <= Ble_length )
        {
        //simpleProfileChar3 = *((uint8*)value);
        memcpy(simpleProfileChar3,value,Ble_length);
        }
        else
        {
        ret = bleInvalidRange;
        }
        break;

        case SIMPLEPROFILE_CHAR4:
        //if ( len == sizeof ( uint8 ) )
        if ( len <= Ble_length)
        {
        //simpleProfileChar4 = *((uint8*)value);
        memcpy(simpleProfileChar4,value,Ble_length);
        
        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( simpleProfileChar4Config, simpleProfileChar4, FALSE,
                                    simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                    INVALID_TASK_ID, simpleProfile_ReadAttrCB );
        }
      
bStatus_t SimpleProfile_GetParameter( uint8 param, void *value )
        case SIMPLEPROFILE_CHAR3:
        //*((uint8*)value) = simpleProfileChar3;
        memcpy(value,simpleProfileChar3,Ble_length);
        break;

        case SIMPLEPROFILE_CHAR4:
        //*((uint8*)value) = simpleProfileChar4;
        memcpy(value,simpleProfileChar4,Ble_length);
        break;    


static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,gattAttribute_t *pAttr, uint8_t *pValue, uint16_t *pLen, uint16_t offset, uint16_t maxLen, uint8_t method)
        case SIMPLEPROFILE_CHAR4_UUID:
        *pLen = Ble_length;
        //pValue[0] = *pAttr->pValue;
        memcpy(pValue,pAttr->pValue,Ble_length);
        break;

static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,gattAttribute_t *pAttr, uint8_t *pValue, uint16_t len, uint16_t offset, uint8_t method)
            //Write the value
        if ( status == SUCCESS )
        {
          uint8 *pCurValue = (uint8 *)pAttr->pValue;
          //*pCurValue = pValue[0];
          memcpy(pCurValue,pValue,Ble_length);

          if( pAttr->pValue == &simpleProfileChar1 )
          {
            notifyApp = SIMPLEPROFILE_CHAR1;
          }
          else
          {
            notifyApp = SIMPLEPROFILE_CHAR3;
          }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值