Search in sources :

Example 1 with ArgumentRefEntry

use of org.omg.space.xtce.CommandContainerEntryListType.ArgumentRefEntry in project CCDD by nasa.

the class CcddXTCEHandler method addCommand.

/**
 ********************************************************************************************
 * Add a command metadata set to the command metadata
 *
 * @param spaceSystem
 *            space system
 *
 * @param commandName
 *            command name
 *
 * @param commandCode
 *            command code
 *
 * @param isCmdHeader
 *            true if this table represents the CCSDS command header
 *
 * @param argumentNames
 *            list of command argument names
 *
 * @param argArraySizes
 *            list of of command argument array sizes; the list item is null or blank if the
 *            corresponding argument isn't an array
 *
 * @param description
 *            description of the command
 ********************************************************************************************
 */
private void addCommand(SpaceSystemType spaceSystem, String commandName, String commandCode, boolean isCmdHeader, String applicationID, List<String> argumentNames, List<String> argArraySizes, String description) {
    MetaCommandSet commandSet = spaceSystem.getCommandMetaData().getMetaCommandSet();
    MetaCommandType command = factory.createMetaCommandType();
    // Set the command name attribute
    command.setName(commandName);
    // Check is a command description exists
    if (description != null && !description.isEmpty()) {
        // Set the command description attribute
        command.setLongDescription(description);
    }
    // Check if the command has any arguments
    if (!argumentNames.isEmpty()) {
        int index = 0;
        ArgumentList argList = factory.createMetaCommandTypeArgumentList();
        CommandContainerType cmdContainer = factory.createCommandContainerType();
        CommandContainerEntryListType entryList = factory.createCommandContainerEntryListType();
        // Step through each argument
        for (String argumentName : argumentNames) {
            // Set the flag to indicate that the argument is an array
            boolean isArray = argArraySizes.get(index) != null && !argArraySizes.get(index).isEmpty();
            // Add the argument to the the command's argument list
            Argument arg = new Argument();
            arg.setName(argumentName);
            arg.setArgumentTypeRef(argumentName + (isArray ? ARRAY : TYPE));
            argList.getArgument().add(arg);
            // Store the argument reference in the list
            ArgumentRefEntry argumentRef = factory.createCommandContainerEntryListTypeArgumentRefEntry();
            argumentRef.setArgumentRef(argumentName);
            JAXBElement<ArgumentRefEntry> argumentRefElem = factory.createCommandContainerEntryListTypeArgumentRefEntry(argumentRef);
            entryList.getParameterRefEntryOrParameterSegmentRefEntryOrContainerRefEntry().add(argumentRefElem);
            // Check if the command argument is an array
            if (isArray) {
                DimensionList dimList = factory.createArrayParameterRefEntryTypeDimensionList();
                // Set the array dimension start index (always 0)
                IntegerValueType startVal = factory.createIntegerValueType();
                startVal.setFixedValue(String.valueOf(0));
                // Step through each array dimension
                for (int arrayDim : ArrayVariable.getArrayIndexFromSize(argArraySizes.get(index))) {
                    // Create the dimension and set the start and end indices (the end index is
                    // the number of elements in this array dimension)
                    Dimension dim = factory.createArrayParameterRefEntryTypeDimensionListDimension();
                    IntegerValueType endVal = factory.createIntegerValueType();
                    endVal.setFixedValue(String.valueOf(arrayDim));
                    dim.setStartingIndex(startVal);
                    dim.setEndingIndex(endVal);
                    dimList.getDimension().add(dim);
                }
                // Store the array parameter array reference in the list
                ArrayParameterRefEntryType arrayRef = factory.createArrayParameterRefEntryType();
                arrayRef.setParameterRef(argumentName);
                arrayRef.setDimensionList(dimList);
                JAXBElement<ArrayParameterRefEntryType> arrayRefElem = factory.createCommandContainerEntryListTypeArrayArgumentRefEntry(arrayRef);
                entryList.getParameterRefEntryOrParameterSegmentRefEntryOrContainerRefEntry().add(arrayRefElem);
            }
            index++;
        }
        // Check if this table represents the CCSDS command header
        if (isCmdHeader) {
            command.setAbstract(true);
        } else // Not the command header. Check if the command ID is provided
        if (!isCmdHeader && applicationID != null && !applicationID.isEmpty() && cmdHeaderTable != null && !cmdHeaderTable.isEmpty()) {
            // Create the reference to the base meta-command and set it to the empty base, in
            // case no command header is defined
            BaseMetaCommand baseCmd = factory.createMetaCommandTypeBaseMetaCommand();
            baseCmd.setMetaCommandRef("/" + project.getValue().getName() + (cmdHeaderPath == null || cmdHeaderPath.isEmpty() ? "" : "/" + cmdHeaderPath) + "/" + cmdHeaderTable + "/" + cmdHeaderTable);
            // Create the argument assignment list and store the application ID
            ArgumentAssignmentList argAssnList = factory.createMetaCommandTypeBaseMetaCommandArgumentAssignmentList();
            ArgumentAssignment argAssn = factory.createMetaCommandTypeBaseMetaCommandArgumentAssignmentListArgumentAssignment();
            argAssn.setArgumentName(ccsdsAppID);
            argAssn.setArgumentValue(applicationID);
            argAssnList.getArgumentAssignment().add(argAssn);
            // Check if a command code is provided
            if (commandCode != null && !commandCode.isEmpty()) {
                // Store the command code
                argAssn = factory.createMetaCommandTypeBaseMetaCommandArgumentAssignmentListArgumentAssignment();
                argAssn.setArgumentName(ccsdsFuncCode);
                argAssn.setArgumentValue(commandCode);
                argAssnList.getArgumentAssignment().add(argAssn);
            }
            baseCmd.setArgumentAssignmentList(argAssnList);
            command.setBaseMetaCommand(baseCmd);
        }
        command.setArgumentList(argList);
        cmdContainer.setEntryList(entryList);
        command.setCommandContainer(cmdContainer);
    }
    commandSet.getMetaCommandOrMetaCommandRefOrBlockMetaCommand().add(command);
}
Also used : MetaCommandSet(org.omg.space.xtce.CommandMetaDataType.MetaCommandSet) Argument(org.omg.space.xtce.MetaCommandType.ArgumentList.Argument) CommandContainerType(org.omg.space.xtce.CommandContainerType) IntegerValueType(org.omg.space.xtce.IntegerValueType) Dimension(org.omg.space.xtce.ArrayParameterRefEntryType.DimensionList.Dimension) ArgumentList(org.omg.space.xtce.MetaCommandType.ArgumentList) CommandContainerEntryListType(org.omg.space.xtce.CommandContainerEntryListType) ArgumentAssignment(org.omg.space.xtce.MetaCommandType.BaseMetaCommand.ArgumentAssignmentList.ArgumentAssignment) ArgumentRefEntry(org.omg.space.xtce.CommandContainerEntryListType.ArgumentRefEntry) BaseMetaCommand(org.omg.space.xtce.MetaCommandType.BaseMetaCommand) ArrayParameterRefEntryType(org.omg.space.xtce.ArrayParameterRefEntryType) DimensionList(org.omg.space.xtce.ArrayParameterRefEntryType.DimensionList) ArgumentAssignmentList(org.omg.space.xtce.MetaCommandType.BaseMetaCommand.ArgumentAssignmentList) MetaCommandType(org.omg.space.xtce.MetaCommandType)

