Skip to content

Commit 01ccd5c

Browse files
Topics list
1 parent 3967c91 commit 01ccd5c

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

ROS_Packages/ros_tcp_endpoint/src/ros_tcp_endpoint/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import json
2222

2323
from .exceptions import TopicOrServiceNameDoesNotExistError
24-
from unity_interfaces.msg import RosUnitySrvMessage
2524

2625

2726
class ClientThread(threading.Thread):
@@ -217,6 +216,7 @@ def run(self):
217216
pass
218217
elif destination.startswith("__"):
219218
# handle a system command, such as registering new topics
219+
rospy.loginfo(destination)
220220
self.tcp_server.handle_syscommand(destination, data)
221221
elif destination in self.tcp_server.source_destination_dict:
222222
ros_communicator = self.tcp_server.source_destination_dict[destination]

ROS_Packages/ros_tcp_endpoint/src/ros_tcp_endpoint/server.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
from .publisher import RosPublisher
2727
from .service import RosService
2828
from .unity_service import UnityService
29-
from unity_interfaces.msg import RosUnitySysCommand
30-
from unity_interfaces.srv import RosUnityTopicListResponse
3129

3230

3331
class TcpServer:
@@ -103,9 +101,6 @@ def send_unity_service(self, topic, service_class, request):
103101
def send_unity_service_response(self, srv_id, data):
104102
self.unity_tcp_sender.send_unity_service_response(srv_id, data)
105103

106-
def topic_list(self, data):
107-
return RosUnityTopicListResponse(self.source_destination_dict.keys())
108-
109104
def handle_syscommand(self, topic, data):
110105
function = getattr(self.syscommands, topic[2:])
111106
if function is None:
@@ -232,6 +227,8 @@ def request(self, srv_id): # the next message is a service request
232227
self.tcp_server.pending_srv_id = srv_id
233228
self.tcp_server.pending_srv_is_request = True
234229

230+
def topic_list(self):
231+
self.tcp_server.unity_tcp_sender.send_topic_list()
235232

236233

237234
def resolve_message_name(name, extension="msg"):

ROS_Packages/ros_tcp_endpoint/src/ros_tcp_endpoint/tcp_sender.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import struct
2020
from .client import ClientThread
2121
from .thread_pauser import ThreadPauser
22-
from unity_interfaces.msg import RosUnityError
23-
from unity_interfaces.msg import RosUnitySrvMessage
2422
from io import BytesIO
2523

2624
# queue module was renamed between python 2 and 3
@@ -116,6 +114,16 @@ def send_unity_service_response(self, srv_id, data):
116114

117115
thread_pauser.resume_with_result(data)
118116

117+
def send_topic_list(self):
118+
if self.queue is not None:
119+
rospy.loginfo("Sending topic list")
120+
topic_list = SysCommand_TopicsResponse()
121+
topics_and_types = rospy.get_published_topics()
122+
topic_list.topics = [item[0] for item in topics_and_types]
123+
topic_list.types = [item[1] for item in topics_and_types]
124+
serialized_bytes = ClientThread.serialize_command("__topic_list", topic_list)
125+
self.queue.put(serialized_bytes)
126+
119127
def start_sender(self, conn, halt_event):
120128
sender_thread = threading.Thread(
121129
target=self.sender_loop, args=(conn, self.sender_id, halt_event)
@@ -162,3 +170,7 @@ class SysCommand_Log:
162170

163171
class SysCommand_Service:
164172
srv_id = 0
173+
174+
class SysCommand_TopicsResponse:
175+
topics = []
176+
types = []

0 commit comments

Comments
 (0)