-
Notifications
You must be signed in to change notification settings - Fork 0
/
Connection.h
60 lines (48 loc) · 1.2 KB
/
Connection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMap>
#include <QObject>
#include <QUdpSocket>
#include "MessageBuilder.h"
#include "MessageParser.h"
namespace siyi {
class Connection : public QObject
{
Q_OBJECT
public:
explicit Connection(MessageBuilder& messageBuilder,
const QString& serverIp = "192.168.144.25",
quint16 port = 37260,
QObject* parent = nullptr);
~Connection() override;
signals:
// Emit received message and command
void messageReceived(const QVariant& message, quint8 command);
public slots:
/**
* Init connection
*/
void init();
/**
* Send message to camera
* @param message Message to send
*/
void sendMessage(const QByteArray& message);
private slots:
void readPendingDatagrams();
private:
/**
* Add parser
* @param parser
*/
void addParser(ResponseMessageParser* parser);
private:
bool _connected{false};
MessageBuilder& _messageBuilder;
QHostAddress _cameraAddress;
quint16 _port;
QUdpSocket* _socket{nullptr};
QMap<Command, ResponseMessageParser*> _parsers;
};
} // namespace siyi
#endif // CONNECTION_H