Search in sources :

Example 21 with Message

use of CCDD.CcddClassesDataTable.Message in project CCDD by nasa.

the class CcddSchedulerHandler method getStoredData.

/**
 ********************************************************************************************
 * Get the list of messages stored in the database
 *
 * @return List of messages for the data stream stored in the database; null if the scheduler
 *         dialog type is not recognized
 ********************************************************************************************
 */
protected List<Message> getStoredData() {
    List<Message> messages = null;
    // Get the scheduler dialog type
    SchedulerType option = getSchedulerOption();
    // Check if this is a telemetry scheduler
    if (option == SchedulerType.TELEMETRY_SCHEDULER) {
        // Get the variable message assignments for the current data stream
        messages = schedulerDb.getStoredData(rateHandler.getRateInformationIndexByRateName(rateName));
        // Set the link name for the variables in the messages
        ((CcddTelemetrySchedulerInput) schedulerInput).setLinks(messages, rateName);
    } else // Check if this is an application scheduler
    if (option == SchedulerType.APPLICATION_SCHEDULER) {
        // Get the application time slot assignments
        messages = schedulerDb.getStoredData(Integer.valueOf(rateName));
    }
    return messages;
}
Also used : Message(CCDD.CcddClassesDataTable.Message) SchedulerType(CCDD.CcddConstants.SchedulerType)

Example 22 with Message

use of CCDD.CcddClassesDataTable.Message in project CCDD by nasa.

the class CcddSchedulerHandler method getMessageWithRoom.

/**
 ********************************************************************************************
 * Find the message option that has the largest message with the least amount of room
 *
 * @param rate
 *            rate of the options
 *
 * @param totalSize
 *            size of the variable(s) in bytes
 *
 * @return Message into which the specified bytes can fit; null if no option is chosen
 ********************************************************************************************
 */
private String getMessageWithRoom(Float rate, int totalSize) {
    // Option that is chosen
    String selectedOption = null;
    // List of all available options
    List<String> options = schedulerEditor.getMessageAvailability(rate);
    // Check if there is at least one option available
    if (!options.isEmpty()) {
        // Largest amount of bytes in the list of options
        int smallestSize = -100;
        // Step though each message object that the variable can fit into
        for (int optIndex = 0; optIndex < options.size(); optIndex++) {
            // Parse the option string to extract the sub-index (if this is a sub-option) and
            // the message indices
            Object[] parsedIndices = parseOption(options.get(optIndex));
            int parentIndex = (int) parsedIndices[0];
            Integer[] indices = (Integer[]) parsedIndices[1];
            // Check if the message has a remaining slot available
            if (checkSlotAvailability(indices, 1)) {
                // Set the size to that of the first message
                int size = Integer.MAX_VALUE;
                // Step through each message inside an option
                for (int index = 0; index < indices.length; index++) {
                    // Set message to the desired message
                    Message message = schedulerEditor.getMessage(indices[index], parentIndex);
                    // option
                    if (message.getBytesRemaining() < size) {
                        // Set the smallest to the message's bytes
                        size = message.getBytesRemaining();
                    }
                }
                // Check if smallest size is still the default value
                if (smallestSize == -100) {
                    // Set smallest to the size
                    smallestSize = size;
                    // Set option to the current message
                    selectedOption = options.get(optIndex);
                } else // least bytes remaining in each option
                if (size > smallestSize) {
                    // Assign size to the smallest
                    smallestSize = size;
                    // Set the option to the message
                    selectedOption = options.get(optIndex);
                }
            }
        }
        // Check if the smallest size causes the message to be negative
        if (totalSize > smallestSize) {
            // Set to indicate no option exists
            selectedOption = null;
        }
    }
    return selectedOption;
}
Also used : Message(CCDD.CcddClassesDataTable.Message)

Example 23 with Message

use of CCDD.CcddClassesDataTable.Message in project CCDD by nasa.

the class CcddMessageIDHandler method getMessageIDsInUse.

