首页 > 其他分享 >CH582芯片句柄指示\确认(Handle Value Indication\Confirmation)

CH582芯片句柄指示\确认(Handle Value Indication\Confirmation)

时间:2022-11-05 17:44:10浏览次数:55  
标签:Confirmation Handle GATT 句柄 indi len Indication noti pValue

前言:

CH583 是集成 BLE 无线通讯的 RISC-V MCU 微控制器。一般在使用BLE协议进行数据传输,会优先考虑Peripheral(外设从机角色例程)。在CH582的SDK中,自定义包含五种不同属性的服务,包含可读、可写、通知、可读可写、安全可读,唯独没有indication属性的特征值。本篇博客针对Indication使用进行讲解。

 

1、indication属性原理

当Server想要想Client发送快速的属性状态更新时,它可以发送一条句柄值通知(Notification)。这是Server能够发给Client的两种消息中的一种,并且是不要求响应的。Server可以在任何时刻发送该Notification,同时该Notification也是不可靠的。

句柄值指示(Indication)类似于Notification,它有着相同的属性句柄字段和数值,不同的是Client收到Indication以后需要回复。Server一次只能发送一条Indication,并且只有在收到确认响应(Confirmation)后才能发起下一条Indication。这些行为都是在GATT层完成。由于有自动确认机制,Indication在很多应用层级的协议制定中有比较广泛应用。

 

 

 

 

 

 

 

2、CH58x芯片Indication的实现

由于Peripheral例程中已包含了Notification的功能,本篇博客基于该功能进行修改,对以前只接触过Notification的小白来说更加通俗易懂。

①特征值4属性修改,给Characteristic 的属性添加indication 属性

static uint8_t simpleProfileChar4Props = GATT_PROP_INDICATE;

②配置文件修改,在peripheral.c文件夹中基于Notification进行修改

static void peripheralChar4Notify(uint8_t *pValue, uint16_t len)
{
#if 0                                  //原始程序是Noti
    attHandleValueNoti_t noti;
    if(len > (peripheralMTU - 3))
    {
        PRINT("Too large noti\n");
        return;
    }
    noti.len = len;
    noti.pValue = GATT_bm_alloc(peripheralConnList.connHandle, ATT_HANDLE_VALUE_NOTI, noti.len, NULL, 0);
    if(noti.pValue)
    {
        tmos_memcpy(noti.pValue, pValue, noti.len);
        if(simpleProfile_Notify(peripheralConnList.connHandle, &noti) != SUCCESS)
        {
            GATT_bm_free((gattMsg_t *)&noti, ATT_HANDLE_VALUE_NOTI);
        }
    }
#else                                   //修改为Indication
    bStatus_t rs;
    attHandleValueInd_t indi;
    indi.len = len;
    indi.pValue = GATT_bm_alloc( peripheralConnList.connHandle, ATT_HANDLE_VALUE_IND, indi.len, NULL,0);
    if(indi.pValue)
    {
        tmos_memcpy(indi.pValue, pValue, indi.len);
        if(simpleProfile_Indi(peripheralConnList.connHandle, &indi) != SUCCESS)
        {
            GATT_bm_free((gattMsg_t *)&indi, ATT_HANDLE_VALUE_IND);
        }
    }
#endif
}

同时,函数调用simpleProfile_Indi需要重写,也是按照Noti的逻辑

bStatus_t simpleProfile_Indi(uint16_t connHandle, attHandleValueInd_t *pInd)
{
    uint16_t value = GATTServApp_ReadCharCfg(connHandle, simpleProfileChar4Config);
    // If notifications enabled
    if(value & GATT_CLIENT_CFG_INDICATE)
    {
        // Set the handle
        pInd->handle = simpleProfileAttrTbl[SIMPLEPROFILE_CHAR4_VALUE_POS].handle;

         PRINT("pInd->handle = %d\r\n", pInd->handle);
        // Send the notification
        return GATT_Indication(connHandle, pInd, FALSE, INVALID_TASK_ID);
    }
    return bleIncorrectMode;
}

 

标签:Confirmation,Handle,GATT,句柄,indi,len,Indication,noti,pValue
From: https://www.cnblogs.com/gscw/p/16859867.html

相关文章