Search in sources :

Example 1 with InterfaceCommandType

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

the class CcddEDSHandler method importCommandTable.

/**
 ********************************************************************************************
 * Build a command table from the specified command metadata
 *
 * @param namespace
 *            name space
 *
 * @param commandSet
 *            reference to the command set from which to build the command table
 *
 * @param table
 *            name table name, including the full system path
 *
 * @param hasParameter
 *            true if the name space also has a parameter set
 *
 * @throws CCDDException
 *             If an input error is detected
 ********************************************************************************************
 */
private void importCommandTable(NamespaceType namespace, List<InterfaceCommandType> commandSet, String tableName, boolean hasParameter) throws CCDDException {
    // Create a table definition for this command table. If the name space also includes a
    // parameter set (which creates a structure table) then ensure the two tables have
    // different names
    TableDefinition tableDefn = new TableDefinition(tableName + (hasParameter ? "_cmd" : ""), namespace.getLongDescription());
    // Check if a description exists for this command table
    if (namespace.getLongDescription() != null && !namespace.getLongDescription().isEmpty()) {
        // Store the table's description
        tableDefn.setDescription(namespace.getLongDescription());
    }
    // Set the new command table's table type name
    tableDefn.setTypeName(commandTypeDefn.getName());
    // Check if the description column belongs to a command argument
    if (commandArguments.size() != 0 && cmdDescriptionIndex > commandArguments.get(0).getName()) {
        // Reset the command description index to indicate no description exists
        cmdDescriptionIndex = -1;
    }
    // Step through each command
    for (InterfaceCommandType cmdType : commandSet) {
        // Create a new row of data in the table definition to contain this command's
        // information. Initialize all columns to blanks except for the command name
        String[] newRow = new String[commandTypeDefn.getColumnCountVisible()];
        Arrays.fill(newRow, null);
        newRow[commandNameIndex] = cmdType.getName();
        // table type definition
        if (cmdType.getLongDescription() != null && cmdDescriptionIndex != -1) {
            // Store the command description in the row's description
            // column
            newRow[cmdDescriptionIndex] = cmdType.getLongDescription();
        }
        int cmdArgIndex = 0;
        // Step through each of the command's arguments
        for (CommandArgumentType argList : cmdType.getArgument()) {
            // type
            if (namespace.getDataTypeSet() != null && commandNameIndex != -1) {
                // Step through each data type set
                for (RootDataType argType : namespace.getDataTypeSet().getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
                    // list (by matching the command and argument names between the two)
                    if (argList.getType().equals(argType.getName())) {
                        boolean isInteger = false;
                        boolean isUnsigned = false;
                        boolean isFloat = false;
                        boolean isString = false;
                        String dataType = null;
                        String arraySize = null;
                        BigInteger bitLength = null;
                        long sizeInBytes = 0;
                        String enumeration = null;
                        String description = null;
                        Unit units = null;
                        String minimum = null;
                        String maximum = null;
                        // Check if the argument is an array data type
                        if (argType instanceof ArrayDataType) {
                            arraySize = "";
                            // Store the reference to the array parameter type
                            ArrayDataType arrayType = (ArrayDataType) argType;
                            argType = null;
                            // Step through each dimension for the array variable
                            for (DimensionSizeType dim : arrayType.getDimensionList().getDimension()) {
                                // Build the array size string
                                arraySize += String.valueOf(dim.getSize().longValue()) + ",";
                            }
                            arraySize = CcddUtilities.removeTrailer(arraySize, ",");
                            // type entry Step through each data type set
                            for (RootDataType type : namespace.getDataTypeSet().getArrayDataTypeOrBinaryDataTypeOrBooleanDataType()) {
                                // the data type name
                                if (arrayType.getDataTypeRef().equals(type.getName())) {
                                    // Store the reference to the array parameter's data type
                                    // and stop searching
                                    argType = type;
                                    break;
                                }
                            }
                        }
                        // locate the data type entry for the individual array members)
                        if (argType != null) {
                            // Check if the argument is an integer data type
                            if (argType instanceof IntegerDataType) {
                                IntegerDataType icmd = (IntegerDataType) argType;
                                // Get the number of bits occupied by the argument
                                bitLength = icmd.getIntegerDataEncoding().getSizeInBits();
                                // Check if units exist for this argument
                                if (icmd.getSemantics() != null && icmd.getSemantics().getUnit() != null) {
                                    // Get the argument units reference
                                    units = icmd.getSemantics().getUnit();
                                }
                                // Check if integer encoding is set to 'unsigned'
                                if (icmd.getIntegerDataEncoding().getEncoding() == IntegerEncodingType.UNSIGNED) {
                                    isUnsigned = true;
                                }
                                // Determine the smallest integer size that contains the number
                                // of bits occupied by the argument
                                sizeInBytes = 8;
                                while (bitLength.longValue() > sizeInBytes) {
                                    sizeInBytes *= 2;
                                }
                                sizeInBytes /= 8;
                                // Get the argument range
                                IntegerDataTypeRangeType range = icmd.getRange();
                                // Check if the argument has a range
                                if (range != null && range.getMinMaxRange() != null) {
                                    MinMaxRangeType minMax = range.getMinMaxRange();
                                    // Check if the argument has a minimum value
                                    if (minMax.getMin() != null) {
                                        // Store the minimum value
                                        minimum = minMax.getMin().toString();
                                    }
                                    // Check if the argument has a maximum value
                                    if (minMax.getMax() != null) {
                                        // Store the maximum value
                                        maximum = minMax.getMax().toString();
                                    }
                                }
                                isInteger = true;
                            } else // Check if the argument is a floating point data type
                            if (argType instanceof FloatDataType) {
                                // Get the float argument attributes
                                FloatDataType fcmd = (FloatDataType) argType;
                                // Check if units exist for this argument
                                if (fcmd.getSemantics() != null && fcmd.getSemantics().getUnit() != null) {
                                    // Get the argument units reference
                                    units = fcmd.getSemantics().getUnit();
                                }
                                switch(fcmd.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;
                                }
                                // Get the argument range
                                FloatDataTypeRangeType range = fcmd.getRange();
                                // Check if the argument has a range
                                if (range != null && range.getMinMaxRange() != null) {
                                    MinMaxRangeType minMax = range.getMinMaxRange();
                                    // Check if the argument has a minimum value
                                    if (minMax.getMin() != null) {
                                        // Store the minimum value
                                        minimum = minMax.getMin().toString();
                                    }
                                    // Check if the argument has a maximum value
                                    if (minMax.getMax() != null) {
                                        // Store the maximum value
                                        maximum = minMax.getMax().toString();
                                    }
                                }
                                isFloat = true;
                            } else // Check if the argument is a string data type
                            if (argType instanceof StringDataType) {
                                // Get the string argument attributes
                                StringDataType scmd = (StringDataType) argType;
                                sizeInBytes = scmd.getLength().longValue();
                                // Check if units exist for this argument
                                if (scmd.getSemantics() != null && scmd.getSemantics().getUnit() != null) {
                                    // Get the argument units reference
                                    units = scmd.getSemantics().getUnit();
                                }
                                isString = true;
                            } else // Check if the argument is an enumerated data type
                            if (argType instanceof EnumeratedDataType) {
                                EnumeratedDataType ecmd = (EnumeratedDataType) argType;
                                EnumerationListType enumList = ecmd.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 = ecmd.getIntegerDataEncoding().getSizeInBits();
                                    // Check if units exist for this argument
                                    if (ecmd.getSemantics() != null && ecmd.getSemantics().getUnit() != null) {
                                        // Get the argument units reference
                                        units = ecmd.getSemantics().getUnit();
                                    }
                                    // Check if integer encoding is set to 'unsigned'
                                    if (ecmd.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;
                                }
                            }
                            // 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 the description exists
                            if (argList.getLongDescription() != null) {
                                // Store the description
                                description = argList.getLongDescription();
                            }
                            // dictated by the table type definition
                            if (cmdArgIndex < commandArguments.size()) {
                                // Get the command argument reference
                                AssociatedColumns acmdArg = commandArguments.get(cmdArgIndex);
                                // Check if the command argument name is present
                                if (acmdArg.getName() != -1) {
                                    // Store the command argument name
                                    newRow[acmdArg.getName()] = argList.getName();
                                }
                                // Check if the command argument data type is present
                                if (acmdArg.getDataType() != -1 && dataType != null) {
                                    // Store the command argument data type
                                    newRow[acmdArg.getDataType()] = dataType;
                                }
                                // Check if the command argument array size is present
                                if (acmdArg.getArraySize() != -1 && arraySize != null) {
                                    // Store the command argument array size
                                    newRow[acmdArg.getArraySize()] = arraySize;
                                }
                                // Check if the command argument bit length is present
                                if (acmdArg.getBitLength() != -1 && bitLength != null) {
                                    // Store the command argument bit length
                                    newRow[acmdArg.getBitLength()] = bitLength.toString();
                                }
                                // Check if the command argument enumeration is present
                                if (acmdArg.getEnumeration() != -1 && enumeration != null) {
                                    // Store the command argument enumeration
                                    newRow[acmdArg.getEnumeration()] = enumeration;
                                }
                                // Check if the command argument description is present
                                if (acmdArg.getDescription() != -1 && description != null) {
                                    // Store the command argument description
                                    newRow[acmdArg.getDescription()] = description;
                                }
                                // Check if the command argument units is present
                                if (acmdArg.getUnits() != -1 && units != null) {
                                    // Store the command argument units
                                    newRow[acmdArg.getUnits()] = units.toString();
                                }
                                // Check if the command argument minimum is present
                                if (acmdArg.getMinimum() != -1 && minimum != null) {
                                    // Store the command argument minimum
                                    newRow[acmdArg.getMinimum()] = minimum;
                                }
                                // Check if the command argument maximum is present
                                if (acmdArg.getMaximum() != -1 && maximum != null) {
                                    // Store the command argument maximum
                                    newRow[acmdArg.getMaximum()] = maximum;
                                }
                            }
                        }
                        // Increment the argument index
                        cmdArgIndex++;
                        break;
                    }
                }
            }
        }
        // Add the new row to the table definition
        tableDefn.addData(newRow);
    }
    // Add the command table definition to the list
    tableDefinitions.add(tableDefn);
}
Also used : ValueEnumerationType(org.ccsds.schema.sois.seds.ValueEnumerationType) FloatDataType(org.ccsds.schema.sois.seds.FloatDataType) CommandArgumentType(org.ccsds.schema.sois.seds.CommandArgumentType) IntegerDataType(org.ccsds.schema.sois.seds.IntegerDataType) EnumeratedDataType(org.ccsds.schema.sois.seds.EnumeratedDataType) MinMaxRangeType(org.ccsds.schema.sois.seds.MinMaxRangeType) Unit(org.ccsds.schema.sois.seds.Unit) 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) AssociatedColumns(CCDD.CcddClassesDataTable.AssociatedColumns) InterfaceCommandType(org.ccsds.schema.sois.seds.InterfaceCommandType) TableDefinition(CCDD.CcddClassesDataTable.TableDefinition) BigInteger(java.math.BigInteger) ArrayDataType(org.ccsds.schema.sois.seds.ArrayDataType) DimensionSizeType(org.ccsds.schema.sois.seds.DimensionSizeType) FloatDataTypeRangeType(org.ccsds.schema.sois.seds.FloatDataTypeRangeType)