/**
 ********************************************************************************************
 * Create the list of message IDs that are reserved or are already in use
 *
 * @param includeStructures
 *            true to include message IDs assigned to tables that represent structures
 *
 * @param includeCommands
 *            true to include message IDs assigned to tables that represent commands
 *
 * @param includeOthers
 *            true to include message IDs assigned to tables that do not represent structures
 *            or commands
 *
 * @param includeGroups
 *            true to include message IDs assigned to groups
 *
 * @param useTlmMsgIDsFromDb
 *            true to include message IDs assigned to telemetry messages stored in the project
 *            database; false to use the IDs from the currently open telemetry scheduler
 *
 * @param isOverwriteTlmMsgIDs
 *            true to allow overwriting the telemetry message IDs for the currently selected
 *            data stream in the open telemetry scheduler; false to not allow overwriting. This
 *            value is only used if useTlmMsgIDsFromDb is false
 *
 * @param tlmSchedulerDlg
 *            Reference to the currently open telemetry scheduler. This value is only used if
 *            useTlmMsgIDsFromDb is false, in which case it can be set to null
 *
 * @param isGetDuplicates
 *            true to create a list of duplicate IDs. The flags for including tables and for
 *            using the telemetry message IDs from the database should be set to true when
 *            getting the list of duplicates
 *
 * @param parent
 *            GUI component calling this method
 ********************************************************************************************
 */
