/********************************************************************* * @fn SampleApp_ProcessEvent * @brief Generic Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * @return none */ uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; (void)task_id; // Intentionally unreferenced parameter if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); //Databuf = osal_mem_alloc(MSGpkt->cmd.DataLength); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { // Received when a messages is received (OTA) for this endpoint case AF_INCOMING_MSG_CMD: SampleApp_MessageMSGCB( MSGpkt ); break; default: break; } // Release the memory osal_msg_deallocate((uint8 *)MSGpkt ); // Next - if one is available MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } // Send a message out - This event is generated by a timer // (setup in SampleApp_Init()). if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT ) { SampleApp_SendPeriodicMessage(); //发送数据函数 // Setup to send message again in normal period (+ a little jitter) osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, (SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT + (osal_rand() & 0x00FF)) ); // return unprocessed events return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT); } // Discard unknown events return 0; }
/********************************************************************* * @fn SampleApp_ProcessEvent * * @brief Generic Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return none */ uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; (void)task_id; // Intentionally unreferenced parameter if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { // Received when a key is pressed case KEY_CHANGE: SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break; // Received when a messages is received (OTA) for this endpoint case AF_INCOMING_MSG_CMD: SampleApp_MessageMSGCB( MSGpkt ); break; // Received whenever the device changes state in the network 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) ) { #ifdef MODE_ED //开机或断网后测一次 #endif // Start sending the periodic message in a regular interval. osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT ); } else { // Device is no longer in the network } break; default: break; } // Release the memory osal_msg_deallocate( (uint8 *)MSGpkt ); // Next - if one is available MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } // Send a message out - This event is generated by a timer // (setup in SampleApp_Init()). if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT ) { // Send the periodic message //SampleApp_SendPeriodicMessage();//周期性发送函数 //SampleApp_SendPointToPointMessage();//此处替换成点播函数 // Setup to send message again in normal period (+ a little jitter) osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, (SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT + (osal_rand() & 0x00FF)) ); // return unprocessed events return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT); } // Discard unknown events return 0; }
/********************************************************************* * @fn SampleApp_ProcessEvent * * @brief Generic Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return none */ uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; if ((events & SEND_UARTMSG_EVT) && click) { //HalUARTWrite(SERIAL_APP_PORT, otaBuf, 2); if (otaBuf[0] =='O'){//4F HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_Ob( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[0] =='R'){//44 HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_Df( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[0] =='L' && otaBuf[1] =='F'){//46 HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_Lf( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[0] =='L' && otaBuf[1] =='N'){//53 41 HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_Ln( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[0] =='C'){ for(int i=1; i < 4; i++) id_string[i-1] = otaBuf[i]; //id_ptr = id_string; //if(id_string[0] == '0' && id_string[1] == '0' && id_string[2] == '1') //HalLedBlink( HAL_LED_4, 4, 50, 500 ); if(otaBuf[4] == 'N'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); button = 1; }else if(otaBuf[4] == 'F'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); button = 0; } SampleApp_SendFlashMessage_Coordinator_C( SAMPLEAPP_FLASH_DURATION, id_string, button ); } else if (otaBuf[0] =='S' && otaBuf[1] =='R'){ if (otaBuf[2] =='1'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_SR1( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[2] =='2'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_SR2( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[2] =='3'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_SR3( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[2] =='4'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_SR4( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[2] =='5'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_SR5( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[2] =='6'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_SR6( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[2] =='7'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_SR7( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[2] =='8'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_SR8( SAMPLEAPP_FLASH_DURATION );} else if (otaBuf[2] =='9'){ HalLedSet( HAL_LED_ALL, HAL_LED_MODE_TOGGLE); SampleApp_SendFlashMessage_Coordinator_SR9( SAMPLEAPP_FLASH_DURATION );} } //osal_memset(otaBuf,0,sizeof(otaBuf)); otaBuf = NULL; click = 0; return (events ^ SYS_EVENT_MSG); } if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { // Received when a key is pressed case KEY_CHANGE: SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break; // Received when a messages is received (OTA) for this endpoint case AF_INCOMING_MSG_CMD: //HalUARTWrite(SERIAL_APP_PORT, power, 5); HalLedBlink( HAL_LED_2, 4, 50, 500 ); SampleApp_MessageMSGCB( MSGpkt ); break; // Received whenever the device changes state in the network case ZDO_STATE_CHANGE: //SampleApp_SendFlashMessage_Coordinator_Df( SAMPLEAPP_FLASH_DURATION ); SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status); if ( SampleApp_NwkState == DEV_ZB_COORD ) { //osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, 5000 ); } else if (SampleApp_NwkState == DEV_ROUTER) { } else if (SampleApp_NwkState == DEV_END_DEVICE) { //al_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, 5000 ); //osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT ); //osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, 10 ); } else { // Device is no longer in the network } break; default: break; } // Release the memory osal_msg_deallocate( (uint8 *)MSGpkt ); // osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_UART_RECV_EVT,0); // Next - if one is available MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT ) { // SampleApp_SendFlashMessage_Endevice_Df( SAMPLEAPP_FLASH_DURATION ); //HalLedBlink(HAL_LED_4,2,50,200); //osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, 5000 ); return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT); }/* if (eventS & ZB_ENTRY_EVENT) { HalUARTWrite(SERIAL_APP_PORT, "Command sent", 12); HalUARTRead(SERIAL_APP_PORT, commandBuf, 2); HalLedBlink( HAL_LED_2, 4, 50, 500 ); //HalUARTWrite(SERIAL_APP_PORT, "Command sent", 12); if (commandBuf[0] =='O' && commandBuf[1]=='B') SampleApp_SendFlashMessage_Coordinator_Ob( SAMPLEAPP_FLASH_DURATION ); else if (commandBuf[0] =='D' && commandBuf[1]=='F') SampleApp_SendFlashMessage_Coordinator_Df( SAMPLEAPP_FLASH_DURATION ); osal_memset(commandBuf,0,sizeof(commandBuf)); //return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT); }*/ return 0; }
/********************************************************************* * @fn SampleApp_ProcessEvent * * @brief Generic Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return none */ uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; (void)task_id; // Intentionally unreferenced parameter if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); // ³z¹Losal_msg_receive function ±µ¦¬SampleApp_TaskID¼Ð»x while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { case KEY_CHANGE: // Received when a key is pressed(·í«ö¤Ukey®É¶i¦æ±µ¦¬) SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break; case AF_INCOMING_MSG_CMD: // Received when a messages is received (OTA) for this endpoint(·íendpoint±µ¦¬¨ìmessage¶i¦æ±µ¦¬) SampleApp_MessageMSGCB( MSGpkt ); break; case ZDO_STATE_CHANGE: // Received whenever the device changes state in the network(¥[¤Jºô¸ô«áª¬ºA§ïÅܮɶi¦æ±µ¦¬) 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. ¶}©l¦b©w´Áªº®É¶¡¶¡¹j¶Ç°e©w´Á°T®§ osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT ); } else { /* Device is no longer in the network(device¤£¦b¦¹ºô¸ô¤¤) */ } break; default: break; } // Release the memory osal_msg_deallocate( (uint8 *)MSGpkt ); // Next - if one is available MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } // Send a message out - This event is generated by a timer (setup in SampleApp_Init()). if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT ) { // Send the periodic message SampleApp_SendPeriodicMessage(); // Setup to send message again in normal period (+ a little jitter) osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, (SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT + (osal_rand() & 0x00FF)) ); // return unprocessed events return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT); } // Discard unknown events return 0; }