From 41c11b23d3b45ec151989f4b1bafca1b39ad6bea Mon Sep 17 00:00:00 2001 From: Steve Karg Date: Wed, 3 Apr 2024 16:57:36 -0500 Subject: [PATCH] Bugfix/basic object features cleanup (#614) * Fixed compile warnings in basic objects * Added API for setting multi state text with null-terminated name lists in basic objects --- src/bacnet/basic/object/ai.c | 2 + src/bacnet/basic/object/av.c | 2 + src/bacnet/basic/object/bi.c | 132 +++++++++++++++++++++++++++++ src/bacnet/basic/object/bv.c | 49 +++++++++++ src/bacnet/basic/object/ms-input.h | 4 + src/bacnet/basic/object/mso.h | 4 + src/bacnet/basic/object/msv.h | 4 + 7 files changed, 197 insertions(+) diff --git a/src/bacnet/basic/object/ai.c b/src/bacnet/basic/object/ai.c index 9b6532de..e8d441f3 100644 --- a/src/bacnet/basic/object/ai.c +++ b/src/bacnet/basic/object/ai.c @@ -78,6 +78,7 @@ static struct analog_input_descr *Analog_Input_Object(uint32_t object_instance) return Keylist_Data(Object_List, object_instance); } +#if defined(INTRINSIC_REPORTING) /** * @brief Gets an object from the list using its index in the list * @param index - index of the object in the list @@ -87,6 +88,7 @@ static struct analog_input_descr *Analog_Input_Object_Index(int index) { return Keylist_Data_Index(Object_List, index); } +#endif /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ diff --git a/src/bacnet/basic/object/av.c b/src/bacnet/basic/object/av.c index 66334db8..06233cc1 100644 --- a/src/bacnet/basic/object/av.c +++ b/src/bacnet/basic/object/av.c @@ -81,6 +81,7 @@ static struct analog_value_descr *Analog_Value_Object(uint32_t object_instance) return Keylist_Data(Object_List, object_instance); } +#if defined(INTRINSIC_REPORTING) /** * @brief Gets an object from the list using its index in the list * @param index - index of the object in the list @@ -90,6 +91,7 @@ static struct analog_value_descr *Analog_Value_Object_Index(int index) { return Keylist_Data_Index(Object_List, index); } +#endif /** * @brief Determines if a given Analog Value instance is valid diff --git a/src/bacnet/basic/object/bi.c b/src/bacnet/basic/object/bi.c index eea3278d..9327409c 100644 --- a/src/bacnet/basic/object/bi.c +++ b/src/bacnet/basic/object/bi.c @@ -221,6 +221,25 @@ void Binary_Input_Out_Of_Service_Set(uint32_t object_instance, bool value) return; } +/** + * @brief For a given object instance-number, returns the reliability property value + * @param object_instance - object-instance number of the object + * @return reliability property value + */ +BACNET_RELIABILITY Binary_Input_Reliability( + uint32_t object_instance) +{ + BACNET_RELIABILITY value = RELIABILITY_NO_FAULT_DETECTED; + struct object_data *pObject; + + pObject = Binary_Input_Object(object_instance); + if (pObject) { + value = pObject->Reliability; + } + + return value; +} + /** * @brief For a given object, gets the Fault status flag * @param object_instance - object-instance number of the object @@ -239,6 +258,36 @@ static bool Binary_Input_Object_Fault(struct object_data *pObject) return fault; } +/** + * For a given object instance-number, sets the reliability + * + * @param object_instance - object-instance number of the object + * @param value - reliability enumerated value + * + * @return true if values are within range and property is set. + */ +bool Binary_Input_Reliability_Set( + uint32_t object_instance, BACNET_RELIABILITY value) +{ + struct object_data *pObject; + bool status = false; + bool fault = false; + + pObject = Keylist_Data(Object_List, object_instance); + if (pObject) { + if (value <= 255) { + fault = Binary_Input_Object_Fault(pObject); + pObject->Reliability = value; + if (fault != Binary_Input_Object_Fault(pObject)) { + pObject->Change_Of_Value = true; + } + status = true; + } + } + + return status; +} + /** * @brief For a given object instance-number, gets the Fault status flag * @param object_instance - object-instance number of the object @@ -534,6 +583,89 @@ bool Binary_Input_Description_Set(uint32_t object_instance, char *new_name) return status; } +/** + * @brief For a given object instance-number, returns the inactive-text property value + * @param object_instance - object-instance number of the object + * @return inactive-text property value + */ +char *Binary_Input_Inactive_Text( + uint32_t object_instance) +{ + char *name = NULL; + struct object_data *pObject; + + pObject = Binary_Input_Object(object_instance); + if (pObject) { + name = (char *)pObject->Inactive_Text; + } + + return name; +} + +/** + * @brief For a given object instance-number, sets the inactive-text property value + * @param object_instance - object-instance number of the object + * @param new_name - holds the inactive-text to be set + * @return true if the inactive-text property value was set + */ +bool Binary_Input_Inactive_Text_Set( + uint32_t object_instance, + char *new_name) +{ + bool status = false; + struct object_data *pObject; + + pObject = Binary_Input_Object(object_instance); + if (pObject) { + pObject->Inactive_Text = new_name; + status = true; + } + + return status; +} + +/** + * @brief For a given object instance-number, returns the active-text property value + * @param object_instance - object-instance number of the object + * @return active-text property value +*/ +char *Binary_Input_Active_Text( + uint32_t object_instance) +{ + char *name = NULL; + struct object_data *pObject; + + pObject = Binary_Input_Object(object_instance); + if (pObject) { + name = (char *)pObject->Active_Text; + } + + return name; + +} + +/** + * @brief For a given object instance-number, sets the active-text property value + * @param object_instance - object-instance number of the object + * @param new_name - holds the active-text to be set + * @return true if the active-text property value was set + */ +bool Binary_Input_Active_Text_Set( + uint32_t object_instance, + char *new_name) +{ + bool status = false; + struct object_data *pObject; + + pObject = Binary_Input_Object(object_instance); + if (pObject) { + pObject->Inactive_Text = new_name; + status = true; + } + + return status; +} + /** * ReadProperty handler for this object. For the given ReadProperty * data, the application_data is loaded or the error flags are set. diff --git a/src/bacnet/basic/object/bv.c b/src/bacnet/basic/object/bv.c index 7384ed9c..c77729b0 100644 --- a/src/bacnet/basic/object/bv.c +++ b/src/bacnet/basic/object/bv.c @@ -221,6 +221,25 @@ void Binary_Value_Out_Of_Service_Set(uint32_t object_instance, bool value) return; } +/** + * @brief For a given object instance-number, returns the reliability property value + * @param object_instance - object-instance number of the object + * @return reliability property value + */ +BACNET_RELIABILITY Binary_Value_Reliability( + uint32_t object_instance) +{ + BACNET_RELIABILITY value = RELIABILITY_NO_FAULT_DETECTED; + struct object_data *pObject; + + pObject = Binary_Value_Object(object_instance); + if (pObject) { + value = pObject->Reliability; + } + + return value; +} + /** * @brief For a given object, gets the Fault status flag * @param object_instance - object-instance number of the object @@ -239,6 +258,36 @@ static bool Binary_Value_Object_Fault(struct object_data *pObject) return fault; } +/** + * For a given object instance-number, sets the reliability + * + * @param object_instance - object-instance number of the object + * @param value - reliability enumerated value + * + * @return true if values are within range and property is set. + */ +bool Binary_Value_Reliability_Set( + uint32_t object_instance, BACNET_RELIABILITY value) +{ + struct object_data *pObject; + bool status = false; + bool fault = false; + + pObject = Keylist_Data(Object_List, object_instance); + if (pObject) { + if (value <= 255) { + fault = Binary_Value_Object_Fault(pObject); + pObject->Reliability = value; + if (fault != Binary_Value_Object_Fault(pObject)) { + pObject->Change_Of_Value = true; + } + status = true; + } + } + + return status; +} + /** * @brief For a given object instance-number, gets the Fault status flag * @param object_instance - object-instance number of the object diff --git a/src/bacnet/basic/object/ms-input.h b/src/bacnet/basic/object/ms-input.h index 57b3302a..4a87dff0 100644 --- a/src/bacnet/basic/object/ms-input.h +++ b/src/bacnet/basic/object/ms-input.h @@ -119,6 +119,10 @@ extern "C" { BACNET_RELIABILITY value); BACNET_STACK_EXPORT + bool Multistate_Input_State_Text_List_Set( + uint32_t object_instance, + const char *state_text_list); + BACNET_STACK_EXPORT bool Multistate_Input_State_Text_Set( uint32_t object_instance, uint32_t state_index, diff --git a/src/bacnet/basic/object/mso.h b/src/bacnet/basic/object/mso.h index 098f0540..20044cd1 100644 --- a/src/bacnet/basic/object/mso.h +++ b/src/bacnet/basic/object/mso.h @@ -139,6 +139,10 @@ extern "C" { char *text_string); BACNET_STACK_EXPORT + bool Multistate_Output_State_Text_List_Set( + uint32_t object_instance, + const char *state_text_list); + BACNET_STACK_EXPORT bool Multistate_Output_State_Text_Set( uint32_t object_instance, uint32_t state_index, diff --git a/src/bacnet/basic/object/msv.h b/src/bacnet/basic/object/msv.h index 25fa63ae..0c4214fc 100644 --- a/src/bacnet/basic/object/msv.h +++ b/src/bacnet/basic/object/msv.h @@ -110,6 +110,10 @@ extern "C" { char *text_string); BACNET_STACK_EXPORT + bool Multistate_Value_State_Text_List_Set( + uint32_t object_instance, + const char *state_text_list); + BACNET_STACK_EXPORT bool Multistate_Value_State_Text_Set( uint32_t object_instance, uint32_t state_index,