Skip to content
Snippets Groups Projects
Commit 2f74fda4 authored by Paul-Winpenny's avatar Paul-Winpenny
Browse files

Added logging statements.

parent c8a20474
Branches
No related tags found
No related merge requests found
...@@ -33,8 +33,10 @@ class ApiNode(Node): ...@@ -33,8 +33,10 @@ class ApiNode(Node):
data = client_socket.recv(1024).decode() data = client_socket.recv(1024).decode()
if not data: if not data:
break break
self.get_logger().info(f"Received data: {data}")
topic,message = self.message_handler.handle_message(client_socket, data) topic,message = self.message_handler.handle_message(client_socket, data)
if topic is not None: if topic is not None:
self.get_logger().info(f"Publishing to topic: {topic}")
self.publish_to_topic(topic, message) self.publish_to_topic(topic, message)
finally: finally:
client_socket.close() client_socket.close()
......
...@@ -28,13 +28,13 @@ class ConnectionManager: ...@@ -28,13 +28,13 @@ class ConnectionManager:
try: try:
data, addr = udp_sock.recvfrom(1024) data, addr = udp_sock.recvfrom(1024)
if data.decode() == "CONNECT": if data.decode() == "CONNECT":
print(f"Connection request from {addr}") self.api_node.get_logger().info(f"Received CONNECT message from {addr}")
tcp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) tcp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tcp_sock.bind(('', self.LISTEN_PORT)) tcp_sock.bind(('', self.LISTEN_PORT))
tcp_sock.listen(1) tcp_sock.listen(1)
client_socket, client_addr = tcp_sock.accept() client_socket, client_addr = tcp_sock.accept()
print(f"Client connected from {client_addr}") self.api_node.get_logger().info(f"Client connected from {client_addr}")
threading.Thread(target=self.api_node.handle_client_connection, args=(client_socket,)).start() threading.Thread(target=self.api_node.handle_client_connection, args=(client_socket,)).start()
except socket.timeout: except socket.timeout:
continue continue
...@@ -54,13 +54,13 @@ class ConnectionManager: ...@@ -54,13 +54,13 @@ class ConnectionManager:
location = "(0,0)" #At some point this will be retrieved from navigation node location = "(0,0)" #At some point this will be retrieved from navigation node
message = f"ROBOBIN_PRESENT {location}".encode() message = f"ROBOBIN_PRESENT {location}".encode()
sock.sendto(message, (self.UDP_IP, self.UDP_PORT)) sock.sendto(message, (self.UDP_IP, self.UDP_PORT))
print("Broadcasting presence.") self.api_node.get_logger().info("Broadcasting presence.")
time.sleep(5) time.sleep(5)
except OSError: except OSError:
break break
sock.close() sock.close()
print("Stopped broadcasting presence.") self.api_node.get_logger().info("Stopped broadcasting presence.")
def stop(self): def stop(self):
"""Stops the connection manager.""" """Stops the connection manager."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment