use of org.omg.space.xtce.ArgumentTypeSetType in project CCDD by nasa.
the class CcddXTCEHandler method addSpaceSystemCommands.
/**
********************************************************************************************
* Add the command(s) from a table to the specified space system
*
* @param spaceSystem
* parent space system for this node
*
* @param tableInfo
* TableInformation reference for the current node
*
* @param isCmdHeader
* true if this table represents the CCSDS command header
*
* @param applicationID
* application ID
********************************************************************************************
*/
private void addSpaceSystemCommands(SpaceSystemType spaceSystem, TableInformation tableInfo, boolean isCmdHeader, String applicationID) {
// Get the column indices for the command name, code, and description
int cmdNameCol = typeDefn.getColumnIndexByInputType(InputDataType.COMMAND_NAME);
int cmdCodeCol = typeDefn.getColumnIndexByInputType(InputDataType.COMMAND_CODE);
int cmdDescCol = typeDefn.getColumnIndexByInputType(InputDataType.DESCRIPTION);
// Step through each command argument column grouping
for (AssociatedColumns cmdArg : typeDefn.getAssociatedCommandArgumentColumns(false)) {
// command description
if (cmdArg.getDescription() != -1 && cmdArg.getDescription() == cmdDescCol) {
// There is no column for the command description, so reset its column index and
// stop searching
cmdDescCol = -1;
break;
}
}
// Step through each row in the table
for (String[] rowData : tableInfo.getData()) {
// Check if the command name exists
if (cmdNameCol != -1 && !rowData[cmdNameCol].isEmpty()) {
// Initialize the command attributes and argument names list
String commandCode = null;
String commandDescription = null;
List<String> argumentNames = new ArrayList<String>();
List<String> argArraySizes = new ArrayList<String>();
// Check if this system doesn't yet have its command metadata created
if (spaceSystem.getCommandMetaData() == null) {
// Create the command metadata
createCommandMetadata(spaceSystem);
}
// Store the command name
String commandName = rowData[cmdNameCol];
// Check if the command code exists
if (cmdCodeCol != -1 && !rowData[cmdCodeCol].isEmpty()) {
// Store the command code
commandCode = rowData[cmdCodeCol];
}
// Check if the command description exists
if (cmdDescCol != -1 && !rowData[cmdDescCol].isEmpty()) {
// Store the command description
commandDescription = rowData[cmdDescCol];
}
// Step through each command argument column grouping
for (AssociatedColumns cmdArg : typeDefn.getAssociatedCommandArgumentColumns(false)) {
// Initialize the command argument attributes
String argumentName = null;
String dataType = null;
String arraySize = null;
String bitLength = null;
String enumeration = null;
String minimum = null;
String maximum = null;
String units = null;
String description = null;
int stringSize = 1;
// Check if the command argument name and data type exist
if (cmdArg.getName() != -1 && !rowData[cmdArg.getName()].isEmpty() && cmdArg.getDataType() != -1 && !rowData[cmdArg.getDataType()].isEmpty()) {
String uniqueID = "";
int dupCount = 0;
// Store the command argument name and data type
argumentName = rowData[cmdArg.getName()];
dataType = rowData[cmdArg.getDataType()];
// Check if the description column exists
if (cmdArg.getDescription() != -1 && !rowData[cmdArg.getDescription()].isEmpty()) {
// Store the command argument description
description = rowData[cmdArg.getDescription()];
}
// Check if the array size column exists
if (cmdArg.getArraySize() != -1 && !rowData[cmdArg.getArraySize()].isEmpty()) {
// Store the command argument array size value
arraySize = rowData[cmdArg.getArraySize()];
// Check if the command argument has a string data type
if (rowData[cmdArg.getDataType()].equals(DefaultPrimitiveTypeInfo.STRING.getUserName())) {
// Separate the array dimension values and get the string size
int[] arrayDims = ArrayVariable.getArrayIndexFromSize(arraySize);
stringSize = arrayDims[0];
}
}
// Check if the bit length column exists
if (cmdArg.getBitLength() != -1 && !rowData[cmdArg.getBitLength()].isEmpty()) {
// Store the command argument bit length value
bitLength = rowData[cmdArg.getBitLength()];
}
// Check if the enumeration column exists
if (cmdArg.getEnumeration() != -1 && !rowData[cmdArg.getEnumeration()].isEmpty()) {
// Store the command argument enumeration value
enumeration = rowData[cmdArg.getEnumeration()];
}
// Check if the units column exists
if (cmdArg.getUnits() != -1 && !rowData[cmdArg.getUnits()].isEmpty()) {
// Store the command argument units
units = rowData[cmdArg.getUnits()];
}
// Check if the minimum column exists
if (cmdArg.getMinimum() != -1 && !rowData[cmdArg.getMinimum()].isEmpty()) {
// Store the command argument minimum value
minimum = rowData[cmdArg.getMinimum()];
}
// Check if the maximum column exists
if (cmdArg.getMaximum() != -1 && !rowData[cmdArg.getMaximum()].isEmpty()) {
// Store the command argument maximum value
maximum = rowData[cmdArg.getMaximum()];
}
// Step through the list of argument names used so far
for (String argName : argumentNames) {
// Check if the current argument name matches an existing one
if (argumentName.equals(argName)) {
// Increment the duplicate name count
dupCount++;
}
}
// Check if a duplicate argument name exists
if (dupCount != 0) {
// Set the unique ID to the counter value
uniqueID = String.valueOf(dupCount + 1);
}
// Add the name and array status to the lists
argumentNames.add(argumentName);
argArraySizes.add(arraySize);
// Set the command argument data type information
NameDescriptionType type = setArgumentDataType(spaceSystem, commandName, argumentName, dataType, arraySize, bitLength, enumeration, units, minimum, maximum, description, stringSize, uniqueID);
// Add the command to the command space system
ArgumentTypeSetType argument = spaceSystem.getCommandMetaData().getArgumentTypeSet();
argument.getStringArgumentTypeOrEnumeratedArgumentTypeOrIntegerArgumentType().add(type);
}
}
// Add the command metadata set information
addCommand(spaceSystem, commandName, commandCode, isCmdHeader, applicationID, argumentNames, argArraySizes, commandDescription);
}
}
}
use of org.omg.space.xtce.ArgumentTypeSetType in project CCDD by nasa.
the class CcddXTCEHandler method importCommandTable.
/**
********************************************************************************************
* Build a command table from the specified command metadata
*
* @param system
* space system
*
* @param cmdMetaData
* reference to the command metadata from which to build the command table
*
* @param table
* name table name, including the full system path
*
* @throws CCDDException
* If an input error is detected
********************************************************************************************
*/
private void importCommandTable(SpaceSystemType system, CommandMetaDataType cmdMetaData, String tableName) throws CCDDException {
// Create a table definition for this command table. If the name space also includes a
// telemetry metadata (which creates a structure table) then ensure the two tables have
// different names
TableDefinition tableDefn = new TableDefinition(tableName + (system.getTelemetryMetaData() == null ? "" : "_cmd"), system.getLongDescription());
// Check if a description exists for this command table
if (system.getLongDescription() != null && !system.getLongDescription().isEmpty()) {
// Store the table's description
tableDefn.setDescription(system.getLongDescription());
}
// Set the new command table's table type name
tableDefn.setTypeName(commandTypeDefn.getName());
// Check if the description column belongs to a command argument
if (commandArguments.size() != 0 && cmdDescriptionIndex > commandArguments.get(0).getName()) {
// Reset the command description index to indicate no description exists
cmdDescriptionIndex = -1;
}
// Get the command set information
MetaCommandSet metaCmdSet = cmdMetaData.getMetaCommandSet();
// Check if the command set information exists
if (metaCmdSet != null) {
// Get the command argument information
ArgumentTypeSetType argTypeSetType = cmdMetaData.getArgumentTypeSet();
List<NameDescriptionType> argTypeSet = null;
// Check if there are any arguments for this command
if (argTypeSetType != null) {
// Get the list of this command's argument data types
argTypeSet = argTypeSetType.getStringArgumentTypeOrEnumeratedArgumentTypeOrIntegerArgumentType();
}
// Step through each command set
for (Object cmd : metaCmdSet.getMetaCommandOrMetaCommandRefOrBlockMetaCommand()) {
// Check if the command represents a meta command type (all of these should)
if (cmd instanceof MetaCommandType) {
// Get the command type as a meta command type to shorten subsequent calls
MetaCommandType metaCmd = (MetaCommandType) cmd;
// Create a new row of data in the table definition to contain this command's
// information. Initialize all columns to blanks except for the command name
String[] newRow = new String[numCommandColumns];
Arrays.fill(newRow, null);
newRow[commandNameIndex] = metaCmd.getName();
// Get the base meta-command reference
BaseMetaCommand baseMetaCmd = metaCmd.getBaseMetaCommand();
// Check if the base meta-command exists
if (baseMetaCmd != null) {
// Step through each argument assignment
for (ArgumentAssignment argAssn : baseMetaCmd.getArgumentAssignmentList().getArgumentAssignment()) {
// column name
if (argAssn.getArgumentName().equals(ccsdsAppID)) {
boolean isExists = false;
// Step through the data fields already added to this table
for (String[] fieldInfo : tableDefn.getDataFields()) {
// subsequent ones are ignored to prevent duplicates
if (fieldInfo[FieldsColumn.FIELD_NAME.ordinal()].equals(argAssn.getArgumentName())) {
// Set the flag indicating the field already exists and
// stop searching
isExists = true;
break;
}
}
// Check if the application ID data field doesn't exist
if (!isExists) {
// Create a data field for the table containing the application
// ID and stop searching
tableDefn.addDataField(new String[] { tableName, argAssn.getArgumentName(), "Message ID", String.valueOf(argAssn.getArgumentValue().length()), InputDataType.MESSAGE_ID.getInputName(), String.valueOf(false), ApplicabilityType.ALL.getApplicabilityName(), argAssn.getArgumentValue() });
}
} else // argument column name
if (argAssn.getArgumentName().equals(ccsdsFuncCode)) {
// Store the command function code and stop searching
newRow[commandCodeIndex] = argAssn.getArgumentValue();
break;
}
}
}
// exists in the table type definition
if (metaCmd.getLongDescription() != null && cmdDescriptionIndex != -1) {
// Store the command description in the row's description column
newRow[cmdDescriptionIndex] = metaCmd.getLongDescription();
}
// Check if the command has any arguments
if (metaCmd.getArgumentList() != null && argTypeSet != null) {
int cmdArgIndex = 0;
CommandContainerType cmdContainer = metaCmd.getCommandContainer();
// Step through each of the command's arguments
for (Argument argList : metaCmd.getArgumentList().getArgument()) {
// Step through each command argument type
for (NameDescriptionType argType : argTypeSet) {
// between the two)
if (argList.getArgumentTypeRef().equals(argType.getName())) {
boolean isInteger = false;
boolean isUnsigned = false;
boolean isFloat = false;
boolean isString = false;
String dataType = null;
String arraySize = null;
BigInteger bitLength = null;
long sizeInBytes = 0;
String enumeration = null;
String description = null;
UnitSet unitSet = null;
String units = null;
String minimum = null;
String maximum = null;
// Check if the argument is an array data type
if (argType instanceof ArrayDataTypeType && metaCmd != null && cmdContainer != null) {
// set
for (JAXBElement<? extends SequenceEntryType> seqEntry : cmdContainer.getEntryList().getParameterRefEntryOrParameterSegmentRefEntryOrContainerRefEntry()) {
// reference matches the target parameter
if (seqEntry.getValue() instanceof ArrayParameterRefEntryType && argList.getName().equals(((ArrayParameterRefEntryType) seqEntry.getValue()).getParameterRef())) {
arraySize = "";
// Store the reference to the array parameter type
ArrayDataTypeType arrayType = (ArrayDataTypeType) argType;
argType = null;
// the array variable
for (Dimension dim : ((ArrayParameterRefEntryType) seqEntry.getValue()).getDimensionList().getDimension()) {
// Build the array size string
arraySize += String.valueOf(dim.getEndingIndex().getFixedValue()) + ",";
}
arraySize = CcddUtilities.removeTrailer(arraySize, ",");
// data type entry
for (NameDescriptionType type : argTypeSet) {
// reference matches the data type name
if (arrayType.getArrayTypeRef().equals(type.getName())) {
// Store the reference to the array
// parameter's data type and stop searching
argType = type;
break;
}
}
break;
}
}
}
// individual array members)
if (argType != null) {
// Check if the argument is an integer data type
if (argType instanceof IntegerArgumentType) {
IntegerArgumentType icmd = (IntegerArgumentType) argType;
// Get the number of bits occupied by the argument
bitLength = icmd.getSizeInBits();
// Get the argument units reference
unitSet = icmd.getUnitSet();
// Check if integer encoding is set to 'unsigned'
if (icmd.getIntegerDataEncoding().getEncoding().equalsIgnoreCase("unsigned")) {
isUnsigned = true;
}
// Determine the smallest integer size that contains
// the number of bits occupied by the argument
sizeInBytes = 8;
while (bitLength.longValue() > sizeInBytes) {
sizeInBytes *= 2;
}
sizeInBytes /= 8;
// Get the argument alarm
IntegerArgumentType.ValidRangeSet alarmType = icmd.getValidRangeSet();
// Check if the argument has an alarm
if (alarmType != null) {
// Get the alarm range
List<IntegerRangeType> alarmRange = alarmType.getValidRange();
// Check if the alarm range exists
if (alarmRange != null) {
// Store the minimum alarm value
minimum = alarmRange.get(0).getMinInclusive();
// Store the maximum alarm value
maximum = alarmRange.get(0).getMaxInclusive();
}
}
isInteger = true;
} else // Check if the argument is a floating point data type
if (argType instanceof FloatArgumentType) {
// Get the float argument attributes
FloatArgumentType fcmd = (FloatArgumentType) argType;
sizeInBytes = fcmd.getSizeInBits().longValue() / 8;
unitSet = fcmd.getUnitSet();
// Get the argument alarm
FloatArgumentType.ValidRangeSet alarmType = fcmd.getValidRangeSet();
// Check if the argument has an alarm
if (alarmType != null) {
// Get the alarm range
List<FloatRangeType> alarmRange = alarmType.getValidRange();
// Check if the alarm range exists
if (alarmRange != null) {
// Get the minimum value
Double min = alarmRange.get(0).getMinInclusive();
// Check if a minimum value exists
if (min != null) {
// Get the minimum alarm value
minimum = String.valueOf(min);
}
// Get the maximum value
Double max = alarmRange.get(0).getMaxInclusive();
// Check if a maximum value exists
if (max != null) {
// Get the maximum alarm value
maximum = String.valueOf(max);
}
}
}
isFloat = true;
} else // Check if the argument is a string data type
if (argType instanceof StringDataType) {
// Get the string argument attributes
StringDataType scmd = (StringDataType) argType;
sizeInBytes = scmd.getCharacterWidth().longValue();
unitSet = scmd.getUnitSet();
isString = true;
} else // Check if the argument is an enumerated data type
if (argType instanceof EnumeratedDataType) {
EnumeratedDataType ecmd = (EnumeratedDataType) argType;
EnumerationList enumList = ecmd.getEnumerationList();
// Check if any enumeration parameters are defined
if (enumList != null) {
// Step through each enumeration parameter
for (ValueEnumerationType enumType : enumList.getEnumeration()) {
// Check if this is the first parameter
if (enumeration == null) {
// Initialize the enumeration string
enumeration = "";
} else // Not the first parameter
{
// Add the separator for the
// enumerations
enumeration += ", ";
}
// Begin building this enumeration
enumeration += enumType.getValue() + " | " + enumType.getLabel();
}
bitLength = ecmd.getIntegerDataEncoding().getSizeInBits();
unitSet = ecmd.getUnitSet();
// 'unsigned'
if (ecmd.getIntegerDataEncoding().getEncoding().equalsIgnoreCase("unsigned")) {
isUnsigned = true;
}
// Determine the smallest integer size that
// contains the number of bits occupied by the
// argument
sizeInBytes = 8;
while (bitLength.longValue() > sizeInBytes) {
sizeInBytes *= 2;
}
sizeInBytes /= 8;
isInteger = true;
}
}
// Get the name of the data type from the data type table
// that matches the base type and size of the parameter
dataType = getDataType(dataTypeHandler, sizeInBytes, isInteger, isUnsigned, isFloat, isString);
// Check if the description exists
if (argType.getLongDescription() != null) {
// Store the description
description = argType.getLongDescription();
}
// Check if the units exists
if (unitSet != null) {
List<UnitType> unitType = unitSet.getUnit();
// Check if the units is set
if (!unitType.isEmpty()) {
// Store the units
units = unitType.get(0).getContent();
}
}
// dictated by the table type definition
if (cmdArgIndex < commandArguments.size()) {
// Get the command argument reference
AssociatedColumns acmdArg = commandArguments.get(cmdArgIndex);
// Check if the command argument name is present
if (acmdArg.getName() != -1) {
// Store the command argument name
newRow[acmdArg.getName()] = argList.getName();
}
// Check if the command argument data type is present
if (acmdArg.getDataType() != -1 && dataType != null) {
// Store the command argument data type
newRow[acmdArg.getDataType()] = dataType;
}
// Check if the command argument array size is present
if (acmdArg.getArraySize() != -1 && arraySize != null) {
// Store the command argument array size
newRow[acmdArg.getArraySize()] = arraySize;
}
// Check if the command argument bit length is present
if (acmdArg.getBitLength() != -1 && bitLength != null) {
// Store the command argument bit length
newRow[acmdArg.getBitLength()] = bitLength.toString();
}
// Check if the command argument enumeration is present
if (acmdArg.getEnumeration() != -1 && enumeration != null) {
// Store the command argument enumeration
newRow[acmdArg.getEnumeration()] = enumeration;
}
// Check if the command argument description is present
if (acmdArg.getDescription() != -1 && description != null) {
// Store the command argument description
newRow[acmdArg.getDescription()] = description;
}
// Check if the command argument units is present
if (acmdArg.getUnits() != -1 && units != null) {
// Store the command argument units
newRow[acmdArg.getUnits()] = units;
}
// Check if the command argument minimum is present
if (acmdArg.getMinimum() != -1 && minimum != null) {
// Store the command argument minimum
newRow[acmdArg.getMinimum()] = minimum;
}
// Check if the command argument maximum is present
if (acmdArg.getMaximum() != -1 && maximum != null) {
// Store the command argument maximum
newRow[acmdArg.getMaximum()] = maximum;
}
}
}
// Increment the argument index
cmdArgIndex++;
break;
}
}
}
}
// Add the new row to the table definition
tableDefn.addData(newRow);
}
}
}
// Add the command table definition to the list
tableDefinitions.add(tableDefn);
}
Aggregations