Search in sources :

Example 1 with ContainerDataType

use of org.ccsds.schema.sois.seds.ContainerDataType 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)

Example 2 with ContainerDataType

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

the class CcddEDSHandler method buildNamespaces.

/**
 ********************************************************************************************
 * Build the name spaces for the list of tables specified
 *
 * @param tableNames
 *            array of table names
 *
 * @param includeVariablePaths
 *            true to include the variable path for each variable in a structure table, both in
 *            application format and using the user-defined separator characters
 *
 * @param variableHandler
 *            variable handler class reference; null if includeVariablePaths is false
 *
 * @param separators
 *            string array containing the variable path separator character(s), show/hide data
 *            types flag ('true' or 'false'), and data type/variable name separator
 *            character(s); null if includeVariablePaths is false
 ********************************************************************************************
 */
private void buildNamespaces(String[] tableNames, boolean includeVariablePaths, CcddVariableSizeAndConversionHandler variableHandler, String[] separators) {
    // Build the data field information for all fields
    fieldHandler.buildFieldInformation(null);
    // Get the names of the tables representing the CCSDS telemetry and command headers
    tlmHeaderTable = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_TLM_HDR);
    cmdHeaderTable = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_CMD_HDR);
    // Get the command header argument names for the application ID and the command function
    // code. These are stored as project-level data fields
    String ccsdsAppID = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_APP_ID);
    String ccsdsFuncCode = fieldHandler.getFieldValue(CcddFieldHandler.getFieldProjectName(), InputDataType.XML_FUNC_CODE);
    // Step through each table name
    for (String tableName : tableNames) {
        // Check if this is a child (instance) table
        if (!TableInformation.isPrototype(tableName)) {
            // Get the prototype of the instance table. Only prototypes of the tables are
            // used to create the space systems
            tableName = TableInformation.getPrototypeName(tableName);
            // Get the name of the system to which this table belongs from the table's
            // system path data field (if present)
            String systemPath = cleanSystemPath(fieldHandler.getFieldValue(tableName, InputDataType.SYSTEM_PATH));
            // created
            if (searchNamespacesForName(systemPath, tableName) != null) {
                // Skip this table since it's space system has already been created
                continue;
            }
        }
        // Get the information from the database for the specified table
        TableInformation tableInfo = dbTable.loadTableData(tableName, true, false, true, parent);
        // Check if the table's data successfully loaded
        if (!tableInfo.isErrorFlag()) {
            // Get the table type and from the type get the type definition. The type
            // definition can be a global parameter since if the table represents a structure,
            // then all of its children are also structures, and if the table represents
            // commands or other table type then it is processed within this nest level
            typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
            // Check if the table type represents a structure or command
            if (typeDefn != null && (typeDefn.isStructure() || typeDefn.isCommand())) {
                // Replace all macro names with their corresponding values
                tableInfo.setData(macroHandler.replaceAllMacros(tableInfo.getData()));
                // Get the application ID data field value, if present
                String applicationID = fieldHandler.getFieldValue(tableName, InputDataType.MESSAGE_ID);
                // Get the name of the system to which this table belongs from the table's
                // system path data field (if present)
                String systemPath = cleanSystemPath(fieldHandler.getFieldValue(tableName, InputDataType.SYSTEM_PATH));
                // Add the name space
                NamespaceType namespace = addNamespace(systemPath, tableName, tableInfo.getDescription());
                // Check if this is a structure table
                if (typeDefn.isStructure()) {
                    // Get the default column indices
                    int varColumn = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE);
                    int typeColumn = typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT);
                    int sizeColumn = typeDefn.getColumnIndexByInputType(InputDataType.ARRAY_INDEX);
                    int bitColumn = typeDefn.getColumnIndexByInputType(InputDataType.BIT_LENGTH);
                    int enumColumn = typeDefn.getColumnIndexByInputType(InputDataType.ENUMERATION);
                    int descColumn = typeDefn.getColumnIndexByInputType(InputDataType.DESCRIPTION);
                    int unitsColumn = typeDefn.getColumnIndexByInputType(InputDataType.UNITS);
                    int minColumn = typeDefn.getColumnIndexByInputType(InputDataType.MINIMUM);
                    int maxColumn = typeDefn.getColumnIndexByInputType(InputDataType.MAXIMUM);
                    // Set the flag to indicate if this is the telemetry header table
                    boolean isTlmHeaderTable = tableName.equals(tlmHeaderTable);
                    // Check if this is the telemetry header table
                    if (isTlmHeaderTable) {
                        // Store the telemetry header's path
                        tlmHeaderPath = systemPath;
                    }
                    // Export the parameter container for this structure
                    addParameterContainer(namespace, tableInfo, varColumn, typeColumn, sizeColumn, minColumn, maxColumn, isTlmHeaderTable, applicationID, ccsdsAppID);
                    // Step through each row in the structure table
                    for (String[] rowData : tableInfo.getData()) {
                        // used to define the array)
                        if (!ArrayVariable.isArrayMember(rowData[varColumn])) {
                            // Add the variable to the data sheet
                            addParameter(namespace, rowData[varColumn], rowData[typeColumn], rowData[sizeColumn], rowData[bitColumn], (enumColumn != -1 && !rowData[enumColumn].isEmpty() ? rowData[enumColumn] : null), (unitsColumn != -1 && !rowData[unitsColumn].isEmpty() ? rowData[unitsColumn] : null), (descColumn != -1 && !rowData[descColumn].isEmpty() ? rowData[descColumn] : null), (dataTypeHandler.isString(rowData[typeColumn]) && !rowData[sizeColumn].isEmpty() ? Integer.valueOf(rowData[sizeColumn].replaceAll("^.*(\\d+)$", "$1")) : 1));
                        }
                    }
                } else // This is a command table
                {
                    // Check if this is the command header table
                    if (tableName.equals(cmdHeaderTable)) {
                        // Store the command header's path
                        cmdHeaderPath = systemPath;
                    }
                    // Add the command(s) from this table to the data sheet
                    addNamespaceCommands(namespace, tableInfo, tableName.equals(cmdHeaderTable), applicationID, ccsdsAppID, ccsdsFuncCode);
                }
            }
        }
    }
    // Step through each table name
    for (String tableName : tableNames) {
        // Get the prototype for the child
        tableName = TableInformation.getPrototypeName(tableName);
        // Get the name of the system to which this table belongs from the table's
        // system path data field (if present)
        String systemPath = cleanSystemPath(fieldHandler.getFieldValue(tableName, InputDataType.SYSTEM_PATH));
        // Get the name space for this table
        NamespaceType namespace = searchNamespacesForName(systemPath, tableName);
        // Check if the table's name space exists
        if (namespace != null) {
            // Step through the each parameter type
            for (RootDataType type : namespace.getDataTypeSet().getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
                // base type it's a reference to a child structure
                if (type instanceof ContainerDataType && ((ContainerDataType) type).getBaseType() != null) {
                    // Get the base type, which has the name space path for the child structure
                    String typeName = ((ContainerDataType) type).getBaseType();
                    // Get the beginning of the last portion of the path, which is the
                    // structure data type
                    int index = ((ContainerDataType) type).getBaseType().lastIndexOf("/");
                    // Check if the structure data type exists
                    if (index != -1) {
                        // Remove the structure data type, leaving only the name space path to
                        // the child structure's definition
                        typeName = typeName.substring(0, index);
                    }
                    // Get the name space for the child structure's definition
                    NamespaceType nmspc = searchNamespacesForName(null, typeName);
                    // Check if the name space exists
                    if (nmspc != null) {
                        DataTypeSetType dataTypeSet = nmspc.getDataTypeSet();
                        // Check if the child's data type set exists
                        if (dataTypeSet != null && !dataTypeSet.getArrayDataTypeOrBinaryDataTypeOrBooleanDataType().isEmpty()) {
                            // Step through each data type
                            for (RootDataType rootData : dataTypeSet.getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
                                // Check if this is the container with the structure's members
                                if (rootData instanceof ContainerDataType && rootData.getName().equals(type.getName())) {
                                    // Set the parent structure table's list of members of the
                                    // child structure using the child structure definition's
                                    // list, and stop searching
                                    ((ContainerDataType) type).setEntryList(((ContainerDataType) rootData).getEntryList());
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ContainerDataType(org.ccsds.schema.sois.seds.ContainerDataType) DataTypeSetType(org.ccsds.schema.sois.seds.DataTypeSetType) TableInformation(CCDD.CcddClassesDataTable.TableInformation) RootDataType(org.ccsds.schema.sois.seds.RootDataType) NamespaceType(org.ccsds.schema.sois.seds.NamespaceType)

Example 3 with ContainerDataType

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

the class CcddEDSHandler method importStructureTable.

/**
 ********************************************************************************************
 * Build a structure table from the specified telemetry metadata
 *
 * @param namespace
 *            name space
 *
 * @param parameterSet
 *            reference to the parameter set from which to build the structure table
 *
 * @param table
 *            name table name, including the full system path
 *
 * @param hasCommand
 *            true if the name space also has a command set
 *
 * @throws CCDDException
 *             If an input error is detected
 ********************************************************************************************
 */
private void importStructureTable(NamespaceType namespace, List<InterfaceParameterType> parameterSet, String tableName, boolean hasCommand) throws CCDDException {
    List<DescriptionType> memberList = null;
    // Create a table definition for this structure table. If the name space also includes a
    // command set (which creates a command table) then ensure the two tables have different
    // names
    TableDefinition tableDefn = new TableDefinition(tableName + (hasCommand ? "_tlm" : ""), namespace.getLongDescription());
    // Check if a description exists for this structure table
    if (namespace.getLongDescription() != null && !namespace.getLongDescription().isEmpty()) {
        // Store the table's description
        tableDefn.setDescription(namespace.getLongDescription());
    }
    // Set the new structure table's table type name
    tableDefn.setTypeName(structureTypeDefn.getName());
    // Extract the table's name, minus the path, from the name space name
    String typeName = namespace.getName();
    int index = typeName.lastIndexOf("/");
    if (index != -1) {
        typeName = typeName.substring(index + 1);
    }
    typeName += TYPE;
    // container for this structure
    for (RootDataType parmType : namespace.getDataTypeSet().getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
        // Check if this is the container for the structure's members
        if (parmType instanceof ContainerDataType && parmType.getName().equals(typeName)) {
            // Check if the member list exists
            if (((ContainerDataType) parmType).getEntryList() != null && !((ContainerDataType) parmType).getEntryList().getEntryOrFixedValueEntryOrPaddingEntry().isEmpty()) {
                // Set the reference to the container's member list
                memberList = ((ContainerDataType) parmType).getEntryList().getEntryOrFixedValueEntryOrPaddingEntry();
            }
            // Stop searching since the matching container was found
            break;
        }
    }
    // Step through each telemetry parameter
    for (int parmIndex = 0; parmIndex < parameterSet.size(); parmIndex++) {
        // Get the reference to the parameter in the parameter set
        InterfaceParameterType parm = parameterSet.get(parmIndex);
        // Create a new row of data in the table definition to contain
        // this structure's information. Initialize all columns to
        // blanks except for the variable name
        String[] newRow = new String[structureTypeDefn.getColumnCountVisible()];
        Arrays.fill(newRow, null);
        newRow[variableNameIndex] = parm.getName();
        // definition and that a description exists
        if (descriptionIndex != -1 && parm.getLongDescription() != null) {
            // Store the description for this variable
            newRow[descriptionIndex] = parm.getLongDescription();
        }
        // Add the new row to the table definition
        tableDefn.addData(newRow);
        // name matches the parameter type reference from the parameter set
        for (RootDataType parmType : namespace.getDataTypeSet().getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
            // parameter type set's name
            if (parm.getType().equals(parmType.getName())) {
                String dataType = null;
                String arraySize = null;
                BigInteger bitLength = null;
                long sizeInBytes = 0;
                String enumeration = null;
                String minimum = null;
                String maximum = null;
                Unit units = null;
                // Check if the parameter is an array data type
                if (parmType instanceof ArrayDataType) {
                    arraySize = "";
                    // Store the reference to the array parameter type
                    ArrayDataType arrayType = (ArrayDataType) parmType;
                    // Step through each dimension for the array variable
                    for (DimensionSizeType dim : ((ArrayDataType) parmType).getDimensionList().getDimension()) {
                        // Build the array size string
                        arraySize += String.valueOf(dim.getSize().longValue()) + ",";
                    }
                    arraySize = CcddUtilities.removeTrailer(arraySize, ",");
                    parmType = null;
                    // the parameter type set in order to locate this data type entry
                    for (RootDataType type : namespace.getDataTypeSet().getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
                        // type name
                        if (arrayType.getDataTypeRef().equals(type.getName())) {
                            // Store the reference to the array parameter's data type and stop
                            // searching
                            parmType = type;
                            break;
                        }
                    }
                }
                // locate the data type entry for the individual array members)
                if (parmType != null) {
                    boolean isInteger = false;
                    boolean isUnsigned = false;
                    boolean isFloat = false;
                    boolean isString = false;
                    // Check if the parameter is an integer data type
                    if (parmType instanceof IntegerDataType) {
                        // The 'sizeInBits' references are the integer size for
                        // non-bit-wise parameters, but equal the number of bits
                        // assigned to the parameter for a bit-wise parameter. It
                        // doens't appear that the size of the integer used to contain
                        // the parameter is stored. The assumption is made that the
                        // smallest integer required to store the bits is used.
                        // However, this can alter the originally intended bit-packing
                        // (e.g., a 3-bit and a 9-bit fit within a single 16-bit
                        // integer, but the code below assigns the first to an 8-bit
                        // integer and the second to a 16-bit integer)
                        IntegerDataType itlm = (IntegerDataType) parmType;
                        // Get the number of bits occupied by the parameter
                        bitLength = itlm.getIntegerDataEncoding().getSizeInBits();
                        // Check if units exist for this parameter
                        if (itlm.getSemantics() != null && itlm.getSemantics().getUnit() != null) {
                            // Get the parameter units reference
                            units = itlm.getSemantics().getUnit();
                        }
                        // Check if integer encoding is set to 'unsigned'
                        if (itlm.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;
                        // Check if the table's member list exists
                        if (memberList != null) {
                            // Step through each member in the member list
                            for (DescriptionType entry : memberList) {
                                // Check if this is the entry for this parameter
                                if (((EntryType) entry).getName().equals(parm.getName() + TYPE)) {
                                    // Get the minimum and maximum values, if present
                                    DerivedTypeRangeType range = ((EntryType) entry).getValidRange();
                                    // Check if the range information exists
                                    if (range != null) {
                                        // Get the minimum and maximum information
                                        MinMaxRangeType minMaxRange = range.getMinMaxRange();
                                        // Check if the minimum value is specified
                                        if (minMaxRange.getMin() != null) {
                                            // Set the minimum value
                                            minimum = minMaxRange.getMin().toString();
                                        }
                                        // Check if the maximum value is specified
                                        if (minMaxRange.getMax() != null) {
                                            // Set the maximum value
                                            maximum = minMaxRange.getMax().toString();
                                        }
                                    }
                                    // Stop searching since the matching parameter was located
                                    break;
                                }
                            }
                        }
                        isInteger = true;
                    } else // Check if the parameter is a floating point data type
                    if (parmType instanceof FloatDataType) {
                        // Get the float parameter attributes
                        FloatDataType ftlm = (FloatDataType) parmType;
                        switch(ftlm.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;
                        }
                        // Check if units exist for this parameter
                        if (ftlm.getSemantics() != null && ftlm.getSemantics().getUnit() != null) {
                            // Get the parameter units reference
                            units = ftlm.getSemantics().getUnit();
                        }
                        // Check if the table's member list exists
                        if (memberList != null) {
                            // Step through each member in the member list
                            for (DescriptionType entry : memberList) {
                                // Check if this is the entry for this parameter
                                if (((EntryType) entry).getName().equals(parm.getName())) {
                                    // Get the minimum and maximum values, if present
                                    DerivedTypeRangeType range = ((EntryType) entry).getValidRange();
                                    // Check if the range information exists
                                    if (range != null) {
                                        // Get the minimum and maximum information
                                        MinMaxRangeType minMaxRange = range.getMinMaxRange();
                                        // Check if the minimum value is specified
                                        if (minMaxRange.getMin() != null) {
                                            // Set the minimum value
                                            minimum = minMaxRange.getMin().toString();
                                        }
                                        // Check if the maximum value is specified
                                        if (minMaxRange.getMax() != null) {
                                            // Set the maximum value
                                            maximum = minMaxRange.getMax().toString();
                                        }
                                    }
                                    // Stop searching since the matching parameter was located
                                    break;
                                }
                            }
                        }
                        isFloat = true;
                    } else // Check if the parameter is a string data type
                    if (parmType instanceof StringDataType) {
                        // Get the string parameter attributes
                        StringDataType stlm = (StringDataType) parmType;
                        sizeInBytes = stlm.getLength().longValue();
                        // Check if units exist for this parameter
                        if (stlm.getSemantics() != null && stlm.getSemantics().getUnit() != null) {
                            // Get the parameter units reference
                            units = stlm.getSemantics().getUnit();
                        }
                        isString = true;
                    } else // Check if the parameter is an enumerated data type
                    if (parmType instanceof EnumeratedDataType) {
                        // Get the enumeration parameters
                        EnumeratedDataType etlm = (EnumeratedDataType) parmType;
                        EnumerationListType enumList = etlm.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 = etlm.getIntegerDataEncoding().getSizeInBits();
                            // Check if units exist for this parameter
                            if (etlm.getSemantics() != null && etlm.getSemantics().getUnit() != null) {
                                // Get the parameter units reference
                                units = etlm.getSemantics().getUnit();
                            }
                            // Check if integer encoding is set to 'unsigned'
                            if (etlm.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;
                        }
                    } else // reference
                    if (parmType instanceof ContainerDataType && ((ContainerDataType) parmType).getEntryList() != null) {
                        // Get the reference to the container's base type, which is the name
                        // space path
                        dataType = ((ContainerDataType) parmType).getBaseType();
                        // it begins with a '/'. This beginning '/' is stripped off
                        if (dataType.startsWith("/")) {
                            // Remove the initial '/'
                            dataType = dataType.substring(1);
                        }
                        // The variable name must be stripped from the name space path. Get the
                        // index of the beginning of the variable name
                        int end = dataType.lastIndexOf("/");
                        // Check if the beginning of the variable name was found
                        if (end != -1) {
                            // Strip off the variable name from the path
                            dataType = dataType.substring(0, end);
                        }
                        // Convert the path to a valid structure name, replacing invalid
                        // characters with underscores
                        dataType = convertPathToTableName(dataType);
                    }
                    // Check if the data type isn't a structure reference
                    if (dataType == null) {
                        // 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 a data type exists
                    if (dataType != null) {
                        // Store the data type
                        tableDefn.getData().set(parmIndex * numStructureColumns + dataTypeIndex, dataType);
                    }
                    // Check if a array size exists
                    if (arraySize != null) {
                        // Store the array size
                        tableDefn.getData().set(parmIndex * numStructureColumns + arraySizeIndex, arraySize);
                    }
                    // Check if a bit length exists
                    if (bitLength != null && bitLength.longValue() != sizeInBytes) {
                        // Store the bit length
                        tableDefn.getData().set(parmIndex * numStructureColumns + bitLengthIndex, bitLength.toString());
                    }
                    // Check if a description exists
                    if (parm.getLongDescription() != null) {
                        // Store the description
                        tableDefn.getData().set(parmIndex * numStructureColumns + descriptionIndex, parm.getLongDescription());
                    }
                    // Check if a units exists
                    if (units != null && !units.value().isEmpty()) {
                        // Store the units for this variable
                        tableDefn.getData().set(parmIndex * numStructureColumns + unitsIndex, units.value());
                    }
                }
                // Check if an enumeration exists
                if (enumeration != null) {
                    // Store the enumeration parameters. This accounts only for the
                    // first enumeration for a variable
                    tableDefn.getData().set(parmIndex * numStructureColumns + enumerationIndex, enumeration);
                }
                // Check if a minimum value exists
                if (minimum != null) {
                    // Store the minimum value
                    tableDefn.getData().set(parmIndex * numStructureColumns + minimumIndex, minimum);
                }
                // Check if a maximum value exists
                if (maximum != null) {
                    // Store the maximum value
                    tableDefn.getData().set(parmIndex * numStructureColumns + maximumIndex, maximum);
                }
                break;
            }
        }
    }
    // Add the structure table definition to the list
    tableDefinitions.add(tableDefn);
}
Also used : ValueEnumerationType(org.ccsds.schema.sois.seds.ValueEnumerationType) FloatDataType(org.ccsds.schema.sois.seds.FloatDataType) DescriptionType(org.ccsds.schema.sois.seds.DescriptionType) IntegerDataType(org.ccsds.schema.sois.seds.IntegerDataType) EnumeratedDataType(org.ccsds.schema.sois.seds.EnumeratedDataType) MinMaxRangeType(org.ccsds.schema.sois.seds.MinMaxRangeType) DerivedTypeRangeType(org.ccsds.schema.sois.seds.DerivedTypeRangeType) Unit(org.ccsds.schema.sois.seds.Unit) RootDataType(org.ccsds.schema.sois.seds.RootDataType) EnumerationListType(org.ccsds.schema.sois.seds.EnumerationListType) StringDataType(org.ccsds.schema.sois.seds.StringDataType) EntryType(org.ccsds.schema.sois.seds.EntryType) ContainerDataType(org.ccsds.schema.sois.seds.ContainerDataType) TableDefinition(CCDD.CcddClassesDataTable.TableDefinition) BigInteger(java.math.BigInteger) InterfaceParameterType(org.ccsds.schema.sois.seds.InterfaceParameterType) ArrayDataType(org.ccsds.schema.sois.seds.ArrayDataType) DimensionSizeType(org.ccsds.schema.sois.seds.DimensionSizeType)

Example 4 with ContainerDataType

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

the class CcddEDSHandler method addParameterContainer.

/**
 ********************************************************************************************
 * Add the parameter container
 *
 * @param namespace
 *            name space
 *
 * @param tableInfo
 *            table information reference
 *
 * @param varColumn
 *            variable name column index (model coordinates)
 *
 * @param typeColumn
 *            data type column index (model coordinates)
 *
 * @param sizeColumn
 *            array size column index (model coordinates)
 *
 * @param minColumn
 *            minimum value column index (model coordinates)
 *
 * @param maxColumn
 *            maximum value column index (model coordinates)
 *
 * @param isTlmHeader
 *            true if this table represents the CCSDS telemetry header
 *
 * @param applicationID
 *            application ID
 *
 * @param ccsdsAppID
 *            name of the command header argument containing the application ID
 ********************************************************************************************
 */
private void addParameterContainer(NamespaceType namespace, TableInformation tableInfo, int varColumn, int typeColumn, int sizeColumn, int minColumn, int maxColumn, boolean isTlmHeader, // TODO WHERE DOES THIS GET PUT?
String applicationID, // TODO WHERE DOES THIS GET PUT?
String ccsdsAppID) {
    ContainerDataType containerType = null;
    EntryListType entryList = factory.createEntryListType();
    // Step through each row of data in the structure table
    for (String[] rowData : tableInfo.getData()) {
        // used to create the list)
        if (!ArrayVariable.isArrayMember(rowData[varColumn])) {
            // TODO A REFERENCE IN A CONTAINER TO A STRUCTURE THAT CONTAINS AN ARRAY THROWS A
            // NULL POINTER EXCEPTION IN THE EDS VIEWER (UNDER THE DATA TYPES TAB WHEN THE
            // CONTAINER IS EXPANDED)
            // Store the parameter reference in the list
            EntryType entryType = factory.createEntryType();
            entryType.setName(rowData[varColumn]);
            entryType.setType(getReferenceByDataType(rowData[varColumn], rowData[typeColumn], !dataTypeHandler.isPrimitive(rowData[typeColumn])) + getObjectIdentifier(rowData[sizeColumn]));
            // Check if a minimum or maximum value exists
            if ((minColumn != -1 && !rowData[minColumn].isEmpty()) || (maxColumn != -1 && !rowData[maxColumn].isEmpty())) {
                DerivedTypeRangeType range = factory.createDerivedTypeRangeType();
                MinMaxRangeType minMaxRange = factory.createMinMaxRangeType();
                minMaxRange.setRangeType(RangeType.INCLUSIVE_MIN_INCLUSIVE_MAX);
                // Set the flag if the parameter is in integer data type
                boolean isInteger = dataTypeHandler.isInteger(rowData[typeColumn]);
                // Check if a minimum value is specified
                if (minColumn != -1 && !rowData[minColumn].isEmpty()) {
                    // Set the minimum value
                    minMaxRange.setMin(isInteger ? BigDecimal.valueOf(Integer.valueOf(rowData[minColumn])) : BigDecimal.valueOf(Float.valueOf(rowData[minColumn])));
                }
                // Check if a maximum value is specified
                if (maxColumn != -1 && !rowData[maxColumn].isEmpty()) {
                    // Set the maximum value
                    minMaxRange.setMax(isInteger ? BigDecimal.valueOf(Integer.valueOf(rowData[maxColumn])) : BigDecimal.valueOf(Float.valueOf(rowData[maxColumn])));
                }
                // Set the range
                range.setMinMaxRange(minMaxRange);
                entryType.setValidRange(range);
            }
            entryList.getEntryOrFixedValueEntryOrPaddingEntry().add(entryType);
        }
    }
    // Check if any parameters exist
    if (!entryList.getEntryOrFixedValueEntryOrPaddingEntry().isEmpty()) {
        // Check if the parameter sequence container set hasn't been created
        if (containerType == null) {
            // Create the parameter sequence container set
            containerType = factory.createContainerDataType();
        }
        // Check if this is the telemetry header
        if (isTlmHeader) {
            containerType.setName(tlmHeaderTable + TYPE);
            containerType.setAbstract(true);
        } else // Not the telemetry header
        {
            containerType.setName(tableInfo.getPrototypeName() + TYPE);
        }
        // Store the parameters in the parameter sequence container
        containerType.setEntryList(entryList);
    }
    // Check if any parameters exist
    if (containerType != 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();
        }
        // Add the parameters to the system
        dataTypeSet.getArrayDataTypeOrBinaryDataTypeOrBooleanDataType().add(containerType);
        namespace.setDataTypeSet(dataTypeSet);
    }
}
Also used : EntryType(org.ccsds.schema.sois.seds.EntryType) ContainerDataType(org.ccsds.schema.sois.seds.ContainerDataType) EntryListType(org.ccsds.schema.sois.seds.EntryListType) MinMaxRangeType(org.ccsds.schema.sois.seds.MinMaxRangeType) DataTypeSetType(org.ccsds.schema.sois.seds.DataTypeSetType) DerivedTypeRangeType(org.ccsds.schema.sois.seds.DerivedTypeRangeType)

Aggregations

ContainerDataType (org.ccsds.schema.sois.seds.ContainerDataType)4 DataTypeSetType (org.ccsds.schema.sois.seds.DataTypeSetType)3 RootDataType (org.ccsds.schema.sois.seds.RootDataType)3 ArrayDataType (org.ccsds.schema.sois.seds.ArrayDataType)2 DerivedTypeRangeType (org.ccsds.schema.sois.seds.DerivedTypeRangeType)2 DimensionSizeType (org.ccsds.schema.sois.seds.DimensionSizeType)2 EntryType (org.ccsds.schema.sois.seds.EntryType)2 EnumeratedDataType (org.ccsds.schema.sois.seds.EnumeratedDataType)2 EnumerationListType (org.ccsds.schema.sois.seds.EnumerationListType)2 FloatDataType (org.ccsds.schema.sois.seds.FloatDataType)2 IntegerDataType (org.ccsds.schema.sois.seds.IntegerDataType)2 MinMaxRangeType (org.ccsds.schema.sois.seds.MinMaxRangeType)2 StringDataType (org.ccsds.schema.sois.seds.StringDataType)2 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)1 TableInformation (CCDD.CcddClassesDataTable.TableInformation)1 BigInteger (java.math.BigInteger)1 ArrayDimensionsType (org.ccsds.schema.sois.seds.ArrayDimensionsType)1 DescriptionType (org.ccsds.schema.sois.seds.DescriptionType)1 EntryListType (org.ccsds.schema.sois.seds.EntryListType)1 FloatDataEncodingType (org.ccsds.schema.sois.seds.FloatDataEncodingType)1