This sample is a console application with a mini visualisation for the current data point values and configuration. Every time a datapoint value indication is received the view is updated and shows the new value. For it to work properly the complete view must be visible inside the console windows without scrolling. Scrolling or resizing the console window will mess up the writing of the updated datapoint values on the correct position. This sample heavilly relies on the ANSI Escape sequences to move the cursor in the console, if those are not available in your console, this sample will not work as expected.
#include "Helper.h"
#include <wzcpp/features/utils/Formatter.h>
#include <iostream>
#include <memory>
#include <thread>
using namespace wz::baos::ip;
namespace
{
{
}
enum ColumnWidths
{
};
class BaosView
{
public:
BaosView(
const std::string&
ip4Address, std::uint16_t port = 12004)
{
}
public:
{
std::cout << "|" << std::string(ColumnWidths::Id, '-') << "|" << std::string(ColumnWidths::DPT, '-') << "|"
<< std::string(ColumnWidths::DescriptionString, '-') << "|" << std::string(ColumnWidths::Flags, '-')
<< "|" << std::string(ColumnWidths::Data, '-') << "|" << std::endl;
std::cout << "|" << std::setfill(' ') << std::setw(ColumnWidths::Id) << "Id "
<< "|" << std::setfill(' ') << std::setw(ColumnWidths::DPT) << "DPT "
<< "|" << std::setfill(' ') << std::setw(ColumnWidths::DescriptionString) << "Description "
<< "|" << std::setfill(' ') << std::setw(ColumnWidths::Flags) << "Flags "
<< "|" << std::setfill(' ') << std::setw(ColumnWidths::Data) << "Data "
<< "|" << std::endl;
std::cout << "|" << std::setfill(' ') << std::setw(ColumnWidths::Id) << ""
<< "|" << std::setfill(' ') << std::setw(ColumnWidths::DPT) << ""
<< "|" << std::setfill(' ') << std::setw(ColumnWidths::DescriptionString) << ""
<< "|" << std::setfill(' ') << std::setw(ColumnWidths::Flags) << "C R W T U I "
<< "|" << std::setfill(' ') << std::setw(ColumnWidths::Data) << "(in hex) "
<< "|" << std::endl;
std::cout << "|" << std::string(ColumnWidths::Id, '-') << "|" << std::string(ColumnWidths::DPT, '-') << "|"
<< std::string(ColumnWidths::DescriptionString, '-') << "|" << std::string(ColumnWidths::Flags, '-')
<< "|" << std::string(ColumnWidths::Data, '-') << "|" << std::endl;
if(dp_configs_.empty())
{
std::cout << "No datapoints configured" << std::endl;
return;
}
{
{
}
std::cout <<
"|" << std::setfill(
' ') << std::setw(ColumnWidths::Id) <<
dpId <<
"|" << std::setfill(
' ')
<< std::setw(ColumnWidths::DPT) <<
dptToString(desc.
dpt) <<
"|" << std::setfill(
' ')
<< std::setw(ColumnWidths::DescriptionString) << desc.
desc <<
"|" << std::setfill(
' ')
<< std::setw(ColumnWidths::Flags) <<
formatFlags(desc.
flags) <<
"|" << std::setfill(
' ')
<< std::setw(ColumnWidths::Data-1) <<
formatedValue <<
" |" << std::endl;
std::cout << "|" << std::string(ColumnWidths::Id, '-') << "|" << std::string(ColumnWidths::DPT, '-') << "|"
<< std::string(ColumnWidths::DescriptionString, '-') << "|" << std::string(ColumnWidths::Flags, '-')
<< "|" << std::string(ColumnWidths::Data, '-') << "|" << std::endl;
}
std::cout << "\u001b[s";
{
std::cout <<
omitted <<
" Datapoints omitted" << std::endl;
}
}
{
device_.registerDPValueCallback(
{
try
{
{
std::uint16_t
id =
item.first;
}
}
catch (const std::exception&)
{
}
});
}
private:
{
if(dp_limit < dp_configs_.size())
{
}
else
{
}
}
{
device_.getStaticInfo();
dp_configs_ = device_.getAllDpConfigurations();
}
{
}
{
std::uint32_t
cursorRight = 1 + ColumnWidths::Id + 1 + ColumnWidths::DPT + 1 + ColumnWidths::DescriptionString + 1 +
ColumnWidths::Flags + 1 + 1;
std::cout << "\u001b[u";
std::cout << "\u001b[3B";
{
std::cout <<
"+ Skipped updating: datapoint id(" <<
dpId <<
"): " << wzcpp::rangeToHex(value) <<
" ";
std::cout << "\u001b[u";
}
else
{
std::cout <<
"+ Updating the view: datapoint id(" <<
dpId <<
"): " << wzcpp::rangeToHex(value) <<
" ";
std::cout << "\u001b[u";
std::cout <<
"\u001b["<<
cursorUp <<
"A";
std::cout << "\u001b[0K";
std::cout <<
"\u001b[36m" << std::setfill(
' ') << std::setw(ColumnWidths::Data-1) <<
formatedValue <<
"\u001b[39m" <<
" |";
std::cout << "\u001b[u";
}
}
private:
std::uint16_t lastDpId_{0};
const std::uint32_t dp_limit{5};
};
}
{
try
{
std::cout << "\u001b[2J";
std::cout << "\u001b[H";
std::cout << "******************************************" << std::endl;
std::cout << "09_BaosView sample" << std::endl;
std::cout << "******************************************" << std::endl;
std::cout << std::endl;
setBaosLogLevel(wz::baos::LogLevel::warn);
options.setDurationOptionSupported(
true);
{
return 0;
}
std::cout <<
" Connection requested for " <<
ipAddress << std::endl;
{
std::cout << "Press [Enter] to exit the application ..." << std::endl;
std::getchar();
}
else
{
std::cout <<
"Listening for indications for " <<
durationSeconds <<
" seconds ..." << std::endl;
}
std::cout << "\u001b[3B";
std::cout << "Bye ..." << std::endl;
}
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.
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::map< std::uint16_t, DatapointValue > DatapointValues
A map with datapoint ids as keys and DatapointValue as values.
Definition Defines.h:36
BAOSLIB_EXPORT std::string dptToString(DPT dpt)
Convert the enum value to a human readable string.
DPT
Enumeration value for the supported datapoint types( DPTs )
Definition Defines.h:173
wz::baos::Buffer DatapointValue
An type for the DatapointValues.
Definition Defines.h:34
Global BAOS sdk namespace.
Definition config.h:69
BAOSLIB_EXPORT void setBaosLogLevel(wz::baos::LogLevel level)
std::map< std::uint16_t, DatapointConfig > DatapointConfigurations
Definition BaosDeviceDataTypes.h:212
Information about a datapoint object.
Definition BaosDeviceDataTypes.h:201
std::string desc
Definition BaosDeviceDataTypes.h:205
protocol::DatapointConfigFlags flags
Definition BaosDeviceDataTypes.h:203
protocol::DPT dpt
Definition BaosDeviceDataTypes.h:204
Struct for the communication flags of a datapoint. See KNX spec for more details.
Definition Defines.h:444
std::uint8_t writeFromBus
The writable from bus flag.
Definition Defines.h:511
std::uint8_t readOnInit
The perform read request in onit flag.
Definition Defines.h:512
std::uint8_t updateResponse
Define the bitfield for the flags and transmitPriority.
Definition Defines.h:514
std::uint8_t communication
Definition Defines.h:509
std::uint8_t transmitToBus
The devices send changes on the group object to the KNX bus.
Definition Defines.h:513
std::uint8_t readFromBus
The readable from bus flag.
Definition Defines.h:510