//任務(wù)處理函數(shù)
UINT16 GenericApp_ProcessEvent( byte task_id, UINT16 events )
{
//定義應(yīng)用層數(shù)據(jù)包
afIncomingMSGPacket_t *MSGpkt;
//如果系統(tǒng)消息到來
if ( events & SYS_EVENT_MSG )
{
//接收數(shù)據(jù)包
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
//如果數(shù)據(jù)包不為空
while ( MSGpkt )
{
//判斷消息類型
switch ( MSGpkt->hdr.event )
{
//處理在初始化中注冊(cè)的消息
case ZDO_CB_MSG:
SAPI_ProcessZDOMsgs( (zdoIncomingMsg_t *)pMsg );
break;
//按鍵消息
case KEY_CHANGE:
//調(diào)用按鍵處理函數(shù)
GenericApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
//數(shù)據(jù)發(fā)送后返回信息處理函數(shù)
case AF_DATA_CONFIRM_CMD:
// This message is received as a confirmation of a data packet sent.
// The status is of ZStatus_t type [defined in ZComDef.h]
// The message fields are defined in AF.h
pDataConfirm = (afDataConfirm_t *) pMsg;
SAPI_SendDataConfirm( pDataConfirm->transID, pDataConfirm->hdr.status );
break;
//接收數(shù)據(jù)事件
case AF_INCOMING_MSG_CMD:
//調(diào)接收數(shù)據(jù)的處理函數(shù)
GenericApp_MessageMSGCB( MSGpkt );
break;
//網(wǎng)絡(luò)狀態(tài)發(fā)生變化事件
case ZDO_STATE_CHANGE:
//獲取網(wǎng)絡(luò)狀態(tài)
GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
//判斷網(wǎng)絡(luò)類型
if ( (GenericApp_NwkState == DEV_ZB_COORD)
|| (GenericApp_NwkState == DEV_ROUTER)
|| (GenericApp_NwkState == DEV_END_DEVICE) )
{
}
break;
default:
break;
}
//釋放存儲(chǔ)區(qū)
osal_msg_deallocate( (uint8 *)MSGpkt );
//判斷操作系統(tǒng)層是否有未處理的數(shù)據(jù)包,繼續(xù)處理緩沖區(qū)中的包
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
}
// 返回未處理的任務(wù)
return (events ^ SYS_EVENT_MSG);
}
// Discard unknown events
return 0;
}