Example 2 with InterfaceCommandType

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

the class CcddEDSHandler method addCommand.

/**
 ********************************************************************************************
 * Add a command metadata set to the command metadata
 *
 * @param namespace
 *            name space
 *
 * @param commandName
 *            command name
 *
 * @param commandCode
 *            command code
 *
 * @param isCmdHeader
 *            true if this table represents the CCSDS command header
 *
 * @param applicationID
 *            application ID
 *
 * @param ccsdsAppID
 *            name of the command header argument containing the application ID
 *
 * @param ccsdsFuncCode
 *            name of the command header argument containing the command function code
 *
 * @param argumentNames
 *            list of command argument names
 *
 * @param description
 *            description of the command
 ********************************************************************************************
 */
private void addCommand(NamespaceType namespace, String commandName, // TODO WHERE DOES THIS GET PUT?
String commandCode, boolean isCmdHeader, // TODO WHERE DOES THIS GET PUT?
String applicationID, // TODO WHERE DOES THIS GET PUT?
String ccsdsAppID, // TODO WHERE DOES THIS GET PUT?
String ccsdsFuncCode, List<CommandArgumentType> arguments, String description) {
    // Build the command attributes
    InterfaceCommandType command = factory.createInterfaceCommandType();
    command.setName(commandName);
    // Check if a command description is provided
    if (description != null && !description.isEmpty()) {
        // Set the command description
        command.setLongDescription(description);
    }
    // Check if any arguments are supplied for this command
    if (!arguments.isEmpty()) {
        // Step through each argument type
        for (CommandArgumentType argType : arguments) {
            // Add the argument information to the command
            command.getArgument().add(argType);
        }
    }
    InterfaceDeclarationType intCmdType = null;
    // Step through the interfaces in order to locate the name space's command set
    for (InterfaceDeclarationType intfcDecType : namespace.getDeclaredInterfaceSet().getInterface()) {
        // Check if the interface contains a command set
        if (intfcDecType.getCommandSet() != null) {
            // Get the command set reference and stop searching
            intCmdType = intfcDecType;
            break;
        }
    }
    // Check if a command set exists
    if (intCmdType == null) {
        // Create the command set for this name space
        intCmdType = createCommandSet(namespace);
    }
    // Check if this isn't the command header table
    if (!namespace.getName().equals(cmdHeaderTable)) {
        // Set the command header as the base
        BaseTypeSetType baseType = factory.createBaseTypeSetType();
        InterfaceRefType intfcType = factory.createInterfaceRefType();
        intfcType.setType(cmdHeaderTable + "/" + COMMAND);
        baseType.getBaseType().add(intfcType);
        intCmdType.setBaseTypeSet(baseType);
    }
    // Add the command to the command set
    intCmdType.getCommandSet().getCommand().add(command);
}
Also used : CommandArgumentType(org.ccsds.schema.sois.seds.CommandArgumentType) InterfaceCommandType(org.ccsds.schema.sois.seds.InterfaceCommandType) InterfaceDeclarationType(org.ccsds.schema.sois.seds.InterfaceDeclarationType) BaseTypeSetType(org.ccsds.schema.sois.seds.BaseTypeSetType) InterfaceRefType(org.ccsds.schema.sois.seds.InterfaceRefType)

