Search in sources :

Example 16 with Variable

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

the class CcddSchedulerDbIOHandler method loadTelemetryData.

/**
 ********************************************************************************************
 * Load the stored data from the project database and initialize the telemetry table
 ********************************************************************************************
 */
private void loadTelemetryData() {
    // Load the data from the database
    List<String[]> storedData = dbTable.retrieveInformationTable(InternalTable.TLM_SCHEDULER, ccddMain.getMainFrame());
    // Check if there is data stored
    if (!storedData.isEmpty()) {
        List<Message> msgList = null;
        List<Variable> varList;
        // Get the maximum messages per second in floating point format
        float msgsPerSec = Float.valueOf(rateHandler.getMaxMsgsPerSecond());
        // Step through each row in from the table
        for (String[] data : storedData) {
            RateInformation info = null;
            msgList = null;
            varList = null;
            // Get the rate column name, message name, message ID, and members
            String rateName = data[TlmSchedulerColumn.RATE_NAME.ordinal()];
            String messageName = data[TlmSchedulerColumn.MESSAGE_NAME.ordinal()];
            String messageID = data[TlmSchedulerColumn.MESSAGE_ID.ordinal()];
            String member = data[TlmSchedulerColumn.MEMBER.ordinal()];
            // Step through the existing data streams
            for (DataStream dataStream : dataStreams) {
                // Check if the data stream already exists
                if (rateName.equals(dataStream.getRateName())) {
                    // Get the rate information for the data stream
                    info = rateHandler.getRateInformationByRateName(dataStream.getRateName());
                    // Get the messages for this the data stream
                    msgList = dataStream.getMessages();
                    // Get the variables for this the data stream
                    varList = dataStream.getVariableList();
                    break;
                }
            }
            // exist
            if (msgList == null) {
                // Get the rate information for this rate column
                info = rateHandler.getRateInformationByRateName(rateName);
                // Check if the rate exists
                if (info != null) {
                    // Create a new data stream for the data
                    DataStream stream = new DataStream(rateName);
                    // Add the stream to the existing list
                    dataStreams.add(stream);
                    // Get a reference to the created data stream message list
                    msgList = stream.getMessages();
                    // Get a reference to the created data stream variable list
                    varList = stream.getVariableList();
                }
            }
            // Check if the rate exists
            if (info != null) {
                int subIndex = -1;
                Message message = null;
                Variable variable = null;
                // Separate the message's name and the sub-index, if any
                String[] nameAndIndex = messageName.split("\\.");
                // Calculate the period (= total messages / total messages per second)
                float period = Float.valueOf(info.getMaxMsgsPerCycle()) / Float.valueOf(msgsPerSec);
                // Step through the created messages
                for (Message msg : msgList) {
                    // Check if the message has already been created
                    if (msg.getName().equals(nameAndIndex[0])) {
                        // Store the message object
                        message = msg;
                        // Check if this is a sub-message definition
                        if (nameAndIndex.length == 2) {
                            // Step through all the message's sub-messages
                            for (Message subMessage : message.getSubMessages()) {
                                // Check if the sub-message already exists
                                if (subMessage.getName().equals(messageName)) {
                                    // Get the sub-message's index and assign the sub-message's
                                    // ID
                                    subIndex = Integer.valueOf(nameAndIndex[1]);
                                    message.getSubMessage(subIndex).setID(messageID);
                                }
                            }
                            // Check if no sub-index was found
                            if (subIndex == -1) {
                                // Get the sub-index from the message name
                                subIndex = Integer.valueOf(nameAndIndex[1]);
                                // Create a new sub-message and assign the sub-message's ID
                                message.addNewSubMessage(messageID);
                            }
                        }
                        break;
                    }
                }
                // Check if no message object was found
                if (message == null) {
                    // Create a new parent message
                    message = new Message(nameAndIndex[0], messageID, info.getMaxBytesPerSec() / info.getMaxMsgsPerCycle());
                    subIndex = 0;
                    // Add the message to the existing message list
                    msgList.add(message);
                }
                // Check if the message has a member
                if (!member.isEmpty()) {
                    // Split the member column to remove the rate and extract the variable name
                    String varName = member.split("\\" + TLM_SCH_SEPARATOR, 2)[1];
                    // Step through the variables
                    for (Variable var : varList) {
                        // Check if the variable has already been created
                        if (var.getFullName().equals(varName)) {
                            // Store the variable and stop searching
                            variable = var;
                            break;
                        }
                    }
                    // Check if the variable doesn't already exist
                    if (variable == null) {
                        // Create a new variable
                        variable = VariableGenerator.generateTelemetryData(member);
                        // Add the variable to the existing variable list
                        varList.add(variable);
                    }
                    // Check if the rate is a sub-rate
                    if (variable.getRate() < period) {
                        // Assign the variable to the sub-message and store the message index
                        message.getSubMessage(subIndex).addVariable(variable);
                        variable.addMessageIndex(subIndex);
                    } else // The rate isn't a sub-rate
                    {
                        // Check if the variable has not already been assigned to the message
                        if (!message.getAllVariables().contains(variable)) {
                            // Add the variable to the general message
                            message.addVariable(variable);
                        }
                        // Store the message index
                        variable.addMessageIndex(msgList.indexOf(message));
                    }
                }
            }
        }
    }
}
Also used : Variable(CCDD.CcddClassesDataTable.Variable) Message(CCDD.CcddClassesDataTable.Message) DataStream(CCDD.CcddClassesDataTable.DataStream) RateInformation(CCDD.CcddClassesDataTable.RateInformation)

