/*********************************************************************
* @fn SerialApp_ProcessEvent
*
* @brief Generic Application Task event processor.
*
* @param task_id - The OSAL assigned task ID.
* @param events - Bit map of events to process.
*
* @return Event flags of all unprocessed events.
*/
UINT16 SerialApp_ProcessEvent( uint8 task_id, UINT16 events )
{
(void)task_id; // Intentionally unreferenced parameter
if ( events & SYS_EVENT_MSG )
{
afIncomingMSGPacket_t *MSGpkt;
while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SerialApp_TaskID )) )
{
switch ( MSGpkt->hdr.event )
{
case KEY_CHANGE:
SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
case AF_INCOMING_MSG_CMD:
SerialApp_ProcessMSGCmd( MSGpkt );
break;
case ZDO_STATE_CHANGE:
SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
if ( (SampleApp_NwkState == DEV_ZB_COORD)
|| (SampleApp_NwkState == DEV_ROUTER)
|| (SampleApp_NwkState == DEV_END_DEVICE) )
{
// Start sending the periodic message in a regular interval.
HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);
if(SampleApp_NwkState != DEV_ZB_COORD)
SerialApp_DeviceConnect();
}
else
{
// Device is no longer in the network
}
break;
default:
break;
}
osal_msg_deallocate( (uint8 *)MSGpkt );
}
return ( events ^ SYS_EVENT_MSG );
}
if ( events & SERIALAPP_SEND_EVT )
{
SerialApp_Send();
return ( events ^ SERIALAPP_SEND_EVT );
}
if ( events & SERIALAPP_RESP_EVT )
{
SerialApp_Resp();
return ( events ^ SERIALAPP_RESP_EVT );
}
return ( 0 ); // Discard unknown events.
}
void SampleApp_HandleKeys( uint8 shift, uint8 keys )
{
(void)shift; // Intentionally unreferenced parameter
if ( keys & HAL_KEY_SW_6 )
{
//#if defined(ZDO_COORDINATOR) //协调器只接收数据
//SampleApp_SendPeriodicMessage(); //以组播方式发数据
//#else //路由器和终端才发送数据
//#endif
HalLcdWriteString( "1111: ", HAL_LCD_LINE_1 );
}
if ( keys & HAL_KEY_SW_1 )
{
HalLcdWriteString( "2222: ", HAL_LCD_LINE_1 );
/* The Flashr Command is sent to Group 1.
* This key toggles this device in and out of group 1.
* If this device doesn't belong to group 1, this application
* will not receive the Flash command sent to group 1.
*/
//aps_Group_t *grp;
//grp = aps_FindGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP );
//if ( grp )
//{
// Remove from the group
// aps_RemoveGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP );
//}
//else
//{
// Add to the flash group
// aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );
//}
}
}
* @fn SerialApp_ProcessEvent
*
* @brief Generic Application Task event processor.
*
* @param task_id - The OSAL assigned task ID.
* @param events - Bit map of events to process.
*
* @return Event flags of all unprocessed events.
*/
UINT16 SerialApp_ProcessEvent( uint8 task_id, UINT16 events )
{
(void)task_id; // Intentionally unreferenced parameter
if ( events & SYS_EVENT_MSG )
{
afIncomingMSGPacket_t *MSGpkt;
while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SerialApp_TaskID )) )
{
switch ( MSGpkt->hdr.event )
{
case KEY_CHANGE:
SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
case AF_INCOMING_MSG_CMD:
SerialApp_ProcessMSGCmd( MSGpkt );
break;
case ZDO_STATE_CHANGE:
SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
if ( (SampleApp_NwkState == DEV_ZB_COORD)
|| (SampleApp_NwkState == DEV_ROUTER)
|| (SampleApp_NwkState == DEV_END_DEVICE) )
{
// Start sending the periodic message in a regular interval.
HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);
if(SampleApp_NwkState != DEV_ZB_COORD)
SerialApp_DeviceConnect();
}
else
{
// Device is no longer in the network
}
break;
default:
break;
}
osal_msg_deallocate( (uint8 *)MSGpkt );
}
return ( events ^ SYS_EVENT_MSG );
}
if ( events & SERIALAPP_SEND_EVT )
{
SerialApp_Send();
return ( events ^ SERIALAPP_SEND_EVT );
}
if ( events & SERIALAPP_RESP_EVT )
{
SerialApp_Resp();
return ( events ^ SERIALAPP_RESP_EVT );
}
return ( 0 ); // Discard unknown events.
}
void SampleApp_HandleKeys( uint8 shift, uint8 keys )
{
(void)shift; // Intentionally unreferenced parameter
if ( keys & HAL_KEY_SW_6 )
{
//#if defined(ZDO_COORDINATOR) //协调器只接收数据
//SampleApp_SendPeriodicMessage(); //以组播方式发数据
//#else //路由器和终端才发送数据
//#endif
HalLcdWriteString( "1111: ", HAL_LCD_LINE_1 );
}
if ( keys & HAL_KEY_SW_1 )
{
HalLcdWriteString( "2222: ", HAL_LCD_LINE_1 );
/* The Flashr Command is sent to Group 1.
* This key toggles this device in and out of group 1.
* If this device doesn't belong to group 1, this application
* will not receive the Flash command sent to group 1.
*/
//aps_Group_t *grp;
//grp = aps_FindGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP );
//if ( grp )
//{
// Remove from the group
// aps_RemoveGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP );
//}
//else
//{
// Add to the flash group
// aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );
//}
}
}