use of org.yamcs.protobuf.Mdb.ArgumentInfo in project yamcs-studio by yamcs.
the class ImportCommandStackHandler method parseCommandStack.
public List<StackedCommand> parseCommandStack(String fileName) {
try {
final JAXBContext jc = JAXBContext.newInstance(org.yamcs.studio.commanding.stack.xml.CommandStack.class);
final Unmarshaller unmarshaller = jc.createUnmarshaller();
final org.yamcs.studio.commanding.stack.xml.CommandStack commandStack = (org.yamcs.studio.commanding.stack.xml.CommandStack) unmarshaller.unmarshal(new FileReader(fileName));
List<StackedCommand> importedStack = new LinkedList<StackedCommand>();
for (CommandStack.Command c : commandStack.getCommand()) {
StackedCommand sc = new StackedCommand();
CommandInfo mc = CommandingCatalogue.getInstance().getCommandInfo(c.getQualifiedName());
if (mc == null) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Import Command Stack", "Command " + c.getQualifiedName() + " does not exist in MDB.");
return null;
}
sc.setMetaCommand(mc);
sc.setSelectedAliase(c.getSelectedAlias());
sc.setComment(c.getComment());
for (CommandArgument ca : c.getCommandArgument()) {
ArgumentInfo a = getArgumentFromYamcs(mc, ca.getArgumentName());
if (a == null) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Import Command Stack", "In command " + c.getQualifiedName() + ", argument " + ca.getArgumentName() + " does not exist in MDB.");
return null;
}
sc.addAssignment(a, ca.getArgumentValue());
}
importedStack.add(sc);
}
return importedStack;
} catch (Exception e) {
log.log(Level.SEVERE, "Unable to load command stack for importation. Check the XML file is correct. Details:\n" + e.toString());
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Import Command Stack", "Unable to load command stack for importation. Check the XML file is correct. Details:\n" + e.toString());
return null;
}
}
use of org.yamcs.protobuf.Mdb.ArgumentInfo in project yamcs-studio by yamcs.
the class StackedCommand method toStyledString.
public StyledString toStyledString(CommandStackView styleProvider) {
Styler identifierStyler = styleProvider != null ? styleProvider.getIdentifierStyler(this) : null;
Styler bracketStyler = styleProvider != null ? styleProvider.getBracketStyler(this) : null;
Styler argNameSyler = styleProvider != null ? styleProvider.getArgNameStyler(this) : null;
Styler errorStyler = styleProvider != null ? styleProvider.getErrorStyler(this) : null;
Styler numberStyler = styleProvider != null ? styleProvider.getNumberStyler(this) : null;
StyledString str = new StyledString();
str.append(getSelectedAlias(), identifierStyler);
str.append("(", bracketStyler);
boolean first = true;
for (ArgumentInfo arg : meta.getArgumentList()) {
String value = getAssignedStringValue(arg);
if (value == null && arg.hasInitialValue())
continue;
if (!first)
str.append("\n, ", bracketStyler);
first = false;
str.append(arg.getName() + ": ", argNameSyler);
if (value == null) {
str.append(" ", errorStyler);
} else {
boolean needQuotationMark = ArgumentTableBuilder.STRING.equals(arg.getType().getEngType()) || ArgumentTableBuilder.ENUM.equals(arg.getType().getEngType());
if (needQuotationMark)
str.append("\"", isValid(arg) ? numberStyler : errorStyler);
str.append(value, isValid(arg) ? numberStyler : errorStyler);
if (needQuotationMark)
str.append("\"", isValid(arg) ? numberStyler : errorStyler);
}
}
str.append(")", bracketStyler);
return str;
}
use of org.yamcs.protobuf.Mdb.ArgumentInfo in project yamcs-studio by yamcs.
the class StackedCommand method getEffectiveAssignments.
public Collection<TelecommandArgument> getEffectiveAssignments() {
// We want this to be top-down, as-defined in mdb
Map<String, TelecommandArgument> argumentsByName = new LinkedHashMap<>();
List<CommandInfo> hierarchy = new ArrayList<>();
hierarchy.add(meta);
CommandInfo base = meta;
while (base.getBaseCommand() != null) {
base = base.getBaseCommand();
hierarchy.add(0, base);
}
// From parent to child. Children can override initial values (= defaults)
for (CommandInfo cmd : hierarchy) {
// Set all values, even if null initial value. This gives us consistent ordering
for (ArgumentInfo argument : cmd.getArgumentList()) {
String name = argument.getName();
String value = argument.hasInitialValue() ? argument.getInitialValue() : null;
boolean editable = true;
argumentsByName.put(name, new TelecommandArgument(name, value, editable));
}
// TODO this should return an empty list in yamcs. Not null
if (cmd.getArgumentAssignmentList() != null)
for (ArgumentAssignmentInfo argumentAssignment : cmd.getArgumentAssignmentList()) {
String name = argumentAssignment.getName();
String value = argumentAssignment.getValue();
boolean editable = (cmd == meta);
argumentsByName.put(name, new TelecommandArgument(name, value, editable));
}
}
return argumentsByName.values();
}
use of org.yamcs.protobuf.Mdb.ArgumentInfo in project yamcs-studio by yamcs.
the class StackedCommand method buildCommandFromSource.
public static StackedCommand buildCommandFromSource(String commandSource) throws Exception {
StackedCommand result = new StackedCommand();
// <CommandAlias>()
if (commandSource == null)
throw new Exception("No Source attached to this command");
commandSource = commandSource.trim();
if (commandSource.isEmpty())
throw new Exception("No Source attached to this command");
int indexStartOfArguments = commandSource.indexOf("(");
int indexStopOfArguments = commandSource.lastIndexOf(")");
String commandArguments = commandSource.substring(indexStartOfArguments + 1, indexStopOfArguments);
commandArguments = commandArguments.replaceAll("[\n]", "");
String commandAlias = commandSource.substring(0, indexStartOfArguments);
// Retrieve meta command and selected namespace
CommandInfo commandInfo = null;
String selectedAlias = "";
for (CommandInfo ci : CommandingCatalogue.getInstance().getMetaCommands()) {
for (NamedObjectId noi : ci.getAliasList()) {
String alias = noi.getNamespace() + "/" + noi.getName();
if (alias.equals(commandAlias)) {
commandInfo = ci;
selectedAlias = alias;
break;
}
}
}
if (commandInfo == null)
throw new Exception("Unable to retrieved this command in the MDB");
result.setMetaCommand(commandInfo);
result.setSelectedAliase(selectedAlias);
// Retrieve arguments assignment
// TODO: write formal source grammar
String[] commandArgumentsTab = commandArguments.split(",");
for (String commandArgument : commandArgumentsTab) {
if (commandArgument == null || commandArgument.isEmpty())
continue;
String[] components = commandArgument.split(":");
String argument = components[0].trim();
String value = components[1].trim();
boolean foundArgument = false;
for (ArgumentInfo ai : commandInfo.getArgumentList()) {
foundArgument = ai.getName().toUpperCase().equals(argument.toUpperCase());
if (foundArgument) {
if (value.startsWith("\"") && value.endsWith("\""))
value = value.substring(1, value.length() - 1);
result.addAssignment(ai, value);
break;
}
}
if (!foundArgument)
throw new Exception("Argument " + argument + " is not part of the command definition");
}
return result;
}
use of org.yamcs.protobuf.Mdb.ArgumentInfo in project yamcs-studio by yamcs.
the class ArgumentTableBuilder method updateCommandArguments.
public void updateCommandArguments() {
argumentAssignements = new ArrayList<>();
for (ArgumentInfo arg : command.getMetaCommand().getArgumentList()) {
String value = command.getAssignedStringValue(arg);
argumentAssignements.add(new ArgumentAssignement(arg, value == null ? "" : value));
}
argumentTable.setInput(argumentAssignements);
}
Aggregations