/********************************************************************* * @fn loadcontrol_SendReportEventStatus * * @brief Callback from the ZCL SE Profile Message Cluster Library when * it received a Load Control Event Command for * this application. * * @param afAddrType_t *srcAddr - pointer to source address * @param uint8 seqNum - sequence number for this event * @param uint32 eventID - event ID for this event * @param uint32 startTime - start time for this event * @param uint8 eventStatus - status for this event * @param uint8 criticalityLevel - criticality level for this event * @param uint8 eventControl - event control for this event * * @return none */ static void loadcontrol_SendReportEventStatus( afAddrType_t *srcAddr, uint8 seqNum, uint32 eventID, uint32 startTime, uint8 eventStatus, uint8 criticalityLevel, uint8 eventControl ) { // Mandatory fields - use the incoming data rsp.issuerEventID = eventID; rsp.eventStartTime = startTime; rsp.criticalityLevelApplied = criticalityLevel; rsp.eventControl = eventControl; rsp.eventStatus = eventStatus; rsp.signatureType = SE_PROFILE_SIGNATURE_TYPE_ECDSA; // loadcontrol_Signature is a static array. // value can be changed in loadcontrol_data.c osal_memcpy( rsp.signature, loadControlSignature, SE_PROFILE_SIGNATURE_LENGTH ); // Optional fields - fill in with non-used value by default rsp.coolingTemperatureSetPointApplied = SE_OPTIONAL_FIELD_TEMPERATURE_SET_POINT; rsp.heatingTemperatureSetPointApplied = SE_OPTIONAL_FIELD_TEMPERATURE_SET_POINT; rsp.averageLoadAdjustment = SE_OPTIONAL_FIELD_INT8; rsp.dutyCycleApplied = SE_OPTIONAL_FIELD_UINT8; // Send response back // DisableDefaultResponse is set to false - it is recommended to turn on // default response since Report Event Status Command does not have // a response. zclSE_LoadControl_Send_ReportEventStatus( LOADCONTROL_ENDPOINT, srcAddr, &rsp, false, seqNum ); }
/********************************************************************* * @fn loadcontrol_event_loop * * @brief Event Loop Processor for loadcontrol. * * @param uint8 task id - load control task id * @param uint16 events - event bitmask * * @return none */ uint16 loadcontrol_event_loop( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; if ( events & SYS_EVENT_MSG ) { while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( loadControlTaskID )) ) { switch ( MSGpkt->hdr.event ) { case ZCL_INCOMING_MSG: // Incoming ZCL foundation command/response messages loadcontrol_ProcessZCLMsg( (zclIncomingMsg_t *)MSGpkt ); break; case KEY_CHANGE: loadcontrol_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break; case ZDO_STATE_CHANGE: if (DEV_ROUTER == (devStates_t)(MSGpkt->hdr.status)) { #if SECURE { // check to see if link key had already been established linkKeyStatus = loadcontrol_KeyEstablish_ReturnLinkKey(ESPAddr.addr.shortAddr); if (linkKeyStatus != ZSuccess) { // send out key establishment request osal_set_event( loadControlTaskID, LOADCONTROL_KEY_ESTABLISHMENT_REQUEST_EVT); } } #endif } break; default: break; } // Release the memory osal_msg_deallocate( (uint8 *)MSGpkt ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } // event to intiate key establishment request if ( events & LOADCONTROL_KEY_ESTABLISHMENT_REQUEST_EVT ) { zclGeneral_KeyEstablish_InitiateKeyEstablishment(loadControlTaskID, &ESPAddr, loadControlTransID); return ( events ^ LOADCONTROL_KEY_ESTABLISHMENT_REQUEST_EVT ); } // handle processing of identify timeout event triggered by an identify command if ( events & LOADCONTROL_IDENTIFY_TIMEOUT_EVT ) { if ( loadControlIdentifyTime > 0 ) { loadControlIdentifyTime--; } loadcontrol_ProcessIdentifyTimeChange(); return ( events ^ LOADCONTROL_IDENTIFY_TIMEOUT_EVT ); } // event to get current time if ( events & LOADCONTROL_UPDATE_TIME_EVT ) { loadControlTime = osal_getClock(); osal_start_timerEx( loadControlTaskID, LOADCONTROL_UPDATE_TIME_EVT, LOADCONTROL_UPDATE_TIME_PERIOD ); return ( events ^ LOADCONTROL_UPDATE_TIME_EVT ); } // event to handle load control complete event if ( events & LOADCONTROL_LOAD_CTRL_EVT ) { // load control evt completed // Send response back // DisableDefaultResponse is set to false - it is recommended to turn on // default response since Report Event Status Command does not have // a response. rsp.eventStatus = EVENT_STATUS_LOAD_CONTROL_EVENT_COMPLETED; zclSE_LoadControl_Send_ReportEventStatus( LOADCONTROL_ENDPOINT, &ESPAddr, &rsp, false, loadControlTransID ); HalLcdWriteString("Load Evt Complete", HAL_LCD_LINE_3); HalLedSet(HAL_LED_4, HAL_LED_MODE_OFF); return ( events ^ LOADCONTROL_LOAD_CTRL_EVT ); } // Discard unknown events return 0; }
/********************************************************************* * @fn loadcontrol_event_loop * * @brief Event Loop Processor for loadcontrol. * * @param uint8 task id - load control task id * @param uint16 events - event bitmask * * @return none */ uint16 loadcontrol_event_loop( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; if ( events & SYS_EVENT_MSG ) { while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( loadControlTaskID )) ) { switch ( MSGpkt->hdr.event ) { case ZDO_CB_MSG: loadcontrol_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt ); break; case ZCL_INCOMING_MSG: // Incoming ZCL foundation command/response messages loadcontrol_ProcessZCLMsg( (zclIncomingMsg_t *)MSGpkt ); break; case KEY_CHANGE: loadcontrol_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break; case ZDO_STATE_CHANGE: if (DEV_ROUTER == (devStates_t)(MSGpkt->hdr.status)) { #if SECURE { // check to see if link key had already been established linkKeyStatus = loadcontrol_KeyEstablish_ReturnLinkKey(ESPAddr.addr.shortAddr); if (linkKeyStatus != ZSuccess) { cId_t cbkeCluster = ZCL_CLUSTER_ID_GEN_KEY_ESTABLISHMENT; zAddrType_t dstAddr; // Send out a match for the key establishment dstAddr.addrMode = AddrBroadcast; dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR; ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR, ZCL_SE_PROFILE_ID, 1, &cbkeCluster, 0, NULL, FALSE ); } } #endif } break; #if defined( ZCL_KEY_ESTABLISH ) case ZCL_KEY_ESTABLISH_IND: if ((MSGpkt->hdr.status) == TermKeyStatus_Success) { ESPAddr.endPoint = LOADCONTROL_ENDPOINT; // set destination endpoint back to application endpoint } break; #endif default: break; } // Release the memory osal_msg_deallocate( (uint8 *)MSGpkt ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } // event to intiate key establishment request if ( events & LOADCONTROL_KEY_ESTABLISHMENT_REQUEST_EVT ) { zclGeneral_KeyEstablish_InitiateKeyEstablishment(loadControlTaskID, &ESPAddr, loadControlTransID); return ( events ^ LOADCONTROL_KEY_ESTABLISHMENT_REQUEST_EVT ); } // handle processing of identify timeout event triggered by an identify command if ( events & LOADCONTROL_IDENTIFY_TIMEOUT_EVT ) { if ( loadControlIdentifyTime > 0 ) { loadControlIdentifyTime--; } loadcontrol_ProcessIdentifyTimeChange(); return ( events ^ LOADCONTROL_IDENTIFY_TIMEOUT_EVT ); } // event to get current time if ( events & LOADCONTROL_UPDATE_TIME_EVT ) { loadControlTime = osal_getClock(); osal_start_timerEx( loadControlTaskID, LOADCONTROL_UPDATE_TIME_EVT, LOADCONTROL_UPDATE_TIME_PERIOD ); return ( events ^ LOADCONTROL_UPDATE_TIME_EVT ); } // event to handle load control complete event if ( events & LOADCONTROL_LOAD_CTRL_EVT ) { // load control evt completed // Send response back // DisableDefaultResponse is set to FALSE - it is recommended to turn on // default response since Report Event Status Command does not have // a response. rsp.eventStatus = EVENT_STATUS_LOAD_CONTROL_EVENT_COMPLETED; zclSE_LoadControl_Send_ReportEventStatus( LOADCONTROL_ENDPOINT, &ESPAddr, &rsp, FALSE, loadControlTransID ); HalLcdWriteString("Load Evt Complete", HAL_LCD_LINE_3); HalLedSet(HAL_LED_4, HAL_LED_MODE_OFF); return ( events ^ LOADCONTROL_LOAD_CTRL_EVT ); } // Discard unknown events return 0; }