From 46dc7eb5a0db9fde2cf172abdd6660f356653121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20S=C3=A1nchez-Gallego?= Date: Tue, 28 May 2024 20:48:05 -0700 Subject: [PATCH] Full implementation --- src/hal/actor/commands/abort_exposures.py | 28 +++++++++++++++++++---- src/hal/helpers/apogee.py | 2 ++ src/hal/helpers/boss.py | 12 ++++++---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/hal/actor/commands/abort_exposures.py b/src/hal/actor/commands/abort_exposures.py index 1686c65..e68d085 100644 --- a/src/hal/actor/commands/abort_exposures.py +++ b/src/hal/actor/commands/abort_exposures.py @@ -8,14 +8,16 @@ from __future__ import annotations +import asyncio + from typing import TYPE_CHECKING from . import hal_command_parser if TYPE_CHECKING: - - from .. import HALCommandType + from hal.actor import HALCommandType + from hal.macros.expose import ExposeMacro __all__ = ["abort_exposures"] @@ -25,12 +27,28 @@ async def abort_exposures(command: HALCommandType): """Aborts ongoing exposures..""" - if command.actor.observatory == "APO": - return command.fail("abort-exposures is not supported for APO.") + expose_macro = command.actor.helpers.macros["expose"] + assert isinstance(expose_macro, ExposeMacro) + + if expose_macro.running: + command.warning("Cancelling the expose macro.") + expose_macro.cancel(now=True) + + command.warning("Aborting ongoing exposures.") tasks = [ command.actor.helpers.apogee.abort(command), command.actor.helpers.boss.abort(command), ] - return command.finish() + results = await asyncio.gather(*tasks, return_exceptions=True) + for iresult, result in enumerate(results): + instrument = ["APOGEE", "BOSS"][iresult] + if isinstance(result, Exception): + return command.fail(f"Failed to abort {instrument} exposure: {result!s}") + elif result is not True: + return command.fail(f"Unkown error while aborting {instrument} exposure.") + else: + continue + + return command.finish(text="Exposures have been aborted.") diff --git a/src/hal/helpers/apogee.py b/src/hal/helpers/apogee.py index cf62a83..ccba18a 100644 --- a/src/hal/helpers/apogee.py +++ b/src/hal/helpers/apogee.py @@ -311,6 +311,8 @@ async def abort(self, command: HALCommandType): await self._send_command(command, "apogee", "stop", time_limit=60) + return True + class APOGEEGangHelper: """Helper for the APOGEE gang connector.""" diff --git a/src/hal/helpers/boss.py b/src/hal/helpers/boss.py index 5b5ef03..418c1d5 100644 --- a/src/hal/helpers/boss.py +++ b/src/hal/helpers/boss.py @@ -252,10 +252,14 @@ async def readout(self, command: HALCommandType): async def abort(self, command: HALCommandType): """Aborts the ongoing exposure.""" - if not self.actor.observatory == "LCO": - raise ValueError("abort is not supported at APO.") - if not self.is_exposing(): + command.warning("No exposure to abort.") return True - await self._send_command(command, "apogee", "abort", time_limit=60) + if self.actor.observatory == "LCO": + await self._send_command(command, "yao", "abort --reset", time_limit=60) + else: + await self._send_command(command, "boss", "abort", time_limit=60) + await self._send_command(command, "boss", "clearExposure", time_limit=30) + + return True