Skip to content

Commit

Permalink
pr updates
Browse files Browse the repository at this point in the history
  • Loading branch information
EricChen-Lei committed Sep 7, 2023
1 parent cc27632 commit cf70a3b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.util.List;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.net.MalformedURLException;
import java.net.URL;

/**
* Implementation of a {@link AbstractFederateAmbassador} for the vehicle
Expand Down Expand Up @@ -206,8 +208,17 @@ public void initialize(long startTime, long endTime) throws InternalFederateExce
throw new InternalFederateException(e);
}
//initialize CarlaXmlRpcClient
carlaXmlRpcClient = new CarlaXmlRpcClient();
carlaXmlRpcClient.initialize();
//set the connected server URL
try{
URL xmlRpcServerUrl = new URL("http://127.0.0.1:8090/RPC2");
carlaXmlRpcClient = new CarlaXmlRpcClient();
carlaXmlRpcClient.initialize(xmlRpcServerUrl);
}
catch (MalformedURLException m)
{
log.error("Errors occurred with {0}", m.getMessage());
carlaXmlRpcClient.closeConnection();
}
// Start the CARLA simulator
startCarlaLocal();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/
package org.eclipse.mosaic.fed.carla.carlaconnect;

import java.net.URL;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
Expand Down Expand Up @@ -44,23 +45,20 @@ public CarlaXmlRpcClient() {
public void closeConnection()
{
log.info("carla connection server closing");
isConnected = false;
try {
Object[] params = new Object[]{"Stop Server"};
String result = (String)client.execute(registeredFunction, params);
log.info(result);
}
catch (XmlRpcException e)
{
log.error("Errors occurred with {0}", e.getMessage());
}
isConnected = false;
}

public void initialize()


/**
* need to getting a URL to connect to from ambassador
* @param xmlRpcServerUrl
*/
public void initialize(URL xmlRpcServerUrl)
{
try{
config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:8090/RPC2"));
config.setServerURL(xmlRpcServerUrl);
client = new XmlRpcClient();
client.setConfig(config);
Object[] connectionTest = new Object[]{"Connection test"};
Expand All @@ -73,11 +71,6 @@ public void initialize()
log.error("Server is not connected!");
}
}
catch (MalformedURLException m)
{
log.error("Errors occurred with {0}", m.getMessage());
isConnected = false;
}
catch (XmlRpcException x)
{
log.error("Errors occurred with xmlrpc connection {0}", x.getMessage());
Expand All @@ -89,13 +82,20 @@ public void initialize()

/**
* This method uses xmlrpc to connect with CARLA CDASim adapter service
* @throws XmlRpcException
*/
public void requestCarlaList()
{
if(!isConnected)
{
log.error("Server is not connected!");
return;

try {
throw new XmlRpcException("Server is not connected!");
}
catch (XmlRpcException e)
{
log.error("Server is not connected! {0}", e.getMessage());
}
}
try{
Object[] params = new Object[]{"Test " + java.time.LocalDateTime.now()};
Expand Down

0 comments on commit cf70a3b

Please sign in to comment.