pycram.worlds.multiverse_communication.socket
=============================================

.. py:module:: pycram.worlds.multiverse_communication.socket

.. autoapi-nested-parse::

   Multiverse Client base class.



Attributes
----------

.. autoapisummary::

   pycram.worlds.multiverse_communication.socket.T


Classes
-------

.. autoapisummary::

   pycram.worlds.multiverse_communication.socket.MultiverseSocket


Module Contents
---------------

.. py:data:: T

.. py:class:: MultiverseSocket(port: str, host: str = Conf.HOST, meta_data: pycram.datastructures.dataclasses.MultiverseMetaData = MultiverseMetaData())

   .. py:attribute:: _send_data
      :value: None



   .. py:attribute:: port


   .. py:attribute:: host


   .. py:attribute:: _meta_data


   .. py:attribute:: client_name


   .. py:attribute:: _multiverse_socket


   .. py:property:: request_meta_data
      :type: typing_extensions.Dict


      The request_meta_data which is sent to the server.
              



   .. py:attribute:: _api_callbacks
      :type:  typing_extensions.Optional[typing_extensions.Dict]
      :value: None



   .. py:attribute:: _start_time
      :value: 0.0



   .. py:method:: run() -> None

      Run the client.



   .. py:method:: _run() -> None

      Run the client, should call the _connect_and_start() method. It's left to the user to implement this method
      in threaded or non-threaded fashion.



   .. py:method:: stop() -> None

      Stop the client.



   .. py:property:: response_meta_data
      :type: typing_extensions.Dict


      Get the response_meta_data.

      :return: The response_meta_data as a dictionary.



   .. py:method:: send_and_receive_meta_data()

      Send and receive the metadata, this should be called before sending and receiving data.



   .. py:method:: send_and_receive_data()

      Send and receive the data, this should be called after sending and receiving the metadata.



   .. py:property:: send_data
      :type: typing_extensions.List[float]


      Get the send_data.



   .. py:property:: receive_data
      :type: typing_extensions.List[float]


      Get the receive_data, the first element should be the current simulation time,
      the rest should be the received data with the following order:
      double -> uint8_t -> uint16_t

      :return: The received data.



   .. py:property:: api_callbacks
      :type: typing_extensions.Dict[str, typing_extensions.Callable[[typing_extensions.List[str]], typing_extensions.List[str]]]


      Get the api_callbacks.

      :return: The api_callbacks as a dictionary of function names and their respective callbacks.



   .. py:method:: _bind_request_meta_data(request_meta_data: T) -> T

      Bind the request_meta_data before sending it to the server.

      :param request_meta_data: The request_meta_data to bind.
      :return: The bound request_meta_data.



   .. py:method:: _bind_response_meta_data(response_meta_data: T) -> T

      Bind the response_meta_data after receiving it from the server.

      :param response_meta_data: The response_meta_data to bind.
      :return: The bound response_meta_data.



   .. py:method:: _bind_send_data(send_data: T) -> T

      Bind the send_data before sending it to the server.

      :param send_data: The send_data to bind.
      :return: The bound send_data.



   .. py:method:: _bind_receive_data(receive_data: T) -> T

      Bind the receive_data after receiving it from the server.

      :param receive_data: The receive_data to bind.
      :return: The bound receive_data.



   .. py:method:: _connect_and_start() -> None

      Connect to the server and start the client.
              



   .. py:method:: _disconnect() -> None

      Disconnect from the server.
              



   .. py:method:: _communicate(resend_request_meta_data: bool = False) -> bool

      Communicate with the server.

      :param resend_request_meta_data: Resend the request metadata.
      :return: True if the communication was successful, False otherwise.



   .. py:method:: _restart() -> None

      Restart the client.
              



   .. py:method:: log_info(message: str) -> None

      Log information.

      :param message: The message to log.



   .. py:method:: log_warn(message: str) -> None

      Warn the user.

      :param message: The message to warn about.



   .. py:method:: _message_template(message: str) -> str


   .. py:property:: world_time
      :type: float


      Get the world time from the server.

      :return: The world time.



   .. py:property:: sim_time
      :type: float


      Get the current simulation time.

      :return: The current simulation time.