Aggregations

ArrayParameterRefEntryType (org.omg.space.xtce.ArrayParameterRefEntryType)1 DimensionList (org.omg.space.xtce.ArrayParameterRefEntryType.DimensionList)1 Dimension (org.omg.space.xtce.ArrayParameterRefEntryType.DimensionList.Dimension)1 CommandContainerEntryListType (org.omg.space.xtce.CommandContainerEntryListType)1 ArgumentRefEntry (org.omg.space.xtce.CommandContainerEntryListType.ArgumentRefEntry)1 CommandContainerType (org.omg.space.xtce.CommandContainerType)1 MetaCommandSet (org.omg.space.xtce.CommandMetaDataType.MetaCommandSet)1 IntegerValueType (org.omg.space.xtce.IntegerValueType)1 MetaCommandType (org.omg.space.xtce.MetaCommandType)1 ArgumentList (org.omg.space.xtce.MetaCommandType.ArgumentList)1 Argument (org.omg.space.xtce.MetaCommandType.ArgumentList.Argument)1 BaseMetaCommand (org.omg.space.xtce.MetaCommandType.BaseMetaCommand)1 ArgumentAssignmentList (org.omg.space.xtce.MetaCommandType.BaseMetaCommand.ArgumentAssignmentList)1 ArgumentAssignment (org.omg.space.xtce.MetaCommandType.BaseMetaCommand.ArgumentAssignmentList.ArgumentAssignment)1