Commit 298e3ad5 authored by Jean Meurice's avatar Jean Meurice
Browse files

New Package structure + New Hardware Emulator usage

parent 5446235f
Pipeline #169810 failed with stage
in 1 minute and 3 seconds
......@@ -5,3 +5,5 @@
.classpath
/.settings
.vscode/
*.jar
*.dll
\ No newline at end of file
......@@ -23,5 +23,6 @@
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.hostname=localhost" -cp rmi-model-server.jar rwth.rmi.model.server.RMIServer %PORT% %AUTOPILOT_FOLDER% --no-zookeeper %*
@REM java "-Djava.rmi.server.codebase=file:rmi-model-server.jar" "-Djava.rmi.server.hostname=localhost" -cp rmi-model-server.jar rwth.rmi.model.server.RMIServer %PORT% %AUTOPILOT_FOLDER% --no-zookeeper %*
java -jar rmi-model-server.jar port=%PORT% autopilots_folder=%AUTOPILOT_FOLDER% no-zookeeper default_config %*
pause
......@@ -23,4 +23,5 @@
source ./config.sh
echo "Starting RMIModelServer on port $PORT with Autopilot folder: $AUTOPILOT_FOLDER"
java "-Djava.rmi.server.codebase=file:rmi-model-server.jar" "-Djava.rmi.server.hostname=localhost" -cp rmi-model-server.jar rwth.rmi.model.server.RMIServer $PORT $AUTOPILOT_FOLDER --no-zookeeper os=linux no_time
# java "-Djava.rmi.server.codebase=file:rmi-model-server.jar" "-Djava.rmi.server.hostname=localhost" -cp rmi-model-server.jar rwth.rmi.model.server.RMIServer $PORT $AUTOPILOT_FOLDER --no-zookeeper os=linux no_time
java "-Djava.rmi.server.hostname=localhost" -jar rmi-model-server.jar port=$PORT autopilots_folder=$AUTOPILOT_FOLDER no-zookeeper default_config os=linux no_time
\ No newline at end of file
......@@ -20,8 +20,7 @@
*******************************************************************************
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>montisim</groupId>
......@@ -34,6 +33,7 @@
<properties>
<!-- USE THESE TO SET THE VERSIONS OF THE DEPENDENCIES FOR ALL THE SUB-PROJECTS -->
<commons.version>1.0.8</commons.version>
<hardware_emulator.version>1.0.0</hardware_emulator.version>
<!-- .. SE-Libraries .................................................. -->
<monticore.version>4.5.4.08.11.2017</monticore.version>
......@@ -79,6 +79,11 @@
<artifactId>commons</artifactId>
<version>${commons.version}</version>
</dependency>
<dependency>
<groupId>montisim</groupId>
<artifactId>hardware_emulator</artifactId>
<version>${hardware_emulator.version}</version>
</dependency>
</dependencies>
<!-- == PROJECT BUILD SETTINGS =========================================== -->
......@@ -132,6 +137,29 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>de.rwth.monticore.EmbeddedMontiArc.simulators.rmimodelserver.RMIServer</mainClass>
</transformer>
</transformers>
<outputFile>${project.basedir}/install/${project.name}.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<!-- Source Jar Configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -180,22 +208,12 @@
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<workingDirectory>${project.basedir}/install</workingDirectory>
<argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<configuration>
</configuration>
<configuration></configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
......@@ -234,6 +252,51 @@
</plugins>
</build>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>eclipse</id>
<url>https://repo.eclipse.org/content/groups/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>topobyte</id>
<url>http://mvn.topobyte.de/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- == DISTRIBUTION ==================================================== -->
<distributionManagement>
......
@REM
@REM
@REM ******************************************************************************
@REM MontiCAR Modeling Family, www.se-rwth.de
@REM Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
@REM All rights reserved.
@REM
@REM This project is free software; you can redistribute it and/or
@REM modify it under the terms of the GNU Lesser General Public
@REM License as published by the Free Software Foundation; either
@REM version 3.0 of the License, or (at your option) any later version.
@REM This library is distributed in the hope that it will be useful,
@REM but WITHOUT ANY WARRANTY; without even the implied warranty of
@REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@REM Lesser General Public License for more details.
@REM
@REM You should have received a copy of the GNU Lesser General Public
@REM License along with this project. If not, see <http://www.gnu.org/licenses/>.
@REM *******************************************************************************
@REM
pushd %~dp0..
call mvn clean install -s "settings.xml"
cd target
ren "rmi-model-server-*-jar-with-dependencies.jar" "rmi-model-server.jar"
copy "rmi-model-server.jar" "..\install"
popd
\ No newline at end of file
#!/bin/bash
#
#
# ******************************************************************************
# MontiCAR Modeling Family, www.se-rwth.de
# Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
# All rights reserved.
#
# This project is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this project. If not, see <http://www.gnu.org/licenses/>.
# *******************************************************************************
#
cd ..
mvn clean install -s settings.xml -DskipTests
cd target
cp rmi-model-server-*-jar-with-dependencies.jar ../install/rmi-model-server.jar
......@@ -82,106 +82,7 @@
</profile>
<profile>
<id>se-nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled /></releases>
<snapshots><enabled /></snapshots>
</repository>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>eclipse</id>
<url>https://repo.eclipse.org/content/groups/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>topobyte</id>
<url>http://mvn.topobyte.de/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled /></releases>
<snapshots><enabled /></snapshots>
</pluginRepository>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>eclipse</id>
<url>https://repo.eclipse.org/content/groups/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>topobyte</id>
<url>http://mvn.topobyte.de/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
......
......@@ -18,10 +18,10 @@
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package rwth.rmi.model.server;
package de.rwth.monticore.EmbeddedMontiArc.simulators.rmimodelserver;
import org.I0Itec.zkclient.ZkClient;
import simulator.integration.HardwareEmulatorInterface;
import de.rwth.monticore.EmbeddedMontiArc.simulators.hardware_emulator.HardwareEmulatorInterface;
import java.io.File;
import java.io.IOException;
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package rwth.rmi.model.server.interfaces;
import java.rmi.AlreadyBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.io.Serializable;
import java.util.HashMap;
public interface RMIManager extends Remote {
public int alloc_autopilot(String config) throws RemoteException;
public void free_autopilot(int id) throws RemoteException;
public void update_bus(int id, HashMap<String, Serializable> inputs) throws RemoteException;
public HashMap<String, Serializable> old_execute(int id, long time_delta, HashMap<String, Serializable> inputs) throws RemoteException;
public void start_tick(long time_delta) throws RemoteException;
public void end_tick() throws RemoteException;
public HashMap<String, Serializable> get_outputs(int id) throws RemoteException;
public String query(String msg) throws RemoteException;
public String query_autopilot(int id, String msg) throws RemoteException;
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package simulator.integration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.io.Serializable;
import rwth.rmi.model.server.interfaces.RMIManager;
import commons.utils.LibraryService;
public class HardwareEmulatorInterface implements RMIManager {
String lib_path = "";
public HardwareEmulatorInterface(String emu_config, String default_config) throws LibraryService.LibraryException, Exception {
super();
load_library();
if (!init(emu_config, default_config)){
String error_msg = query("get_error_msg");
throw new Exception("Error initializing the HardwareEmulator: " + error_msg);
}
}
public void load_library() throws LibraryService.LibraryException {
//Use LibraryService to get the library from resources to the working directory (if not already there)
String system_library_name = LibraryService.getSystemLibraryName("HardwareEmulator");
LibraryService.prepareLibrary(system_library_name);
//Load the library
lib_path = LibraryService.getWorkingDirectory() + system_library_name;
System.load(lib_path);
//System.out.println("LibPath: " + lib_path);
}
public File get_library(){
return new File(lib_path);
}
private native boolean init(String config, String default_config);
@Override
public native int alloc_autopilot(String config);
@Override
public native void free_autopilot(int id);
@Override
public void update_bus(int id, HashMap<String, Serializable> inputs){
for (HashMap.Entry<String, Serializable> entry : inputs.entrySet()){
add_one_input(id, entry.getKey(), entry.getValue());
}
}
@Override
public HashMap<String, Serializable> old_execute(int id, long time_delta, HashMap<String, Serializable> inputs){
for (HashMap.Entry<String, Serializable> entry : inputs.entrySet()){
add_one_input(id, entry.getKey(), entry.getValue());
}
execute_one(id, time_delta);
HashMap<String, Serializable> outputs = new HashMap<String, Serializable>();
query_outputs(id, outputs);
return outputs;
}
private native void execute_one(int id, long time_delta);
@Override
public native void start_tick(long time_delta);
@Override
public native void end_tick();
@Override
public HashMap<String, Serializable> get_outputs(int id) {
HashMap<String, Serializable> outputs = new HashMap<String, Serializable>();
query_outputs(id, outputs);
return outputs;
}
@Override
public native String query(String msg);
@Override
public native String query_autopilot(int id, String msg);
private native void add_one_input(int id, String key, Serializable value);
private native void query_outputs(int id, HashMap<String, Serializable> opaque_hashmap);
private void add_one_output(HashMap<String, Serializable> opaque_hashmap, String key, Serializable value) {
opaque_hashmap.put(key, value);
}
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package simulator.integration;
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