Projekt

Obecné

Profil

Stáhnout (1.64 KB) Statistiky
| Větev: | Tag: | Revize:
1
#ifndef CURVEDATASERVER_H
2
#define CURVEDATASERVER_H
3

    
4
#include <QObject>
5
#include <QTcpServer>
6
#include <QTcpSocket>
7
#include <map>
8
#include <mutex>
9

    
10

    
11
#include "../element/trajectory.hpp" //obsahuje MAX_CURVE_SIZE kterou se ridi sendNewCurve 4D
12

    
13
class CurveDataServer : QObject
14
{
15
    Q_OBJECT
16

    
17
public:
18
    struct Client {
19
        static const size_t BUF_SIZE = 32;
20
        static const size_t MESSAGE_ID_SIZE = 2;
21

    
22
        QTcpSocket* socket;
23
        std::map<long, long> ping;  ///< key: ping ID;  value: ping timestamp (msec);
24
        long latency;               ///< client's latency
25
        long lastPong;              ///< timestamp of last pong
26

    
27
        char buf[BUF_SIZE];
28
        size_t bufUsed;
29

    
30
        Client(QTcpSocket* socket);
31
    };
32

    
33
    explicit CurveDataServer();
34
    ~CurveDataServer();
35

    
36
    void sendActuatorPosition(float x, float y, float z);
37
    void sendActualDirection(float x, float y, float z);
38
    void sendTargetDirection(float x, float y, float z);
39
    void sendNewCurve(QList<QVector4D> points);
40
    void sendNewCurve(QList<QVector3D> points);
41

    
42
public slots:
43
    void onNewConnection();
44
    void onSocketStateChanged(QAbstractSocket::SocketState socketState);
45
    void onReadyRead();
46

    
47
private:
48
    QList<Client>::iterator clientOf(QTcpSocket *socket);
49

    
50
    void handleMessage(Client& client, uint16_t messageId, void* content);
51

    
52
    void sendPreamble(QTcpSocket *socket);
53
    void sendProtocolMagic(QTcpSocket *socket);
54
    void sendVersion(QTcpSocket *socket);
55
    void sendEot(QTcpSocket *socket, std::string&& message);
56

    
57
    QTcpServer _server;
58

    
59
    std::recursive_mutex _socketsLock;
60
    QList<Client> _sockets;
61
};
62

    
63
#endif // CURVEDATASERVER_H
(3-3/19)