bacnet/runtime/bv.c
changeset 2020 6dddf3070806
equal deleted inserted replaced
2019:92f02bb17c7e 2020:6dddf3070806
       
     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 Value 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 "bv_%(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_VALUE_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 BV_VALUE_RELINQUISH_DEFAULT BINARY_INACTIVE
       
    54 
       
    55 /* The IEC 61131-3 located variables mapped onto the Binary Value objects of BACnet protocol */
       
    56 %(BV_lvars)s
       
    57 
       
    58 
       
    59 /* The array where we keep all the state related to the Binary Value Objects */
       
    60 #define MAX_BINARY_VALUES %(BV_count)s
       
    61 static BINARY_VALUE_DESCR BV_Descr[MAX_BINARY_VALUES] = {
       
    62 %(BV_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_Value_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  R ( 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_PROPERTY_LIST,       /* R  R (371) */
       
    84     -1
       
    85 };
       
    86 
       
    87 static const int Binary_Value_Properties_Optional[] = {
       
    88  /* (1) Currently Supported                  */
       
    89  /* (2) Required by standard ASHRAE 135-2016 */
       
    90                                   /*(1)(2)      */
       
    91     PROP_DESCRIPTION,             /* R  O ( 28) */
       
    92     /* required if Present_Value is writable (which is true in our case!) */
       
    93     PROP_PRIORITY_ARRAY,          /* R  O ( 87) */
       
    94     PROP_RELINQUISH_DEFAULT,      /* R  O (104) */
       
    95 //  PROP_CURRENT_COMMAND_PRIORITY,/* R  O (431) */   
       
    96     -1
       
    97 };
       
    98 
       
    99 static const int Binary_Value_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_Value_Init() based off the values
       
   108  * stored in Binary_Value_Properties_Required 
       
   109  *           Binary_Value_Properties_Optional
       
   110  *           Binary_Value_Properties_Proprietary
       
   111  */
       
   112 /* TODO: Allocate memory for this array with malloc() at startup */
       
   113 static int Binary_Value_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_Value_Property_Lists(
       
   127     const int **pRequired,
       
   128     const int **pOptional,
       
   129     const int **pProprietary)
       
   130 {
       
   131     if (pRequired)
       
   132         *pRequired = Binary_Value_Properties_Required;
       
   133     if (pOptional)
       
   134         *pOptional = Binary_Value_Properties_Optional;
       
   135     if (pProprietary)
       
   136         *pProprietary = Binary_Value_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_Value_Init(
       
   144     void)
       
   145 {
       
   146     unsigned i, j;
       
   147     static bool initialized = false;
       
   148 
       
   149     // fprintf(stderr, "BACnet plugin: Binary_Value_Init() called!\n");
       
   150     
       
   151     if (!initialized) {
       
   152         initialized = true;
       
   153 
       
   154         /* initialize the Binary_Value_Properties_List array */
       
   155         int len = 0;
       
   156         len += BACnet_Init_Properties_List(Binary_Value_Properties_List + len,
       
   157                                            Binary_Value_Properties_Required);
       
   158         len += BACnet_Init_Properties_List(Binary_Value_Properties_List + len,
       
   159                                            Binary_Value_Properties_Optional);
       
   160         len += BACnet_Init_Properties_List(Binary_Value_Properties_List + len,
       
   161                                            Binary_Value_Properties_Proprietary);
       
   162 
       
   163         /* initialize all the binary values priority arrays to NULL */
       
   164         for (i = 0; i < MAX_BINARY_VALUES; i++) {
       
   165             for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
       
   166                 BV_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_Value_Valid_Instance(
       
   179     uint32_t object_instance)
       
   180 {
       
   181     // fprintf(stderr, "BACnet plugin: Binary_Value_Valid_Instance(obj_ID=%%u) called!\n", object _instance);
       
   182     return (Binary_Value_Instance_To_Index(object_instance) < MAX_BINARY_VALUES);
       
   183 }
       
   184 
       
   185 
       
   186 /* the number of Binary Value Objects */
       
   187 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   188 unsigned Binary_Value_Count(void)   {return MAX_BINARY_VALUES;}
       
   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_Value_Index_To_Instance(unsigned index) {return BV_Descr[index].Object_Identifier;}
       
   194 
       
   195 
       
   196 /* returns the index that correlates to the correct instance number (Object Identifier) */
       
   197 unsigned Binary_Value_Instance_To_Index(
       
   198     uint32_t object_instance)
       
   199 {
       
   200     unsigned index = 0;
       
   201   
       
   202     for (index = 0; index < MAX_BINARY_VALUES; index++)
       
   203         if (object_instance == BV_Descr[index].Object_Identifier)
       
   204             return index;
       
   205 
       
   206     /* error, this object ID is not in our list! */
       
   207     return MAX_BINARY_VALUES;
       
   208 }
       
   209 
       
   210 
       
   211 
       
   212 BACNET_BINARY_PV Binary_Value_Present_Value(
       
   213     uint32_t object_instance)
       
   214 {
       
   215     BACNET_BINARY_PV value = BV_VALUE_RELINQUISH_DEFAULT;
       
   216     unsigned index = 0;
       
   217     unsigned i = 0;
       
   218 
       
   219     // fprintf(stderr, "BACnet plugin: Binary_Value_Present_Value(obj_ID=%%u) called!\n", object_instance);
       
   220 
       
   221     index = Binary_Value_Instance_To_Index(object_instance);
       
   222     if (index < MAX_BINARY_VALUES) {
       
   223         for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
       
   224             if (!BINARY_VALUE_IS_NULL(BV_Descr[index].Present_Value[i])) {
       
   225                 value = BV_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_Value_Current_Command_Priority(
       
   238     uint32_t object_instance)
       
   239 {
       
   240     unsigned index = 0;
       
   241     unsigned i = 0;
       
   242 
       
   243     index = Binary_Value_Instance_To_Index(object_instance);
       
   244     if (index < MAX_BINARY_VALUES) {
       
   245         for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
       
   246             if (!BINARY_VALUE_IS_NULL(BV_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_Value_Object_Name(
       
   260     uint32_t object_instance,
       
   261     BACNET_CHARACTER_STRING * object_name)
       
   262 {
       
   263     bool    status = false;
       
   264     unsigned index = Binary_Value_Instance_To_Index(object_instance);
       
   265 
       
   266     if (index < MAX_BINARY_VALUES)
       
   267         status = characterstring_init_ansi(object_name, BV_Descr[index].Object_Name);
       
   268     
       
   269     return status;
       
   270 }
       
   271 
       
   272 
       
   273 
       
   274 bool Binary_Value_Object_Description(
       
   275     uint32_t object_instance,
       
   276     BACNET_CHARACTER_STRING * object_name)
       
   277 {
       
   278     bool    status = false;
       
   279     unsigned index = Binary_Value_Instance_To_Index(object_instance);
       
   280 
       
   281     if (index < MAX_BINARY_VALUES)
       
   282         status = characterstring_init_ansi(object_name, BV_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_Value_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_Value_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_Value_Instance_To_Index(rpdata->object_instance);
       
   312     if (object_index >= MAX_BINARY_VALUES) {
       
   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_VALUE,
       
   323                 rpdata->object_instance);
       
   324             break;
       
   325         case PROP_OBJECT_NAME:
       
   326             Binary_Value_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_Value_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_VALUE);
       
   338             break;
       
   339         case PROP_PRESENT_VALUE:
       
   340             present_value =
       
   341                 Binary_Value_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 = BV_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 = BV_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(BV_Descr[object_index].Present_Value,
       
   365                                 BACNET_MAX_PRIORITY,
       
   366                                 BINARY_VALUE_IS_NULL,
       
   367                                 encode_application_enumerated)
       
   368             break;
       
   369 //      case PROP_CURRENT_COMMAND_PRIORITY: {
       
   370 //          unsigned i = Binary_Value_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 = BV_VALUE_RELINQUISH_DEFAULT;
       
   378             apdu_len = encode_application_enumerated(&apdu[0], present_value);
       
   379             break;
       
   380 //      case PROP_PROPERTY_LIST:
       
   381 //          BACnet_encode_array(Binary_Value_Properties_List,
       
   382 //                              property_list_count(Binary_Value_Properties_List),
       
   383 //                              retfalse, encode_application_enumerated);
       
   384 //          break;
       
   385         default:
       
   386             rpdata->error_class = ERROR_CLASS_PROPERTY;
       
   387             rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
       
   388             apdu_len = BACNET_STATUS_ERROR;
       
   389             break;
       
   390     }
       
   391     /*  only array properties can have array options */
       
   392     if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
       
   393 //      (rpdata->object_property != PROP_PROPERTY_LIST) &&
       
   394         (rpdata->array_index != BACNET_ARRAY_ALL)) {
       
   395         rpdata->error_class = ERROR_CLASS_PROPERTY;
       
   396         rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
       
   397         apdu_len = BACNET_STATUS_ERROR;
       
   398     }
       
   399 
       
   400     return apdu_len;
       
   401 }
       
   402 
       
   403 
       
   404 
       
   405 
       
   406 /* returns true if successful */
       
   407 /* This is a callback function. Callback set in My_Object_Table[] array declared in device.c,  */
       
   408 bool Binary_Value_Write_Property(
       
   409     BACNET_WRITE_PROPERTY_DATA * wp_data)
       
   410 {
       
   411     bool status = false;        /* return value */
       
   412     unsigned int object_index = 0;
       
   413     unsigned int priority = 0;
       
   414     BACNET_BINARY_PV level = BINARY_NULL;
       
   415     int len = 0;
       
   416     BACNET_APPLICATION_DATA_VALUE value;
       
   417 
       
   418     /* decode the some of the request */
       
   419     len =
       
   420         bacapp_decode_application_data(wp_data->application_data,
       
   421         wp_data->application_data_len, &value);
       
   422     /* FIXME: len < application_data_len: more data? */
       
   423     if (len < 0) {
       
   424         /* error while decoding - a value larger than we can handle */
       
   425         wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   426         wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
       
   427         return false;
       
   428     }
       
   429     /*  only array properties can have array options */
       
   430     if ((wp_data->object_property != PROP_PRIORITY_ARRAY) &&
       
   431         (wp_data->array_index != BACNET_ARRAY_ALL)) {
       
   432         wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   433         wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
       
   434         return false;
       
   435     }
       
   436     /* No need to check whether object_index is within bounds.
       
   437      * Has already been checked before Binary_Value_Write_Property() is called
       
   438      */
       
   439     object_index = Binary_Value_Instance_To_Index(wp_data->object_instance);
       
   440 
       
   441     switch (wp_data->object_property) {
       
   442         case PROP_PRESENT_VALUE:
       
   443             if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
       
   444                 priority = wp_data->priority;
       
   445                 if (priority && (priority <= BACNET_MAX_PRIORITY) &&
       
   446                     (priority != 6 /* reserved */ ) &&
       
   447                     (value.type.Enumerated <= MAX_BINARY_PV)) {
       
   448                     level = (BACNET_BINARY_PV) value.type.Enumerated;
       
   449                     priority--;
       
   450                     BV_Descr[object_index].Present_Value[priority] = level;
       
   451                     status = true;
       
   452                 } else if (priority == 6) {
       
   453                     /* Command priority 6 is reserved for use by Minimum On/Off
       
   454                        algorithm and may not be used for other purposes in any
       
   455                        object. */
       
   456                     wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   457                     wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
       
   458                 } else {
       
   459                     wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   460                     wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
       
   461                 }
       
   462             } else {
       
   463                 status =
       
   464                     WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
       
   465                     &wp_data->error_class, &wp_data->error_code);
       
   466                 if (status) {
       
   467                     level = BINARY_NULL;
       
   468                     priority = wp_data->priority;
       
   469                     if (priority && (priority <= BACNET_MAX_PRIORITY)) {
       
   470                         priority--;
       
   471                         BV_Descr[object_index].Present_Value[priority] = level;
       
   472                     } else {
       
   473                         status = false;
       
   474                         wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   475                         wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
       
   476                     }
       
   477                 }
       
   478             }
       
   479             break;
       
   480         case PROP_OUT_OF_SERVICE:
       
   481         {
       
   482             bool Previous_Out_Of_Service = BV_Descr[object_index].Out_Of_Service;
       
   483             status =
       
   484                 WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
       
   485                 &wp_data->error_class, &wp_data->error_code);
       
   486             if (status) {
       
   487                 BV_Descr[object_index].Out_Of_Service = value.type.Boolean;
       
   488                 if (Previous_Out_Of_Service && !BV_Descr[object_index].Out_Of_Service)
       
   489                     /* We have just changed from Out_of_Service -> In Service */
       
   490                     /* We need to update the Present_Value to the value
       
   491                      * currently in the PLC...
       
   492                      */
       
   493                     BV_Descr[object_index].Present_Value[BACNET_MAX_PRIORITY-1] =
       
   494                                            *(BV_Descr[object_index].Located_Var_ptr);
       
   495             }
       
   496             break;
       
   497         }
       
   498         case PROP_OBJECT_IDENTIFIER:
       
   499         case PROP_OBJECT_NAME:
       
   500         case PROP_DESCRIPTION:
       
   501         case PROP_OBJECT_TYPE:
       
   502         case PROP_STATUS_FLAGS:
       
   503         case PROP_EVENT_STATE:
       
   504         case PROP_PRIORITY_ARRAY:
       
   505 //      case PROP_CURRENT_COMMAND_PRIORITY:
       
   506         case PROP_RELINQUISH_DEFAULT:
       
   507 //      case PROP_PROPERTY_LIST:
       
   508             wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   509             wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
       
   510             break;
       
   511         default:
       
   512             wp_data->error_class = ERROR_CLASS_PROPERTY;
       
   513             wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
       
   514             break;
       
   515     }
       
   516 
       
   517     return status;
       
   518 }
       
   519 
       
   520 
       
   521 
       
   522 
       
   523 
       
   524 /********************************************/
       
   525 /** Functions required for Beremiz plugin  **/
       
   526 /********************************************/
       
   527 
       
   528 
       
   529 
       
   530 void  Binary_Value_Copy_Present_Value_to_Located_Var(void) {
       
   531     unsigned i;
       
   532     for (i = 0; i < MAX_BINARY_VALUES; i++) {
       
   533         // decouple PLC's Located Variable from Bacnet Object's Present Value if Out_Of_Service is true
       
   534         if (BV_Descr[i].Out_Of_Service)
       
   535             continue;
       
   536 
       
   537         // copy the value
       
   538         *(BV_Descr[i].Located_Var_ptr) = Binary_Value_Present_Value(BV_Descr[i].Object_Identifier);
       
   539     }
       
   540 }
       
   541   
       
   542 void  Binary_Value_Copy_Located_Var_to_Present_Value(void) {
       
   543     unsigned i;
       
   544     for (i = 0; i < MAX_BINARY_VALUES; i++) {
       
   545         // decouple PLC's Located Variable from Bacnet Object's Present Value if Out_Of_Service is true
       
   546         if (BV_Descr[i].Out_Of_Service)
       
   547             continue;
       
   548 
       
   549         // copy the value
       
   550         BV_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] = *(BV_Descr[i].Located_Var_ptr);
       
   551 
       
   552         // If the Present_Value was set to an invalid value (i.e. > 1, and < BINARY_NULL)
       
   553         //   then we set it to BINARY_ACTIVE 
       
   554         //   (i.e. we assume 0 is FALSE, all other non NULL values are TRUE)
       
   555         if ((BV_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] != BINARY_INACTIVE) &&
       
   556             (BV_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] != BINARY_ACTIVE  ) &&
       
   557             (BV_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] != BINARY_NULL    ))
       
   558              BV_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1]  = BINARY_ACTIVE;          
       
   559     }
       
   560 }
       
   561 
       
   562