# -*- coding: utf-8 -*- """ This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences) """ from __future__ import unicode_literals from robot_interface.utils.get_config import get_config class AgentSettings(object): """ Agent port configuration. :ivar control_backend_host: Hostname of the control backend, defaults to "localhost". :vartype control_backend_host: string :ivar actuation_receiver_port: Port for receiving actuation commands, defaults to 5557. :vartype actuation_receiver_port: int :ivar main_receiver_port: Port for receiving main messages, defaults to 5555. :vartype main_receiver_port: int :ivar video_sender_port: Port used for sending video frames, defaults to 5556. :vartype video_sender_port: int :ivar audio_sender_port: Port used for sending audio data, defaults to 5558. :vartype audio_sender_port: int """ def __init__( self, control_backend_host=None, actuation_receiver_port=None, main_receiver_port=None, video_sender_port=None, audio_sender_port=None, ): self.control_backend_host = get_config(control_backend_host, "AGENT__CONTROL_BACKEND_HOST", "localhost") self.actuation_receiver_port = get_config(actuation_receiver_port, "AGENT__ACTUATION_RECEIVER_PORT", 5557, int) self.main_receiver_port = get_config(main_receiver_port, "AGENT__MAIN_RECEIVER_PORT", 5555, int) self.video_sender_port = get_config(video_sender_port, "AGENT__VIDEO_SENDER_PORT", 5556, int) self.audio_sender_port = get_config(audio_sender_port, "AGENT__AUDIO_SENDER_PORT", 5558, int) class VideoConfig(object): """ Video configuration constants. :ivar camera_index: Index of the camera used, defaults to 0. :vartype camera_index: int :ivar resolution: Video resolution mode, defaults to 2. :vartype resolution: int :ivar color_space: Color space identifier, defaults to 11. :vartype color_space: int :ivar fps: Frames per second of the video stream, defaults to 15. :vartype fps: int :ivar stream_name: Name of the video stream, defaults to "Pepper Video". :vartype stream_name: str :ivar image_buffer: Internal buffer size for video frames, defaults to 6. :vartype image_buffer: int """ def __init__( self, camera_index=None, resolution=None, color_space=None, fps=None, stream_name=None, image_buffer=None, ): self.camera_index = get_config(camera_index, "VIDEO__CAMERA_INDEX", 0, int) self.resolution = get_config(resolution, "VIDEO__RESOLUTION", 2, int) self.color_space = get_config(color_space, "VIDEO__COLOR_SPACE", 11, int) self.fps = get_config(fps, "VIDEO__FPS", 15, int) self.stream_name = get_config(stream_name, "VIDEO__STREAM_NAME", "Pepper Video") self.image_buffer = get_config(image_buffer, "VIDEO__IMAGE_BUFFER", 6, int) class AudioConfig(object): """ Audio configuration constants. :ivar sample_rate: Audio sampling rate in Hz, defaults to 16000. :vartype sample_rate: int :ivar chunk_size: Size of audio chunks to capture/process, defaults to 512. :vartype chunk_size: int :ivar channels: Number of audio channels, defaults to 1. :vartype channels: int """ def __init__(self, sample_rate=None, chunk_size=None, channels=None): self.sample_rate = get_config(sample_rate, "AUDIO__SAMPLE_RATE", 16000, int) self.chunk_size = get_config(chunk_size, "AUDIO__CHUNK_SIZE", 512, int) self.channels = get_config(channels, "AUDIO__CHANNELS", 1, int) class MainConfig(object): """ Main system configuration. :ivar poll_timeout_ms: Timeout for polling events, in milliseconds, defaults to 100. :vartype poll_timeout_ms: int :ivar max_handler_time_ms: Maximum allowed handler time, in milliseconds, defaults to 50. :vartype max_handler_time_ms: int """ def __init__(self, poll_timeout_ms=None, max_handler_time_ms=None): self.poll_timeout_ms = get_config(poll_timeout_ms, "MAIN__POLL_TIMEOUT_MS", 100, int) self.max_handler_time_ms = get_config(max_handler_time_ms, "MAIN__MAX_HANDLER_TIME_MS", 50, int) class Settings(object): """ Global settings container. :ivar agent_settings: Agent-related port configuration. :vartype agent_settings: AgentSettings :ivar video_config: Video stream configuration. :vartype video_config: VideoConfig :ivar audio_config: Audio stream configuration. :vartype audio_config: AudioConfig :ivar main_config: Main system-level configuration. :vartype main_config: MainConfig """ def __init__(self, agent_settings=None, video_config=None, audio_config=None, main_config=None): self.agent_settings = agent_settings or AgentSettings() self.video_config = video_config or VideoConfig() self.audio_config = audio_config or AudioConfig() self.main_config = main_config or MainConfig() settings = Settings()