Add port to ROS Adapter
@@ -51,10 +51,12 @@ public class RosBridgeAdapter extends SpecificDataStreamAdapter {
public static final String ID = "http://streampipes.org/adapter/specific/ros";
private static final String ROS_HOST_KEY = "ROS_HOST_KEY";
+ private static final String ROS_PORT_KEY = "ROS_PORT_KEY";
private static final String TOPIC_KEY = "TOPIC_KEY";
private String topic;
private String host;
+ private int port;
private Ros ros;
@@ -70,6 +72,8 @@ public class RosBridgeAdapter extends SpecificDataStreamAdapter {
for (StaticProperty sp : all) {
if (sp.getInternalName().equals(ROS_HOST_KEY)) {
this.host = ((FreeTextStaticProperty) sp).getValue();
+ } else if (sp.getInternalName().equals(ROS_PORT_KEY)) {
+ port = Integer.parseInt(((FreeTextStaticProperty) sp).getValue());
} else {
this.topic = ((FreeTextStaticProperty) sp).getValue();
}
@@ -83,6 +87,7 @@ public class RosBridgeAdapter extends SpecificDataStreamAdapter {
SpecificAdapterStreamDescription description = SpecificDataStreamAdapterBuilder.create(ID, "ROS Bridge", "Connect Robots running on ROS")
.iconUrl("ros.png")
.requiredTextParameter(Labels.from(ROS_HOST_KEY, "Ros Bridge", "Hostname of the ROS Bridge"))
+ .requiredTextParameter(Labels.from(ROS_PORT_KEY, "Port", "Port of the ROS Bridge"))
.requiredTextParameter(Labels.from(TOPIC_KEY, "Topic", "Name of the topic to be connected of the ROS Bridge"))
.build();
description.setAppId(ID);
@@ -93,7 +98,7 @@ public class RosBridgeAdapter extends SpecificDataStreamAdapter {
@Override
public void startAdapter() throws AdapterException {
- this.ros = new Ros(this.host);
+ this.ros = new Ros(this.host, this.port);
this.ros.connect();
String topicType = getMethodType(this.ros, this.topic);
@@ -152,21 +157,25 @@ public class RosBridgeAdapter extends SpecificDataStreamAdapter {
public GuessSchema getSchema(SpecificAdapterStreamDescription adapterDescription) throws AdapterException {
String host = null;
String topic = null;
+ int port = 0;
for (StaticProperty sp : adapterDescription.getConfig()) {
if (sp.getInternalName().equals(ROS_HOST_KEY)) {
host = ((FreeTextStaticProperty) sp).getValue();
- } else {
+ } else if (sp.getInternalName().equals(ROS_PORT_KEY)) {
+ port = Integer.parseInt(((FreeTextStaticProperty) sp).getValue());
+ }
+ else {
topic = ((FreeTextStaticProperty) sp).getValue();
}
}
- Ros ros = new Ros(host);
+ Ros ros = new Ros(host, port);
boolean connect = ros.connect();
if (!connect) {
- throw new AdapterException("Could not connect to ROS bridge Endpoint: " + host);
+ throw new AdapterException("Could not connect to ROS bridge Endpoint: " + host + " with port: " + port);
}
String topicType = getMethodType(ros, topic);
