bacnet/runtime/bo.c
changeset 2189 49a6738b7c63
parent 2020 6dddf3070806
equal deleted inserted replaced
2186:2ec02f0f9fa9 2189:49a6738b7c63
       
     1 /**************************************************************************
       
     2 *
       
     3 * Copyright (C) 2006 Steve Karg <skarg@users.sourceforge.net>
       
     4 * Copyright (C) 2017 Mario de Sousa <msousa@fe.up.pt>
       
     5 *
       
     6 * Permission is hereby granted, free of charge, to any person obtaining
       
     7 * a copy of this software and associated documentation files (the
       
     8 * "Software"), to deal in the Software without restriction, including
       
     9 * without limitation the rights to use, copy, modify, merge, publish,
       
    10 * distribute, sublicense, and/or sell copies of the Software, and to
       
    11 * permit persons to whom the Software is furnished to do so, subject to
       
    12 * the following conditions:
       
    13 *
       
    14 * The above copyright notice and this permission notice shall be included
       
    15 * in all copies or substantial portions of the Software.
       
    16 *
       
    17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
    20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
       
    21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
       
    22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
       
    23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
       
    24 *
       
    25 *********************************************************************/
       
    26 
       
    27 /* Binary Output Objects - customize for your use */
       
    28 
       
    29 #include <stdbool.h>
       
    30 #include <stdint.h>
       
    31 #include <stdio.h>
       
    32 
       
    33 #include "config_bacnet_for_beremiz_%(locstr)s.h"     /* the custom configuration for beremiz plugin */
       
    34 #include "bacdef.h"
       
    35 #include "bacdcode.h"
       
    36 #include "bacenum.h"
       
    37 #include "bacapp.h"
       
    38 #include "wp.h"
       
    39 #include "rp.h"
       
    40 #include "bo_%(locstr)s.h"
       
    41 #include "handlers.h"
       
    42 
       
    43 /* we choose to have a NULL level in our system represented by */
       
    44 /* a particular value.  When the priorities are not in use, they */
       
    45 /* will be relinquished (i.e. set to the NULL level). */
       
    46 // BINARY_NULL
       
    47 /* test whether value is NULL */
       
    48 #define BINARY_OUTPUT_IS_NULL(x) ((x) == BINARY_NULL)
       
    49 
       
    50 /* When all the priorities are level null, the present value returns
       
    51  * the Relinquish Default value 
       
    52  */
       
    53 #define BO_VALUE_RELINQUISH_DEFAULT BINARY_INACTIVE
       
    54 
       
    55 /* The IEC 61131-3 located variables mapped onto the Binary Output objects of BACnet protocol */
       
    56 %(BO_lvars)s
       
    57 
       
    58 
       
    59 /* The array where we keep all the state related to the Binary Output Objects */
       
    60 #define MAX_BINARY_OUTPUTS %(BO_count)s
       
    61 static BINARY_OUTPUT_DESCR BO_Descr[MAX_BINARY_OUTPUTS] = {
       
    62 %(BO_param)s
       
    63 };
       
    64 
       
    65 
       
    66 
       
    67 
       
    68 /* These three arrays are used by the ReadPropertyMultiple handler,
       
    69  * as well as to initialize the XXX_Property_List used by the 
       
    70  * Property List (PROP_PROPERTY_LIST) property.
       
    71  */
       
    72 static const int Binary_Output_Properties_Required[] = {
       
    73  /* (1) Currently Supported                  */
       
    74  /* (2) Required by standard ASHRAE 135-2016 */
       
    75                                   /*(1)(2)      */
       
    76     PROP_OBJECT_IDENTIFIER,       /* R  R ( 75) */
       
    77     PROP_OBJECT_NAME,             /* R  R ( 77) */
       
    78     PROP_OBJECT_TYPE,             /* R  R ( 79) */
       
    79     PROP_PRESENT_VALUE,           /* W  W ( 85) */
       
    80     PROP_STATUS_FLAGS,            /* R  R (111) */
       
    81     PROP_EVENT_STATE,             /* R  R ( 36) */
       
    82     PROP_OUT_OF_SERVICE,          /* W  R ( 81) */
       
    83     PROP_POLARITY,                /* R  R ( 84) */
       
    84     PROP_PRIORITY_ARRAY,          /* R  R ( 87) */
       
    85     PROP_RELINQUISH_DEFAULT,      /* R  R (104) */
       
    86 //  PROP_PROPERTY_LIST,           /* R  R (371) */
       
    87 //  PROP_CURRENT_COMMAND_PRIORITY,/* R  R (431) */   
       
    88     -1
       
    89 };
       
    90 
       
    91 static const int Binary_Output_Properties_Optional[] = {
       
    92  /* (1) Currently Supported                  */
       
    93  /* (2) Required by standard ASHRAE 135-2016 */
       
    94                               /*(1)(2)      */
       
    95     PROP_DESCRIPTION,         /* R  O ( 28) */
       
    96     -1
       
    97 };
       
    98 
       
    99 static const int Binary_Output_Properties_Proprietary[] = {
       
   100     -1
       
   101 };
       
   102 
       
   103 
       
   104 /* This array stores the PROPERTY_LIST which may be read by clients.
       
   105  * End of list is marked by following the last element with the value '-1'
       
   106  * 
       
   107  * It is initialized by Binary_Output_Init() based off the values
       
   108  * stored in Binary_Output_Properties_Required 
       
   109  *           Binary_Output_Properties_Optional
       
   110  *           Binary_Output_Properties_Proprietary
       
   111  */
       
   112 /* TODO: Allocate memory for this array with malloc() at startup */
       
   113 static int Binary_Output_Properties_List[64];
       
   114 
       
   115 
       
   116 
       
   117 
       
   118 
       
   119 /********************************************************/
       
   120 /**                  Callback functions.               **/
       
   121 /** Functions required by BACnet devie implementation. **/
       
   122 /********************************************************/
       
   123 
       
   124 
       
   125 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   126 void Binary_Output_Property_Lists(
       
   127     const int **pRequired,
       
   128     const int **pOptional,
       
   129     const int **pProprietary)
       
   130 {
       
   131     if (pRequired)
       
   132         *pRequired = Binary_Output_Properties_Required;
       
   133     if (pOptional)
       
   134         *pOptional = Binary_Output_Properties_Optional;
       
   135     if (pProprietary)
       
   136         *pProprietary = Binary_Output_Properties_Proprietary;
       
   137 
       
   138     return;
       
   139 }
       
   140 
       
   141 
       
   142 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   143 void Binary_Output_Init(
       
   144     void)
       
   145 {
       
   146     unsigned i, j;
       
   147     static bool initialized = false;
       
   148 
       
   149     // fprintf(stderr, "BACnet plugin: Binary_Output_Init() called!\n");
       
   150     
       
   151     if (!initialized) {
       
   152         initialized = true;
       
   153 
       
   154         /* initialize the Binary_Output_Properties_List array */
       
   155         int len = 0;
       
   156         len += BACnet_Init_Properties_List(Binary_Output_Properties_List + len,
       
   157                                            Binary_Output_Properties_Required);
       
   158         len += BACnet_Init_Properties_List(Binary_Output_Properties_List + len,
       
   159                                            Binary_Output_Properties_Optional);
       
   160         len += BACnet_Init_Properties_List(Binary_Output_Properties_List + len,
       
   161                                            Binary_Output_Properties_Proprietary);
       
   162 
       
   163         /* initialize all the binary values priority arrays to NULL */
       
   164         for (i = 0; i < MAX_BINARY_OUTPUTS; i++) {
       
   165             for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
       
   166                 BO_Descr[i].Present_Value[j] = BINARY_NULL;
       
   167             }
       
   168         }
       
   169     }
       
   170 
       
   171     return;
       
   172 }
       
   173 
       
   174 
       
   175 
       
   176 /* validate that the given instance (Object ID) exists */
       
   177 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   178 bool Binary_Output_Valid_Instance(
       
   179     uint32_t object_instance)
       
   180 {
       
   181     // fprintf(stderr, "BACnet plugin: Binary_Output_Valid_Instance(obj_ID=%%u) called!\n", object _instance);
       
   182     return (Binary_Output_Instance_To_Index(object_instance) < MAX_BINARY_OUTPUTS);
       
   183 }
       
   184 
       
   185 
       
   186 /* the number of Binary Output Objects */
       
   187 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   188 unsigned Binary_Output_Count(void)   {return MAX_BINARY_OUTPUTS;}
       
   189 
       
   190 
       
   191 /* returns the instance (i.e. Object Identifier) that correlates to the correct index */
       
   192 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   193 uint32_t Binary_Output_Index_To_Instance(unsigned index) {return BO_Descr[index].Object_Identifier;}
       
   194 
       
   195 
       
   196 /* returns the index that correlates to the correct instance number (Object Identifier) */
       
   197 unsigned Binary_Output_Instance_To_Index(
       
   198     uint32_t object_instance)
       
   199 {
       
   200     unsigned index = 0;
       
   201   
       
   202     for (index = 0; index < MAX_BINARY_OUTPUTS; index++)
       
   203         if (object_instance == BO_Descr[index].Object_Identifier)
       
   204             return index;
       
   205 
       
   206     /* error, this object ID is not in our list! */
       
   207     return MAX_BINARY_OUTPUTS;
       
   208 }
       
   209 
       
   210 
       
   211 
       
   212 BACNET_BINARY_PV Binary_Output_Present_Value(
       
   213     uint32_t object_instance)
       
   214 {
       
   215     BACNET_BINARY_PV value = BO_VALUE_RELINQUISH_DEFAULT;
       
   216     unsigned index = 0;
       
   217     unsigned i = 0;
       
   218 
       
   219     // fprintf(stderr, "BACnet plugin: Binary_Output_Present_Value(obj_ID=%%u) called!\n", object_instance);
       
   220 
       
   221     index = Binary_Output_Instance_To_Index(object_instance);
       
   222     if (index < MAX_BINARY_OUTPUTS) {
       
   223         for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
       
   224             if (!BINARY_OUTPUT_IS_NULL(BO_Descr[index].Present_Value[i])) {
       
   225                 value = BO_Descr[index].Present_Value[i];
       
   226                 break;
       
   227             }
       
   228         }
       
   229     }
       
   230 
       
   231     return value;
       
   232 }
       
   233 
       
   234 
       
   235 
       
   236 /* returns command priority (1..16), or 0 if all priority values are at NULL */
       
   237 int Binary_Output_Current_Command_Priority(
       
   238     uint32_t object_instance)
       
   239 {
       
   240     unsigned index = 0;
       
   241     unsigned i = 0;
       
   242 
       
   243     index = Binary_Output_Instance_To_Index(object_instance);
       
   244     if (index < MAX_BINARY_OUTPUTS) {
       
   245         for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
       
   246             if (!BINARY_OUTPUT_IS_NULL(BO_Descr[index].Present_Value[i])) {
       
   247                 return i+1; // +1 since priority is 1..16, and not 0..15
       
   248             }
       
   249         }
       
   250     }
       
   251     // command values in all priorities are set to NULL
       
   252     return 0;
       
   253 }
       
   254 
       
   255 
       
   256 
       
   257 /* note: the object name must be unique within this device */
       
   258 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   259 bool Binary_Output_Object_Name(
       
   260     uint32_t object_instance,
       
   261     BACNET_CHARACTER_STRING * object_name)
       
   262 {
       
   263     bool    status = false;
       
   264     unsigned index = Binary_Output_Instance_To_Index(object_instance);
       
   265 
       
   266     if (index < MAX_BINARY_OUTPUTS)
       
   267         status = characterstring_init_ansi(object_name, BO_Descr[index].Object_Name);
       
   268     
       
   269     return status;
       
   270 }
       
   271 
       
   272 
       
   273 
       
   274 bool Binary_Output_Object_Description(
       
   275     uint32_t object_instance,
       
   276     BACNET_CHARACTER_STRING * object_name)
       
   277 {
       
   278     bool    status = false;
       
   279     unsigned index = Binary_Output_Instance_To_Index(object_instance);
       
   280 
       
   281     if (index < MAX_BINARY_OUTPUTS)
       
   282         status = characterstring_init_ansi(object_name, BO_Descr[index].Description);
       
   283     
       
   284     return status;    
       
   285 }
       
   286 
       
   287 
       
   288 
       
   289 /* return apdu len, or BACNET_STATUS_ERROR on error */
       
   290 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   291 int Binary_Output_Read_Property(
       
   292     BACNET_READ_PROPERTY_DATA * rpdata)
       
   293 {
       
   294     int len = 0;
       
   295     int apdu_len = 0;   /* return value */
       
   296     BACNET_BIT_STRING bit_string;
       
   297     BACNET_CHARACTER_STRING char_string;
       
   298     BACNET_BINARY_PV present_value = BINARY_INACTIVE;
       
   299     unsigned object_index = 0;
       
   300     unsigned i = 0;
       
   301     bool state = false;
       
   302     uint8_t *apdu = NULL;
       
   303 
       
   304     // fprintf(stderr, "BACnet plugin: Binary_Output_Read_Property() called!\n");
       
   305 
       
   306     if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
       
   307         (rpdata->application_data_len == 0)) {
       
   308         return 0;
       
   309     }
       
   310 
       
   311     object_index = Binary_Output_Instance_To_Index(rpdata->object_instance);
       
   312     if (object_index >= MAX_BINARY_OUTPUTS) {
       
   313         rpdata->error_class = ERROR_CLASS_OBJECT;
       
   314         rpdata->error_code  = ERROR_CODE_UNKNOWN_OBJECT;
       
   315         return BACNET_STATUS_ERROR;
       
   316     }
       
   317     
       
   318     apdu = rpdata->application_data;
       
   319     switch (rpdata->object_property) {
       
   320         case PROP_OBJECT_IDENTIFIER:
       
   321             apdu_len =
       
   322                 encode_application_object_id(&apdu[0], OBJECT_BINARY_OUTPUT,
       
   323                 rpdata->object_instance);
       
   324             break;
       
   325         case PROP_OBJECT_NAME:
       
   326             Binary_Output_Object_Name(rpdata->object_instance, &char_string);
       
   327             apdu_len =
       
   328                 encode_application_character_string(&apdu[0], &char_string);
       
   329             break;
       
   330         case PROP_DESCRIPTION:
       
   331             Binary_Output_Object_Description(rpdata->object_instance, &char_string);
       
   332             apdu_len =
       
   333                 encode_application_character_string(&apdu[0], &char_string);
       
   334             break;
       
   335         case PROP_OBJECT_TYPE:
       
   336             apdu_len =
       
   337                 encode_application_enumerated(&apdu[0], OBJECT_BINARY_OUTPUT);
       
   338             break;
       
   339         case PROP_PRESENT_VALUE:
       
   340             present_value =
       
   341                 Binary_Output_Present_Value(rpdata->object_instance);
       
   342             apdu_len = encode_application_enumerated(&apdu[0], present_value);
       
   343             break;
       
   344         case PROP_STATUS_FLAGS:
       
   345             /* note: see the details in the standard on how to use these */
       
   346             bitstring_init(&bit_string);
       
   347             bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false);
       
   348             bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false);
       
   349             bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false);
       
   350             state = BO_Descr[object_index].Out_Of_Service;
       
   351             bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, state);
       
   352             apdu_len = encode_application_bitstring(&apdu[0], &bit_string);
       
   353             break;
       
   354         case PROP_EVENT_STATE:
       
   355             /* note: see the details in the standard on how to use this */
       
   356             apdu_len =
       
   357                 encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
       
   358             break;
       
   359         case PROP_OUT_OF_SERVICE:
       
   360             state = BO_Descr[object_index].Out_Of_Service;
       
   361             apdu_len = encode_application_boolean(&apdu[0], state);
       
   362             break;
       
   363         case PROP_PRIORITY_ARRAY:
       
   364             BACnet_encode_array(BO_Descr[object_index].Present_Value,
       
   365                                 BACNET_MAX_PRIORITY,
       
   366                                 BINARY_OUTPUT_IS_NULL,
       
   367                                 encode_application_enumerated)
       
   368             break;
       
   369 //      case PROP_CURRENT_COMMAND_PRIORITY: {
       
   370 //          unsigned i = Binary_Output_Current_Command_Priority(rpdata->object_instance);
       
   371 //          if (i == 0)  apdu_len = encode_application_null    (&apdu[0]);
       
   372 //          else         apdu_len = encode_application_unsigned(&apdu[0], i);
       
   373 //          break;
       
   374 //      }
       
   375 
       
   376         case PROP_RELINQUISH_DEFAULT:
       
   377             present_value = BO_VALUE_RELINQUISH_DEFAULT;
       
   378             apdu_len = encode_application_enumerated(&apdu[0], present_value);
       
   379             break;
       
   380         case PROP_POLARITY:
       
   381             apdu_len = encode_application_enumerated(&apdu[0],
       
   382                                 BO_Descr[object_index].Polarity);
       
   383             break;
       
   384 //      case PROP_PROPERTY_LIST:
       
   385 //          BACnet_encode_array(Binary_Output_Properties_List,
       
   386 //                              property_list_count(Binary_Output_Properties_List),
       
   387 //                              retfalse, encode_application_enumerated);
       
   388 //          break;
       
   389         default:
       
   390             rpdata->error_class = ERROR_CLASS_PROPERTY;
       
   391             rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
       
   392             apdu_len = BACNET_STATUS_ERROR;
       
   393             break;
       
   394     }
       
   395     /*  only array properties can have array options */
       
   396     if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
       
   397 //      (rpdata->object_property != PROP_PROPERTY_LIST) &&
       
   398         (rpdata->array_index != BACNET_ARRAY_ALL)) {
       
   399         rpdata->error_class = ERROR_CLASS_PROPERTY;
       
   400         rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
       
   401         apdu_len = BACNET_STATUS_ERROR;
       
   402     }
       
   403 
       
   404     return apdu_len;
       
   405 }
       
   406 
       
   407 
       
   408 
       
   409 
       
   410 /* returns true if successful */
       
   411 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   412 bool Binary_Output_Write_Property(
       
   413     BACNET_WRITE_PROPERTY_DATA * wp_data)
       
   414 {
       
   415     bool status = false;        /* return value */
       
   416     unsigned int object_index = 0;
       
   417     unsigned int priority = 0;
       
   418     BACNET_BINARY_PV level = BINARY_NULL;
       
   419     int len = 0;
       
   420     BACNET_APPLICATION_DATA_VALUE value;
       
   421 
       
   422     /* decode the some of the request */
       
   423     len =
       
   424         bacapp_decode_application_data(wp_data->application_data,
       
   425         wp_data->application_data_len, &value);
       
   426     /* FIXME: len < application_data_len: more data? */
       
   427     if (len < 0) {
       
   428         /* error while decoding - a value larger than we can handle */
       
   429         wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   430         wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
       
   431         return false;
       
   432     }
       
   433     /*  only array properties can have array options */
       
   434     if ((wp_data->object_property != PROP_PRIORITY_ARRAY) &&
       
   435         (wp_data->array_index != BACNET_ARRAY_ALL)) {
       
   436         wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   437         wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
       
   438         return false;
       
   439     }
       
   440     /* No need to check whether object_index is within bounds.
       
   441      * Has already been checked before Binary_Output_Write_Property() is called
       
   442      */
       
   443     object_index = Binary_Output_Instance_To_Index(wp_data->object_instance);
       
   444 
       
   445     switch (wp_data->object_property) {
       
   446         case PROP_PRESENT_VALUE:
       
   447             if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
       
   448                 priority = wp_data->priority;
       
   449                 if (priority && (priority <= BACNET_MAX_PRIORITY) &&
       
   450                     (priority != 6 /* reserved */ ) &&
       
   451                     (value.type.Enumerated <= MAX_BINARY_PV)) {
       
   452                     level = (BACNET_BINARY_PV) value.type.Enumerated;
       
   453                     priority--;
       
   454                     BO_Descr[object_index].Present_Value[priority] = level;
       
   455                     status = true;
       
   456                 } else if (priority == 6) {
       
   457                     /* Command priority 6 is reserved for use by Minimum On/Off
       
   458                        algorithm and may not be used for other purposes in any
       
   459                        object. */
       
   460                     wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   461                     wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
       
   462                 } else {
       
   463                     wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   464                     wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
       
   465                 }
       
   466             } else {
       
   467                 status =
       
   468                     WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
       
   469                     &wp_data->error_class, &wp_data->error_code);
       
   470                 if (status) {
       
   471                     level = BINARY_NULL;
       
   472                     priority = wp_data->priority;
       
   473                     if (priority && (priority <= BACNET_MAX_PRIORITY)) {
       
   474                         priority--;
       
   475                         BO_Descr[object_index].Present_Value[priority] = level;
       
   476                     } else {
       
   477                         status = false;
       
   478                         wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   479                         wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
       
   480                     }
       
   481                 }
       
   482             }
       
   483             break;
       
   484         case PROP_OUT_OF_SERVICE:
       
   485         {
       
   486             bool Previous_Out_Of_Service = BO_Descr[object_index].Out_Of_Service;
       
   487             status =
       
   488                 WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
       
   489                 &wp_data->error_class, &wp_data->error_code);
       
   490             if (status) {
       
   491                 BO_Descr[object_index].Out_Of_Service = value.type.Boolean;
       
   492                 if (Previous_Out_Of_Service && !BO_Descr[object_index].Out_Of_Service)
       
   493                     /* We have just changed from Out_of_Service -> In Service */
       
   494                     /* We need to update the Present_Value to the value
       
   495                      * currently in the PLC...
       
   496                      */
       
   497                     BO_Descr[object_index].Present_Value[BACNET_MAX_PRIORITY-1] =
       
   498                                            *(BO_Descr[object_index].Located_Var_ptr);
       
   499             }
       
   500             break;
       
   501         }
       
   502         case PROP_OBJECT_IDENTIFIER:
       
   503         case PROP_OBJECT_NAME:
       
   504         case PROP_DESCRIPTION:
       
   505         case PROP_OBJECT_TYPE:
       
   506         case PROP_STATUS_FLAGS:
       
   507         case PROP_EVENT_STATE:
       
   508         case PROP_PRIORITY_ARRAY:
       
   509 //      case PROP_CURRENT_COMMAND_PRIORITY:
       
   510         case PROP_RELINQUISH_DEFAULT:
       
   511         case PROP_POLARITY:
       
   512 //      case PROP_PROPERTY_LIST:
       
   513             wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   514             wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
       
   515             break;
       
   516         default:
       
   517             wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   518             wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
       
   519             break;
       
   520     }
       
   521 
       
   522     return status;
       
   523 }
       
   524 
       
   525 
       
   526 
       
   527 
       
   528 
       
   529 /********************************************/
       
   530 /** Functions required for Beremiz plugin  **/
       
   531 /********************************************/
       
   532 
       
   533 
       
   534 
       
   535 void  Binary_Output_Copy_Present_Value_to_Located_Var(void) {
       
   536     unsigned i;
       
   537     for (i = 0; i < MAX_BINARY_OUTPUTS; i++) {
       
   538         // decouple PLC's Located Variable from Bacnet Object's Present Value if Out_Of_Service is true
       
   539         if (BO_Descr[i].Out_Of_Service)
       
   540             continue;
       
   541 
       
   542         // copy the value
       
   543         *(BO_Descr[i].Located_Var_ptr) = Binary_Output_Present_Value(BO_Descr[i].Object_Identifier);
       
   544     }
       
   545 }
       
   546   
       
   547 void  Binary_Output_Copy_Located_Var_to_Present_Value(void) {
       
   548     unsigned i;
       
   549     for (i = 0; i < MAX_BINARY_OUTPUTS; i++) {
       
   550         // decouple PLC's Located Variable from Bacnet Object's Present Value if Out_Of_Service is true
       
   551         if (BO_Descr[i].Out_Of_Service)
       
   552             continue;
       
   553 
       
   554         // copy the value
       
   555         BO_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] = *(BO_Descr[i].Located_Var_ptr);
       
   556 
       
   557         // If the Present_Value was set to an invalid value (i.e. > 1, and < BINARY_NULL)
       
   558         //   then we set it to BINARY_ACTIVE 
       
   559         //   (i.e. we assume 0 is FALSE, all other non NULL values are TRUE)
       
   560         if ((BO_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] != BINARY_INACTIVE) &&
       
   561             (BO_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] != BINARY_ACTIVE  ) &&
       
   562             (BO_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] != BINARY_NULL    ))
       
   563              BO_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1]  = BINARY_ACTIVE;          
       
   564     }
       
   565 }
       
   566 
       
   567