From db2f4258464dad20a72ffc951dc626f3351b0d45 Mon Sep 17 00:00:00 2001 From: Maxime St-Pierre Date: Mon, 27 Aug 2018 22:35:37 -0400 Subject: [PATCH] show connection info on rosnode info --- clients/rospy/src/rospy/impl/tcpros_base.py | 1 + tools/rosnode/src/rosnode/__init__.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/clients/rospy/src/rospy/impl/tcpros_base.py b/clients/rospy/src/rospy/impl/tcpros_base.py index 430bca9d04..b48d7727c5 100644 --- a/clients/rospy/src/rospy/impl/tcpros_base.py +++ b/clients/rospy/src/rospy/impl/tcpros_base.py @@ -473,6 +473,7 @@ def get_transport_info(self): Similar to getTransportInfo() in 'libros/transport/transport_tcp.cpp' e.g. TCPROS connection on port 41374 to [127.0.0.1:40623 on socket 6] """ + # Pattern matching this output in tools/rosnode/src/rosnode/__init__.py CONNECTION_PATTERN return "%s connection on port %s to [%s:%s on socket %s]" % (self.transport_type, self.local_endpoint[1], self.remote_endpoint[0], self.remote_endpoint[1], self._fileno) def fileno(self): diff --git a/tools/rosnode/src/rosnode/__init__.py b/tools/rosnode/src/rosnode/__init__.py index 4c8322902f..c916072275 100644 --- a/tools/rosnode/src/rosnode/__init__.py +++ b/tools/rosnode/src/rosnode/__init__.py @@ -45,6 +45,7 @@ import sys import socket import time +import re try: from xmlrpc.client import ServerProxy except ImportError: @@ -62,6 +63,8 @@ NAME='rosnode' ID = '/rosnode' +# The string is defined in clients/rospy/src/rospy/impl/tcpros_base.py TCPROSTransport.get_transport_info +CONNECTION_PATTERN = re.compile(r'\w+ connection on port (\d+) to \[(.*) on socket (\d+)\]') class ROSNodeException(Exception): """ @@ -543,11 +546,16 @@ def get_node_connection_info_description(node_api, master): # older ros publisher implementations don't report a URI buff += " * to: %s\n"%lookup_uri(master, system_state, topic, dest_id) if direction == 'i': - buff += " * direction: inbound\n" + buff += " * direction: inbound" elif direction == 'o': - buff += " * direction: outbound\n" + buff += " * direction: outbound" else: - buff += " * direction: unknown\n" + buff += " * direction: unknown" + if len(info) > 6: + match = CONNECTION_PATTERN.match(info[6]) + if match is not None: + buff += " (%s - %s) [%s]" % match.groups() + buff += "\n" buff += " * transport: %s\n"%transport except socket.error: raise ROSNodeIOException("Communication with node[%s] failed!"%(node_api))