/********************************************************************* * @fn zcl_ProcessZDOMsgs * * @brief Process response messages. * * @param inMsg - ZDO response message. * * @return none */ static void zcl_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg ) { uint8 response; switch( inMsg->clusterID ) { case End_Device_Bind_rsp: response = ZDO_ParseBindRsp( inMsg ); if ( response == ZSuccess ) { debug_str( "Bind succeeded." ); #if DEV_TYPE != COORDINATOR zcl_SendDeviceData(); #endif } break; #if DEV_TYPE == COORDINATOR case Device_annce: { ZDO_DeviceAnnce_t msg; uint8 buffer[50]; ZDO_ParseDeviceAnnce( inMsg, &msg ); sprintf( ( char* )buffer, "New device joined, address: %d", msg.nwkAddr ); zcl_SendBindRequest(); } break; #endif } }
/********************************************************************* * @fn SerialApp_ProcessZDOMsgs() * * @brief Process response messages * * @param none * * @return none */ static void SerialApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg ) { switch ( inMsg->clusterID ) { case End_Device_Bind_rsp: if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess ) { // Light LED HalLedSet( HAL_LED_1, HAL_LED_MODE_ON ); osal_stop_timerEx(SerialApp_TaskID,SERIALAPP_MSG_AUTOMATCH); } #if defined(BLINK_LEDS) else { // Flash LED to show failure HalLedSet ( HAL_LED_1, HAL_LED_MODE_FLASH ); } #endif break; case Match_Desc_rsp: { ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg ); if ( pRsp ) { if ( pRsp->status == ZSuccess && pRsp->cnt && SerialApp_DstAddr.addrMode == afAddrNotPresent ) { osal_stop_timerEx(SerialApp_TaskID,SERIALAPP_MSG_AUTOMATCH); SerialApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; #if defined(ZDO_COORDINATOR) SerialApp_DstAddr.addr.shortAddr = pRsp->nwkAddr; #else SerialApp_DstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVZCZR; #endif // Take the first endpoint, Can be changed to search through endpoints SerialApp_DstAddr.endPoint = pRsp->epList[0]; // Light LED HalLedSet( HAL_LED_2, HAL_LED_MODE_ON ); #if defined(ZDO_COORDINATOR) HalUARTWrite(SERIAL_APP_PORT,"OK\n",3); #endif } osal_mem_free( pRsp ); } } break; } }
/********************************************************************* * @fn GenericApp_ProcessZDOMsgs() * * @brief Process response messages * * @param none * * @return none */ static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg ) { switch ( inMsg->clusterID ) { case End_Device_Bind_rsp: if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess ) { // Light LED HalLedSet( HAL_LED_2, HAL_LED_MODE_ON ); } #if defined( BLINK_LEDS ) else { // Flash LED to show failure HalLedSet ( HAL_LED_2, HAL_LED_MODE_FLASH ); } #endif break; case Match_Desc_rsp: { uprint("Match_Decs_rsp"); ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg ); if ( pRsp ) { if ( pRsp->status == ZSuccess && pRsp->cnt ) { GenericApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; //GenericApp_DstAddr.addr.shortAddr = pRsp->nwkAddr; GenericApp_DstAddr.addr.shortAddr = 0xFFFF; // Take the first endpoint, Can be changed to search through endpoints GenericApp_DstAddr.endPoint = pRsp->epList[0]; // Light LED //HalLedSet( HAL_LED_2, HAL_LED_MODE_ON ); } osal_mem_free( pRsp ); } } break; } }
//This function process the ZDO events to bind static void ParkWay_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg ) { switch ( inMsg->clusterID ) { case End_Device_Bind_rsp: if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess ) { // Light LED //HalLedSet ( HAL_LED_2, HAL_LED_MODE_FLASH ); } break; case Match_Desc_rsp: { ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg ); if ( pRsp ) { if ( pRsp->status == ZSuccess && pRsp->cnt ) { ParkWay_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; ParkWay_DstAddr.addr.shortAddr = pRsp->nwkAddr; // Take the first endpoint, Can be changed to search through endpoints ParkWay_DstAddr.endPoint = pRsp->epList[0]; // Light LED //HalLedSet( HAL_LED_2, HAL_LED_MODE_ON ); //This stop the peer from send request do the coordinator //HalLedSet ( HAL_LED_1, HAL_LED_MODE_OFF); osal_stop_timerEx( ParkWay_TaskID,POLLING_OF_DEV_EVT); } osal_mem_free( pRsp ); } } break; } }