Commit a3f046fc authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Merge branch 'master' of gitlab.lrz.de:vadere/vadere

parents 47dae5ed 807de088
package org.vadere.manager.traci;
import org.vadere.manager.TraCIException;
import org.vadere.manager.traci.commandHandler.variables.ControlVar;
import org.vadere.manager.traci.commandHandler.variables.PersonVar;
import org.vadere.manager.traci.commandHandler.variables.PolygonVar;
import org.vadere.manager.traci.commandHandler.variables.SimulationVar;
import org.vadere.manager.traci.commandHandler.variables.VadereVar;
/**
* List of all TraCI Commands and there Types.
*/
public enum TraCICmd {
// TraCI/Control-related commands
GET_VERSION(0x00, CmdType.CTRL),
SIM_STEP(0x02, CmdType.CTRL),
CLOSE(0x7F, CmdType.CTRL),
LOAD(0x01, CmdType.CTRL),
SET_ORDER(0x03, CmdType.CTRL),
SEND_FILE(0x75, CmdType.CTRL),
GET_VERSION(0x00, CmdType.CTRL, ControlVar::asString),
SIM_STEP(0x02, CmdType.CTRL, ControlVar::asString),
CLOSE(0x7F, CmdType.CTRL, ControlVar::asString),
LOAD(0x01, CmdType.CTRL, ControlVar::asString),
SET_ORDER(0x03, CmdType.CTRL, ControlVar::asString),
SEND_FILE(0x75, CmdType.CTRL, ControlVar::asString),
// Value Retrieval
GET_INDUCTION_LOOP(0xa0, CmdType.VALUE_GET),
RESPONSE_GET_INDUCTION_LOOP(0xb0, CmdType.RESPONSE),
......@@ -30,22 +35,23 @@ public enum TraCICmd {
RESPONSE_GET_ROUTE_VALUE(0xb6, CmdType.RESPONSE),
GET_POI_VALUE(0xa7, CmdType.VALUE_GET),
RESPONSE_GET_POI_VALUE(0xb7, CmdType.RESPONSE),
GET_POLYGON(0xa8, CmdType.VALUE_GET),
RESPONSE_GET_POLYGON(0xb8, CmdType.RESPONSE),
GET_POLYGON(0xa8, CmdType.VALUE_GET, PolygonVar::asString),
RESPONSE_GET_POLYGON(0xb8, CmdType.RESPONSE, PolygonVar::asString),
GET_JUNCTION_VALUE(0xa9, CmdType.VALUE_GET),
RESPONSE_GET_JUNCTION_VALUE(0xb9, CmdType.RESPONSE),
GET_EDGE_VALUE(0xaa, CmdType.VALUE_GET),
RESPONSE_GET_EDGE_VALUE(0xba, CmdType.RESPONSE),
GET_SIMULATION_VALUE(0xab, CmdType.VALUE_GET),
RESPONSE_GET_SIMULATION_VALUE(0xbb, CmdType.RESPONSE),
GET_SIMULATION_VALUE(0xab, CmdType.VALUE_GET, SimulationVar::asString),
RESPONSE_GET_SIMULATION_VALUE(0xbb, CmdType.RESPONSE, SimulationVar::asString),
GET_GUI_VALUE(0xac, CmdType.VALUE_GET),
RESPONSE_GET_GUI_VALUE(0xbc, CmdType.RESPONSE),
GET_LANEAREA_DETECTOR(0xad, CmdType.VALUE_GET),
RESPONSE_GET_LANEAREA_DETECTOR(0xbd, CmdType.RESPONSE),
GET_PERSON_VALUE(0xae, CmdType.VALUE_GET),
RESPONSE_GET_PERSON_VALUE(0xbe, CmdType.RESPONSE),
GET_VADERE_VALUE(0xaf, CmdType.VALUE_GET),
RESPONSE_GET_VADERE_VALUE(0xbf, CmdType.RESPONSE),
GET_PERSON_VALUE(0xae, CmdType.VALUE_GET, PersonVar::asString),
RESPONSE_GET_PERSON_VALUE(0xbe, CmdType.RESPONSE, PersonVar::asString),
GET_VADERE_VALUE(0xaf, CmdType.VALUE_GET, VadereVar::asString),
RESPONSE_GET_VADERE_VALUE(0xbf, CmdType.RESPONSE, VadereVar::asString),
// State Changing
SET_TRAFFIC_LIGHT_STATE(0xc2, CmdType.VALUE_SET),
SET_LANE_STATE(0xc3, CmdType.VALUE_SET),
......@@ -93,13 +99,21 @@ public enum TraCICmd {
public int id;
public CmdType type;
public VarString varString;
TraCICmd(int id, CmdType type) {
this.id = id;
this.type = type;
this.varString = id1 -> "varID: " + id1;
}
TraCICmd(int id, CmdType type, VarString varString) {
this.id = id;
this.type = type;
this.varString = varString;
}
public static TraCICmd fromId(int id) {
for (TraCICmd traCICmd : values()) {
if (traCICmd.id == id)
......@@ -110,11 +124,14 @@ public enum TraCICmd {
@Override
public String toString() {
return String.format("TraCICmd{%s: id=0x%02X, type=%s}", name(), id, type);
}
public String logShort() {
return String.format("{%s: 0x%02X%s}", name(), id, type);
return String.format("{%s: 0x%02X %s}", name(), id, type);
}
public String logShort(int varId) {
return String.format("{%s: 0x%02X %s VAR: %s}", name(), id, type, varString.varAsString(varId));
}
}
package org.vadere.manager.traci;
public interface VarString {
String varAsString(int id);
}
package org.vadere.manager.traci.commandHandler;
import com.sun.jdi.InvocationException;
import org.vadere.manager.RemoteManager;
import org.vadere.manager.TraCIException;
import org.vadere.manager.traci.TraCICmd;
......@@ -9,6 +11,7 @@ import org.vadere.manager.traci.writer.TraCIPacket;
import org.vadere.util.logging.Logger;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;
/**
* Dispatcher for {@link TraCICommand}s.
......@@ -45,26 +48,29 @@ public class CommandExecutor {
public TraCIPacket execute(TraCICommand cmd) {
TraCICmdHandler handler = cmdMap.get(cmd.getTraCICmd().id);
int varId = cmd.getVariableIdentifier();
if (handler == null) {
logger.errorf("No CommandHandler found for command: %s", cmd.getTraCICmd().logShort());
logger.errorf("No CommandHandler found for command: %s", cmd.getTraCICmd().logShort(varId));
return TraCIPacket.create().add_Err_StatusResponse(cmd.getTraCICmd().id, "ID not found.");
}
TraCIPacket response;
try {
logger.debugf("execute cmd: %s", cmd.getTraCICmd().logShort());
logger.debugf("execute cmd: %s", cmd.getTraCICmd().logShort(varId));
cmd = handler.handel(cmd, remoteManager);
} catch (TraCIException e) {
logger.errorf("Error handling cmd: %s", cmd.getTraCICmd().logShort());
} catch (Exception e) {
String err = String.format("Error handling cmd: %s", cmd.getTraCICmd().logShort(varId));
logger.errorf(err);
e.printStackTrace();
return TraCIPacket.createErr(cmd.getTraCICmd().id, e.getMessageForClient());
return TraCIPacket.createErr(cmd.getTraCICmd().id, err + "see Vadere log for details");
}
try {
logger.debugf("build response for: %s", cmd.getTraCICmd().logShort());
logger.debugf("build response for: %s", cmd.getTraCICmd().logShort(varId));
response = cmd.buildResponsePacket();
} catch (TraCIException e) {
logger.errorf("error building response for: %s", cmd.getTraCICmd().logShort());
} catch (Exception e) {
String err = String.format("error building response for: %s", cmd.getTraCICmd().logShort(varId));
logger.errorf(err);
e.printStackTrace();
return TraCIPacket.createErr(cmd.getTraCICmd().id, e.getMessageForClient());
return TraCIPacket.createErr(cmd.getTraCICmd().id, err + "see Vadere log for details");
}
logger.tracef("return response for: %s", cmd.getTraCICmd().logShort());
......
......@@ -265,7 +265,6 @@ public class SimulationCommandHandler extends CommandHandler<SimulationVar> {
);
cmd.setResponse(responseOK(SimulationVar.COORD_REF.type, o));
});
return cmd;
}
......
......@@ -23,9 +23,16 @@ public enum ControlVar {
throw new TraCIException(String.format("No ControlVar var found with id: %02X", id));
}
public static String asString(int id){
try {
return fromId(id).toString();
} catch (TraCIException ignored) { }
return "No variable for id: " + id;
}
@Override
public String toString() {
return "ControlVar{" +
return name() + "{" +
"id=" + id +
", type=" + returnType +
'}';
......
......@@ -57,11 +57,17 @@ public enum PersonVar {
throw new TraCIException(String.format("No person var found with id: %02X", id));
}
public static String asString(int id){
try {
return fromId(id).toString();
} catch (TraCIException ignored) { }
return "No variable for id: " + id;
}
@Override
public String toString() {
return "PersonVar{" +
name() +
": id=" + id +
return name() + "{" +
"id=" + id +
", type=" + type +
'}';
}
......
......@@ -34,4 +34,19 @@ public enum PolygonVar {
}
throw new TraCIException(String.format("No polygon var found with id: %02X", id));
}
public static String asString(int id){
try {
return fromId(id).toString();
} catch (TraCIException ignored) { }
return "No variable for id: " + id;
}
@Override
public String toString() {
return name() + "{" +
"id=" + id +
", type=" + type +
'}';
}
}
......@@ -44,9 +44,16 @@ public enum SimulationVar {
throw new TraCIException(String.format("No simulation var found with id: %02X", id));
}
public static String asString(int id){
try {
return fromId(id).toString();
} catch (TraCIException ignored) { }
return "No variable for id: " + id;
}
@Override
public String toString() {
return "SimulationVar{" +
return name() + "{" +
"id=" + id +
", type=" + type +
'}';
......
......@@ -26,4 +26,19 @@ public enum VadereVar {
}
throw new TraCIException(String.format("No vadere var found with id: %02X", id));
}
public static String asString(int id){
try {
return fromId(id).toString();
} catch (TraCIException ignored) { }
return "No variable for id: " + id;
}
@Override
public String toString() {
return name() + "{" +
"id=" + id +
", type=" + type +
'}';
}
}
......@@ -23,9 +23,16 @@ public enum VehicleVar {
throw new TraCIException(String.format("No vehicle var found with id: %02X", id));
}
public static String asString(int id){
try {
return fromId(id).toString();
} catch (TraCIException ignored) { }
return "No variable for id: " + id;
}
@Override
public String toString() {
return "VehicleVar{" +
return name() + "{" +
"id=" + id +
", type=" + returnType +
'}';
......
......@@ -102,4 +102,6 @@ public abstract class TraCICommand {
}
public abstract TraCIPacket buildResponsePacket();
public int getVariableIdentifier(){return -1;}
}
......@@ -56,6 +56,12 @@ public class TraCISetCommand extends TraCICommand {
return variableId;
}
public int getVariableIdentifier() {
return variableId;
}
public String getElementId() {
return elementId;
}
......
......@@ -85,6 +85,10 @@ public class TraCIValueSubscriptionCommand extends TraCICommand {
this.variables = variables;
}
public int getVariableIdentifier() {
return -1;
}
public TraCISubscriptionResponse getResponse() {
return response;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment