BAOS SDK v2  1.2.1
An SDK providing access to IP-BAOS devices through BAOS binary protocol version 2.x
Loading...
Searching...
No Matches
DatapointValueIndication.cpp

This sample shows how to register a callback function for datapoint value indications via the connection API.

Usage:

DatapointValueIndication <ip_address>
// e.g.:
DatapointValueIndication 10.0.0.102
//
// Copyright (c) 2002-2026 WEINZIERL ENGINEERING GmbH
// All rights reserved.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
// WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
//
#include "Helper.h"
#include <baos/Sdk.h>
#include <iostream>
#include <memory>
#include <thread>
using namespace wz::baos;
using namespace wz::baos::ip;
using namespace wz::baos::protocol;
/******************************************
** Anonymous namespace
*******************************************/
namespace
{
{
std::cout.fill('0');
std::cout << std::hex << std::uppercase;
for (auto& item : dpValue)
{
std::cout << std::setw(2) << static_cast<std::int32_t>(item) << " ";
}
std::cout << std::nouppercase << std::dec;
}
} // end anonymous namespace
/******************************************
** Main
*******************************************/
int main(int argc, char* argv[])
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "DatapointValueIndication sample" << std::endl;
std::cout << "******************************************" << std::endl;
std::cout << std::endl;
// Reduce log messages
setBaosLogLevel(wz::baos::LogLevel::warn);
// The CommandLineOptions::parse function
// validates the arguments and handles also the help command
CommandLineOptions options;
options.setDurationOptionSupported(true);
options.parse(argc, argv);
if (options.wasHelpdisplayed())
{
return 0;
}
// Get the ip address from the parsed command line options
const std::string ipAddress = options.getIpAddress();
std::cout << " Connection requested for " << ipAddress << std::endl;
// Create a TPC/IP connection with the remote BAOS device
// register callback function for datapoint value indications
{
for (const auto& item : valueStates)
{
const DatapointValueState& value = item.second;
std::cout << "Received datapoint value indication for id " << item.first;
std::cout << ", value: ";
std::cout << std::endl;
}
});
// Default behaviour is interactive: wait for user input.
// For automated runs the sample can terminate automatically after N seconds.
if (options.isInteractive())
{
// Wait for Enter, all indications will be shown in the callback event handlers.
std::cout << "Press [Enter] to exit the application ..." << std::endl;
std::getchar();
}
else
{
// Wait for End, all indications will be shown in the callback event handlers.
const std::int32_t durationSeconds = options.getDurationSeconds();
std::cout << "Listening for indications for " << durationSeconds << " seconds ..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(durationSeconds));
}
}
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.
Definition Helper.h:23
void setDatapointValueIndCallback(DatapointValueCb callback)
A specialization for (connection-less) connection to the BAOS device via a TCP connection.
Definition BaosTcpConnection.h:145
A specialization for (connection oriented) connection to the BAOS device via a TCP connection.
Definition BaosTcpConnection.h:182
void open(const std::string &ip4Address, std::uint16_t port=12004)
Open a connection to physical BAOS device.
Groups BAOS binary protocol specific types , defines and classes for Indications, Responses etc.
Definition Defines.h:33
std::map< std::uint16_t, DatapointValueState > DatapointValueStates
Definition Defines.h:607
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)
A combination of the status of a datapoint and its actual value.
Definition Defines.h:601
DatapointValue value
The actual value of the datapoint.
Definition Defines.h:602