protected List<Integer> getMessageIDsInUse(boolean includeStructures, boolean includeCommands, boolean includeOthers, boolean includeGroups, boolean useTlmMsgIDsFromDb, boolean isOverwriteTlmMsgIDs, CcddTelemetrySchedulerDialog tlmSchedulerDlg, boolean isGetDuplicates, Component parent) {
    List<String[]> tableIDs = new ArrayList<String[]>();
    // Empty the duplicates list in case this isn't the first execution of this method
    duplicates.clear();
    potentialDuplicates.clear();
    // Get the list of reserved message ID values
    idsInUse = rsvMsgIDHandler.getReservedMsgIDs();
    // Step through each table type
    for (TypeDefinition typeDefn : tableTypeHandler.getTypeDefinitions()) {
        // Step through each column that contains message IDs
        for (int idColumn : typeDefn.getColumnIndicesByInputType(InputDataType.MESSAGE_ID)) {
            // Query the database for those values in the specified message ID column that are
            // in use in any table, including any references in the custom values table
            tableIDs.addAll(dbTable.queryDatabase("SELECT" + (isGetDuplicates ? " " : " DISTINCT ON (2) ") + "* FROM find_columns_by_name('" + typeDefn.getColumnNamesUser()[idColumn] + "', '" + typeDefn.getColumnNamesDatabase()[idColumn] + "', '{" + typeDefn.getName() + "}');", parent));
        }
    }
    // Get the list of all message ID data field values
    tableIDs.addAll(dbTable.queryDatabase("SELECT" + (isGetDuplicates ? " " : " DISTINCT ON (2) ") + InternalTable.FIELDS.getColumnName(FieldsColumn.OWNER_NAME.ordinal()) + ", " + InternalTable.FIELDS.getColumnName(FieldsColumn.FIELD_VALUE.ordinal()) + " FROM " + InternalTable.FIELDS.getTableName() + " WHERE " + InternalTable.FIELDS.getColumnName(FieldsColumn.FIELD_TYPE.ordinal()) + " = '" + InputDataType.MESSAGE_ID.getInputName() + "' AND " + InternalTable.FIELDS.getColumnName(FieldsColumn.FIELD_VALUE.ordinal()) + " != '';", parent));
    // Get the list of tables representing structures
    structureTables = Arrays.asList(dbTable.getPrototypeTablesOfType(TYPE_STRUCTURE));
    // Get the list of tables representing commands
    commandTables = Arrays.asList(dbTable.getPrototypeTablesOfType(TYPE_COMMAND));
    // Get the list of tables representing table types other than structures and commands
    otherTables = Arrays.asList(dbTable.getPrototypeTablesOfType(TYPE_OTHER));
    // Step through each data field message ID
    for (String[] tableOwnerAndID : tableIDs) {
        // Replace any macro in the message ID with the corresponding text
        tableOwnerAndID[1] = macroHandler.getMacroExpansion(tableOwnerAndID[1]);
        // IDs are to be included
        if (tableOwnerAndID[1].endsWith(PROTECTED_MSG_ID_IDENT) || (includeStructures && structureTables.contains(TableInformation.getPrototypeName(tableOwnerAndID[0]))) || (includeCommands && commandTables.contains(tableOwnerAndID[0])) || (includeOthers && otherTables.contains(tableOwnerAndID[0]))) {
            // Get the IDs in use in the table cells and data fields, and update the duplicates
            // list (if the flag is set)
            updateUsageAndDuplicates("Table", tableOwnerAndID, isGetDuplicates);
        } else // be included
        if (includeGroups && tableOwnerAndID[0].startsWith(GROUP_DATA_FIELD_IDENT)) {
            // Get the IDs in use in the group data fields, and update the duplicates list (if
            // the flag is set)
            updateUsageAndDuplicates("Group", tableOwnerAndID, isGetDuplicates);
        }
    }
    // Check if telemetry message IDs should be obtained from the database
    if (useTlmMsgIDsFromDb) {
        // Get the telemetry message IDs assigned in the telemetry scheduler table
        List<String[]> tlmIDs = dbTable.queryDatabase("SELECT DISTINCT ON (2) " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.RATE_NAME.ordinal()) + " || ', ' || " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_NAME.ordinal()) + ", " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_ID.ordinal()) + " FROM " + InternalTable.TLM_SCHEDULER.getTableName() + " WHERE " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_ID.ordinal()) + " != '' AND " + InternalTable.TLM_SCHEDULER.getColumnName(TlmSchedulerColumn.MESSAGE_NAME.ordinal()) + " !~ E'^.+\\\\..*$';", parent);
        // Step through each telemetry message ID
        for (String[] tlmMsgNameAndID : tlmIDs) {
            // Check if the list of duplicate message IDs is to be created
            if (isGetDuplicates) {
                // Replace the rate name with its corresponding stream name when displaying
                // duplicate IDs
                String rateName = tlmMsgNameAndID[0].replaceFirst(",.*", "");
                String streamName = rateHandler.getRateInformationByRateName(rateName).getStreamName();
                tlmMsgNameAndID[0] = tlmMsgNameAndID[0].replaceFirst(rateName, streamName);
            }
            // Update the IDs in use in the telemetry messages, and update the duplicates list
            // (if the flag is set)
            updateUsageAndDuplicates("Message", tlmMsgNameAndID, isGetDuplicates);
        }
    } else // telemetry scheduler but not yet stored them to the database
    if (tlmSchedulerDlg != null) {
        // Step through each data stream
        for (CcddSchedulerHandler schHndlr : tlmSchedulerDlg.getSchedulerHandlers()) {
            // overwrite check box is not selected
            if (!schHndlr.equals(tlmSchedulerDlg.getSchedulerHandler()) || !isOverwriteTlmMsgIDs) {
                // Step through each message for this data stream
                for (Message message : schHndlr.getSchedulerEditor().getCurrentMessages()) {
                    // Check if the message has an ID
                    if (!message.getID().isEmpty()) {
                        // Add the message ID to the list of existing ID values
                        idsInUse.add(Integer.decode(message.getID()));
                    }
                    // Step through each of the message's sub-messages
                    for (Message subMessage : message.getSubMessages()) {
                        // Check if the sub-message has an ID
                        if (!subMessage.getID().isEmpty()) {
                            // Add the sub-message ID to the list of existing ID values
                            idsInUse.add(Integer.decode(subMessage.getID()));
                        }
                    }
                }
            }
        }
    }
    return idsInUse;
}
Also used : Message(CCDD.CcddClassesDataTable.Message) ArrayList(java.util.ArrayList) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition)

Example 24 with Message

use of CCDD.CcddClassesDataTable.Message in project CCDD by nasa.

the class CcddTelemetrySchedulerInput method selectMessageByVariable.

