Edouard@2020: /************************************************************************** Edouard@2020: * Edouard@2020: * Copyright (C) 2006 Steve Karg Edouard@2020: * Copyright (C) 2011 Krzysztof Malorny Edouard@2020: * Copyright (C) 2017 Mario de Sousa Edouard@2020: * Edouard@2020: * Permission is hereby granted, free of charge, to any person obtaining Edouard@2020: * a copy of this software and associated documentation files (the Edouard@2020: * "Software"), to deal in the Software without restriction, including Edouard@2020: * without limitation the rights to use, copy, modify, merge, publish, Edouard@2020: * distribute, sublicense, and/or sell copies of the Software, and to Edouard@2020: * permit persons to whom the Software is furnished to do so, subject to Edouard@2020: * the following conditions: Edouard@2020: * Edouard@2020: * The above copyright notice and this permission notice shall be included Edouard@2020: * in all copies or substantial portions of the Software. Edouard@2020: * Edouard@2020: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Edouard@2020: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Edouard@2020: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. Edouard@2020: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY Edouard@2020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, Edouard@2020: * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE Edouard@2020: * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Edouard@2020: * Edouard@2020: *********************************************************************/ Edouard@2020: Edouard@2020: /* Analog Output Objects - customize for your use */ Edouard@2020: Edouard@2020: #include Edouard@2020: #include Edouard@2020: #include Edouard@2020: #include Edouard@2020: #include /* NAN maro */ Edouard@2020: Edouard@2020: #include "config_bacnet_for_beremiz_%(locstr)s.h" /* the custom configuration for beremiz plugin */ Edouard@2020: #include "bacdef.h" Edouard@2020: #include "bacdcode.h" Edouard@2020: #include "bacenum.h" Edouard@2020: #include "bacapp.h" Edouard@2020: #include "bactext.h" Edouard@2020: #include "device_%(locstr)s.h" Edouard@2020: #include "handlers.h" Edouard@2020: #include "ao_%(locstr)s.h" Edouard@2020: Edouard@2020: /* we choose to have a NULL level in our system represented by */ Edouard@2020: /* a particular value. When the priorities are not in use, they */ Edouard@2020: /* will be relinquished (i.e. set to the NULL level). */ Edouard@2020: /* Since the values are floats, we use NAN (Not A Number) as our NULL value. */ Edouard@2020: /* WARNING: Never use comparisons like 'if (value == AO_LEVEL_NULL)' Edouard@2020: * as it will always return false, even if both values are NAN. Edouard@2020: * Use instead the negated version 'if (value != AO_LEVEL_NULL)' Edouard@2020: * and add an 'else' to the 'if' condition if necessary. Edouard@2020: * However, some compilers may screw this up if they do not Edouard@2020: * implement IEEE 754 properly. It is probably best to stick with Edouard@2020: * the isnan() macro if available. Edouard@2020: */ Edouard@2020: #define AO_VALUE_NULL NAN Edouard@2020: #define AO_VALUE_IS_NULL(x) (isnan(x)) Edouard@2020: /* When all the priorities are level null, the present value returns */ Edouard@2020: /* the Relinquish Default value */ Edouard@2020: #define AO_VALUE_RELINQUISH_DEFAULT (0.0) Edouard@2020: Edouard@2020: Edouard@2020: /* The IEC 61131-3 located variables mapped onto the Analog Output objects of BACnet protocol */ Edouard@2020: %(AO_lvars)s Edouard@2020: Edouard@2020: Edouard@2020: /* The array where we keep all the state related to the Analog Output Objects */ Edouard@2020: #define MAX_ANALOG_OUTPUTS %(AO_count)s Edouard@2020: static ANALOG_OUTPUT_DESCR AO_Descr[MAX_ANALOG_OUTPUTS] = { Edouard@2020: %(AO_param)s Edouard@2020: }; Edouard@2020: Edouard@2020: Edouard@2020: /* These three arrays are used by the ReadPropertyMultiple handler, Edouard@2020: * as well as to initialize the XXX_Property_List used by the Edouard@2020: * Property List (PROP_PROPERTY_LIST) property. Edouard@2020: */ Edouard@2020: static const int Analog_Output_Properties_Required[] = { Edouard@2020: /* (1) Currently Supported */ Edouard@2020: /* (2) Required by standard ASHRAE 135-2016 */ Edouard@2020: /*(1)(2) */ Edouard@2020: PROP_OBJECT_IDENTIFIER, /* R R ( 75) */ Edouard@2020: PROP_OBJECT_NAME, /* R R ( 77) */ Edouard@2020: PROP_OBJECT_TYPE, /* R R ( 79) */ Edouard@2020: PROP_PRESENT_VALUE, /* W W ( 85) */ Edouard@2020: PROP_STATUS_FLAGS, /* R R (111) */ Edouard@2020: PROP_EVENT_STATE, /* R R ( 36) */ Edouard@2020: PROP_OUT_OF_SERVICE, /* W R ( 81) */ Edouard@2020: PROP_UNITS, /* W R (117) */ Edouard@2020: PROP_PRIORITY_ARRAY, /* R R ( 87) */ Edouard@2020: PROP_RELINQUISH_DEFAULT, /* R R (104) */ Edouard@2020: // PROP_PROPERTY_LIST, /* R R (371) */ Edouard@2020: // PROP_CURRENT_COMMAND_PRIORITY,/* R R (431) */ Edouard@2020: -1 Edouard@2020: }; Edouard@2020: Edouard@2020: static const int Analog_Output_Properties_Optional[] = { Edouard@2020: /* (1) Currently Supported */ Edouard@2020: /* (2) Required by standard ASHRAE 135-2016 */ Edouard@2020: /*(1)(2) */ Edouard@2020: PROP_DESCRIPTION, /* R O ( 28) */ Edouard@2020: -1 Edouard@2020: }; Edouard@2020: Edouard@2020: static const int Analog_Output_Properties_Proprietary[] = { Edouard@2020: -1 Edouard@2020: }; Edouard@2020: Edouard@2020: /* This array stores the PROPERTY_LIST which may be read by clients. Edouard@2020: * End of list is marked by following the last element with the value '-1' Edouard@2020: * Edouard@2020: * It is initialized by Analog_Outputs_Init() based off the values Edouard@2020: * stored in Analog_Output_Properties_Required Edouard@2020: * Analog_Output_Properties_Optional Edouard@2020: * Analog_Output_Properties_Proprietary Edouard@2020: */ Edouard@2020: /* TODO: Allocate memory for this array with malloc() at startup */ Edouard@2020: static int Analog_Output_Properties_List[64]; Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: /********************************************************/ Edouard@2020: /** Callback functions. **/ Edouard@2020: /** Functions required by BACnet devie implementation. **/ Edouard@2020: /********************************************************/ Edouard@2020: Edouard@2020: Edouard@2020: /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ Edouard@2020: void Analog_Output_Property_Lists( Edouard@2020: const int **pRequired, Edouard@2020: const int **pOptional, Edouard@2020: const int **pProprietary) Edouard@2020: { Edouard@2020: if (pRequired) Edouard@2020: *pRequired = Analog_Output_Properties_Required; Edouard@2020: if (pOptional) Edouard@2020: *pOptional = Analog_Output_Properties_Optional; Edouard@2020: if (pProprietary) Edouard@2020: *pProprietary = Analog_Output_Properties_Proprietary; Edouard@2020: Edouard@2020: return; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ Edouard@2020: void Analog_Output_Init( Edouard@2020: void) Edouard@2020: { Edouard@2020: unsigned i, j; Edouard@2020: static bool initialized = false; Edouard@2020: Edouard@2020: if (!initialized) { Edouard@2020: initialized = true; Edouard@2020: Edouard@2020: /* initialize the Analog_Output_Properties_List array */ Edouard@2020: int len = 0; Edouard@2020: len += BACnet_Init_Properties_List(Analog_Output_Properties_List + len, Edouard@2020: Analog_Output_Properties_Required); Edouard@2020: len += BACnet_Init_Properties_List(Analog_Output_Properties_List + len, Edouard@2020: Analog_Output_Properties_Optional); Edouard@2020: len += BACnet_Init_Properties_List(Analog_Output_Properties_List + len, Edouard@2020: Analog_Output_Properties_Proprietary); Edouard@2020: Edouard@2020: for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) { Edouard@2020: // MJS: the following line in th original demo code was commented out so we do not Edouard@2020: // overwrite the initial values configured by the user in beremiz IDE Edouard@2020: // memset(&AO_Descr[i], 0x00, sizeof(ANALOG_OUTPUT_DESCR)); Edouard@2020: for (j = 0; j < BACNET_MAX_PRIORITY; j++) { Edouard@2020: AO_Descr[i].Present_Value[j] = AO_VALUE_NULL; Edouard@2020: } Edouard@2020: AO_Descr[i].Out_Of_Service = 0; Edouard@2020: AO_Descr[i].Event_State = 0; Edouard@2020: // AO_Descr[i].Units = UNITS_NO_UNITS; Edouard@2020: } Edouard@2020: } Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: /* validate that the given instance exists */ Edouard@2020: /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ Edouard@2020: bool Analog_Output_Valid_Instance( Edouard@2020: uint32_t object_instance) Edouard@2020: { Edouard@2020: return (Analog_Output_Instance_To_Index(object_instance) < MAX_ANALOG_OUTPUTS); Edouard@2020: } Edouard@2020: Edouard@2020: /* the number of Analog Output Objects */ Edouard@2020: /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ Edouard@2020: unsigned Analog_Output_Count(void) {return MAX_ANALOG_OUTPUTS;} Edouard@2020: Edouard@2020: Edouard@2020: /* returns the instance (i.e. Object Identifier) that correlates to the correct index */ Edouard@2020: /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ Edouard@2020: uint32_t Analog_Output_Index_To_Instance(unsigned index) {return AO_Descr[index].Object_Identifier;} Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: /* returns the index that correlates to the correct instance number (Object Identifier) */ Edouard@2020: unsigned Analog_Output_Instance_To_Index( Edouard@2020: uint32_t object_instance) Edouard@2020: { Edouard@2020: unsigned index = 0; Edouard@2020: Edouard@2020: for (index = 0; index < MAX_ANALOG_OUTPUTS; index++) Edouard@2020: if (object_instance == AO_Descr[index].Object_Identifier) Edouard@2020: return index; Edouard@2020: Edouard@2020: /* error, this object ID is not in our list! */ Edouard@2020: return MAX_ANALOG_OUTPUTS; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: float Analog_Output_Present_Value( Edouard@2020: uint32_t object_instance) Edouard@2020: { Edouard@2020: float value = AO_VALUE_RELINQUISH_DEFAULT; Edouard@2020: unsigned index = 0; Edouard@2020: unsigned i = 0; Edouard@2020: Edouard@2020: index = Analog_Output_Instance_To_Index(object_instance); Edouard@2020: if (index < MAX_ANALOG_OUTPUTS) { Edouard@2020: for (i = 0; i < BACNET_MAX_PRIORITY; i++) { Edouard@2020: if (!AO_VALUE_IS_NULL(AO_Descr[index].Present_Value[i])) { Edouard@2020: value = AO_Descr[index].Present_Value[i]; Edouard@2020: break; Edouard@2020: } Edouard@2020: } Edouard@2020: } Edouard@2020: Edouard@2020: return value; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: /* returns command priority (1..16), or 0 if all priority values are at NULL */ Edouard@2020: int Analog_Output_Current_Command_Priority( Edouard@2020: uint32_t object_instance) Edouard@2020: { Edouard@2020: unsigned index = 0; Edouard@2020: unsigned i = 0; Edouard@2020: Edouard@2020: index = Analog_Output_Instance_To_Index(object_instance); Edouard@2020: if (index < MAX_ANALOG_OUTPUTS) { Edouard@2020: for (i = 0; i < BACNET_MAX_PRIORITY; i++) { Edouard@2020: if (!AO_VALUE_IS_NULL(AO_Descr[index].Present_Value[i])) { Edouard@2020: return i+1; // +1 since priority is 1..16, and not 0..15 Edouard@2020: } Edouard@2020: } Edouard@2020: } Edouard@2020: // command values in all priorities are set to NULL Edouard@2020: return 0; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: /* For a given object instance-number, sets the present-value at a given Edouard@2020: * priority 1..16 (except 6, see ASHRAE 135-2016, section 19.2.2) Edouard@2020: */ Edouard@2020: bool Analog_Output_Present_Value_Set( Edouard@2020: uint32_t object_instance, Edouard@2020: float value, Edouard@2020: uint8_t priority) Edouard@2020: { Edouard@2020: unsigned index = 0; Edouard@2020: Edouard@2020: index = Analog_Output_Instance_To_Index(object_instance); Edouard@2020: if (index >= MAX_ANALOG_OUTPUTS) Edouard@2020: return false; Edouard@2020: if ((priority == 0) || (priority > BACNET_MAX_PRIORITY) || Edouard@2020: (priority == 6 /* reserved, ASHRAE 135-2016, section 19.2.2 */)) Edouard@2020: return false; Edouard@2020: Edouard@2020: priority--; Edouard@2020: AO_Descr[index].Present_Value[priority] = value; Edouard@2020: return true; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: bool Analog_Output_Present_Value_Relinquish( Edouard@2020: uint32_t object_instance, Edouard@2020: unsigned priority) Edouard@2020: { Edouard@2020: unsigned index = 0; Edouard@2020: Edouard@2020: index = Analog_Output_Instance_To_Index(object_instance); Edouard@2020: if (index >= MAX_ANALOG_OUTPUTS) Edouard@2020: return false; Edouard@2020: Edouard@2020: if ((priority == 0) || (priority > BACNET_MAX_PRIORITY) || Edouard@2020: (priority == 6 /* reserved, ASHRAE 135-2016, section 19.2.2 */)) Edouard@2020: return false; Edouard@2020: Edouard@2020: priority--; Edouard@2020: AO_Descr[index].Present_Value[priority] = AO_VALUE_NULL; Edouard@2020: return true; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: /* note: the object name must be unique within this device */ Edouard@2020: /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ Edouard@2020: bool Analog_Output_Object_Name( Edouard@2020: uint32_t object_instance, Edouard@2020: BACNET_CHARACTER_STRING * object_name) Edouard@2020: { Edouard@2020: bool status = false; Edouard@2020: unsigned index = Analog_Output_Instance_To_Index(object_instance); Edouard@2020: Edouard@2020: if (index < MAX_ANALOG_OUTPUTS) Edouard@2020: status = characterstring_init_ansi(object_name, AO_Descr[index].Object_Name); Edouard@2020: Edouard@2020: return status; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: bool Analog_Output_Object_Description( Edouard@2020: uint32_t object_instance, Edouard@2020: BACNET_CHARACTER_STRING * object_name) Edouard@2020: { Edouard@2020: bool status = false; Edouard@2020: unsigned index = Analog_Output_Instance_To_Index(object_instance); Edouard@2020: Edouard@2020: if (index < MAX_ANALOG_OUTPUTS) Edouard@2020: status = characterstring_init_ansi(object_name, AO_Descr[index].Description); Edouard@2020: Edouard@2020: return status; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: /* return apdu len, or BACNET_STATUS_ERROR on error */ Edouard@2020: /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ Edouard@2020: int Analog_Output_Read_Property( Edouard@2020: BACNET_READ_PROPERTY_DATA * rpdata) Edouard@2020: { Edouard@2020: int apdu_len = 0; /* return value */ Edouard@2020: BACNET_BIT_STRING bit_string; Edouard@2020: BACNET_CHARACTER_STRING char_string; Edouard@2020: float real_value = (float) 1.414; Edouard@2020: unsigned object_index = 0; Edouard@2020: bool state = false; Edouard@2020: uint8_t *apdu = NULL; Edouard@2020: Edouard@2020: if ((rpdata == NULL) || (rpdata->application_data == NULL) || Edouard@2020: (rpdata->application_data_len == 0)) { Edouard@2020: return 0; Edouard@2020: } Edouard@2020: Edouard@2020: apdu = rpdata->application_data; Edouard@2020: Edouard@2020: object_index = Analog_Output_Instance_To_Index(rpdata->object_instance); Edouard@2020: if (object_index >= MAX_ANALOG_OUTPUTS) { Edouard@2020: rpdata->error_class = ERROR_CLASS_OBJECT; Edouard@2020: rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; Edouard@2020: return BACNET_STATUS_ERROR; Edouard@2020: } Edouard@2020: Edouard@2020: switch (rpdata->object_property) { Edouard@2020: case PROP_OBJECT_IDENTIFIER: Edouard@2020: apdu_len = Edouard@2020: encode_application_object_id(&apdu[0], OBJECT_ANALOG_OUTPUT, Edouard@2020: rpdata->object_instance); Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_OBJECT_NAME: Edouard@2020: Analog_Output_Object_Name(rpdata->object_instance, &char_string); Edouard@2020: apdu_len = Edouard@2020: encode_application_character_string(&apdu[0], &char_string); Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_DESCRIPTION: Edouard@2020: Analog_Output_Object_Description(rpdata->object_instance, &char_string); Edouard@2020: apdu_len = Edouard@2020: encode_application_character_string(&apdu[0], &char_string); Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_OBJECT_TYPE: Edouard@2020: apdu_len = Edouard@2020: encode_application_enumerated(&apdu[0], OBJECT_ANALOG_OUTPUT); Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_PRESENT_VALUE: Edouard@2020: real_value = Analog_Output_Present_Value(rpdata->object_instance); Edouard@2020: apdu_len = encode_application_real(&apdu[0], real_value); Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_STATUS_FLAGS: Edouard@2020: bitstring_init(&bit_string); Edouard@2020: bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); Edouard@2020: bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); Edouard@2020: bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); Edouard@2020: bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, Edouard@2020: AO_Descr[object_index].Out_Of_Service); Edouard@2020: Edouard@2020: apdu_len = encode_application_bitstring(&apdu[0], &bit_string); Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_EVENT_STATE: Edouard@2020: apdu_len = Edouard@2020: encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_OUT_OF_SERVICE: Edouard@2020: state = AO_Descr[object_index].Out_Of_Service; Edouard@2020: apdu_len = encode_application_boolean(&apdu[0], state); Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_PRIORITY_ARRAY: Edouard@2020: BACnet_encode_array(AO_Descr[object_index].Present_Value, Edouard@2020: BACNET_MAX_PRIORITY, Edouard@2020: AO_VALUE_IS_NULL, Edouard@2020: encode_application_real) Edouard@2020: break; Edouard@2020: Edouard@2020: // case PROP_CURRENT_COMMAND_PRIORITY: { Edouard@2020: // unsigned i = Analog_Output_Current_Command_Priority(rpdata->object_instance); Edouard@2020: // if (i == 0) apdu_len = encode_application_null (&apdu[0]); Edouard@2020: // else apdu_len = encode_application_unsigned(&apdu[0], i); Edouard@2020: // break; Edouard@2020: // } Edouard@2020: Edouard@2020: case PROP_RELINQUISH_DEFAULT: Edouard@2020: real_value = AO_VALUE_RELINQUISH_DEFAULT; Edouard@2020: apdu_len = encode_application_real(&apdu[0], real_value); Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_UNITS: Edouard@2020: apdu_len = Edouard@2020: encode_application_enumerated(&apdu[0], AO_Descr[object_index].Units); Edouard@2020: break; Edouard@2020: Edouard@2020: // case PROP_PROPERTY_LIST: Edouard@2020: // BACnet_encode_array(Analog_Output_Properties_List, Edouard@2020: // property_list_count(Analog_Output_Properties_List), Edouard@2020: // retfalse, encode_application_enumerated); Edouard@2020: // break; Edouard@2020: default: Edouard@2020: rpdata->error_class = ERROR_CLASS_PROPERTY; Edouard@2020: rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; Edouard@2020: apdu_len = BACNET_STATUS_ERROR; Edouard@2020: break; Edouard@2020: } Edouard@2020: /* only array properties can have array options */ Edouard@2020: if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) && Edouard@2020: (rpdata->object_property != PROP_EVENT_TIME_STAMPS) && Edouard@2020: // (rpdata->object_property != PROP_PROPERTY_LIST) && Edouard@2020: (rpdata->array_index != BACNET_ARRAY_ALL)) { Edouard@2020: rpdata->error_class = ERROR_CLASS_PROPERTY; Edouard@2020: rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; Edouard@2020: apdu_len = BACNET_STATUS_ERROR; Edouard@2020: } Edouard@2020: Edouard@2020: return apdu_len; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: /* returns true if successful */ Edouard@2020: /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c, */ Edouard@2020: bool Analog_Output_Write_Property( Edouard@2020: BACNET_WRITE_PROPERTY_DATA * wp_data) Edouard@2020: { Edouard@2020: bool status = false; /* return value */ Edouard@2020: unsigned int object_index = 0; Edouard@2020: int len = 0; Edouard@2020: BACNET_APPLICATION_DATA_VALUE value; Edouard@2020: ANALOG_OUTPUT_DESCR *CurrentAO; Edouard@2020: Edouard@2020: /* decode the some of the request */ Edouard@2020: len = Edouard@2020: bacapp_decode_application_data(wp_data->application_data, Edouard@2020: wp_data->application_data_len, &value); Edouard@2020: /* FIXME: len < application_data_len: more data? */ Edouard@2020: if (len < 0) { Edouard@2020: /* error while decoding - a value larger than we can handle */ Edouard@2020: wp_data->error_class = ERROR_CLASS_PROPERTY; Edouard@2020: wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; Edouard@2020: return false; Edouard@2020: } Edouard@2020: if ((wp_data->object_property != PROP_PRIORITY_ARRAY) && Edouard@2020: (wp_data->object_property != PROP_EVENT_TIME_STAMPS) && Edouard@2020: (wp_data->array_index != BACNET_ARRAY_ALL)) { Edouard@2020: /* only array properties can have array options */ Edouard@2020: wp_data->error_class = ERROR_CLASS_PROPERTY; Edouard@2020: wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; Edouard@2020: return false; Edouard@2020: } Edouard@2020: object_index = Analog_Output_Instance_To_Index(wp_data->object_instance); Edouard@2020: if (object_index < MAX_ANALOG_OUTPUTS) Edouard@2020: CurrentAO = &AO_Descr[object_index]; Edouard@2020: else Edouard@2020: return false; Edouard@2020: Edouard@2020: switch (wp_data->object_property) { Edouard@2020: case PROP_PRESENT_VALUE: Edouard@2020: if (value.tag == BACNET_APPLICATION_TAG_REAL) { Edouard@2020: if (Analog_Output_Present_Value_Set(wp_data->object_instance, Edouard@2020: value.type.Real, wp_data->priority)) { Edouard@2020: status = true; Edouard@2020: } else if (wp_data->priority == 6) { Edouard@2020: /* Command priority 6 is reserved for use by Minimum On/Off Edouard@2020: algorithm and may not be used for other purposes in any Edouard@2020: object. */ Edouard@2020: wp_data->error_class = ERROR_CLASS_PROPERTY; Edouard@2020: wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; Edouard@2020: } else { Edouard@2020: wp_data->error_class = ERROR_CLASS_PROPERTY; Edouard@2020: wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; Edouard@2020: } Edouard@2020: } else { Edouard@2020: status = Edouard@2020: WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, Edouard@2020: &wp_data->error_class, &wp_data->error_code); Edouard@2020: if (status) { Edouard@2020: status = Edouard@2020: Analog_Output_Present_Value_Relinquish Edouard@2020: (wp_data->object_instance, wp_data->priority); Edouard@2020: } Edouard@2020: if (!status) { Edouard@2020: wp_data->error_class = ERROR_CLASS_PROPERTY; Edouard@2020: wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; Edouard@2020: } Edouard@2020: } Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_OUT_OF_SERVICE: Edouard@2020: { Edouard@2020: bool Previous_Out_Of_Service = CurrentAO->Out_Of_Service; Edouard@2020: status = Edouard@2020: WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, Edouard@2020: &wp_data->error_class, &wp_data->error_code); Edouard@2020: if (status) { Edouard@2020: CurrentAO->Out_Of_Service = value.type.Boolean; Edouard@2020: if (Previous_Out_Of_Service && !CurrentAO->Out_Of_Service) Edouard@2020: /* We have just changed from Out_of_Service -> In Service */ Edouard@2020: /* We need to update the Present_Value to the value Edouard@2020: * currently in the PLC... Edouard@2020: */ Edouard@2020: CurrentAO->Present_Value[BACNET_MAX_PRIORITY-1] = Edouard@2020: *(CurrentAO->Located_Var_ptr); Edouard@2020: } Edouard@2020: break; Edouard@2020: } Edouard@2020: Edouard@2020: case PROP_UNITS: Edouard@2020: status = Edouard@2020: WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, Edouard@2020: &wp_data->error_class, &wp_data->error_code); Edouard@2020: if (status) { Edouard@2020: CurrentAO->Units = value.type.Enumerated; Edouard@2020: } Edouard@2020: break; Edouard@2020: Edouard@2020: case PROP_OBJECT_IDENTIFIER: Edouard@2020: case PROP_OBJECT_NAME: Edouard@2020: case PROP_OBJECT_TYPE: Edouard@2020: case PROP_STATUS_FLAGS: Edouard@2020: case PROP_EVENT_STATE: Edouard@2020: case PROP_DESCRIPTION: Edouard@2020: case PROP_RELINQUISH_DEFAULT: Edouard@2020: case PROP_PRIORITY_ARRAY: Edouard@2020: // case PROP_PROPERTY_LIST: Edouard@2020: // case PROP_CURRENT_COMMAND_PRIORITY: Edouard@2020: wp_data->error_class = ERROR_CLASS_PROPERTY; Edouard@2020: wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; Edouard@2020: break; Edouard@2020: default: Edouard@2020: wp_data->error_class = ERROR_CLASS_PROPERTY; Edouard@2020: wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY; Edouard@2020: break; Edouard@2020: } Edouard@2020: Edouard@2020: return status; Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: /********************************************/ Edouard@2020: /** Functions required for Beremiz plugin **/ Edouard@2020: /********************************************/ Edouard@2020: Edouard@2020: void Analog_Output_Copy_Present_Value_to_Located_Var(void) { Edouard@2020: unsigned i; Edouard@2020: for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) { Edouard@2020: // decouple PLC's Located Variable from Bacnet Object's Present Value if Out_Of_Service is true Edouard@2020: if (AO_Descr[i].Out_Of_Service) Edouard@2020: continue; Edouard@2020: Edouard@2020: // copy the value Edouard@2020: *(AO_Descr[i].Located_Var_ptr) = Analog_Output_Present_Value(AO_Descr[i].Object_Identifier); Edouard@2020: } Edouard@2020: } Edouard@2020: Edouard@2020: Edouard@2020: Edouard@2020: void Analog_Output_Copy_Located_Var_to_Present_Value(void) { Edouard@2020: unsigned i; Edouard@2020: for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) { Edouard@2020: // decouple PLC's Located Variable from Bacnet Object's Present Value if Out_Of_Service is true Edouard@2020: if (AO_Descr[i].Out_Of_Service) Edouard@2020: continue; Edouard@2020: Edouard@2020: // copy the value Edouard@2020: AO_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] = *(AO_Descr[i].Located_Var_ptr); Edouard@2020: } Edouard@2020: } Edouard@2020: