diff --git a/co-simulation/NOTICE-THIRD-PARTY.md b/co-simulation/NOTICE-THIRD-PARTY.md index 705c50ee..d0e22226 100644 --- a/co-simulation/NOTICE-THIRD-PARTY.md +++ b/co-simulation/NOTICE-THIRD-PARTY.md @@ -69,6 +69,30 @@ Apache Commons Text (1.6) * Source: https://git-wip-us.apache.org/repos/asf?p=commons-text +Apache WebServices Common Utilities (1.0.2) + + * License: The Apache Software License, Version 2.0 + * Maven artifact: `org.apache.ws.commons.util:ws-commons-util:1.0.2` + * Project: http://ws.apache.org/commons/util + * Source: https://svn.apache.org/viewcvs.cgi/webservices/commons/trunk/util + + +Apache XML-RPC Client Library (3.1.3) + + * License: The Apache Software License, Version 2.0 + * Maven artifact: `org.apache.xmlrpc:xmlrpc-client:3.1.3` + * Project: http://ws.apache.org/xmlrpc/xmlrpc-client/ + * Source: https://svn.apache.org/viewvc/webservices/xmlrpc/tags/xmlrpc-3.1.3/xmlrpc-client + + +Apache XML-RPC Common Library (3.1.3) + + * License: The Apache Software License, Version 2.0 + * Maven artifact: `org.apache.xmlrpc:xmlrpc-common:3.1.3` + * Project: http://ws.apache.org/xmlrpc/xmlrpc-common/ + * Source: https://svn.apache.org/viewvc/webservices/xmlrpc/tags/xmlrpc-3.1.3/xmlrpc-common + + Commons Compiler (2.7.5) * License: New BSD License @@ -355,3 +379,13 @@ Woodstox (5.1.0) * Maven artifact: `com.fasterxml.woodstox:woodstox-core:5.1.0` * Project: https://github.com/FasterXML/woodstox * Source: https://github.com/FasterXML/woodstox + + +XML Commons External Components XML APIs (1.0.b2) + + * License: The Apache Software License, Version 2.0 + * Maven artifact: `xml-apis:xml-apis:1.0.b2` + * Project: http://xml.apache.org/commons/#external + * Source: https://svn.apache.org/viewvc/xml/commons/tags/xml-commons-1_0_b2 + + diff --git a/co-simulation/fed/mosaic-carla/src/main/java/org/eclipse/mosaic/fed/carla/ambassador/CarlaAmbassador.java b/co-simulation/fed/mosaic-carla/src/main/java/org/eclipse/mosaic/fed/carla/ambassador/CarlaAmbassador.java index b0b35528..7047372c 100644 --- a/co-simulation/fed/mosaic-carla/src/main/java/org/eclipse/mosaic/fed/carla/ambassador/CarlaAmbassador.java +++ b/co-simulation/fed/mosaic-carla/src/main/java/org/eclipse/mosaic/fed/carla/ambassador/CarlaAmbassador.java @@ -16,6 +16,8 @@ import com.google.common.collect.Lists; import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.StringUtils; +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClientException; import org.eclipse.mosaic.fed.carla.carlaconnect.CarlaConnection; import org.eclipse.mosaic.fed.carla.carlaconnect.CarlaXmlRpcClient; import org.eclipse.mosaic.fed.carla.config.CarlaConfiguration; @@ -23,6 +25,8 @@ import org.eclipse.mosaic.fed.sumo.traci.writer.ListTraciWriter; import org.eclipse.mosaic.fed.sumo.traci.writer.StringTraciWriter; import org.eclipse.mosaic.interactions.application.*; +import org.eclipse.mosaic.interactions.detector.DetectorRegistration; +import org.eclipse.mosaic.lib.objects.detector.Detector; import org.eclipse.mosaic.lib.util.ProcessLoggingThread; import org.eclipse.mosaic.lib.util.objects.ObjectInstantiation; import org.eclipse.mosaic.rti.TIME; @@ -37,6 +41,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.TimeUnit; @@ -110,6 +115,8 @@ public class CarlaAmbassador extends AbstractFederateAmbassador { */ private final PriorityBlockingQueue carlaV2xInteractionQueue = new PriorityBlockingQueue<>(); + private List registeredDetectors = new ArrayList<>(); + /** * Creates a new {@link CarlaAmbassador} object. * @@ -355,12 +362,16 @@ public synchronized void processTimeAdvanceGrant(long time) throws InternalFeder this.executedTimes++; //call CarlaXmlRpcClient to ask for data whenever time advances - carlaXmlRpcClient.requestCarlaList(); - + for (Detector detector: registeredDetectors ) { + carlaXmlRpcClient.get_detected_objects(detector.getSensorId()); + } } catch (IllegalValueException e) { log.error("Error during advanceTime(" + time + ")", e); throw new InternalFederateException(e); } + catch (XmlRpcException e) { + log.error("Failed to connect to CARLA Adapter : ", e); + } } /** @@ -494,6 +505,21 @@ public void processInteraction(Interaction interaction) { } else if (interaction.getTypeId().equals(CarlaV2xMessageReception.TYPE_ID)) { this.receiveInteraction((CarlaV2xMessageReception) interaction); } + else if (interaction.getTypeId().equals(DetectorRegistration.TYPE_ID)) { + this.receiveInteraction((DetectorRegistration) interaction); + } + } + + + private void receiveInteraction(DetectorRegistration interaction) { + try { + carlaXmlRpcClient.create_sensor(interaction); + registeredDetectors.add(interaction.getDetector()); + } + catch(XmlRpcException e) { + log.error("Error occurred attempting to create sensor : {}", interaction.getDetector(), e); + } + } /** @@ -508,7 +534,7 @@ private void receiveInteraction(CarlaTraciResponse interaction) { carlaConnection.getDataOutputStream().write(interaction.getResult()); } } catch (Exception e) { - log.error("error occurs during process carla traci response interaction: " + e.getMessage()); + log.error("error occurs during process carla traci response interaction: {} ", e.getMessage()); } } @@ -526,7 +552,7 @@ private void receiveInteraction(SimulationStepResponse interaction) { } } catch (Exception e) { - log.error("error occurs during process simulation step response interaction: " + e.getMessage()); + log.error("error occurs during process simulation step response interaction: {}", e.getMessage()); } } @@ -536,7 +562,7 @@ private void receiveInteraction(SimulationStepResponse interaction) { * @param interaction CarlaV2xMessageReception interaction */ private void receiveInteraction(CarlaV2xMessageReception interaction) { - log.info("{} received V2x message: {}.", interaction.getReceiverID(), interaction.getMessage().toString()); + log.info("{} received V2x message: {}.", interaction.getReceiverID(), interaction.getMessage()); interactionQueue.add(interaction); } diff --git a/co-simulation/fed/mosaic-carla/src/main/java/org/eclipse/mosaic/fed/carla/carlaconnect/CarlaXmlRpcClient.java b/co-simulation/fed/mosaic-carla/src/main/java/org/eclipse/mosaic/fed/carla/carlaconnect/CarlaXmlRpcClient.java index d74984a8..d4f1c06f 100644 --- a/co-simulation/fed/mosaic-carla/src/main/java/org/eclipse/mosaic/fed/carla/carlaconnect/CarlaXmlRpcClient.java +++ b/co-simulation/fed/mosaic-carla/src/main/java/org/eclipse/mosaic/fed/carla/carlaconnect/CarlaXmlRpcClient.java @@ -16,10 +16,15 @@ package org.eclipse.mosaic.fed.carla.carlaconnect; import java.net.URL; +import java.util.Arrays; +import java.util.List; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.client.XmlRpcClient; import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; +import org.apache.xmlrpc.client.XmlRpcClientException; +import org.eclipse.mosaic.interactions.detector.DetectorRegistration; +import org.eclipse.mosaic.lib.objects.detector.DetectedObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +34,10 @@ public class CarlaXmlRpcClient{ boolean isConnected; - private String registeredFunction = "test.echo"; + private static final String CREATE_SENSOR = "create_simulated_semantic_lidar_sensor"; + private static final String GET_SENSOR = "get_simulated_sensor"; + private static final String GET_DETECTED_OBJECTS = "get_detected_objects"; + private XmlRpcClient client; private final Logger log = LoggerFactory.getLogger(this.getClass()); @@ -63,33 +71,29 @@ public void initialize(URL xmlRpcServerUrl) } - /** - * This method uses xmlrpc to connect with CARLA CDASim adapter service - * @throws XmlRpcException - */ - public void requestCarlaList() - { - if(!isConnected) - { - - try { - throw new XmlRpcException("Server is not connected!"); - } - catch (XmlRpcException e) - { - log.error("Server is not connected! {}", e.getMessage()); - } + public void create_sensor(DetectorRegistration registration) throws XmlRpcException{ + List location = Arrays.asList(registration.getDetector().getLocation().getX(), registration.getDetector().getLocation().getY(), registration.getDetector().getLocation().getZ()); + List orientation = Arrays.asList(registration.getDetector().getOrientation().getPitch(), registration.getDetector().getOrientation().getRoll(), registration.getDetector().getOrientation().getYaw()); + + if (isConnected) { + Object[] params = new Object[]{1/** TODO Infrastructure ID */, registration.getDetector().getSensorId(), location, orientation}; + Object result = client.execute(CREATE_SENSOR, params); + log.info((String)result); } - try{ - Object[] params = new Object[]{"Test " + java.time.LocalDateTime.now()}; - Object result = client.execute(registeredFunction, params); + else { + log.warn("XMLRpcClient is not connected to CARLA Adapter!"); + } + } + + public void get_detected_objects(String sensorId) throws XmlRpcException{ + if (isConnected) { + Object[] params = new Object[]{1/** TODO Infrastructure ID */, sensorId}; + Object result = client.execute(GET_DETECTED_OBJECTS, params); log.info((String)result); } - catch (XmlRpcException x) - { - log.error("Errors occurred with xmlrpc connection {}", x.getMessage()); - closeConnection(); - } - + else { + log.warn("XMLRpcClient is not connected to CARLA Adapter!"); + } } + } 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 f2376038..c6b0d116 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 @@ -40,6 +40,7 @@ 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.DetectedObject; import org.eclipse.mosaic.lib.objects.detector.Detector; import org.eclipse.mosaic.lib.objects.v2x.ExternalV2xMessage; import org.eclipse.mosaic.lib.objects.v2x.V2xMessage; @@ -290,7 +291,6 @@ public synchronized void processTimeAdvanceGrant(long time) throws InternalFeder } log.info("Infrastructure message ambassador processing timestep to {}.", time); try { - // Handle any new infrastructure registration requests List newRegistrations = infrastructureRegistrationReceiver .getReceivedMessages();