This sample shows how to read and write datapoint values via the device API.
Usage:
06_LightSwitcher <ip_address>
06_LightSwitcher 10.0.0.102
It assumes an application with a single boolean bit (i.e. a light switch) which it turns on and off (5 repetitions). A parameter is also used to specify the waiting period before turning the light off.
Pre-condition: It assumes that the following datapoints and parameters are configured:
Datapoints:
|---------|-----------------|-----------------------------|-------------|---------------|
| Id | DPT | Name | SizeInBit | Flags |
| | | | | C R W T U I |
|---------|-----------------|-----------------------------|-------------|---------------|
| 11 | DPT 01 - 1 bit | Push button - Switch | 1 | C R - T - - |
|---------|-----------------|-----------------------------|-------------|---------------|
Parameter:
|---------|-----------------|-----------------------------|-------------|
| Number | Size | Name | Value |
| | | | |
|---------|-----------------|-----------------------------|-------------|
| 1 | 1 Byte | Timeout in ms | 200 |
|---------|-----------------|-----------------------------|-------------|
In the KNX installation exists another device (push button)
#include "Helper.h"
#include <iostream>
#include <memory>
#include <thread>
using namespace wz::baos::ip;
namespace
{
enum Datapoints
{
};
enum Parameters
{
};
{
{
std::cout << "Datapoint value is not initialized. Using value 0" << std::endl;
return false;
}
return value;
}
{
const std::string status =
enabled ?
"on" :
"off";
std::cout << "Switching DP Switch: " << status << std::endl;
}
{
std::cout <<
"Waiting " <<
static_cast<std::uint32_t
>(
timeout) <<
" ms" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(
timeout));
}
}
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "06_LightSwitcher sample" << std::endl;
std::cout << "******************************************" << std::endl;
std::cout << std::endl;
setBaosLogLevel(wz::baos::LogLevel::warn);
{
return 0;
}
std::cout <<
" Connection requested for " <<
ipAddress << std::endl;
for (std::uint32_t index = 0; index < 5; ++index)
{
}
}
catch (
const std::exception&
e)
{
std::cerr <<
"Failed: " <<
e.what() << std::endl;
return -1;
}
return 0;
}
Specialization for a IP v4 BAOSDevice.
Specialization for a TCP IP v4 BAOSConnection.
Global BAOS protocol defines and types.
Global BAOS SDK function and options.
void setDpValue(std::uint16_t dpId, protocol::DatapointChangeValue &&dpValue)
Send a SetDatapointValue request to the BAOS device for one datapoint.
protocol::ParameterBytes getParameterBytes(std::uint16_t byteIndex, std::uint16_t numberOfBytes)
Get a list of parameter bytes.
A specialization for (connection oriented) connection to the BAOS device via a TCP connection.
Definition BaosTcpConnection.h:182
Represents a BAOS IP4 device with an underlying TCP connection (with BAOS unsecure connection-less)
Definition BaosIpv4Device.h:55
Groups BAOS binary protocol specific types , defines and classes for Indications, Responses etc.
Definition Defines.h:33
std::vector< std::uint8_t > ParameterBytes
Strong type for a list of parameter bytes.
Definition Defines.h:635
Global BAOS sdk namespace.
Definition config.h:69
std::vector< std::uint8_t > Buffer
An alias type for a byte buffer.
Definition config.h:71
BAOSLIB_EXPORT void setBaosLogLevel(wz::baos::LogLevel level)