Search in sources :

Example 1 with FloatDataEncodingType

use of org.ccsds.schema.sois.seds.FloatDataEncodingType in project CCDD by nasa.

the class CcddEDSHandler method setDataType.

/**
 ********************************************************************************************
 * Create the parameter data type and set the specified attributes
 *
 * @param namespace
 *            space system
 *
 * @param parameterName
 *            parameter name; null to not specify
 *
 * @param dataType
 *            data type; null to not specify
 *
 * @param arraySize
 *            parameter array size; null or blank if the parameter isn't an array
 *
 * @param bitLength
 *            parameter bit length; null or empty if not a bit-wise parameter
 *
 * @param enumeration
 *            enumeration in the format <enum label>|<enum value>[|...][,...]; null to not
 *            specify
 *
 * @param units
 *            parameter units; null to not specify
 *
 * @param description
 *            parameter description; null to not specify
 *
 * @param description
 *            parameter description; null or blank to not specify
 *
 * @param stringSize
 *            size, in characters, of a string parameter; ignored if not a string or character
 *
 * @param uniqueID
 *            text used to uniquely identify data types with the same name; blank if the data
 *            type has no name conflict
 ********************************************************************************************
 */
private void setDataType(NamespaceType namespace, String parameterName, String dataType, String arraySize, String bitLength, String enumeration, String units, String description, int stringSize, String uniqueID) {
    RootDataType parameterDescription = null;
    // Get the data type set for this name space
    DataTypeSetType dataTypeSet = namespace.getDataTypeSet();
    // enumerated parameter
    if (dataTypeSet == null) {
        // Create the data type set
        dataTypeSet = factory.createDataTypeSetType();
    }
    // Check if the parameter is an array
    if (arraySize != null && !arraySize.isEmpty()) {
        // Create an array type and set its attributes
        ArrayDataType arrayType = factory.createArrayDataType();
        String name = getReferenceByDataType(parameterName, dataType, false);
        arrayType.setName(name + ARRAY);
        arrayType.setDataTypeRef(name + TYPE);
        ArrayDimensionsType dimList = factory.createArrayDimensionsType();
        // Step through each array dimension
        for (int dim : ArrayVariable.getArrayIndexFromSize(arraySize)) {
            // Create a dimension entry for the array type
            DimensionSizeType dimSize = factory.createDimensionSizeType();
            dimSize.setSize(BigInteger.valueOf(dim));
            dimList.getDimension().add(dimSize);
        }
        arrayType.setDimensionList(dimList);
        // Add the data type information to this name space
        dataTypeSet.getArrayDataTypeOrBinaryDataTypeOrBooleanDataType().add(arrayType);
        namespace.setDataTypeSet(dataTypeSet);
    }
    // Check if the parameter has a primitive data type
    if (dataTypeHandler.isPrimitive(dataType)) {
        // Get the EDS data type corresponding to the primitive data type
        EDSDataType edsDataType = getEDSDataType(dataType);
        // Check if the a corresponding EDS data type exists
        if (edsDataType != null) {
            // Check if enumeration parameters are provided
            if (enumeration != null && !enumeration.isEmpty()) {
                // Create an enumeration type and enumeration list
                EnumeratedDataType enumType = factory.createEnumeratedDataType();
                EnumerationListType enumList = createEnumerationList(namespace, 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)));
                }
                // Check if the data type is an unsigned integer
                if (dataTypeHandler.isUnsignedInt(dataType)) {
                    // Set the encoding type to indicate an unsigned integer
                    intEncodingType.setEncoding(IntegerEncodingType.UNSIGNED);
                }
                intEncodingType.setByteOrder(endianess == EndianType.BIG_ENDIAN ? ByteOrderType.BIG_ENDIAN : ByteOrderType.LITTLE_ENDIAN);
                enumType.setIntegerDataEncoding(intEncodingType);
                enumType.setEnumerationList(enumList);
                parameterDescription = enumType;
            } else // Not an enumeration
            {
                switch(edsDataType) {
                    case INTEGER:
                        // Create an integer type
                        IntegerDataType integerType = factory.createIntegerDataType();
                        IntegerDataEncodingType intEncodingType = factory.createIntegerDataEncodingType();
                        IntegerDataTypeRangeType integerRange = factory.createIntegerDataTypeRangeType();
                        // 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)));
                        }
                        // Check if the data type is an unsigned integer
                        if (dataTypeHandler.isUnsignedInt(dataType)) {
                            // Set the encoding type to indicate an unsigned integer
                            intEncodingType.setEncoding(IntegerEncodingType.UNSIGNED);
                        }
                        integerType.setRange(integerRange);
                        intEncodingType.setByteOrder(endianess == EndianType.BIG_ENDIAN ? ByteOrderType.BIG_ENDIAN : ByteOrderType.LITTLE_ENDIAN);
                        integerType.setIntegerDataEncoding(intEncodingType);
                        setUnits(units, integerType);
                        parameterDescription = integerType;
                        break;
                    case FLOAT:
                        // Create a float type
                        FloatDataType floatType = factory.createFloatDataType();
                        FloatDataEncodingType floatEncodingType = factory.createFloatDataEncodingType();
                        FloatDataTypeRangeType floatRange = factory.createFloatDataTypeRangeType();
                        // Set the encoding type based on the size in bytes
                        switch(dataTypeHandler.getSizeInBytes(dataType)) {
                            case 4:
                                floatEncodingType.setEncodingAndPrecision(FloatEncodingAndPrecisionType.IEEE_754_2008_SINGLE);
                                floatRange.setPrecisionRange(FloatPrecisionRangeType.SINGLE);
                                break;
                            case 8:
                                floatEncodingType.setEncodingAndPrecision(FloatEncodingAndPrecisionType.IEEE_754_2008_DOUBLE);
                                floatRange.setPrecisionRange(FloatPrecisionRangeType.DOUBLE);
                                break;
                            case 16:
                                floatEncodingType.setEncodingAndPrecision(FloatEncodingAndPrecisionType.IEEE_754_2008_QUAD);
                                break;
                            default:
                                break;
                        }
                        floatType.setRange(floatRange);
                        floatEncodingType.setByteOrder(endianess == EndianType.BIG_ENDIAN ? ByteOrderType.BIG_ENDIAN : ByteOrderType.LITTLE_ENDIAN);
                        floatType.setFloatDataEncoding(floatEncodingType);
                        setUnits(units, floatType);
                        parameterDescription = floatType;
                        break;
                    case STRING:
                        // Create a string type
                        StringDataType stringType = factory.createStringDataType();
                        StringDataEncodingType stringEncodingType = factory.createStringDataEncodingType();
                        stringEncodingType.setEncoding(StringEncodingType.UTF_8);
                        stringEncodingType.setByteOrder(endianess == EndianType.BIG_ENDIAN ? ByteOrderType.BIG_ENDIAN : ByteOrderType.LITTLE_ENDIAN);
                        stringType.setStringDataEncoding(stringEncodingType);
                        parameterDescription = stringType;
                        break;
                }
            }
        }
    } else // Structure data type
    {
        // Create a container type for the structure
        ContainerDataType containerType = factory.createContainerDataType();
        containerType.setBaseType(getReferenceByDataType(parameterName, dataType, true) + getObjectIdentifier(arraySize));
        parameterName = dataType;
        parameterDescription = containerType;
    }
    // Set the type name
    parameterDescription.setName(parameterName + TYPE + uniqueID);
    // Check is a description exists
    if (description != null && !description.isEmpty()) {
        // Set the description attribute
        parameterDescription.setLongDescription(description);
    }
    // Add the data type information to this name space
    dataTypeSet.getArrayDataTypeOrBinaryDataTypeOrBooleanDataType().add(parameterDescription);
    namespace.setDataTypeSet(dataTypeSet);
}
Also used : FloatDataType(org.ccsds.schema.sois.seds.FloatDataType) IntegerDataEncodingType(org.ccsds.schema.sois.seds.IntegerDataEncodingType) IntegerDataType(org.ccsds.schema.sois.seds.IntegerDataType) EnumeratedDataType(org.ccsds.schema.sois.seds.EnumeratedDataType) DataTypeSetType(org.ccsds.schema.sois.seds.DataTypeSetType) ArrayDimensionsType(org.ccsds.schema.sois.seds.ArrayDimensionsType) RootDataType(org.ccsds.schema.sois.seds.RootDataType) IntegerDataTypeRangeType(org.ccsds.schema.sois.seds.IntegerDataTypeRangeType) EnumerationListType(org.ccsds.schema.sois.seds.EnumerationListType) StringDataType(org.ccsds.schema.sois.seds.StringDataType) FloatDataEncodingType(org.ccsds.schema.sois.seds.FloatDataEncodingType) ContainerDataType(org.ccsds.schema.sois.seds.ContainerDataType) StringDataEncodingType(org.ccsds.schema.sois.seds.StringDataEncodingType) ArrayDataType(org.ccsds.schema.sois.seds.ArrayDataType) DimensionSizeType(org.ccsds.schema.sois.seds.DimensionSizeType) FloatDataTypeRangeType(org.ccsds.schema.sois.seds.FloatDataTypeRangeType)

