Search in sources :

Example 1 with InterfaceParameterType

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

the class CcddEDSHandler method addParameter.

/**
 ********************************************************************************************
 * Add a telemetry parameter to the name space's parameter set. Create the parameter set for
 * the name space if it does not exist
 *
 * @param namespace
 *            name space
 *
 * @param parameterName
 *            parameter name
 *
 * @param dataType
 *            parameter primitive data type
 *
 * @param arraySize
 *            parameter array size; null or blank if the parameter isn't an array
 *
 * @param bitLength
 *            parameter bit length; null or blank if not a bit-wise parameter
 *
 * @param enumeration
 *            enumeration in the format <enum label>|<enum value>[|...][,...]; null to not
 *            specify
 *
 * @param units
 *            parameter units
 *
 * @param description
 *            parameter description
 *
 * @param stringSize
 *            size, in characters, of a string parameter; ignored if not a string or character
 ********************************************************************************************
 */
private void addParameter(NamespaceType namespace, String parameterName, String dataType, String arraySize, String bitLength, String enumeration, String units, String description, int stringSize) {
    // appears under the ParameterTypeSet, but it will appear under the ParameterSet
    if (dataType != null) {
        // Get the parameter's data type information
        setDataType(namespace, parameterName, dataType, arraySize, bitLength, enumeration, units, description, stringSize, "");
        // Build the parameter attributes
        InterfaceParameterType parameter = factory.createInterfaceParameterType();
        parameter.setName(parameterName);
        parameter.setType(getReferenceByDataType(parameterName, dataType, false) + getObjectIdentifier(arraySize));
        // Check if a description is provided for this parameter
        if (description != null && !description.isEmpty()) {
            // Set the parameter's description
            parameter.setLongDescription(description);
        }
        InterfaceDeclarationType intParmType = null;
        // Step through the interfaces in order to locate the name space's parameter set
        for (InterfaceDeclarationType intfcDecType : namespace.getDeclaredInterfaceSet().getInterface()) {
            // Check if the interface contains a parameter set
            if (intfcDecType.getParameterSet() != null) {
                // Get the parameter set reference and stop searching
                intParmType = intfcDecType;
                break;
            }
        }
        // Check if a parameter set exists
        if (intParmType == null) {
            // Create the parameter set for this name space
            intParmType = createParameterSet(namespace);
        }
        // Add the parameter to the parameter set
        intParmType.getParameterSet().getParameter().add(parameter);
    }
}
Also used : InterfaceDeclarationType(org.ccsds.schema.sois.seds.InterfaceDeclarationType) InterfaceParameterType(org.ccsds.schema.sois.seds.InterfaceParameterType)

Example 2 with InterfaceParameterType

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

Aggregations

InterfaceParameterType (org.ccsds.schema.sois.seds.InterfaceParameterType)2 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)1 BigInteger (java.math.BigInteger)1 ArrayDataType (org.ccsds.schema.sois.seds.ArrayDataType)1 ContainerDataType (org.ccsds.schema.sois.seds.ContainerDataType)1 DerivedTypeRangeType (org.ccsds.schema.sois.seds.DerivedTypeRangeType)1 DescriptionType (org.ccsds.schema.sois.seds.DescriptionType)1 DimensionSizeType (org.ccsds.schema.sois.seds.DimensionSizeType)1 EntryType (org.ccsds.schema.sois.seds.EntryType)1 EnumeratedDataType (org.ccsds.schema.sois.seds.EnumeratedDataType)1 EnumerationListType (org.ccsds.schema.sois.seds.EnumerationListType)1 FloatDataType (org.ccsds.schema.sois.seds.FloatDataType)1 IntegerDataType (org.ccsds.schema.sois.seds.IntegerDataType)1 InterfaceDeclarationType (org.ccsds.schema.sois.seds.InterfaceDeclarationType)1 MinMaxRangeType (org.ccsds.schema.sois.seds.MinMaxRangeType)1 RootDataType (org.ccsds.schema.sois.seds.RootDataType)1 StringDataType (org.ccsds.schema.sois.seds.StringDataType)1 Unit (org.ccsds.schema.sois.seds.Unit)1 ValueEnumerationType (org.ccsds.schema.sois.seds.ValueEnumerationType)1