Aggregations

CommandArgumentType (org.ccsds.schema.sois.seds.CommandArgumentType)2 InterfaceCommandType (org.ccsds.schema.sois.seds.InterfaceCommandType)2 AssociatedColumns (CCDD.CcddClassesDataTable.AssociatedColumns)1 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)1 BigInteger (java.math.BigInteger)1 ArrayDataType (org.ccsds.schema.sois.seds.ArrayDataType)1 BaseTypeSetType (org.ccsds.schema.sois.seds.BaseTypeSetType)1 DimensionSizeType (org.ccsds.schema.sois.seds.DimensionSizeType)1 EnumeratedDataType (org.ccsds.schema.sois.seds.EnumeratedDataType)1 EnumerationListType (org.ccsds.schema.sois.seds.EnumerationListType)1 FloatDataType (org.ccsds.schema.sois.seds.FloatDataType)1 FloatDataTypeRangeType (org.ccsds.schema.sois.seds.FloatDataTypeRangeType)1 IntegerDataType (org.ccsds.schema.sois.seds.IntegerDataType)1 IntegerDataTypeRangeType (org.ccsds.schema.sois.seds.IntegerDataTypeRangeType)1 InterfaceDeclarationType (org.ccsds.schema.sois.seds.InterfaceDeclarationType)1 InterfaceRefType (org.ccsds.schema.sois.seds.InterfaceRefType)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