Commit 4195ee41 authored by Jean Meurice's avatar Jean Meurice Committed by Evgeny Kusmenko
Browse files

Software simulator

parent 97374b5a
......@@ -9,6 +9,6 @@
@echo off
call config.bat
echo Starting RMIModelServer on port %PORT% with Autopilot folder: %AUTOPILOT_FOLDER%
java "-Djava.rmi.server.codebase=file:rmi-model-server.jar" "-Djava.rmi.server.useLocalHostname" -cp rmi-model-server.jar rwth.rmi.model.server.RMIServer %PORT% %AUTOPILOT_FOLDER% os=windows no_time %*
echo Starting RMIModelServer on port %PORT% with softwares folder: %SOFTWARES_FOLDER%
java "-Djava.rmi.server.codebase=file:rmi-model-server.jar" "-Djava.rmi.server.useLocalHostname" -cp rmi-model-server.jar rwth.rmi.model.server.RMIServer port=%PORT% softwares_folder=%SOFTWARES_FOLDER%
pause
......@@ -7,15 +7,7 @@
#
if [ -z "$1" ]; then
PORT=10101
else
PORT="$1"
fi
source ./config.sh
AUTOPILOT_FOLDER=autopilots
java -cp rmi-model-server.jar\
-Djava.rmi.server.codebase=file:rmi-model-server.jar\
-Djava.rmi.server.useLocalHostname rwth.rmi.model.server.RMIServer\
$PORT $AUTOPILOT_FOLDER os=linux no_time
echo "Starting RMIModelServer on port $PORT with Autopilot folder: $SOFTWARES_FOLDER"
java "-Djava.rmi.server.hostname=localhost" -jar rmi-model-server.jar port=$PORT softwares_folder=$SOFTWARES_FOLDER
......@@ -11,7 +11,7 @@
<groupId>montisim</groupId>
<artifactId>rmi-model-server</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
<packaging>jar</packaging>
<name>rmi-model-server</name>
......@@ -19,7 +19,7 @@
<properties>
<!-- USE THESE TO SET THE VERSIONS OF THE DEPENDENCIES FOR ALL THE SUB-PROJECTS -->
<commons.version>1.0.11</commons.version>
<hardware_emulator.version>1.0.2</hardware_emulator.version>
<hardware_emulator.version>1.0.4</hardware_emulator.version>
<!-- .. SE-Libraries .................................................. -->
<monticore.version>4.5.4.08.11.2017</monticore.version>
......
......@@ -7,7 +7,9 @@
package de.rwth.monticore.EmbeddedMontiArc.simulators.rmimodelserver;
import org.I0Itec.zkclient.ZkClient;
import de.rwth.monticore.EmbeddedMontiArc.simulators.hardware_emulator.HardwareEmulatorInterface;
import de.rwth.monticore.EmbeddedMontiArc.simulators.hardware_emulator.interfaces.SoftwareSimulatorManager;
import de.rwth.monticore.EmbeddedMontiArc.simulators.hardware_emulator.RemoteSoftwareSimulatorManager;
import de.rwth.monticore.EmbeddedMontiArc.simulators.hardware_emulator.config.SoftwareSimulatorConfig;
import java.io.File;
import java.io.IOException;
......@@ -20,36 +22,27 @@ import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Arrays;
import java.util.HashMap;
public class RMIServer {
public final static String MODEL_MANAGER = "ModelManager";
public final static String SOFTWARE_SIMULATOR_MANAGER = "SoftwareSimulatorManager";
public final static String ZK_NODE = "/rmi-servers/all";
public static void parse_args(String[] args, HashMap<String, String> options){
String default_config = "";
boolean add_to_default_config = false;
for (String arg : args){
if (add_to_default_config){
default_config += arg + "\n";
} else {
String sub_args[] = arg.split("=");
if (arg.equals("no-zookeeper")){
options.put("no-zookeeper", "true");
} else if (arg.equals("default_config")){
add_to_default_config = true;
} else if (sub_args.length > 1) {
if (sub_args[0].equals("port")){
options.put("port", sub_args[1]);
} else if (sub_args[0].equals("autopilots_folder")){
options.put("autopilots_folder", sub_args[1]);
}
String sub_args[] = arg.split("=");
if (arg.equals("no-zookeeper")){
options.put("no-zookeeper", "true");
} else if (sub_args.length > 1) {
if (sub_args[0].equals("port")){
options.put("port", sub_args[1]);
} else if (sub_args[0].equals("softwares_folder")){
options.put("softwares_folder", sub_args[1]);
}
}
}
options.put("default_config", default_config);
}
......@@ -76,32 +69,30 @@ public class RMIServer {
if (!use_zookeeper)
System.out.println("Not using Zookeeper.");
String default_config = options.get("default_config");
String emu_config = "";
SoftwareSimulatorConfig manager_config = new SoftwareSimulatorConfig();
try {// Load AutopilotAdapter.dll from libraryPath
emu_config += "autopilots_folder=" + autopilot_folder.getCanonicalPath() + "\n";
manager_config.set_softwares_folder(autopilot_folder.getCanonicalPath());
} catch (IOException e) {
e.printStackTrace();
System.out.println("Could not resolve the Hardware Emulator autopilots path.");
System.out.println("Could not resolve the SoftwareSimulator's software folder path. ("+autopilot_folder+")");
}
HardwareEmulatorInterface manager = null;
int port_id = Integer.valueOf(port);
SoftwareSimulatorManager manager = null;
try {
manager = new HardwareEmulatorInterface(emu_config, default_config);
manager = new RemoteSoftwareSimulatorManager(manager_config , port_id);
} catch (Exception e) {
e.printStackTrace();
System.exit(-2);
}
String host = InetAddress.getLocalHost().getHostName();
int port_id = Integer.valueOf(port);
try {
Registry registry = LocateRegistry.createRegistry(port_id);
System.out.println("RMIRegistry serving on port: " + port);
//bind the ModelManager to a stub, representing the remote object
registry.bind(MODEL_MANAGER, UnicastRemoteObject.exportObject(manager, port_id));
registry.bind(SOFTWARE_SIMULATOR_MANAGER, UnicastRemoteObject.exportObject(manager, port_id));
if (use_zookeeper){
String zoo_servers;
......
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.rmimodelserver;
import de.rwth.monticore.EmbeddedMontiArc.simulators.hardware_emulator.HardwareEmulatorInterface;
import org.junit.Test;
import org.junit.Assert;
import java.io.File;
import java.io.Serializable;
import java.util.HashMap;
public class HardwareEmulatorTest {
@Test
public void basic_test() throws Exception {
System.out.println("Current test directory: " + System.getProperty("user.dir"));
HardwareEmulatorInterface manager = new HardwareEmulatorInterface("autopilots_folder=autopilots", "");
String querry = "get_available_autopilots\nget_available_threads";
String res = manager.query(querry);
System.out.println("EmulatorManager querry response: " + res);
String lines[] = res.split("\n");
Assert.assertEquals("Querry result line count", 2, lines.length);
String line1[] = lines[0].split("=");
Assert.assertEquals("available_autopilots two values (=)", 2, line1.length);
Assert.assertEquals("available_autopilots command", new String("available_autopilots"), line1[0]);
String line2[] = lines[1].split("=");
Assert.assertEquals("available_threads two values (=)", 2, line2.length);
Assert.assertEquals("available_threads command", new String("available_threads"), line2[0]);
String config = "autopilot=AutopilotAdapter";
config += "\nos=windows";
int id = manager.alloc_autopilot(config);
if (id < 0){
String q = manager.query( "get_error_msg" );
Assert.assertTrue("Could not allocate Emulator: " + q, id >= 0);
}
HashMap<String, Serializable> inputs = new HashMap<String, Serializable>();
inputs.put("timeIncrement", 1.0);
inputs.put("currentVelocity", 0.0);
inputs.put("x", 0.01);
inputs.put("y", 0.01);
inputs.put("compass", 0.0);
inputs.put("currentEngine", 0.0);
inputs.put("currentSteering", 0.0);
inputs.put("currentBrakes", 0.0);
inputs.put("trajectory_length", 5);
inputs.put("trajectory_x", new double[]{0.01, 0.02, 0.03, 0.04, 0.05, 0.06});
inputs.put("trajectory_y", new double[]{0.01, 0.01, 0.02, 0.02, 0.01, 0.01});
manager.update_bus(id, inputs);
//manager.start_tick(1000000);
//manager.end_tick();
HashMap<String, Serializable> outputs = manager.old_execute(id, 1000000, inputs);
String emu_querry = manager.query_autopilot(id, "get_avg_runtime");
System.out.println("Emu querry: " + emu_querry);
//HashMap<String, Serializable> outputs = manager.get_outputs(id);
Assert.assertEquals("output count", outputs.size(), 3);
for (HashMap.Entry<String, Serializable> entry : outputs.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
manager.free_autopilot(id);
//Try to clear up the library from the test directory
File lib = manager.get_library();
manager = null;
System.gc();
lib.delete();
}
}
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