工具/软件:
您好、TI
*SDK 版本:9.11.00.18、示例: key_node
我们需要通过蓝牙传输按键事件。 为了实现这一点、我修改了 密钥中断回调函数 可将密钥数据转发到 BLE 堆栈 流经 BLE 消息队列 。
void BLE_button_event(uint32_t event, GapAdv_data_t *pBuf, uint32_t arg)
{
BLEAppUtil_AdvEventData_t *pData = BLEAppUtil_malloc(sizeof(BLEAppUtil_AdvEventData_t));
if (pData != NULL)
{
pData->event = event;
pData->pBuf = pBuf;
pData->arg = &arg;
// Enqueue the event
if (BLEAppUtil_enqueueMsg(BLEAPPUTIL_EVT_ADV_CB_EVENT, pData) != SUCCESS)
{
if (pBuf != NULL)
{
BLEAppUtil_free(pBuf);
}
BLEAppUtil_free(pData);
}
}
else
{
if (pBuf != NULL)
{
BLEAppUtil_free(pBuf);
}
}
}
void App_ButtonCallBack(uint32_t events, uint32_t button_id) /*IN: Events from keyboard module */
{
BLE_button_event(events, NULL, button_id);
}
/*
* ======== handleButtonCallback ========
*/
void handleButtonCallback(Button_Handle handle, Button_EventMask events)
{
if (Button_EV_CLICKED == (events & Button_EV_CLICKED))
{
if(handle == buttonHandle[CONFIG_BUTTON_0])
{
button_num = 0x00;
App_ButtonCallBack(BLEAPPUTIL_BUTTON_CLICK, button_num);
}
else if(handle == buttonHandle[CONFIG_BUTTON_1])
{
button_num = 0x01;
App_ButtonCallBack(BLEAPPUTIL_BUTTON_CLICK, button_num);
}
else
{}
}
}
我在 Peripheral_Adv EventHandler 中接收并打印按键数据、但发现收到的 advMsg->arg 有时与预期值不匹配、似乎在该过程中发生了变化。
我向蓝牙堆栈传输按键数据的方法是否符合规格? 什么可能导致这种异常数据变化?
/*********************************************************************
* @fn Peripheral_AdvEventHandler
*
* @brief The purpose of this function is to handle peripheral state
* events that rise from the GAP and were registered
* in @ref BLEAppUtil_registerEventHandler
*
* @param event - message event.
* @param pMsgData - pointer to message data.
*
* @return none
*/
static void Peripheral_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
{
// if (pMsgData != NULL)
// {
// // Send the event to the upper layer
// Peripheral_extEvtHandler(BLEAPPUTIL_GAP_ADV_TYPE, event, pMsgData);
// }
BLEAppUtil_AdvEventData_t *scanMsg = (BLEAppUtil_AdvEventData_t *)pMsgData;
switch(event)
{
case BLEAPPUTIL_ADV_START_AFTER_ENABLE:
{
PHSCA_ESELOG_PRINTF("Adv status: Started - handle: %d", ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);
break;
}
case BLEAPPUTIL_ADV_END_AFTER_DISABLE:
{
PHSCA_ESELOG_PRINTF("Adv status: Ended - handle: %d", ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);
if(linkDB_NumActive() < linkDB_NumConns())
{
Peripheral_advStart(pMsgData);
}
break;
}
case BLEAPPUTIL_BUTTON_CLICK:
{
PHSCA_ESELOG_PRINTF("scanMsg->arg[0x%2x]\r\n", (*(scanMsg->arg))&0xFF);
break;
}
default:
{
break;
}
}
}
此致!
普雷斯顿