/********************************************************************* * @fn SampleApp_HandleKeys * * @brief Handles all key events for this device. * * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * HAL_KEY_SW_2 * HAL_KEY_SW_1 * * @return none */ void SampleApp_HandleKeys( uint8 shift, uint8 keys ) { (void)shift; // Intentionally unreferenced parameter if ( keys & HAL_KEY_SW_1 ) { /* This key sends the Flash Command is sent to Group 1. * This device will not receive the Flash Command from this * device (even if it belongs to group 1). */ SampleApp_SendFlashMessage( SAMPLEAPP_FLASH_DURATION ); } if ( keys & HAL_KEY_SW_2 ) { /* 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 ); } } }
ZStatus_t processGroupsClusterServerCommands(zclIncoming_t *pInMsg) { aps_Group_t group; uint8 grpCnt; uint16 *grpList; uint8 grpRspCnt = 0; ZStatus_t response; uint8 *pData; aps_Group_t *pGroup; afAddrType_t *dstAddr; pData = pInMsg->pData; group.ID = BUILD_UINT16( pData[0], pData[1] ); dstAddr = &pInMsg->msg->srcAddr; srcEP = pInMsg->msg->endPoint; seqNum = pInMsg->hdr.transSeqNum; switch(pInMsg->hdr.commandID){ case COMMAND_GROUP_ADD: response = aps_AddGroup( srcEP,& group ); if (response != ZSuccess){ if ( response == ZApsDuplicateEntry ) response = ZCL_STATUS_DUPLICATE_EXISTS; else response=ZCL_STATUS_INSUFFICIENT_SPACE; } sendGroupResponse( dstAddr, COMMAND_GROUP_ADD_RSP, response, group.ID, TRUE); response = ZCL_STATUS_CMD_HAS_RSP; break; case COMMAND_GROUP_VIEW: pGroup = aps_FindGroup( srcEP, group.ID ); if ( pGroup ) { response = ZCL_STATUS_SUCCESS; } else { // Group not found response = ZCL_STATUS_NOT_FOUND; pGroup = &group; } sendGroupViewResponse( dstAddr, response, pGroup, true ); response = ZCL_STATUS_CMD_HAS_RSP; break; case COMMAND_GROUP_GET_MEMBERSHIP: grpCnt = *pData++; // Allocate space for the group list grpList = osal_mem_alloc( sizeof( uint16 ) * APS_MAX_GROUPS ); if ( grpList != NULL ) { if ( grpCnt == 0 ) { // Find out all the groups of which the endpoint is a member. grpRspCnt = aps_FindAllGroupsForEndpoint( srcEP, grpList ); } else { // Find out the groups (in the list) of which the endpoint is a member. for ( int i = 0; i < grpCnt; i++ ){ group.ID = BUILD_UINT16( pData[0], pData[1] ); pData += 2; if ( aps_FindGroup( srcEP, group.ID ) ) grpList[grpRspCnt++] = group.ID; } } if ( grpCnt == 0 || grpRspCnt != 0 ) { sendGroupGetMembershipRequest( dstAddr, COMMAND_GROUP_GET_MEMBERSHIP_RSP, TRUE, ZCL_FRAME_SERVER_CLIENT_DIR, aps_GroupsRemaingCapacity(), grpRspCnt, grpList, true ); } osal_mem_free( grpList ); } else { // Couldn't allocate space for the group list -- send a Default Response command back. zclDefaultRspCmd_t defaultRspCmd; defaultRspCmd.commandID = pInMsg->hdr.commandID; defaultRspCmd.statusCode = ZCL_STATUS_INSUFFICIENT_SPACE; zcl_SendDefaultRspCmd( srcEP, dstAddr, pInMsg->msg->clusterId, &defaultRspCmd, ZCL_FRAME_SERVER_CLIENT_DIR, true, 0, seqNum ); } response = ZCL_STATUS_CMD_HAS_RSP; break; case COMMAND_GROUP_REMOVE: if ( aps_RemoveGroup( pInMsg->msg->endPoint, group.ID ) ) response = ZCL_STATUS_SUCCESS; else response = ZCL_STATUS_NOT_FOUND; sendGroupResponse( dstAddr, COMMAND_GROUP_REMOVE_RSP, response, group.ID, true ); response = ZCL_STATUS_CMD_HAS_RSP; break; case COMMAND_GROUP_REMOVE_ALL: case COMMAND_GROUP_ADD_IF_IDENTIFYING: default: response = ZFailure; } return response; }