Example 17 with Variable

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

the class CcddSchedulerDbIOHandler method loadApplicationData.

/**
 ********************************************************************************************
 * Get the stored data from the project database and initialize the application table
 ********************************************************************************************
 */
private void loadApplicationData() {
    List<Message> messages = new ArrayList<Message>();
    List<Variable> varList = new ArrayList<Variable>();
    // Load the application scheduler table
    List<String[]> storedData = dbTable.retrieveInformationTable(InternalTable.APP_SCHEDULER, ccddMain.getMainFrame());
    // Check if any stored data exists
    if (!storedData.isEmpty()) {
        // Calculate the message's time usage
        int time = 1000 / appHandler.getMaxMsgsPerSecond();
        for (String[] row : storedData) {
            Message msg = null;
            Variable var = null;
            // Step through all the created message
            for (Message message : messages) {
                // Check if the message has already been created
                if (message.getName().equals(row[AppSchedulerColumn.TIME_SLOT.ordinal()])) {
                    // Assign the existing message to the message object and stop searching
                    msg = message;
                    break;
                }
            }
            // Check if the message object is still null
            if (msg == null) {
                // Create a new message
                msg = new Message(row[AppSchedulerColumn.TIME_SLOT.ordinal()], "", time);
                // Add the message to the existing message list
                messages.add(msg);
            }
            // Check if the member column contains application information
            if (!row[AppSchedulerColumn.APP_INFO.ordinal()].isEmpty()) {
                // Split the member column to extract the application name
                String name = row[AppSchedulerColumn.APP_INFO.ordinal()].split(",", DefaultApplicationField.values().length)[0];
                // Step through all created variables
                for (Variable variable : varList) {
                    // Check if the variable has already been created
                    if (variable.getFullName().equals(name)) {
                        // Assign the existing variable to the variable object
                        var = variable;
                        break;
                    }
                }
                // Check if the variable is still null
                if (var == null) {
                    // Create a new variable
                    var = VariableGenerator.generateApplicationData(row[AppSchedulerColumn.APP_INFO.ordinal()]);
                    // Add the variable to the existing variable list
                    varList.add(var);
                }
                // Add the variable to the general message
                msg.addVariable(var);
                var.addMessageIndex(Integer.valueOf(msg.getName().trim().split("_")[1]) - 1);
            }
        }
    }
    // Create a data stream object for the application information
    dataStreams.add(new DataStream(messages, varList));
}
Also used : Variable(CCDD.CcddClassesDataTable.Variable) Message(CCDD.CcddClassesDataTable.Message) DataStream(CCDD.CcddClassesDataTable.DataStream) ArrayList(java.util.ArrayList)

Example 18 with Variable

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

the class CcddSchedulerEditorHandler method initializeSchedulerTable.

/**
 ********************************************************************************************
 * Initialize the scheduler table. Add values to the current data which is used when creating
 * the table. The message list is also initialized
 ********************************************************************************************
 */
