#include "Helper.h"
#include <iostream>
#include <memory>
namespace
{
void getDeviceInfo(ip::BaosIp4Device& baosDevice)
{
try
{
const DeviceStaticInfo staticInfo = baosDevice.getStaticInfo();
auto dpDescs = baosDevice.getAllDpConfigurations();
std::cout << dpDescs.size() << " datapoints configured" << std::endl;
auto dpValues = baosDevice.getAllDpValuesRaw();
std::cout << dpValues.size() << " valid datapoint values" << std::endl;
std::cout << "Read all parameter bytes: " << std::endl;
auto params = baosDevice.getAllParameterBytes();
std::cout << params.size() << " parameter bytes read" << std::endl;
}
catch (const wzcpp::error::WzBaseException& e)
{
std::cerr << "Wz Exception in main: " << e.msg() << std::endl;
}
}
}
int main(int argc, char* argv[])
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "08_Class config 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 << " Working with device on IP address " << ipAddress << std::endl;
{
std::cout << "------------------ ServerItemReadStrategy::METADATAREADWITHFALLBACK -----------------------"
<< std::endl;
ip::BaosIp4Device baosDevice(ipAddress);
getDeviceInfo(baosDevice);
}
{
std::cout << "------------------ Set meta data manually -----------------------" << std::endl;
ip::BaosIp4Device baosDevice(ipAddress);
baosDevice.setMetaInfo(DeviceMeta{"BaosGeneric", 18, 100, 100});
const DeviceConfigInfo configInfo = baosDevice.getConfigInfo();
const DeviceGroupIdentifier devicegroupid{configInfo.manufactureCodeApp,
configInfo.applicationId,
configInfo.applicationVersion};
auto hexString = wzcpp::rangeToHex<std::array<std::byte, 5>>(devicegroupid.deviceid);
std::cout << "The DeviceGroupIdentifier for this device is: " << hexString << std::endl;
getDeviceInfo(baosDevice);
}
{
std::cout << "------------------ ServerItemReadStrategy::AllATONCE -----------------------" << std::endl;
ip::BaosIp4Device baosDevice(ipAddress);
bool allAtOnceAvailable{false};
try
{
auto staticInfo = baosDevice.getStaticInfo();
auto connection = baosDevice.getConnection();
if (maxDatapointsItem.has_value())
{
std::cout << "Serveritem MaxDatapoints available" << std::endl;
}
if (maxParameterBytesItem.has_value())
{
std::cout << "Serveritem MaxParameterBytes available" << std::endl;
}
if (maxDatapointsItem.has_value() && maxParameterBytesItem.has_value())
{
allAtOnceAvailable = true;
}
}
catch (const wzcpp::error::WzBaseException& e)
{
std::cerr << "Wz Exception in main: " << e.msg() << std::endl;
}
std::cout << "The device with ip " << ipAddress << " can use the all at once strategy: " << std::boolalpha
<< allAtOnceAvailable << 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 SDK function and options.
@ MaxParameterBytes
(Read Only; 2 bytes; from V2.1)
@ MaxDatapoints
(Read Only; 2 bytes; from V2.1)
Global BAOS sdk namespace.
Definition: config.h:62
void setBaosLogLevel(wzcpp::LogLevel level)
@ ALLATONCE
Read from first to std::uint16_t Max serveritems.