24 #include "csa_config.h"
37 ua_additionalvariable::ua_additionalvariable(
38 UA_Server* server, UA_NodeId basenodeid,
string name,
string value,
string description)
40 this->name = std::move(name);
41 this->value = std::move(value);
42 this->description = std::move(description);
43 this->ownNodeId = UA_NODEID_NULL;
45 this->mapSelfToNamespace();
51 UA_NodeId_clear(&this->ownNodeId);
56 const UA_NodeId* ,
void* ,
const UA_NodeId* ,
void* nodeContext,
57 UA_Boolean includeSourceTimeStamp,
const UA_NumericRange* , UA_DataValue* value) {
60 char* s = (
char*)malloc(thisObj->getValue().length() + 1);
61 strncpy(s, (
char*)thisObj->getValue().c_str(), thisObj->getValue().length());
62 ua_val.length = thisObj->getValue().length();
63 ua_val.data = (UA_Byte*)malloc(ua_val.length);
64 memcpy(ua_val.data, s, ua_val.length);
66 UA_Variant_setScalarCopy(&value->value, &ua_val, &UA_TYPES[11]);
67 UA_String_clear(&ua_val);
68 value->hasValue =
true;
69 if(includeSourceTimeStamp) {
70 value->sourceTimestamp = thisObj->getSourceTimeStamp();
71 value->hasSourceTimestamp =
true;
73 return UA_STATUSCODE_GOOD;
81 UA_StatusCode ua_additionalvariable::mapSelfToNamespace() {
82 UA_StatusCode retval = UA_STATUSCODE_GOOD;
83 UA_NodeId createdNodeId = UA_NODEID_NULL;
85 if(UA_NodeId_equal(&this->
baseNodeId, &createdNodeId) == UA_TRUE)
return UA_STATUSCODE_BADINVALIDARGUMENT;
88 UA_String baseNodeIdString =
baseNodeId.identifier.string;
89 string baseNodeIdStringCPP;
91 if(!baseNodeIdStringCPP.empty()) {
92 baseNodeIdStringCPP.resize(baseNodeIdStringCPP.size() - 3);
95 UA_String* opcua_node_variable_t_ns_2_variant_DataContents = UA_String_new();
96 *opcua_node_variable_t_ns_2_variant_DataContents = UA_STRING_ALLOC(this->value.c_str());
97 UA_VariableAttributes vAttr;
98 UA_VariableAttributes_init(&vAttr);
99 vAttr = UA_VariableAttributes_default;
100 vAttr.displayName = UA_LOCALIZEDTEXT_ALLOC(
const_cast<char*
>(
"en_US"),
const_cast<char*
>(this->name.c_str()));
102 UA_LOCALIZEDTEXT_ALLOC(
const_cast<char*
>(
"en_US"),
const_cast<char*
>(this->description.c_str()));
103 vAttr.dataType = UA_NODEID_NUMERIC(0, UA_NS0ID_STRING);
104 vAttr.valueRank = UA_VALUERANK_SCALAR;
105 UA_Variant_setScalar(&vAttr.value, opcua_node_variable_t_ns_2_variant_DataContents, &UA_TYPES[UA_TYPES_STRING]);
107 UA_QualifiedName qualName = UA_QUALIFIEDNAME_ALLOC(1, this->name.c_str());
109 UA_NODEID_STRING(1,
const_cast<char*
>((baseNodeIdStringCPP +
"/" + name +
"AdditionalVariable").c_str())),
110 this->
baseNodeId, UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), qualName,
111 UA_NODEID_NUMERIC(CSA_NSID, UA_NS2ID_CTKADDITIONALVARIABLE), vAttr, (
void*)
this, &createdNodeId);
112 UA_NodeId_copy(&createdNodeId, &this->ownNodeId);
114 createdNodeId, UA_NODEID_NUMERIC(CSA_NSID, UA_NS2ID_CTKADDITIONALVARIABLE), &this->
ownedNodes);
116 UA_QualifiedName_clear(&qualName);
117 UA_VariableAttributes_clear(&vAttr);
119 UA_VariableAttributes vAttr2;
120 UA_VariableAttributes_init(&vAttr2);
121 vAttr2 = UA_VariableAttributes_default;
122 vAttr2.displayName = UA_LOCALIZEDTEXT_ALLOC(
const_cast<char*
>(
"en_US"),
const_cast<char*
>(
"Description"));
124 UA_LOCALIZEDTEXT_ALLOC(
const_cast<char*
>(
"en_US"),
const_cast<char*
>(this->description.c_str()));
125 vAttr2.dataType = UA_NODEID_NUMERIC(0, UA_NS0ID_STRING);
126 vAttr.valueRank = UA_VALUERANK_SCALAR;
127 UA_String addVarDescription = UA_STRING_ALLOC(description.c_str());
128 UA_Variant_setScalarCopy(&vAttr2.value, &addVarDescription, &UA_TYPES[UA_TYPES_STRING]);
130 UA_QualifiedName qualName2 = UA_QUALIFIEDNAME_ALLOC(1, this->description.c_str());
131 string parentNodeStringDescription = baseNodeIdStringCPP +
"/" + name +
"/Description";
133 UA_NODEID_STRING(1,
const_cast<char*
>(parentNodeStringDescription.c_str())), this->ownNodeId,
134 UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), qualName2, UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
135 vAttr2,
nullptr,
nullptr);
137 UA_QualifiedName_clear(&qualName2);
142 mapElemValue.
typeTemplateId = UA_NODEID_NUMERIC(CSA_NSID, CSA_NSID_ADDITIONAL_VARIABLE_VALUE);
143 mapElemValue.description = vAttr2.description;
145 mapElemValue.dataSource.write =
nullptr;
146 mapDs.push_back(mapElemValue);
148 UA_Server_setVariableNode_dataSource(this->
mappedServer, createdNodeId, mapElemValue.dataSource);
150 UA_String_clear(&addVarDescription);
151 UA_VariableAttributes_clear(&vAttr2);
152 UA_NodeId_clear(&createdNodeId);
158 return UA_DateTime_now();