Skip to content

Commit 0dbd405

Browse files
authoredDec 2, 2016
Update ua_proxies.cpp
set the right AccessLevel and ValueRank
1 parent 4782b23 commit 0dbd405

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed
 

‎src/ua_proxies.cpp

+57-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
2-
* Copyright (c) 2016 Chris Iatrou <Chris_Paul.Iatrou@tu-dresden.de>
2+
* Copyright (c) 2016
3+
* Chris Iatrou <Chris_Paul.Iatrou@tu-dresden.de>
4+
* Julian Rahm <Julian.Rahm@tu-dresden.de>
35
* Chair for Process Systems Engineering
46
* Technical University of Dresden
57
*
@@ -167,12 +169,65 @@ UA_StatusCode ua_callProxy_mapDataSources(UA_Server* server, nodePairList instan
167169
ds.read = ele->read;
168170
ds.write = ele->write;
169171
ds.handle = srcClass;
172+
173+
// Set accesslevel depending on callback functions
174+
UA_Byte accessLevel;
175+
if(ele->write == NULL && ele->read == NULL) {
176+
accessLevel = 0;
177+
}
178+
if(ele->write != NULL && ele->read == NULL) {
179+
accessLevel = UA_ACCESSLEVELMASK_WRITE;
180+
}
181+
if(ele->write != NULL && ele->read != NULL) {
182+
accessLevel = UA_ACCESSLEVELMASK_WRITE^UA_ACCESSLEVELMASK_READ;
183+
}
184+
if(ele->write == NULL && ele->read != NULL) {
185+
accessLevel = UA_ACCESSLEVELMASK_READ;
186+
}
187+
retval = UA_Server_writeAccessLevel(server, instantiatedId, accessLevel);
188+
// There is currently no high- level function to do this. (02.12.2016)
189+
retval = __UA_Server_write(server, &instantiatedId, UA_ATTRIBUTEID_USERACCESSLEVEL, &UA_TYPES[UA_TYPES_BYTE], &accessLevel);
170190
// add individual description for every variable
171191
UA_Server_writeDescription(server, instantiatedId, ele->description);
172192
delete ele; // inhibit memleak warning during static analysis
173193

174194
retval |= UA_Server_setVariableNode_dataSource(server, (const UA_NodeId) instantiatedId, ds);
175-
}
195+
196+
/* Set the right Value Datatype and ValueRank
197+
* -> This is a quickfix for subjective data handling by open62541
198+
* (02.12.2016)
199+
*/
200+
UA_NodeId datatTypeNodeId = UA_NODEID_NULL;
201+
retval = UA_Server_readDataType(server, instantiatedId, &datatTypeNodeId);
202+
if(retval == UA_STATUSCODE_GOOD) {
203+
const UA_NodeId basedatatype = UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATATYPE);
204+
UA_Variant variantVal;
205+
UA_Variant_init(&variantVal);
206+
retval = UA_Server_readValue(server, instantiatedId, &variantVal);
207+
if(UA_NodeId_equal(&datatTypeNodeId, &basedatatype) && retval == UA_STATUSCODE_GOOD) {
208+
retval = UA_Server_writeDataType(server, instantiatedId, variantVal.type->typeId);
209+
// See IEC 62541-3: OPC Unified Architecture - Part 3: Address space model -> Page 75
210+
UA_Int32 valueRank = -2;
211+
if(variantVal.arrayDimensionsSize == 0 && UA_Variant_isScalar(&variantVal)) {
212+
// Scalar
213+
valueRank = -1;
214+
}
215+
else {
216+
if(variantVal.arrayDimensionsSize > 1) {
217+
// OneOrMoreDimensions
218+
valueRank = 0;
219+
}
220+
else {
221+
if(variantVal.arrayDimensionsSize == 1 || variantVal.arrayLength) {
222+
// OneDimension
223+
valueRank = 1;
224+
}
225+
}
226+
}
227+
UA_Server_writeValueRank(server, instantiatedId, valueRank);
228+
}
229+
}
230+
}
176231

177232
return retval;
178233
}

0 commit comments

Comments
 (0)
Please sign in to comment.