public static void main(String... args) { Ros ros = new Ros("ipe-girlitz.fzi.de"); ros.connect();
@Override public void connectToExternal() throws ComponentException { String patternString = "(?<protocol>wss?):\\/\\/(?<host>.*):(?<port>\\d*)"; Pattern pattern = Pattern.compile(patternString); Matcher matcher = pattern.matcher(componentConfig.getExternalConnectionString()); boolean matches = matcher.matches(); if (!matches) { throw new ComponentException("Invalid external connection string! " + componentConfig.getExternalConnectionString() + " does not match the expected pattern " + patternString); } protocol = matcher.group("protocol"); host = matcher.group("host"); port = Integer.parseInt(matcher.group("port")); //TODO: support also wss ros = new Ros(host, port, WebSocketType.valueOf(protocol)); if (!ros.connect()) { throw new ComponentException( getName() + " cannot connect to \"" + componentConfig.getExternalConnectionString() + "\""); } }
@Override public void startAdapter() throws AdapterException { this.ros = new Ros(this.host); this.ros.connect(); String topicType = getMethodType(this.ros, this.topic); Topic echoBack = new Topic(ros, this.topic, topicType); echoBack.subscribe(new TopicCallback() { @Override public void handleMessage(Message message) { InputStream stream = new ByteArrayInputStream(message.toString().getBytes(StandardCharsets.UTF_8)); jsonObjectParser.parse(stream, new ParseData()); } }); }
Ros ros = new Ros(host); ros.connect();