Search in sources :

Example 1 with Parameter

use of org.omg.space.xtce.ParameterSetType.Parameter in project CCDD by nasa.

the class CcddXTCEHandler method importStructureTable.

/**
 ********************************************************************************************
 * Build a structure table from the specified telemetry metadata
 *
 * @param system
 *            space system
 *
 * @param tlmMetaData
 *            reference to the telemetry metadata from which to build the structure table
 *
 * @param table
 *            name table name, including the full system path
 *
 * @throws CCDDException
 *             If an input error is detected
 ********************************************************************************************
 */
private void importStructureTable(SpaceSystemType system, TelemetryMetaDataType tlmMetaData, String tableName) throws CCDDException {
    // Create a table definition for this structure table. If the name space also includes a
    // command metadata (which creates a command table) then ensure the two tables have
    // different names
    TableDefinition tableDefn = new TableDefinition(tableName + (system.getCommandMetaData() == null ? "" : "_tlm"), system.getLongDescription());
    // Check if a description exists for this structure table
    if (system.getLongDescription() != null && !system.getLongDescription().isEmpty()) {
        // Store the table's description
        tableDefn.setDescription(system.getLongDescription());
    }
    // Set the new structure table's table type name
    tableDefn.setTypeName(structureTypeDefn.getName());
    // Get the telemetry information
    ParameterSetType parmSetType = tlmMetaData.getParameterSet();
    ParameterTypeSetType parmTypeSetType = tlmMetaData.getParameterTypeSet();
    // Check if the telemetry information exists
    if (parmSetType != null && parmTypeSetType != null) {
        // Get the references to the parameter set and parameter type set
        List<Object> parmSet = parmSetType.getParameterOrParameterRef();
        List<NameDescriptionType> parmTypeSet = parmTypeSetType.getStringParameterTypeOrEnumeratedParameterTypeOrIntegerParameterType();
        // Step through each telemetry parameter
        for (int parmIndex = 0; parmIndex < parmSet.size(); parmIndex++) {
            // Get the reference to the parameter in the parameter set
            Parameter parm = (Parameter) parmSet.get(parmIndex);
            // Create a new row of data in the table definition to contain this
            // structures's information. Initialize all columns to blanks except for the
            // variable name
            String[] newRow = new String[numStructureColumns];
            Arrays.fill(newRow, null);
            newRow[variableNameIndex] = parm.getName();
            tableDefn.addData(newRow);
            // name matches the parameter type reference from the parameter set
            for (NameDescriptionType parmType : parmTypeSet) {
                // parameter type set's name
                if (parm.getParameterTypeRef().equals(parmType.getName())) {
                    String dataType = null;
                    String arraySize = null;
                    BigInteger bitLength = null;
                    long sizeInBytes = 0;
                    String enumeration = null;
                    String minimum = null;
                    String maximum = null;
                    UnitSet unitSet = null;
                    // Check if the parameter is an array data type
                    if (parmType instanceof ArrayDataTypeType) {
                        // The size of each array dimension is located in a container set.
                        // The array parameter reference containing the dimensions for the
                        // parameter matches the parameter name. Get the container set
                        // reference
                        ContainerSetType containerSet = tlmMetaData.getContainerSet();
                        // Check if the container set exists
                        if (containerSet != null) {
                            // Step through each sequence container in the container set
                            for (SequenceContainerType seqContainer : containerSet.getSequenceContainer()) {
                                // system
                                if (system.getName().equals(seqContainer.getName())) {
                                    // Step through each entry in the sequence
                                    for (SequenceEntryType entry : seqContainer.getEntryList().getParameterRefEntryOrParameterSegmentRefEntryOrContainerRefEntry()) {
                                        // parameter reference matches the target parameter
                                        if (entry instanceof ArrayParameterRefEntryType && parm.getName().equals(((ArrayParameterRefEntryType) entry).getParameterRef())) {
                                            arraySize = "";
                                            // Store the reference to the array parameter
                                            // type
                                            ArrayDataTypeType arrayType = (ArrayDataTypeType) parmType;
                                            parmType = null;
                                            // variable
                                            for (Dimension dim : ((ArrayParameterRefEntryType) entry).getDimensionList().getDimension()) {
                                                // Build the array size string
                                                arraySize += String.valueOf(dim.getEndingIndex().getFixedValue()) + ",";
                                            }
                                            arraySize = CcddUtilities.removeTrailer(arraySize, ",");
                                            // to locate this data type entry
                                            for (NameDescriptionType type : parmTypeSet) {
                                                // name
                                                if (arrayType.getArrayTypeRef().equals(type.getName())) {
                                                    // Store the reference to the array
                                                    // parameter's data type and stop
                                                    // searching
                                                    parmType = type;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    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 IntegerParameterType) {
                            // 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)
                            IntegerParameterType itlm = (IntegerParameterType) parmType;
                            // Get the number of bits occupied by the parameter
                            bitLength = itlm.getSizeInBits();
                            // Get the parameter units reference
                            unitSet = itlm.getUnitSet();
                            // Check if integer encoding is set to 'unsigned'
                            if (itlm.getIntegerDataEncoding().getEncoding().equalsIgnoreCase("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;
                            // Get the parameter range
                            IntegerRangeType range = itlm.getValidRange();
                            // Check if the parameter has a range
                            if (range != null) {
                                // Check if the minimum value exists
                                if (range.getMinInclusive() != null) {
                                    // Store the minimum
                                    minimum = range.getMinInclusive();
                                }
                                // Check if the maximum value exists
                                if (range.getMaxInclusive() != null) {
                                    // Store the maximum
                                    maximum = range.getMaxInclusive();
                                }
                            }
                            isInteger = true;
                        } else // Check if the parameter is a floating point data type
                        if (parmType instanceof FloatParameterType) {
                            // Get the float parameter attributes
                            FloatParameterType ftlm = (FloatParameterType) parmType;
                            sizeInBytes = ftlm.getSizeInBits().longValue() / 8;
                            unitSet = ftlm.getUnitSet();
                            // Get the parameter range
                            FloatRangeType range = ftlm.getValidRange();
                            // Check if the parameter has a range
                            if (range != null) {
                                // Check if the minimum value exists
                                if (range.getMinInclusive() != null) {
                                    // Store the minimum
                                    minimum = String.valueOf(range.getMinInclusive());
                                }
                                // Check if the maximum exists
                                if (range.getMaxInclusive() != null) {
                                    // Store the maximum
                                    maximum = String.valueOf(range.getMaxInclusive());
                                }
                            }
                            isFloat = true;
                        } else // Check if the parameter is a string data type
                        if (parmType instanceof StringParameterType) {
                            // Get the string parameter attributes
                            StringParameterType stlm = (StringParameterType) parmType;
                            sizeInBytes = stlm.getCharacterWidth().longValue();
                            unitSet = stlm.getUnitSet();
                            isString = true;
                        } else // Check if the parameter is an enumerated data type
                        if (parmType instanceof EnumeratedParameterType) {
                            // Get the enumeration parameters
                            EnumeratedParameterType etlm = (EnumeratedParameterType) parmType;
                            EnumerationList 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();
                                unitSet = etlm.getUnitSet();
                                // Check if integer encoding is set to 'unsigned'
                                if (etlm.getIntegerDataEncoding().getEncoding().equalsIgnoreCase("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 // structure reference
                        if (parmType instanceof AggregateDataType) {
                            // The aggregate type contains a member list of the parameters
                            // belonging to the referenced structure. Each list parameter
                            // has the path to the space system defining the structure;
                            // this path is used to get the structure data type
                            // Get the reference to the aggregate's member list
                            List<Member> memberList = ((AggregateDataType) parmType).getMemberList().getMember();
                            // Check if the member list exists
                            if (!memberList.isEmpty()) {
                                // Get the type reference of the structure's first
                                // parameter which is the path to its space system
                                dataType = memberList.get(0).getTypeRef();
                                // beginning '/' is stripped off
                                if (dataType.startsWith("/")) {
                                    // Remove the initial '/'
                                    dataType = dataType.substring(1);
                                }
                                // The variable name must be stripped from the space system
                                // 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 (parmType.getLongDescription() != null) {
                            // Store the description
                            tableDefn.getData().set(parmIndex * numStructureColumns + descriptionIndex, parmType.getLongDescription());
                        }
                        // Check if a units exists and
                        if (unitSet != null) {
                            List<UnitType> unitType = unitSet.getUnit();
                            // Check if the units exist
                            if (!unitType.isEmpty()) {
                                // Store the units for this variable
                                tableDefn.getData().set(parmIndex * numStructureColumns + unitsIndex, unitType.get(0).getContent());
                            }
                        }
                        // 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;
                }
            }
        }
        ContainerSetType containerSet;
        // Check if the application ID data field name and the container set exist
        if ((containerSet = tlmMetaData.getContainerSet()) != null) {
            // Step through each sequence container in the container set
            for (SequenceContainerType seqContainer : containerSet.getSequenceContainer()) {
                // Check if this is the sequence container for the target system
                if (system.getName().equals(seqContainer.getName())) {
                    BaseContainer baseContainer;
                    RestrictionCriteria restrictionCriteria;
                    ComparisonList comparisonList;
                    // Check if the comparison list exists
                    if (((baseContainer = seqContainer.getBaseContainer()) != null) && ((restrictionCriteria = baseContainer.getRestrictionCriteria()) != null) && ((comparisonList = restrictionCriteria.getComparisonList()) != null)) {
                        // Step through each item in the comparison list
                        for (ComparisonType comparison : comparisonList.getComparison()) {
                            // application ID name
                            if (comparison.getParameterRef().equals(ccsdsAppID)) {
                                // Create a data field for the table containing the application
                                // ID. Once a match is found the search is discontinued
                                tableDefn.addDataField(new String[] { tableName, comparison.getParameterRef(), "Message ID", String.valueOf(comparison.getValue().length()), InputDataType.MESSAGE_ID.getInputName(), String.valueOf(false), ApplicabilityType.ROOT_ONLY.getApplicabilityName(), comparison.getValue() });
                                break;
                            }
                        }
                    }
                    break;
                }
            }
        }
    }
    // Add the structure table definition to the list
    tableDefinitions.add(tableDefn);
}
Also used : EnumerationList(org.omg.space.xtce.EnumeratedDataType.EnumerationList) ValueEnumerationType(org.omg.space.xtce.ValueEnumerationType) SequenceContainerType(org.omg.space.xtce.SequenceContainerType) ComparisonType(org.omg.space.xtce.ComparisonType) StringParameterType(org.omg.space.xtce.ParameterTypeSetType.StringParameterType) IntegerParameterType(org.omg.space.xtce.ParameterTypeSetType.IntegerParameterType) IntegerRangeType(org.omg.space.xtce.IntegerRangeType) RestrictionCriteria(org.omg.space.xtce.SequenceContainerType.BaseContainer.RestrictionCriteria) SequenceEntryType(org.omg.space.xtce.SequenceEntryType) NameDescriptionType(org.omg.space.xtce.NameDescriptionType) BaseContainer(org.omg.space.xtce.SequenceContainerType.BaseContainer) FloatParameterType(org.omg.space.xtce.ParameterTypeSetType.FloatParameterType) UnitType(org.omg.space.xtce.UnitType) ArrayParameterRefEntryType(org.omg.space.xtce.ArrayParameterRefEntryType) TableDefinition(CCDD.CcddClassesDataTable.TableDefinition) ParameterTypeSetType(org.omg.space.xtce.ParameterTypeSetType) ComparisonList(org.omg.space.xtce.MatchCriteriaType.ComparisonList) Member(org.omg.space.xtce.AggregateDataType.MemberList.Member) ParameterSetType(org.omg.space.xtce.ParameterSetType) Dimension(org.omg.space.xtce.ArrayParameterRefEntryType.DimensionList.Dimension) ArrayDataTypeType(org.omg.space.xtce.ArrayDataTypeType) ContainerSetType(org.omg.space.xtce.ContainerSetType) AggregateDataType(org.omg.space.xtce.AggregateDataType) Parameter(org.omg.space.xtce.ParameterSetType.Parameter) BigInteger(java.math.BigInteger) UnitSet(org.omg.space.xtce.BaseDataType.UnitSet) FloatRangeType(org.omg.space.xtce.FloatRangeType) EnumeratedParameterType(org.omg.space.xtce.ParameterTypeSetType.EnumeratedParameterType)

Example 2 with Parameter

use of org.omg.space.xtce.ParameterSetType.Parameter in project CCDD by nasa.

the class CcddXTCEHandler method addParameter.

/**
 ********************************************************************************************
 * Add a telemetry parameter to the telemetry metadata
 *
 * @param spaceSystem
 *            space system
 *
 * @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 minimum
 *            minimum parameter value
 *
 * @param maximum
 *            maximum parameter value
 *
 * @param description
 *            parameter description
 *
 * @param stringSize
 *            size, in characters, of a string parameter; ignored if not a string or character
 ********************************************************************************************
 */
private void addParameter(SpaceSystemType spaceSystem, String parameterName, String dataType, String arraySize, String bitLength, String enumeration, String units, String minimum, String maximum, String description, int stringSize) {
    // Check if this system doesn't yet have its telemetry metadata created
    if (spaceSystem.getTelemetryMetaData() == null) {
        // Create the telemetry metadata
        createTelemetryMetadata(spaceSystem);
    }
    // Check if a data type is provided
    if (dataType != null) {
        // Get the parameter's data type information
        setParameterDataType(spaceSystem, parameterName, dataType, arraySize, bitLength, enumeration, units, minimum, maximum, description, stringSize);
    }
    // Create the parameter. This links the parameter name with the parameter reference type
    ParameterSetType parameterSet = spaceSystem.getTelemetryMetaData().getParameterSet();
    Parameter parameter = factory.createParameterSetTypeParameter();
    parameter.setName(parameterName);
    parameter.setParameterTypeRef(getNameByDataType(parameterName, dataType) + (arraySize.isEmpty() ? TYPE : ARRAY));
    parameterSet.getParameterOrParameterRef().add(parameter);
}
Also used : ParameterSetType(org.omg.space.xtce.ParameterSetType) Parameter(org.omg.space.xtce.ParameterSetType.Parameter)

Aggregations

ParameterSetType (org.omg.space.xtce.ParameterSetType)2 Parameter (org.omg.space.xtce.ParameterSetType.Parameter)2 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)1 BigInteger (java.math.BigInteger)1 AggregateDataType (org.omg.space.xtce.AggregateDataType)1 Member (org.omg.space.xtce.AggregateDataType.MemberList.Member)1 ArrayDataTypeType (org.omg.space.xtce.ArrayDataTypeType)1 ArrayParameterRefEntryType (org.omg.space.xtce.ArrayParameterRefEntryType)1 Dimension (org.omg.space.xtce.ArrayParameterRefEntryType.DimensionList.Dimension)1 UnitSet (org.omg.space.xtce.BaseDataType.UnitSet)1 ComparisonType (org.omg.space.xtce.ComparisonType)1 ContainerSetType (org.omg.space.xtce.ContainerSetType)1 EnumerationList (org.omg.space.xtce.EnumeratedDataType.EnumerationList)1 FloatRangeType (org.omg.space.xtce.FloatRangeType)1 IntegerRangeType (org.omg.space.xtce.IntegerRangeType)1 ComparisonList (org.omg.space.xtce.MatchCriteriaType.ComparisonList)1 NameDescriptionType (org.omg.space.xtce.NameDescriptionType)1 ParameterTypeSetType (org.omg.space.xtce.ParameterTypeSetType)1 EnumeratedParameterType (org.omg.space.xtce.ParameterTypeSetType.EnumeratedParameterType)1 FloatParameterType (org.omg.space.xtce.ParameterTypeSetType.FloatParameterType)1