From 2f201f4a422aab8bcc74b037d1e1fc4fb977e5e7 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 27 Jul 2023 15:23:31 -0400 Subject: [PATCH] Added logic to trigger sensor registration interactions replace List with ArrayList in method signature/ class members --- .../ambassador/InfrastructureInstance.java | 6 ++--- .../InfrastructureInstanceManager.java | 6 ++++- .../InfrastructureMessageAmbassador.java | 7 ++++++ .../InfrastructureRegistrationMessage.java | 9 +++---- .../sensor/SensorRegistration.java | 4 ++-- .../mosaic/interactions/sensor/Velocity.java | 24 ------------------- 6 files changed, 22 insertions(+), 34 deletions(-) delete mode 100644 co-simulation/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/sensor/Velocity.java diff --git a/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureInstance.java b/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureInstance.java index 64f9a244..1a79bd03 100644 --- a/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureInstance.java +++ b/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureInstance.java @@ -17,7 +17,6 @@ package org.eclipse.mosaic.fed.infrastructure.ambassador; import org.eclipse.mosaic.interactions.sensor.Sensor; -import org.eclipse.mosaic.interactions.sensor.SensorRegistration; import org.eclipse.mosaic.lib.geo.CartesianPoint; import java.io.IOException; @@ -25,6 +24,7 @@ import java.net.DatagramSocket; import java.net.InetAddress; import java.util.ArrayList; +import java.util.List; /** * InfrastructureInstance class represents a physical instance of an @@ -41,7 +41,7 @@ public class InfrastructureInstance { private int simulatedInteractionPort; private CartesianPoint location = null; private DatagramSocket rxMsgsSocket = null; - private ArrayList sensors; + private List sensors; /** * Constructor for InfrastructureInstance @@ -56,7 +56,7 @@ public class InfrastructureInstance { * simulated environment */ public InfrastructureInstance(String infrastructureId, InetAddress targetAddress, int rxMessagePort, - int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, ArrayList sensors) { + int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List sensors) { this.infrastructureId = infrastructureId; this.targetAddress = targetAddress; this.rxMessagePort = rxMessagePort; diff --git a/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureInstanceManager.java b/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureInstanceManager.java index 9dfb9ef9..ca181f57 100644 --- a/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureInstanceManager.java +++ b/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureInstanceManager.java @@ -21,7 +21,10 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; +import java.util.Queue; import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission; import org.eclipse.mosaic.interactions.sensor.DetectedObject; @@ -100,7 +103,7 @@ public void onNewRegistration(InfrastructureRegistrationMessage registration) { * */ private void newInfrastructureInstance(String infrastructureId, InetAddress rxMessageIpAddress, int rxMessagePort, - int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, ArrayList sensors) { + int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List sensors) { InfrastructureInstance tmp = new InfrastructureInstance(infrastructureId, rxMessageIpAddress, rxMessagePort, timeSyncPort, simulatedInteractionPort, location, sensors); try { @@ -111,6 +114,7 @@ private void newInfrastructureInstance(String infrastructureId, InetAddress rxMe infrastructureId, e.getMessage()); log.error("Stack trace:", e); } + managedInstances.put(infrastructureId, tmp); } diff --git a/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureMessageAmbassador.java b/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureMessageAmbassador.java index abe95f22..d7a35a65 100644 --- a/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureMessageAmbassador.java +++ b/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureMessageAmbassador.java @@ -27,6 +27,8 @@ import org.eclipse.mosaic.interactions.mapping.RsuRegistration; import org.eclipse.mosaic.interactions.sensor.DetectedObject; import org.eclipse.mosaic.interactions.sensor.DetectedObjectInteraction; +import org.eclipse.mosaic.interactions.sensor.Sensor; +import org.eclipse.mosaic.interactions.sensor.SensorRegistration; import org.eclipse.mosaic.lib.enums.AdHocChannel; import org.eclipse.mosaic.lib.geo.GeoPoint; import org.eclipse.mosaic.lib.misc.Tuple; @@ -298,6 +300,11 @@ public synchronized void processTimeAdvanceGrant(long time) throws InternalFeder onRsuRegistrationRequest(reg.getInfrastructureId(), reg.getLocation().toGeo()); log.info("RSU Registration for "+ reg.getInfrastructureId() + " @ x, y, z: (" + reg.getLocation().getX() + ", " + reg.getLocation().getY() + ", " + reg.getLocation().getZ() + ")"); onDsrcRegistrationRequest(reg.getInfrastructureId()); + log.debug("Sending SensorRegistration interactions for sensor : {}", reg.getSensors().toString()); + for (Sensor sensor : reg.getSensors()) { + // Trigger Sensor registrations for all listed sensors. + this.rti.triggerInteraction(new SensorRegistration(time,sensor)); + } } if (currentSimulationTime == 0) { diff --git a/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureRegistrationMessage.java b/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureRegistrationMessage.java index 3e824c67..3a108e72 100644 --- a/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureRegistrationMessage.java +++ b/co-simulation/fed/mosaic-infrastructure/src/main/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureRegistrationMessage.java @@ -17,6 +17,7 @@ package org.eclipse.mosaic.fed.infrastructure.ambassador; import java.util.ArrayList; +import java.util.List; import org.eclipse.mosaic.interactions.sensor.Sensor; import org.eclipse.mosaic.lib.geo.CartesianPoint; @@ -46,7 +47,7 @@ public class InfrastructureRegistrationMessage { // Geo-coordinate of the Infrastructure Device location private CartesianPoint location = null; - private ArrayList sensors; + private List sensors; /** @@ -67,7 +68,7 @@ public class InfrastructureRegistrationMessage { * Device */ public InfrastructureRegistrationMessage(String rxMessageIpAddress, String infrastructureId, int rxMessagePort, - int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, ArrayList sensors) { + int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List sensors) { this.rxMessageIpAddress = rxMessageIpAddress; this.infrastructureId = infrastructureId; this.rxMessagePort = rxMessagePort; @@ -181,11 +182,11 @@ public void setLocation(CartesianPoint location) { this.location = location; } - public ArrayList getSensors() { + public List getSensors() { return sensors; } - public void setSensors(ArrayList sensors) { + public void setSensors(List sensors) { this.sensors = sensors; } diff --git a/co-simulation/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/sensor/SensorRegistration.java b/co-simulation/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/sensor/SensorRegistration.java index a2eb64bb..ef17fd1c 100644 --- a/co-simulation/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/sensor/SensorRegistration.java +++ b/co-simulation/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/sensor/SensorRegistration.java @@ -21,9 +21,9 @@ public class SensorRegistration extends Interaction { public final static String TYPE_ID = createTypeIdentifier(SensorRegistration.class); private Sensor sensor; - protected SensorRegistration(long time) { + public SensorRegistration(long time, Sensor sensor) { super(time); - //TODO Auto-generated constructor stub + this.sensor = sensor; } public Sensor getSensor() { return sensor; diff --git a/co-simulation/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/sensor/Velocity.java b/co-simulation/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/sensor/Velocity.java deleted file mode 100644 index 2d00ed9f..00000000 --- a/co-simulation/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/sensor/Velocity.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2023 LEIDOS. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.eclipse.mosaic.interactions.sensor; - -public class Velocity { - private double x; - - private double y; - - private double z; -}