This sample shows how to read and write datapoint values via the device API.
#include "Helper.h"
#include <iostream>
#include <memory>
using namespace wz::baos::ip;
namespace
{
{
std::cout.fill('0');
std::cout << std::hex << std::uppercase;
for (auto& item : dpValue)
{
std::cout << std::setw(2) << static_cast<int>(item) << " ";
}
std::cout << std::nouppercase << std::dec;
}
}
int main(int argc, char* argv[])
{
try
{
std::cout << "******************************************" << std::endl;
std::cout << "04_BaosDatapoints 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;
BaosIp4Device baosDevice(ipAddress);
auto maybeValue = baosDevice.getDpValueRaw(1);
if (maybeValue.has_value())
{
std::cout << "Id: 1, value: ";
traceDatapointValue(*maybeValue);
std::cout << std::endl;
}
else
{
std::cerr << "No datapoint value for datapoint id 1" << std::endl;
}
maybeValue = baosDevice.getDpValueRaw(4);
if (maybeValue.has_value())
{
std::cout << "Id: 4, value: ";
traceDatapointValue(*maybeValue);
std::cout << std::endl;
}
maybeValue = baosDevice.getDpValueRaw(10);
if (maybeValue.has_value())
{
std::cout << "Id: 10, value: ";
traceDatapointValue(*maybeValue);
std::cout << std::endl;
}
std::cout << std::endl << "all datapoints: " << std::endl;
for (const auto& item : values)
{
std::cout << "Id: " << item.first;
std::cout << ", value: ";
traceDatapointValue(value);
std::cout << std::endl;
}
std::cout << "---------------" << std::endl;
baosDevice.setDpValue(1, {0x00}, DatapointSetCommand::SetNewValue);
baosDevice.setDpValue(2, {0x00}, DatapointSetCommand::SetNewValueAndSendOnBus);
baosDevice.setDpValue(10, {0x01, 0x23}, DatapointSetCommand::SetNewValueAndSendOnBus);
}
catch (const wzcpp::error::WzBaseException& e)
{
std::cout << "Wz Exception in main: " << e.msg() << 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 protocol defines and types.
Global BAOS SDK function and options.
Groups BAOS binary protocol specific types , defines and classes for Indications, Responses etc.
Definition: Defines.h:32
std::map< std::uint16_t, DatapointValue > DatapointValues
A map with datapoint ids as keys and DatapointValue as values.
Definition: Defines.h:35
wz::baos::Buffer DatapointValue
An type for the DatapointValues.
Definition: Defines.h:33
Global BAOS sdk namespace.
Definition: config.h:62
void setBaosLogLevel(wzcpp::LogLevel level)