diff --git a/examples/tutorial_server_alarms_conditions.c b/examples/tutorial_server_alarms_conditions.c index a8f4f30702b..4078a414afc 100644 --- a/examples/tutorial_server_alarms_conditions.c +++ b/examples/tutorial_server_alarms_conditions.c @@ -70,12 +70,28 @@ afterInputNodeWrite (UA_Server *server, UA_Server_exclusiveLimitAlarmEvaluate_default(server, &conditionInstance_1, NULL, (UA_Double*) data->value.data); } +static UA_StatusCode +getInputNodeValue (UA_Server *server, UA_NodeId conditionId, UA_Variant *out) +{ + UA_QualifiedName inputNodeQN = UA_QUALIFIEDNAME(0, "InputNode"); + UA_BrowsePathResult bpr = UA_Server_browseSimplifiedBrowsePath(server, conditionId, 1, &inputNodeQN); + if (bpr.statusCode != UA_STATUSCODE_GOOD || bpr.targetsSize != 1) return bpr.statusCode; + UA_Variant sourceNodeId; + UA_StatusCode status = UA_Server_readValue(server, bpr.targets[0].targetId.nodeId, &sourceNodeId); + UA_BrowsePathResult_clear(&bpr); + if (status != UA_STATUSCODE_GOOD || sourceNodeId.type != &UA_TYPES[UA_TYPES_NODEID]) return status; + status = UA_Server_readValue(server, *(UA_NodeId*) sourceNodeId.data, out); + UA_Variant_clear(&sourceNodeId); + return status; +} + + static void * sourceNodeGetInputDouble (UA_Server *server, const UA_NodeId *conditionId, void *conditionCtx) { UA_Variant val; UA_Variant_init (&val); - UA_StatusCode ret = UA_Server_Condition_getInputNodeValue(server, *conditionId, &val); + UA_StatusCode ret = getInputNodeValue(server, *conditionId, &val); if (ret != UA_STATUSCODE_GOOD || val.type != &UA_TYPES[UA_TYPES_DOUBLE]) { UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, @@ -101,7 +117,11 @@ static UA_StatusCode onCondition1Active ( void *context ) { - return UA_Server_Condition_setAcknowledgeRequired(server, *conditionId); + UA_NodeId ackedId; + UA_Server_getNodeIdWithBrowseName(server, conditionId, UA_QUALIFIEDNAME(0, "AckedState"), &ackedId); + UA_Server_writeTwoStateVariable(server, ackedId, UA_LOCALIZEDTEXT("en", "Unacknowledged"), false); + UA_NodeId_clear (&ackedId); + return UA_STATUSCODE_GOOD; } UA_ConditionCallbacks condition1Impl = { diff --git a/include/open62541/server.h b/include/open62541/server.h index 6b7c82b80bd..01d9f8de240 100644 --- a/include/open62541/server.h +++ b/include/open62541/server.h @@ -1265,6 +1265,59 @@ UA_StatusCode UA_EXPORT UA_THREADSAFE UA_Server_readObjectProperty(UA_Server *server, const UA_NodeId objectId, const UA_QualifiedName propertyName, UA_Variant *value); + +/** + * Write a value to a node via a simplified browsepath + * @param server + * @param objectId + * @param value + * @param pathSize + * @param path + * @return + */ +UA_StatusCode +UA_Server_writeValueSimplifiedBrowsePath ( + UA_Server *server, + const UA_NodeId objectId, + const UA_Variant value, + size_t pathSize, + const UA_QualifiedName *path +); + +/** + * read a value from a node via a simplified browsepath + * @param server + * @param objectId + * @param pathSize + * @param path + * @param value + * @return + */ +UA_StatusCode +UA_Server_readValueSimplifiedBrowsePath ( + UA_Server *server, + const UA_NodeId objectId, + size_t pathSize, + const UA_QualifiedName *path, + UA_Variant *value +); + +/** + * write the values to a two state variable node + * @param server + * @param twoStateVariableId + * @param value + * @param idValue + * @return + */ +UA_StatusCode +UA_Server_writeTwoStateVariable ( + UA_Server *server, + const UA_NodeId twoStateVariableId, + UA_LocalizedText value, + UA_Boolean idValue +); + /* * Get the nodeId of a node from an origin node and a browse name * @@ -1758,28 +1811,10 @@ UA_StatusCode UA_EXPORT UA_Server_Condition_placeInService(UA_Server *server, UA_NodeId conditionId, const UA_LocalizedText *comment); /* - Condition direct State Maniputation + Condition Evaluation and Event Generation */ - -/* - * Set the condition confirmed state where a confirmation is required. The logic for setting this is Server specific, so - * the only time a conditions ConfirmedState will be set to false is when a server implementation uses this function . - */ UA_StatusCode UA_EXPORT -UA_Server_Condition_setConfirmRequired(UA_Server *server, UA_NodeId conditionId); - -UA_StatusCode UA_EXPORT -UA_Server_Condition_setAcknowledgeRequired(UA_Server *server, UA_NodeId conditionId); - -UA_StatusCode UA_EXPORT -UA_Server_Condition_getInputNodeValue (UA_Server *server, UA_NodeId conditionId, UA_Variant *out); - -UA_StatusCode UA_EXPORT -UA_Server_Condition_setActiveState (UA_Server *server, UA_NodeId conditionId, UA_Boolean active); - -/* - Condition Event Generation -*/ +UA_Server_Condition_evaluateRetainState (UA_Server *server, UA_NodeId conditionId); UA_StatusCode UA_EXPORT UA_Server_Condition_notifyStateChange(UA_Server *server, UA_NodeId condition, const UA_ConditionEventInfo *info); diff --git a/src/server/ua_server_internal.h b/src/server/ua_server_internal.h index d3e16c2f059..43f984d49e8 100644 --- a/src/server/ua_server_internal.h +++ b/src/server/ua_server_internal.h @@ -480,6 +480,30 @@ readObjectProperty(UA_Server *server, const UA_NodeId objectId, const UA_QualifiedName propertyName, UA_Variant *value); +UA_StatusCode writeValueSimplifiedBrowsePath ( + UA_Server *server, + const UA_NodeId object_id, + const UA_Variant value, + size_t path_size, + const UA_QualifiedName *path +); + +UA_StatusCode readValueSimplifiedBrowsePath ( + UA_Server *server, + const UA_NodeId object_id, + size_t path_size, + const UA_QualifiedName *path, + UA_Variant *value +); + +UA_StatusCode +writeTwoStateVariable ( + UA_Server *server, + const UA_NodeId twoStateVariableId, + UA_LocalizedText value, + UA_Boolean idValue +); + UA_StatusCode getNodeIdWithBrowseName(UA_Server *server, const UA_NodeId *origin, UA_QualifiedName browseName, UA_NodeId *outNodeId); diff --git a/src/server/ua_services_attribute.c b/src/server/ua_services_attribute.c index 3ab88025e87..df837bb2bf3 100644 --- a/src/server/ua_services_attribute.c +++ b/src/server/ua_services_attribute.c @@ -788,7 +788,6 @@ readObjectProperty(UA_Server *server, const UA_NodeId objectId, return retval; } - UA_StatusCode UA_Server_readObjectProperty(UA_Server *server, const UA_NodeId objectId, const UA_QualifiedName propertyName, @@ -799,6 +798,107 @@ UA_Server_readObjectProperty(UA_Server *server, const UA_NodeId objectId, return retval; } +UA_StatusCode writeValueSimplifiedBrowsePath ( + UA_Server *server, + const UA_NodeId object_id, + const UA_Variant value, + size_t path_size, + const UA_QualifiedName *path +) +{ + UA_StatusCode retval; + UA_BrowsePathResult bpr = browseSimplifiedBrowsePath (server, object_id, path_size, path); + if(bpr.statusCode != UA_STATUSCODE_GOOD || bpr.targetsSize < 1) { + retval = bpr.statusCode; + UA_BrowsePathResult_clear(&bpr); + return retval; + } + UA_StatusCode ret = writeValueAttribute(server, bpr.targets[0].targetId.nodeId, &value); + UA_BrowsePathResult_clear (&bpr); + return ret; +} + +UA_StatusCode readValueSimplifiedBrowsePath ( + UA_Server *server, + const UA_NodeId object_id, + size_t path_size, + const UA_QualifiedName *path, + UA_Variant *value +) +{ + UA_StatusCode retval; + UA_BrowsePathResult bpr = browseSimplifiedBrowsePath (server, object_id, path_size, path); + if(bpr.statusCode != UA_STATUSCODE_GOOD || bpr.targetsSize < 1) { + retval = bpr.statusCode; + UA_BrowsePathResult_clear(&bpr); + return retval; + } + UA_StatusCode ret = readWithReadValue(server, &bpr.targets[0].targetId.nodeId, UA_ATTRIBUTEID_VALUE, value); + UA_BrowsePathResult_clear (&bpr); + return ret; +} + +inline UA_StatusCode +UA_Server_writeValueSimplifiedBrowsePath ( + UA_Server *server, + const UA_NodeId objectId, + const UA_Variant value, + size_t pathSize, + const UA_QualifiedName *path +) +{ + UA_LOCK(&server->serviceMutex); + UA_StatusCode retval = writeValueSimplifiedBrowsePath (server, objectId, value, pathSize, path); + UA_UNLOCK(&server->serviceMutex); + return retval; +} + +inline UA_StatusCode +UA_Server_readValueSimplifiedBrowsePath ( + UA_Server *server, + const UA_NodeId objectId, + size_t pathSize, + const UA_QualifiedName *path, + UA_Variant *value +) +{ + UA_LOCK(&server->serviceMutex); + UA_StatusCode retval = readValueSimplifiedBrowsePath (server, objectId, pathSize, path, value); + UA_UNLOCK(&server->serviceMutex); + return retval; +} + +inline UA_StatusCode +writeTwoStateVariable ( + UA_Server *server, + const UA_NodeId twoStateVariableId, + UA_LocalizedText value, + UA_Boolean idValue +) +{ + UA_Variant val; + UA_Variant_setScalar(&val, &value, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]); + UA_StatusCode ret = writeValueAttribute (server, twoStateVariableId, &val); + if (ret != UA_STATUSCODE_GOOD) return ret; + UA_Variant_setScalar(&val, &idValue, &UA_TYPES[UA_TYPES_BOOLEAN]); + UA_QualifiedName idPath = UA_QUALIFIEDNAME(0, "Id"); + return writeValueSimplifiedBrowsePath (server, twoStateVariableId, val, 1, &idPath); +} + +inline UA_StatusCode +UA_Server_writeTwoStateVariable ( + UA_Server *server, + const UA_NodeId twoStateVariableId, + UA_LocalizedText value, + UA_Boolean idValue +) +{ + UA_LOCK(&server->serviceMutex); + UA_StatusCode retval = writeTwoStateVariable (server, twoStateVariableId, value, idValue); + UA_UNLOCK(&server->serviceMutex); + return retval; +} + UA_StatusCode getNodeIdWithBrowseName(UA_Server *server, const UA_NodeId *origin, UA_QualifiedName browseName, UA_NodeId *outNodeId) diff --git a/src/server/ua_subscription_alarms_conditions.c b/src/server/ua_subscription_alarms_conditions.c index 2a25c0a9704..9dafbf918b8 100644 --- a/src/server/ua_subscription_alarms_conditions.c +++ b/src/server/ua_subscription_alarms_conditions.c @@ -631,29 +631,21 @@ readObjectPropertyUInt16 (UA_Server *server, UA_NodeId id, UA_QualifiedName prop return retval; } -static UA_StatusCode +static inline UA_StatusCode setTwoStateVariable (UA_Server *server, const UA_NodeId *condition, UA_QualifiedName field, - UA_Boolean idValue, const char *state) + UA_Boolean idValue, UA_LocalizedText state) { - /* Update Enabled State */ - UA_Variant value; - UA_Variant_setScalar(&value, &idValue, &UA_TYPES[UA_TYPES_BOOLEAN]); - UA_StatusCode retval = UA_STATUSCODE_GOOD; - retval = setConditionVariableFieldProperty(server, *condition, &value, - field, stateVariableIdQN); - CONDITION_ASSERT_RETURN_RETVAL(retval, "Setting State Id failed",); - - UA_LocalizedText stateText = UA_LOCALIZEDTEXT(LOCALE, (char *) (uintptr_t) state); - UA_Variant_setScalar(&value, &stateText, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]); - retval = setConditionField (server, *condition, &value, field); - CONDITION_ASSERT_RETURN_RETVAL(retval, "set State text failed",); - return retval; + UA_NodeId stateId; + UA_StatusCode ret = getNodeIdWithBrowseName(server, condition, field, &stateId); + if (ret != UA_STATUSCODE_GOOD) return ret; + ret = writeTwoStateVariable(server, stateId, state, idValue); + UA_NodeId_clear (&stateId); + return ret; } - -static UA_StatusCode +static inline UA_StatusCode setOptionalTwoStateVariable (UA_Server *server, const UA_NodeId *condition, UA_QualifiedName field, - UA_Boolean idValue, const char *state) + UA_Boolean idValue, UA_LocalizedText state) { if (!fieldExists(server, condition, &field))return UA_STATUSCODE_GOOD; return setTwoStateVariable (server, condition, field, idValue, state); @@ -1012,7 +1004,7 @@ static inline UA_StatusCode UA_ConditionBranch_State_setAckedState(UA_ConditionBranch *branch, UA_Server *server, UA_Boolean acked) { return setTwoStateVariable ( - server, &branch->id, fieldAckedStateQN, acked, acked ? ACKED_TEXT : UNACKED_TEXT + server, &branch->id, fieldAckedStateQN, acked, UA_LOCALIZEDTEXT(LOCALE, acked ? ACKED_TEXT : UNACKED_TEXT) ); } @@ -1020,7 +1012,7 @@ static inline UA_StatusCode UA_ConditionBranch_State_setConfirmedState(UA_ConditionBranch *branch, UA_Server *server, UA_Boolean confirmed) { return setOptionalTwoStateVariable ( - server, &branch->id, fieldConfirmedStateQN, confirmed, confirmed ? CONFIRMED_TEXT: UNCONFIRMED_TEXT + server, &branch->id, fieldConfirmedStateQN, confirmed, UA_LOCALIZEDTEXT(LOCALE, confirmed ? CONFIRMED_TEXT: UNCONFIRMED_TEXT) ); } @@ -1103,7 +1095,7 @@ UA_Condition_State_setEnabledState(UA_Condition *condition, UA_Server *server, U { return setTwoStateVariable ( server, &condition->mainBranch->id, fieldEnabledStateQN, enabled, - enabled ? ENABLED_TEXT : DISABLED_TEXT + UA_LOCALIZEDTEXT (LOCALE, enabled ? ENABLED_TEXT : DISABLED_TEXT) ); } @@ -1112,7 +1104,7 @@ Condition_State_setActiveState (UA_Server *server, const UA_NodeId * condition, { return setTwoStateVariable ( server, condition, fieldActiveStateQN, active, - active ? ACTIVE_TEXT : INACTIVE_TEXT + UA_LOCALIZEDTEXT (LOCALE, active ? ACTIVE_TEXT : INACTIVE_TEXT) ); } @@ -1130,21 +1122,12 @@ UA_Condition_State_setActiveState (UA_Condition *condition, UA_Server *server, U return Condition_State_setActiveState (server, &condition->mainBranch->id, active); } -inline UA_StatusCode -UA_Server_Condition_setActiveState (UA_Server *server, UA_NodeId conditionId, UA_Boolean active) -{ - UA_LOCK (&server->serviceMutex); - UA_StatusCode status = Condition_State_setActiveState (server, &conditionId, active); - UA_UNLOCK (&server->serviceMutex); - return status; -} - static inline UA_StatusCode UA_Condition_State_setLatchedState (UA_Condition *condition, UA_Server *server, UA_Boolean latched) { return setOptionalTwoStateVariable ( server, &condition->mainBranch->id, fieldLatchedStateQN, latched, - latched ? LATCHED_TEXT: NOT_LATCHED_TEXT + UA_LOCALIZEDTEXT (LOCALE, latched ? LATCHED_TEXT: NOT_LATCHED_TEXT) ); } @@ -1153,7 +1136,7 @@ UA_Condition_State_setSuppressedState (UA_Condition *condition, UA_Server *serve { return setOptionalTwoStateVariable ( server, &condition->mainBranch->id, fieldSuppressedStateQN, suppressed, - suppressed ? SUPPRESSED_TEXT : NOT_SUPPRESSED_TEXT + UA_LOCALIZEDTEXT (LOCALE, suppressed ? SUPPRESSED_TEXT : NOT_SUPPRESSED_TEXT) ); } @@ -1162,7 +1145,7 @@ UA_Condition_State_setOutOfServiceState (UA_Condition *condition, UA_Server *ser { return setOptionalTwoStateVariable ( server, &condition->mainBranch->id, fieldOutOfServiceStateQN, outOfService, - outOfService ? OUT_OF_SERVICE_TEXT : IN_SERVICE_TEXT + UA_LOCALIZEDTEXT (LOCALE, outOfService ? OUT_OF_SERVICE_TEXT : IN_SERVICE_TEXT) ); } @@ -1549,6 +1532,21 @@ UA_ConditionBranch_evaluateRetainState(UA_ConditionBranch *branch, UA_Server *se UA_ConditionBranch_State_setRetain(branch, server, retain); } +UA_StatusCode +UA_Server_Condition_evaluateRetainState (UA_Server *server, UA_NodeId conditionId) +{ + UA_LOCK (&server->serviceMutex); + UA_ConditionBranch *branch = getConditionBranch(server, &conditionId); + if (!branch) + { + UA_LOCK (&server->serviceMutex); + return UA_STATUSCODE_BADNODEIDUNKNOWN; + } + UA_ConditionBranch_evaluateRetainState(branch, server); + UA_LOCK (&server->serviceMutex); + return UA_STATUSCODE_GOOD; +} + static UA_StatusCode conditionBranchAcknowledge(UA_Server *server, UA_ConditionBranch *branch, const UA_LocalizedText *comment) { @@ -1616,37 +1614,6 @@ UA_Server_Condition_confirm(UA_Server *server, UA_NodeId conditionId, const UA_L return ret; } -UA_StatusCode -UA_Server_Condition_setConfirmRequired(UA_Server *server, UA_NodeId conditionId) -{ - UA_LOCK (&server->serviceMutex); - UA_ConditionBranch *branch = getConditionBranch(server, &conditionId); - if (!branch) - { - UA_UNLOCK(&server->serviceMutex); - return UA_STATUSCODE_BADNODEIDUNKNOWN; - } - UA_StatusCode ret = UA_ConditionBranch_State_setConfirmedState (branch, server, false); - UA_UNLOCK(&server->serviceMutex); - return ret; -} - -UA_StatusCode -UA_Server_Condition_setAcknowledgeRequired(UA_Server *server, UA_NodeId conditionId) -{ - UA_LOCK (&server->serviceMutex); - UA_ConditionBranch *branch = getConditionBranch(server, &conditionId); - if (!branch) - { - UA_UNLOCK(&server->serviceMutex); - return UA_STATUSCODE_BADNODEIDUNKNOWN; - } - UA_StatusCode ret = UA_STATUSCODE_GOOD; - ret = UA_ConditionBranch_State_setAckedState(branch, server, false); - UA_UNLOCK(&server->serviceMutex); - return ret; -} - static UA_StatusCode condition_reset (UA_Server *server, UA_Condition *condition, const UA_LocalizedText *comment) { @@ -2075,7 +2042,7 @@ static UA_StatusCode setConditionProperties ( } /* Set EnabledState */ - retval = setTwoStateVariable (server, conditionId, fieldEnabledStateQN, false, DISABLED_TEXT); + retval = setTwoStateVariable (server, conditionId, fieldEnabledStateQN, false, UA_LOCALIZEDTEXT(LOCALE, DISABLED_TEXT)); CONDITION_ASSERT_RETURN_RETVAL(retval, "Setting initial Enabled state failed",); return retval; } @@ -2498,60 +2465,11 @@ addOptionalField(UA_Server *server, const UA_NodeId object, } /* Set the value of condition field (only scalar). */ -static UA_StatusCode +static inline UA_StatusCode setConditionField(UA_Server *server, const UA_NodeId condition, const UA_Variant* value, const UA_QualifiedName fieldName) { UA_LOCK_ASSERT(&server->serviceMutex, 1); - - if(value->arrayLength != 0 || value->data <= UA_EMPTY_ARRAY_SENTINEL) { - //TODO implement logic for array variants! - CONDITION_ASSERT_RETURN_RETVAL(UA_STATUSCODE_BADNOTIMPLEMENTED, - "Set Condition Field with Array value not implemented",); - } - - UA_BrowsePathResult bpr = browseSimplifiedBrowsePath(server, condition, 1, &fieldName); - if(bpr.statusCode != UA_STATUSCODE_GOOD) - return bpr.statusCode; - - UA_StatusCode retval = writeValueAttribute(server, bpr.targets[0].targetId.nodeId, value); - UA_BrowsePathResult_clear(&bpr); - - return retval; -} - -static UA_StatusCode -setConditionVariableFieldProperty(UA_Server *server, const UA_NodeId condition, - const UA_Variant* value, - const UA_QualifiedName variableFieldName, - const UA_QualifiedName variablePropertyName) { - UA_LOCK_ASSERT(&server->serviceMutex, 1); - - if(value->arrayLength != 0 || value->data <= UA_EMPTY_ARRAY_SENTINEL) { - //TODO implement logic for array variants! - CONDITION_ASSERT_RETURN_RETVAL(UA_STATUSCODE_BADNOTIMPLEMENTED, - "Set Property of Condition Field with Array value not implemented",); - } - - /* 1) find Variable Field of the Condition*/ - UA_BrowsePathResult bprConditionVariableField = - browseSimplifiedBrowsePath(server, condition, 1, &variableFieldName); - if(bprConditionVariableField.statusCode != UA_STATUSCODE_GOOD) - return bprConditionVariableField.statusCode; - - /* 2) find Property of the Variable Field of the Condition*/ - UA_BrowsePathResult bprVariableFieldProperty = - browseSimplifiedBrowsePath(server, bprConditionVariableField.targets->targetId.nodeId, - 1, &variablePropertyName); - if(bprVariableFieldProperty.statusCode != UA_STATUSCODE_GOOD) { - UA_BrowsePathResult_clear(&bprConditionVariableField); - return bprVariableFieldProperty.statusCode; - } - - UA_StatusCode retval = - writeValueAttribute(server, bprVariableFieldProperty.targets[0].targetId.nodeId, value); - UA_BrowsePathResult_clear(&bprConditionVariableField); - UA_BrowsePathResult_clear(&bprVariableFieldProperty); - return retval; + return writeValueSimplifiedBrowsePath(server, condition, *value , 1, &fieldName); } // -------- Interact with condition @@ -3462,7 +3380,7 @@ setupAcknowledgeableConditionNodes (UA_Server *server, const UA_NodeId *conditio const UA_AcknowledgeableConditionProperties *properties) { UA_NodeId acknowledgeableConditionTypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ACKNOWLEDGEABLECONDITIONTYPE); - UA_StatusCode retval = setTwoStateVariable (server, condition, fieldAckedStateQN, true, ACKED_TEXT); + UA_StatusCode retval = setTwoStateVariable (server, condition, fieldAckedStateQN, true, UA_LOCALIZEDTEXT(LOCALE,ACKED_TEXT)); CONDITION_ASSERT_RETURN_RETVAL(retval, "Setting initial Acked state failed",); /* add optional field ConfirmedState*/ if (properties->confirmable) @@ -3471,7 +3389,7 @@ setupAcknowledgeableConditionNodes (UA_Server *server, const UA_NodeId *conditio fieldConfirmedStateQN, NULL); CONDITION_ASSERT_RETURN_RETVAL(retval, "Adding ConfirmedState optional Field failed",); - retval = setTwoStateVariable (server, condition, fieldConfirmedStateQN, true, CONFIRMED_TEXT); + retval = setTwoStateVariable (server, condition, fieldConfirmedStateQN, true, UA_LOCALIZEDTEXT(LOCALE, CONFIRMED_TEXT)); CONDITION_ASSERT_RETURN_RETVAL(retval, "Setting initial Confirmed state failed",); /* add reference from Condition to Confirm Method */ @@ -3529,7 +3447,7 @@ setupAlarmConditionNodes (UA_Server *server, const UA_NodeId *condition, UA_NodeId alarmConditionTypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ALARMCONDITIONTYPE); UA_Variant value; - setTwoStateVariable (server, condition, fieldActiveStateQN, false, INACTIVE_TEXT); + setTwoStateVariable (server, condition, fieldActiveStateQN, false, UA_LOCALIZEDTEXT(LOCALE, INACTIVE_TEXT)); if (!UA_NodeId_isNull(&properties->inputNode)) { UA_Variant_setScalar(&value,(void *)(uintptr_t) &properties->inputNode, &UA_TYPES[UA_TYPES_NODEID]); @@ -3542,7 +3460,7 @@ setupAlarmConditionNodes (UA_Server *server, const UA_NodeId *condition, retval = addOptionalField(server, *condition, alarmConditionTypeId, fieldLatchedStateQN, NULL); CONDITION_ASSERT_RETURN_RETVAL(retval, "Adding LatchedState optional Field failed",); - setTwoStateVariable (server, condition, fieldLatchedStateQN, false, NOT_LATCHED_TEXT); + setTwoStateVariable (server, condition, fieldLatchedStateQN, false, UA_LOCALIZEDTEXT(LOCALE, NOT_LATCHED_TEXT)); /* add reference from Condition to Reset Method */ UA_NodeId hasComponent = UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT); @@ -3563,7 +3481,7 @@ setupAlarmConditionNodes (UA_Server *server, const UA_NodeId *condition, retval = addOptionalField(server, *condition, alarmConditionTypeId, fieldSuppressedStateQN, NULL); CONDITION_ASSERT_RETURN_RETVAL(retval, "Adding SuppressedState optional Field failed",); - setTwoStateVariable(server, condition, fieldSuppressedStateQN, false, NOT_SUPPRESSED_TEXT); + setTwoStateVariable(server, condition, fieldSuppressedStateQN, false, UA_LOCALIZEDTEXT(LOCALE, NOT_SUPPRESSED_TEXT)); /* add reference from Condition to Suppress Method */ UA_NodeId hasComponent = UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT); @@ -3596,7 +3514,7 @@ setupAlarmConditionNodes (UA_Server *server, const UA_NodeId *condition, retval = addOptionalField(server, *condition, alarmConditionTypeId, fieldOutOfServiceStateQN, NULL); CONDITION_ASSERT_RETURN_RETVAL(retval, "Adding OutOfServiceState optional Field failed",); - setTwoStateVariable(server, condition, fieldOutOfServiceStateQN, false, IN_SERVICE_TEXT); + setTwoStateVariable(server, condition, fieldOutOfServiceStateQN, false, UA_LOCALIZEDTEXT(LOCALE,IN_SERVICE_TEXT)); UA_NodeId hasComponent = UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT); UA_NodeId place = UA_NODEID_NUMERIC(0, UA_NS0ID_ALARMCONDITIONTYPE_PLACEINSERVICE); @@ -3985,7 +3903,7 @@ setupNonExclusiveLimitAlarmNodes(UA_Server *server, const UA_NodeId *condition, { retval = addOptionalField(server, *condition, typeId, fieldLowLowStateQN, NULL); CONDITION_ASSERT_RETURN_RETVAL(retval, "Adding optional LowLowState Field failed",); - setTwoStateVariable(server, condition, fieldLowLowStateQN, false, INACTIVE_LOWLOW_TEXT); + setTwoStateVariable(server, condition, fieldLowLowStateQN, false, UA_LOCALIZEDTEXT(LOCALE,INACTIVE_LOWLOW_TEXT)); CONDITION_ASSERT_RETURN_RETVAL(retval, "Set LowLowState failed",); } @@ -3993,7 +3911,7 @@ setupNonExclusiveLimitAlarmNodes(UA_Server *server, const UA_NodeId *condition, { retval = addOptionalField(server, *condition, typeId, fieldLowStateQN, NULL); CONDITION_ASSERT_RETURN_RETVAL(retval, "Adding optional LowState Field failed",); - setTwoStateVariable(server, condition, fieldLowStateQN, false, INACTIVE_LOW_TEXT); + setTwoStateVariable(server, condition, fieldLowStateQN, false, UA_LOCALIZEDTEXT(LOCALE,INACTIVE_LOW_TEXT)); CONDITION_ASSERT_RETURN_RETVAL(retval, "Set LowState failed",); } @@ -4001,7 +3919,7 @@ setupNonExclusiveLimitAlarmNodes(UA_Server *server, const UA_NodeId *condition, { retval = addOptionalField(server, *condition, typeId, fieldHighStateQN, NULL); CONDITION_ASSERT_RETURN_RETVAL(retval, "Adding optional HighState Field failed",); - setTwoStateVariable(server, condition, fieldHighStateQN, false, INACTIVE_HIGH_TEXT); + setTwoStateVariable(server, condition, fieldHighStateQN, false, UA_LOCALIZEDTEXT(LOCALE,INACTIVE_HIGH_TEXT)); CONDITION_ASSERT_RETURN_RETVAL(retval, "Set HighState failed",); } @@ -4010,7 +3928,7 @@ setupNonExclusiveLimitAlarmNodes(UA_Server *server, const UA_NodeId *condition, { retval = addOptionalField(server, *condition, typeId, fieldHighHighStateQN, NULL); CONDITION_ASSERT_RETURN_RETVAL(retval, "Adding optional HighHighState Field failed",); - setTwoStateVariable(server, condition, fieldHighHighStateQN, false, INACTIVE_HIGHHIGH_TEXT); + setTwoStateVariable(server, condition, fieldHighHighStateQN, false, UA_LOCALIZEDTEXT(LOCALE,INACTIVE_HIGHHIGH_TEXT)); CONDITION_ASSERT_RETURN_RETVAL(retval, "Set HighHighState failed",); } return retval; @@ -4206,21 +4124,6 @@ void initNs0ConditionAndAlarms (UA_Server *server) } } -UA_StatusCode -UA_Server_Condition_getInputNodeValue (UA_Server *server, UA_NodeId conditionId, UA_Variant *out) -{ - UA_QualifiedName inputNodeQN = UA_QUALIFIEDNAME(0, "InputNode"); - UA_BrowsePathResult bpr = UA_Server_browseSimplifiedBrowsePath(server, conditionId, 1, &inputNodeQN); - if (bpr.statusCode != UA_STATUSCODE_GOOD || bpr.targetsSize != 1) return bpr.statusCode; - UA_Variant sourceNodeId; - UA_StatusCode status = UA_Server_readValue(server, bpr.targets[0].targetId.nodeId, &sourceNodeId); - UA_BrowsePathResult_clear(&bpr); - if (status != UA_STATUSCODE_GOOD || sourceNodeId.type != &UA_TYPES[UA_TYPES_NODEID]) return status; - status = UA_Server_readValue(server, *(UA_NodeId*) sourceNodeId.data, out); - UA_Variant_clear(&sourceNodeId); - return status; -} - void UA_Server_Condition_iterBranches (UA_Server *server, UA_NodeId conditionId, UA_ConditionBranchIterCb iterFn, void *iterCtx) @@ -4585,7 +4488,7 @@ nonExclusiveLimitAlarmSetState (UA_Server *server, const UA_NodeId *conditionId, if (UA_LIMITSTATE_CHECK(prevState, UA_LIMITSTATE_LOWSTATEBIT) != lowStateVal) { ret = setOptionalTwoStateVariable(server, conditionId, fieldLowStateQN, lowStateVal, - lowStateVal ? ACTIVE_LOW_TEXT : INACTIVE_LOW_TEXT); + UA_LOCALIZEDTEXT(LOCALE, lowStateVal ? ACTIVE_LOW_TEXT : INACTIVE_LOW_TEXT)); if (ret != UA_STATUSCODE_GOOD) goto done; } @@ -4593,7 +4496,7 @@ nonExclusiveLimitAlarmSetState (UA_Server *server, const UA_NodeId *conditionId, if (UA_LIMITSTATE_CHECK(prevState, UA_LIMITSTATE_LOWLOWSTATEBIT) != lowLowStateVal) { ret = setOptionalTwoStateVariable(server, conditionId, fieldLowLowStateQN, lowLowStateVal, - lowLowStateVal ? ACTIVE_LOWLOW_TEXT : INACTIVE_LOWLOW_TEXT); + UA_LOCALIZEDTEXT(LOCALE, lowLowStateVal ? ACTIVE_LOWLOW_TEXT : INACTIVE_LOWLOW_TEXT)); if (ret != UA_STATUSCODE_GOOD) goto done; } @@ -4602,7 +4505,7 @@ nonExclusiveLimitAlarmSetState (UA_Server *server, const UA_NodeId *conditionId, if (UA_LIMITSTATE_CHECK(prevState, UA_LIMITSTATE_HIGHSTATEBIT) != highStateVal) { ret = setOptionalTwoStateVariable(server, conditionId, fieldLowStateQN, highStateVal, - highStateVal ? ACTIVE_HIGH_TEXT : INACTIVE_HIGH_TEXT); + UA_LOCALIZEDTEXT(LOCALE, highStateVal ? ACTIVE_HIGH_TEXT : INACTIVE_HIGH_TEXT)); if (ret != UA_STATUSCODE_GOOD) goto done; } @@ -4610,7 +4513,7 @@ nonExclusiveLimitAlarmSetState (UA_Server *server, const UA_NodeId *conditionId, if (UA_LIMITSTATE_CHECK(prevState, UA_LIMITSTATE_HIGHHIGHSTATEBIT) != highHighStateVal) { ret = setOptionalTwoStateVariable(server, conditionId, fieldLowLowStateQN, highHighStateVal, - highHighStateVal ? ACTIVE_HIGHHIGH_TEXT : INACTIVE_HIGHHIGH_TEXT); + UA_LOCALIZEDTEXT(LOCALE, highHighStateVal ? ACTIVE_HIGHHIGH_TEXT : INACTIVE_HIGHHIGH_TEXT)); if (ret != UA_STATUSCODE_GOOD) goto done; } diff --git a/tests/server/check_server_alarmsconditions.c b/tests/server/check_server_alarmsconditions.c index 2e02b375062..fb655067747 100644 --- a/tests/server/check_server_alarmsconditions.c +++ b/tests/server/check_server_alarmsconditions.c @@ -201,11 +201,17 @@ typedef struct UA_Boolean active; }ConditionState; - static UA_StatusCode onAcked(UA_Server *server, const UA_NodeId *id, void *ctx) { UA_Boolean *autoConfirm = (UA_Boolean *)ctx; - if(!*autoConfirm) UA_Server_Condition_setConfirmRequired(server, *id); + if(!*autoConfirm) + { + UA_NodeId confirmedId; + UA_Server_getNodeIdWithBrowseName(server, id, UA_QUALIFIEDNAME(0, "ConfirmedState"), &confirmedId); + UA_Server_writeTwoStateVariable(server, confirmedId, UA_LOCALIZEDTEXT("en", "Unconfirmed"), false); + UA_NodeId_clear (&confirmedId); + + } return UA_STATUSCODE_GOOD; } @@ -220,7 +226,10 @@ static UA_StatusCode onActive(UA_Server *server, const UA_NodeId *id, void *ctx) { UA_Boolean *autoConfirm = (UA_Boolean *)ctx; *autoConfirm = false; - UA_Server_Condition_setAcknowledgeRequired(server, *id); + UA_NodeId ackedId; + UA_Server_getNodeIdWithBrowseName(server, id, UA_QUALIFIEDNAME(0, "AckedState"), &ackedId); + UA_Server_writeTwoStateVariable(server, ackedId, UA_LOCALIZEDTEXT("en", "Unacknowledged"), false); + UA_NodeId_clear (&ackedId); return UA_STATUSCODE_GOOD; }