/**
 ********************************************************************************************
 * Select the message(s) in the assignment tree for which the selected variable in the variable
 * tree is a member
 ********************************************************************************************
 */
private void selectMessageByVariable() {
    // Check if only a single node is selected in the variable tree
    if (variableTree.getSelectionPaths() != null && variableTree.getSelectionPaths().length == 1) {
        // Get the selected variable's path
        Object[] path = variableTree.getSelectionPath().getPath();
        // Set the start of the variable path
        int index = 0;
        // Check if the variable is linked
        if (variableTree.removeExtraText(path[1].toString().trim()).equals(LINKED_VARIABLES_NODE_NAME)) {
            // Set the start of the variable path to skip the root, link header, and link name
            // nodes
            index = 1;
        }
        // Get the first selected variable
        String variablePath = variableTree.getFullVariablePath(path, index);
        // to a message
        if (variablePath.contains(DISABLED_TEXT_COLOR)) {
            // Remove the HTML flags from the variable path
            variablePath = variableTree.removeExtraText(variablePath);
            // Clear any selected message(s) in the Scheduler table
            schedulerDlg.getSchedulerHandler().getSchedulerEditor().getTable().clearSelection();
            // message containing the variable gets the focus
            for (int row = schedulerDlg.getSchedulerHandler().getCurrentMessages().size() - 1; row >= 0; row--) {
                String option = "";
                // Get the message reference
                Message message = schedulerDlg.getSchedulerHandler().getCurrentMessages().get(row);
                // Check if the variable is a member of the message
                if (message.isVariableInMessage(variablePath)) {
                    // Set the option to the message name
                    option = message.getName();
                    // Select the message in the Scheduler table
                    schedulerDlg.getSchedulerHandler().getSchedulerEditor().getTable().changeSelection(row, SchedulerColumn.NAME.ordinal(), true, false);
                } else // Check if the message has any sub-messages
                if (message.getNumberOfSubMessages() > 1) {
                    // Set the column index to the first sub-message ID column
                    int column = SchedulerColumn.ID.ordinal() + 1;
                    // Step through each sub-message
                    for (Message subMsg : message.getSubMessages()) {
                        // Check if the variable is a member of the sub-message
                        if (subMsg.isVariableInMessage(variablePath)) {
                            // Append the sub-message index to the option
                            option += (column - 2) + ", ";
                            // Select the sub-message in the Scheduler table
                            schedulerDlg.getSchedulerHandler().getSchedulerEditor().getTable().changeSelection(row, column, true, false);
                        }
                        column++;
                    }
                    // Check if a matching sub-message was found
                    if (!option.isEmpty()) {
                        // Remove the trailing comma
                        option = CcddUtilities.removeTrailer(option, ", ");
                        // Prepend the message name and sub-message(s) text
                        option = message.getName() + " sub-msg" + (option.contains(",") ? "s" : "") + " " + option;
                    }
                }
                // Check if a matching option was found
                if (!option.isEmpty()) {
                    // Select the option in the options list
                    schedulerDlg.getSchedulerHandler().selectOptionByMessage(option);
                }
            }
        }
    }
}
Also used : Message(CCDD.CcddClassesDataTable.Message)

Aggregations

Message (CCDD.CcddClassesDataTable.Message)24 Variable (CCDD.CcddClassesDataTable.Variable)8 ArrayList (java.util.ArrayList)8 ApplicationData (CCDD.CcddClassesDataTable.ApplicationData)3 DataStream (CCDD.CcddClassesDataTable.DataStream)2 DefaultListModel (javax.swing.DefaultListModel)2 CustomSplitPane (CCDD.CcddClassesComponent.CustomSplitPane)1 CCDDException (CCDD.CcddClassesDataTable.CCDDException)1 FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)1 RateInformation (CCDD.CcddClassesDataTable.RateInformation)1 TelemetryData (CCDD.CcddClassesDataTable.TelemetryData)1 SchedulerType (CCDD.CcddConstants.SchedulerType)1 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 JComponent (javax.swing.JComponent)1 JLabel (javax.swing.JLabel)1