Send preparatory '.t_rows=80' before atomic 'tgtset /-s' reset; add test
This commit is contained in:
parent
d5d30b9bac
commit
1259ff1a38
@ -413,14 +413,21 @@ class MainView(tk.Tk):
|
|||||||
self.logger.exception("Error while building atomic reset command; falling back to raw string.")
|
self.logger.exception("Error while building atomic reset command; falling back to raw string.")
|
||||||
reset_command = "tgtset /-s"
|
reset_command = "tgtset /-s"
|
||||||
|
|
||||||
# Send the single atomic reset command using the communicator's
|
# Some radar servers require adjusting internal parameters to accept
|
||||||
# send_commands API which accepts a list of commands.
|
# large multi-target operations. Send a preparatory command to set
|
||||||
if not self.target_communicator.send_commands([reset_command]):
|
# the server t_rows parameter before issuing the atomic tgtset reset.
|
||||||
self.logger.error("Failed to send atomic reset command to the radar.")
|
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.")
|
messagebox.showerror("Reset Error", "Failed to send reset command to the radar.")
|
||||||
return False
|
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
|
# Poll the simulation hub for up to a short timeout to ensure the server
|
||||||
# processed the reset and returned no active targets.
|
# processed the reset and returned no active targets.
|
||||||
timeout_s = 3.0
|
timeout_s = 3.0
|
||||||
|
|||||||
46
tests/gui/test_main_view_reset.py
Normal file
46
tests/gui/test_main_view_reset.py
Normal file
@ -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"
|
||||||
Loading…
Reference in New Issue
Block a user