package edu.berkeley.fleet.interpreter;
import edu.berkeley.fleet.api.*;
+import edu.berkeley.sbp.util.ANSI;
class Packet {
- InterpreterPath path;
- BitVector value;
- boolean isToken;
+ private final InterpreterPath path;
+ private final BitVector value;
+ private final boolean isToken;
public Packet(InterpreterPath path, BitVector value, boolean isToken) {
this.value = value;
this.path = path;
this.isToken = isToken;
+ this.value.setImmutable();
}
public void send() {
- if (isToken) {
- Log.token(path.getSource(), path.getDestination());
+ Log.packet(this);
+ ((InterpreterDestination)path.getDestination()).addDataFromFabric(this);
+ }
+
+ public Destination getDestination() {
+ return path.getDestination();
+ }
+
+ public Dock getSource() {
+ return path.getSource();
+ }
+
+ public BitVector getSignal() {
+ return path.getSignal();
+ }
+
+ public BitVector getValue() {
+ return value;
+ }
+
+ public boolean isToken() {
+ return isToken;
+ }
+
+ public String toString() {
+ Packet p = this;
+ BitVector data = p.getValue();
+ Dock source = p.getSource();
+ Destination dest = p.getDestination();
+ if (dest.getDock().getInstructionDestination()==dest) {
+ if (p.isToken()) {
+ return (ANSI.yellow(ANSI.bold(" torpedo: ")) + (source + " -> " + ANSI.yellow(ANSI.bold(dest+""))));
+ } else {
+ Instruction d = source.getShip().getFleet().decodeInstruction(data, source);
+ return (ANSI.red("dispatch: " + d));
+ }
} else {
- Log.data(value+"", path.getSource(), path.getDestination());
+ if (p.isToken()) {
+ return (ANSI.blue(ANSI.bold(" token: ")) + (source + " -> " + ANSI.blue(ANSI.bold(dest+""))));
+ } else {
+ return (ANSI.cyan(" data: "+data) +
+ (source==null ? "" :
+ (" : " + source))+(" -> "+ANSI.cyan(""+dest)));
+ }
}
- ((InterpreterDestination)path.getDestination()).addDataFromFabric(this);
}
}