-
Notifications
You must be signed in to change notification settings - Fork 0
/
knxtunnel.h
91 lines (71 loc) · 2.82 KB
/
knxtunnel.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Contact: [email protected]
*
* This file is part of nymea.
*
* GNU Lesser General Public License Usage
* This project may be redistributed and/or modified under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; version 3. This project is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this project. If not, see <https://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef KNXTUNNEL_H
#define KNXTUNNEL_H
#include <QTimer>
#include <QObject>
#include <QQueue>
#include <QHostAddress>
#include <QKnxNetIpTunnel>
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(dcKnxTunnelTraffic)
class KnxTunnel : public QObject
{
Q_OBJECT
public:
explicit KnxTunnel(const QHostAddress &remoteAddress, QObject *parent = nullptr);
QHostAddress remoteAddress() const;
void setRemoteAddress(const QHostAddress &remoteAddress);
bool connected() const;
bool connectTunnel();
void disconnectTunnel();
void sendKnxDpdSwitchFrame(const QKnxAddress &knxAddress, bool power);
void sendKnxDpdUpDownFrame(const QKnxAddress &knxAddress, bool status);
void sendKnxDpdStepFrame(const QKnxAddress &knxAddress, bool status);
void sendKnxDpdScalingFrame(const QKnxAddress &knxAddress, int scale);
void readKnxGroupValue(const QKnxAddress &knxAddress);
void readKnxDpdSwitchState(const QKnxAddress &knxAddress);
void readKnxDpdScalingState(const QKnxAddress &knxAddress);
void readKnxDpdTemperatureSensor(const QKnxAddress &knxAddress);
static void printFrame(const QKnxLinkLayerFrame &frame);
private:
QHostAddress m_localAddress;
QHostAddress m_remoteAddress;
quint16 m_port = 3671;
QTimer *m_timer = nullptr;
QTimer *m_queueTimer = nullptr;
QKnxNetIpTunnel *m_tunnel = nullptr;
QQueue<QKnxLinkLayerFrame> m_sendingQueue;
// Helper
void requestSendFrame(const QKnxLinkLayerFrame &frame);
void sendFrame(const QKnxLinkLayerFrame &frame);
QHostAddress getLocalAddress(const QHostAddress &remoteAddress);
signals:
void connectedChanged();
void frameReceived(const QKnxLinkLayerFrame &frame);
private slots:
void onTimeout();
void onQueueTimeout();
void onTunnelConnected();
void onTunnelDisconnected();
void onTunnelStateChanged(QKnxNetIpEndpointConnection::State state);
void onTunnelFrameReceived(const QKnxLinkLayerFrame &frame);
};
#endif // KNXTUNNEL_H