diff --git a/App/RobobinApp/Networking/WifiManager.cs b/App/RobobinApp/Networking/WifiManager.cs index b034c3496698af9c8bce55c84ae0feccec2db2eb..1ba99cc03b7edc3659ac4991482a22295259a77c 100644 --- a/App/RobobinApp/Networking/WifiManager.cs +++ b/App/RobobinApp/Networking/WifiManager.cs @@ -186,9 +186,10 @@ namespace RobobinApp.Networking public async Task SendMessageAsync(string message) { + Debug.WriteLine($"Sent message: {message}"); if (!_isConnected || _tcpClient == null) { - Debug.WriteLine("Not connected. Cannot send message."); + //Debug.WriteLine("Not connected. Cannot send message."); return; } @@ -197,7 +198,7 @@ namespace RobobinApp.Networking NetworkStream stream = _tcpClient.GetStream(); byte[] data = Encoding.ASCII.GetBytes(message); await stream.WriteAsync(data, 0, data.Length); - Debug.WriteLine($"Sent message: {message}"); + } catch (Exception ex) { diff --git a/App/RobobinApp/ViewModels/MainPageViewModel.cs b/App/RobobinApp/ViewModels/MainPageViewModel.cs index a3477a1d0ff40f31f1e1d4e42b9b69a2ff06a3cd..536ae8e31f87b1dbcad4ced19da53555b6cbcd31 100644 --- a/App/RobobinApp/ViewModels/MainPageViewModel.cs +++ b/App/RobobinApp/ViewModels/MainPageViewModel.cs @@ -182,6 +182,9 @@ namespace RobobinApp.ViewModels { mode = "Call"; await App.WifiManager.SendMessageAsync("SETMODE " + mode); + } else + { + Debug.WriteLine($"Can't switch while in mode " + App.WifiManager.Mode); } } diff --git a/App/RobobinApp/Views/Sides/AdminBox.xaml.cs b/App/RobobinApp/Views/Sides/AdminBox.xaml.cs index e9b1e994edf09559fd4f9cb582cbdf6951eccf3f..473bf50334a75b302df3a7e709f48ed5893665a3 100644 --- a/App/RobobinApp/Views/Sides/AdminBox.xaml.cs +++ b/App/RobobinApp/Views/Sides/AdminBox.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using Microsoft.Maui.Controls; namespace RobobinApp.Views.Sides @@ -85,10 +86,12 @@ namespace RobobinApp.Views.Sides } private async void OnStopClicked(object sender, EventArgs e) { - + if (App.WifiManager.Mode == "Manual") + { string stopMessage = "STOP"; await App.WifiManager.SendMessageAsync(stopMessage); - + } + } private async void OnCallBPMClicked(object sender, EventArgs e) diff --git a/ros2/src/robobin/robobin/helpers/message_handler.py b/ros2/src/robobin/robobin/helpers/message_handler.py index 3182da3bd7e274b158b5f3003f77798ee748a734..533db517abbbe89d081780c72625426c0198438d 100644 --- a/ros2/src/robobin/robobin/helpers/message_handler.py +++ b/ros2/src/robobin/robobin/helpers/message_handler.py @@ -14,12 +14,15 @@ class MessageHandler: "SETMODE": self.handle_set_mode, "STOP": self.handle_stop, "CALLME": self.handle_call_me, - "BPM": self.handle_call_bpm, + "CALLBPM": self.handle_call_bpm, "REQMAP": self.handle_request_map, "LOCATION": self.handle_request_location } def handle_request_location(self, client_socket, message): """Handles the LOC command.""" + if self.testing: + print("Requesting location") + return "nav_command", "LOC" response = f"location is {self.api_node.connection_manager.location}".encode() if self.testing: print(response.decode()) @@ -44,16 +47,17 @@ class MessageHandler: print(message) location = message.strip() # Remove parentheses location = f"{location}" # Add parentheses back for proper formatting - - for existing_socket, existing_location in self.api_node.called_locations: - if existing_socket == client_socket: - client_socket.sendall(b"User already requested location") - return None - - # Append the client socket and location to the list - self.api_node.called_locations.append((client_socket, location)) + if not self.testing: + for existing_socket, existing_location in self.api_node.called_locations: + if existing_socket == client_socket: + client_socket.sendall(b"User already requested location") + return None + + # Append the client socket and location to the list + self.api_node.called_locations.append((client_socket, location)) print(f"Added {ip} with location {location} to the queue.") - + if self.testing: + return None response = f"Queue Position = {len(self.api_node.called_locations)-1} {location}".encode() client_socket.sendall(response) # print("nav_command", location) @@ -66,7 +70,8 @@ class MessageHandler: print(response.decode()) else: client_socket.sendall(response) - self.api_node.called_locations = [] # Clear the queue + + self.api_node.called_locations = [] # Clear the queue return "cmd_vel", (0.0, 0.0) def handle_ping(self, client_socket, _): @@ -85,8 +90,9 @@ class MessageHandler: print(response.decode()) else: client_socket.sendall(response) - self.api_node.mode = message - self.api_node.called_locations = [] # Clear the queue + if self.api_node is not None: + self.api_node.mode = message + self.api_node.called_locations = [] # Clear the queue return "nav_command", "SETMODE " + message def handle_time_request(self, client_socket, _): """Sends the current server time.""" @@ -104,7 +110,7 @@ class MessageHandler: print(response.decode()) else: client_socket.sendall(response) - + return "nav_command","BPM" def handle_manual_control(self, client_socket, message): """Handles manual control commands: W, A, S, D.""" @@ -138,7 +144,7 @@ class MessageHandler: """Handles the REQMAP command.""" # Relative path to the JSON file working_dir = os.getcwd() - graph_file_path = os.path.abspath(os.path.join(working_dir,"src", "robobin", "robobin", "graphs", "graph.json")) + graph_file_path = os.path.abspath(os.path.join(working_dir,"src", "robobin", "robobin", "graphs", "anchors.json")) try: # Load the graph JSON file @@ -201,6 +207,13 @@ if __name__ == "__main__": assert message_handler.handle_message(None, "MANUALCTRL D") == ("cmd_vel", (0, -0.25)) assert message_handler.handle_message(None, "STOP") == ("cmd_vel", (0.0, 0.0)) - assert message_handler.handle_message(None, "CALLME (212.9638, 283.98108)") == ("nav_command", "(212.9638, 283.98108)") + assert message_handler.handle_message(None, "CALLME (212.9638, 283.98108)") == None assert message_handler.handle_message(None, "UNKNOWN") is None - assert message_handler.handle_message(None, "REQMAP") is None \ No newline at end of file + assert message_handler.handle_message(None, "REQMAP") is None + assert message_handler.handle_message(None, "SETMODE MANUAL") == ("nav_command", "SETMODE MANUAL") + + + + + assert message_handler.handle_message(None, "CALLBPM")== ("nav_command", "BPM") + assert message_handler.handle_message(None, "LOCATION") is ("nav_command", "LOC") \ No newline at end of file