DAQ: added end points for local contact panel, needs fixing

This commit is contained in:
2026-05-20 16:11:33 +02:00
parent b250e69fef
commit ff609bc68d
+55 -18
View File
@@ -40,6 +40,7 @@ from aare.daq.server_exception_handler import register_exception_handlers
from aare.common.exception_handler import (
SampleException,
UserRightsException,
MaintenanceStateException,
)
logger = setup_logger("aareDAQ")
@@ -548,25 +549,45 @@ async def initialise_smargon(token: str = Depends(oauth2_scheme)) -> dict:
"message": "Smargon initialised.",
}
def bec_load_user_macros(self):
self.__cfg.try_set_busy(timeout=360)
try:
self.__devs.bec_worker.load_user_macros()
self.__cfg.state_busy = False
except Exception as e:
self.__cfg.state_busy = False
logger.error(f"Failed to load BEC user macros: {e}")
raise
@app.post("/detector/initialize")
async def initialise_detector(token: str = Depends(oauth2_scheme)) -> dict:
"""
Initialise the detector. Staff only.
def initialise_aerotech(self):
self.__cfg.try_set_busy(timeout=360)
try:
self.__devs.aerotech.home_aerotech()
self.__cfg.state_busy = False
except Exception as e:
self.__cfg.state_busy = False
logger.error(f"Failed to initialise Aerotech: {e}")
raise
Args:
token: OAuth2 access token.
def detector_take_pedestal(self):
self.__cfg.try_set_busy(timeout=360)
try:
self.__jfjoch.take_pedestal()
self.__cfg.state_busy = False
except Exception as e:
self.__cfg.state_busy = False
logger.error(f"Failed to take detector pedestal: {e}")
raise
Returns:
Dictionary with status and message.
"""
data = auth.parse_token(token)
auth.check_jwt_staff_only(data)
daq.initialise_detector()
return {
"ok": True,
"message": "Detector initialised.",
}
def initialise_detector(self):
self.__cfg.try_set_busy(timeout=360)
try:
self.__jfjoch.initialize()
self.__cfg.state_busy = False
except Exception as e:
self.__cfg.state_busy = False
logger.error(f"Failed to initialise detector: {e}")
raise
@app.post("/beamline/goto_abr_meas_pos")
async def goto_abr_meas_pos(token: str = Depends(oauth2_scheme)):
@@ -787,7 +808,7 @@ async def park_and_dry(token: str = Depends(oauth2_scheme)):
Dictionary with status and message.
"""
auth.check_jwt_rw(cfg, auth.parse_token(token))
daq.park_and_dry()
daq.park_and_dry(park=True)
return {
"ok": True,
"message": "TELL has been dried and parked",
@@ -806,7 +827,7 @@ async def tell_dry(token: str = Depends(oauth2_scheme)) -> dict:
"""
data = auth.parse_token(token)
auth.check_jwt_staff_only(data)
daq.tell_dry()
daq.park_and_dry(park=False)
return {
"ok": True,
"message": "TELL dry cycle completed.",
@@ -2195,6 +2216,22 @@ async def set_camera_source(use_zmq: bool, token: str = Depends(oauth2_scheme)):
daq._AareDAQ__devs.set_camera_source(use_zmq)
return {"source": daq._AareDAQ__devs.samcam_source}
@app.post("/state/maintenance")
async def maintenance(token: str = Depends(oauth2_scheme)) -> str:
"""
Transition beamline state to Maintenance. Staff only.
Args:
token: OAuth2 access token.
Returns:
"OK" on success.
"""
auth.check_jwt_staff(cfg, auth.parse_token(token))
cfg.state = BeamlineStateEnum.Maintenance
logger.warning("Beamline state set to Maintenance via protected endpoint.")
raise MaintenanceStateException("Beamline was set to Maintenance. Automation must stop.")
def main():
# Remove in production!