Skip to content
Snippets Groups Projects
Commit 3c34f8ab authored by FrankR's avatar FrankR
Browse files

added much fake-functionality for demo

parent 8853a958
No related branches found
No related tags found
No related merge requests found
...@@ -14,8 +14,13 @@ import org.springframework.stereotype.Component; ...@@ -14,8 +14,13 @@ import org.springframework.stereotype.Component;
public class SimpleSceneIntegration { public class SimpleSceneIntegration {
private final Logger LOG = LoggerFactory.getLogger(getClass()); private final Logger LOG = LoggerFactory.getLogger(getClass());
//@Autowired
public static ExternalPubServiceImpl mqttService;
@Autowired @Autowired
private static ExternalPubServiceImpl mqttService; public SimpleSceneIntegration(ExternalPubServiceImpl mqttService_){
mqttService = mqttService_;
}
/* /*
@JmsListener(destination = "/positions", containerFactory = "jmsListenFactory") @JmsListener(destination = "/positions", containerFactory = "jmsListenFactory")
...@@ -28,14 +33,21 @@ public class SimpleSceneIntegration { ...@@ -28,14 +33,21 @@ public class SimpleSceneIntegration {
} }
}*/ }*/
public static void receiveMessage(PositionEvent positionEvent) { public static void receiveMessage(PositionEvent positionEvent, String monitoringTaskId) {
// LOG.trace("Data integration get: " + pos); // LOG.trace("Data integration get: " + pos);
System.out.println("SimpleSceneIntegration: Data integration get: " + positionEvent); System.out.println("SimpleSceneIntegration: Data integration get: " + positionEvent);
// we can translate a class into a string using several methods: 1) `.toString()` 2) `JsonFormat` in `ProtoJsonMap` // we can translate a class into a string using several methods: 1) `.toString()` 2) `JsonFormat` in `ProtoJsonMap`
//String jsonPos = ProtoJsonMap.toJson(positionEvent); //String jsonPos = ProtoJsonMap.toJson(positionEvent);
// TODO: Transform Internal-PositionEvent to Protobuf-SensorPositionEvent // TODO: Transform Internal-PositionEvent to Protobuf-SensorPositionEvent
if (positionEvent != null) { if (positionEvent != null) {
mqttService.publish("usertopic/SensorPositionEvent", positionEvent.toString(), 0, false); System.out.println("SimpleSceneIntegration: mqtt-message will be published: monitoringTaskId: " + monitoringTaskId + " positionEvent: " + positionEvent.toString());
if (null == mqttService) {
System.out.println("Warning: SimpleSceneIntegration: mqttService is null");
}
// getsensorId, load sensor-type, agent-type, agent-id and create IposPositionEvent
// SimpleSceneTransformer.posEvent_internal2Proto();
mqttService.publish(monitoringTaskId, positionEvent.toString(), 0, false);
}else{ }else{
System.out.println("Warning: SimpleScene: Received empty PositionEvent"); System.out.println("Warning: SimpleScene: Received empty PositionEvent");
} }
......
...@@ -24,7 +24,7 @@ public class readConfig { ...@@ -24,7 +24,7 @@ public class readConfig {
config.setPositionConditionCell(transformZone2PositionConditionCell(zone_monReq)); config.setPositionConditionCell(transformZone2PositionConditionCell(zone_monReq));
} }
private static ArrayList<Float[][]> transformZone2PositionConditionCell(Zone zone) { public static ArrayList<Float[][]> transformZone2PositionConditionCell(Zone zone) {
// TODO: support Point-Types other than Point3D // TODO: support Point-Types other than Point3D
ArrayList<Float[][]> position_condition_cell = new ArrayList<>(); ArrayList<Float[][]> position_condition_cell = new ArrayList<>();
for (var space : zone.getSpace()) { for (var space : zone.getSpace()) {
......
package ipos.project; package ipos.project;
import ipos.project.DataModellntegration.SimpleSceneIntegration.SimpleSceneIntegration;
import ipos.project.Functionality.eventfilter.TestEventFilter; import ipos.project.Functionality.eventfilter.TestEventFilter;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
...@@ -16,5 +17,10 @@ public class MainApp { ...@@ -16,5 +17,10 @@ public class MainApp {
public static void main(String[] args) throws ParseException { public static void main(String[] args) throws ParseException {
// TestEventFilter.test(); // TestEventFilter.test();
SpringApplication.run(MainApp.class, args); SpringApplication.run(MainApp.class, args);
System.out.println("MainApp: Attempting to send mqtt-testmessage");
SimpleSceneIntegration.mqttService.publish("UWB", "Testnachricht", 0, false);
SimpleSceneIntegration.mqttService.publish("Human_at_Window_Side", "Testnachricht", 0, false);
SimpleSceneIntegration.mqttService.publish("Human_at_Door_Side", "Testnachricht", 0, false);
System.out.println("sent mqtt-testmessage");
} }
} }
...@@ -4,6 +4,7 @@ import com.google.protobuf.InvalidProtocolBufferException; ...@@ -4,6 +4,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
import ipos.models.GenericSensor.SensorPositionEvent; import ipos.models.GenericSensor.SensorPositionEvent;
import ipos.models.SimpleScene.IposPosition; import ipos.models.SimpleScene.IposPosition;
import ipos.models.GenericSensor.SensorEventWrapper; import ipos.models.GenericSensor.SensorEventWrapper;
import ipos.project.DataModellntegration.SimpleSceneIntegration.service.impl.ExternalPubServiceImpl;
import ipos.project.DataModellntegration.iPos_Datamodel.PositionEvent; import ipos.project.DataModellntegration.iPos_Datamodel.PositionEvent;
import ipos.project.SensorValueIntegration.Service.GenericSensorTransformer; import ipos.project.SensorValueIntegration.Service.GenericSensorTransformer;
import ipos.project.UseCaseController.PositionMonitoring; import ipos.project.UseCaseController.PositionMonitoring;
...@@ -29,6 +30,9 @@ public class MqttPositionHandler implements Handler { ...@@ -29,6 +30,9 @@ public class MqttPositionHandler implements Handler {
this.jmsTemplate = jmsTemplate; this.jmsTemplate = jmsTemplate;
} }
// @Autowired
// private ExternalPubServiceImpl mqttService;
// method that handle new message from the topic // method that handle new message from the topic
public void handle(MqttMessage message) { public void handle(MqttMessage message) {
try { try {
...@@ -38,9 +42,19 @@ public class MqttPositionHandler implements Handler { ...@@ -38,9 +42,19 @@ public class MqttPositionHandler implements Handler {
//IposPosition pos = IposPosition.parseFrom(message.toString().getBytes()); //IposPosition pos = IposPosition.parseFrom(message.toString().getBytes());
assert protoSensPosEvent != null; assert protoSensPosEvent != null;
LOG.info("SensorPositionEvent received: \n" + protoSensPosEvent); LOG.info("SensorPositionEvent received: \n" + protoSensPosEvent);
System.out.println("SimpleSceneIntegration: Proto-Point: " + protoSensPosEvent.getPosition().getPoint().toString());
PositionEvent positionEvent = GenericSensorTransformer.posEvent_GSensor2Internal(protoSensPosEvent); PositionEvent positionEvent = GenericSensorTransformer.posEvent_GSensor2Internal(protoSensPosEvent);
System.out.println("Transformed Protobuf-SensorPositionEvent into Internal-PositionEvent: " + positionEvent.toString() + ", " + positionEvent.getPlacing().getPosition().getPoint().toString() + ", " + positionEvent.getPlacing().getOrientation().toString()); System.out.println("SimpleSceneIntegration: Internal-Point: " + positionEvent.getPlacing().getPosition().getPoint().toString());
System.out.println("SensorValueIntegration: Transformed Protobuf-SensorPositionEvent into Internal-PositionEvent: " + positionEvent.toString() + ", " + positionEvent.getPlacing().getPosition().getPoint().toString() + ", " + positionEvent.getPlacing().getOrientation().toString());
/* System.out.println("Sending Internal-PositionEvent using mqttService");
if (null == mqttService)
System.out.println("SimpleSceneIntegration: mqttService is null");
else
System.out.println("SimpleSceneIntegration: mqttService is not null");
mqttService.publish("Human_at_Window_Side", positionEvent.toString(), 0, false);
*/
// ggf. anstatt JMS einfach den PositionMonitoringController per Funktionsaufruf aufrufen // ggf. anstatt JMS einfach den PositionMonitoringController per Funktionsaufruf aufrufen
PositionMonitoring.receiveMessage(positionEvent); PositionMonitoring.receiveMessage(positionEvent);
// this.jmsTemplate.convertAndSend("/PositionEvent", protoSensPosEvent); // submit position to the internal broker // this.jmsTemplate.convertAndSend("/PositionEvent", protoSensPosEvent); // submit position to the internal broker
......
...@@ -34,6 +34,42 @@ public class PositionMonitoring { ...@@ -34,6 +34,42 @@ public class PositionMonitoring {
wm.getZoneMap().get(0).getZone().add(createZone("cobot1_warning_zone", "cobot1_warning_zone", spaces)); wm.getZoneMap().get(0).getZone().add(createZone("cobot1_warning_zone", "cobot1_warning_zone", spaces));
wm.getAgent().add(createAgent("Employee1", "HUMAN")); wm.getAgent().add(createAgent("Employee1", "HUMAN"));
wm.getAgent().get(0).getLObject().add(createLobject("UWB_1", "UWB", wm.getAgent().get(0), null)); wm.getAgent().get(0).getLObject().add(createLobject("UWB_1", "UWB", wm.getAgent().get(0), null));
initEventFiltersForDemo();
}
private void initEventFiltersForDemo(){
String taskIdWindow = "Human_at_Window_Side";
String taskIdDoor = "Human_at_Door_Side";
ReferenceSystem rootRefSystem = createReferenceSystem("ROOT", "ROOT", null);
eventFilter filterWindow = createWindowZoneEventFilter(taskIdWindow, rootRefSystem);
eventFilter filterDoor = createDoorZoneEventFilter(taskIdDoor, rootRefSystem);
eventFilters.add(filterDoor);
eventFilters.add(filterWindow);
}
private eventFilter createWindowZoneEventFilter(String monitoringTaskId, ReferenceSystem rootRefSystem){
Space windowSpace = createSpace(2.0f, 2.0f, 2.0f, createPlacing(createPosition(createPoint3D(2.0f, 4.0f, 0f), 1f, rootRefSystem), createOrientation(0f, 0f, 0f, 0f)));
Zone windowZone = createZone("cobot1_window_zone", "cobot1_window_zone", Arrays.asList(windowSpace));
return createEventFilter(monitoringTaskId, windowZone);
}
private eventFilter createDoorZoneEventFilter(String monitoringTaskId, ReferenceSystem rootRefSystem){
Space windowSpace = createSpace(2.0f, 2.0f, 2.0f, createPlacing(createPosition(createPoint3D(2.0f, 0.0f, 0f), 1f, rootRefSystem), createOrientation(0f, 0f, 0f, 0f)));
Zone windowZone = createZone("cobot1_door_zone", "cobot1_door_zone", Arrays.asList(windowSpace));
return createEventFilter(monitoringTaskId, windowZone);
}
private eventFilter createEventFilter(String monitoringTaskId, Zone zone){
eventFilter filter = new eventFilter(monitoringTaskId);
filter.setWM(wm);
EventFilterCondition config = modelFactory.createEventFilterCondition();
readConfig.setWM(wm);
config.setFilterStructure(new boolean[] {false, false, false, false, false, false, false, false, true});
config.setPositionConditionCell(readConfig.transformZone2PositionConditionCell(zone));
//readConfig.readFilterConfigFromMonitoringRequest(monReq, config);
filter.init(config);
return filter;
} }
private POI createPOI(Position position, String description, Map<String, String> data){ private POI createPOI(Position position, String description, Map<String, String> data){
...@@ -142,9 +178,14 @@ public class PositionMonitoring { ...@@ -142,9 +178,14 @@ public class PositionMonitoring {
public static void receiveMessage(PositionEvent posEvent) { public static void receiveMessage(PositionEvent posEvent) {
// LOG.info("Received <" + posEvent + ">"); // LOG.info("Received <" + posEvent + ">");
System.out.println("MonitoringController: Received <" + posEvent.toString() + ">"); System.out.println("MonitoringController: Received <" + posEvent.toString() + ">");
eventFilter filterWindow = new eventFilter("Human_at_Window_Side"); String taskIdWindow = "Human_at_Window_Side";
eventFilter filterDoor = new eventFilter("Human_at_Door_Side"); String taskIdDoor = "Human_at_Door_Side";
SimpleSceneIntegration.receiveMessage(posEvent); float y_coordinate = ((Point3D) posEvent.getPlacing().getPosition().getPoint()).getY();
if (y_coordinate > 2.08f){
SimpleSceneIntegration.receiveMessage(posEvent, taskIdWindow);
}else{
SimpleSceneIntegration.receiveMessage(posEvent, taskIdDoor);
}
/* /*
for (eventFilter eFilter : eventFilters){ for (eventFilter eFilter : eventFilters){
......
...@@ -10,8 +10,9 @@ mqtt: ...@@ -10,8 +10,9 @@ mqtt:
cleanSession: true cleanSession: true
setKeepAliveInterval: 10 setKeepAliveInterval: 10
connectionTimeout: 20 connectionTimeout: 20
clientId: ipos.project clientId: ipos.project.fw
hostname: broker.hivemq.com hostname: 192.168.0.192
# hostname: broker.hivemq.com
port: 1883 port: 1883
spring: spring:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment