#include "Helper.h"
#include <wzcpp/features/utils.h>
#include <iostream>
#include <memory>
using namespace wz::baos::ip;
namespace
{
std::uint16_t decodeServerItem_uint16(const ServerItem& serverItem)
{
return serverItem.data.at(0) << 8 | serverItem.data.at(1);
}
bool decodeServerItem_bool(const ServerItem& serverItem)
{
bool value = (serverItem.data.at(0) & 0x01) ? true : false;
return value;
}
std::string decodeServerItem_string(const ServerItem& serverItem)
{
return std::string(serverItem.data.begin(), serverItem.data.end());
}
}
int main(int argc, char* argv[])
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "GetServerItem sample" << std::endl;
std::cout << "******************************************" << std::endl;
std::cout << std::endl;
CommandLineOptions options;
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);
auto serverItem = connection.getServerItem(ServerItemId::DeviceFriendlyName);
if (serverItem.has_value())
{
std::cout << "Device friendly name: " << decodeServerItem_string(*serverItem) << std::endl;
}
else
{
std::cerr << "Unable to get serveritem ServerItemId::DeviceFriendlyName" << std::endl;
}
serverItem = connection.getServerItem(ServerItemId::ManufactureCodeApp);
if (serverItem.has_value())
{
std::cout << "Manufacturer code app.: " << decodeServerItem_uint16(*serverItem) << std::endl;
}
else
{
std::cerr << "Unable to get serveritem ServerItemId::ManufactureCodeApp" << std::endl;
}
serverItem = connection.getServerItem(ServerItemId::ProgrammingMode);
if (serverItem.has_value())
{
std::cout << "Programming mode: " << std::boolalpha << decodeServerItem_bool(*serverItem) << std::endl;
}
else
{
std::cerr << "Unable to get serveritem ServerItemId::ProgrammingMode" << std::endl;
}
std::cout << std::endl;
std::cout << "Reading serveritems 3 - 12:" << std::endl;
const ServerItems serverItems = connection.getServerItems(3, 10);
for (const ServerItem& item : serverItems)
{
std::cout << description << " data: ";
std::cout.fill('0');
std::cout << std::hex << std::uppercase;
for (auto& value : item.data)
{
std::cout << std::setw(2) << static_cast<std::int32_t>(value) << " ";
}
std::cout << std::nouppercase << std::dec << std::endl;
}
}
catch (const std::exception& e)
{
std::cerr << "Failed: " << e.what() << std::endl;
return -1;
}
return 0;
}
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)