Merge remote-tracking branch 'origin/master'
# Conflicts: # src/Main.java
This commit is contained in:
11
.idea/libraries/google_code_gson.xml
generated
Normal file
11
.idea/libraries/google_code_gson.xml
generated
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="google.code.gson" type="repository">
|
||||||
|
<properties maven-id="com.google.code.gson:gson:2.11.0" />
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.11.0/gson-2.11.0.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.27.0/error_prone_annotations-2.27.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
@@ -20,5 +20,6 @@
|
|||||||
<orderEntry type="library" name="tinylog" level="project" />
|
<orderEntry type="library" name="tinylog" level="project" />
|
||||||
<orderEntry type="library" name="io.javalin" level="project" />
|
<orderEntry type="library" name="io.javalin" level="project" />
|
||||||
<orderEntry type="library" name="projectlombok.lombok" level="project" />
|
<orderEntry type="library" name="projectlombok.lombok" level="project" />
|
||||||
|
<orderEntry type="library" name="google.code.gson" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -1,19 +1,65 @@
|
|||||||
import AASMini.AASMini;
|
import AASMini.AASMini;
|
||||||
|
import ProtegeGX.ProtegeGX;
|
||||||
|
import Web.WebResponse;
|
||||||
|
import Web.WebServer;
|
||||||
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private static AASMini aas;
|
private static AASMini aas;
|
||||||
|
private static ProtegeGX protegeGX;
|
||||||
|
private static WebServer web;
|
||||||
private static String aasIP = "192.168.10.10";
|
private static String aasIP = "192.168.10.10";
|
||||||
private static int aasPort = 8080;
|
private static int aasPort = 5000;
|
||||||
|
private static int webPort = 8080;
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
GetArguments(args);
|
||||||
public void run() {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
System.out.println("Shutting down...");
|
System.out.println("Shutting down...");
|
||||||
if (aas!=null) aas.Disconnect();
|
if (aas!=null) aas.Disconnect();
|
||||||
|
if (protegeGX!=null) protegeGX.Disconnect();
|
||||||
|
if (web!=null) web.Stop();
|
||||||
|
}));
|
||||||
|
|
||||||
|
System.out.println("Protege to AAS Mini Connector");
|
||||||
|
|
||||||
|
protegeGX = new ProtegeGX();
|
||||||
|
protegeGX.setOnCardRead(data -> {
|
||||||
|
Logger.info(data);
|
||||||
|
if (aas!=null && aas.IsConnected()){
|
||||||
|
// send something to AAS
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
System.out.println("Protege to AAS Mini Connector");
|
|
||||||
aas = new AASMini(aasIP, aasPort);
|
aas = new AASMini(aasIP, aasPort);
|
||||||
aas.Connect();
|
aas.Connect();
|
||||||
|
|
||||||
|
web = new WebServer();
|
||||||
|
web.Start(webPort);
|
||||||
|
web.setAasAPI(data -> {
|
||||||
|
Logger.info(data);
|
||||||
|
// Do something with AAS
|
||||||
|
WebResponse wr = new WebResponse();
|
||||||
|
return wr;
|
||||||
|
});
|
||||||
|
web.setProtegeGXAPI(data -> {
|
||||||
|
Logger.info(data);
|
||||||
|
// Do something with ProtegeGX
|
||||||
|
WebResponse wr = new WebResponse();
|
||||||
|
return wr;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GetArguments(String[] args){
|
||||||
|
for(String arg: args){
|
||||||
|
if (arg.startsWith("-aasip=")){
|
||||||
|
aasIP = arg.substring(7);
|
||||||
|
}
|
||||||
|
if (arg.startsWith("-aasport=")){
|
||||||
|
aasPort = Integer.parseInt(arg.substring(9));
|
||||||
|
}
|
||||||
|
if (arg.startsWith("-webport=")){
|
||||||
|
webPort = Integer.parseInt(arg.substring(9));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
12
src/Web/WebRequest.java
Normal file
12
src/Web/WebRequest.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package Web;
|
||||||
|
|
||||||
|
public class WebRequest {
|
||||||
|
public String command;
|
||||||
|
public String data;
|
||||||
|
public String additional;
|
||||||
|
public WebRequest(){
|
||||||
|
command = "";
|
||||||
|
data = "";
|
||||||
|
additional = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/Web/WebResponse.java
Normal file
12
src/Web/WebResponse.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package Web;
|
||||||
|
|
||||||
|
public class WebResponse {
|
||||||
|
public String reply;
|
||||||
|
public String data;
|
||||||
|
public String additional;
|
||||||
|
public WebResponse(){
|
||||||
|
reply = "";
|
||||||
|
data = "";
|
||||||
|
additional = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,31 @@
|
|||||||
package Web;
|
package Web;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static io.javalin.apibuilder.ApiBuilder.get;
|
import static io.javalin.apibuilder.ApiBuilder.*;
|
||||||
import static io.javalin.apibuilder.ApiBuilder.path;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class WebServer {
|
public class WebServer {
|
||||||
@Setter private Consumer<String> aasAPI;
|
@Setter private Function<WebRequest, WebResponse> aasAPI;
|
||||||
@Setter private Consumer<String> protegeGXAPI;
|
@Setter private Function<WebRequest, WebResponse> protegeGXAPI;
|
||||||
|
private final Gson gson = new Gson();
|
||||||
|
|
||||||
private void updateAASAPI(String data){
|
private WebResponse ProcessAAS(WebRequest request){
|
||||||
if (aasAPI!=null) aasAPI.accept(data);
|
if (aasAPI!=null){
|
||||||
|
return aasAPI.apply(request);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProtegeGXAPI(String data){
|
private WebResponse ProcessProtegeGX(WebRequest request){
|
||||||
if (protegeGXAPI!=null) protegeGXAPI.accept(data);
|
if (protegeGXAPI!=null){
|
||||||
|
return protegeGXAPI.apply(request);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Javalin app;
|
Javalin app;
|
||||||
@@ -31,11 +38,41 @@ public class WebServer {
|
|||||||
path("aasmini", ()->{
|
path("aasmini", ()->{
|
||||||
//TODO implement API for AAS Mini
|
//TODO implement API for AAS Mini
|
||||||
get(ctx -> ctx.result("AAS Mini API"));
|
get(ctx -> ctx.result("AAS Mini API"));
|
||||||
|
post(ctx -> {
|
||||||
|
try{
|
||||||
|
WebRequest request = gson.fromJson(ctx.body(), WebRequest.class);
|
||||||
|
WebResponse response = ProcessAAS(request);
|
||||||
|
if (response!=null){
|
||||||
|
ctx.result(gson.toJson(response));
|
||||||
|
} else {
|
||||||
|
ctx.status(400);
|
||||||
|
ctx.result("No response from AAS Mini");
|
||||||
|
}
|
||||||
|
} catch(Exception e){
|
||||||
|
ctx.status(400);
|
||||||
|
ctx.result("Exception: "+e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
// API for ProtegeGX
|
// API for ProtegeGX
|
||||||
path("protegegx", ()->{
|
path("protegegx", ()->{
|
||||||
//TODO implement API for ProtegeGX
|
//TODO implement API for ProtegeGX
|
||||||
get(ctx -> ctx.result("ProtegeGX API"));
|
get(ctx -> ctx.result("ProtegeGX API"));
|
||||||
|
post(ctx -> {
|
||||||
|
try{
|
||||||
|
WebRequest request = gson.fromJson(ctx.body(), WebRequest.class);
|
||||||
|
WebResponse response = ProcessProtegeGX(request);
|
||||||
|
if (response!=null){
|
||||||
|
ctx.result(gson.toJson(response));
|
||||||
|
} else {
|
||||||
|
ctx.status(400);
|
||||||
|
ctx.result("No response from ProtegeGX");
|
||||||
|
}
|
||||||
|
} catch(Exception e){
|
||||||
|
ctx.status(400);
|
||||||
|
ctx.result("Exception: "+e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user