Skip to content

Commit

Permalink
fix reAlarmCount
Browse files Browse the repository at this point in the history
  • Loading branch information
dpazj committed Oct 28, 2024
1 parent 05afed9 commit a9bf80c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 0 additions & 2 deletions examples/tutorial_server_alarms_conditions.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ addExclusiveLimitAlarmCondition (UA_Server *server) {
//.maxTimeShelved = &test,
//.onDelay = &test,
//.offDelay = &test,
//.reAlarmRepeatCount = &repeatCount,
//.reAlarmTime = &reAlarmTime

};

UA_Double highLimit = 20.0f;
Expand Down
2 changes: 0 additions & 2 deletions include/open62541/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 17 additions & 12 deletions src/server/ua_subscription_alarms_conditions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/server/check_server_alarmsconditions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a9bf80c

Please sign in to comment.