CC2640之配对与绑定

CC2640之配对与绑定

参考了https://blog.csdn.net/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;
          }
        }

猜你喜欢

转载自blog.csdn.net/farsight_2098/article/details/86594284