use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.
the class CcddRateParameterHandler method getRateParameters.
/**
********************************************************************************************
* Get the rate parameters from the database and calculate the sample rates
********************************************************************************************
*/
private void getRateParameters() {
// Build the rate information list from the table types
setRateInformation();
// Get the rate parameters from the database
String[] rateValues = dbTable.queryTableComment(InternalTable.TLM_SCHEDULER.getTableName(), ccddMain.getMainFrame());
try {
// Check if the number of rate parameters is invalid
if (rateValues.length < 3 || (rateValues.length - 3) % 4 != 0) {
throw new Exception("missing rate value");
}
// Convert the rate parameters to integers and set the flag for whether or not unevenly
// time-spaced rates should be included
maxSecPerMsg = Integer.valueOf(rateValues[RateParameter.MAXIMUM_SECONDS_PER_MESSAGE.ordinal()]);
maxMsgsPerSec = Integer.valueOf(rateValues[RateParameter.MAXIMUM_MESSAGES_PER_SECOND.ordinal()]);
includeUneven = Boolean.valueOf(rateValues[RateParameter.INCLUDE_UNEVEN_RATES.ordinal()]);
// Check if any of the values are less than 1
if (maxSecPerMsg <= 0 || maxMsgsPerSec <= 0) {
throw new Exception("zero or negative rate value");
}
// Get the number of stream-specific parameters per rate column
int numStreamParms = RateParameter.values().length - 3;
// Step through each stream
for (int index = numStreamParms; index < rateValues.length; index += numStreamParms) {
int offset = index - numStreamParms;
// Remove the leading and trailing quotes from the rate column name
String rateColName = rateValues[RateParameter.RATE_COLUMN_NAME.ordinal() + offset].replaceAll("^\"(.*)\"$", "$1");
// Get the rate information for this rate column
RateInformation rateInfo = getRateInformationByRateName(rateColName);
// Check if the rate information for this column exists
if (getRateInformationByRateName(rateColName) != null) {
// Remove the leading and trailing quotes from the stream name
String streamName = rateValues[RateParameter.STREAM_NAME.ordinal() + offset].replaceAll("^\"(.*)\"$", "$1");
// Convert the rate parameters to integers
int maxMsgsPerCycle = Integer.valueOf(rateValues[RateParameter.MAXIMUM_MESSAGES_PER_CYCLE.ordinal() + offset]);
int maxBytesPerSec = Integer.valueOf(rateValues[RateParameter.MAXIMUM_BYTES_PER_SECOND.ordinal() + offset]);
// Check if any of the values are less than 1
if (maxMsgsPerCycle <= 0 || maxBytesPerSec <= 0) {
throw new Exception("zero or negative rate value");
}
// Update the rate information
rateInfo.setStreamName(streamName);
rateInfo.setMaxMsgsPerCycle(maxMsgsPerCycle);
rateInfo.setMaxBytesPerSec(maxBytesPerSec);
}
}
} catch (Exception e) {
// Inform the user that calculating the rate parameters failed
ccddMain.getSessionEventLog().logFailEvent(ccddMain.getMainFrame(), "Rate Parameter Error", "Invalid rate parameter(s): using default values instead; cause '" + e.getMessage() + "'", "<html><b>Invalid rate parameter(s): using default values instead");
// Use default values
maxSecPerMsg = 1;
maxMsgsPerSec = 1;
includeUneven = false;
// Step through each stream
for (int rateIndex = 0; rateIndex < rateInformation.size(); rateIndex++) {
// Use default values
rateInformation.get(rateIndex).setDefaultValues();
}
// Store the default rate parameters in the project database
dbTable.storeRateParameters(ccddMain.getMainFrame());
}
// Calculate the sample rates from the rate parameter values
calculateSampleRates();
}
use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.
the class CcddSchedulerHandler method createDualScrollPanelwithButtons.
/**
********************************************************************************************
* Create dual scroll panels
*
* @return Split pane containing the dual panels
********************************************************************************************
*/
@SuppressWarnings("serial")
private JSplitPane createDualScrollPanelwithButtons() {
// Create an empty border
Border emptyBorder = BorderFactory.createEmptyBorder();
// 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(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0);
// Create the scheduler input (variables or applications) handler
schedulerInput = schedulerDlg.createSchedulerInput(rateName);
int totalMsgs = 0;
int totalBytes = 0;
int msgsPerSec = 0;
// Get the scheduler dialog type
SchedulerType option = getSchedulerOption();
// Check if this is the telemetry scheduler
if (option == SchedulerType.TELEMETRY_SCHEDULER) {
// Get the information for the rate
RateInformation info = rateHandler.getRateInformationByRateName(rateName);
// Get the rate parameters
totalMsgs = info.getMaxMsgsPerCycle();
totalBytes = info.getMaxBytesPerSec();
msgsPerSec = rateHandler.getMaxMsgsPerSecond();
} else // Check if this is an application scheduler
if (option == SchedulerType.APPLICATION_SCHEDULER) {
// Set the total number of messages to the largest rate
totalMsgs = appHandler.getMsgsPerCycle();
// Set messages per second to highest to ensure the cycle time is 1 second
msgsPerSec = appHandler.getMaxMsgsPerSecond();
totalBytes = (int) ((Float.valueOf(totalMsgs) / Float.valueOf(msgsPerSec)) * 1000);
}
// Create the scheduler editor handler
schedulerEditor = new CcddSchedulerEditorHandler(ccddMain, this, totalMsgs, totalBytes, msgsPerSec);
// Create the options model
optionModel = new DefaultListModel<String>();
// Set the cycle value label to the period
cycleFld.setText(String.valueOf(Float.valueOf(totalMsgs) / Float.valueOf(msgsPerSec)));
// Create panels to hold the components
JPanel packPnl = new JPanel(new GridBagLayout());
JPanel rateSelectPnl = new JPanel(new GridBagLayout());
JPanel optionPnl = new JPanel(new GridBagLayout());
packPnl.setBorder(emptyBorder);
rateSelectPnl.setBorder(emptyBorder);
optionPnl.setBorder(emptyBorder);
// Create the options label and add it to the rate panel
JLabel optionLbl = new JLabel("Options");
optionLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
optionLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
optionPnl.add(optionLbl, gbc);
// Create the rate label and add it to the rate panel
JLabel rateSelectLbl = new JLabel("Rate Filter ");
rateSelectLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
rateSelectLbl.setForeground(ModifiableColorInfo.LABEL_TEXT.getColor());
gbc.weighty = 1.0;
gbc.gridx++;
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
rateSelectPnl.add(rateSelectLbl, gbc);
// Create the combo box that displays the variable rates
rateFilter = new PaddedComboBox(schedulerInput.getAvailableRates(), ModifiableFontInfo.INPUT_TEXT.getFont()) {
/**
************************************************************************************
* Override so that items flagged as disabled (grayed out) can't be selected. Only the
* telemetry scheduler makes use of this; it has no effect on the application scheduler
************************************************************************************
*/
@Override
public void setSelectedItem(Object anObject) {
// Check if the item isn't flagged as disabled
if (!anObject.toString().startsWith(DISABLED_TEXT_COLOR)) {
// Set the selected item to the specified item, if it exists in the list
super.setSelectedItem(anObject);
}
}
};
rateFilter.setBorder(emptyBorder);
rateFilter.setSelectedItem(schedulerInput.getSelectedRate());
// Add a listener for rate filter selection changes
rateFilter.addActionListener(new ActionListener() {
/**
************************************************************************************
* Rebuild the table tree using the selected rate filter
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Get the rate selected in the combo box
String rate = ((JComboBox<?>) ae.getSource()).getSelectedItem().toString();
// Update the variable tree to display variables with the given rate
schedulerInput.updateVariableTree(rate);
// Set the options panel to display the options for the selected rate
getTelemetryOptions();
}
});
// Add the rate filter to the rate panel
gbc.gridx++;
rateSelectPnl.add(rateFilter, gbc);
// Create a list that will contain all the telemetry options for a variable
optionList = new JList<String>(optionModel);
optionList.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
optionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// Add a listener to set the message availability given the selected option
optionList.addListSelectionListener(new ListSelectionListener() {
/**
************************************************************************************
* Handle a selection change
************************************************************************************
*/
@Override
public void valueChanged(ListSelectionEvent listSelectionEvent) {
// Update the scheduler table text highlighting
updateSchedulerTableHighlight();
}
});
// Add the list to a scroll pane that will be placed next to the variable list
JScrollPane optionScroll = new JScrollPane(optionList);
optionScroll.setBorder(border);
// Set the preferred width of the tree's scroll pane
optionScroll.setPreferredSize(new Dimension(Math.min(Math.max(optionScroll.getPreferredSize().width, 200), 200), optionScroll.getPreferredSize().height));
// Set the minimum size to the preferred size
optionScroll.setMinimumSize(optionScroll.getPreferredSize());
// Add the option scroll pane to the option panel
gbc.insets.top = 0;
gbc.insets.bottom = 0;
gbc.gridx = 0;
gbc.gridy++;
optionPnl.add(optionScroll, gbc);
// Add the rate selection panel to the option panel
gbc.gridy++;
gbc.weighty = 0.0;
gbc.fill = GridBagConstraints.NONE;
optionPnl.add(rateSelectPnl, gbc);
// Add the option panel to the pack panel
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridy = 0;
gbc.gridx++;
packPnl.add(optionPnl, gbc);
// Create the split pane containing the input tree and options panel
JSplitPane leftSpltPn = new CustomSplitPane(schedulerInput.getInputPanel(), packPnl, null, JSplitPane.HORIZONTAL_SPLIT);
// Create the split pane containing the left split pane and the split pane containing the
// scheduler and assignment tree/list. Use the arrow button panel as the split pane divider
JSplitPane allSpltPn = new CustomSplitPane(leftSpltPn, schedulerEditor.getSchedulerAndAssignPanel(), createArrowButtonPanel(), JSplitPane.HORIZONTAL_SPLIT);
// Set the options list to display the starting rate value
getTelemetryOptions();
return allSpltPn;
}
use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.
the class CcddScriptDataAccessHandler method getLinkDescription.
/**
********************************************************************************************
* Get the description of the specified link
*
* @param streamName
* data stream name
*
* @param linkName
* link name
*
* @return Link description; returns a blank if the data stream or link don't exist, or the
* link has no description
********************************************************************************************
*/
public String getLinkDescription(String streamName, String linkName) {
String description = "";
// Get the rate information based on the supplied data stream name
RateInformation rateInfo = rateHandler.getRateInformationByStreamName(streamName);
// Check if the rate information exists with this stream name
if (rateInfo != null) {
// Get the link description based on the rate column and link names
description = linkHandler.getLinkDescription(rateInfo.getRateName(), linkName);
}
return description;
}
use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.
the class CcddWebDataAccessHandler method getTelemetrySchedulerData.
/**
********************************************************************************************
* Get the telemetry scheduler's copy table entries
*
* @param parameters
* comma-separated string containing the data stream name, header size (in bytes),
* message ID name data field name, and the optimize result flag ('true' or 'false')
*
* @return JSON encoded string containing the specified copy table entries; null if the number
* of parameters or their formats are incorrect
*
* @throws CCDDException
* If an error occurs while parsing the telemetry scheduler data
********************************************************************************************
*/
@SuppressWarnings("unchecked")
private String getTelemetrySchedulerData(String parameters) throws CCDDException {
String response = null;
// Separate the input parameters
String[] parameter = getParts(parameters, ",", 4, true);
// Check if all the input parameters are present and that they're in the expected formats
if (parameter[1].matches("\\d+") && parameter[3].matches(TRUE_OR_FALSE)) {
JSONArray tableJA = new JSONArray();
// Get the individual parameters and format them if needed
String streamName = parameter[0];
int headerSize = Integer.valueOf(parameter[1]);
String messageIDNameField = parameter[2];
boolean optimize = Boolean.valueOf(parameter[3]);
// Get the rate information based on the supplied data stream name
RateInformation rateInfo = rateHandler.getRateInformationByStreamName(streamName);
// Check if the rate information doesn't exist with this stream name
if (rateInfo == null) {
throw new CCDDException("unknown data stream name");
}
// Create an instance of the copy table handler in order to read the information from
// the database
CcddCopyTableHandler copyHandler = new CcddCopyTableHandler(ccddMain);
// Create the copy table entries based on the supplied parameters
String[][] copyTable = copyHandler.createCopyTable(new CcddFieldHandler(ccddMain, null, ccddMain.getMainFrame()), new CcddLinkHandler(ccddMain, ccddMain.getMainFrame()), rateInfo.getStreamName(), headerSize, messageIDNameField, null, optimize, isReplaceMacro);
// Check if there are any entries in the table
if (copyTable.length != 0) {
// Step through each row in the table
for (String[] row : copyTable) {
JSONObject rowJO = new JSONObject();
// Step through each column in the row
for (int column = 0; column < row.length; column++) {
// Add the copy table value to the array. An array is used to preserve the
// order of the items
rowJO.put(CopyTableEntry.values()[column].getColumnName(), row[column]);
}
// Add the row's copy table values to the table array
tableJA.add(rowJO);
}
}
// Store the copy table information
JSONObject copyJO = new JSONObject();
copyJO.put(JSONTags.COPY_TABLE_STREAM.getTag(), streamName);
copyJO.put(JSONTags.COPY_TABLE_HDR_SIZE.getTag(), String.valueOf(headerSize));
copyJO.put(JSONTags.COPY_TABLE_OPTIMIZE.getTag(), String.valueOf(optimize));
copyJO.put(JSONTags.COPY_TABLE_DATA.getTag(), tableJA);
response = copyJO.toString();
} else // Invalid parameter format
{
throw new CCDDException("parameter type mismatch");
}
return response;
}
use of CCDD.CcddClassesDataTable.RateInformation in project CCDD by nasa.
the class CcddLinkHandler method getVariableLinks.
/**
********************************************************************************************
* Return an array of rate and link names to which the specified variable belongs
*
* @param variable
* variable path and name
*
* @param useDataStream
* true to return the data stream name in place of the rate column name
*
* @return Array containing the rates and links to which the specified variable is a member; an
* empty array if the variable does not belong to a link
********************************************************************************************
*/
protected String[][] getVariableLinks(String variable, boolean useDataStream) {
List<String[]> links = new ArrayList<String[]>();
// Step through each link definition
for (String[] linkDefn : linkDefinitions) {
// Extract the rate name, link name, and rate/description or member
String rateName = linkDefn[LinksColumn.RATE_NAME.ordinal()];
String linkName = linkDefn[LinksColumn.LINK_NAME.ordinal()];
String linkMember = linkDefn[LinksColumn.MEMBER.ordinal()];
// target variable
if (!linkMember.matches("\\d.*") && macroHandler.getMacroExpansion(variable).equals(macroHandler.getMacroExpansion(linkMember))) {
// Check if the data stream name should be returned instead of the rate column name
if (useDataStream) {
// Get the rate information based on the rate column name
RateInformation rateInfo = ccddMain.getRateParameterHandler().getRateInformationByRateName(rateName);
// Check if the rate information exists for this rate column
if (rateInfo != null) {
// Substitute the data stream name for the rate column name
rateName = rateInfo.getStreamName();
}
}
// Add the link to the list
links.add(new String[] { rateName, linkName });
}
}
return links.toArray(new String[0][0]);
}
Aggregations