private void initializeSchedulerTable() {
    // Initialize the messages lists
    messages = new ArrayList<Message>();
    // Load the stored variables
    List<Variable> excludedVars = schedulerHndlr.getVariableList();
    // Get the messages from the stored data
    List<Message> storedMsgs = schedulerHndlr.getStoredData();
    // Check if the stored data is either not accurate or not set
    if (storedMsgs.size() != totalMessages) {
        Message msg;
        currentData = new Object[totalMessages][SchedulerColumn.values().length];
        // Step through each row
        for (int row = 0; row < currentData.length; row++) {
            // Create a new message. The space in the name is necessary when parsing the
            // message row for the message indices
            msg = new Message((schedulerHndlr.getSchedulerOption() == TELEMETRY_SCHEDULER ? "Message" : "Time Slot") + "_" + (row + 1), "", emptyMessageSize);
            // Add the message to the existing list
            messages.add(msg);
            // Add message name, size, and ID to the table's current data
            currentData[row][SchedulerColumn.NAME.ordinal()] = msg.getName();
            currentData[row][SchedulerColumn.SIZE.ordinal()] = msg.getBytesRemaining();
            currentData[row][SchedulerColumn.ID.ordinal()] = msg.getID();
        }
    } else // The data stored in the database is accurate
    {
        // Add the messages to the existing list
        messages.addAll(storedMsgs);
        // Set the scheduler table data array to the current message information
        updateSchedulerTable(false);
        // Check if there are any excluded variables
        if (excludedVars != null && !excludedVars.isEmpty()) {
            List<String> varNames = new ArrayList<String>();
            // Step through each variable in the list of excluded variables
            for (Variable var : excludedVars) {
                // Add the variable name with path to the list
                varNames.add(var.getFullName());
            }
            // Make each variable in the excluded variables list unavailable in the variable
            // tree
            schedulerHndlr.setVariableUnavailable(varNames);
        }
    }
    // Copy the current messages for change comparison purposes
    copyMessages();
}
Also used : Variable(CCDD.CcddClassesDataTable.Variable) Message(CCDD.CcddClassesDataTable.Message) ArrayList(java.util.ArrayList)

Example 19 with Variable

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

the class CcddSchedulerEditorHandler method removeSelectedVariable.

/**
 ********************************************************************************************
 * Remove the selected variable(s). This will remove it from any other messages the variable is
 * in. If the variable is a member of a link it removes all the other link member variables as
 * well
 *
 * @return List of variable names removed
 ********************************************************************************************
 */
protected List<String> removeSelectedVariable() {
    List<String> removedVarNames = new ArrayList<String>();
    List<String> selectedVars = null;
    // Check if this is a telemetry scheduler
    if (schedulerHndlr.getSchedulerOption() == TELEMETRY_SCHEDULER) {
        // Get the selected variable(s)
        selectedVars = assignmentTree.getSelectedVariables();
    } else // Check if this is a application scheduler
    if (schedulerHndlr.getSchedulerOption() == APPLICATION_SCHEDULER) {
        // Get the selected variable(s)
        selectedVars = assignmentList.getSelectedValuesList();
    }
    // Check if an item is selected and that the selected value is not the empty message value
    if (selectedVars != null && !selectedVars.isEmpty() && !selectedVars.get(0).equals(MESSAGE_EMPTY)) {
        // Row of selected variable. Convert the row index to view coordinates in case the
        // Scheduler table is sorted
        int row = schedulerTable.convertRowIndexToModel(schedulerTable.getSelectedRow());
        // List of variables to be removed
        List<Variable> removedVars = new ArrayList<Variable>();
        // Step through each selected variable
        for (String selectedVar : selectedVars) {
            // Variable object to be returned
            Variable variable = messages.get(row).getVariable(selectedVar);
            // Check if the selected variable hasn't already been added to removed list
            if (variable != null && !removedVars.contains(variable)) {
                // Check to see if the variable is linked
                if (variable.getLink() != null) {
                    // Add all the variables in the link to the removed list
                    for (Variable packetVar : messages.get(row).getVariables()) {
                        // Check if the variable is in the link of the selected item
                        if (packetVar.getLink() != null && packetVar.getLink().equals(variable.getLink())) {
                            // Add the variable to the removed list
                            removedVars.add(packetVar);
                        }
                    }
                } else // The variable is not in a link; add the selected variable to the removed
                // variables list
                {
                    // Add the variable to the list of removed variables
                    removedVars.add(variable);
                }
            }
        }
        // Remove the variables in the list from the message
        removedVarNames = removeVariablesFromMessages(removedVars, row);
        // Check if this is a telemetry scheduler
        if (schedulerHndlr.getSchedulerOption() == TELEMETRY_SCHEDULER) {
            // Update the assignment definition list for when the assignment tree is rebuilt
            assignmentTree.updateAssignmentDefinitions(messages, schedulerHndlr.getRateName());
        }
        // Calculate the bytes remaining in the messages
        calculateTotalBytesRemaining();
        // Update the remaining bytes column values
        updateRemainingBytesColumn();
        // Update the package list to the new message's variables
        updateAssignmentList();
    }
    return removedVarNames;
}
Also used : Variable(CCDD.CcddClassesDataTable.Variable) ArrayList(java.util.ArrayList)

