The QKnxNetIpServerDiscoveryAgent class discovers KNXnet/IP servers by sending a search request in the network that the client is connected to. 更多...
头: | #include <QKnxNetIpServerDiscoveryAgent> |
qmake: | QT += knx |
继承: | QObject |
enum | DiscoveryMode { CoreV1, CoreV2 } |
flags | DiscoveryModes |
enum class | Error { None, Network, NotIPv4, Timeout, Unknown } |
flags | InterfaceTypes |
enum class | ResponseType { Unicast, Multicast } |
enum class | State { NotRunning, Starting, Running, Stopping } |
QKnxNetIpServerDiscoveryAgent (const QHostAddress & localAddress , quint16 port , QObject * parent = nullptr) | |
QKnxNetIpServerDiscoveryAgent (const QHostAddress & localAddress , QObject * parent = nullptr) | |
QKnxNetIpServerDiscoveryAgent (QObject * parent = nullptr) | |
virtual | ~QKnxNetIpServerDiscoveryAgent () override |
QVector<QKnxNetIpServerInfo> | discoveredServers () const |
QKnxNetIpServerDiscoveryAgent::DiscoveryModes | discoveryMode () const |
QKnxNetIpServerDiscoveryAgent::Error | error () const |
QString | errorString () const |
QVector<QKnxNetIpSrp> | extendedSearchParameters () const |
QHostAddress | localAddress () const |
quint16 | localPort () const |
quint8 | multicastTtl () const |
bool | natAware () const |
QKnxNetIpServerDiscoveryAgent::ResponseType | responseType () const |
int | searchFrequency () const |
void | setDiscoveryMode (QKnxNetIpServerDiscoveryAgent::DiscoveryModes mode ) |
void | setExtendedSearchParameters (const QVector<QKnxNetIpSrp> & srps ) |
void | setLocalAddress (const QHostAddress & address ) |
void | setLocalPort (quint16 port ) |
void | setMulticastTtl (quint8 ttl ) |
void | setNatAware (bool useNat ) |
void | setResponseType (QKnxNetIpServerDiscoveryAgent::ResponseType type ) |
void | setSearchFrequency (int timesPerMinute ) |
void | setTimeout (int msec ) |
QKnxNetIpServerDiscoveryAgent::State | state () const |
int | timeout () const |
void | start (QKnxNetIpServerDiscoveryAgent::InterfaceTypes 类型 ) |
void | start (const QVector<QHostAddress> & addresses ) |
void | start (int timeout ) |
void | start () |
void | stop () |
void | deviceDiscovered (QKnxNetIpServerInfo server ) |
void | errorOccurred (QKnxNetIpServerDiscoveryAgent::Error error , QString errorString ) |
void | finished () |
void | started () |
void | stateChanged (QKnxNetIpServerDiscoveryAgent::State state ) |
The agent may be set up with the Unicast response type to receive the answers from the different KNXnet/IP servers directly in a point-to-point manner. Typically, it should use the Multicast response type to ensure reception from KNXnet/IP servers that are on a different subnetwork.
Here is an example on how to use this discovery agent:
QKnxNetIpServerDiscoveryAgent agent; QHostAddress clientLocalAddress = ... agent.setLocalAddress(clientLocalAddress); agent.start();
The discovery agent further provides the option to send extended search requests as specified by the KNX application note AN184. This allows the discovery client to include zero or more search request parameter (SRP) blocks to transfer additional information regarding the search. This can be used for example to restrict the set of devices that are expected to respond or to influence the type of device information blocks (DIBs) which the client is interested in.
注意: A combination of both discovery modes is permitted.
Here is an example on how to use this discovery agent with extended search features to indicate that the KNXnet/IP client is interested only in the response from the KNXnet/IP server with the given MAC address:
QHostAddress clientLocalAddress = ... auto builder = QKnxNetIpSrpProxy::macAddressBuilder(); QKnxNetIpServerDiscoveryAgent agent(clientLocalAddress); agent.setDiscoveryMode(QKnxNetIpServerDiscoveryAgent::DiscoveryMode::CoreV2); agent.setExtendedSearchParameters({ builder.setMac(QKnxByteArray::fromHex("bcaec56690f9")).create(), builder.setMac(QKnxByteArray::fromHex("4ccc6ae40000")).create() }); agent.start();
To retrieve the list of discovered servers:
auto servers = agent.discoveredServers();
另请参阅 Qt KNXnet/IP Connection Classes .
This enum type holds the mode that the agent is set up with to send search request messages. A combination of both values is permitted.
常量 | 值 | 描述 |
---|---|---|
QKnxNetIpServerDiscoveryAgent::CoreV1
|
0x01
|
The server uses search request frames as specified in KNXnet/IP Core Version 1 to discover KNXnet/IP devices. |
QKnxNetIpServerDiscoveryAgent::CoreV2
|
0x02
|
The server uses extended search request frames as specified in KNXnet/IP Core Version 2 to discover KNXnet/IP devices. |
该枚举在 Qt 5.12 引入或被修改。
The DiscoveryModes type is a typedef for QFlags <DiscoveryMode>. It stores an OR combination of DiscoveryMode values.
This enum value holds the type of an error that occurred.
常量 | 值 | 描述 |
---|---|---|
QKnxNetIpServerDiscoveryAgent::Error::None
|
0
|
No errors occurred. |
QKnxNetIpServerDiscoveryAgent::Error::Network
|
1
|
发生网络错误。 |
QKnxNetIpServerDiscoveryAgent::Error::NotIPv4
|
2
|
The network protocol used is not IPv4. |
QKnxNetIpServerDiscoveryAgent::Error::Timeout
|
3
|
A timeout occurred while waiting for the description response. |
QKnxNetIpServerDiscoveryAgent::Error::Unknown
|
0x80
|
出现未知错误。 |
This enum type holds the response type that the agent is set up with to receive search response messages.
常量 | 值 | 描述 |
---|---|---|
QKnxNetIpServerDiscoveryAgent::ResponseType::Unicast
|
0x00
|
Receive responses in a point-to-point manner. |
QKnxNetIpServerDiscoveryAgent::ResponseType::Multicast
|
0x01
|
Collect responses from multicast messages. |
This enum value holds the state of the discovery agent.
常量 | 值 | 描述 |
---|---|---|
QKnxNetIpServerDiscoveryAgent::State::NotRunning
|
0
|
The discovery agent is not running. |
QKnxNetIpServerDiscoveryAgent::State::Starting
|
1
|
The discovery agent is starting up. |
QKnxNetIpServerDiscoveryAgent::State::Running
|
2
|
The discovery agent is running. |
QKnxNetIpServerDiscoveryAgent::State::Stopping
|
3
|
The discovery agent is stopping. |
Creates a KNXnet/IP server discovery agent with the host address localAddress , the port number port , and the parent parent .
注意: If the port number is already bound by a different process, discovery will fail.
Creates a KNXnet/IP server discovery agent with the host address localAddress and the parent parent .
Creates a KNXnet/IP server discovery agent with the parent parent .
[signal]
void
QKnxNetIpServerDiscoveryAgent::
deviceDiscovered
(
QKnxNetIpServerInfo
server
)
This signal is emitted when the server server is discovered.
[signal]
void
QKnxNetIpServerDiscoveryAgent::
errorOccurred
(
QKnxNetIpServerDiscoveryAgent::Error
error
,
QString
errorString
)
This signal is emitted when the error error with the message errorString 出现。
[signal]
void
QKnxNetIpServerDiscoveryAgent::
finished
()
This signal is emitted when the discovery agent has finished discovering servers.
[slot]
void
QKnxNetIpServerDiscoveryAgent::
start
(
QKnxNetIpServerDiscoveryAgent::InterfaceTypes
类型
)
Starts a server discovery agent with the network interfaces specified by the list of interface types 类型 .
注意: Does not emit the errorOccurred 信号。
[slot]
void
QKnxNetIpServerDiscoveryAgent::
start
(const
QVector
<
QHostAddress
> &
addresses
)
Starts a server discovery agent with the network interfaces specified by the list of local host addresses .
注意: Does not emit the errorOccurred 信号。
[slot]
void
QKnxNetIpServerDiscoveryAgent::
start
(
int
timeout
)
Starts a server discovery agent with the timeout timeout .
另请参阅 setTimeout () 和 timeout ().
[slot]
void
QKnxNetIpServerDiscoveryAgent::
start
()
Starts a server discovery agent.
[signal]
void
QKnxNetIpServerDiscoveryAgent::
started
()
This signal is emitted when the discovery agent starts discovering servers.
[signal]
void
QKnxNetIpServerDiscoveryAgent::
stateChanged
(
QKnxNetIpServerDiscoveryAgent::State
state
)
This signal is emitted when the state of the discovery agent changes to state .
[slot]
void
QKnxNetIpServerDiscoveryAgent::
stop
()
Stops a server discovery agent.
[override virtual]
QKnxNetIpServerDiscoveryAgent::
~QKnxNetIpServerDiscoveryAgent
()
Deletes a KNXnet/IP server discovery agent.
Returns a list of servers that were discovered.
Returns the search mode used to discover a KNXnet/IP server on the network and by default returns QKnxNetIpServerDiscoveryAgent::CoreV1 .
该函数在 Qt 5.12 引入。
另请参阅 setDiscoveryMode ().
Returns the type of an error that occurred when discovering servers.
Returns a human-readable string that describes an error.
Returns the search request parameter (SRP) objects used in an extended search request .
该函数在 Qt 5.12 引入。
另请参阅 setExtendedSearchParameters ().
Returns the host address of a discovery agent.
另请参阅 setLocalAddress ().
Returns the port number used by a discovery agent.
另请参阅 setLocalPort ().
Returns the time to live (TTL) used for multicast search response messages. TTL is the maximum number of IP routers that may route the message. Each IP router that the message passes decrements the TTL by one. When the TTL has reached zero, the message is discarded.
另请参阅 setMulticastTtl ().
返回
true
if the server discovery agent uses network address translation (NAT).
另请参阅 setNatAware ().
Returns the response type of search response messages.
另请参阅 setResponseType ().
Returns the frequency at which the discovery agent sends search request messages. The default value is
0
.
另请参阅 setSearchFrequency .
Sets the search mode used to discover a KNXnet/IP server on the network to mode . The function supports QKnxNetIpServerDiscoveryAgent::CoreV1 , QKnxNetIpServerDiscoveryAgent::CoreV2 , or a combination of both.
该函数在 Qt 5.12 引入。
另请参阅 discoveryMode ().
Sets the extended search request parameter (SRP) objects to srps .
The discovery agent may include zero or more SRP objects to transfer additional information regarding the search (for example to restrict the set of KNXnet/IP servers that are expected to respond).
该函数在 Qt 5.12 引入。
另请参阅 extendedSearchParameters (), QKnxNetIpSrpProxy::MacAddress , QKnxNetIpSrpProxy::ProgrammingMode , QKnxNetIpSrpProxy::SupportedFamily ,和 QKnxNetIpSrpProxy::RequestDibs .
Sets the host address of a discovery agent to address . To unset the local address use QHostAddress::Null .
注意: If the address changes during discovery, the new address will not be used until the next run.
另请参阅 localAddress ().
Sets the port number used by a discovery agent to port .
注意: If the port changes during discovery, the new port will not be used until the next run.
另请参阅 localPort ().
Sets the TTL used for multicasting to
ttl
。值
1
means that the message does not leave the local network.
另请参阅 multicastTtl ().
Sets whether the server discovery agent is using NAT to useNat .
注意: If the setting changes during discovery, it will not be used until the next run.
另请参阅 natAware ().
Sets the response type of search response messages to type .
另请参阅 responseType ().
Sets the frequency at which the discovery agent sends search request messages to
timesPerMinute
。默认值为
0
.
另请参阅 timeout , setTimeout ,和 searchFrequency .
Sets the timeout for the discovery agent to
msec
。若
msec
is
-1
, the agent will not timeout and has to be terminated by calling the
stop
() 函数。
另请参阅 timeout , searchFrequency ,和 setSearchFrequency .
Returns the state of a KNXnet/IP server discovery agent.
Returns the timeout value used by the discovery agent to wait for incoming search response messages. The default value is 3000 milliseconds.
另请参阅 setTimeout .