diff --git a/README.md b/README.md index 5380fe0..832079a 100644 --- a/README.md +++ b/README.md @@ -55,13 +55,6 @@ Follow these steps to run the app locally: 3. **Run the FAST-API application** ```bash uvicorn ansto_simplon_api.main:app - ``` - > **Note:** The FastAPI Swagger / ReDoc endpoint documentation is disabled by default, to enable the documentation, please set the following environment variables. - > ```bash - > export AS_API_DOCS_URL=/swagger - > export AS_API_REDOC_URL=/docs - > export AS_API_OPENAPI_URL=/openapi.json - >``` ## Example usage Once the simulated SIMPLON API is up and running, you can verify its functionality by: diff --git a/ansto_simplon_api/config.py b/ansto_simplon_api/config.py index 9f454c0..3a322af 100644 --- a/ansto_simplon_api/config.py +++ b/ansto_simplon_api/config.py @@ -24,15 +24,15 @@ class APISettings(BaseSettings): ) API_DOCS_URL: str | None = Field( title="OpenAPI Docs Path", - default=None, + default="/swagger", ) API_REDOC_URL: str | None = Field( title="ReDocs Path", - default=None, + default="/docs", ) API_OPENAPI_URL: str | None = Field( title="OpenAPI Path", - default=None, + default="/openapi.json", ) API_FAVICON: FilePath = Field( title="Favicon Image", diff --git a/ansto_simplon_api/main.py b/ansto_simplon_api/main.py index 28e5b00..e9fe073 100644 --- a/ansto_simplon_api/main.py +++ b/ansto_simplon_api/main.py @@ -9,6 +9,7 @@ from .routes.ansto_endpoints.load_hdf5_files import router as ansto_endpoints from .routes.detector.command import router as command from .routes.detector.config import router as detector_config +from .routes.status.status import router as status from .routes.stream.config import router as stream_config config = get_settings() @@ -44,6 +45,7 @@ async def favicon(): app.include_router(command) app.include_router(stream_config) app.include_router(detector_config) +app.include_router(status) app.include_router(ansto_endpoints) diff --git a/ansto_simplon_api/routes/detector/config.py b/ansto_simplon_api/routes/detector/config.py index e8b01e2..7fb5114 100644 --- a/ansto_simplon_api/routes/detector/config.py +++ b/ansto_simplon_api/routes/detector/config.py @@ -254,8 +254,28 @@ async def put_photon_energy(input: SimplonRequestFloat): # pixel_mask -# pixel_mask_applied -# roi_mode +@router.get("/pixel_mask_applied") +async def get_pixel_mask(): + zmq_stream.detector_config.pixel_mask_applied + return {"value": zmq_stream.detector_config.pixel_mask_applied} + + +@router.put("/pixel_mask_applied") +async def set_pixel_mask(input: SimplonRequestBool): + zmq_stream.detector_config.pixel_mask_applied = input.value + return {"value": zmq_stream.detector_config.pixel_mask_applied} + + +@router.get("/roi_mode") +async def get_roi_mode(): + zmq_stream.detector_config.roi_mode + return {"value": zmq_stream.detector_config.roi_mode} + + +@router.put("/roi_mode") +async def put_roi_mode(input: SimplonRequestStr): + zmq_stream.detector_config.roi_mode = input.value + return {"value": zmq_stream.detector_config.roi_mode} @router.put("/sensor_material") diff --git a/ansto_simplon_api/routes/status/status.py b/ansto_simplon_api/routes/status/status.py new file mode 100644 index 0000000..4955d81 --- /dev/null +++ b/ansto_simplon_api/routes/status/status.py @@ -0,0 +1,8 @@ +from fastapi import APIRouter + +router = APIRouter(prefix="/detector/api/1.8.0/status", tags=["Detector Status"]) + + +@router.get("/state") +def get_detector_state(): + return {"value": "idle"} diff --git a/ansto_simplon_api/routes/stream/config.py b/ansto_simplon_api/routes/stream/config.py index 09e39b0..81e7e32 100644 --- a/ansto_simplon_api/routes/stream/config.py +++ b/ansto_simplon_api/routes/stream/config.py @@ -1,10 +1,16 @@ from fastapi import APIRouter -from ...schemas.configuration import SimplonRequestAny +from ...schemas.configuration import ( + SimplonRequestAny, + SimplonRequestStr, + StreamConfiguration, +) from ...simulate_zmq_stream import zmq_stream router = APIRouter(prefix="/stream/api/1.8.0/config", tags=["Stream Configuration"]) +stream_config = StreamConfiguration() + @router.put("/header_appendix") async def set_user_data(user_data: SimplonRequestAny): @@ -17,6 +23,28 @@ async def get_user_data(): return {"value": zmq_stream.user_data} +@router.get("/format") +async def get_format(): + return {"value": stream_config.format} + + +@router.put("/format") +async def set_format(input: SimplonRequestStr): + stream_config.format = input.value + return {"value": stream_config.format} + + +@router.get("/mode") +async def get_mode(): + return {"value": stream_config.format} + + +@router.put("/mode") +async def set_mode(input: SimplonRequestStr): + stream_config.mode = input.value + return {"value": stream_config.mode} + + ### Stream subsystem config # header_detail # image_appendix diff --git a/ansto_simplon_api/schemas/ansto_endpoints.py b/ansto_simplon_api/schemas/ansto_endpoints.py index 04d2dd8..44ae520 100644 --- a/ansto_simplon_api/schemas/ansto_endpoints.py +++ b/ansto_simplon_api/schemas/ansto_endpoints.py @@ -1,9 +1,10 @@ +from pathlib import Path from typing import Literal from pydantic import BaseModel, Field class LoadHDF5File(BaseModel): - hdf5_file_path: str = Field(examples=["/path/to/master_file"]) + hdf5_file_path: str | Path = Field(examples=["/path/to/master_file"]) number_of_datafiles: int | None = Field(default=None, examples=[1]) compression: Literal["bslz4", "none"] = Field(default="bslz4", examples=["bslz4"]) diff --git a/ansto_simplon_api/schemas/configuration.py b/ansto_simplon_api/schemas/configuration.py index 6ee5ddc..c5581a3 100644 --- a/ansto_simplon_api/schemas/configuration.py +++ b/ansto_simplon_api/schemas/configuration.py @@ -1,5 +1,5 @@ from datetime import datetime, timezone -from typing import Any +from typing import Any, Literal from pydantic import BaseModel @@ -85,3 +85,10 @@ class DetectorConfiguration(BaseModel): detector_trigger_mode: str = "exts" software_version: str = "E-32-0130" eiger_fw_version: str = "release-2022.1.2rc2" + roi_mode: Literal["disabled", "4M"] = "disabled" + pixel_mask_applied: bool = True + + +class StreamConfiguration(BaseModel): + format: Literal["cbor", "legacy"] = "cbor" + mode: Literal["enabled", "disabled"] = "enabled" diff --git a/docker-compose.yml b/docker-compose.yml index f7e2094..97234b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,9 +7,6 @@ services: dockerfile: Dockerfile container_name: mx-simplon-api environment: - - "AS_API_DOCS_URL=/swagger" - - "AS_API_REDOC_URL=/docs" - - "AS_API_OPENAPI_URL=/openapi.json" - "AS_ZMQ_ADDRESS=tcp://*:5555" #To access the masterfile, you can either copy it to the container by modifying # the dockerfile, or you can mount a volume containing the masterfile. diff --git a/pyproject.toml b/pyproject.toml index 2cfbf83..3407b90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ansto-simplon-api" -version = "0.3.2" +version = "0.3.3" description = "Simulated simplon api" authors = [ "Francisco Hernandez Vivanco ",