open62541pp 0.15.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
custom_datatypes/custom_datatypes.hpp
#pragma once
#include <cstdint>
// Example struct
struct Point {
float x;
float y;
float z;
};
const opcua::DataType& getPointDataType() {
static const opcua::DataType dt =
.addField<&Point::x>("x")
.addField<&Point::y>("y")
.addField<&Point::z>("z")
.build();
return dt;
}
// Example struct with an array
struct Measurements {
opcua::String description;
size_t measurementsSize;
float* measurements;
};
const opcua::DataType& getMeasurementsDataType() {
static const opcua::DataType dt =
opcua::DataTypeBuilder<Measurements>::createStructure("Measurements", {1, 4443}, {1, 2})
.addField<&Measurements::description>("description")
.addField<&Measurements::measurementsSize, &Measurements::measurements>("measurements")
.build();
return dt;
}
// Example struct with optional fields
struct Opt {
int16_t a;
float* b;
float* c;
};
const opcua::DataType& getOptDataType() {
static const opcua::DataType dt =
.addField<&Opt::a>("a")
.addField<&Opt::b>("b")
.addField<&Opt::c>("c")
.build();
return dt;
}
// Example union
enum class UniSwitch : uint32_t { None = 0, OptionA = 1, OptionB = 2 };
struct Uni {
UniSwitch switchField;
union {
double optionA;
UA_String optionB;
} fields;
};
const opcua::DataType& getUniDataType() {
static const opcua::DataType dt =
opcua::DataTypeBuilder<Uni>::createUnion("Uni", {1, 4845}, {1, 4})
.addUnionField<&Uni::fields, double>("optionA")
.addUnionField<&Uni::fields, UA_String>("optionB", UA_TYPES[UA_TYPES_STRING])
.build();
return dt;
}
// Example enumeration
enum class Color : int32_t {
Red = 0,
Green = 1,
Yellow = 2,
};
const opcua::DataType& getColorDataType() {
static const opcua::DataType dt =
opcua::DataTypeBuilder<Color>::createEnum("Color", {1, 4946}, {1, 5}).build();
return dt;
}
static auto createEnum(const char *typeName, NodeId typeId, NodeId binaryEncodingId)
Build a DataType definition for an enum.
Definition datatype.hpp:309
static auto createStructure(const char *typeName, NodeId typeId, NodeId binaryEncodingId)
Build a DataType definition for a structure.
Definition datatype.hpp:325
static auto createUnion(const char *typeName, NodeId typeId, NodeId binaryEncodingId)
Build a DataType definition for an union.
Definition datatype.hpp:341
UA_DataType wrapper class.
Definition datatype.hpp:25
UA_String wrapper class.
Definition types.hpp:251
#define UA_TYPES_STRING
const UA_DataType UA_TYPES[191]