Commit f045321e authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Traci wrapper fix

parent 7244c69e
...@@ -69,6 +69,19 @@ cli2.startScenario(scenarioPath) ...@@ -69,6 +69,19 @@ cli2.startScenario(scenarioPath)
embed() embed()
``` ```
```python
if __name__ == "__main__":
c = Py4jClient.create(
project_path="VADERE_PATH/Scenarios/Demos/roVer/scenarios",
vadere_base_path="VADERE_PATH",
start_server=False,
debug=False,
)
c.entrypoint_jar = "/VADERE_PATH/Tools/PythonTraciWrapper/vadere-traci-entrypoint.jar"
c.connect()
c.startScenario("roVerTest002.scenario")
```
## Extend API ## Extend API
If new TraCI commands are implemented in vadere, these can also be used via a python client. To achieve this the following steps are required: If new TraCI commands are implemented in vadere, these can also be used via a python client. To achieve this the following steps are required:
......
...@@ -46,6 +46,7 @@ class Py4jClient: ...@@ -46,6 +46,7 @@ class Py4jClient:
self.server_log = server_log self.server_log = server_log
self.entrypoint_log = entry_point_log self.entrypoint_log = entry_point_log
self.debug = debug self.debug = debug
self.entrypoint_jar = ''
self._build_argparser() self._build_argparser()
if isinstance(args, List): if isinstance(args, List):
...@@ -53,6 +54,7 @@ class Py4jClient: ...@@ -53,6 +54,7 @@ class Py4jClient:
else: else:
self._parser.parse_args(["--help"]) self._parser.parse_args(["--help"])
def connect(self):
self._start_entrypoint() self._start_entrypoint()
self._connect_gateway() self._connect_gateway()
...@@ -111,12 +113,18 @@ class Py4jClient: ...@@ -111,12 +113,18 @@ class Py4jClient:
def _start_entrypoint(self): def _start_entrypoint(self):
if self.start_server: if self.start_server:
if self.entrypoint_jar == '':
jar_path = os.path.join(
self.vadere_base_path,
"VadereManager/target/vadere-server.jar",
),
else:
jar_path = self.entrypoint_jar
vadere_server_cmd = [ vadere_server_cmd = [
"java", "java",
"-jar", "-jar",
os.path.join( jar_path,
self.vadere_base_path, "VadereManager/target/vadere-server.jar",
),
] ]
vadere_server_cmd.extend(self._server_args()) vadere_server_cmd.extend(self._server_args())
self.server_thread = Runner( self.server_thread = Runner(
...@@ -132,13 +140,18 @@ class Py4jClient: ...@@ -132,13 +140,18 @@ class Py4jClient:
self.server_thread = None self.server_thread = None
print("Connecting to existing Server...") print("Connecting to existing Server...")
entrypoint_cmd = [ if self.entrypoint_jar == '':
"java", jar_path = os.path.join(
"-jar",
os.path.join(
self.vadere_base_path, self.vadere_base_path,
"VadereManager/target/vadere-traci-entrypoint.jar", "VadereManager/target/vadere-traci-entrypoint.jar",
), ),
else:
jar_path = self.entrypoint_jar
entrypoint_cmd = [
"java",
"-jar",
jar_path,
] ]
entrypoint_cmd.extend(self._entrypoint_args()) entrypoint_cmd.extend(self._entrypoint_args())
self.entrypoint_thread = Runner( self.entrypoint_thread = Runner(
...@@ -252,13 +265,3 @@ class Py4jClient: ...@@ -252,13 +265,3 @@ class Py4jClient:
dest="defaultScenario", dest="defaultScenario",
help="Supply a default scenario", help="Supply a default scenario",
) )
if __name__ == "__main__":
c = Py4jClient.create(
project_path="/path/to/vadere/scenarios/",
vadere_base_path="/path/to/vadere",
start_server=False,
debug=False,
)
c.startScenario("Test001.scenario")
...@@ -116,6 +116,8 @@ public class SimulationCommandHandler extends CommandHandler<SimulationVar> { ...@@ -116,6 +116,8 @@ public class SimulationCommandHandler extends CommandHandler<SimulationVar> {
try { try {
SimulationCfg cfg = new SimulationCfg((CompoundObject) cmd.getVariableValue()); SimulationCfg cfg = new SimulationCfg((CompoundObject) cmd.getVariableValue());
remoteManager.setSimCfg(cfg); remoteManager.setSimCfg(cfg);
logger.infof("Received SimulationConfig:");
logger.infof(cfg.toString());
cmd.setOK(); cmd.setOK();
} catch (TraCIException ex) { } catch (TraCIException ex) {
......
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