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

fake-code erweitert

parent 997aa9c8
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import ipos.models.SimpleScene; ...@@ -4,6 +4,7 @@ import ipos.models.SimpleScene;
import ipos.project.DataModellntegration.SimpleSceneIntegration.service.SimpleSceneTransformer; import ipos.project.DataModellntegration.SimpleSceneIntegration.service.SimpleSceneTransformer;
import ipos.project.DataModellntegration.SimpleSceneIntegration.service.impl.ExternalPubServiceImpl; 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.mapper.ProtoJsonMap;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -33,16 +34,19 @@ public class SimpleSceneIntegration { ...@@ -33,16 +34,19 @@ public class SimpleSceneIntegration {
} }
}*/ }*/
public static void receiveMessage(PositionEvent positionEvent, String monitoringTaskId) { public static void receiveMessage(PositionEvent positionEvent, String monitoringTaskId, String type) {
LOG.info("receiveMessage get: " + positionEvent); LOG.info("receiveMessage get: " + positionEvent);
//String jsonPos = ProtoJsonMap.toJson(positionEvent); // we can translate a class into a string using several methods: 1) `.toString()` 2) `JsonFormat` in `ProtoJsonMap` //String jsonPos = ProtoJsonMap.toJson(positionEvent); // we can translate a class into a string using several methods: 1) `.toString()` 2) `JsonFormat` in `ProtoJsonMap`
if (positionEvent != null) { if (positionEvent != null) {
LOG.info("received internal-positionEvent: monitoringTaskId: " + monitoringTaskId + " positionEvent: " + positionEvent.toString()); LOG.info("received internal-positionEvent: monitoringTaskId: " + monitoringTaskId + " positionEvent: " + positionEvent.toString());
SimpleScene.IposPositionEvent posEvent_proto = SimpleSceneTransformer.posEvent_internal2Proto(positionEvent); SimpleScene.IposPositionEvent posEvent_proto = SimpleSceneTransformer.posEvent_internal2Proto(positionEvent, type);
LOG.info("obtained protobuf-positionEvent:" + posEvent_proto.toString()); LOG.info("obtained protobuf-positionEvent:" + posEvent_proto.toString());
MqttMessage mqttMessage = mqttService.createMqttMsg(posEvent_proto, 0, false); MqttMessage mqttMessage = mqttService.createMqttMsg(posEvent_proto, 0, false);
LOG.info("publishing mqttMessage:" + mqttMessage.toString() + " on topic: " + monitoringTaskId); LOG.info("publishing mqttMessage:" + mqttMessage.toString() + " on topic: " + monitoringTaskId);
mqttService.publish(monitoringTaskId, mqttMessage); mqttService.publish(monitoringTaskId, mqttMessage);
// JSON-Versand... LOG.info("publishing mqttMessage:" + ProtoJsonMap.toJson(posEvent_proto) + " on topic: " + monitoringTaskId);
// mqttService.publish(monitoringTaskId, ProtoJsonMap.toJson(posEvent_proto), 0, false);
}else{ }else{
LOG.debug("Warning: SimpleScene: Received empty PositionEvent"); LOG.debug("Warning: SimpleScene: Received empty PositionEvent");
} }
......
...@@ -40,7 +40,7 @@ public class SimpleSceneTransformer { ...@@ -40,7 +40,7 @@ public class SimpleSceneTransformer {
return null; return null;
} }
public static SimpleScene.IposPositionEvent posEvent_internal2Proto(PositionEvent internalPosEvent){ public static SimpleScene.IposPositionEvent posEvent_internal2Proto(PositionEvent internalPosEvent, String type){
LocalizableObject lObject = PositionMonitoring.getLObjectByIdOrNull(internalPosEvent.getSensorId()); LocalizableObject lObject = PositionMonitoring.getLObjectByIdOrNull(internalPosEvent.getSensorId());
if (null == lObject || null == lObject.getAgent()) { if (null == lObject || null == lObject.getAgent()) {
LOG.error("Internal-PositionEvent could not be transformed into protobuf-format. " + LOG.error("Internal-PositionEvent could not be transformed into protobuf-format. " +
...@@ -48,22 +48,33 @@ public class SimpleSceneTransformer { ...@@ -48,22 +48,33 @@ public class SimpleSceneTransformer {
"is associated to the LocalizableObject that has been found."); "is associated to the LocalizableObject that has been found.");
return null; return null;
} }
SimpleScene.IposPoint3D.Builder protoPoint3D = transformIntoProtoPoint3D(internalPosEvent); SimpleScene.IposPoint3D.Builder protoPoint3D = transformIntoProtoPoint3D(internalPosEvent);
SimpleScene.IposPosition.Builder protoIposPosition = transformIntoProtoIposPosition(internalPosEvent, protoPoint3D); SimpleScene.IposPosition.Builder protoIposPosition = transformIntoProtoIposPosition(internalPosEvent, protoPoint3D);
SimpleScene.IposSimpleOrientation.Builder protoOrientation = transformIntoProtoOrientation(internalPosEvent); SimpleScene.IposSimpleOrientation.Builder protoOrientation = transformIntoProtoOrientation(internalPosEvent);
SimpleScene.IposObject.Builder protoIposObject = transformIntoProtoObject(internalPosEvent, type, lObject, protoIposPosition, protoOrientation);
SimpleScene.IposPositionEvent.Builder protoIposPosEvent = transformIntoProtoIposPosEvent(type, protoIposObject);
return protoIposPosEvent.build();
}
private static SimpleScene.IposPositionEvent.Builder transformIntoProtoIposPosEvent(String type, SimpleScene.IposObject.Builder protoIposObject) {
SimpleScene.IposPositionEvent.Builder protoIposPosEvent = SimpleScene.IposPositionEvent.newBuilder();
if (!"undefined".equals(type)) {
protoIposPosEvent.setType(type);
}
protoIposPosEvent.addObject(protoIposObject);
return protoIposPosEvent;
}
private static SimpleScene.IposObject.Builder transformIntoProtoObject(PositionEvent internalPosEvent, String type, LocalizableObject lObject, SimpleScene.IposPosition.Builder protoIposPosition, SimpleScene.IposSimpleOrientation.Builder protoOrientation) {
SimpleScene.IposObject.Builder protoIposObject = SimpleScene.IposObject.newBuilder(); SimpleScene.IposObject.Builder protoIposObject = SimpleScene.IposObject.newBuilder();
protoIposObject.setSensorId(lObject.getId()).setSensorType(lObject.getSensorType()).setId(lObject.getAgent().getId()).setType(lObject.getAgent().getAgentType()).setOrientation(protoOrientation).setPosition(protoIposPosition).setLastPosUpdate(internalPosEvent.getTimeStamp()); protoIposObject.setSensorId(lObject.getId()).setSensorType(lObject.getSensorType()).setId(lObject.getAgent().getId()).setType(lObject.getAgent().getAgentType()).setOrientation(protoOrientation).setPosition(protoIposPosition).setLastPosUpdate(internalPosEvent.getTimeStamp());
return protoIposObject;
SimpleScene.IposPositionEvent.Builder protoIPosEvent = SimpleScene.IposPositionEvent.newBuilder();
protoIPosEvent.addObject(protoIposObject);
return protoIPosEvent.build();
} }
private static SimpleScene.IposSimpleOrientation.Builder transformIntoProtoOrientation(PositionEvent internalPosEvent) { private static SimpleScene.IposSimpleOrientation.Builder transformIntoProtoOrientation(PositionEvent internalPosEvent) {
SimpleScene.IposSimpleOrientation.Builder protoOrientation = SimpleScene.IposSimpleOrientation.newBuilder(); SimpleScene.IposSimpleOrientation.Builder protoOrientation = SimpleScene.IposSimpleOrientation.newBuilder();
Quaternion internalOrientation = (Quaternion) internalPosEvent.getPlacing().getOrientation(); Quaternion internalOrientation = (Quaternion) internalPosEvent.getPlacing().getOrientation();
protoOrientation.setX(internalOrientation.getX()).setY(internalOrientation.getY()).setZ(internalOrientation.getZ()); protoOrientation.setX(internalOrientation.getX()).setY(internalOrientation.getY()).setZ(internalOrientation.getZ()).setW(internalOrientation.getW());
return protoOrientation; return protoOrientation;
} }
......
...@@ -181,16 +181,66 @@ public class PositionMonitoring { ...@@ -181,16 +181,66 @@ public class PositionMonitoring {
eventFilters.add(filter); eventFilters.add(filter);
} }
private static boolean isDoor = false;
private static boolean isCentre = false;
private static boolean isWindow = false;
private static boolean firstMessage = true;
// @JmsListener(destination = "/PositionEvent", containerFactory = "jmsListenFactory") // @JmsListener(destination = "/PositionEvent", containerFactory = "jmsListenFactory")
public static void receiveMessage(PositionEvent posEvent) { public static void receiveMessage(PositionEvent posEvent) {
LOG.info("Received <" + posEvent + ">"); LOG.info("Received <" + posEvent + ">");
String taskIdWindow = "Human_at_Window_Side"; String taskIdWindow = "Human_at_Window_Side";
String taskIdDoor = "Human_at_Door_Side"; String taskIdDoor = "Human_at_Door_Side";
String type = "undefined"; // definition: if undefined, type-attribute in protobuf-message will not be set
float y_coordinate = ((Point3D) posEvent.getPlacing().getPosition().getPoint()).getY(); float y_coordinate = ((Point3D) posEvent.getPlacing().getPosition().getPoint()).getY();
if (y_coordinate > 2.08f){ // Achtung, Entry- und Exit-Notification müssten eigentlich Personengebunden sein
SimpleSceneIntegration.receiveMessage(posEvent, taskIdWindow); if (y_coordinate <= 2.08f){
isDoor = true;
if (isCentre == true){
isCentre = false;
type = "EntryNotification";
} else
if (isWindow == true){
isWindow = false;
type = "SwitchNotification"; // note: Event will be sent to the topic of the zone that the agent switched into
} else
if (firstMessage){
firstMessage = false;
type = "EntryNotification";
}
SimpleSceneIntegration.receiveMessage(posEvent, taskIdDoor, type);
}
else if (y_coordinate > 2.08f && y_coordinate <= 2.5f){
isCentre = true;
if (isDoor == true){
isDoor = false;
type = "ExitNotification";
SimpleSceneIntegration.receiveMessage(posEvent, taskIdDoor, type); // previous zone was door: ExitNotification is sent for this zone
} else
if (isWindow == true){
isWindow = false;
type = "ExitNotification";
SimpleSceneIntegration.receiveMessage(posEvent, taskIdWindow, type);
} else
if (firstMessage){
firstMessage = false;
}
}else{ }else{
SimpleSceneIntegration.receiveMessage(posEvent, taskIdDoor); isWindow = true;
if (isCentre == true){
isCentre = false;
type = "EntryNotification";
} else
if (isDoor == true){
isDoor = false;
type = "SwitchNotification";
} else
if (firstMessage){
firstMessage = false;
type = "EntryNotification";
}
SimpleSceneIntegration.receiveMessage(posEvent, taskIdWindow, type);
} }
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment