This sample shows how to register a callback function for server item indications via the connection API.
#include "Helper.h"
#include <iostream>
#include <memory>
#include <thread>
using namespace wz::baos::ip;
int main(int argc, char* argv[])
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "ServerItemIndication sample" << std::endl;
std::cout << "******************************************" << std::endl;
std::cout << std::endl;
CommandLineOptions options;
options.setDurationOptionSupported(true);
options.parse(argc, argv);
if (options.wasHelpdisplayed())
{
return 0;
}
const std::string ipAddress = options.getIpAddress();
std::cout << " Connection requested for " << ipAddress << std::endl;
connection.
open(ipAddress);
connection.setServerItemsIndCallback(
{
for (const auto& serverItem : serverItems)
{
std::cout << "Received server item indication for id " << static_cast<std::uint32_t>(serverItem.id);
std::cout << ", " << description;
std::cout << ", data: ";
std::cout.fill('0');
std::cout << std::hex << std::uppercase;
for (auto& value : serverItem.data)
{
std::cout << std::setw(2) << static_cast<std::int32_t>(value) << " ";
}
std::cout << std::nouppercase << std::dec << std::endl;
}
});
if (options.isInteractive())
{
std::cout << "Press [Enter] to exit the application ..." << std::endl;
std::getchar();
}
else
{
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.
BaosConLessTcpConnection BaosTcpConnection
A specialization for (connection-less) connection to the BAOS device via a TCP connection.
Definition: BaosTcpConnection.h:168
Global BAOS protocol defines and types.
Global BAOS SDK function and options.
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
BAOSLIB_EXPORT std::string serverItemIdToString(ServerItemId sid)
Convert the enum value to a human readable string.
std::vector< ServerItem > ServerItems
Type for a list of ServerItems.
Definition: Defines.h:440
Global BAOS sdk namespace.
Definition: config.h:69
BAOSLIB_EXPORT void setBaosLogLevel(wz::baos::LogLevel level)