From 8ab87cafd69e26cb0222a488d59475948c41efe7 Mon Sep 17 00:00:00 2001 From: Thomas Vaughan Date: Wed, 26 Jun 2024 12:23:48 -0400 Subject: [PATCH] MNT: Rename MCast to MCT (for MultiCamTracker as per #43) --- .../api/add_calibration_image_request.py | 4 +- .../api/add_calibration_image_response.py | 4 +- src/calibrator/api/calibrate_request.py | 4 +- src/calibrator/api/calibrate_response.py | 4 +- src/calibrator/api/delete_staged_request.py | 4 +- .../api/get_calibration_image_request.py | 4 +- .../api/get_calibration_image_response.py | 4 +- .../api/get_calibration_result_request.py | 4 +- .../api/get_calibration_result_response.py | 4 +- ...alibration_detector_resolutions_request.py | 4 +- ...libration_detector_resolutions_response.py | 4 +- ...list_calibration_image_metadata_request.py | 4 +- ...ist_calibration_image_metadata_response.py | 4 +- ...ist_calibration_result_metadata_request.py | 4 +- ...st_calibration_result_metadata_response.py | 4 +- ...date_calibration_image_metadata_request.py | 4 +- ...ate_calibration_result_metadata_request.py | 4 +- src/calibrator/calibrator.py | 10 +- src/common/__init__.py | 12 +- src/common/api/__init__.py | 10 +- .../api/dequeue_status_messages_request.py | 4 +- .../api/dequeue_status_messages_response.py | 4 +- src/common/api/empty_response.py | 4 +- src/common/api/error_response.py | 4 +- src/common/api/mcast_request.py | 7 - src/common/api/mcast_request_series.py | 6 - src/common/api/mcast_response.py | 7 - src/common/api/mcast_response_series.py | 7 - .../{mcast_parsable.py => mct_parsable.py} | 18 +-- src/common/api/mct_request.py | 7 + src/common/api/mct_request_series.py | 6 + src/common/api/mct_response.py | 7 + src/common/api/mct_response_series.py | 7 + src/common/exceptions/__init__.py | 5 +- src/common/exceptions/component_error.py | 5 - .../{mcast_error.py => mct_error.py} | 2 +- ...{parsing_error.py => mct_parsing_error.py} | 4 +- .../{mcast_component.py => mct_component.py} | 52 ++++---- src/common/structures/component_role_label.py | 3 +- src/connector/__init__.py | 5 - .../response_series_not_expected.py | 5 - src/controller/__init__.py | 5 + .../exceptions/__init__.py | 0 .../response_series_not_expected.py | 5 + .../mct_controller.py} | 122 +++++++++--------- .../structures/__init__.py | 2 +- .../structures/connection.py | 44 +++---- .../structures/connection_report.py | 0 .../structures/detector_connection.py | 26 ++-- .../structures/mct_component_address.py} | 2 +- .../structures/pose_solver_connection.py | 26 ++-- src/detector/api/get_capture_image_request.py | 4 +- .../api/get_capture_image_response.py | 4 +- .../api/get_capture_properties_request.py | 4 +- .../api/get_capture_properties_response.py | 4 +- .../api/get_detection_parameters_request.py | 4 +- .../api/get_detection_parameters_response.py | 4 +- .../api/get_marker_snapshots_request.py | 4 +- .../api/get_marker_snapshots_response.py | 4 +- .../api/set_capture_intrinsics_request.py | 4 +- .../api/set_capture_properties_request.py | 4 +- .../api/set_detection_parameters_request.py | 4 +- .../api/set_marker_dictionary_request.py | 4 +- src/detector/api/start_capture_request.py | 4 +- src/detector/api/stop_capture_request.py | 4 +- src/detector/detector.py | 16 +-- .../exceptions/update_capture_error.py | 4 +- .../abstract_camera_interface.py | 6 +- .../picamera2_implementation.py | 6 +- .../usb_webcam_implementation.py | 6 +- src/gui/gui.py | 52 ++++---- src/gui/panels/__init__.py | 2 +- src/gui/panels/base_panel.py | 10 +- src/gui/panels/calibrator_panel.py | 55 ++++---- ...connector_panel.py => controller_panel.py} | 69 +++++----- src/gui/panels/detector_panel.py | 47 ++++--- src/gui/panels/pose_solver_panel.py | 49 ++++--- .../panels/specialized/connection_table.py | 2 +- .../api/add_marker_corners_request.py | 4 +- .../api/add_target_marker_request.py | 4 +- .../api/add_target_marker_response.py | 4 +- src/pose_solver/api/get_poses_request.py | 4 +- src/pose_solver/api/get_poses_response.py | 4 +- .../api/set_intrinsic_parameters_request.py | 4 +- .../api/set_reference_marker_request.py | 4 +- .../api/start_pose_solver_request.py | 4 +- .../api/stop_pose_solver_request.py | 4 +- src/pose_solver/pose_solver_api.py | 14 +- 88 files changed, 456 insertions(+), 475 deletions(-) delete mode 100644 src/common/api/mcast_request.py delete mode 100644 src/common/api/mcast_request_series.py delete mode 100644 src/common/api/mcast_response.py delete mode 100644 src/common/api/mcast_response_series.py rename src/common/api/{mcast_parsable.py => mct_parsable.py} (77%) create mode 100644 src/common/api/mct_request.py create mode 100644 src/common/api/mct_request_series.py create mode 100644 src/common/api/mct_response.py create mode 100644 src/common/api/mct_response_series.py delete mode 100644 src/common/exceptions/component_error.py rename src/common/exceptions/{mcast_error.py => mct_error.py} (68%) rename src/common/exceptions/{parsing_error.py => mct_parsing_error.py} (69%) rename src/common/{mcast_component.py => mct_component.py} (77%) delete mode 100644 src/connector/__init__.py delete mode 100644 src/connector/exceptions/response_series_not_expected.py create mode 100644 src/controller/__init__.py rename src/{connector => controller}/exceptions/__init__.py (100%) create mode 100644 src/controller/exceptions/response_series_not_expected.py rename src/{connector/connector.py => controller/mct_controller.py} (89%) rename src/{connector => controller}/structures/__init__.py (77%) rename src/{connector => controller}/structures/connection.py (94%) rename src/{connector => controller}/structures/connection_report.py (100%) rename src/{connector => controller}/structures/detector_connection.py (84%) rename src/{connector/structures/component_address.py => controller/structures/mct_component_address.py} (91%) rename src/{connector => controller}/structures/pose_solver_connection.py (78%) rename src/gui/panels/{connector_panel.py => controller_panel.py} (85%) diff --git a/src/calibrator/api/add_calibration_image_request.py b/src/calibrator/api/add_calibration_image_request.py index 191bb26..8c98102 100644 --- a/src/calibrator/api/add_calibration_image_request.py +++ b/src/calibrator/api/add_calibration_image_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import CaptureFormat from pydantic import Field -class AddCalibrationImageRequest(MCastRequest): +class AddCalibrationImageRequest(MCTRequest): """ Calibrator will infer resolution from the image itself, and associate its own label to the data. """ diff --git a/src/calibrator/api/add_calibration_image_response.py b/src/calibrator/api/add_calibration_image_response.py index e21be47..8cba0b4 100644 --- a/src/calibrator/api/add_calibration_image_response.py +++ b/src/calibrator/api/add_calibration_image_response.py @@ -1,8 +1,8 @@ -from src.common import MCastResponse +from src.common import MCTResponse from pydantic import Field -class AddCalibrationImageResponse(MCastResponse): +class AddCalibrationImageResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "add_calibration_image" diff --git a/src/calibrator/api/calibrate_request.py b/src/calibrator/api/calibrate_request.py index a498cf8..6f20f3c 100644 --- a/src/calibrator/api/calibrate_request.py +++ b/src/calibrator/api/calibrate_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import ImageResolution from pydantic import Field -class CalibrateRequest(MCastRequest): +class CalibrateRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "calibrate" diff --git a/src/calibrator/api/calibrate_response.py b/src/calibrator/api/calibrate_response.py index c21a6d2..2bb24c8 100644 --- a/src/calibrator/api/calibrate_response.py +++ b/src/calibrator/api/calibrate_response.py @@ -1,9 +1,9 @@ -from src.common import MCastResponse +from src.common import MCTResponse from src.common.structures import IntrinsicCalibration from pydantic import Field -class CalibrateResponse(MCastResponse): +class CalibrateResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "calibrate" diff --git a/src/calibrator/api/delete_staged_request.py b/src/calibrator/api/delete_staged_request.py index 6ab98df..1248221 100644 --- a/src/calibrator/api/delete_staged_request.py +++ b/src/calibrator/api/delete_staged_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class DeleteStagedRequest(MCastRequest): +class DeleteStagedRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "clear_calibration_data_staged_for_deletion" diff --git a/src/calibrator/api/get_calibration_image_request.py b/src/calibrator/api/get_calibration_image_request.py index 5810940..a73eb6c 100644 --- a/src/calibrator/api/get_calibration_image_request.py +++ b/src/calibrator/api/get_calibration_image_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class GetCalibrationImageRequest(MCastRequest): +class GetCalibrationImageRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "get_calibration_image" diff --git a/src/calibrator/api/get_calibration_image_response.py b/src/calibrator/api/get_calibration_image_response.py index 0c37bd3..ae6f509 100644 --- a/src/calibrator/api/get_calibration_image_response.py +++ b/src/calibrator/api/get_calibration_image_response.py @@ -1,8 +1,8 @@ -from src.common import MCastResponse +from src.common import MCTResponse from pydantic import Field -class GetCalibrationImageResponse(MCastResponse): +class GetCalibrationImageResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "get_calibration_image" diff --git a/src/calibrator/api/get_calibration_result_request.py b/src/calibrator/api/get_calibration_result_request.py index 8e72982..8dbfd8d 100644 --- a/src/calibrator/api/get_calibration_result_request.py +++ b/src/calibrator/api/get_calibration_result_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class GetCalibrationResultRequest(MCastRequest): +class GetCalibrationResultRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "get_calibration_result" diff --git a/src/calibrator/api/get_calibration_result_response.py b/src/calibrator/api/get_calibration_result_response.py index 0fd9481..fdc0f07 100644 --- a/src/calibrator/api/get_calibration_result_response.py +++ b/src/calibrator/api/get_calibration_result_response.py @@ -1,9 +1,9 @@ -from src.common import MCastResponse +from src.common import MCTResponse from src.common.structures import IntrinsicCalibration from pydantic import Field -class GetCalibrationResultResponse(MCastResponse): +class GetCalibrationResultResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "get_calibration_result" diff --git a/src/calibrator/api/list_calibration_detector_resolutions_request.py b/src/calibrator/api/list_calibration_detector_resolutions_request.py index 4227cd3..80a054b 100644 --- a/src/calibrator/api/list_calibration_detector_resolutions_request.py +++ b/src/calibrator/api/list_calibration_detector_resolutions_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class ListCalibrationDetectorResolutionsRequest(MCastRequest): +class ListCalibrationDetectorResolutionsRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "list_calibration_detector_resolutions" diff --git a/src/calibrator/api/list_calibration_detector_resolutions_response.py b/src/calibrator/api/list_calibration_detector_resolutions_response.py index 29e066f..52bd1dc 100644 --- a/src/calibrator/api/list_calibration_detector_resolutions_response.py +++ b/src/calibrator/api/list_calibration_detector_resolutions_response.py @@ -1,9 +1,9 @@ -from src.common import MCastResponse +from src.common import MCTResponse from src.common.structures import DetectorResolution from pydantic import Field -class ListCalibrationDetectorResolutionsResponse(MCastResponse): +class ListCalibrationDetectorResolutionsResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "list_calibration_detector_resolutions" diff --git a/src/calibrator/api/list_calibration_image_metadata_request.py b/src/calibrator/api/list_calibration_image_metadata_request.py index e310583..d68cb45 100644 --- a/src/calibrator/api/list_calibration_image_metadata_request.py +++ b/src/calibrator/api/list_calibration_image_metadata_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import ImageResolution from pydantic import Field -class ListCalibrationImageMetadataRequest(MCastRequest): +class ListCalibrationImageMetadataRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "get_calibration_metadata_identifier_list" diff --git a/src/calibrator/api/list_calibration_image_metadata_response.py b/src/calibrator/api/list_calibration_image_metadata_response.py index 9e47283..b924cc9 100644 --- a/src/calibrator/api/list_calibration_image_metadata_response.py +++ b/src/calibrator/api/list_calibration_image_metadata_response.py @@ -1,9 +1,9 @@ from ..structures import CalibrationImageMetadata -from src.common import MCastResponse +from src.common import MCTResponse from pydantic import Field -class ListCalibrationImageMetadataResponse(MCastResponse): +class ListCalibrationImageMetadataResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "get_calibration_metadata_identifier_list" diff --git a/src/calibrator/api/list_calibration_result_metadata_request.py b/src/calibrator/api/list_calibration_result_metadata_request.py index 35cca4d..cd2e77d 100644 --- a/src/calibrator/api/list_calibration_result_metadata_request.py +++ b/src/calibrator/api/list_calibration_result_metadata_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import ImageResolution from pydantic import Field -class ListCalibrationResultMetadataRequest(MCastRequest): +class ListCalibrationResultMetadataRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "get_calibration_result_metadata_list" diff --git a/src/calibrator/api/list_calibration_result_metadata_response.py b/src/calibrator/api/list_calibration_result_metadata_response.py index 79339df..38c2b87 100644 --- a/src/calibrator/api/list_calibration_result_metadata_response.py +++ b/src/calibrator/api/list_calibration_result_metadata_response.py @@ -1,9 +1,9 @@ from ..structures import CalibrationResultMetadata -from src.common import MCastResponse +from src.common import MCTResponse from pydantic import Field -class ListCalibrationResultMetadataResponse(MCastResponse): +class ListCalibrationResultMetadataResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "get_calibration_result_metadata_list" diff --git a/src/calibrator/api/update_calibration_image_metadata_request.py b/src/calibrator/api/update_calibration_image_metadata_request.py index cef09a8..39a8528 100644 --- a/src/calibrator/api/update_calibration_image_metadata_request.py +++ b/src/calibrator/api/update_calibration_image_metadata_request.py @@ -1,9 +1,9 @@ from ..structures import CalibrationImageState -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class UpdateCalibrationImageMetadataRequest(MCastRequest): +class UpdateCalibrationImageMetadataRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "update_calibration_image_metadata" diff --git a/src/calibrator/api/update_calibration_result_metadata_request.py b/src/calibrator/api/update_calibration_result_metadata_request.py index 5192f73..d2056a5 100644 --- a/src/calibrator/api/update_calibration_result_metadata_request.py +++ b/src/calibrator/api/update_calibration_result_metadata_request.py @@ -1,9 +1,9 @@ from ..structures import CalibrationResultState -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class UpdateCalibrationResultMetadataRequest(MCastRequest): +class UpdateCalibrationResultMetadataRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "update_calibration_result_metadata" diff --git a/src/calibrator/calibrator.py b/src/calibrator/calibrator.py index 42bde8e..243a151 100644 --- a/src/calibrator/calibrator.py +++ b/src/calibrator/calibrator.py @@ -3,9 +3,9 @@ ErrorResponse, \ get_kwarg, \ ImageCoding, \ - MCastComponent, \ - MCastRequest, \ - MCastResponse + MCTComponent, \ + MCTRequest, \ + MCTResponse from src.common.structures import \ DetectorResolution, \ ImageResolution, \ @@ -86,8 +86,8 @@ def __init__( self.add_status_message(severity="critical", message=message) raise RuntimeError(message) - def supported_request_types(self) -> dict[type[MCastRequest], Callable[[dict], MCastResponse]]: - return_value: dict[type[MCastRequest], Callable[[dict], MCastResponse]] = super().supported_request_types() + def supported_request_types(self) -> dict[type[MCTRequest], Callable[[dict], MCTResponse]]: + return_value: dict[type[MCTRequest], Callable[[dict], MCTResponse]] = super().supported_request_types() return return_value def add_calibration_image(self, **kwargs) -> AddCalibrationImageResponse | ErrorResponse: diff --git a/src/common/__init__.py b/src/common/__init__.py index 8809a9e..7a6a70f 100644 --- a/src/common/__init__.py +++ b/src/common/__init__.py @@ -3,15 +3,15 @@ DequeueStatusMessagesResponse, \ EmptyResponse, \ ErrorResponse, \ - MCastParsable, \ - MCastRequest, \ - MCastRequestSeries, \ - MCastResponse, \ - MCastResponseSeries + MCTParsable, \ + MCTRequest, \ + MCTRequestSeries, \ + MCTResponse, \ + MCTResponseSeries from .client_identifier_from_connection import client_identifier_from_connection from .get_kwarg import get_kwarg from .image_coding import ImageCoding from .image_utils import ImageUtils -from .mcast_component import MCastComponent +from .mct_component import MCTComponent from .standard_resolutions import StandardResolutions from .status_message_source import StatusMessageSource diff --git a/src/common/api/__init__.py b/src/common/api/__init__.py index 69683b9..9dab08e 100644 --- a/src/common/api/__init__.py +++ b/src/common/api/__init__.py @@ -2,8 +2,8 @@ from .dequeue_status_messages_response import DequeueStatusMessagesResponse from .empty_response import EmptyResponse from .error_response import ErrorResponse -from .mcast_parsable import MCastParsable -from .mcast_request import MCastRequest -from .mcast_request_series import MCastRequestSeries -from .mcast_response import MCastResponse -from .mcast_response_series import MCastResponseSeries +from .mct_parsable import MCTParsable +from .mct_request import MCTRequest +from .mct_request_series import MCTRequestSeries +from .mct_response import MCTResponse +from .mct_response_series import MCTResponseSeries diff --git a/src/common/api/dequeue_status_messages_request.py b/src/common/api/dequeue_status_messages_request.py index 61902d7..1bbdb8c 100644 --- a/src/common/api/dequeue_status_messages_request.py +++ b/src/common/api/dequeue_status_messages_request.py @@ -1,8 +1,8 @@ -from .mcast_request import MCastRequest +from .mct_request import MCTRequest from pydantic import Field -class DequeueStatusMessagesRequest(MCastRequest): +class DequeueStatusMessagesRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "dequeue_status_messages" diff --git a/src/common/api/dequeue_status_messages_response.py b/src/common/api/dequeue_status_messages_response.py index fee9c48..1602e29 100644 --- a/src/common/api/dequeue_status_messages_response.py +++ b/src/common/api/dequeue_status_messages_response.py @@ -1,9 +1,9 @@ -from .mcast_response import MCastResponse +from .mct_response import MCTResponse from src.common.structures.status_message import StatusMessage from pydantic import Field -class DequeueStatusMessagesResponse(MCastResponse): +class DequeueStatusMessagesResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: diff --git a/src/common/api/empty_response.py b/src/common/api/empty_response.py index c842d6f..9a64a0a 100644 --- a/src/common/api/empty_response.py +++ b/src/common/api/empty_response.py @@ -1,8 +1,8 @@ -from .mcast_response import MCastResponse +from .mct_response import MCTResponse from pydantic import Field -class EmptyResponse(MCastResponse): +class EmptyResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "empty" diff --git a/src/common/api/error_response.py b/src/common/api/error_response.py index 8a77820..be06531 100644 --- a/src/common/api/error_response.py +++ b/src/common/api/error_response.py @@ -1,8 +1,8 @@ -from .mcast_response import MCastResponse +from .mct_response import MCTResponse from pydantic import Field -class ErrorResponse(MCastResponse): +class ErrorResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "error" diff --git a/src/common/api/mcast_request.py b/src/common/api/mcast_request.py deleted file mode 100644 index f373383..0000000 --- a/src/common/api/mcast_request.py +++ /dev/null @@ -1,7 +0,0 @@ -from .mcast_parsable import MCastParsable -import abc -from pydantic import BaseModel - - -class MCastRequest(BaseModel, MCastParsable, abc.ABC): - parsable_type: str diff --git a/src/common/api/mcast_request_series.py b/src/common/api/mcast_request_series.py deleted file mode 100644 index 3f89dce..0000000 --- a/src/common/api/mcast_request_series.py +++ /dev/null @@ -1,6 +0,0 @@ -from src.common.api.mcast_request import MCastRequest -from pydantic import BaseModel, Field - - -class MCastRequestSeries(BaseModel): - series: list[MCastRequest] = Field() diff --git a/src/common/api/mcast_response.py b/src/common/api/mcast_response.py deleted file mode 100644 index 62e9589..0000000 --- a/src/common/api/mcast_response.py +++ /dev/null @@ -1,7 +0,0 @@ -from .mcast_parsable import MCastParsable -import abc -from pydantic import BaseModel - - -class MCastResponse(BaseModel, MCastParsable, abc.ABC): - parsable_type: str diff --git a/src/common/api/mcast_response_series.py b/src/common/api/mcast_response_series.py deleted file mode 100644 index 4c4321c..0000000 --- a/src/common/api/mcast_response_series.py +++ /dev/null @@ -1,7 +0,0 @@ -from src.common.api.mcast_response import MCastResponse -from pydantic import BaseModel, Field - - -class MCastResponseSeries(BaseModel): - series: list[MCastResponse] = Field(default=list()) - responder: str = Field(default=str()) diff --git a/src/common/api/mcast_parsable.py b/src/common/api/mct_parsable.py similarity index 77% rename from src/common/api/mcast_parsable.py rename to src/common/api/mct_parsable.py index f3897f4..d6400f1 100644 --- a/src/common/api/mcast_parsable.py +++ b/src/common/api/mct_parsable.py @@ -1,13 +1,13 @@ -from src.common.exceptions import ParsingError +from src.common.exceptions import MCTParsingError import abc from pydantic import ValidationError from typing import TypeVar -ParsableDynamic = TypeVar('ParsableDynamic', bound='MCastParsable') +ParsableDynamic = TypeVar('ParsableDynamic', bound='MCTParsable') -class MCastParsable(abc.ABC): +class MCTParsable(abc.ABC): @staticmethod @abc.abstractmethod @@ -21,14 +21,14 @@ def parse_dynamic_series_list( ) -> list[ParsableDynamic]: if "series" not in parsable_series_dict or not isinstance(parsable_series_dict["series"], list): message: str = "parsable_series_dict did not contain field series. Input is improperly formatted." - raise ParsingError(message) + raise MCTParsingError(message) output_series: list[ParsableDynamic] = list() for parsable_dict in parsable_series_dict["series"]: if not isinstance(parsable_dict, dict): message: str = "series contained a non-dict element. Input is improperly formatted." - raise ParsingError(message) - output_series.append(MCastParsable.parse_dynamic_single( + raise MCTParsingError(message) + output_series.append(MCTParsable.parse_dynamic_single( parsable_dict=parsable_dict, supported_types=supported_types)) @@ -41,7 +41,7 @@ def parse_dynamic_single( ) -> ParsableDynamic: if "parsable_type" not in parsable_dict or not isinstance(parsable_dict["parsable_type"], str): message: str = "parsable_dict did not contain parsable_type. Input is improperly formatted." - raise ParsingError(message) from None + raise MCTParsingError(message) from None for supported_type in supported_types: if parsable_dict["parsable_type"] == supported_type.parsable_type_identifier(): @@ -49,8 +49,8 @@ def parse_dynamic_single( try: request = supported_type(**parsable_dict) except ValidationError as e: - raise ParsingError(f"A request of type {supported_type} was ill-formed: {str(e)}") from None + raise MCTParsingError(f"A request of type {supported_type} was ill-formed: {str(e)}") from None return request message: str = "parsable_type did not match any expected value. Input is improperly formatted." - raise ParsingError(message) + raise MCTParsingError(message) diff --git a/src/common/api/mct_request.py b/src/common/api/mct_request.py new file mode 100644 index 0000000..2d8122e --- /dev/null +++ b/src/common/api/mct_request.py @@ -0,0 +1,7 @@ +from .mct_parsable import MCTParsable +import abc +from pydantic import BaseModel + + +class MCTRequest(BaseModel, MCTParsable, abc.ABC): + parsable_type: str diff --git a/src/common/api/mct_request_series.py b/src/common/api/mct_request_series.py new file mode 100644 index 0000000..bea8cc0 --- /dev/null +++ b/src/common/api/mct_request_series.py @@ -0,0 +1,6 @@ +from .mct_request import MCTRequest +from pydantic import BaseModel, Field + + +class MCTRequestSeries(BaseModel): + series: list[MCTRequest] = Field() diff --git a/src/common/api/mct_response.py b/src/common/api/mct_response.py new file mode 100644 index 0000000..579395a --- /dev/null +++ b/src/common/api/mct_response.py @@ -0,0 +1,7 @@ +from .mct_parsable import MCTParsable +import abc +from pydantic import BaseModel + + +class MCTResponse(BaseModel, MCTParsable, abc.ABC): + parsable_type: str diff --git a/src/common/api/mct_response_series.py b/src/common/api/mct_response_series.py new file mode 100644 index 0000000..f341eee --- /dev/null +++ b/src/common/api/mct_response_series.py @@ -0,0 +1,7 @@ +from .mct_response import MCTResponse +from pydantic import BaseModel, Field + + +class MCTResponseSeries(BaseModel): + series: list[MCTResponse] = Field(default=list()) + responder: str = Field(default=str()) diff --git a/src/common/exceptions/__init__.py b/src/common/exceptions/__init__.py index b7d9702..f5f7ff8 100644 --- a/src/common/exceptions/__init__.py +++ b/src/common/exceptions/__init__.py @@ -1,3 +1,2 @@ -from .component_error import ComponentError -from .mcast_error import MCastError -from .parsing_error import ParsingError +from .mct_error import MCTError +from .mct_parsing_error import MCTParsingError diff --git a/src/common/exceptions/component_error.py b/src/common/exceptions/component_error.py deleted file mode 100644 index 363855a..0000000 --- a/src/common/exceptions/component_error.py +++ /dev/null @@ -1,5 +0,0 @@ -from .mcast_error import MCastError - - -class ComponentError(MCastError): - pass diff --git a/src/common/exceptions/mcast_error.py b/src/common/exceptions/mct_error.py similarity index 68% rename from src/common/exceptions/mcast_error.py rename to src/common/exceptions/mct_error.py index 4bd828a..97abf2f 100644 --- a/src/common/exceptions/mcast_error.py +++ b/src/common/exceptions/mct_error.py @@ -1,3 +1,3 @@ -class MCastError(Exception): +class MCTError(Exception): def __init__(self, *args): super().__init__(*args) diff --git a/src/common/exceptions/parsing_error.py b/src/common/exceptions/mct_parsing_error.py similarity index 69% rename from src/common/exceptions/parsing_error.py rename to src/common/exceptions/mct_parsing_error.py index 7b96dfe..a550f2c 100644 --- a/src/common/exceptions/parsing_error.py +++ b/src/common/exceptions/mct_parsing_error.py @@ -1,7 +1,7 @@ -from .mcast_error import MCastError +from .mct_error import MCTError -class ParsingError(MCastError): +class MCTParsingError(MCTError): message: str def __init__( diff --git a/src/common/mcast_component.py b/src/common/mct_component.py similarity index 77% rename from src/common/mcast_component.py rename to src/common/mct_component.py index 7387c6d..553f605 100644 --- a/src/common/mcast_component.py +++ b/src/common/mct_component.py @@ -4,12 +4,12 @@ DequeueStatusMessagesRequest, \ DequeueStatusMessagesResponse, \ ErrorResponse, \ - MCastParsable, \ - MCastRequest, \ - MCastRequestSeries, \ - MCastResponse, \ - MCastResponseSeries -from src.common.exceptions import ParsingError + MCTParsable, \ + MCTRequest, \ + MCTRequestSeries, \ + MCTResponse, \ + MCTResponseSeries +from src.common.exceptions import MCTParsingError from src.common.structures import \ SeverityLabel, \ StatusMessage @@ -22,10 +22,10 @@ logger = logging.getLogger(__name__) -ParsableDynamicSingle = TypeVar('ParsableDynamicSingle', bound=MCastParsable) +ParsableDynamicSingle = TypeVar('ParsableDynamicSingle', bound=MCTParsable) -class MCastComponent(abc.ABC): +class MCTComponent(abc.ABC): _status_message_source: StatusMessageSource @@ -63,10 +63,10 @@ def parse_dynamic_series_list( supported_types: list[type[ParsableDynamicSingle]] ) -> list[ParsableDynamicSingle]: try: - return MCastParsable.parse_dynamic_series_list( + return MCTParsable.parse_dynamic_series_list( parsable_series_dict=parsable_series_dict, supported_types=supported_types) - except ParsingError as e: + except MCTParsingError as e: self.add_status_message( severity="error", message=e.message) @@ -86,14 +86,14 @@ def dequeue_status_messages(self, **kwargs) -> DequeueStatusMessagesResponse: status_messages=status_messages) @abc.abstractmethod - def supported_request_types(self) -> dict[type[MCastRequest], Callable[[dict], MCastResponse]]: + def supported_request_types(self) -> dict[type[MCTRequest], Callable[[dict], MCTResponse]]: """ All subclasses are expected to implement this method, even if it is simply a call to super(). :return: A mapping between request type and the function that is meant to handle it. The function shall generally accept a kwargs dict, and the kwargs dict may contain: - client_identifier: str unique to the component making the request - - request: Of type derived from MCastRequest that contains information specific to the request + - request: Of type derived from MCTRequest that contains information specific to the request """ return {DequeueStatusMessagesRequest: self.dequeue_status_messages} @@ -102,21 +102,21 @@ async def websocket_handler(self, websocket: WebSocket) -> None: try: client_identifier: str = f"{websocket.client.host}:{websocket.client.port}" self.add_status_subscriber(client_identifier=client_identifier) - request_series: MCastRequestSeries - response_series: MCastResponseSeries + request_series: MCTRequestSeries + response_series: MCTResponseSeries while True: request_series_dict = await websocket.receive_json() try: - request_series_list: list[MCastRequest] = self.parse_dynamic_series_list( + request_series_list: list[MCTRequest] = self.parse_dynamic_series_list( parsable_series_dict=request_series_dict, supported_types=list(self.supported_request_types().keys())) - except ParsingError as e: + except MCTParsingError as e: logger.exception(str(e)) - await websocket.send_json(MCastResponseSeries(requests_parsed=False).dict()) + await websocket.send_json(MCTResponseSeries(requests_parsed=False).dict()) continue - response_series: MCastResponseSeries = self.websocket_handle_requests( + response_series: MCTResponseSeries = self.websocket_handle_requests( client_identifier=client_identifier, - request_series=MCastRequestSeries(series=request_series_list)) + request_series=MCTRequestSeries(series=request_series_list)) await websocket.send_json(response_series.dict()) except WebSocketDisconnect as e: print(f"DISCONNECTED: {str(e)}") @@ -125,16 +125,16 @@ async def websocket_handler(self, websocket: WebSocket) -> None: def websocket_handle_requests( self, client_identifier: str, - request_series: MCastRequestSeries - ) -> MCastResponseSeries: - request_map: dict[type[MCastRequest], Callable] = self.supported_request_types() - response_series: list[MCastResponse] = list() + request_series: MCTRequestSeries + ) -> MCTResponseSeries: + request_map: dict[type[MCTRequest], Callable] = self.supported_request_types() + response_series: list[MCTResponse] = list() for request in request_series.series: # noinspection PyBroadException try: if type(request) in request_map: - response_function: Callable[[dict], MCastResponse] = request_map[type(request)] - response: MCastResponse = response_function( + response_function: Callable[[dict], MCTResponse] = request_map[type(request)] + response: MCTResponse = response_function( client_identifier=client_identifier, request=request) response_series.append(response) @@ -148,6 +148,6 @@ def websocket_handle_requests( logger.error(message + " " + str(e)) self.add_status_message(severity="error", message=message) response_series.append(ErrorResponse(message=message)) - return MCastResponseSeries( + return MCTResponseSeries( requests_parsed=True, series=response_series) diff --git a/src/common/structures/component_role_label.py b/src/common/structures/component_role_label.py index e65607c..edbcf17 100644 --- a/src/common/structures/component_role_label.py +++ b/src/common/structures/component_role_label.py @@ -1,6 +1,5 @@ from typing import Final, Literal -COMPONENT_ROLE_LABEL_CONNECTOR: Final[str] = "connector" COMPONENT_ROLE_LABEL_DETECTOR: Final[str] = "detector" COMPONENT_ROLE_LABEL_POSE_SOLVER: Final[str] = "pose_solver" -ComponentRoleLabel = Literal["connector", "detector", "pose_solver"] +ComponentRoleLabel = Literal["detector", "pose_solver"] diff --git a/src/connector/__init__.py b/src/connector/__init__.py deleted file mode 100644 index cdc347a..0000000 --- a/src/connector/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .connector import Connector -from .structures import \ - ComponentAddress, \ - Connection, \ - ConnectionReport diff --git a/src/connector/exceptions/response_series_not_expected.py b/src/connector/exceptions/response_series_not_expected.py deleted file mode 100644 index 3bac86e..0000000 --- a/src/connector/exceptions/response_series_not_expected.py +++ /dev/null @@ -1,5 +0,0 @@ -from src.common.exceptions import MCastError - - -class ResponseSeriesNotExpected(MCastError): - pass diff --git a/src/controller/__init__.py b/src/controller/__init__.py new file mode 100644 index 0000000..56390e1 --- /dev/null +++ b/src/controller/__init__.py @@ -0,0 +1,5 @@ +from .mct_controller import MCTController +from .structures import \ + MCTComponentAddress, \ + Connection, \ + ConnectionReport diff --git a/src/connector/exceptions/__init__.py b/src/controller/exceptions/__init__.py similarity index 100% rename from src/connector/exceptions/__init__.py rename to src/controller/exceptions/__init__.py diff --git a/src/controller/exceptions/response_series_not_expected.py b/src/controller/exceptions/response_series_not_expected.py new file mode 100644 index 0000000..d2f3abc --- /dev/null +++ b/src/controller/exceptions/response_series_not_expected.py @@ -0,0 +1,5 @@ +from src.common.exceptions import MCTError + + +class ResponseSeriesNotExpected(MCTError): + pass diff --git a/src/connector/connector.py b/src/controller/mct_controller.py similarity index 89% rename from src/connector/connector.py rename to src/controller/mct_controller.py index 2a558f6..2c594f8 100644 --- a/src/connector/connector.py +++ b/src/controller/mct_controller.py @@ -1,6 +1,6 @@ from .exceptions import ResponseSeriesNotExpected from .structures import \ - ComponentAddress, \ + MCTComponentAddress, \ ConnectionReport, \ Connection, \ DetectorConnection, \ @@ -8,11 +8,11 @@ from src.common import \ EmptyResponse, \ ErrorResponse, \ - MCastComponent, \ - MCastRequest, \ - MCastRequestSeries, \ - MCastResponse, \ - MCastResponseSeries, \ + MCTComponent, \ + MCTRequest, \ + MCTRequestSeries, \ + MCTResponse, \ + MCTResponseSeries, \ StatusMessageSource from src.common.structures import \ ComponentRoleLabel, \ @@ -51,7 +51,7 @@ ConnectionType = TypeVar('ConnectionType', bound=Connection) -class Connector(MCastComponent): +class MCTController(MCTComponent): class Status(StrEnum): STOPPED: Final[int] = "Idle" @@ -90,18 +90,18 @@ def __init__( send_status_messages_to_logger=send_status_messages_to_logger) self.status_message_source = StatusMessageSource( - source_label="connector", + source_label="controller", send_to_logger=True) - self._status = Connector.Status.STOPPED - self._startup_mode = Connector.StartupMode.DETECTING_AND_SOLVING # Will be overwritten on startup - self._startup_state = Connector.StartupState.INITIAL + self._status = MCTController.Status.STOPPED + self._startup_mode = MCTController.StartupMode.DETECTING_AND_SOLVING # Will be overwritten on startup + self._startup_state = MCTController.StartupState.INITIAL self._connections = dict() self._pending_request_ids = list() def add_connection( self, - component_address: ComponentAddress + component_address: MCTComponentAddress ) -> None: label = component_address.label if label in self._connections: @@ -114,21 +114,21 @@ def add_connection( raise ValueError(f"Unrecognized component role {component_address.role}.") def _advance_startup_state(self) -> None: - if len(self._pending_request_ids) <= 0 and self._startup_state == Connector.StartupState.STARTING_CAPTURE: + if len(self._pending_request_ids) <= 0 and self._startup_state == MCTController.StartupState.STARTING_CAPTURE: self.status_message_source.enqueue_status_message( severity="debug", message="STARTING_CAPTURE complete") detector_labels: list[str] = self.get_active_detector_labels() for detector_label in detector_labels: - request_series: MCastRequestSeries = MCastRequestSeries( + request_series: MCTRequestSeries = MCTRequestSeries( series=[ ListCalibrationDetectorResolutionsRequest(), GetCapturePropertiesRequest()]) self._pending_request_ids.append(self.request_series_push( connection_label=detector_label, request_series=request_series)) - self._startup_state = Connector.StartupState.GET_RESOLUTIONS - if len(self._pending_request_ids) <= 0 and self._startup_state == Connector.StartupState.GET_RESOLUTIONS: + self._startup_state = MCTController.StartupState.GET_RESOLUTIONS + if len(self._pending_request_ids) <= 0 and self._startup_state == MCTController.StartupState.GET_RESOLUTIONS: self.status_message_source.enqueue_status_message( severity="debug", message="GET_RESOLUTIONS complete") @@ -141,7 +141,7 @@ def _advance_startup_state(self) -> None: severity="error", message=f"Failed to find DetectorConnection with label {detector_label}.") continue - requests: list[MCastRequest] = list() + requests: list[MCTRequest] = list() target_resolution: DetectorResolution = DetectorResolution( detector_serial_identifier=detector_label, image_resolution=detector_connection.current_resolution) @@ -159,12 +159,12 @@ def _advance_startup_state(self) -> None: message=f"No calibration available for detector {detector_label} " f"at resolution {str(detector_connection.current_resolution)}. " "No intrinsics will be set.") - request_series: MCastRequestSeries = MCastRequestSeries(series=requests) + request_series: MCTRequestSeries = MCTRequestSeries(series=requests) self._pending_request_ids.append(self.request_series_push( connection_label=detector_label, request_series=request_series)) - self._startup_state = Connector.StartupState.LIST_INTRINSICS - if len(self._pending_request_ids) <= 0 and self._startup_state == Connector.StartupState.LIST_INTRINSICS: + self._startup_state = MCTController.StartupState.LIST_INTRINSICS + if len(self._pending_request_ids) <= 0 and self._startup_state == MCTController.StartupState.LIST_INTRINSICS: self.status_message_source.enqueue_status_message( severity="debug", message="LIST_INTRINSICS complete") @@ -178,25 +178,25 @@ def _advance_startup_state(self) -> None: message=f"Failed to find DetectorConnection with label {detector_label}.") continue if detector_connection.calibration_result_identifier is not None: - request_series: MCastRequestSeries = MCastRequestSeries( + request_series: MCTRequestSeries = MCTRequestSeries( series=[ GetCalibrationResultRequest( result_identifier=detector_connection.calibration_result_identifier)]) self._pending_request_ids.append(self.request_series_push( connection_label=detector_label, request_series=request_series)) - self._startup_state = Connector.StartupState.GET_INTRINSICS - if len(self._pending_request_ids) <= 0 and self._startup_state == Connector.StartupState.GET_INTRINSICS: + self._startup_state = MCTController.StartupState.GET_INTRINSICS + if len(self._pending_request_ids) <= 0 and self._startup_state == MCTController.StartupState.GET_INTRINSICS: self.status_message_source.enqueue_status_message( severity="debug", message="GET_INTRINSICS complete") - if self._startup_mode == Connector.StartupMode.DETECTING_ONLY: - self._startup_state = Connector.StartupState.INITIAL - self._status = Connector.Status.RUNNING # We're done + if self._startup_mode == MCTController.StartupMode.DETECTING_ONLY: + self._startup_state = MCTController.StartupState.INITIAL + self._status = MCTController.Status.RUNNING # We're done else: pose_solver_labels: list[str] = self.get_active_pose_solver_labels() for pose_solver_label in pose_solver_labels: - requests: list[MCastRequest] = list() + requests: list[MCTRequest] = list() for detector_label in self.get_active_detector_labels(): detector_connection: DetectorConnection = self._get_connection( connection_label=detector_label, @@ -210,17 +210,17 @@ def _advance_startup_state(self) -> None: requests.append(SetIntrinsicParametersRequest( detector_label=detector_label, intrinsic_parameters=detector_connection.current_intrinsic_parameters)) - request_series: MCastRequestSeries = MCastRequestSeries(series=requests) + request_series: MCTRequestSeries = MCTRequestSeries(series=requests) self._pending_request_ids.append(self.request_series_push( connection_label=pose_solver_label, request_series=request_series)) - self._startup_state = Connector.StartupState.SET_INTRINSICS - if len(self._pending_request_ids) <= 0 and self._startup_state == Connector.StartupState.SET_INTRINSICS: + self._startup_state = MCTController.StartupState.SET_INTRINSICS + if len(self._pending_request_ids) <= 0 and self._startup_state == MCTController.StartupState.SET_INTRINSICS: self.status_message_source.enqueue_status_message( severity="debug", message="SET_INTRINSICS complete") - self._startup_state = Connector.StartupState.INITIAL - self._status = Connector.Status.RUNNING + self._startup_state = MCTController.StartupState.INITIAL + self._status = MCTController.Status.RUNNING def contains_connection_label(self, label: str) -> bool: return label in self._connections @@ -447,7 +447,7 @@ def handle_response_list_calibration_result_metadata( def handle_response_unknown( self, - response: MCastResponse + response: MCTResponse ): self.status_message_source.enqueue_status_message( severity="error", @@ -455,7 +455,7 @@ def handle_response_unknown( def handle_response_series( self, - response_series: MCastResponseSeries, + response_series: MCTResponseSeries, task_description: str | None = None, expected_response_count: int | None = None ) -> bool: @@ -478,7 +478,7 @@ def handle_response_series( f"than expected ({expected_response_count}).") success: bool = True - response: MCastResponse + response: MCTResponse for response in response_series.series: if isinstance(response, AddTargetMarkerResponse): success = True # we don't currently do anything with this response in this interface @@ -518,13 +518,13 @@ def handle_response_series( return success def is_idle(self): - return self._status == Connector.Status.STOPPED + return self._status == MCTController.Status.STOPPED def is_running(self): - return self._status == Connector.Status.RUNNING + return self._status == MCTController.Status.RUNNING def is_transitioning(self): - return self._status == Connector.Status.STARTING or self._status == Connector.Status.STOPPING + return self._status == MCTController.Status.STARTING or self._status == MCTController.Status.STOPPING def remove_connection( self, @@ -537,7 +537,7 @@ def remove_connection( def request_series_push( self, connection_label: str, - request_series: MCastRequestSeries + request_series: MCTRequestSeries ) -> uuid.UUID: if connection_label not in self._connections: raise RuntimeError(f"Failed to find connection with label {connection_label}.") @@ -549,12 +549,12 @@ def request_series_push( def response_series_pop( self, request_series_id: uuid.UUID - ) -> tuple[uuid.UUID | None, MCastResponseSeries | None]: + ) -> tuple[uuid.UUID | None, MCTResponseSeries | None]: """ Only "pop" if there is a response (not None). Return value is a tuple whose elements comprise: - UUID of the request if no response has been received, or None - - MCastResponseSeries if a response has been received, or None + - MCTResponseSeries if a response has been received, or None The dual return values allow easier reassignment of completed request ID's in calling code """ for connection in self._connections.values(): @@ -573,31 +573,31 @@ def start_up( self, mode: str = StartupMode.DETECTING_AND_SOLVING ) -> None: - if mode not in Connector.StartupMode: + if mode not in MCTController.StartupMode: raise ValueError(f"Unexpected mode \"{mode}\".") - self._startup_mode = Connector.StartupMode(mode) + self._startup_mode = MCTController.StartupMode(mode) - if self._status != Connector.Status.STOPPED: - raise RuntimeError("Cannot start up if connector isn't first stopped.") + if self._status != MCTController.Status.STOPPED: + raise RuntimeError("Cannot start up if controller isn't first stopped.") for connection in self._connections.values(): - if mode == Connector.StartupMode.DETECTING_ONLY and \ + if mode == MCTController.StartupMode.DETECTING_ONLY and \ connection.get_role() == COMPONENT_ROLE_LABEL_POSE_SOLVER: continue connection.start_up() - self._startup_state = Connector.StartupState.STARTING_CAPTURE - self._status = Connector.Status.STARTING + self._startup_state = MCTController.StartupState.STARTING_CAPTURE + self._status = MCTController.Status.STARTING def shut_down(self) -> None: - if self._status != Connector.Status.RUNNING: - raise RuntimeError("Cannot shut down if connector isn't first running.") + if self._status != MCTController.Status.RUNNING: + raise RuntimeError("Cannot shut down if controller isn't first running.") for connection in self._connections.values(): if connection.is_start_up_finished(): connection.shut_down() - self._status = Connector.Status.STOPPING + self._status = MCTController.Status.STOPPING - def supported_request_types(self) -> dict[type[MCastRequest], Callable[[dict], MCastResponse]]: + def supported_request_types(self) -> dict[type[MCTRequest], Callable[[dict], MCTResponse]]: return super().supported_request_types() # Right now this function doesn't update on its own - must be called externally and regularly @@ -608,11 +608,11 @@ async def update( for connection in connections: await connection.update() - if self._status == Connector.Status.STARTING and \ - self._startup_state == Connector.StartupState.STARTING_CAPTURE: + if self._status == MCTController.Status.STARTING and \ + self._startup_state == MCTController.StartupState.STARTING_CAPTURE: startup_finished: bool = True for connection in connections: - if self._startup_mode == Connector.StartupMode.DETECTING_ONLY and \ + if self._startup_mode == MCTController.StartupMode.DETECTING_ONLY and \ connection.get_role() == COMPONENT_ROLE_LABEL_POSE_SOLVER: continue if not connection.is_start_up_finished(): @@ -620,14 +620,14 @@ async def update( break if startup_finished: self._advance_startup_state() - elif self._status == Connector.Status.STOPPING: + elif self._status == MCTController.Status.STOPPING: shutdown_finished: bool = True for connection in connections: if not connection.is_shut_down(): shutdown_finished = False break if shutdown_finished: - self._status = Connector.Status.STOPPED + self._status = MCTController.Status.STOPPED if self.is_running(): for detector_label in self.get_active_detector_labels(): @@ -645,7 +645,7 @@ async def update( if detector_connection.request_id is None: detector_connection.request_id = self.request_series_push( connection_label=detector_label, - request_series=MCastRequestSeries(series=[GetMarkerSnapshotsRequest()])) + request_series=MCTRequestSeries(series=[GetMarkerSnapshotsRequest()])) for pose_solver_label in self.get_active_pose_solver_labels(): pose_solver_connection: PoseSolverConnection = self._get_connection( connection_label=pose_solver_label, @@ -659,7 +659,7 @@ async def update( _, pose_solver_connection.request_id = self.update_request( request_id=pose_solver_connection.request_id) if pose_solver_connection.request_id is None: - solver_request_list: list[MCastRequest] = list() + solver_request_list: list[MCTRequest] = list() detector_labels: list[str] = self.get_active_detector_labels() for detector_label in detector_labels: current_detector_frame: DetectorFrame = self.get_live_detector_frame( @@ -683,7 +683,7 @@ async def update( detector_timestamp_utc_iso8601=current_detector_frame.timestamp_utc_iso8601) solver_request_list.append(marker_request) solver_request_list.append(GetPosesRequest()) - request_series: MCastRequestSeries = MCastRequestSeries(series=solver_request_list) + request_series: MCTRequestSeries = MCTRequestSeries(series=solver_request_list) pose_solver_connection.request_id = self.request_series_push( connection_label=pose_solver_label, request_series=request_series) @@ -711,7 +711,7 @@ def update_request( - value that request_id shall take for subsequent iterations (None means a response series has been received) """ - response_series: MCastResponseSeries | None + response_series: MCTResponseSeries | None _, response_series = self.response_series_pop(request_series_id=request_id) if response_series is None: return False, request_id # try again next loop diff --git a/src/connector/structures/__init__.py b/src/controller/structures/__init__.py similarity index 77% rename from src/connector/structures/__init__.py rename to src/controller/structures/__init__.py index bf82dab..75d66f5 100644 --- a/src/connector/structures/__init__.py +++ b/src/controller/structures/__init__.py @@ -1,4 +1,4 @@ -from .component_address import ComponentAddress +from .mct_component_address import MCTComponentAddress from .connection import Connection from .connection_report import ConnectionReport from .detector_connection import DetectorConnection diff --git a/src/connector/structures/connection.py b/src/controller/structures/connection.py similarity index 94% rename from src/connector/structures/connection.py rename to src/controller/structures/connection.py index ada0e3b..a53d546 100644 --- a/src/connector/structures/connection.py +++ b/src/controller/structures/connection.py @@ -1,10 +1,10 @@ -from .component_address import ComponentAddress +from .mct_component_address import MCTComponentAddress from .connection_report import ConnectionReport from src.common import \ - MCastParsable, \ - MCastRequestSeries, \ - MCastResponse, \ - MCastResponseSeries + MCTParsable, \ + MCTRequestSeries, \ + MCTResponse, \ + MCTResponseSeries from src.common.structures import StatusMessage, SeverityLabel import abc import datetime @@ -69,18 +69,18 @@ class Status(StrEnum): RESPONDED: Final[str] = "Responded" UNTRACKED: Final[str] = "Untracked" # this suggests an error has occurred status: Status - response_series: MCastResponseSeries | None + response_series: MCTResponseSeries | None def __init__( self, status: Status, - response_series: MCastResponseSeries | None = None + response_series: MCTResponseSeries | None = None ): self.status = status self.response_series = response_series # treat as immutable - _component_address: ComponentAddress + _component_address: MCTComponentAddress _state: State @@ -93,13 +93,13 @@ def __init__( _deinit_request_id: uuid.UUID | None # Requests are handled one at a time, with results being appended to a Response queue - _request_series_queue: list[tuple[MCastRequestSeries, uuid.UUID]] + _request_series_queue: list[tuple[MCTRequestSeries, uuid.UUID]] _current_request_id: uuid.UUID | None - _response_series_queue: dict[uuid.UUID, MCastResponseSeries] + _response_series_queue: dict[uuid.UUID, MCTResponseSeries] def __init__( self, - component_address: ComponentAddress + component_address: MCTComponentAddress ): self._component_address = component_address @@ -118,10 +118,10 @@ def __init__( self._response_series_queue = dict() @abc.abstractmethod - def create_deinitialization_request_series(self) -> MCastRequestSeries: ... + def create_deinitialization_request_series(self) -> MCTRequestSeries: ... @abc.abstractmethod - def create_initialization_request_series(self) -> MCastRequestSeries: ... + def create_initialization_request_series(self) -> MCTRequestSeries: ... def dequeue_status_messages(self) -> list[StatusMessage]: status_messages = self._status_message_queue @@ -130,7 +130,7 @@ def dequeue_status_messages(self) -> list[StatusMessage]: def enqueue_request_series( self, - request_series: MCastRequestSeries + request_series: MCTRequestSeries ) -> uuid.UUID: """ Returns the id that can be used to get the result (when it is ready) @@ -174,13 +174,13 @@ def get_role(self) -> str: @abc.abstractmethod def handle_initialization_response_series( self, - response_series: MCastResponseSeries + response_series: MCTResponseSeries ) -> InitializationResult: ... @abc.abstractmethod def handle_deinitialization_response_series( self, - response_series: MCastResponseSeries + response_series: MCTResponseSeries ) -> DeinitializationResult: ... def is_shut_down(self) -> bool: @@ -220,14 +220,14 @@ async def _send_recv( def _response_series_converter( response_series_dict: dict - ) -> MCastResponseSeries: - series_list: list[MCastResponse] = MCastParsable.parse_dynamic_series_list( + ) -> MCTResponseSeries: + series_list: list[MCTResponse] = MCTParsable.parse_dynamic_series_list( parsable_series_dict=response_series_dict, supported_types=self.supported_response_types()) - return MCastResponseSeries(series=series_list) + return MCTResponseSeries(series=series_list) if self._current_request_id is None and len(self._request_series_queue) > 0: - request_series: MCastRequestSeries + request_series: MCTRequestSeries (request_series, self._current_request_id) = self._request_series_queue.pop(0) request_series_as_dict: dict = request_series.dict() request_series_as_str: str = json.dumps(request_series_as_dict) @@ -240,7 +240,7 @@ def _response_series_converter( if self._current_request_id is not None: response_series_as_str: str = await self._socket.recv() response_series_as_dict: dict = json.loads(response_series_as_str) - response_series: MCastResponseSeries = _response_series_converter(response_series_as_dict) + response_series: MCTResponseSeries = _response_series_converter(response_series_as_dict) response_series.responder = self._component_address.label self._response_series_queue[self._current_request_id] = response_series self._current_request_id = None @@ -274,7 +274,7 @@ def start_up(self) -> None: self._next_attempt_timestamp_utc = datetime.datetime.utcnow() @abc.abstractmethod - def supported_response_types(self) -> list[type[MCastResponse]]: ... + def supported_response_types(self) -> list[type[MCTResponse]]: ... async def _try_connect(self) -> ConnectionResult: uri: str = f"ws://{self._component_address.ip_address}:{self._component_address.port}/websocket" diff --git a/src/connector/structures/connection_report.py b/src/controller/structures/connection_report.py similarity index 100% rename from src/connector/structures/connection_report.py rename to src/controller/structures/connection_report.py diff --git a/src/connector/structures/detector_connection.py b/src/controller/structures/detector_connection.py similarity index 84% rename from src/connector/structures/detector_connection.py rename to src/controller/structures/detector_connection.py index 5f93f16..2d02f6e 100644 --- a/src/connector/structures/detector_connection.py +++ b/src/controller/structures/detector_connection.py @@ -1,12 +1,12 @@ -from .component_address import ComponentAddress +from .mct_component_address import MCTComponentAddress from .connection import Connection from src.common.api import \ DequeueStatusMessagesResponse, \ EmptyResponse, \ ErrorResponse, \ - MCastRequestSeries, \ - MCastResponse, \ - MCastResponseSeries + MCTRequestSeries, \ + MCTResponse, \ + MCTResponseSeries from src.common.structures import \ DetectorResolution, \ ImageResolution, \ @@ -33,7 +33,7 @@ class DetectorConnection(Connection): - # These are variables used directly by the Connector for storing data + # These are variables used directly by the MCTController for storing data request_id: uuid.UUID | None calibration_result_identifier: str | None calibrated_resolutions: list[DetectorResolution] | None @@ -45,7 +45,7 @@ class DetectorConnection(Connection): def __init__( self, - component_address: ComponentAddress + component_address: MCTComponentAddress ): super().__init__(component_address=component_address) self.request_id = None @@ -57,15 +57,15 @@ def __init__( self.rejected_marker_snapshots = list() self.marker_snapshot_timestamp = datetime.datetime.min - def create_deinitialization_request_series(self) -> MCastRequestSeries: - return MCastRequestSeries(series=[StopCaptureRequest()]) + def create_deinitialization_request_series(self) -> MCTRequestSeries: + return MCTRequestSeries(series=[StopCaptureRequest()]) - def create_initialization_request_series(self) -> MCastRequestSeries: - return MCastRequestSeries(series=[StartCaptureRequest()]) + def create_initialization_request_series(self) -> MCTRequestSeries: + return MCTRequestSeries(series=[StartCaptureRequest()]) def handle_deinitialization_response_series( self, - response_series: MCastResponseSeries + response_series: MCTResponseSeries ) -> Connection.DeinitializationResult: response_count: int = len(response_series.series) if response_count != 1: @@ -80,7 +80,7 @@ def handle_deinitialization_response_series( def handle_initialization_response_series( self, - response_series: MCastResponseSeries + response_series: MCTResponseSeries ) -> Connection.InitializationResult: response_count: int = len(response_series.series) if response_count != 1: @@ -93,7 +93,7 @@ def handle_initialization_response_series( message=f"The initialization response was not of the expected type EmptyResponse.") return Connection.InitializationResult.SUCCESS - def supported_response_types(self) -> list[type[MCastResponse]]: + def supported_response_types(self) -> list[type[MCTResponse]]: return [ AddCalibrationImageResponse, CalibrateResponse, diff --git a/src/connector/structures/component_address.py b/src/controller/structures/mct_component_address.py similarity index 91% rename from src/connector/structures/component_address.py rename to src/controller/structures/mct_component_address.py index 2642a0c..955d7d1 100644 --- a/src/connector/structures/component_address.py +++ b/src/controller/structures/mct_component_address.py @@ -3,7 +3,7 @@ from pydantic import BaseModel, Field -class ComponentAddress(BaseModel): +class MCTComponentAddress(BaseModel): """ Information used to establish a connection, there is nothing that should change here without a user's explicit input. diff --git a/src/connector/structures/pose_solver_connection.py b/src/controller/structures/pose_solver_connection.py similarity index 78% rename from src/connector/structures/pose_solver_connection.py rename to src/controller/structures/pose_solver_connection.py index bfc63f8..02fc523 100644 --- a/src/connector/structures/pose_solver_connection.py +++ b/src/controller/structures/pose_solver_connection.py @@ -1,12 +1,12 @@ -from .component_address import ComponentAddress +from .mct_component_address import MCTComponentAddress from .connection import Connection from src.common.api import \ DequeueStatusMessagesResponse, \ EmptyResponse, \ ErrorResponse, \ - MCastRequestSeries, \ - MCastResponse, \ - MCastResponseSeries + MCTRequestSeries, \ + MCTResponse, \ + MCTResponseSeries from src.common.structures import Pose from src.pose_solver.api import \ AddTargetMarkerResponse, \ @@ -19,7 +19,7 @@ class PoseSolverConnection(Connection): - # These are variables used directly by the Connector for storing data + # These are variables used directly by the MCTController for storing data request_id: uuid.UUID | None detector_poses: list[Pose] target_poses: list[Pose] @@ -28,7 +28,7 @@ class PoseSolverConnection(Connection): def __init__( self, - component_address: ComponentAddress + component_address: MCTComponentAddress ): super().__init__(component_address=component_address) self.request_id = None @@ -37,15 +37,15 @@ def __init__( self.detector_timestamps = dict() self.poses_timestamp = datetime.datetime.min - def create_deinitialization_request_series(self) -> MCastRequestSeries: - return MCastRequestSeries(series=[StopPoseSolverRequest()]) + def create_deinitialization_request_series(self) -> MCTRequestSeries: + return MCTRequestSeries(series=[StopPoseSolverRequest()]) - def create_initialization_request_series(self) -> MCastRequestSeries: - return MCastRequestSeries(series=[StartPoseSolverRequest()]) + def create_initialization_request_series(self) -> MCTRequestSeries: + return MCTRequestSeries(series=[StartPoseSolverRequest()]) def handle_deinitialization_response_series( self, - response_series: MCastResponseSeries + response_series: MCTResponseSeries ) -> Connection.DeinitializationResult: response_count: int = len(response_series.series) if response_count != 1: @@ -60,7 +60,7 @@ def handle_deinitialization_response_series( def handle_initialization_response_series( self, - response_series: MCastResponseSeries + response_series: MCTResponseSeries ) -> Connection.InitializationResult: response_count: int = len(response_series.series) if response_count != 1: @@ -73,7 +73,7 @@ def handle_initialization_response_series( message=f"The initialization response was not of the expected type EmptyResponse.") return Connection.InitializationResult.SUCCESS - def supported_response_types(self) -> list[type[MCastResponse]]: + def supported_response_types(self) -> list[type[MCTResponse]]: return [ AddTargetMarkerResponse, DequeueStatusMessagesResponse, diff --git a/src/detector/api/get_capture_image_request.py b/src/detector/api/get_capture_image_request.py index 6503692..e63b111 100644 --- a/src/detector/api/get_capture_image_request.py +++ b/src/detector/api/get_capture_image_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import CaptureFormat from pydantic import Field -class GetCaptureImageRequest(MCastRequest): +class GetCaptureImageRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "get_capture_image" diff --git a/src/detector/api/get_capture_image_response.py b/src/detector/api/get_capture_image_response.py index 3de7f8f..12a3020 100644 --- a/src/detector/api/get_capture_image_response.py +++ b/src/detector/api/get_capture_image_response.py @@ -1,9 +1,9 @@ -from src.common import MCastResponse +from src.common import MCTResponse from src.common.structures import CaptureFormat from pydantic import Field -class GetCaptureImageResponse(MCastResponse): +class GetCaptureImageResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: diff --git a/src/detector/api/get_capture_properties_request.py b/src/detector/api/get_capture_properties_request.py index 1e87e43..fe1649b 100644 --- a/src/detector/api/get_capture_properties_request.py +++ b/src/detector/api/get_capture_properties_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class GetCapturePropertiesRequest(MCastRequest): +class GetCapturePropertiesRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "get_capture_properties" diff --git a/src/detector/api/get_capture_properties_response.py b/src/detector/api/get_capture_properties_response.py index 1dab9a8..a980f76 100644 --- a/src/detector/api/get_capture_properties_response.py +++ b/src/detector/api/get_capture_properties_response.py @@ -1,8 +1,8 @@ -from src.common import MCastResponse +from src.common import MCTResponse from pydantic import Field -class GetCapturePropertiesResponse(MCastResponse): +class GetCapturePropertiesResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "get_capture_properties" diff --git a/src/detector/api/get_detection_parameters_request.py b/src/detector/api/get_detection_parameters_request.py index b9ac214..6c1f7a0 100644 --- a/src/detector/api/get_detection_parameters_request.py +++ b/src/detector/api/get_detection_parameters_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class GetDetectionParametersRequest(MCastRequest): +class GetDetectionParametersRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "get_detection_parameters" diff --git a/src/detector/api/get_detection_parameters_response.py b/src/detector/api/get_detection_parameters_response.py index fc0095d..d5ba7d4 100644 --- a/src/detector/api/get_detection_parameters_response.py +++ b/src/detector/api/get_detection_parameters_response.py @@ -1,9 +1,9 @@ -from src.common import MCastResponse +from src.common import MCTResponse from src.common.structures import DetectionParameters from pydantic import Field -class GetDetectionParametersResponse(MCastResponse): +class GetDetectionParametersResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "get_detection_parameters" diff --git a/src/detector/api/get_marker_snapshots_request.py b/src/detector/api/get_marker_snapshots_request.py index 2e4383a..15b687b 100644 --- a/src/detector/api/get_marker_snapshots_request.py +++ b/src/detector/api/get_marker_snapshots_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class GetMarkerSnapshotsRequest(MCastRequest): +class GetMarkerSnapshotsRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "get_marker_snapshots" diff --git a/src/detector/api/get_marker_snapshots_response.py b/src/detector/api/get_marker_snapshots_response.py index 5f68f34..baac54c 100644 --- a/src/detector/api/get_marker_snapshots_response.py +++ b/src/detector/api/get_marker_snapshots_response.py @@ -1,9 +1,9 @@ -from src.common import MCastResponse +from src.common import MCTResponse from src.common.structures import MarkerSnapshot from pydantic import Field -class GetMarkerSnapshotsResponse(MCastResponse): +class GetMarkerSnapshotsResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "get_marker_snapshots" diff --git a/src/detector/api/set_capture_intrinsics_request.py b/src/detector/api/set_capture_intrinsics_request.py index db1228a..cac88bd 100644 --- a/src/detector/api/set_capture_intrinsics_request.py +++ b/src/detector/api/set_capture_intrinsics_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import IntrinsicParameters from pydantic import Field -class SetCaptureIntrinsicsRequest(MCastRequest): +class SetCaptureIntrinsicsRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "set_capture_intrinsics" diff --git a/src/detector/api/set_capture_properties_request.py b/src/detector/api/set_capture_properties_request.py index 3c2715c..e492e1e 100644 --- a/src/detector/api/set_capture_properties_request.py +++ b/src/detector/api/set_capture_properties_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class SetCapturePropertiesRequest(MCastRequest): +class SetCapturePropertiesRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "set_capture_properties" diff --git a/src/detector/api/set_detection_parameters_request.py b/src/detector/api/set_detection_parameters_request.py index 3fceb31..364e341 100644 --- a/src/detector/api/set_detection_parameters_request.py +++ b/src/detector/api/set_detection_parameters_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import DetectionParameters from pydantic import Field -class SetDetectionParametersRequest(MCastRequest): +class SetDetectionParametersRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "set_detection_parameters" diff --git a/src/detector/api/set_marker_dictionary_request.py b/src/detector/api/set_marker_dictionary_request.py index 406a770..4cfc5f1 100644 --- a/src/detector/api/set_marker_dictionary_request.py +++ b/src/detector/api/set_marker_dictionary_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import MarkerDefinition from pydantic import Field -class SetMarkerDictionaryRequest(MCastRequest): +class SetMarkerDictionaryRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "set_marker_dictionary" diff --git a/src/detector/api/start_capture_request.py b/src/detector/api/start_capture_request.py index d73440d..8a8924f 100644 --- a/src/detector/api/start_capture_request.py +++ b/src/detector/api/start_capture_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class StartCaptureRequest(MCastRequest): +class StartCaptureRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "start_capture" diff --git a/src/detector/api/stop_capture_request.py b/src/detector/api/stop_capture_request.py index 3028941..2addd18 100644 --- a/src/detector/api/stop_capture_request.py +++ b/src/detector/api/stop_capture_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class StopCaptureRequest(MCastRequest): +class StopCaptureRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "stop_capture" diff --git a/src/detector/detector.py b/src/detector/detector.py index 4638b27..dac79a7 100644 --- a/src/detector/detector.py +++ b/src/detector/detector.py @@ -29,9 +29,9 @@ from src.common import \ EmptyResponse, \ ErrorResponse, \ - MCastComponent, \ - MCastRequest, \ - MCastResponse + MCTComponent, \ + MCTRequest, \ + MCTResponse from src.common.structures.capture_status import CaptureStatus from src.common.structures.marker_status import MarkerStatus import logging @@ -43,7 +43,7 @@ logger = logging.getLogger(__name__) -class Detector(MCastComponent): +class Detector(MCTComponent): _detector_configuration: DetectorConfiguration _calibrator: Calibrator @@ -84,8 +84,8 @@ async def internal_update(self): if self._frame_count % 1000 == 0: print(f"Update count: {self._frame_count}") - def supported_request_types(self) -> dict[type[MCastRequest], Callable[[dict], MCastResponse]]: - return_value: dict[type[MCastRequest], Callable[[dict], MCastResponse]] = super().supported_request_types() + def supported_request_types(self) -> dict[type[MCTRequest], Callable[[dict], MCTResponse]]: + return_value: dict[type[MCTRequest], Callable[[dict], MCTResponse]] = super().supported_request_types() return_value.update({ # Detector Requests @@ -129,10 +129,10 @@ def get_capture_properties(self, **_kwargs) -> GetCapturePropertiesResponse | Er def get_capture_image(self, **kwargs) -> GetCaptureImageResponse: return self._camera_interface.get_capture_image(**kwargs) - def start_capture(self, **kwargs) -> MCastResponse: + def start_capture(self, **kwargs) -> MCTResponse: return self._camera_interface.start_capture(**kwargs) - def stop_capture(self, **kwargs) -> MCastResponse: + def stop_capture(self, **kwargs) -> MCTResponse: return self._camera_interface.stop_capture(**kwargs) # Marker diff --git a/src/detector/exceptions/update_capture_error.py b/src/detector/exceptions/update_capture_error.py index 7b72317..3730aa5 100644 --- a/src/detector/exceptions/update_capture_error.py +++ b/src/detector/exceptions/update_capture_error.py @@ -1,8 +1,8 @@ -from src.common.exceptions import MCastError +from src.common.exceptions import MCTError from src.common.structures import SeverityLabel -class UpdateCaptureError(MCastError): +class UpdateCaptureError(MCTError): severity: SeverityLabel message: str diff --git a/src/detector/implementations/abstract_camera_interface.py b/src/detector/implementations/abstract_camera_interface.py index 27028f4..a92ae47 100644 --- a/src/detector/implementations/abstract_camera_interface.py +++ b/src/detector/implementations/abstract_camera_interface.py @@ -3,7 +3,7 @@ EmptyResponse, \ ErrorResponse, \ get_kwarg, \ - MCastResponse + MCTResponse from src.detector.api import \ GetCapturePropertiesResponse, \ GetCaptureImageResponse, \ @@ -32,10 +32,10 @@ def set_capture_properties(self, **kwargs) -> EmptyResponse: def get_capture_properties(self, **_kwargs) -> GetCapturePropertiesResponse | ErrorResponse: pass - def start_capture(self, **kwargs) -> MCastResponse: + def start_capture(self, **kwargs) -> MCTResponse: pass - def stop_capture(self, **kwargs) -> MCastResponse: + def stop_capture(self, **kwargs) -> MCTResponse: pass def get_capture_image(self, **kwargs) -> GetCaptureImageResponse: diff --git a/src/detector/implementations/picamera2_implementation.py b/src/detector/implementations/picamera2_implementation.py index f9ebf5c..50ef4c0 100644 --- a/src/detector/implementations/picamera2_implementation.py +++ b/src/detector/implementations/picamera2_implementation.py @@ -6,7 +6,7 @@ EmptyResponse, \ ErrorResponse, \ get_kwarg, \ - MCastResponse + MCTResponse from src.common.structures.capture_status import CaptureStatus from src.detector.implementations import AbstractCameraInterface @@ -122,13 +122,13 @@ def get_capture_properties(self, **_kwargs) -> GetCapturePropertiesResponse | Er sharpness=self._camera_controls.Sharpness) return ret - def start_capture(self, **kwargs) -> MCastResponse: + def start_capture(self, **kwargs) -> MCTResponse: self._camera.start() self._captured_image = self._camera.capture_array() self._capture_status.status = CaptureStatus.Status.RUNNING return EmptyResponse() - def stop_capture(self, **kwargs) -> MCastResponse: + def stop_capture(self, **kwargs) -> MCTResponse: if self._captured_image is not None: self._captured_image = None self._capture_status.status = CaptureStatus.Status.STOPPED diff --git a/src/detector/implementations/usb_webcam_implementation.py b/src/detector/implementations/usb_webcam_implementation.py index 041c563..0cb53cd 100644 --- a/src/detector/implementations/usb_webcam_implementation.py +++ b/src/detector/implementations/usb_webcam_implementation.py @@ -6,7 +6,7 @@ EmptyResponse, \ ErrorResponse, \ get_kwarg, \ - MCastResponse + MCTResponse from src.common.structures.capture_status import CaptureStatus from src.detector.implementations import AbstractCameraInterface @@ -117,7 +117,7 @@ def get_capture_properties(self, **_kwargs) -> GetCapturePropertiesResponse | Er gamma=int(self._capture.get(cv2.CAP_PROP_GAMMA))) # TODO: Get powerline_frequency_hz and backlight_compensation - def start_capture(self, **kwargs) -> MCastResponse: + def start_capture(self, **kwargs) -> MCTResponse: if isinstance(self._capture_device_id, str) and self._capture_device_id.isnumeric(): self._capture_device_id.isnumeric = int(self._capture_device_id) if self._capture is not None: @@ -134,7 +134,7 @@ def start_capture(self, **kwargs) -> MCastResponse: self._capture_status.status = CaptureStatus.Status.RUNNING return EmptyResponse() - def stop_capture(self, **kwargs) -> MCastResponse: + def stop_capture(self, **kwargs) -> MCTResponse: if self._capture is not None: self._capture.release() self._capture = None diff --git a/src/gui/gui.py b/src/gui/gui.py index 31d916c..4d38d7c 100644 --- a/src/gui/gui.py +++ b/src/gui/gui.py @@ -1,11 +1,11 @@ from src.gui.panels import \ BasePanel, \ CalibratorPanel, \ - ConnectorPanel, \ + ControllerPanel, \ DetectorPanel, \ PoseSolverPanel from src.common import StatusMessageSource -from src.connector import Connector +from src.controller import MCTController import asyncio import logging import wx @@ -13,7 +13,7 @@ from typing import Final -CONNECTOR_LABEL: Final[str] = "Connector" +CONTROLLER_LABEL: Final[str] = "Controller" DETECTOR_LABEL: Final[str] = "Detector" CALIBRATOR_LABEL: Final[str] = "Calibrator" POSE_SOLVER_LABEL: Final[str] = "Pose Solver" @@ -23,17 +23,17 @@ class ControllerFrame(wx.Frame): _status_message_source: StatusMessageSource - _connector: Connector + _controller: MCTController _notebook: wx.Notebook - _connector_panel: ConnectorPanel + _controller_panel: ControllerPanel _detector_panel: DetectorPanel _calibrator_panel: CalibratorPanel _pose_solver_panel: PoseSolverPanel def __init__( self, - connector: Connector, + controller: MCTController, *args, **kwargs ): @@ -42,7 +42,7 @@ def __init__( self._status_message_source = StatusMessageSource( source_label="gui", send_to_logger=True) - self._connector = connector + self._controller = controller self.SetMinSize(wx.Size(800, 600)) @@ -54,19 +54,19 @@ def __init__( wx.SizerFlags(1).Expand()) frame_panel.SetSizerAndFit(frame_panel_sizer) - self._connector_panel = ConnectorPanel( + self._controller_panel = ControllerPanel( parent=self._notebook, - connector=self._connector, + controller=self._controller, status_message_source=self._status_message_source) self._notebook.AddPage( - page=self._connector_panel, - text=CONNECTOR_LABEL, + page=self._controller_panel, + text=CONTROLLER_LABEL, select=True) - self._connector_panel.panel_is_selected = True + self._controller_panel.panel_is_selected = True self._detector_panel = DetectorPanel( parent=self._notebook, - connector=self._connector, + controller=self._controller, status_message_source=self._status_message_source) self._notebook.AddPage( page=self._detector_panel, @@ -75,7 +75,7 @@ def __init__( self._calibrator_panel = CalibratorPanel( parent=self._notebook, - connector=self._connector, + controller=self._controller, status_message_source=self._status_message_source) self._notebook.AddPage( page=self._calibrator_panel, @@ -84,7 +84,7 @@ def __init__( self._pose_solver_panel = PoseSolverPanel( parent=self._notebook, - connector=self._connector, + controller=self._controller, status_message_source=self._status_message_source) self._notebook.AddPage( page=self._pose_solver_panel, @@ -100,7 +100,7 @@ def __init__( def on_page_changed(self, event: wx.BookCtrlEvent): pages: list[BasePanel] = [ - self._connector_panel, + self._controller_panel, self._detector_panel, self._calibrator_panel, self._pose_solver_panel] @@ -116,32 +116,32 @@ def on_page_changed(self, event: wx.BookCtrlEvent): break -async def connector_frame_repeat(connector: Connector): +async def controller_frame_repeat(controller: MCTController): # noinspection PyBroadException try: - await connector.update() + await controller.update() except Exception as e: - connector.add_status_message( + controller.add_status_message( severity="error", - message=f"Exception occurred in connector loop: {str(e)}") + message=f"Exception occurred in controller loop: {str(e)}") event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop() - event_loop.create_task(connector_frame_repeat(connector=connector)) + event_loop.create_task(controller_frame_repeat(controller=controller)) async def main(): logging.basicConfig(level=logging.INFO) - connector = Connector( - serial_identifier="connector", + controller = MCTController( + serial_identifier="controller", send_status_messages_to_logger=True) event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop() - event_loop.create_task(connector_frame_repeat(connector=connector)) + event_loop.create_task(controller_frame_repeat(controller=controller)) app: wxasync.WxAsyncApp = wxasync.WxAsyncApp() frame: ControllerFrame = ControllerFrame( - connector=connector, + controller=controller, parent=None, - title="MCAST Controller") + title="MCT Controller") frame.Show() await app.MainLoop() diff --git a/src/gui/panels/__init__.py b/src/gui/panels/__init__.py index 88c4c91..ccf810f 100644 --- a/src/gui/panels/__init__.py +++ b/src/gui/panels/__init__.py @@ -1,5 +1,5 @@ from .base_panel import BasePanel from .calibrator_panel import CalibratorPanel -from .connector_panel import ConnectorPanel +from .controller_panel import ControllerPanel from .detector_panel import DetectorPanel from .pose_solver_panel import PoseSolverPanel diff --git a/src/gui/panels/base_panel.py b/src/gui/panels/base_panel.py index 8ff5d17..bb1f493 100644 --- a/src/gui/panels/base_panel.py +++ b/src/gui/panels/base_panel.py @@ -6,10 +6,8 @@ ParameterText from src.common import \ ErrorResponse, \ - MCastResponse, \ + MCTResponse, \ StatusMessageSource -from src.connector import \ - Connector from typing import Final import wx @@ -26,17 +24,13 @@ class BasePanel(wx.Panel): _update_loop_running: bool - _connector: Connector - def __init__( self, parent: wx.Window, - connector: Connector, status_message_source: StatusMessageSource, name: str ): super().__init__(parent=parent, name=name) - self._connector = connector self.panel_is_selected = False self.status_message_source = status_message_source @@ -53,7 +47,7 @@ def handle_error_response( def handle_unknown_response( self, - response: MCastResponse + response: MCTResponse ): self.status_message_source.enqueue_status_message( severity="error", diff --git a/src/gui/panels/calibrator_panel.py b/src/gui/panels/calibrator_panel.py index c612fd6..eeea80f 100644 --- a/src/gui/panels/calibrator_panel.py +++ b/src/gui/panels/calibrator_panel.py @@ -34,15 +34,15 @@ EmptyResponse, \ ImageCoding, \ ImageUtils, \ - MCastRequestSeries, \ - MCastResponse, \ - MCastResponseSeries, \ + MCTRequestSeries, \ + MCTResponse, \ + MCTResponseSeries, \ StatusMessageSource from src.common.structures import \ DetectorResolution, \ ImageResolution -from src.connector import \ - Connector +from src.controller import \ + MCTController from io import BytesIO import logging from typing import Optional @@ -56,7 +56,7 @@ class CalibratorPanel(BasePanel): - _connector: Connector + _controller: MCTController _detector_selector: ParameterSelector _detector_resolution_selector: ParameterSelector @@ -85,16 +85,15 @@ class CalibratorPanel(BasePanel): def __init__( self, parent: wx.Window, - connector: Connector, + controller: MCTController, status_message_source: StatusMessageSource, name: str = "CalibratorPanel" ): super().__init__( parent=parent, - connector=connector, status_message_source=status_message_source, name=name) - self._connector = connector + self._controller = controller self._control_blocking_request_id = None self._is_updating = False @@ -280,11 +279,11 @@ def handle_error_response( def handle_response_series( self, - response_series: MCastResponseSeries, + response_series: MCTResponseSeries, task_description: Optional[str] = None, expected_response_count: Optional[int] = None ) -> None: - response: MCastResponse + response: MCTResponse for response in response_series.series: if isinstance(response, CalibrateResponse): self._handle_response_calibrate(response=response) @@ -306,7 +305,7 @@ def handle_response_series( def on_page_select(self) -> None: super().on_page_select() selected_detector_label: str = self._detector_selector.selector.GetStringSelection() - available_detector_labels: list[str] = self._connector.get_active_detector_labels() + available_detector_labels: list[str] = self._controller.get_active_detector_labels() self._detector_selector.set_options(option_list=available_detector_labels) if selected_detector_label in available_detector_labels: self._detector_selector.selector.SetStringSelection(selected_detector_label) @@ -317,9 +316,9 @@ def on_page_select(self) -> None: def update_loop(self) -> None: super().update_loop() self._is_updating = True - response_series: MCastResponseSeries | None + response_series: MCTResponseSeries | None if self._control_blocking_request_id is not None: - self._control_blocking_request_id, response_series = self._connector.response_series_pop( + self._control_blocking_request_id, response_series = self._controller.response_series_pop( request_series_id=self._control_blocking_request_id) if response_series is not None: # self._control_blocking_request_id will be None self.handle_response_series(response_series) @@ -404,14 +403,14 @@ def _on_calibrate_pressed(self, _event: wx.CommandEvent) -> None: selected_detector_label: str = self._detector_selector.selector.GetStringSelection() selected_image_resolution: ImageResolution = \ ImageResolution.from_str(self._detector_resolution_selector.selector.GetStringSelection()) - request_series: MCastRequestSeries = MCastRequestSeries(series=[ + request_series: MCTRequestSeries = MCTRequestSeries(series=[ CalibrateRequest( detector_serial_identifier=selected_detector_label, image_resolution=selected_image_resolution), ListCalibrationResultMetadataRequest( detector_serial_identifier=selected_detector_label, image_resolution=selected_image_resolution)]) - self._control_blocking_request_id = self._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=selected_detector_label, request_series=request_series) self._calibration_in_progress = True @@ -424,8 +423,8 @@ def _on_detector_selected(self, _event: wx.CommandEvent) -> None: self._calibrate_status_textbox.SetValue(str()) self._result_display_textbox.SetValue(str()) detector_label: str = self._detector_selector.selector.GetStringSelection() - request_series: MCastRequestSeries = MCastRequestSeries(series=[ListCalibrationDetectorResolutionsRequest()]) - self._control_blocking_request_id = self._connector.request_series_push( + request_series: MCTRequestSeries = MCTRequestSeries(series=[ListCalibrationDetectorResolutionsRequest()]) + self._control_blocking_request_id = self._controller.request_series_push( connection_label=detector_label, request_series=request_series) self._update_ui_controls() @@ -438,14 +437,14 @@ def _on_detector_load_pressed(self, _event: wx.CommandEvent) -> None: selected_detector_label: str = self._detector_selector.selector.GetStringSelection() selected_image_resolution: ImageResolution = \ ImageResolution.from_str(self._detector_resolution_selector.selector.GetStringSelection()) - request_series: MCastRequestSeries = MCastRequestSeries(series=[ + request_series: MCTRequestSeries = MCTRequestSeries(series=[ ListCalibrationImageMetadataRequest( detector_serial_identifier=selected_detector_label, image_resolution=selected_image_resolution), ListCalibrationResultMetadataRequest( detector_serial_identifier=selected_detector_label, image_resolution=selected_image_resolution)]) - self._control_blocking_request_id = self._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=selected_detector_label, request_series=request_series) self._update_ui_controls() @@ -471,10 +470,10 @@ def _on_image_metadata_selected(self, _event: wx.grid.GridEvent) -> None: image_index: int = self._image_table.get_selected_row_index() image_identifier: str | None = self._image_metadata_list[image_index].identifier if image_identifier is not None: - request_series: MCastRequestSeries = MCastRequestSeries(series=[ + request_series: MCTRequestSeries = MCTRequestSeries(series=[ GetCalibrationImageRequest(image_identifier=image_identifier)]) detector_label: str = self._detector_selector.selector.GetStringSelection() - self._control_blocking_request_id = self._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=detector_label, request_series=request_series) self._update_ui_controls() @@ -489,7 +488,7 @@ def _on_image_update_pressed(self, _event: wx.CommandEvent) -> None: image_state: CalibrationImageState = \ CalibrationImageState[self._image_state_selector.selector.GetStringSelection()] image_label: str = self._image_label_textbox.textbox.GetValue() - request_series: MCastRequestSeries = MCastRequestSeries(series=[ + request_series: MCTRequestSeries = MCTRequestSeries(series=[ UpdateCalibrationImageMetadataRequest( image_identifier=image_identifier, image_state=image_state, @@ -498,7 +497,7 @@ def _on_image_update_pressed(self, _event: wx.CommandEvent) -> None: ListCalibrationImageMetadataRequest( detector_serial_identifier=detector_label, image_resolution=image_resolution)]) - self._control_blocking_request_id = selfu._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=detector_label, request_series=request_series) self._update_ui_controls() @@ -510,10 +509,10 @@ def _on_result_metadata_selected(self, _event: wx.grid.GridEvent) -> None: result_index: int = self._result_table.get_selected_row_index() result_identifier: str | None = self._result_metadata_list[result_index].identifier if result_identifier is not None: - request_series: MCastRequestSeries = MCastRequestSeries(series=[ + request_series: MCTRequestSeries = MCTRequestSeries(series=[ GetCalibrationResultRequest(result_identifier=result_identifier)]) detector_label: str = self._detector_selector.selector.GetStringSelection() - self._control_blocking_request_id = self._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=detector_label, request_series=request_series) self._update_ui_controls() @@ -527,7 +526,7 @@ def _on_result_update_pressed(self, _event: wx.CommandEvent) -> None: result_identifier: str = self._result_metadata_list[result_index].identifier result_state: CalibrationResultState = \ CalibrationResultState[self._result_state_selector.selector.GetStringSelection()] - request_series: MCastRequestSeries = MCastRequestSeries(series=[ + request_series: MCTRequestSeries = MCTRequestSeries(series=[ UpdateCalibrationResultMetadataRequest( result_identifier=result_identifier, result_state=result_state), @@ -535,7 +534,7 @@ def _on_result_update_pressed(self, _event: wx.CommandEvent) -> None: ListCalibrationResultMetadataRequest( detector_serial_identifier=detector_label, image_resolution=image_resolution)]) - self._control_blocking_request_id = self._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=detector_label, request_series=request_series) self._update_ui_controls() diff --git a/src/gui/panels/connector_panel.py b/src/gui/panels/controller_panel.py similarity index 85% rename from src/gui/panels/connector_panel.py rename to src/gui/panels/controller_panel.py index ba16fdd..4f27a9f 100644 --- a/src/gui/panels/connector_panel.py +++ b/src/gui/panels/controller_panel.py @@ -13,9 +13,9 @@ COMPONENT_ROLE_LABEL_DETECTOR, \ COMPONENT_ROLE_LABEL_POSE_SOLVER, \ StatusMessage -from src.connector import \ - ComponentAddress, \ - Connector, \ +from src.controller import \ + MCTComponentAddress, \ + MCTController, \ ConnectionReport from ipaddress import IPv4Address from pydantic import ValidationError @@ -27,9 +27,9 @@ _STATUS_MESSAGE_TABLE_SUBSCRIBER_LABEL: Final[str] = "status_message_table" -class ConnectorPanel(BasePanel): +class ControllerPanel(BasePanel): - _connector: Connector + _controller: MCTController _parameter_label: ParameterText _parameter_role: ParameterSelector _parameter_ipaddress: ParameterText @@ -37,31 +37,30 @@ class ConnectorPanel(BasePanel): _add_new_button: wx.Button _connection_table: ConnectionTable _remove_button: wx.Button - _connector_status_textbox: wx.TextCtrl + _controller_status_textbox: wx.TextCtrl _start_detectors_only_button: wx.Button _start_detectors_solvers_button: wx.Button _stop_button: wx.Button _log_panel: LogPanel - _controller_status: str # last status reported by Controller + _controller_status: str # last status reported by MCTController _connection_reports: list[ConnectionReport] _is_updating: bool # Some things should only trigger during explicit user events def __init__( self, parent: wx.Window, - connector: Connector, + controller: MCTController, status_message_source: StatusMessageSource, - name: str = "ConnectorPanel" + name: str = "ControllerPanel" ): super().__init__( parent=parent, - connector=connector, status_message_source=status_message_source, name=name) - self._connector = connector + self._controller = controller - self._connector.add_status_subscriber(client_identifier=_STATUS_MESSAGE_TABLE_SUBSCRIBER_LABEL) + self._controller.add_status_subscriber(client_identifier=_STATUS_MESSAGE_TABLE_SUBSCRIBER_LABEL) self.status_message_source.add_status_subscriber(subscriber_label=_STATUS_MESSAGE_TABLE_SUBSCRIBER_LABEL) horizontal_split_sizer: wx.BoxSizer = wx.BoxSizer(orient=wx.HORIZONTAL) @@ -132,13 +131,13 @@ def __init__( parent=control_panel, sizer=control_sizer) - self._connector_status_textbox = wx.TextCtrl( + self._controller_status_textbox = wx.TextCtrl( parent=control_panel, style=wx.TE_READONLY | wx.TE_RICH) - self._connector_status_textbox.SetEditable(False) - self._connector_status_textbox.SetBackgroundColour(colour=wx.Colour(red=249, green=249, blue=249, alpha=255)) + self._controller_status_textbox.SetEditable(False) + self._controller_status_textbox.SetBackgroundColour(colour=wx.Colour(red=249, green=249, blue=249, alpha=255)) control_sizer.Add( - window=self._connector_status_textbox, + window=self._controller_status_textbox, flags=wx.SizerFlags(0).Expand()) control_sizer.AddSpacer(size=BasePanel.DEFAULT_SPACING_PX_VERTICAL) @@ -219,13 +218,13 @@ def on_add_new_pressed(self, _event: wx.CommandEvent) -> None: label: str = self._parameter_label.textbox.GetValue() if len(label) < 1: message: str = f"Provided label must contain 1 or more characters." - self._connector.add_status_message( + self._controller.add_status_message( severity="error", message=message) return - if self._connector.contains_connection_label(label=label): + if self._controller.contains_connection_label(label=label): message: str = f"Provided label {label} already exists. Remove existing before adding again." - self._connector.add_status_message( + self._controller.add_status_message( severity="error", message=message) return @@ -235,25 +234,25 @@ def on_add_new_pressed(self, _event: wx.CommandEvent) -> None: ip_address = IPv4Address(ip_address_str) except ValueError: message: str = f"Provided IP Address {ip_address_str} does not appear to be valid." - self._connector.add_status_message( + self._controller.add_status_message( severity="error", message=message) return - component_address: ComponentAddress + component_address: MCTComponentAddress try: selected_role_index: int = self._parameter_role.selector.GetSelection() - component_address: ComponentAddress = ComponentAddress( + component_address: MCTComponentAddress = MCTComponentAddress( label=label, role=self._parameter_role.selector.GetString(n=selected_role_index), ip_address=ip_address, port=self._parameter_port.spinbox.GetValue()) except ValidationError as e: message: str = f"Unexpected validation error {e}" - self._connector.add_status_message( + self._controller.add_status_message( severity="error", message=message) return - self._connector.add_connection(component_address=component_address) + self._controller.add_connection(component_address=component_address) self.update_controller_buttons() self._parameter_label.textbox.SetValue(value=str()) @@ -266,20 +265,20 @@ def on_connection_selected(self, event: wx.grid.GridEvent): self._remove_button.Enable(enable=False) def on_start_detectors_only_pressed(self, _event: wx.CommandEvent) -> None: - self._connector.start_up(mode=Connector.StartupMode.DETECTING_ONLY) + self._controller.start_up(mode=MCTController.StartupMode.DETECTING_ONLY) self.update_controller_buttons() def on_start_detectors_solvers_pressed(self, _event: wx.CommandEvent) -> None: - self._connector.start_up(mode=Connector.StartupMode.DETECTING_AND_SOLVING) + self._controller.start_up(mode=MCTController.StartupMode.DETECTING_AND_SOLVING) self.update_controller_buttons() def on_stop_pressed(self, _event: wx.CommandEvent) -> None: - self._connector.shut_down() + self._controller.shut_down() self.update_controller_buttons() def on_remove_pressed(self, _event: wx.CommandEvent): selected_row_label: str | None = self._connection_table.get_selected_row_label() - self._connector.remove_connection(label=selected_row_label) + self._controller.remove_connection(label=selected_row_label) self.update_connection_table_display() self.update_controller_buttons() self._remove_button.Enable(enable=False) @@ -288,10 +287,10 @@ def update_loop(self): super().update_loop() self._is_updating = True self.update_connection_table_display() - controller_status: str = self._connector.get_status() + controller_status: str = self._controller.get_status() if controller_status != self._controller_status: self._controller_status = controller_status - self._connector_status_textbox.SetValue(f"Controller Status: {controller_status}") + self._controller_status_textbox.SetValue(f"MCTController Status: {controller_status}") self.update_controller_buttons() self.update_loop_log_table() self._is_updating = False @@ -300,10 +299,10 @@ def update_controller_buttons(self): self._start_detectors_only_button.Enable(enable=False) self._start_detectors_solvers_button.Enable(enable=False) self._stop_button.Enable(enable=False) - if self._connector.is_running(): + if self._controller.is_running(): self._stop_button.Enable(enable=True) - elif self._connector.is_idle(): - detector_list: list = self._connector.get_component_labels(role=COMPONENT_ROLE_LABEL_DETECTOR) + elif self._controller.is_idle(): + detector_list: list = self._controller.get_component_labels(role=COMPONENT_ROLE_LABEL_DETECTOR) contains_detectors: bool = len(detector_list) > 0 if contains_detectors: self._start_detectors_only_button.Enable(enable=True) @@ -311,7 +310,7 @@ def update_controller_buttons(self): def update_connection_table_display(self) -> None: # Return if there is no change - connection_reports: list[ConnectionReport] = self._connector.get_connection_reports() + connection_reports: list[ConnectionReport] = self._controller.get_connection_reports() if len(connection_reports) == len(self._connection_reports): identical: bool = True for connection_report in connection_reports: @@ -331,7 +330,7 @@ def update_connection_table_display(self) -> None: def update_loop_log_table(self): status_messages_response: DequeueStatusMessagesResponse = \ - self._connector.dequeue_status_messages( + self._controller.dequeue_status_messages( client_identifier=_STATUS_MESSAGE_TABLE_SUBSCRIBER_LABEL) status_messages: list[StatusMessage] = status_messages_response.status_messages status_messages += self.status_message_source.pop_new_status_messages( diff --git a/src/gui/panels/detector_panel.py b/src/gui/panels/detector_panel.py index 5252fe5..821efe6 100644 --- a/src/gui/panels/detector_panel.py +++ b/src/gui/panels/detector_panel.py @@ -15,9 +15,9 @@ EmptyResponse, \ ImageCoding, \ ImageUtils, \ - MCastRequestSeries, \ - MCastResponse, \ - MCastResponseSeries, \ + MCTRequestSeries, \ + MCTResponse, \ + MCTResponseSeries, \ StandardResolutions, \ StatusMessageSource from src.common.structures import \ @@ -26,8 +26,8 @@ DetectorFrame, \ ImageResolution, \ MarkerSnapshot -from src.connector import \ - Connector +from src.controller import \ + MCTController from src.detector.api import \ GetCaptureImageRequest, \ GetCaptureImageResponse, \ @@ -69,7 +69,7 @@ class DetectorPanel(BasePanel): - _connector: Connector + _controller: MCTController _control_blocking_request_id: uuid.UUID | None _live_preview_request_id: uuid.UUID | None @@ -137,16 +137,15 @@ class DetectorPanel(BasePanel): def __init__( self, parent: wx.Window, - connector: Connector, + controller: MCTController, status_message_source: StatusMessageSource, name: str = "DetectorPanel" ): super().__init__( parent=parent, - connector=connector, status_message_source=status_message_source, name=name) - self._connector = connector + self._controller = controller self._capture_active = False self._live_preview_request_id = None self._control_blocking_request_id = None @@ -660,27 +659,27 @@ def begin_capture_calibration(self) -> None: severity="error", message=f"Requested to add a calibration image but there is no live image. Returning.") return - request_series: MCastRequestSeries = MCastRequestSeries( + request_series: MCTRequestSeries = MCTRequestSeries( series=[ AddCalibrationImageRequest( detector_serial_identifier=selected_detector_label, format=_CAPTURE_FORMAT, image_base64=self._live_image_base64)]) - self._live_preview_request_id = self._connector.request_series_push( + self._live_preview_request_id = self._controller.request_series_push( connection_label=selected_detector_label, request_series=request_series) self._update_ui_controls() def begin_capture_snapshot(self): selected_detector_label: str = self._detector_selector.selector.GetStringSelection() - request_series: MCastRequestSeries = MCastRequestSeries( + request_series: MCTRequestSeries = MCTRequestSeries( series=[ GetCaptureImageRequest( format=_CAPTURE_FORMAT), GetMarkerSnapshotsRequest( detected_marker_snapshots=True, rejected_marker_snapshots=True)]) - self._live_preview_request_id = self._connector.request_series_push( + self._live_preview_request_id = self._controller.request_series_push( connection_label=selected_detector_label, request_series=request_series) @@ -688,7 +687,7 @@ def begin_set_capture_parameters(self): selected_detector_label: str = self._detector_selector.selector.GetStringSelection() resolution_str: str = self._capture_param_resolution.selector.GetStringSelection() image_resolution = ImageResolution.from_str(in_str=resolution_str) - request_series: MCastRequestSeries = MCastRequestSeries( + request_series: MCTRequestSeries = MCTRequestSeries( series=[ SetCapturePropertiesRequest( resolution_x_px=image_resolution.x_px, @@ -701,7 +700,7 @@ def begin_set_capture_parameters(self): sharpness=self._capture_param_sharpness.spinbox.GetValue(), gamma=self._capture_param_gamma.spinbox.GetValue()), GetCapturePropertiesRequest()]) # sync - self._control_blocking_request_id = self._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=selected_detector_label, request_series=request_series) self._update_ui_controls() @@ -741,21 +740,21 @@ def begin_set_detection_parameters(self): use_aruco_3_detection=self._detection_param_use_aruco_3_detection.checkbox.GetValue(), min_marker_length_ratio_original_img=self._detection_param_min_marker_length_ratio_orig.spinbox.GetValue(), min_side_length_canonical_img=self._detection_param_min_side_length_canonical_img.spinbox.GetValue()) - request_series: MCastRequestSeries = MCastRequestSeries(series=[ + request_series: MCTRequestSeries = MCTRequestSeries(series=[ SetDetectionParametersRequest(parameters=params), GetDetectionParametersRequest()]) # sync - self._control_blocking_request_id = self._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=selected_detector_label, request_series=request_series) self._update_ui_controls() def handle_response_series( self, - response_series: MCastResponseSeries, + response_series: MCTResponseSeries, task_description: Optional[str] = None, expected_response_count: Optional[int] = None ) -> None: - response: MCastResponse + response: MCTResponse for response in response_series.series: if isinstance(response, AddCalibrationImageResponse): self._handle_add_calibration_image_response(response=response) @@ -931,7 +930,7 @@ def on_display_mode_changed(self, _event: wx.CommandEvent): def on_page_select(self): super().on_page_select() - available_detector_labels: list[str] = self._connector.get_active_detector_labels() + available_detector_labels: list[str] = self._controller.get_active_detector_labels() self._detector_selector.set_options(option_list=available_detector_labels) self._update_ui_controls() @@ -999,15 +998,15 @@ def _set_parameter_controls_enabled( def update_loop(self): super().update_loop() - response_series: MCastResponseSeries | None + response_series: MCTResponseSeries | None if self._control_blocking_request_id is not None: - self._control_blocking_request_id, response_series = self._connector.response_series_pop( + self._control_blocking_request_id, response_series = self._controller.response_series_pop( request_series_id=self._control_blocking_request_id) if response_series is not None: # self._control_blocking_request_id will be None self.handle_response_series(response_series) self._update_ui_controls() elif self._live_preview_request_id is not None: - self._live_preview_request_id, response_series = self._connector.response_series_pop( + self._live_preview_request_id, response_series = self._controller.response_series_pop( request_series_id=self._live_preview_request_id) if response_series is not None: self.handle_response_series(response_series) @@ -1016,7 +1015,7 @@ def update_loop(self): if detector_label is not None and len(detector_label) > 0: if self._preview_image_checkbox.checkbox.GetValue() and self._live_preview_request_id is None: self.begin_capture_snapshot() - detector_frame: DetectorFrame | None = self._connector.get_live_detector_frame( + detector_frame: DetectorFrame | None = self._controller.get_live_detector_frame( detector_label=detector_label) if detector_frame is not None: self._live_markers_detected = detector_frame.detected_marker_snapshots diff --git a/src/gui/panels/pose_solver_panel.py b/src/gui/panels/pose_solver_panel.py index 05c9981..3cb1e12 100644 --- a/src/gui/panels/pose_solver_panel.py +++ b/src/gui/panels/pose_solver_panel.py @@ -11,17 +11,17 @@ from src.common import \ ErrorResponse, \ EmptyResponse, \ - MCastRequestSeries, \ - MCastResponse, \ - MCastResponseSeries, \ + MCTRequestSeries, \ + MCTResponse, \ + MCTResponseSeries, \ StatusMessageSource from src.common.structures import \ DetectorFrame, \ Matrix4x4, \ Pose, \ PoseSolverFrame -from src.connector import \ - Connector +from src.controller import \ + MCTController from src.pose_solver.api import \ AddTargetMarkerRequest, \ AddTargetMarkerResponse, \ @@ -42,7 +42,7 @@ class PoseSolverPanel(BasePanel): - _connector: Connector + _controller: MCTController _pose_solver_selector: ParameterSelector _reference_marker_id_spinbox: ParameterSpinboxInteger @@ -63,16 +63,15 @@ class PoseSolverPanel(BasePanel): def __init__( self, parent: wx.Window, - connector: Connector, + controller: MCTController, status_message_source: StatusMessageSource, name: str = "PoseSolverPanel" ): super().__init__( parent=parent, - connector=connector, status_message_source=status_message_source, name=name) - self._connector = connector + self._controller = controller self._control_blocking_request_id = None self._is_updating = False @@ -219,11 +218,9 @@ def handle_error_response( def handle_response_series( self, - response_series: MCastResponseSeries, - task_description: Optional[str] = None, - expected_response_count: Optional[int] = None + response_series: MCTResponseSeries ) -> None: - response: MCastResponse + response: MCTResponse for response in response_series.series: if isinstance(response, AddTargetMarkerResponse): pass # we don't currently do anything with this response in this interface @@ -235,7 +232,7 @@ def handle_response_series( def on_page_select(self) -> None: super().on_page_select() selected_pose_solver_label: str = self._pose_solver_selector.selector.GetStringSelection() - available_pose_solver_labels: list[str] = self._connector.get_active_pose_solver_labels() + available_pose_solver_labels: list[str] = self._controller.get_active_pose_solver_labels() self._pose_solver_selector.set_options(option_list=available_pose_solver_labels) if selected_pose_solver_label in available_pose_solver_labels: self._pose_solver_selector.selector.SetStringSelection(selected_pose_solver_label) @@ -247,23 +244,23 @@ def on_pose_solver_select(self, _event: wx.CommandEvent) -> None: self._update_ui_controls() def on_reference_target_submit_pressed(self, _event: wx.CommandEvent) -> None: - request_series: MCastRequestSeries = MCastRequestSeries(series=[ + request_series: MCTRequestSeries = MCTRequestSeries(series=[ (SetReferenceMarkerRequest( marker_id=self._reference_marker_id_spinbox.spinbox.GetValue(), marker_diameter=self._reference_marker_diameter_spinbox.spinbox.GetValue()))]) selected_pose_solver_label: str = self._pose_solver_selector.selector.GetStringSelection() - self._control_blocking_request_id = self._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=selected_pose_solver_label, request_series=request_series) self._update_ui_controls() def on_tracked_target_submit_pressed(self, _event: wx.CommandEvent) -> None: - request_series: MCastRequestSeries = MCastRequestSeries(series=[ + request_series: MCTRequestSeries = MCTRequestSeries(series=[ (AddTargetMarkerRequest( marker_id=self._tracked_marker_id_spinbox.spinbox.GetValue(), marker_diameter=self._tracked_marker_diameter_spinbox.spinbox.GetValue()))]) selected_pose_solver_label: str = self._pose_solver_selector.selector.GetStringSelection() - self._control_blocking_request_id = self._connector.request_series_push( + self._control_blocking_request_id = self._controller.request_series_push( connection_label=selected_pose_solver_label, request_series=request_series) self._update_ui_controls() @@ -291,10 +288,10 @@ def update_loop(self) -> None: self._is_updating = True - if self._connector.is_running(): - detector_labels: list[str] = self._connector.get_active_detector_labels() + if self._controller.is_running(): + detector_labels: list[str] = self._controller.get_active_detector_labels() for detector_label in detector_labels: - retrieved_detector_frame: DetectorFrame = self._connector.get_live_detector_frame( + retrieved_detector_frame: DetectorFrame = self._controller.get_live_detector_frame( detector_label=detector_label) retrieved_detector_frame_timestamp: datetime.datetime = retrieved_detector_frame.timestamp_utc() if detector_label in self._latest_detector_frames: @@ -306,9 +303,9 @@ def update_loop(self) -> None: self._latest_detector_frames[detector_label] = retrieved_detector_frame new_poses_available: bool = False - pose_solver_labels: list[str] = self._connector.get_active_pose_solver_labels() + pose_solver_labels: list[str] = self._controller.get_active_pose_solver_labels() for pose_solver_label in pose_solver_labels: - retrieved_pose_solver_frame: PoseSolverFrame = self._connector.get_live_pose_solver_frame( + retrieved_pose_solver_frame: PoseSolverFrame = self._controller.get_live_pose_solver_frame( pose_solver_label=pose_solver_label) retrieved_pose_solver_frame_timestamp: datetime.datetime = retrieved_pose_solver_frame.timestamp_utc() if pose_solver_label in self._latest_pose_solver_frames: @@ -364,9 +361,9 @@ def update_loop(self) -> None: else: self._tracking_table.Enable(False) - response_series: MCastResponseSeries | None + response_series: MCTResponseSeries | None if self._control_blocking_request_id is not None: - self._control_blocking_request_id, response_series = self._connector.response_series_pop( + self._control_blocking_request_id, response_series = self._controller.response_series_pop( request_series_id=self._control_blocking_request_id) if response_series is not None: # self._control_blocking_request_id will be None self.handle_response_series(response_series) @@ -382,7 +379,7 @@ def _update_ui_controls(self) -> None: self._tracked_target_submit_button.Enable(False) self._tracking_table.Enable(False) self._tracking_display_textbox.Enable(False) - if self._connector.is_transitioning() or (self._control_blocking_request_id is not None): + if self._controller.is_transitioning() or (self._control_blocking_request_id is not None): return # We're waiting for something self._pose_solver_selector.Enable(True) selected_pose_solver: str = self._pose_solver_selector.selector.GetStringSelection() diff --git a/src/gui/panels/specialized/connection_table.py b/src/gui/panels/specialized/connection_table.py index 8043037..ff13e86 100644 --- a/src/gui/panels/specialized/connection_table.py +++ b/src/gui/panels/specialized/connection_table.py @@ -1,5 +1,5 @@ from .row_selection_table import RowSelectionTable -from src.connector import \ +from src.controller import \ ConnectionReport from typing import Final import wx diff --git a/src/pose_solver/api/add_marker_corners_request.py b/src/pose_solver/api/add_marker_corners_request.py index 52dec84..539b810 100644 --- a/src/pose_solver/api/add_marker_corners_request.py +++ b/src/pose_solver/api/add_marker_corners_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import MarkerSnapshot from pydantic import Field -class AddMarkerCornersRequest(MCastRequest): +class AddMarkerCornersRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "add_marker_corners" diff --git a/src/pose_solver/api/add_target_marker_request.py b/src/pose_solver/api/add_target_marker_request.py index d2888fb..9d99739 100644 --- a/src/pose_solver/api/add_target_marker_request.py +++ b/src/pose_solver/api/add_target_marker_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class AddTargetMarkerRequest(MCastRequest): +class AddTargetMarkerRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "add_target_marker" diff --git a/src/pose_solver/api/add_target_marker_response.py b/src/pose_solver/api/add_target_marker_response.py index 18d5eae..24b6c9a 100644 --- a/src/pose_solver/api/add_target_marker_response.py +++ b/src/pose_solver/api/add_target_marker_response.py @@ -1,8 +1,8 @@ -from src.common import MCastResponse +from src.common import MCTResponse from pydantic import Field -class AddTargetMarkerResponse(MCastResponse): +class AddTargetMarkerResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "add_marker_corners" diff --git a/src/pose_solver/api/get_poses_request.py b/src/pose_solver/api/get_poses_request.py index 519afff..994aa97 100644 --- a/src/pose_solver/api/get_poses_request.py +++ b/src/pose_solver/api/get_poses_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class GetPosesRequest(MCastRequest): +class GetPosesRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "get_poses" diff --git a/src/pose_solver/api/get_poses_response.py b/src/pose_solver/api/get_poses_response.py index 8be2090..cff8fba 100644 --- a/src/pose_solver/api/get_poses_response.py +++ b/src/pose_solver/api/get_poses_response.py @@ -1,9 +1,9 @@ -from src.common import MCastResponse +from src.common import MCTResponse from src.common.structures import Pose from pydantic import Field -class GetPosesResponse(MCastResponse): +class GetPosesResponse(MCTResponse): @staticmethod def parsable_type_identifier() -> str: return "get_poses" diff --git a/src/pose_solver/api/set_intrinsic_parameters_request.py b/src/pose_solver/api/set_intrinsic_parameters_request.py index d711551..45c6ebf 100644 --- a/src/pose_solver/api/set_intrinsic_parameters_request.py +++ b/src/pose_solver/api/set_intrinsic_parameters_request.py @@ -1,9 +1,9 @@ -from src.common import MCastRequest +from src.common import MCTRequest from src.common.structures import IntrinsicParameters from pydantic import Field -class SetIntrinsicParametersRequest(MCastRequest): +class SetIntrinsicParametersRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "set_intrinsic_parameters" diff --git a/src/pose_solver/api/set_reference_marker_request.py b/src/pose_solver/api/set_reference_marker_request.py index a41b419..9723be1 100644 --- a/src/pose_solver/api/set_reference_marker_request.py +++ b/src/pose_solver/api/set_reference_marker_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class SetReferenceMarkerRequest(MCastRequest): +class SetReferenceMarkerRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "set_reference_marker" diff --git a/src/pose_solver/api/start_pose_solver_request.py b/src/pose_solver/api/start_pose_solver_request.py index bfe0bd2..63b8414 100644 --- a/src/pose_solver/api/start_pose_solver_request.py +++ b/src/pose_solver/api/start_pose_solver_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class StartPoseSolverRequest(MCastRequest): +class StartPoseSolverRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "start_pose_solver" diff --git a/src/pose_solver/api/stop_pose_solver_request.py b/src/pose_solver/api/stop_pose_solver_request.py index 9e54932..293e590 100644 --- a/src/pose_solver/api/stop_pose_solver_request.py +++ b/src/pose_solver/api/stop_pose_solver_request.py @@ -1,8 +1,8 @@ -from src.common import MCastRequest +from src.common import MCTRequest from pydantic import Field -class StopPoseSolverRequest(MCastRequest): +class StopPoseSolverRequest(MCTRequest): @staticmethod def parsable_type_identifier() -> str: return "stop_pose_solver" diff --git a/src/pose_solver/pose_solver_api.py b/src/pose_solver/pose_solver_api.py index ba1b1d0..1288c8b 100644 --- a/src/pose_solver/pose_solver_api.py +++ b/src/pose_solver/pose_solver_api.py @@ -18,9 +18,9 @@ EmptyResponse, \ ErrorResponse, \ get_kwarg, \ - MCastComponent, \ - MCastRequest, \ - MCastResponse + MCTComponent, \ + MCTRequest, \ + MCTResponse from src.common.structures import \ Pose, \ PoseSolverStatus @@ -31,11 +31,11 @@ logger = logging.getLogger(__name__) -def dummy_function(_: dict) -> MCastResponse: +def dummy_function(_: dict) -> MCTResponse: return EmptyResponse() -class PoseSolverAPI(MCastComponent): +class PoseSolverAPI(MCTComponent): """ API-friendly layer overtop of a PoseSolver """ @@ -57,8 +57,8 @@ async def internal_update(self): if self._status.solve_status == PoseSolverStatus.Solve.RUNNING: self._pose_solver.update() - def supported_request_types(self) -> dict[type[MCastRequest], Callable[[dict], MCastResponse]]: - return_value: dict[type[MCastRequest], Callable[[dict], MCastResponse]] = super().supported_request_types() + def supported_request_types(self) -> dict[type[MCTRequest], Callable[[dict], MCTResponse]]: + return_value: dict[type[MCTRequest], Callable[[dict], MCTResponse]] = super().supported_request_types() return_value.update({ AddMarkerCornersRequest: self.add_marker_corners, AddTargetMarkerRequest: self.add_target_marker,