diff --git a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java index bd3fb8a634c9c7b42301a63e8a0428275146d0bb..af5fd0b9a79b09b5688f53a069836312423daa52 100644 --- a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java +++ b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/SimpleSceneIntegration.java @@ -43,11 +43,12 @@ public class SimpleSceneIntegration { // LOG.info("obtained protobuf-positionEvent:" + posEvent_proto.toString()); MqttMessage mqttMessage = mqttService.createMqttMsg(posEvent_proto, 0, false); - // Protobuf-Versand: LOG.info("publishing mqttMessage:" + mqttMessage.toString() + " on topic: " + monitoringTaskId); - // mqttService.publish(monitoringTaskId, mqttMessage); + // LOG.info("publishing mqttMessage:" + mqttMessage.toString() + " on topic: " + monitoringTaskId); + mqttService.publish(monitoringTaskId, mqttMessage); + LOG.info("publishing protobuf mqttMessage. JSON-representation:" + ProtoJsonMap.toJson(posEvent_proto) + " on topic: " + monitoringTaskId); - LOG.info("publishing mqttMessage:" + ProtoJsonMap.toJson(posEvent_proto) + " on topic: " + monitoringTaskId); - mqttService.publish(monitoringTaskId, ProtoJsonMap.toJson(posEvent_proto), 0, false); + //LOG.info("publishing mqttMessage:" + ProtoJsonMap.toJson(posEvent_proto) + " on topic: " + monitoringTaskId); + // mqttService.publish(monitoringTaskId, ProtoJsonMap.toJson(posEvent_proto), 0, false); }else{ LOG.warn("Warning: SimpleScene: Received empty PositionEvent"); } diff --git a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/api/MqttRequestHandler.java b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/api/MqttRequestHandler.java index 0b451171c166a8aacf01d685ba9e632e2e78a65a..5804bc8a79206d1535ad428c415ef8afdf9076b2 100644 --- a/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/api/MqttRequestHandler.java +++ b/src/main/java/ipos/project/DataModellntegration/SimpleSceneIntegration/api/MqttRequestHandler.java @@ -1,11 +1,17 @@ package ipos.project.DataModellntegration.SimpleSceneIntegration.api; import com.google.protobuf.InvalidProtocolBufferException; +import ipos.models.GenericSensor; +import ipos.models.SimpleScene; import ipos.models.SimpleScene.IposMonitoringRequest; +import ipos.project.DataModellntegration.SimpleSceneIntegration.SimpleSceneIntegration; import ipos.project.DataModellntegration.SimpleSceneIntegration.service.SimpleSceneTransformer; import ipos.project.DataModellntegration.iPos_Datamodel.MonitoringRequest; +import ipos.project.UseCaseController.PositionMonitoring; import ipos.project.config.mqtt.Handler; import ipos.project.config.mqtt.MqttListener; +import ipos.project.mapper.ProtoJsonMap; +import org.apache.logging.log4j.LogManager; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,10 +20,10 @@ import org.springframework.jms.core.JmsTemplate; // subscribe to the topic. It's example -@MqttListener("usertopic/IposMonitoringRequest") +@MqttListener("usertopic/IposConfigWrapper") public class MqttRequestHandler implements Handler { - private final Logger LOG = LoggerFactory.getLogger(getClass()); + private static org.apache.logging.log4j.Logger LOG = LogManager.getLogger(); JmsTemplate jmsTemplate; @Autowired @@ -28,13 +34,17 @@ public class MqttRequestHandler implements Handler { // method that handle new message from the topic public void handle(MqttMessage message) { try { - IposMonitoringRequest monReqProto = IposMonitoringRequest.parseFrom(message.getPayload()); - LOG.info("IposMonitoringRequest received: \n" - + monReqProto.toString()); - MonitoringRequest monReqInternal = SimpleSceneTransformer.monReq_SScene2Internal(monReqProto); - // TODO: send request via JMS to MonitoringController + SimpleScene.IposConfigWrapper iposConfigWrapper = ProtoJsonMap.fromJson(message.toString(), SimpleScene.IposConfigWrapper.class); + // IposMonitoringRequest monReqProto = IposMonitoringRequest.parseFrom(message.getPayload()); + LOG.info("IposConfigWrapper received: \n" + + iposConfigWrapper.toString()); + for (IposMonitoringRequest monReq : iposConfigWrapper.getMonitoringRequestsList()){ + MonitoringRequest monReqInternal = SimpleSceneTransformer.monReq_SScene2Internal(monReq); + PositionMonitoring.receiveMessage(monReqInternal); + // TODO: send request via JMS to MonitoringController + } - this.jmsTemplate.convertAndSend("/request123", monReqInternal); // submit request to the internal broker + // this.jmsTemplate.convertAndSend("/request123", monReqInternal); // submit request to the internal broker } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } diff --git a/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java b/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java index b6f56efd9b2fb550edd20c1571d0e03dd380a275..8791d240af1919d00fed6fdd78994282a048239f 100644 --- a/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java +++ b/src/main/java/ipos/project/UseCaseController/PositionMonitoring.java @@ -22,20 +22,20 @@ public class PositionMonitoring { private static WorldModel wm; private static List<eventFilter> eventFilters = new ArrayList<eventFilter>(); private static Map<String, List<String>> zonePopulation = new HashMap<String, List<String>>(); - private IPos_DatamodelFactory modelFactory = IPos_DatamodelFactory.eINSTANCE; + private static IPos_DatamodelFactory modelFactory = IPos_DatamodelFactory.eINSTANCE; public static final String EXIT_NOTIFICATION_TYPE = "ExitNotification"; public static final String ENTRY_NOTIFICATION_TYPE = "EntryNotification"; public static final String UNDEFINED_TYPE = "undefined"; - public static final String TOPIC_WINDOW = "Human_at_Window_Side"; public static final String TOPIC_DOOR = "Human_at_Door_Side"; + public static final String TOPIC_WINDOW = "Human_at_Window_Side"; public static final String ZONE_ID_DOOR = "cobot1_door_zone"; public static final String ZONE_ID_WINDOW = "cobot1_window_zone"; public PositionMonitoring(){ ReferenceSystem rootRefSystem = createReferenceSystem("ROOT", "ROOT", null); - List<Space> doorSpaces = new LinkedList<Space>(Arrays.asList(createSpace(2.0f, 2.0f, 2.0f, createPlacing(createPosition(createPoint3D(2.0f, 0.0f, 0f), 1f, rootRefSystem), createOrientation(0f, 0f, 0f, 0f))))); - List<Space> windowSpaces = new LinkedList<Space>(Arrays.asList(createSpace(2.0f, 2.0f, 2.0f, createPlacing(createPosition(createPoint3D(2.0f, 4.0f, 0f), 1f, rootRefSystem), createOrientation(0f, 0f, 0f, 0f))))); + List<Space> doorSpaces = new LinkedList<Space>(Arrays.asList(createSpace(2.0f, 2.0f, 6.0f, createPlacing(createPosition(createPoint3D(2.0f, 0.0f, 0f), 1f, rootRefSystem), createOrientation(0f, 0f, 0f, 0f))))); + List<Space> windowSpaces = new LinkedList<Space>(Arrays.asList(createSpace(2.0f, 2.0f, 6.0f, createPlacing(createPosition(createPoint3D(2.0f, 4.0f, 0f), 1f, rootRefSystem), createOrientation(0f, 0f, 0f, 0f))))); Zone doorZone = createZone(ZONE_ID_DOOR, ZONE_ID_DOOR, doorSpaces); Zone windowZone = createZone(ZONE_ID_WINDOW, ZONE_ID_WINDOW,windowSpaces); wm = modelFactory.createWorldModel(); @@ -164,8 +164,8 @@ public class PositionMonitoring { } @JmsListener(destination = "/monitoringRequest", containerFactory = "jmsListenFactory") - public void receiveMessage(MonitoringRequest monReq) { - LOG.info("Received <" + monReq + ">"); + public static void receiveMessage(MonitoringRequest monReq) { + LOG.info("Received MonitoringRequest <" + monReq + ">"); eventFilter filter = new eventFilter(monReq.getMonitoringTaskId()); filter.setWM(wm); EventFilterCondition config = modelFactory.createEventFilterCondition(); @@ -175,7 +175,7 @@ public class PositionMonitoring { } filter.init(config); eventFilters.add(filter); - LOG.info("EventFilter was created"); + LOG.info("EventFilter was created: " + filter.toString() + "; monitoringTaskId: " + filter.getMonitoringTaskId() + "; zone-id:" + filter.getFilterConditionConfig().getPositionConditionCellId()); } private static boolean isDoor = false; diff --git a/src/main/resources/SimpleScene.proto b/src/main/resources/SimpleScene.proto index 3fa713f07e56071ae022809805497f7e23a97657..79aa262ba9416e19aec32aa3f097b9e0a15e98d5 100644 --- a/src/main/resources/SimpleScene.proto +++ b/src/main/resources/SimpleScene.proto @@ -3,11 +3,12 @@ syntax = "proto3"; package ipos.models; message IposConfigWrapper { // wrapper-message for configuration-topic - repeated IposFrameConfig frame = 1; - repeated IposObject object = 2; // an object must be either in this list - repeated IposObjectConfig objectConfig = 3; // or in this list, not in both - repeated POI poi = 4; - repeated RefSystem refsystem = 5; + repeated IposFrameConfig frames = 1; + repeated IposObject objects = 2; // an object must be either in this list + repeated IposObjectConfig objectConfigs = 3; // or in this list, not in both + repeated POI pois = 4; + repeated RefSystem refsystems = 5; + repeated IposMonitoringRequest monitoringRequests = 6; } message IposObjectConfig {