diff --git a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java index c79e5ffe6dc83c43ba93dc4ee786afdf8fdbec3a..d03f4b301c2efe365e2bb7cb822d7cbd8d6e1f53 100644 --- a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java +++ b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java @@ -4,6 +4,7 @@ import ipos.models.SimpleScene; import ipos.project.DataModellntegration.SimpleSceneIntegration.service.SimpleSceneTransformer; import ipos.project.DataModellntegration.SimpleSceneIntegration.service.impl.ExternalPubServiceImpl; import ipos.project.DataModellntegration.iPos_Datamodel.PositionEvent; +import ipos.project.mapper.ProtoJsonMap; import org.apache.logging.log4j.LogManager; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.springframework.beans.factory.annotation.Autowired; @@ -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); //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) { 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()); MqttMessage mqttMessage = mqttService.createMqttMsg(posEvent_proto, 0, false); LOG.info("publishing mqttMessage:" + mqttMessage.toString() + " on topic: " + monitoringTaskId); 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{ LOG.debug("Warning: SimpleScene: Received empty PositionEvent"); } diff --git a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/service/SimpleSceneTransformer.java b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/service/SimpleSceneTransformer.java index 0c9c7dba881a55547cd71ef42440ecbaaf986930..46ea341338d849c91b328179d5c7e69484404c30 100644 --- a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/service/SimpleSceneTransformer.java +++ b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/service/SimpleSceneTransformer.java @@ -40,7 +40,7 @@ public class SimpleSceneTransformer { 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()); if (null == lObject || null == lObject.getAgent()) { LOG.error("Internal-PositionEvent could not be transformed into protobuf-format. " + @@ -48,22 +48,33 @@ public class SimpleSceneTransformer { "is associated to the LocalizableObject that has been found."); return null; } - SimpleScene.IposPoint3D.Builder protoPoint3D = transformIntoProtoPoint3D(internalPosEvent); SimpleScene.IposPosition.Builder protoIposPosition = transformIntoProtoIposPosition(internalPosEvent, protoPoint3D); 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(); protoIposObject.setSensorId(lObject.getId()).setSensorType(lObject.getSensorType()).setId(lObject.getAgent().getId()).setType(lObject.getAgent().getAgentType()).setOrientation(protoOrientation).setPosition(protoIposPosition).setLastPosUpdate(internalPosEvent.getTimeStamp()); - - SimpleScene.IposPositionEvent.Builder protoIPosEvent = SimpleScene.IposPositionEvent.newBuilder(); - protoIPosEvent.addObject(protoIposObject); - return protoIPosEvent.build(); + return protoIposObject; } private static SimpleScene.IposSimpleOrientation.Builder transformIntoProtoOrientation(PositionEvent internalPosEvent) { SimpleScene.IposSimpleOrientation.Builder protoOrientation = SimpleScene.IposSimpleOrientation.newBuilder(); 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; } diff --git a/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java b/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java index 80c3c40f5b4d8eb0998e7ce4cf6ec81b0a03584b..b79d981ee1a4f138c3aa60b4455baa1128617f17 100644 --- a/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java +++ b/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java @@ -181,16 +181,66 @@ public class PositionMonitoring { 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") public static void receiveMessage(PositionEvent posEvent) { LOG.info("Received <" + posEvent + ">"); String taskIdWindow = "Human_at_Window_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(); - if (y_coordinate > 2.08f){ - SimpleSceneIntegration.receiveMessage(posEvent, taskIdWindow); + // Achtung, Entry- und Exit-Notification müssten eigentlich Personengebunden sein + 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{ - 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); } /*