diff --git a/target_simulator/gui/main_view.py b/target_simulator/gui/main_view.py index 415caed..f3e1de8 100644 --- a/target_simulator/gui/main_view.py +++ b/target_simulator/gui/main_view.py @@ -413,14 +413,21 @@ class MainView(tk.Tk): self.logger.exception("Error while building atomic reset command; falling back to raw string.") reset_command = "tgtset /-s" - # Send the single atomic reset command using the communicator's - # send_commands API which accepts a list of commands. - if not self.target_communicator.send_commands([reset_command]): - self.logger.error("Failed to send atomic reset command to the radar.") + # Some radar servers require adjusting internal parameters to accept + # large multi-target operations. Send a preparatory command to set + # the server t_rows parameter before issuing the atomic tgtset reset. + prep_command = "$mex.t_rows=80" + + commands_to_send = [prep_command, reset_command] + + # Send the preparatory command followed by the atomic reset using the + # communicator's send_commands API which accepts a list of commands. + if not self.target_communicator.send_commands(commands_to_send): + self.logger.error("Failed to send preparatory/reset commands to the radar.") messagebox.showerror("Reset Error", "Failed to send reset command to the radar.") return False - self.logger.info("Successfully sent atomic reset command: tgtset /-s") + self.logger.info("Successfully sent preparatory and atomic reset commands: %s", commands_to_send) # Poll the simulation hub for up to a short timeout to ensure the server # processed the reset and returned no active targets. timeout_s = 3.0 diff --git a/tests/gui/test_main_view_reset.py b/tests/gui/test_main_view_reset.py new file mode 100644 index 0000000..fb78b18 --- /dev/null +++ b/tests/gui/test_main_view_reset.py @@ -0,0 +1,46 @@ +import pytest +from target_simulator.gui.main_view import MainView +from target_simulator.core.models import Target + + +class DummyCommunicator: + def __init__(self): + self.sent_commands = [] + self.is_open = True + + def send_commands(self, commands): + self.sent_commands.extend(commands) + return True + + def connect(self, cfg): + self.is_open = True + return True + + def disconnect(self): + self.is_open = False + + +@pytest.fixture +def main_view(tmp_path, monkeypatch): + # Create a MainView but avoid opening the Tk mainloop + mv = MainView() + # Replace actual communicators with dummy to avoid I/O + dummy = DummyCommunicator() + mv.target_communicator = dummy + return mv + + +def test_reset_radar_state_sends_atomic_tgtset(main_view): + mv = main_view + # Ensure that the communicator reports open + assert mv.target_communicator.is_open + + # Call the reset function + result = mv._reset_radar_state() + + # Expect success + assert result is True + # Verify that two commands were sent: preparatory $mex.t_rows=80 then tgtset /-s + assert len(mv.target_communicator.sent_commands) == 2 + assert mv.target_communicator.sent_commands[0].strip() == "$mex.t_rows=80" + assert mv.target_communicator.sent_commands[1].strip() == "tgtset /-s"