CH582MPeripheral例程問(wèn)題
uint16_t?Peripheral_ProcessEvent(uint8_t?task_id,?uint16_t?events)
{
??...
????if(events?&?SBP_PERIODIC_EVT)
????{
????????if(SBP_PERIODIC_EVT_PERIOD)
????????{
????????????tmos_start_task(Peripheral_TaskID,?SBP_PERIODIC_EVT,?SBP_PERIODIC_EVT_PERIOD);
????????}
????????performPeriodicTask();
????????return?(events?^?SBP_PERIODIC_EVT);
????}
??...
}


static?void?performPeriodicTask(void)
{
????uint8_t?notiData[SIMPLEPROFILE_CHAR4_LEN]?=?{0x88};
????peripheralChar4Notify(notiData,?SIMPLEPROFILE_CHAR4_LEN);
}

static?void?peripheralChar4Notify(uint8_t?*pValue,?uint16_t?len)
{
????attHandleValueNoti_t?noti;
????if(len?>?(peripheralMTU?-?3))
????{
????????PRINT("Too?large?noti\r\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);
????????}
????}
}

當(dāng)BLE調(diào)試助手開(kāi)啟Characteristic 4的通知功能 ,上述幾個(gè)函數(shù)將周期向主機(jī)發(fā)送通知

有幾個(gè)問(wèn)題請(qǐng)教各位大神

1、如何觸發(fā)開(kāi)啟或關(guān)閉周期發(fā)送通知

2、它是如何知道是gattprofile服務(wù)中Characteristic 4 的通知

連接后開(kāi)啟noti的功能是主機(jī)在進(jìn)行,如果主機(jī)是手機(jī)的話是手機(jī)APP進(jìn)行開(kāi)啟接收的。主機(jī)是的CH582M的話可以參考主機(jī)例程例程中有開(kāi)啟通知的功能。

else if(centralDiscState == BLE_DISC_STATE_CCCD)
{
if(pMsg->method == ATT_READ_BY_TYPE_RSP &&
pMsg->msg.readByTypeRsp.numPairs > 0)
{
centralCCCDHdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0],
pMsg->msg.readByTypeRsp.pDataList[1]);
centralProcedureInProgress = FALSE;

// Start do write CCCD
tmos_start_task(centralTaskId, START_WRITE_CCCD_EVT, DEFAULT_WRITE_CCCD_DELAY);? ? ? ? ? ?//通過(guò)這個(gè)寫(xiě)任務(wù)打開(kāi)notify

// Display Characteristic 1 handle
PRINT("Found client characteristic configuration handle : %x \n", centralCCCDHdl);
}
centralDiscState = BLE_DISC_STATE_IDLE;
}

從機(jī)開(kāi)啟通知的功能:

uint8 enable_notify(uint16 connection_handle,uint8 enable) {
uint16 cccd = 0;
if(enable) {
cccd |= GATT_CLIENT_CFG_NOTIFY;
}else {
cccd &= ~GATT_CLIENT_CFG_NOTIFY;
}
return GATTServApp_WriteCharCfg( connection_handle, simpleProfileChar4Config, cccd );
}

在連接后此函數(shù)(Peripheral_LinkEstablished)調(diào)用就可以了。

如果需要修改定時(shí)發(fā)送可以修改本事件。

?if(events?&?SBP_PERIODIC_EVT)
????{
????????if(SBP_PERIODIC_EVT_PERIOD)
????????{
????????????tmos_start_task(Peripheral_TaskID,?SBP_PERIODIC_EVT,?SBP_PERIODIC_EVT_PERIOD);
????????}
????????performPeriodicTask();
????????return?(events?^?SBP_PERIODIC_EVT);
????}


問(wèn)題二:你使用的手機(jī)APP此處查詢服務(wù)是APP完成的可以參考本鏈接的APP的demo

http://m.findthetime.net/downloads/WCHBleLib_MultiOS_ZIP.html


icon_jpg.gif1692146558884.png

RB_IER_RESET 此位是將整個(gè)串口功能關(guān)閉還是只是禁止R8_UARTx_IER單個(gè)寄存器


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频