org.yamcs.commanding.PreparedCommand Maven / Gradle / Ivy
package org.yamcs.commanding;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.yamcs.StandardTupleDefinitions;
import org.yamcs.cmdhistory.protobuf.Cmdhistory.Assignment;
import org.yamcs.cmdhistory.protobuf.Cmdhistory.AssignmentInfo;
import org.yamcs.mdb.Mdb;
import org.yamcs.parameter.ParameterValue;
import org.yamcs.parameter.ParameterValueList;
import org.yamcs.parameter.Value;
import org.yamcs.protobuf.Commanding.CommandAssignment;
import org.yamcs.protobuf.Commanding.CommandHistoryAttribute;
import org.yamcs.protobuf.Commanding.CommandHistoryEntry;
import org.yamcs.protobuf.Commanding.CommandId;
import org.yamcs.protobuf.Commanding.VerifierConfig;
import org.yamcs.protobuf.Yamcs.Value.Type;
import org.yamcs.utils.StringConverter;
import org.yamcs.utils.ValueHelper;
import org.yamcs.utils.ValueUtility;
import org.yamcs.xtce.Argument;
import org.yamcs.xtce.MetaCommand;
import org.yamcs.xtce.Parameter;
import org.yamcs.yarch.ColumnDefinition;
import org.yamcs.yarch.DataType;
import org.yamcs.yarch.Stream;
import org.yamcs.yarch.Tuple;
import org.yamcs.yarch.TupleDefinition;
/**
* Stores command information
*/
public class PreparedCommand {
private CommandId id;
private MetaCommand metaCommand;
// Target stream (may be null, for autoselection)
private Stream tcStream;
List attributes = new ArrayList<>();
private Map argAssignment; // Ordered from top entry to bottom entry
private Set userAssignedArgumentNames;
// Verifier-specific configuration options (that override the MDB verifier settings)
private Map verifierConfig = new HashMap<>();
// same as attributes but converted to parameters for usage in verifiers and transmission constraints
private volatile ParameterValueList cmdParams;
// column names to use when converting to tuple
public final static String CNAME_GENTIME = StandardTupleDefinitions.GENTIME_COLUMN;
public final static String CNAME_SEQNUM = StandardTupleDefinitions.SEQNUM_COLUMN;
public final static String CNAME_ORIGIN = StandardTupleDefinitions.TC_ORIGIN_COLUMN;
public final static String CNAME_USERNAME = "username";
public final static String CNAME_UNPROCESSED_BINARY = "unprocessedBinary";
public final static String CNAME_BINARY = "binary";
public final static String CNAME_CMDNAME = "cmdName";
public final static String CNAME_ASSIGNMENTS = "assignments";
public final static String CNAME_COMMENT = "comment";
public final static String CNAME_NO_POSTPROCESSING = "noPostprocessing";
public final static String CNAME_NO_TRANSMISSION_CONSTRAINTS = "noTransmissionConstraints";
public final static String CNAME_NO_VERIFIERS = "noVerifiers";
public final static String CNAME_RAW = "raw";
private static Set reservedColumns = new HashSet<>();
static {
reservedColumns.add(CNAME_GENTIME);
reservedColumns.add(CNAME_SEQNUM);
reservedColumns.add(CNAME_ORIGIN);
reservedColumns.add(CNAME_USERNAME);
reservedColumns.add(CNAME_UNPROCESSED_BINARY);
reservedColumns.add(CNAME_BINARY);
reservedColumns.add(CNAME_CMDNAME);
reservedColumns.add(CNAME_ASSIGNMENTS);
reservedColumns.add(CNAME_COMMENT);
reservedColumns.add(CNAME_NO_POSTPROCESSING);
reservedColumns.add(CNAME_NO_TRANSMISSION_CONSTRAINTS);
reservedColumns.add(CNAME_NO_VERIFIERS);
}
/**
* Columns that can't be updated via cmdhist_realtime attributes.
*/
public static Set protectedColumns = new HashSet<>();
static {
protectedColumns.add(CNAME_GENTIME);
protectedColumns.add(CNAME_SEQNUM);
protectedColumns.add(CNAME_ORIGIN);
protectedColumns.add(CNAME_ASSIGNMENTS);
}
public PreparedCommand(CommandId id) {
this.id = id;
}
/**
* Used for testing the uplinkers
*/
public PreparedCommand(byte[] binary) {
setBinary(binary);
}
public long getGenerationTime() {
return id.getGenerationTime();
}
public void setComment(String comment) {
setAttribute(CNAME_COMMENT, comment);
}
public String getComment() {
return getStringAttribute(CNAME_COMMENT);
}
/**
* Specify the target TC stream. If unset, a stream is automatically selected.
*/
public void setTcStream(Stream tcStream) {
this.tcStream = tcStream;
}
public Stream getTcStream() {
return tcStream;
}
public String getCmdName() {
return id.getCommandName();
}
public Boolean getBooleanAttribute(String attrname) {
CommandHistoryAttribute a = getAttribute(attrname);
if (a != null) {
Value v = ValueUtility.fromGpb(a.getValue());
if (v.getType() == Type.BOOLEAN) {
return v.getBooleanValue();
}
}
return null;
}
public String getStringAttribute(String attrname) {
CommandHistoryAttribute a = getAttribute(attrname);
if (a != null) {
Value v = ValueUtility.fromGpb(a.getValue());
if (v.getType() == Type.STRING) {
return v.getStringValue();
}
}
return null;
}
public byte[] getBinaryAttribute(String attrname) {
CommandHistoryAttribute a = getAttribute(attrname);
if (a != null) {
Value v = ValueUtility.fromGpb(a.getValue());
if (v.getType() == Type.BINARY) {
return v.getBinaryValue();
}
}
return null;
}
public String getId() {
return id.getGenerationTime() + "-" + id.getOrigin() + "-" + id.getSequenceNumber();
}
/**
* String useful for logging. Contains command name and sequence number
*/
public String getLoggingId() {
return id.getCommandName() + "-" + id.getSequenceNumber();
}
public String getOrigin() {
return id.getOrigin();
}
public int getSequenceNumber() {
return id.getSequenceNumber();
}
public String getCommandName() {
return id.getCommandName();
}
public CommandId getCommandId() {
return id;
}
static public CommandId getCommandId(Tuple t) {
CommandId cmdId = CommandId.newBuilder()
.setGenerationTime((Long) t.getColumn(CNAME_GENTIME))
.setOrigin((String) t.getColumn(CNAME_ORIGIN))
.setSequenceNumber((Integer) t.getColumn(CNAME_SEQNUM))
.setCommandName((String) t.getColumn(CNAME_CMDNAME))
.build();
return cmdId;
}
public Tuple toTuple() {
TupleDefinition td = StandardTupleDefinitions.TC.copy();
ArrayList
© 2015 - 2024 Weber Informatics LLC | Privacy Policy