Exemple #1
0
/*********************************************************************
 * @fn      zclLighting_ProcessInCmd_ColorControl_MoveSaturation
 *
 * @brief   Process in the received Move Saturation Command.
 *
 * @param   pInMsg - pointer to the incoming message
 * @param   pCBs - pointer to the application callbacks
 *
 * @return  ZStatus_t
 */
static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveSaturation( zclIncoming_t *pInMsg,
                                                            zclLighting_AppCallbacks_t *pCBs )
{
  zclCCMoveSaturation_t cmd;

  cmd.moveMode = pInMsg->pData[0];
  cmd.rate = pInMsg->pData[1];
    
  // If the Rate field has a value of zero, the command has no effect and
  // a Default Response command is sent in response, with the status code
  // set to INVALID_FIELD.
  if ( cmd.rate == 0 )
  {
    zclDefaultRspCmd_t defaultRspCmd;
    
    defaultRspCmd.commandID = pInMsg->hdr.commandID;
    defaultRspCmd.statusCode = ZCL_STATUS_INVALID_FIELD;
    zcl_SendDefaultRspCmd( pInMsg->msg->endPoint, &(pInMsg->msg->srcAddr),
                           pInMsg->msg->clusterId, &defaultRspCmd,
                           ZCL_FRAME_SERVER_CLIENT_DIR, true, 0, pInMsg->hdr.transSeqNum );

    // Don't need the ZCL foundation to generate another Default Response command
    return ( ZCL_STATUS_CMD_HAS_RSP );
  }
  
  if ( pCBs->pfnColorControl_MoveSaturation )
    return ( pCBs->pfnColorControl_MoveSaturation( &cmd ) );

  return ( ZFailure );
}
Exemple #2
0
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;
}