Skip to content

Commit

Permalink
Moved non-interactions to mosiac lib objects
Browse files Browse the repository at this point in the history
Renamed Sensor to detector
  • Loading branch information
paulbourelly999 committed Jul 28, 2023
1 parent 364fcae commit c699981
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.net.InetAddress;
import java.util.List;

import org.eclipse.mosaic.interactions.sensor.Sensor;
import org.eclipse.mosaic.lib.geo.CartesianPoint;
import org.eclipse.mosaic.lib.objects.detector.Detector;

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

/**
* Constructor for InfrastructureInstance
Expand All @@ -55,7 +55,7 @@ public class InfrastructureInstance {
* simulated environment
*/
public InfrastructureInstance(String infrastructureId, InetAddress targetAddress, int rxMessagePort,
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Sensor> sensors) {
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Detector> sensors) {
this.infrastructureId = infrastructureId;
this.targetAddress = targetAddress;
this.rxMessagePort = rxMessagePort;
Expand Down Expand Up @@ -158,7 +158,7 @@ public void setTimeSyncPort(int timeSyncPort) {
}

public boolean containsSensor(String sensorId) {
for (Sensor sensor : sensors) {
for (Detector sensor : sensors) {
if (sensor.getSensorId().equals(sensorId) ) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import java.util.Map;

import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission;
import org.eclipse.mosaic.interactions.sensor.DetectedObject;
import org.eclipse.mosaic.interactions.sensor.Sensor;
import org.eclipse.mosaic.lib.enums.AdHocChannel;
import org.eclipse.mosaic.lib.geo.CartesianPoint;
import org.eclipse.mosaic.lib.geo.GeoCircle;
import org.eclipse.mosaic.lib.objects.addressing.AdHocMessageRoutingBuilder;
import org.eclipse.mosaic.lib.objects.detector.DetectedObject;
import org.eclipse.mosaic.lib.objects.detector.Detector;
import org.eclipse.mosaic.lib.objects.v2x.ExternalV2xContent;
import org.eclipse.mosaic.lib.objects.v2x.ExternalV2xMessage;
import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void onNewRegistration(InfrastructureRegistrationMessage registration) {
*
*/
private void newInfrastructureInstance(String infrastructureId, InetAddress rxMessageIpAddress, int rxMessagePort,
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Sensor> sensors) {
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Detector> sensors) {
InfrastructureInstance tmp = new InfrastructureInstance(infrastructureId, rxMessageIpAddress, rxMessagePort,
timeSyncPort, simulatedInteractionPort, location, sensors);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
import org.eclipse.mosaic.interactions.communication.AdHocCommunicationConfiguration;
import org.eclipse.mosaic.interactions.communication.V2xMessageReception;
import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission;
import org.eclipse.mosaic.interactions.detector.DetectedObjectInteraction;
import org.eclipse.mosaic.interactions.detector.DetectorRegistration;
import org.eclipse.mosaic.interactions.mapping.RsuRegistration;
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;
import org.eclipse.mosaic.lib.objects.addressing.IpResolver;
import org.eclipse.mosaic.lib.objects.communication.AdHocConfiguration;
import org.eclipse.mosaic.lib.objects.communication.InterfaceConfiguration;
import org.eclipse.mosaic.lib.objects.detector.Detector;
import org.eclipse.mosaic.lib.objects.v2x.ExternalV2xMessage;
import org.eclipse.mosaic.lib.objects.v2x.V2xMessage;
import org.eclipse.mosaic.lib.util.objects.ObjectInstantiation;
Expand Down Expand Up @@ -298,9 +298,9 @@ public synchronized void processTimeAdvanceGrant(long time) throws InternalFeder
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());
for (Sensor sensor : reg.getSensors()) {
for (Detector sensor : reg.getSensors()) {
// Trigger Sensor registrations for all listed sensors.
this.rti.triggerInteraction(new SensorRegistration(time,sensor));
this.rti.triggerInteraction(new DetectorRegistration(time,sensor));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.util.List;

import org.eclipse.mosaic.interactions.sensor.Sensor;
import org.eclipse.mosaic.lib.geo.CartesianPoint;
import org.eclipse.mosaic.lib.objects.detector.Detector;

/**
* A message to be sent by Infrastructure Device when it registers with the
Expand All @@ -46,7 +46,7 @@ public class InfrastructureRegistrationMessage {
// Geo-coordinate of the Infrastructure Device location
private CartesianPoint location = null;

private List<Sensor> sensors;
private List<Detector> sensors;


/**
Expand All @@ -67,7 +67,7 @@ public class InfrastructureRegistrationMessage {
* Device
*/
public InfrastructureRegistrationMessage(String rxMessageIpAddress, String infrastructureId, int rxMessagePort,
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Sensor> sensors) {
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Detector> sensors) {
this.rxMessageIpAddress = rxMessageIpAddress;
this.infrastructureId = infrastructureId;
this.rxMessagePort = rxMessagePort;
Expand Down Expand Up @@ -130,78 +130,15 @@ public CartesianPoint getLocation() {
return this.location;
}

/**
* Sets the IP address where the Infrastructure Device will be listening for
* inbound messages
*
* @param rxMessageIpAddress The IP address where the Infrastructure Device will
* be listening for inbound messages
*/
public void setRxMessageIpAddress(String rxMessageIpAddress) {
this.rxMessageIpAddress = rxMessageIpAddress;
}

/**
* Sets the unique identifier for the Infrastructure Device
* It currently is the same with RSU ID
*
* @param infrastructureId The unique identifier for the Infrastructure Device
*/
public void setInfrastructureId(String infrastructureId) {
this.infrastructureId = infrastructureId;
}

/**
* Sets the port number where the Infrastructure Device will be listening for
* inbound messages
*
* @param rxMessagePort The port number where the Infrastructure Device will be
* listening for inbound messages
*/
public void setRxMessagePort(int rxMessagePort) {
this.rxMessagePort = rxMessagePort;
}

/**
* Set the time sync port for the InfrastructureRegistrationMessage
*
* @param timeSyncPort the new time sync port to be set
*/
public void setTimeSyncPort(int timeSyncPort) {
this.timeSyncPort = timeSyncPort;
}

/**
* Set the location for the InfrastructureRegistrationMessage
*
* @param location the new GeoPoint object representing the location of the
* Infrastructure Device
*/
public void setLocation(CartesianPoint location) {
this.location = location;
}

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

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


public int getSimulatedInteractionPort() {
return simulatedInteractionPort;
}



public void setSimulatedInteractionPort(int simulatedInteractionPort) {
this.simulatedInteractionPort = simulatedInteractionPort;
}



@Override
public String toString() {
return "InfrastructureRegistrationMessage [rxMessageIpAddress=" + rxMessageIpAddress + ", infrastructureId="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import java.net.InetAddress;
import java.util.ArrayList;

import org.eclipse.mosaic.interactions.sensor.Orientation;
import org.eclipse.mosaic.interactions.sensor.Sensor;
import org.eclipse.mosaic.interactions.sensor.SensorType;
import org.eclipse.mosaic.lib.geo.CartesianPoint;
import org.eclipse.mosaic.lib.objects.detector.Detector;
import org.eclipse.mosaic.lib.objects.detector.DetectorType;
import org.eclipse.mosaic.lib.objects.detector.Orientation;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
Expand Down Expand Up @@ -55,11 +55,11 @@ public void testOnNewRegistration() {
int simulatedInteractionPort = 2355;
String ipAddressString = "127.0.0.1";
CartesianPoint pt = CartesianPoint.xyz(37.3382, -121.8863, 1.0);
ArrayList<Sensor> sensors = new ArrayList<>();
ArrayList<Detector> sensors = new ArrayList<>();
sensors.add(
new Sensor(
new Detector(
"String sensorId",
SensorType.SEMANTIC_LIDAR,
DetectorType.SEMANTIC_LIDAR,
new Orientation( 0.0,0.0,0.0),
CartesianPoint.ORIGO));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.fed.infrastructure.ambassador;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;

import org.eclipse.mosaic.lib.geo.CartesianPoint;
import org.eclipse.mosaic.lib.objects.detector.Detector;
import org.eclipse.mosaic.lib.objects.detector.DetectorType;
import org.eclipse.mosaic.lib.objects.detector.Orientation;
import org.junit.Test;

public class InfrastructureRegistrationMessageTest {
@Test
public void testGetterSettersConstructor() {
ArrayList<Detector> sensors = new ArrayList<>();
sensors.add(
new Detector(
"String sensorId",
DetectorType.SEMANTIC_LIDAR,
new Orientation( 0.0,0.0,0.0),
CartesianPoint.ORIGO));
InfrastructureRegistrationMessage message = new InfrastructureRegistrationMessage(
"127.0.0.1",
"rsu_1",
4567 ,
5678,
8642,
CartesianPoint.xy(1, 2),
sensors);
assertEquals(message.getInfrastructureId(), "rsu_1");
assertEquals(message.getRxMessageIpAddress(), "127.0.0.1" );
assertEquals(message.getRxMessagePort(), 4567);
assertEquals(message.getTimeSyncPort(), 5678);
assertEquals(message.getSimulatedInteractionPort(), 8642);
assertEquals(message.getLocation(), CartesianPoint.xy(1,2));
assertEquals(message.getSensors(), sensors);



}

@Test
public void testToString() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public void testMessageReceive() throws Exception {
assertEquals(121.8863, msg.getLocation().getY(), delta);
assertEquals(1.0, msg.getLocation().getZ(), delta);
}



}

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.eclipse.mosaic.interactions.sensor;
package org.eclipse.mosaic.interactions.detector;

import org.eclipse.mosaic.lib.objects.detector.DetectedObject;
import org.eclipse.mosaic.rti.api.Interaction;

public class DetectedObjectInteraction extends Interaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,30 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.eclipse.mosaic.interactions.sensor;
package org.eclipse.mosaic.interactions.detector;

import org.eclipse.mosaic.lib.objects.detector.Detector;
import org.eclipse.mosaic.rti.api.Interaction;

public class SensorRegistration extends Interaction {
public static final String TYPE_ID = createTypeIdentifier(SensorRegistration.class);
public class DetectorRegistration extends Interaction {
public static final String TYPE_ID = createTypeIdentifier(DetectorRegistration.class);

private Sensor sensor;
public SensorRegistration(long time, Sensor sensor) {
private Detector detector;
public DetectorRegistration(long time, Detector sensor) {
super(time);
this.sensor = sensor;
this.detector = sensor;
}
public Sensor getSensor() {
return sensor;
public Detector getDetector() {
return detector;
}
public void setSensor(Sensor sensor) {
this.sensor = sensor;
public void setDetector(Detector sensor) {
this.detector = sensor;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((sensor == null) ? 0 : sensor.hashCode());
result = prime * result + ((detector == null) ? 0 : detector.hashCode());
return result;
}
@Override
Expand All @@ -46,11 +47,11 @@ public boolean equals(Object obj) {
return false;
if (getClass() != obj.getClass())
return false;
SensorRegistration other = (SensorRegistration) obj;
if (sensor == null) {
if (other.sensor != null)
DetectorRegistration other = (DetectorRegistration) obj;
if (detector == null) {
if (other.detector != null)
return false;
} else if (!sensor.equals(other.sensor))
} else if (!detector.equals(other.detector))
return false;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import org.eclipse.mosaic.lib.geo.CartesianPoint;
import org.eclipse.mosaic.lib.math.Vector3d;
import org.eclipse.mosaic.lib.objects.detector.DetectedObject;
import org.eclipse.mosaic.lib.objects.detector.DetectionType;
import org.eclipse.mosaic.lib.objects.detector.Size;
import org.junit.Before;
import org.junit.Test;

Expand Down
Loading

0 comments on commit c699981

Please sign in to comment.