use of org.omg.space.xtce.CommandContainerEntryListType 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);
}
Aggregations