Skip to content

Commit

Permalink
Added logic to trigger sensor registration interactions
Browse files Browse the repository at this point in the history
replace List with ArrayList in method signature/ class members
  • Loading branch information
paulbourelly999 committed Jul 27, 2023
1 parent 69a8ca8 commit 2f201f4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
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;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;

/**
* InfrastructureInstance class represents a physical instance of an
Expand All @@ -41,7 +41,7 @@ public class InfrastructureInstance {
private int simulatedInteractionPort;
private CartesianPoint location = null;
private DatagramSocket rxMsgsSocket = null;
private ArrayList<Sensor> sensors;
private List<Sensor> sensors;

/**
* Constructor for InfrastructureInstance
Expand All @@ -56,7 +56,7 @@ public class InfrastructureInstance {
* simulated environment
*/
public InfrastructureInstance(String infrastructureId, InetAddress targetAddress, int rxMessagePort,
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, ArrayList<Sensor> sensors) {
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Sensor> sensors) {
this.infrastructureId = infrastructureId;
this.targetAddress = targetAddress;
this.rxMessagePort = rxMessagePort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Sensor> sensors) {
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Sensor> sensors) {
InfrastructureInstance tmp = new InfrastructureInstance(infrastructureId, rxMessageIpAddress, rxMessagePort,
timeSyncPort, simulatedInteractionPort, location, sensors);
try {
Expand All @@ -111,6 +114,7 @@ private void newInfrastructureInstance(String infrastructureId, InetAddress rxMe
infrastructureId, e.getMessage());
log.error("Stack trace:", e);
}

managedInstances.put(infrastructureId, tmp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class InfrastructureRegistrationMessage {
// Geo-coordinate of the Infrastructure Device location
private CartesianPoint location = null;

private ArrayList<Sensor> sensors;
private List<Sensor> sensors;


/**
Expand All @@ -67,7 +68,7 @@ public class InfrastructureRegistrationMessage {
* Device
*/
public InfrastructureRegistrationMessage(String rxMessageIpAddress, String infrastructureId, int rxMessagePort,
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, ArrayList<Sensor> sensors) {
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Sensor> sensors) {
this.rxMessageIpAddress = rxMessageIpAddress;
this.infrastructureId = infrastructureId;
this.rxMessagePort = rxMessagePort;
Expand Down Expand Up @@ -181,11 +182,11 @@ public void setLocation(CartesianPoint location) {
this.location = location;
}

public ArrayList<Sensor> getSensors() {
public List<Sensor> getSensors() {
return sensors;
}

public void setSensors(ArrayList<Sensor> sensors) {
public void setSensors(List<Sensor> sensors) {
this.sensors = sensors;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

0 comments on commit 2f201f4

Please sign in to comment.