use of CCDD.CcddClassesDataTable.AssociatedColumns in project CCDD by nasa.
the class CcddEDSHandler method importCommandTable.
/**
********************************************************************************************
* Build a command table from the specified command metadata
*
* @param namespace
* name space
*
* @param commandSet
* reference to the command set from which to build the command table
*
* @param table
* name table name, including the full system path
*
* @param hasParameter
* true if the name space also has a parameter set
*
* @throws CCDDException
* If an input error is detected
********************************************************************************************
*/
private void importCommandTable(NamespaceType namespace, List<InterfaceCommandType> commandSet, String tableName, boolean hasParameter) throws CCDDException {
// Create a table definition for this command table. If the name space also includes a
// parameter set (which creates a structure table) then ensure the two tables have
// different names
TableDefinition tableDefn = new TableDefinition(tableName + (hasParameter ? "_cmd" : ""), namespace.getLongDescription());
// Check if a description exists for this command table
if (namespace.getLongDescription() != null && !namespace.getLongDescription().isEmpty()) {
// Store the table's description
tableDefn.setDescription(namespace.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;
}
// Step through each command
for (InterfaceCommandType cmdType : commandSet) {
// 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[commandTypeDefn.getColumnCountVisible()];
Arrays.fill(newRow, null);
newRow[commandNameIndex] = cmdType.getName();
// table type definition
if (cmdType.getLongDescription() != null && cmdDescriptionIndex != -1) {
// Store the command description in the row's description
// column
newRow[cmdDescriptionIndex] = cmdType.getLongDescription();
}
int cmdArgIndex = 0;
// Step through each of the command's arguments
for (CommandArgumentType argList : cmdType.getArgument()) {
// type
if (namespace.getDataTypeSet() != null && commandNameIndex != -1) {
// Step through each data type set
for (RootDataType argType : namespace.getDataTypeSet().getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
// list (by matching the command and argument names between the two)
if (argList.getType().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;
Unit units = null;
String minimum = null;
String maximum = null;
// Check if the argument is an array data type
if (argType instanceof ArrayDataType) {
arraySize = "";
// Store the reference to the array parameter type
ArrayDataType arrayType = (ArrayDataType) argType;
argType = null;
// Step through each dimension for the array variable
for (DimensionSizeType dim : arrayType.getDimensionList().getDimension()) {
// Build the array size string
arraySize += String.valueOf(dim.getSize().longValue()) + ",";
}
arraySize = CcddUtilities.removeTrailer(arraySize, ",");
// type entry Step through each data type set
for (RootDataType type : namespace.getDataTypeSet().getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
// the data type name
if (arrayType.getDataTypeRef().equals(type.getName())) {
// Store the reference to the array parameter's data type
// and stop searching
argType = type;
break;
}
}
}
// locate the data type entry for the individual array members)
if (argType != null) {
// Check if the argument is an integer data type
if (argType instanceof IntegerDataType) {
IntegerDataType icmd = (IntegerDataType) argType;
// Get the number of bits occupied by the argument
bitLength = icmd.getIntegerDataEncoding().getSizeInBits();
// Check if units exist for this argument
if (icmd.getSemantics() != null && icmd.getSemantics().getUnit() != null) {
// Get the argument units reference
units = icmd.getSemantics().getUnit();
}
// Check if integer encoding is set to 'unsigned'
if (icmd.getIntegerDataEncoding().getEncoding() == IntegerEncodingType.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 range
IntegerDataTypeRangeType range = icmd.getRange();
// Check if the argument has a range
if (range != null && range.getMinMaxRange() != null) {
MinMaxRangeType minMax = range.getMinMaxRange();
// Check if the argument has a minimum value
if (minMax.getMin() != null) {
// Store the minimum value
minimum = minMax.getMin().toString();
}
// Check if the argument has a maximum value
if (minMax.getMax() != null) {
// Store the maximum value
maximum = minMax.getMax().toString();
}
}
isInteger = true;
} else // Check if the argument is a floating point data type
if (argType instanceof FloatDataType) {
// Get the float argument attributes
FloatDataType fcmd = (FloatDataType) argType;
// Check if units exist for this argument
if (fcmd.getSemantics() != null && fcmd.getSemantics().getUnit() != null) {
// Get the argument units reference
units = fcmd.getSemantics().getUnit();
}
switch(fcmd.getFloatDataEncoding().getEncodingAndPrecision()) {
case IEEE_754_2008_SINGLE:
sizeInBytes = 4;
break;
case IEEE_754_2008_DOUBLE:
sizeInBytes = 8;
break;
case IEEE_754_2008_QUAD:
sizeInBytes = 16;
break;
default:
break;
}
// Get the argument range
FloatDataTypeRangeType range = fcmd.getRange();
// Check if the argument has a range
if (range != null && range.getMinMaxRange() != null) {
MinMaxRangeType minMax = range.getMinMaxRange();
// Check if the argument has a minimum value
if (minMax.getMin() != null) {
// Store the minimum value
minimum = minMax.getMin().toString();
}
// Check if the argument has a maximum value
if (minMax.getMax() != null) {
// Store the maximum value
maximum = minMax.getMax().toString();
}
}
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.getLength().longValue();
// Check if units exist for this argument
if (scmd.getSemantics() != null && scmd.getSemantics().getUnit() != null) {
// Get the argument units reference
units = scmd.getSemantics().getUnit();
}
isString = true;
} else // Check if the argument is an enumerated data type
if (argType instanceof EnumeratedDataType) {
EnumeratedDataType ecmd = (EnumeratedDataType) argType;
EnumerationListType 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();
// Check if units exist for this argument
if (ecmd.getSemantics() != null && ecmd.getSemantics().getUnit() != null) {
// Get the argument units reference
units = ecmd.getSemantics().getUnit();
}
// Check if integer encoding is set to 'unsigned'
if (ecmd.getIntegerDataEncoding().getEncoding() == IntegerEncodingType.UNSIGNED) {
isUnsigned = true;
}
// Determine the smallest integer size that contains the
// number of bits occupied by the parameter
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 (argList.getLongDescription() != null) {
// Store the description
description = argList.getLongDescription();
}
// 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.toString();
}
// 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);
}
use of CCDD.CcddClassesDataTable.AssociatedColumns in project CCDD by nasa.
the class CcddEDSHandler method addNamespaceCommands.
/**
********************************************************************************************
* Add the command(s) from a table to the specified name space
*
* @param namespace
* name space 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
*
* @param ccsdsAppID
* name of the command header argument containing the application ID
*
* @param ccsdsFuncCode
* name of the command header argument containing the command function code
********************************************************************************************
*/
private void addNamespaceCommands(NamespaceType namespace, TableInformation tableInfo, boolean isCmdHeader, String applicationID, String ccsdsAppID, String ccsdsFuncCode) {
List<String> argumentNames = new ArrayList<String>();
// 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<CommandArgumentType> arguments = new ArrayList<CommandArgumentType>();
// 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 units = 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()];
// Add a command argument to the command metadata
CommandArgumentType argType = factory.createCommandArgumentType();
argType.setName(argumentName);
// Check if the description column exists
if (cmdArg.getDescription() != -1 && !rowData[cmdArg.getDescription()].isEmpty()) {
// Store the command argument description
argType.setLongDescription(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
DerivedTypeRangeType range = argType.getValidRange() == null ? factory.createDerivedTypeRangeType() : argType.getValidRange();
MinMaxRangeType minMax = range.getMinMaxRange() == null ? factory.createMinMaxRangeType() : range.getMinMaxRange();
minMax.setMin(BigDecimal.valueOf(Double.valueOf(rowData[cmdArg.getMinimum()])));
argType.setValidRange(range);
}
// Check if the maximum column exists
if (cmdArg.getMaximum() != -1 && !rowData[cmdArg.getMaximum()].isEmpty()) {
// Store the command argument maximum value
DerivedTypeRangeType range = argType.getValidRange() == null ? factory.createDerivedTypeRangeType() : argType.getValidRange();
MinMaxRangeType minMax = range.getMinMaxRange() == null ? factory.createMinMaxRangeType() : range.getMinMaxRange();
minMax.setMax(BigDecimal.valueOf(Double.valueOf(rowData[cmdArg.getMaximum()])));
argType.setValidRange(range);
}
// 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);
}
argType.setType(argumentName + TYPE + uniqueID);
// Add the name to the list
argumentNames.add(argumentName);
// Get the argument's data type information
setDataType(namespace, argumentName, dataType, arraySize, bitLength, enumeration, units, null, stringSize, uniqueID);
// Add the command argument to the list
arguments.add(argType);
}
}
// Add the command information
addCommand(namespace, commandName, commandCode, isCmdHeader, applicationID, ccsdsAppID, ccsdsFuncCode, arguments, commandDescription);
}
}
}
use of CCDD.CcddClassesDataTable.AssociatedColumns in project CCDD by nasa.
the class CcddScriptDataAccessHandler method getCommandArgMaximum.
/**
********************************************************************************************
* Get the argument maximum value (as a string) for the command argument specified at the
* specified row in the command data. Macro expansion is controlled by the input flag
*
* @param argumentNumber
* command argument index. The first argument is 0
*
* @param row
* table data row index
*
* @param expandMacros
* true to replace any macros with their corresponding value; false to return the
* data with any macro names in place
*
* @return Argument maximum value (as a string) for the command argument specified at the
* specified row in the command data; null if the argument number or row index is
* invalid
********************************************************************************************
*/
private String getCommandArgMaximum(int argumentNumber, int row, boolean expandMacros) {
String argMaximum = null;
// Get the table type definition for the command table referenced in the specified row
TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(getCommandTypeNameByRow(row));
// Check if the table type exists and represents a command
if (typeDefn != null && typeDefn.isCommand()) {
// Get the list of command arguments associated with this command table type
List<AssociatedColumns> commandArguments = typeDefn.getAssociatedCommandArgumentColumns(false);
// Check if the argument number is valid and that the argument maximum value exists
if (argumentNumber < commandArguments.size() && commandArguments.get(argumentNumber).getMaximum() != -1) {
// Get the reference to the table information
TableInformation tableInfo = getTableInformation(TYPE_COMMAND);
// Get the argument maximum value
argMaximum = tableInfo.getData()[row][commandArguments.get(argumentNumber).getMaximum()];
// Check if any macros should be expanded
if (expandMacros) {
// Expand any macros
argMaximum = macroHandler.getMacroExpansion(argMaximum);
}
}
}
return argMaximum;
}
use of CCDD.CcddClassesDataTable.AssociatedColumns in project CCDD by nasa.
the class CcddScriptDataAccessHandler method getCommandArgEnumeration.
/**
********************************************************************************************
* Get the argument enumeration for the command argument specified at the specified row in the
* command data. Macro expansion is controlled by the input flag
*
* @param argumentNumber
* command argument index. The first argument is 0
*
* @param row
* table data row index
*
* @param expandMacros
* true to replace any macros with their corresponding value; false to return the
* data with any macro names in place
*
* @return Argument enumeration for the command argument specified at the specified row in the
* command data; null if the argument number or row index is invalid
********************************************************************************************
*/
private String getCommandArgEnumeration(int argumentNumber, int row, boolean expandMacros) {
String argEnumeration = null;
// Get the table type definition for the command table referenced in the specified row
TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(getCommandTypeNameByRow(row));
// Check if the table type exists and represents a command
if (typeDefn != null && typeDefn.isCommand()) {
// Get the list of command arguments associated with this command table type
List<AssociatedColumns> commandArguments = typeDefn.getAssociatedCommandArgumentColumns(false);
// Check if the argument number is valid and that the argument enumeration exists
if (argumentNumber < commandArguments.size() && commandArguments.get(argumentNumber).getEnumeration() != -1) {
// Get the reference to the table information
TableInformation tableInfo = getTableInformation(TYPE_COMMAND);
// Get the argument enumeration
argEnumeration = tableInfo.getData()[row][commandArguments.get(argumentNumber).getEnumeration()];
// Check if any macros should be expanded
if (expandMacros) {
// Expand any macros
argEnumeration = macroHandler.getMacroExpansion(argEnumeration);
}
}
}
return argEnumeration;
}
use of CCDD.CcddClassesDataTable.AssociatedColumns in project CCDD by nasa.
the class CcddScriptDataAccessHandler method getCommandArgMinimum.
/**
********************************************************************************************
* Get the argument minimum value (as a string) for the command argument specified at the
* specified row in the command data. Macro expansion is controlled by the input flag
*
* @param argumentNumber
* command argument index. The first argument is 0
*
* @param row
* table data row index
*
* @param expandMacros
* true to replace any macros with their corresponding value; false to return the
* data with any macro names in place
*
* @return Argument minimum value (as a string) for the command argument specified at the
* specified row in the command data; null if the argument number or row index is
* invalid
********************************************************************************************
*/
private String getCommandArgMinimum(int argumentNumber, int row, boolean expandMacros) {
String argMinimum = null;
// Get the table type definition for the command table referenced in the specified row
TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(getCommandTypeNameByRow(row));
// Check if the table type exists and represents a command
if (typeDefn != null && typeDefn.isCommand()) {
// Get the list of command arguments associated with this command table type
List<AssociatedColumns> commandArguments = typeDefn.getAssociatedCommandArgumentColumns(false);
// Check if the argument number is valid and that the argument minimum value exists
if (argumentNumber < commandArguments.size() && commandArguments.get(argumentNumber).getMinimum() != -1) {
// Get the reference to the table information
TableInformation tableInfo = getTableInformation(TYPE_COMMAND);
// Get the argument minimum value
argMinimum = tableInfo.getData()[row][commandArguments.get(argumentNumber).getMinimum()];
// Check if any macros should be expanded
if (expandMacros) {
// Expand any macros
argMinimum = macroHandler.getMacroExpansion(argMinimum);
}
}
}
return argMinimum;
}
Aggregations