use of CCDD.CcddClassesDataTable.Variable in project CCDD by nasa.
the class CcddSchedulerEditorHandler method clearVariablesFromMessages.
/**
********************************************************************************************
* Remove the variables (applications) assigned to the messages (time slots)
*
* @param rateFilter
* rate of the variables to removed from the telemetry messages; null to remove all
* variables. Not used for the application scheduler
********************************************************************************************
*/
protected void clearVariablesFromMessages(String rateFilter) {
String type;
String text;
// Check if this is the telemetry scheduler
if (schedulerHndlr.getSchedulerOption() == TELEMETRY_SCHEDULER) {
type = "Variables";
text = rateFilter == null ? "all variables from messages" : "variables of rate " + rateFilter + " from messages";
} else // This is the application scheduler
{
type = "Applications";
text = "all applications from time slots";
}
boolean isVariable = false;
// Step through each message (time slot) in the stream
for (Message msg : getCurrentMessages()) {
// Check if a variable (application) exists in the message
if (!msg.getAllVariables().isEmpty()) {
// Set the flag indicating a variable (application)exists and stop searching
isVariable = true;
break;
}
}
// resetting the messages (time slots)
if (isVariable && new CcddDialogHandler().showMessageDialog(schedulerHndlr.getSchedulerDialog().getDialog(), "<html><b>Remove " + text + "?", "Remove " + type, JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Create lists for the variables and the variables that are removed
List<Variable> allVarsRemoved = new ArrayList<Variable>();
List<Variable> msgVarsRemoved = new ArrayList<Variable>();
float rate = 0;
// Check if a rate filter is to be applied
if (rateFilter != null) {
// Convert the rate to a floating point value
rate = CcddUtilities.convertStringToFloat(rateFilter);
}
// Step through each message
for (int msgIndex = 0; msgIndex < messages.size(); msgIndex++) {
// Step through each variable assigned to this message
for (Variable variable : messages.get(msgIndex).getAllVariables()) {
// variable's rate matches the rate filter
if (rateFilter == null || rate == variable.getRate()) {
// Add the variable to the list of those to be removed from the message
msgVarsRemoved.add(variable);
}
}
// Remove the variables from the messages
removeVariablesFromMessages(msgVarsRemoved, msgIndex);
// Add the message's removed variables to the list of all removed variables
allVarsRemoved.addAll(msgVarsRemoved);
// Clear the removed variables list for the next pass
msgVarsRemoved.clear();
}
// 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 assignment tree/list
updateAssignmentList();
// Create an included variables (applications) list
List<String> includedVars = new ArrayList<String>();
// Step through each variable (application) in the removed variable (application) list
for (Variable variable : allVarsRemoved) {
// Add each name to the list of included variables (applications)
includedVars.add(variable.getFullName());
}
// Include the variables (applications) back in the variable (application) tree
schedulerHndlr.makeVariableAvailable(includedVars);
// Set the unused bytes field
schedulerHndlr.setUnusedField();
// Update the scheduler dialog's change indicator
schedulerHndlr.getSchedulerDialog().updateChangeIndicator();
}
}
use of CCDD.CcddClassesDataTable.Variable in project CCDD by nasa.
the class CcddSchedulerEditorHandler method removeVariablesFromMessages.
/**
********************************************************************************************
* Remove the specified variable(s) from all messages it is contained in
*
* @param variables
* list of variables to remove
*
* @param row
* message row index
*
* @return List of the variable names removed
********************************************************************************************
*/
private List<String> removeVariablesFromMessages(List<Variable> variables, int row) {
List<Integer> msgIndices;
List<String> removedVarNames = new ArrayList<String>();
// Step through the variable list
for (Variable variable : variables) {
// Add the variable path and name to the list of those removed
removedVarNames.add(variable.getFullName());
// Check if the variable is in a sub-message
if (variable.getRate() < (1 / period)) {
// Remove it from a general message
messages.get(row).removeVariable(variable.getFullName());
} else // Variable is not in a sub-message
{
// Assign the message indices
msgIndices = variable.getMessageIndices();
// Step through all the messages the variable is contained in
for (int msgIndex : msgIndices) {
// Remove it from a general message
messages.get(msgIndex).removeVariable(variable.getFullName());
}
}
}
return removedVarNames;
}
use of CCDD.CcddClassesDataTable.Variable in project CCDD by nasa.
the class CcddSchedulerEditorHandler method isMessageChanged.
/**
********************************************************************************************
* Compare the current (sub-)message to the committed (sub-)message to detect any changes
*
* @param currMsg
* reference to the message's current values
*
* @param commMsg
* reference to the message's original values
*
* @return true if the (sub-)message's content changed; false if no change exists
********************************************************************************************
*/
private boolean isMessageChanged(Message currMsg, Message commMsg) {
boolean isChanged = false;
// Get the list of variables for the current and committed messages
List<Variable> currVars = currMsg.getVariables();
List<Variable> commVars = commMsg.getVariables();
// sub-messages changed
if (currMsg.getBytesRemaining() != commMsg.getBytesRemaining() || !currMsg.getName().equals(commMsg.getName()) || !currMsg.getID().equals(commMsg.getID()) || currVars.size() != commVars.size() || currMsg.getNumberOfSubMessages() != commMsg.getNumberOfSubMessages()) {
isChanged = true;
} else // The message's number of bytes, name, number of variables, or number of sub-messages is
// the same
{
// Step through each variable
for (int varIndex = 0; varIndex < currVars.size(); varIndex++) {
// Get a reference to the current and committed variable to make subsequent calls
// shorter
Variable currVar = currVars.get(varIndex);
Variable commVar = commVars.get(varIndex);
// rate changed
if (currVar.getSize() != commVar.getSize() || !currVar.getFullName().equals(commVar.getFullName()) || currVar.getRate() != commVar.getRate()) {
// Set the flag indicating a change and stop searching
isChanged = true;
break;
}
}
}
return isChanged;
}
use of CCDD.CcddClassesDataTable.Variable in project CCDD by nasa.
the class CcddCopyTableHandler method createCopyTable.
/**
********************************************************************************************
* Create a copy table based on the message definitions
*
* @param fieldHandler
* field handler reference
*
* @param linkHandler
* link handler reference
*
* @param dataStreamName
* data stream name
*
* @param headerSize
* size of the packet header in bytes
*
* @param messageIDNameField
* name of the structure table data field containing the message ID name. If
* provided this is used instead of the tlmMessageIDs list
*
* @param tlmMessageIDs
* list containing string array entries giving the structure table path+name and the
* table's associated message ID name. Used if messageIDNameField is null
*
* @param optimize
* true to create copy table with memory copies optimized
*
* @param expandMacros
* true to expand any macro within the variable names
*
* @return Array containing the copy table entries
********************************************************************************************
*/
protected String[][] createCopyTable(CcddFieldHandler fieldHandler, CcddLinkHandler linkHandler, String dataStreamName, int headerSize, String messageIDNameField, ArrayListMultiple tlmMessageIDs, boolean optimize, boolean expandMacros) {
List<String[]> messageTable = new ArrayList<String[]>();
// Empty the copy table in case a previous one exists
copyTable.clear();
// Step through each message for the specified rate
for (Message message : getStoredMessages(dataStreamName)) {
// Step through the message's sub-messages
for (Message subMsg : message.getSubMessages()) {
// Step through each packet definition
for (Variable variable : subMsg.getVariablesWithParent()) {
String tlmMsgID = null;
// Split the packet definition's variable string into the parent structure name
// and variable reference string
String[] parentAndPath = variable.getFullName().split(",", 2);
// Check if macro in the variable names are to be expanded
if (expandMacros) {
// Replace any macros with their corresponding values
parentAndPath[1] = macroHandler.getMacroExpansion(parentAndPath[1]);
}
// Get the offset in the root structure of the variable indicated by the packet
// definition
int structureOffset = variableHandler.getVariableOffset(variable.getFullName());
// Check if the message ID name field name is provided
if (messageIDNameField != null) {
// Get the field information for the message ID name field
FieldInformation msgIDNameFieldInfo = fieldHandler.getFieldInformationByName(parentAndPath[0], messageIDNameField);
// Check that the message ID name field exists for the specified table
if (msgIDNameFieldInfo != null) {
// Get the message ID name associated with the table
tlmMsgID = msgIDNameFieldInfo.getValue();
}
} else // Check if the telemetry message ID names list is provided
if (tlmMessageIDs != null) {
// Get the index of the table in the list provided
int index = tlmMessageIDs.indexOf(parentAndPath[0]);
// Check if the table exists in the list
if (index != -1) {
// Get the message ID name associated with the table
tlmMsgID = tlmMessageIDs.get(index)[1];
}
}
if (tlmMsgID != null) {
// Build the copy table entry array for this variable. The fields are:
// Input message ID name, input offset, output message ID name (the
// sub-message separator character, a period, is replaced with an
// underscore), output offset (initialized to a blank; the value is
// computed later), variable size, variable root table, and variable path
messageTable.add(new String[] { tlmMsgID, String.valueOf(structureOffset), subMsg.getName().replace(".", "_"), "", String.valueOf(variable.getSize()), parentAndPath[0], parentAndPath[1] });
}
}
// Consolidate the bit-packed variables
combineBitPackedVariables(messageTable);
// Check if this copy table should be optimized
if (optimize) {
// Combine consecutive memory copies
combineMemoryCopies(messageTable);
}
// Add the input and output offset to the list
addInputAndOutputOffset(messageTable, headerSize);
// Add this message's copy table entries to the list of all copy table entries
copyTable.addAll(messageTable);
// Clear out this message's entries to allow storage for the next message
messageTable.clear();
}
}
return copyTable.toArray(new String[0][0]);
}
use of CCDD.CcddClassesDataTable.Variable in project CCDD by nasa.
the class CcddSchedulerHandler method autoFill.
/**
********************************************************************************************
* Automatically fill the variables/applications in messages/time slots corresponding to their
* rate
********************************************************************************************
*/
protected void autoFill() {
canceled = false;
cancelDialog = new HaltDialog();
progBar = new JProgressBar();
progress = 0;
// Create the panel to contain the progress/cancellation dialog components
final JPanel dialogPnl = new JPanel(new GridBagLayout());
// Get the scheduler dialog type
final SchedulerType schedulerType = getSchedulerOption();
// Get the text that describes the type of object being assigned
final String variableType = schedulerType == SchedulerType.TELEMETRY_SCHEDULER ? "variables" : (schedulerType == SchedulerType.APPLICATION_SCHEDULER ? "applications" : "unknown");
// Create a thread to perform the auto-fill operation in the background
final Thread progressThread = new Thread(new Runnable() {
/**
************************************************************************************
* Auto-fill the telemetry messages (if this is the telemetry scheduler) or application
* time slots (if this is the application scheduler). Note that in the comments below
* 'variable' is used to describe the object being assigned, which is accurate for the
* telemetry scheduler. For the application scheduler substitute 'application' for
* 'variable'
************************************************************************************
*/
@Override
public void run() {
int numVariables = 0;
int unassigned = 0;
// Get an array of the available rates
String[] availableRates = schedulerInput.getAvailableRates();
// variables at each rate until no more rates are available
for (String rate : availableRates) {
// out using HTML tags
if (!rate.startsWith("<html>")) {
// Check if this is a telemetry scheduler
if (schedulerType == SchedulerType.TELEMETRY_SCHEDULER) {
// Get the reference to the variable tree in order to shorten the
// subsequent call
CcddTableTreeHandler variableTree = ((CcddTelemetrySchedulerInput) schedulerInput).getVariableTree();
// Add the number of unassigned variables at the given rate.
// getVariablesAtRate() could be used, but it performs other operations
// associated with links and is slower
numVariables += variableTree.getPrimitiveVariablePaths(variableTree.getRootNode(), true).size();
} else // Check if this is an application scheduler
if (schedulerType == SchedulerType.APPLICATION_SCHEDULER) {
// Add the number of unassigned applications at the given rate
numVariables += schedulerInput.getVariablesAtRate(rate).size();
}
}
}
// Check if there are any variables to assign
if (numVariables != 0) {
// Update the progress bar now that the number of variables is known
progBar.setMaximum(numVariables);
progBar.setIndeterminate(false);
// Total size of the variable or link
int totalSize;
// Message option to which the variable or link will be added
String option;
// Variable that will be added
Variable variable;
// Variables that will be removed from the remaining list
List<Variable> removedVars = new ArrayList<Variable>();
// List of variables at a given rate
List<Variable> varList;
// List of the variables to exclude from the Variables tree. This should be all
// of the variables unless there are any that can't be assigned
List<String> excludedVars = new ArrayList<String>();
// variables at each rate until no more rates are available
for (String rate : availableRates) {
// Check if the user canceled auto-fill
if (canceled) {
break;
}
// grayed out using HTML tags
if (!rate.startsWith("<html>")) {
// Show the current rate being processed in the progress bar
progBar.setString("Assigning " + rate + " Hz " + variableType);
// Get the rate as a floating point value
float rateVal = CcddUtilities.convertStringToFloat(rate);
// Get a list of all variables at the given rate (ones already assigned
// are not included)
varList = schedulerInput.getVariablesAtRate(rate);
// Sort the list from largest to smallest
Collections.sort(varList);
// Loop through the list of variables until all are removed
while (!varList.isEmpty()) {
// Check if the user canceled padding adjustment
if (canceled) {
break;
}
// Total size of the variable or link
totalSize = 0;
// Set to the first variable in the list
variable = varList.get(0);
// Check if the variable is linked
if (variable.getLink() != null) {
// Step through each variable in the variable list
for (Variable linkVar : varList) {
// variable
if (linkVar.getLink() != null && linkVar.getLink().equals(variable.getLink())) {
// Add the variable's size to the total size
totalSize += variable.getSize();
// Add the variable to the list of removed variables
removedVars.add(linkVar);
}
}
} else // The variable is unlinked
{
// Check if this is a telemetry scheduler
if (schedulerType == SchedulerType.TELEMETRY_SCHEDULER) {
// Set total size to the given variable's size
totalSize = variable.getSize();
// Get the total size (in bytes) and the list of the
// variable, or variables if this variable is associated
// with others due to bit-packing or string membership and
// therefore must be placed together in a message
AssociatedVariable associates = ((CcddTelemetrySchedulerInput) schedulerInput).getAssociatedVariables(varList);
// Set the total size to that of the associated variable(s)
// and add the variable(s) to the list of those to be
// removed
totalSize = associates.getTotalSize();
removedVars.addAll(associates.getAssociates());
} else // This is an application (or unknown type of) scheduler
{
// Set total size to the given variable's size
totalSize = variable.getSize();
// Add the variable to the list of removed variables
removedVars.add(variable);
}
}
// Find the option with the most room
option = getMessageWithRoom(rateVal, totalSize);
// Check to make sure there is an option
if (option != null) {
// Parse the option string to extract the sub-index (if this is
// a sub-option) and the message indices
Object[] parsedIndices = parseOption(option);
// Add the variable to the given message. If a sub-index is not
// given it will be set to -1. Add the list of added variables
// to the list of those to exclude in the Variables tree
excludedVars.addAll(addVariableToMessage(removedVars, (Integer[]) parsedIndices[1], (int) parsedIndices[0]));
} else // No option is available
{
// Increment the unplaced variable counter
unassigned++;
}
// Remove all the variables in removed variables list. This
// includes variables that did not fit into the telemetry table
varList.removeAll(removedVars);
// Clear the removed variables list
removedVars.clear();
// Update the auto-fill progress
progBar.setValue(progress);
progress++;
}
}
}
// Check if the auto-fill operation wasn't canceled by the user
if (!canceled) {
// Close the auto-fill progress/cancellation dialog
cancelDialog.closeDialog(CANCEL_BUTTON);
}
// Perform any updates needed following adding variables to messages
updateAfterVariableAdded();
// Set the variable tree to exclude the variable(s)
setVariableUnavailable(excludedVars);
// Display the originally selected rate's variable tree
schedulerInput.updateVariableTree(rateFilter.getSelectedItem().toString());
// Update the remaining bytes column values
schedulerEditor.updateRemainingBytesColumn();
// Update the unused bytes/time field
setUnusedField();
// Update the assigned variables/applications list panel
schedulerEditor.updateAssignmentList();
// Update the scheduler dialog's change indicator
getSchedulerDialog().updateChangeIndicator();
// Check if there are items that are not assigned
if (unassigned != 0) {
// Inform the user if there are items that are not assigned
new CcddDialogHandler().showMessageDialog(schedulerDlg.getDialog(), "<html><b> Auto-fill unable to assign " + unassigned + " " + variableType, "Auto-fill", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
}
} else // There are no unassigned variables
{
// user
if (!canceled) {
// Close the auto-fill progress/cancellation dialog
cancelDialog.closeDialog(CANCEL_BUTTON);
}
new CcddDialogHandler().showMessageDialog(schedulerDlg.getDialog(), "<html><b>All " + variableType + " with a rate are already assigned", "Auto-fill", JOptionPane.INFORMATION_MESSAGE, DialogOption.OK_OPTION);
}
}
});
// Execute the command in the background
CcddBackgroundCommand.executeInBackground(ccddMain, schedulerDlg.getDialog(), new BackgroundCommand() {
/**
************************************************************************************
* Build and display the auto-fill progress/cancellation dialog. This is done as a
* background operation so that the
************************************************************************************
*/
@Override
protected void execute() {
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()), 0, 0);
// Build the progress/cancellation dialog
dialogPnl.setBorder(BorderFactory.createEmptyBorder());
JLabel textLbl = new JLabel("<html><b>Assigning " + variableType + "...</b><br><br>", SwingConstants.LEFT);
textLbl.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
gbc.gridy++;
dialogPnl.add(textLbl, gbc);
JLabel textLbl2 = new JLabel("<html><b>" + CcddUtilities.colorHTMLText("*** Press </i>Halt<i> " + "to terminate auto-fill ***", Color.RED) + "</b><br><br>", SwingConstants.CENTER);
textLbl2.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
gbc.gridy++;
dialogPnl.add(textLbl2, gbc);
// Add a progress bar to the dialog
progBar.setIndeterminate(true);
progBar.setMinimum(0);
progBar.setValue(0);
progBar.setString("Calculating number of variables");
progBar.setStringPainted(true);
progBar.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() * 2;
gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() * 2;
gbc.insets.bottom = 0;
gbc.gridy++;
dialogPnl.add(progBar, gbc);
// the dialog if there are no variables to assign
if (!canceled) {
// Display the auto-fill progress/cancellation dialog
cancelDialog.showOptionsDialog(schedulerDlg.getDialog(), dialogPnl, "Auto-fill " + (schedulerType == SchedulerType.TELEMETRY_SCHEDULER ? "Telemetry Messages" : (schedulerType == SchedulerType.APPLICATION_SCHEDULER ? "Time Slots" : "")), DialogOption.HALT_OPTION, false, true);
}
}
});
// Perform the auto-fill operation in a background thread
progressThread.start();
}
Aggregations