Skip to content

Commit

Permalink
rpc json test
Browse files Browse the repository at this point in the history
tested json can be passed to java side
  • Loading branch information
EricChen-Lei committed Aug 31, 2023
1 parent fd9a778 commit 42b75d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import java.util.*;

public class CarlaMessageReceiver implements Runnable {

Expand All @@ -30,14 +31,20 @@ public void run(){
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();

try{
//set up address for server
config.setServerURL(new URL("http://127.0.0.1:8090/RPC2"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);

while(true)
{
//used to pass arguments to python side, can be in any format
Object[] params = new Object[]{new String("Test " + java.time.LocalDateTime.now())};
String result = (String) client.execute("test.echo", params);
System.out.println(result);

//result is the return object from python side
Object result = (Object) client.execute("test.echo", params);

//pause the loop for 10 sec, change as needed
Thread.sleep(10000);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
import json

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
Expand All @@ -12,10 +13,25 @@ class RequestHandler(SimpleXMLRPCRequestHandler):

# Register a function under a different name
def echo(text):
print(text)
return text + " processed!"
print(text)

json_strings = [
"{\"carla_actor\": null, \"id\": 0, \"object_type\": \"Vehicles\", \"timestamp\": 0, \"bounding_box_in_world_coordinate_frame\": [], \"position\": [20.0, 34.64101791381836, 0.0], \"velocity\": [100.0, 1.0, 0.0], \"rotation\": [[0.9983314336437902, -0.02072298021475338, 0.05389718628791056], [0.02439869428620028, 0.9973554635114954, -0.06846008414323508], [-0.05233595624294384, 0.06966087492121549, 0.9961969233988568]], \"angular_velocity\": [0.0, 0.0, 8.726646064915904e-05], \"position_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"velocity_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"confidence\": 1.0}",
"{\"carla_actor\": null, \"id\": 1, \"object_type\": \"Pedestrians\", \"timestamp\": 0, \"bounding_box_in_world_coordinate_frame\": [], \"position\": [20.0, 34.64101791381836, 0.0], \"velocity\": [100.0, 1.0, 0.0], \"rotation\": [[0.9983314336437902, -0.02072298021475338, 0.05389718628791056], [0.02439869428620028, 0.9973554635114954, -0.06846008414323508], [-0.05233595624294384, 0.06966087492121549, 0.9961969233988568]], \"angular_velocity\": [0.0, 0.0, 8.726646064915904e-05], \"position_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"velocity_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"confidence\": 1.0}",
"{\"carla_actor\": null, \"id\": 2, \"object_type\": \"Pedestrians\", \"timestamp\": 0, \"bounding_box_in_world_coordinate_frame\": [], \"position\": [20.0, 34.64101791381836, 0.0], \"velocity\": [100.0, 1.0, 0.0], \"rotation\": [[0.9983314336437902, -0.02072298021475338, 0.05389718628791056], [0.02439869428620028, 0.9973554635114954, -0.06846008414323508], [-0.05233595624294384, 0.06966087492121549, 0.9961969233988568]], \"angular_velocity\": [0.0, 0.0, 8.726646064915904e-05], \"position_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"velocity_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"confidence\": 1.0}",
"{\"carla_actor\": null, \"id\": 3, \"object_type\": \"Pedestrians\", \"timestamp\": 0, \"bounding_box_in_world_coordinate_frame\": [], \"position\": [20.0, 34.64101791381836, 0.0], \"velocity\": [100.0, 1.0, 0.0], \"rotation\": [[0.9983314336437902, -0.02072298021475338, 0.05389718628791056], [0.02439869428620028, 0.9973554635114954, -0.06846008414323508], [-0.05233595624294384, 0.06966087492121549, 0.9961969233988568]], \"angular_velocity\": [0.0, 0.0, 8.726646064915904e-05], \"position_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"velocity_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"confidence\": 1.0}",
"{\"carla_actor\": null, \"id\": 4, \"object_type\": \"Vehicles\", \"timestamp\": 0, \"bounding_box_in_world_coordinate_frame\": [], \"position\": [20.0, 34.64101791381836, 0.0], \"velocity\": [100.0, 1.0, 0.0], \"rotation\": [[0.9983314336437902, -0.02072298021475338, 0.05389718628791056], [0.02439869428620028, 0.9973554635114954, -0.06846008414323508], [-0.05233595624294384, 0.06966087492121549, 0.9961969233988568]], \"angular_velocity\": [0.0, 0.0, 8.726646064915904e-05], \"position_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"velocity_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"confidence\": 1.0}",
"{\"carla_actor\": null, \"id\": 5, \"object_type\": \"Vehicles\", \"timestamp\": 0, \"bounding_box_in_world_coordinate_frame\": [], \"position\": [20.0, 34.64101791381836, 0.0], \"velocity\": [100.0, 1.0, 0.0], \"rotation\": [[0.9983314336437902, -0.02072298021475338, 0.05389718628791056], [0.02439869428620028, 0.9973554635114954, -0.06846008414323508], [-0.05233595624294384, 0.06966087492121549, 0.9961969233988568]], \"angular_velocity\": [0.0, 0.0, 8.726646064915904e-05], \"position_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"velocity_covariance\": [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], \"confidence\": 1.0}"
]

json_array = [json.loads(json_str) for json_str in json_strings]
json_array_string = json.dumps(json_array, indent=2)


return json_array_string

server.register_function(echo, 'test.echo')

# Run the server's main loop

server.serve_forever()

0 comments on commit 42b75d1

Please sign in to comment.