From cbd5f4368488b67d81303e32b463b185decc5657 Mon Sep 17 00:00:00 2001 From: Tomasz Kazimierz Motyl Date: Wed, 21 Aug 2024 20:36:37 +0100 Subject: [PATCH] Added clauses c) and f) of 13.3.6 (out_of_range) algorithm and enabling transitions from high/low limit states to normal when Event_Enable = 0 for the basic Analog Value and Analog Input objects (#733) --- src/bacnet/basic/object/ai.c | 41 +++++++++++++++++++-------------- src/bacnet/basic/object/av.c | 44 +++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/bacnet/basic/object/ai.c b/src/bacnet/basic/object/ai.c index 09c6db23..24d76df3 100644 --- a/src/bacnet/basic/object/ai.c +++ b/src/bacnet/basic/object/ai.c @@ -995,10 +995,6 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) if (!CurrentAI) { return; } - /* check limits */ - if (!CurrentAI->Limit_Enable) { - return; /* limits are not configured */ - } if (CurrentAI->Ack_notify_data.bSendAckNotify) { /* clean bSendAckNotify flag */ CurrentAI->Ack_notify_data.bSendAckNotify = false; @@ -1065,13 +1061,18 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) the HighLimitEnable flag must be set in the Limit_Enable property, and (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal < - CurrentAI->High_Limit - CurrentAI->Deadband) && - ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == - EVENT_HIGH_LIMIT_ENABLE) && - ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == - EVENT_ENABLE_TO_NORMAL)) { - if (!CurrentAI->Remaining_Time_Delay) + if (((PresentVal < + CurrentAI->High_Limit - CurrentAI->Deadband) && + ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == + EVENT_HIGH_LIMIT_ENABLE) && + ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == + EVENT_ENABLE_TO_NORMAL)) || + /* 13.3.6 (c) If pCurrentState is HIGH_LIMIT, and the + * HighLimitEnable flag of pLimitEnable is FALSE, then + * indicate a transition to the NORMAL event state. */ + (!(CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE))) { + if ((!CurrentAI->Remaining_Time_Delay) || + (!(CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE))) CurrentAI->Event_State = EVENT_STATE_NORMAL; else CurrentAI->Remaining_Time_Delay--; @@ -1090,12 +1091,18 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) set in the Limit_Enable property, and (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal > CurrentAI->Low_Limit + CurrentAI->Deadband) && - ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == - EVENT_LOW_LIMIT_ENABLE) && - ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == - EVENT_ENABLE_TO_NORMAL)) { - if (!CurrentAI->Remaining_Time_Delay) + if (((PresentVal > + CurrentAI->Low_Limit + CurrentAI->Deadband) && + ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == + EVENT_LOW_LIMIT_ENABLE) && + ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == + EVENT_ENABLE_TO_NORMAL)) || + /* 13.3.6 (f) If pCurrentState is LOW_LIMIT, and the + * LowLimitEnable flag of pLimitEnable is FALSE, then + * indicate a transition to the NORMAL event state. */ + (!(CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE))) { + if ((!CurrentAI->Remaining_Time_Delay) || + (!(CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE))) CurrentAI->Event_State = EVENT_STATE_NORMAL; else CurrentAI->Remaining_Time_Delay--; diff --git a/src/bacnet/basic/object/av.c b/src/bacnet/basic/object/av.c index 40f7b7f0..b61af9a9 100644 --- a/src/bacnet/basic/object/av.c +++ b/src/bacnet/basic/object/av.c @@ -1030,10 +1030,6 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) if (!CurrentAV) { return; } - /* check limits */ - if (!CurrentAV->Limit_Enable) { - return; /* limits are not configured */ - } if (CurrentAV->Ack_notify_data.bSendAckNotify) { /* clean bSendAckNotify flag */ CurrentAV->Ack_notify_data.bSendAckNotify = false; @@ -1105,13 +1101,18 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) the HighLimitEnable flag must be set in the Limit_Enable property, and (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal < - CurrentAV->High_Limit - CurrentAV->Deadband) && - ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == - EVENT_HIGH_LIMIT_ENABLE) && - ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == - EVENT_ENABLE_TO_NORMAL)) { - if (!CurrentAV->Remaining_Time_Delay) + if (((PresentVal < + CurrentAV->High_Limit - CurrentAV->Deadband) && + ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == + EVENT_HIGH_LIMIT_ENABLE) && + ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == + EVENT_ENABLE_TO_NORMAL)) || + /* 13.3.6 (c) If pCurrentState is HIGH_LIMIT, and the + * HighLimitEnable flag of pLimitEnable is FALSE, then + * indicate a transition to the NORMAL event state. */ + (!(CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE))) { + if ((!CurrentAV->Remaining_Time_Delay) || + (!(CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE))) CurrentAV->Event_State = EVENT_STATE_NORMAL; else CurrentAV->Remaining_Time_Delay--; @@ -1131,12 +1132,18 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) set in the Limit_Enable property, and (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband) && - ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == - EVENT_LOW_LIMIT_ENABLE) && - ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == - EVENT_ENABLE_TO_NORMAL)) { - if (!CurrentAV->Remaining_Time_Delay) + if (((PresentVal > + CurrentAV->Low_Limit + CurrentAV->Deadband) && + ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == + EVENT_LOW_LIMIT_ENABLE) && + ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == + EVENT_ENABLE_TO_NORMAL)) || + /* 13.3.6 (f) If pCurrentState is LOW_LIMIT, and the + * LowLimitEnable flag of pLimitEnable is FALSE, then + * indicate a transition to the NORMAL event state. */ + (!(CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE))) { + if ((!CurrentAV->Remaining_Time_Delay) || + (!(CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE))) CurrentAV->Event_State = EVENT_STATE_NORMAL; else CurrentAV->Remaining_Time_Delay--; @@ -1184,7 +1191,8 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) ExceededLimit = 0; break; } /* switch (ToState) */ - debug_printf("Event_State for (%s,%u) goes from %s to %s.\n", + debug_printf( + "Event_State for (%s,%u) goes from %s to %s.\n", bactext_object_type_name(Object_Type), (unsigned)object_instance, bactext_event_state_name(FromState), bactext_event_state_name(ToState));