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