Skip to content

Commit

Permalink
further doc
Browse files Browse the repository at this point in the history
  • Loading branch information
xLPMG committed Jan 31, 2024
1 parent 4dd2a93 commit f50e338
Showing 1 changed file with 15 additions and 76 deletions.
91 changes: 15 additions & 76 deletions docs/source/files/assignments/project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
In the project phase we decided to implement a userfriendly Gui. The aim is to make the usage of our Tsunami solver
as easy and interactive as possible.

GUI
===========
GUI (Client-side)
==================

.. image:: ../../_static/assets/task-10-Gui_help.png

Expand All @@ -28,85 +28,24 @@ After selecting the simulation has to be recompiled with the according button be
The last tab contains further actions to interact with the simulation. First, the simulation can be started or killed here.
Also files for the bathymetry and displacement can be chosen. As an addition, the user can get data like the heigth from the simulation.

Server-side
=============

Libraries
==============

Communicator
=============================
**************

For communication between simulation and the gui Luca-Philipp introduced a communication library.
The **Communicator.cpp** library can be used to easily create a client-server TCP connection and handle its communication and logging.
For communication between simulation and the GUI we implemented a communication library.
The **Communicator.hpp** library can be used to easily create a client-server TCP connection and handle its communication and logging.

**communicator_api**
Communicator API
******************

Since all communication happens using text over TCP, we had to implement a structure that both server and client can adhere to
in order to guarantee correct communication. For this, we decided to send all data in JSON format. Furthermore, each message
follows a strict pattern. It consists of 3 parts: the TYPE which provides information on the nature of the message,
the KEY which is a unique identifier for each message, and ARGS containing other message data (such as parameters) in JSON format.

.. code:: cpp
enum MessagePart
{
TYPE,
KEY,
ARGS
};
enum MessageType
{
SERVER_CALL,
FUNCTION_CALL,
OTHER,
SERVER_RESPONSE
};
struct Message
{
MessageType type = MessageType::OTHER;
std::string key = "NONE";
json args = "";
};
It also implements various functions to convert from and to json format, such as ``messageToJson()``, ``messageToJsonString()``
and ``jsonToMessage()``.

**Communicator.hpp**

The library provides functions to start server and client and to send messages to each other.
Transmitted data is logged and can be retrieved via ``getLog()``.
Describing the detailed code here would be too extensive and not necessary, as this library
is rather just a tool for us to develop the actually interesting code.

**Communication example**

``communicator_api.h``

.. code:: cpp
inline const Message START_SIMULATION = {MessageType::SERVER_CALL, "start_simulation"};
Client-side usage:

.. code:: cpp
xlpmg::Communicator m_communicator;
m_communicator.startClient(IPADDRESS, PORT)
[...]
xlpmg::Message startSimMsg = xlpmg::START_SIMULATION;
m_communicator.sendToServer(messageToJsonString(startSimMsg));
Server-side usage:

.. code:: cpp
xlpmg::Communicator m_communicator;
m_communicator.startServer(m_PORT);
// listen for key
(**File: communicator_api.h**)

Since all communication happens using text over TCP, we had to implement a structure that both server and client can adhere to
in order to guarantee correct communication. For this, we decided to send all data in JSON format and a ``Message`` struct.

Server
============
TODO
.. note:: For further information, see :ref:`ns-lib`

0 comments on commit f50e338

Please sign in to comment.