From a9bf80ca30b9830c96490fb64a4cbf565cd2dda6 Mon Sep 17 00:00:00 2001 From: dpazj Date: Mon, 28 Oct 2024 09:09:58 +0000 Subject: [PATCH] fix reAlarmCount --- examples/tutorial_server_alarms_conditions.c | 2 -- include/open62541/server.h | 2 -- .../ua_subscription_alarms_conditions.c | 29 +++++++++++-------- tests/server/check_server_alarmsconditions.c | 8 ++--- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/examples/tutorial_server_alarms_conditions.c b/examples/tutorial_server_alarms_conditions.c index 56d2e908547..a8f4f30702b 100644 --- a/examples/tutorial_server_alarms_conditions.c +++ b/examples/tutorial_server_alarms_conditions.c @@ -153,9 +153,7 @@ addExclusiveLimitAlarmCondition (UA_Server *server) { //.maxTimeShelved = &test, //.onDelay = &test, //.offDelay = &test, - //.reAlarmRepeatCount = &repeatCount, //.reAlarmTime = &reAlarmTime - }; UA_Double highLimit = 20.0f; diff --git a/include/open62541/server.h b/include/open62541/server.h index 962e1756878..6b7c82b80bd 100644 --- a/include/open62541/server.h +++ b/include/open62541/server.h @@ -1833,8 +1833,6 @@ typedef struct UA_AlarmConditionProperties UA_Duration offDelay; UA_Boolean hasReAlarmTime; UA_Duration reAlarmTime; - UA_Boolean hasReAlarmRepeatCount; - UA_Int16 reAlarmRepeatCount; } UA_AlarmConditionProperties; UA_StatusCode UA_EXPORT diff --git a/src/server/ua_subscription_alarms_conditions.c b/src/server/ua_subscription_alarms_conditions.c index 5cc1fa61f84..2a25c0a9704 100644 --- a/src/server/ua_subscription_alarms_conditions.c +++ b/src/server/ua_subscription_alarms_conditions.c @@ -1116,6 +1116,14 @@ Condition_State_setActiveState (UA_Server *server, const UA_NodeId * condition, ); } +static inline UA_StatusCode +Condition_State_setReAlarmRepeatCount (UA_Server *server, const UA_NodeId * condition, UA_Int16 count) +{ + UA_Variant val; + UA_Variant_setScalar(&val, &count, &UA_TYPES[UA_TYPES_INT16]); + return setConditionField (server, *condition, &val, fieldReAlarmRepeatCountQN); +} + static inline UA_StatusCode UA_Condition_State_setActiveState (UA_Condition *condition, UA_Server *server, UA_Boolean active) { @@ -2556,13 +2564,6 @@ static void UA_Condition_createReAlarmCallback (UA_Condition *condition, UA_Serv UA_StatusCode retval = UA_Condition_State_getReAlarmTime (condition, server, &reAlarmTime); if (retval != UA_STATUSCODE_GOOD) return; - UA_Int16 repeatCount = 0; - retval = UA_Condition_State_getReAlarmRepeatCount(condition, server, &repeatCount); - if (retval != UA_STATUSCODE_GOOD || condition->reAlarmCount >= repeatCount) - { - return; - } - retval = addTimedCallback( server, reAlarmCallback, @@ -2616,6 +2617,7 @@ static void reAlarmCallback (UA_Server *server, void *data) UA_LOCK(&server->serviceMutex); UA_Condition *condition = (UA_Condition*) data; condition->reAlarmCount++; + Condition_State_setReAlarmRepeatCount (server, &condition->mainBranch->id, condition->reAlarmCount); UA_ConditionEventInfo info = { .message = UA_LOCALIZEDTEXT(LOCALE, REALARM_MESSAGE) }; @@ -2719,8 +2721,12 @@ static void alarmSetInactive(UA_Server *server, UA_Condition *condition, } removeCallback(server, condition->reAlarmCallbackId); - condition->reAlarmCount = 0; + if (condition->reAlarmCount != 0) + { + condition->reAlarmCount = 0; + Condition_State_setReAlarmRepeatCount (server, &condition->mainBranch->id, condition->reAlarmCount); + } UA_Condition_State_setActiveState (condition, server, false); UA_ConditionBranch_evaluateRetainState(condition->mainBranch, server); UA_ConditionBranch_triggerEvent(condition->mainBranch, server, info); @@ -3658,13 +3664,12 @@ setupAlarmConditionNodes (UA_Server *server, const UA_NodeId *condition, UA_Variant_setScalar(&value, (void *) (uintptr_t) &properties->reAlarmTime, &UA_TYPES[UA_TYPES_DURATION]); retval = setConditionField (server, *condition, &value, fieldReAlarmTimeQN); CONDITION_ASSERT_RETURN_RETVAL(retval, "Set ReAlarmTime Field failed",); - } - if (properties->hasReAlarmRepeatCount) - { + retval = addOptionalField(server, *condition, alarmConditionTypeId, fieldReAlarmRepeatCountQN, NULL); CONDITION_ASSERT_RETURN_RETVAL(retval, "Adding ReAlarmRepeatCount optional Field failed",); - UA_Variant_setScalar(&value, (void *) (uintptr_t) &properties->reAlarmRepeatCount, &UA_TYPES[UA_TYPES_INT16]); + UA_Int16 repeatCount = 0; + UA_Variant_setScalar(&value, (void *) (uintptr_t) &repeatCount, &UA_TYPES[UA_TYPES_INT16]); retval = setConditionField (server, *condition, &value, fieldReAlarmRepeatCountQN); CONDITION_ASSERT_RETURN_RETVAL(retval, "Set ReAlarmTimeRepeatCount Field failed",); } diff --git a/tests/server/check_server_alarmsconditions.c b/tests/server/check_server_alarmsconditions.c index ff98743ed92..2e02b375062 100644 --- a/tests/server/check_server_alarmsconditions.c +++ b/tests/server/check_server_alarmsconditions.c @@ -1195,10 +1195,10 @@ int main(void) { #ifdef UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS TCase *tc = tcase_create("Alarms and Conditions"); -// tcase_add_test(tc, createDelete); -// tcase_add_test(tc, createMultiple); -// tcase_add_test(tc, conditionSequence1); -// tcase_add_test(tc, conditionSequence2); + tcase_add_test(tc, createDelete); + tcase_add_test(tc, createMultiple); + tcase_add_test(tc, conditionSequence1); + tcase_add_test(tc, conditionSequence2); tcase_add_test(tc, enableDisable); tcase_add_checked_fixture(tc, setup, teardown); suite_add_tcase(s, tc);