Example 20 with Variable

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

the class CcddSchedulerEditorHandler method copyMessages.

/**
 ********************************************************************************************
 * Copy the specified (sub-)messages to the specified copy location
 *
 * @param messageList
 *            list of (sub-)messages to copy
 *
 * @param copyList
 *            reference to the list to which to copy the (sub-)messages
 *
 * @param parentMessage
 *            parent of the sub-message; null if this is not a sub-message
 ********************************************************************************************
 */
private void copyMessages(List<Message> messageList, List<Message> copyList, Message parentMessage) {
    // Step through each (sub-)message
    for (Message message : messageList) {
        // Create and store a copy of the (sub-)message
        copyList.add(new Message(message.getName(), message.getID(), message.getBytesRemaining(), parentMessage, parentMessage == null ? new ArrayList<Message>() : null));
        // Step through each variable in the (sub-)message
        for (Variable variable : message.getVariables()) {
            Variable copyVar = null;
            // Check if this is a telemetry scheduler
            if (schedulerHndlr.getSchedulerOption() == TELEMETRY_SCHEDULER) {
                TelemetryData tlmData = (TelemetryData) variable;
                // Create a copy of the telemetry data
                copyVar = VariableGenerator.generateTelemetryData(tlmData.getRate() + TLM_SCH_SEPARATOR + tlmData.getFullName());
            } else // Check if this is an application scheduler
            if (schedulerHndlr.getSchedulerOption() == APPLICATION_SCHEDULER) {
                ApplicationData appData = (ApplicationData) variable;
                // Create a copy of the application data
                copyVar = VariableGenerator.generateApplicationData(appData.getFullName() + "," + appData.getRate() + "," + appData.getSize() + "," + appData.getPriority() + "," + appData.getMessageRate() + "," + appData.getWakeUpID() + "," + appData.getWakeUpName() + "," + appData.getHkSendRate() + "," + appData.getHkWakeUpID() + "," + appData.getHkWakeUpName() + "," + appData.getSchGroup());
            }
            // Check if a copy was produced
            if (copyVar != null) {
                // Add the variable to the copy
                copyList.get(copyList.size() - 1).addVariable(copyVar);
            }
        }
    }
}
Also used : Variable(CCDD.CcddClassesDataTable.Variable) Message(CCDD.CcddClassesDataTable.Message) ApplicationData(CCDD.CcddClassesDataTable.ApplicationData) TelemetryData(CCDD.CcddClassesDataTable.TelemetryData)

Aggregations

Variable (CCDD.CcddClassesDataTable.Variable)23 ArrayList (java.util.ArrayList)17 Message (CCDD.CcddClassesDataTable.Message)8 AssociatedVariable (CCDD.CcddClassesDataTable.AssociatedVariable)6 ApplicationData (CCDD.CcddClassesDataTable.ApplicationData)5 TelemetryData (CCDD.CcddClassesDataTable.TelemetryData)3 DataStream (CCDD.CcddClassesDataTable.DataStream)2 FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)2 SchedulerType (CCDD.CcddConstants.SchedulerType)2 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)1 ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)1 BitPackNodeIndex (CCDD.CcddClassesDataTable.BitPackNodeIndex)1 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)1 RateInformation (CCDD.CcddClassesDataTable.RateInformation)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 List (java.util.List)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1