libknx
Public Member Functions | List of all members
knx::connection Class Reference

This class handles the ip connection(s) to the knx gateway. More...

#include <connection.hpp>

Public Member Functions

 connection (const knx::config &config)
 creates the connection with given config
 
 ~connection ()
 simple destructor
 
void start ()
 blocking start of the connection background thread More...
 
void stop ()
 non-blocking stop of the background thread More...
 
template<typename data_type >
void set (knx::group group, typename data_type::major_type::set_type data)
 central function to set any knx group value on the bus More...
 
template<typename data_type >
bool get (knx::group group, typename data_type::major_type::set_type &data)
 central function to get any knx group value from the bus More...
 
template<typename data_type >
bool listen (knx::group group, std::function< void(typename data_type::major_type::set_type &) > callback)
 central function to continously get any knx group value from the bus More...
 
bool set_heartbeat_callback (std::function< void()> callback)
 set a callback which is notified as soon as a heartbeat response is received. More...
 
bool wait_until_connected ()
 Waiting for connection to be established. More...
 

Detailed Description

This class handles the ip connection(s) to the knx gateway.

Member Function Documentation

◆ get()

template<typename data_type >
bool knx::connection::get ( knx::group  group,
typename data_type::major_type::set_type &  data 
)

central function to get any knx group value from the bus

This function is used to get any value from the knx bus.

Parameters
groupA valid group id as string (e.g. "1/2/3")
Returns
true if read was successful – false otherwise

◆ listen()

template<typename data_type >
bool knx::connection::listen ( knx::group  group,
std::function< void(typename data_type::major_type::set_type &) >  callback 
)

central function to continously get any knx group value from the bus

This function is used to listen for any value from the knx bus.

A minimal example would be:

#include "knx.hpp"
#include "debug.hpp"
void my_callback ( knx::dpt_1_001::set_type & data )
{
std::cout << "listened to " << data << std::endl;
}
int main ( int argc, char ** argv )
{
knx::config config ( argc, argv );
knx::handle handle ( connection );
knx::util::sleep ( 2 );
connection.listen<knx::dpt_1_001> ( "0/0/1", my_callback );
knx::util::sleep ( 20 );
return 0;
}
This class represents the configuration of the knx connection.
Definition: config.hpp:19
This class handles the ip connection(s) to the knx gateway.
Definition: connection.hpp:24
connection(const knx::config &config)
creates the connection with given config
data point type 1.001 simple boolean value
Definition: dpt.hpp:68
Thread management for connection handling.
Definition: handle.hpp:19
Parameters
groupA valid group id as string (e.g. "1/2/3")
callbackA function to be called whenever data has been received
Returns
true if registering was successful – false otherwise

◆ set()

template<typename data_type >
void knx::connection::set ( knx::group  group,
typename data_type::major_type::set_type  data 
)

central function to set any knx group value on the bus

This function is used to set any value on the knx bus.

◆ set_heartbeat_callback()

bool knx::connection::set_heartbeat_callback ( std::function< void()>  callback)

set a callback which is notified as soon as a heartbeat response is received.

#include "knx.hpp"
#include "debug.hpp"
void my_heartbeat_callback ( )
{
std::cout << "heartbeat received" << std::endl;
}
int main ( int argc, char ** argv )
{
knx::config config ( argc, argv );
knx::handle handle ( connection );
connection.set_heartbeat_callback ( my_heartbeat_callback );
knx::util::sleep ( 60 );
return 0;
}
Parameters
callbackA function without parameters to be called as soon as the heartbeat arrives
Returns
always returns true since any previsouly registered callback will be overwritten

◆ start()

void knx::connection::start ( )

blocking start of the connection background thread

This function is a blocking call to start the background thread. It is normally only called by the handler.

Warning
you should not call this function from your code.

◆ stop()

void knx::connection::stop ( )

non-blocking stop of the background thread

This function send the termination signals and waits for the thread to stop.

◆ wait_until_connected()

bool knx::connection::wait_until_connected ( )

Waiting for connection to be established.

This function waits until at least one connection reponse has been received. Be aware that this is NOT an guarantee that the connection is still alive when you submit the first message. This function is useful to prevent sending a message before the connection is at least once established.

Returns
true is a connection response has been received within 2 secs.

The documentation for this class was generated from the following file: