#include "Helper.h"
#include <wzcpp/features/utils.h>
#include <iostream>
#include <memory>
using namespace wz::baos::ip;
namespace
{
Buffer encodeServerItem_bool(
bool value)
{
Buffer data(1, value ? 0x01 : 0x00);
return data;
}
Buffer encodeServerItem_string(
const std::string& value)
{
Buffer data(value.begin(), value.end());
data.resize(30, 0);
return data;
}
}
int main(int argc, char* argv[])
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "SetServerItem 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);
std::cout << "DeviceFriendlyName" << std::endl;
const auto backup = connection.getServerItem(ServerItemId::DeviceFriendlyName);
if (backup.has_value())
{
try
{
ServerItem deviceNameItem(ServerItemId::DeviceFriendlyName, 30, encodeServerItem_string("Hello BAOS"));
connection.setServerItem(deviceNameItem);
connection.setServerItem(*backup);
}
catch (WzResponseException&)
{
std::cerr << "Unable to write ServerItem ServerItemId::DeviceFriendlyName" << std::endl;
}
}
else
{
std::cerr << "Unable to read ServerItem ServerItemId::DeviceFriendlyName" << std::endl;
}
std::cout << "ProgrammingMode" << std::endl;
ServerItem progModeItem(ServerItemId::ProgrammingMode, 1, encodeServerItem_bool(true));
connection.setServerItem(progModeItem);
progModeItem.data = encodeServerItem_bool(false);
connection.setServerItem(progModeItem);
}
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
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)