use of org.omg.space.xtce.BaseDataType in project CCDD by nasa.
the class CcddXTCEHandler method setArgumentDataType.
/**
********************************************************************************************
* Set the command argument data type and set the specified attributes
*
* @param spaceSystem
* space system
*
* @param commandName
* command name
*
* @param argumentName
* command argument name; null to not specify
*
* @param dataType
* command argument data type; null to not specify
*
* @param arraySize
* command argument array size; null or blank if the argument isn't an array
*
* @param bitLength
* command argument bit length
*
* @param enumeration
* command argument enumeration in the format <enum label>|<enum value>[|...][,...];
* null to not specify
*
* @param units
* command argument units; null to not specify
*
* @param minimum
* minimum parameter value; null to not specify
*
* @param maximum
* maximum parameter value; null to not specify
*
* @param description
* command argument description ; null to not specify
*
* @param stringSize
* string size in bytes; ignored if the command argument does not have a string data
* type
*
* @return Command description of the type corresponding to the primitive data type with the
* specified attributes set
*
* @param uniqueID
* text used to uniquely identify data types with the same name; blank if the data
* type has no name conflict
********************************************************************************************
*/
private NameDescriptionType setArgumentDataType(SpaceSystemType spaceSystem, String commandName, String argumentName, String dataType, String arraySize, String bitLength, String enumeration, String units, String minimum, String maximum, String description, int stringSize, String uniqueID) {
BaseDataType commandDescription = null;
// Check if the argument is an array
if (arraySize != null && !arraySize.isEmpty()) {
// Create an array type and set its attributes
ArrayDataTypeType arrayType = factory.createArrayDataTypeType();
arrayType.setName(argumentName + ARRAY);
arrayType.setNumberOfDimensions(BigInteger.valueOf(ArrayVariable.getArrayIndexFromSize(arraySize).length));
arrayType.setArrayTypeRef(argumentName + TYPE);
// Set the argument's array information
spaceSystem.getCommandMetaData().getArgumentTypeSet().getStringArgumentTypeOrEnumeratedArgumentTypeOrIntegerArgumentType().add(arrayType);
}
// Get the XTCE data type corresponding to the primitive data type
XTCEDataType xtceDataType = getXTCEDataType(dataType);
// Check if the a corresponding XTCE data type exists
if (xtceDataType != null) {
UnitSet unitSet = null;
// Check if units is provided
if (units != null && !units.isEmpty()) {
// Set the command units
unitSet = createUnitSet(units);
}
// Check if enumeration parameters are provided
if (enumeration != null && !enumeration.isEmpty()) {
// Create an enumeration type and enumeration list, and add any extra enumeration
// parameters as column data
EnumeratedDataType enumType = factory.createEnumeratedDataType();
EnumerationList enumList = createEnumerationList(spaceSystem, enumeration);
// Set the integer encoding (the only encoding available for an enumeration) and
// the size in bits
IntegerDataEncodingType intEncodingType = factory.createIntegerDataEncodingType();
// Check if the parameter has a bit length
if (bitLength != null && !bitLength.isEmpty()) {
// Set the size in bits to the value supplied
intEncodingType.setSizeInBits(BigInteger.valueOf(Integer.parseInt(bitLength)));
} else // Not a bit-wise parameter
{
// Set the size in bits to the full size of the data type
intEncodingType.setSizeInBits(BigInteger.valueOf(dataTypeHandler.getSizeInBits(dataType)));
}
// Set the enumeration list and units attributes
enumType.setEnumerationList(enumList);
enumType.setUnitSet(unitSet);
// Check if the data type is an unsigned integer
if (dataTypeHandler.isUnsignedInt(dataType)) {
// Set the encoding type to indicate an unsigned integer
intEncodingType.setEncoding("unsigned");
}
// Set the bit order
intEncodingType.setBitOrder(endianess == EndianType.BIG_ENDIAN ? "mostSignificantBitFirst" : "leastSignificantBitFirst");
enumType.setIntegerDataEncoding(intEncodingType);
commandDescription = enumType;
} else // This is not an enumerated command argument
{
switch(xtceDataType) {
case INTEGER:
// Create an integer command argument and set its attributes
IntegerArgumentType integerType = factory.createArgumentTypeSetTypeIntegerArgumentType();
IntegerDataEncodingType intEncodingType = factory.createIntegerDataEncodingType();
// Check if the parameter has a bit length
if (bitLength != null && !bitLength.isEmpty()) {
// Set the size in bits to the value supplied
integerType.setSizeInBits(BigInteger.valueOf(Integer.parseInt(bitLength)));
intEncodingType.setSizeInBits(BigInteger.valueOf(Integer.parseInt(bitLength)));
} else // Not a bit-wise parameter
{
// Set the size in bits to the full size of the data type
integerType.setSizeInBits(BigInteger.valueOf(dataTypeHandler.getSizeInBits(dataType)));
intEncodingType.setSizeInBits(BigInteger.valueOf(dataTypeHandler.getSizeInBits(dataType)));
}
// Check if the data type is an unsigned integer
if (dataTypeHandler.isUnsignedInt(dataType)) {
// Set the encoding type to indicate an unsigned integer
integerType.setSigned(false);
intEncodingType.setEncoding("unsigned");
}
// Set the bit order
intEncodingType.setBitOrder(endianess == EndianType.BIG_ENDIAN ? "mostSignificantBitFirst" : "leastSignificantBitFirst");
integerType.setIntegerDataEncoding(intEncodingType);
// Check if a minimum or maximum value is specified
if ((minimum != null && !minimum.isEmpty()) || (maximum != null && !maximum.isEmpty())) {
IntegerArgumentType.ValidRangeSet validRange = factory.createArgumentTypeSetTypeIntegerArgumentTypeValidRangeSet();
IntegerRangeType range = new IntegerRangeType();
// Check if a minimum value is specified
if (minimum != null && !minimum.isEmpty()) {
// Set the minimum value
range.setMinInclusive(minimum);
}
// Check if a maximum value is specified
if (maximum != null && !maximum.isEmpty()) {
// Set the maximum value
range.setMaxInclusive(maximum);
}
validRange.getValidRange().add(range);
integerType.setValidRangeSet(validRange);
}
commandDescription = integerType;
break;
case FLOAT:
// Create a float command argument and set its attributes
FloatArgumentType floatType = factory.createArgumentTypeSetTypeFloatArgumentType();
FloatDataEncodingType floatEncodingType = factory.createFloatDataEncodingType();
floatEncodingType.setSizeInBits(BigInteger.valueOf(dataTypeHandler.getSizeInBits(dataType)));
floatEncodingType.setEncoding("IEEE754_1985");
floatType.setFloatDataEncoding(floatEncodingType);
// Check if a minimum or maximum value is specified
if ((minimum != null && !minimum.isEmpty()) || (maximum != null && !maximum.isEmpty())) {
FloatArgumentType.ValidRangeSet validRange = factory.createArgumentTypeSetTypeFloatArgumentTypeValidRangeSet();
FloatRangeType range = new FloatRangeType();
// Check if a minimum value is specified
if (minimum != null && !minimum.isEmpty()) {
// Set the minimum value
range.setMinExclusive(Double.valueOf(minimum));
}
// Check if a maximum value is specified
if (maximum != null && !maximum.isEmpty()) {
// Set the maximum value
range.setMaxExclusive(Double.valueOf(maximum));
}
validRange.getValidRange().add(range);
floatType.setValidRangeSet(validRange);
}
commandDescription = floatType;
break;
case STRING:
// Create a string command argument and set its attributes
StringDataType stringType = factory.createStringDataType();
stringType.setCharacterWidth(BigInteger.valueOf(stringSize));
StringDataEncodingType stringEncodingType = factory.createStringDataEncodingType();
// Set the string's size in bits based on the number of characters in the
// string with each character occupying a single byte
IntegerValueType intValType = new IntegerValueType();
intValType.setFixedValue(String.valueOf(stringSize * 8));
SizeInBits sizeInBits = new SizeInBits();
sizeInBits.setFixed(intValType);
stringEncodingType.setSizeInBits(sizeInBits);
stringEncodingType.setEncoding("UTF-8");
stringType.setStringDataEncoding(stringEncodingType);
commandDescription = stringType;
break;
}
}
// Set the command name and argument name attributes
commandDescription.setName(argumentName + TYPE + uniqueID);
// Check is a description exists
if (description != null && !description.isEmpty()) {
// Set the command description attribute
commandDescription.setLongDescription(description);
}
}
return commandDescription;
}
Aggregations