Aggregations

ArrayDataType (org.ccsds.schema.sois.seds.ArrayDataType)1 ArrayDimensionsType (org.ccsds.schema.sois.seds.ArrayDimensionsType)1 ContainerDataType (org.ccsds.schema.sois.seds.ContainerDataType)1 DataTypeSetType (org.ccsds.schema.sois.seds.DataTypeSetType)1 DimensionSizeType (org.ccsds.schema.sois.seds.DimensionSizeType)1 EnumeratedDataType (org.ccsds.schema.sois.seds.EnumeratedDataType)1 EnumerationListType (org.ccsds.schema.sois.seds.EnumerationListType)1 FloatDataEncodingType (org.ccsds.schema.sois.seds.FloatDataEncodingType)1 FloatDataType (org.ccsds.schema.sois.seds.FloatDataType)1 FloatDataTypeRangeType (org.ccsds.schema.sois.seds.FloatDataTypeRangeType)1 IntegerDataEncodingType (org.ccsds.schema.sois.seds.IntegerDataEncodingType)1 IntegerDataType (org.ccsds.schema.sois.seds.IntegerDataType)1 IntegerDataTypeRangeType (org.ccsds.schema.sois.seds.IntegerDataTypeRangeType)1 RootDataType (org.ccsds.schema.sois.seds.RootDataType)1 StringDataEncodingType (org.ccsds.schema.sois.seds.StringDataEncodingType)1 StringDataType (org.ccsds.schema.sois.seds.StringDataType)1