summaryrefslogtreecommitdiffstats
path: root/examples/knx/doc/discoverer.qdoc
blob: 9fc1c403d9e20c1297de8ebffedc6fbc4d8e365f (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example discoverer
    \title Discoverer Example
    \ingroup qtknx-examples
    \brief A CLI client for discovering KNX/netIP servers on the network.

    \e {Discoverer} shows how to implement and start a discovery agent that
    discovers KNX/netIP servers on the network.

    \section1 Usage
    Below are the parameters that the client allows.
    \code
Usage: ./discoverer [options]

Options:
  -h, --help                         Displays this help.
  -t, --timeout <timeout>            Discovery response timeout in seconds.
  -n, --nat                          Use Network Address Translation to
                                     traverse across network routers.
  -u, --unicast                      Force unicast response. (defaults to
                                     multicast response)
  -a, --localAddress <localAddress>  The local IP address a response shall be
                                     sent to. Implies <unicast>
  -p, --localPort <localPort>        The local UDP port a response shall be
                                     sent to (defaults to system assigned).
                                     Implies <unicast>.
  -m, --searchMode <searchMode>      Specifies the mode used to send search
                                     request. Possible values: (default,
                                     extended, both).
  --filterProg                       Limit search responses to devices in
                                     programming mode. Implies search mode
                                     extended or both.
  --filterMAC <MAC>                  Limit search responses to the given MAC
                                     address. Implies search mode extended or
                                     both.
  --filterService <Service>          Limit search responses to devices
                                     supporting the given KNXnet/IP service
                                     family in at least the given version (e.g.
                                     0202). Implies search mode extended or
                                     both.
  --descriptionType <Type>           Force returning DIBs inside the search
                                     responses to to at least of the given set
                                     of IDs (e.g. 010208). Implies search mode
                                     extended or both.
    \endcode

    By default the client uses the default network interface determined by the
    Operating System if no local IP address given. However, if an IP
    is given, the client will use the interface attached to that IP.

    The following lines show a few  examples of how to use the client:

    \code
./discoverer -m extended -a 127.0.0.1 -p 5543

Device used to send the search request:
  Network interface: lo, address: 127.0.0.1, port: 5543
No server(s) found on the network.
    \endcode

    The command above uses the loopback interface. No KNX servers are
    available on this interface and therefore none are showed.

    \code
./discoverer -m extended
Device used to send the search request:
  Network interface: Unknown, address: 0.0.0.0, port: 0

1 server(s) found on the network.
  Server: IPR/S3.5.1 IP Router,MDRC
      Individual address: 1.1.0
      Server control endpoint: 10.9.78.33:3671
    Supported services:
      KNXnet/IP Core, Version: 2
      KNXnet/IP Device Management, Version: 2
      KNXnet/IP Tunnel, Version: 2
      KNXnet/IP Routing, Version: 2
      KNXnet/IP Remote Configuration, Version: 1
      KNXnet/IP Security, Version: 1
    Extended hardware information:
      Mask version: 091a
      Max. local APDU length: 254
      Medium status: Communication possible
    \endcode

    Unlike the previous command example, this one uses the default
    network interface determined by the OS and shows that there is one
    KNX server on the network with 10.9.78.33 and listening on port
    3671. The \c searchMode parameter refers to the KNXnet/IP Core
    version used. The \c extended mode indicates version 2 and can
    make use of extended search parameters.

    \code
    ./discoverer -m extended --filterService 0202

Device used to send the search request:
  Network interface: Unknown, address: 0.0.0.0, port: 0

1 server(s) found on the network.
  Server: IPR/S3.5.1 IP Router,MDRC
      Individual address: 1.1.0
      Server control endpoint: 10.9.78.33:3671
    Supported services:
      KNXnet/IP Core, Version: 2
      KNXnet/IP Device Management, Version: 2
      KNXnet/IP Tunnel, Version: 2
      KNXnet/IP Routing, Version: 2
      KNXnet/IP Remote Configuration, Version: 1
      KNXnet/IP Security, Version: 1
    Extended hardware information:
      Mask version: 091a
      Max. local APDU length: 254
      Medium status: Communication possible
    \endcode

    The above command makes use of the extended search parameters
    available only in KNXnet/IP Core version 2. It limits the
    search responses to devices supporting the given KNXnet/IP service
    family 02 and in at least the given version 02.

    In a network with two KNX routers, one of them only supporting
    KNXnet/IP Core Version 1, the output showed by the client with the
    default \c searchMode parameter set would be as follows:
    \code
./discoverer -m default

Device used to send the search request:
  Network interface: Unknown, address: 0.0.0.0, port: 0

2 server(s) found on the network.
  Server: IPR/S3.5.1 IP Router,MDRC
      Individual address: 1.1.0
      Server control endpoint: 10.9.78.33:3671
    Supported services:
      KNXnet/IP Core, Version: 2
      KNXnet/IP Device Management, Version: 2
      KNXnet/IP Tunnel, Version: 2
      KNXnet/IP Routing, Version: 2
      KNXnet/IP Remote Configuration, Version: 1

  Server: IPS/S3.1.1 IP-Schnittstelle,RE
      Individual address: 1.1.250
      Server control endpoint: 10.9.78.81:3671
    Supported services:
      KNXnet/IP Core, Version: 1
      KNXnet/IP Device Management, Version: 1
      KNXnet/IP Tunnel, Version: 1
      KNXnet/IP Remote Configuration, Version: 1
    \endcode

    \section1 Implementation

    The client delegates all the implementation of the KNX discovery
    to a \l QKnxNetIpServerDiscoveryAgent instance.

    \quotefromfile discoverer/main.cpp
    \skipto int main(
    \printuntil {
    \dots
    \skipto QKnxNetIpServerDiscoveryAgent agent;
    \printuntil ;

    The discovery agent is started here:
    \quotefromfile discoverer/main.cpp
    \skipto int main(
    \printuntil {
    \dots
    \skipto QKnxNetIpServerDiscoveryAgent agent;
    \printuntil ;
    \dots
    \skipto QKnxNetIpServerDiscoveryAgent::finished
    \printuntil ;
    \printuntil exec();
    \skipto /^\}/
    \dots
    \printuntil /^\}/

    When the agent finishes discovering the servers, the main function
    of the client is resumed. The above code snippet shows how the \l
    QKnxNetIpServerDiscoveryAgent::finished() signal triggers a call to
    \l QCoreApplication::quit(). The client execution then keeps going after
    the \l QCoreApplication::exec().

    Finally, we recover a list of servers and output the information found:
    \quotefromfile discoverer/main.cpp
    \skipto int main(
    \printuntil {
    \dots
    \skipto agent.error
    \printuntil /^\}/

*/