bacnet/runtime/ao.c
author Edouard Tisserant
Wed, 09 Jan 2019 14:10:07 +0100
changeset 2482 cb53d3bf3380
parent 2020 6dddf3070806
permissions -rw-r--r--
fixed exception happening randomly just after showing discovery panel.
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) 2006 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) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     5
* 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
     6
*
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     7
* 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
     8
* 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
     9
* "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
    10
* 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
    11
* 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
    12
* 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
    13
* the following conditions:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    14
*
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    15
* 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
    16
* 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
    17
*
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    18
* 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
    19
* 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
    20
* 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
    21
* 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
    22
* 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
    23
* 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
    24
* 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
    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
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    28
/* Analog Output Objects - customize for your use */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    29
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    30
#include <stdbool.h>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    31
#include <stdint.h>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    32
#include <stdio.h>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    33
#include <string.h>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    34
#include <math.h>     /* NAN maro */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    35
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    36
#include "config_bacnet_for_beremiz_%(locstr)s.h"     /* the custom configuration for beremiz plugin */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    37
#include "bacdef.h"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    38
#include "bacdcode.h"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    39
#include "bacenum.h"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    40
#include "bacapp.h"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    41
#include "bactext.h"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    42
#include "device_%(locstr)s.h"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    43
#include "handlers.h"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    44
#include "ao_%(locstr)s.h"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    45
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    46
/* we choose to have a NULL level in our system represented by */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    47
/* a particular value.  When the priorities are not in use, they */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    48
/* will be relinquished (i.e. set to the NULL level). */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    49
/* Since the values are floats, we use NAN (Not A Number) as our NULL value. */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    50
/* WARNING: Never use comparisons like 'if (value == AO_LEVEL_NULL)'
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    51
 *           as it will always return false, even if both values are NAN.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    52
 *          Use instead the negated version 'if (value != AO_LEVEL_NULL)'
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    53
 *           and add an 'else' to the 'if' condition if necessary.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    54
 *         However, some compilers may screw this up if they do not
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    55
 *         implement IEEE 754 properly. It is probably best to stick with
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    56
 *         the isnan() macro if available.
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
#define AO_VALUE_NULL NAN
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    59
#define AO_VALUE_IS_NULL(x)  (isnan(x))
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    60
/* When all the priorities are level null, the present value returns */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    61
/* the Relinquish Default value */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    62
#define AO_VALUE_RELINQUISH_DEFAULT (0.0)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    63
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    64
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    65
/* The IEC 61131-3 located variables mapped onto the Analog Output objects of BACnet protocol */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    66
%(AO_lvars)s
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    67
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    68
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    69
/* The array where we keep all the state related to the Analog Output Objects */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    70
#define MAX_ANALOG_OUTPUTS %(AO_count)s
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    71
static ANALOG_OUTPUT_DESCR AO_Descr[MAX_ANALOG_OUTPUTS] = {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    72
%(AO_param)s
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    73
};
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    74
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    75
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    76
/* 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
    77
 * 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
    78
 * Property List (PROP_PROPERTY_LIST) property.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    79
 */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    80
static const int Analog_Output_Properties_Required[] = {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    81
 /* (1) Currently Supported                  */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    82
 /* (2) Required by standard ASHRAE 135-2016 */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    83
                                  /*(1)(2)      */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    84
    PROP_OBJECT_IDENTIFIER,       /* R  R ( 75) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    85
    PROP_OBJECT_NAME,             /* R  R ( 77) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    86
    PROP_OBJECT_TYPE,             /* R  R ( 79) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    87
    PROP_PRESENT_VALUE,           /* W  W ( 85) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    88
    PROP_STATUS_FLAGS,            /* R  R (111) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    89
    PROP_EVENT_STATE,             /* R  R ( 36) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    90
    PROP_OUT_OF_SERVICE,          /* W  R ( 81) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    91
    PROP_UNITS,                   /* W  R (117) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    92
    PROP_PRIORITY_ARRAY,          /* R  R ( 87) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    93
    PROP_RELINQUISH_DEFAULT,      /* R  R (104) */    
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    94
//  PROP_PROPERTY_LIST,           /* R  R (371) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    95
//  PROP_CURRENT_COMMAND_PRIORITY,/* R  R (431) */   
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    96
    -1
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    97
};
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    98
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    99
static const int Analog_Output_Properties_Optional[] = {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   100
 /* (1) Currently Supported                  */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   101
 /* (2) Required by standard ASHRAE 135-2016 */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   102
                                  /*(1)(2)      */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   103
    PROP_DESCRIPTION,             /* R  O ( 28) */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   104
    -1
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
static const int Analog_Output_Properties_Proprietary[] = {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   108
    -1
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   109
};
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   110
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   111
/* 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
   112
 * 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
   113
 * 
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   114
 * It is initialized by Analog_Outputs_Init() based off the values
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   115
 * stored in Analog_Output_Properties_Required 
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   116
 *           Analog_Output_Properties_Optional
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   117
 *           Analog_Output_Properties_Proprietary
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   118
 */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   119
/* 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
   120
static int Analog_Output_Properties_List[64];
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   121
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   122
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   123
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   124
/********************************************************/
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   125
/**                  Callback functions.               **/
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   126
/** Functions required by BACnet devie implementation. **/
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   127
/********************************************************/
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
/* 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
   131
void Analog_Output_Property_Lists(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   132
    const int **pRequired,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   133
    const int **pOptional,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   134
    const int **pProprietary)
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
    if (pRequired)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   137
        *pRequired = Analog_Output_Properties_Required;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   138
    if (pOptional)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   139
        *pOptional = Analog_Output_Properties_Optional;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   140
    if (pProprietary)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   141
        *pProprietary = Analog_Output_Properties_Proprietary;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   142
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   143
    return;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   144
}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   145
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
/* 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
   148
void Analog_Output_Init(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   149
    void)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   150
{
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   151
    unsigned i, j;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   152
    static bool initialized = false;
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
    if (!initialized) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   155
        initialized = true;
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
        /* initialize the Analog_Output_Properties_List array */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   158
        int len = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   159
        len += BACnet_Init_Properties_List(Analog_Output_Properties_List + len,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   160
                                           Analog_Output_Properties_Required);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   161
        len += BACnet_Init_Properties_List(Analog_Output_Properties_List + len,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   162
                                           Analog_Output_Properties_Optional);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   163
        len += BACnet_Init_Properties_List(Analog_Output_Properties_List + len,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   164
                                           Analog_Output_Properties_Proprietary);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   165
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   166
        for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   167
            // MJS: the following line in th original demo code was commented out so we do not
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   168
            //      overwrite the initial values configured by the user in beremiz IDE
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   169
            // memset(&AO_Descr[i], 0x00, sizeof(ANALOG_OUTPUT_DESCR));
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   170
            for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   171
                AO_Descr[i].Present_Value[j]  = AO_VALUE_NULL;
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
            AO_Descr[i].Out_Of_Service = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   174
            AO_Descr[i].Event_State    = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   175
//          AO_Descr[i].Units = UNITS_NO_UNITS;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   176
        }
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
/* validate that the given instance exists */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   184
/* 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
   185
bool Analog_Output_Valid_Instance(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   186
    uint32_t object_instance)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   187
{
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   188
    return (Analog_Output_Instance_To_Index(object_instance) < MAX_ANALOG_OUTPUTS);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   189
}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   190
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   191
/* the number of Analog Output Objects */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   192
/* 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
   193
unsigned Analog_Output_Count(void) {return MAX_ANALOG_OUTPUTS;}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   194
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
/* 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
   197
/* 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
   198
uint32_t Analog_Output_Index_To_Instance(unsigned index) {return AO_Descr[index].Object_Identifier;}
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
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   202
/* 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
   203
unsigned Analog_Output_Instance_To_Index(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   204
    uint32_t object_instance)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   205
{
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   206
    unsigned index = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   207
  
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   208
    for (index = 0; index < MAX_ANALOG_OUTPUTS; index++)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   209
        if (object_instance == AO_Descr[index].Object_Identifier)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   210
            return index;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   211
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   212
    /* 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
   213
    return MAX_ANALOG_OUTPUTS;
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
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   217
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   218
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   219
float Analog_Output_Present_Value(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   220
    uint32_t object_instance)
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
    float value = AO_VALUE_RELINQUISH_DEFAULT;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   223
    unsigned index = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   224
    unsigned i = 0;
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
    index = Analog_Output_Instance_To_Index(object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   227
    if (index < MAX_ANALOG_OUTPUTS) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   228
        for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   229
            if (!AO_VALUE_IS_NULL(AO_Descr[index].Present_Value[i])) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   230
                value = AO_Descr[index].Present_Value[i];
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   231
                break;
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
    return value;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   237
}
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
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   240
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   241
/* returns command priority (1..16), or 0 if all priority values are at NULL */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   242
int Analog_Output_Current_Command_Priority(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   243
    uint32_t object_instance)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   244
{
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   245
    unsigned index = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   246
    unsigned i = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   247
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   248
    index = Analog_Output_Instance_To_Index(object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   249
    if (index < MAX_ANALOG_OUTPUTS) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   250
        for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   251
            if (!AO_VALUE_IS_NULL(AO_Descr[index].Present_Value[i])) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   252
                return i+1; // +1 since priority is 1..16, and not 0..15
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   253
            }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   254
        }
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
    // command values in all priorities are set to NULL
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   257
    return 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   258
}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   259
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   260
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
/* For a given object instance-number, sets the present-value at a given
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   263
 * priority 1..16 (except 6, see ASHRAE 135-2016, section 19.2.2)
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
bool Analog_Output_Present_Value_Set(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   266
    uint32_t object_instance,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   267
    float value,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   268
    uint8_t priority)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   269
{
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   270
    unsigned index = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   271
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   272
    index = Analog_Output_Instance_To_Index(object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   273
    if (index >= MAX_ANALOG_OUTPUTS) 
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   274
      return false;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   275
    if ((priority == 0) || (priority > BACNET_MAX_PRIORITY) ||
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   276
        (priority == 6 /* reserved, ASHRAE 135-2016, section 19.2.2 */))
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   277
      return false;
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
    priority--;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   280
    AO_Descr[index].Present_Value[priority] = value;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   281
    return true;
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
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   285
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   286
bool Analog_Output_Present_Value_Relinquish(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   287
    uint32_t object_instance,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   288
    unsigned priority)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   289
{
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   290
    unsigned index = 0;
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 = Analog_Output_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_ANALOG_OUTPUTS)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   294
      return false;
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
    if ((priority == 0) || (priority > BACNET_MAX_PRIORITY) ||
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   297
        (priority == 6 /* reserved, ASHRAE 135-2016, section 19.2.2 */))
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   298
      return false;
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
    priority--;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   301
    AO_Descr[index].Present_Value[priority] = AO_VALUE_NULL;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   302
    return true;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   303
}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   304
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   305
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
/* note: the object name must be unique within this device */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   308
/* 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
   309
bool Analog_Output_Object_Name(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   310
    uint32_t object_instance,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   311
    BACNET_CHARACTER_STRING * object_name)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   312
{
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   313
    bool    status = false;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   314
    unsigned index = Analog_Output_Instance_To_Index(object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   315
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   316
    if (index < MAX_ANALOG_OUTPUTS)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   317
        status = characterstring_init_ansi(object_name, AO_Descr[index].Object_Name);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   318
    
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   319
    return status;
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
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   323
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   324
bool Analog_Output_Object_Description(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   325
    uint32_t object_instance,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   326
    BACNET_CHARACTER_STRING * object_name)
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
    bool    status = false;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   329
    unsigned index = Analog_Output_Instance_To_Index(object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   330
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   331
    if (index < MAX_ANALOG_OUTPUTS)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   332
        status = characterstring_init_ansi(object_name, AO_Descr[index].Description);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   333
    
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   334
    return status;    
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   335
}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   336
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   337
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   338
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   339
/* 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
   340
/* 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
   341
int Analog_Output_Read_Property(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   342
    BACNET_READ_PROPERTY_DATA * rpdata)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   343
{
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   344
    int apdu_len = 0;   /* return value */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   345
    BACNET_BIT_STRING bit_string;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   346
    BACNET_CHARACTER_STRING char_string;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   347
    float real_value = (float) 1.414;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   348
    unsigned object_index = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   349
    bool state = false;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   350
    uint8_t *apdu = NULL;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   351
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   352
    if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   353
        (rpdata->application_data_len == 0)) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   354
        return 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   355
    }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   356
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   357
    apdu = rpdata->application_data;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   358
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   359
    object_index = Analog_Output_Instance_To_Index(rpdata->object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   360
    if (object_index >= MAX_ANALOG_OUTPUTS) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   361
        rpdata->error_class = ERROR_CLASS_OBJECT;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   362
        rpdata->error_code  = ERROR_CODE_UNKNOWN_OBJECT;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   363
        return BACNET_STATUS_ERROR;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   364
    }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   365
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   366
    switch (rpdata->object_property) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   367
        case PROP_OBJECT_IDENTIFIER:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   368
            apdu_len =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   369
                encode_application_object_id(&apdu[0], OBJECT_ANALOG_OUTPUT,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   370
                rpdata->object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   371
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   372
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   373
        case PROP_OBJECT_NAME:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   374
            Analog_Output_Object_Name(rpdata->object_instance, &char_string);
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_character_string(&apdu[0], &char_string);
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
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   379
        case PROP_DESCRIPTION:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   380
            Analog_Output_Object_Description(rpdata->object_instance, &char_string);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   381
            apdu_len =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   382
                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
   383
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   384
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   385
        case PROP_OBJECT_TYPE:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   386
            apdu_len =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   387
                encode_application_enumerated(&apdu[0], OBJECT_ANALOG_OUTPUT);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   388
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   389
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   390
        case PROP_PRESENT_VALUE:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   391
            real_value = Analog_Output_Present_Value(rpdata->object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   392
            apdu_len = encode_application_real(&apdu[0], real_value);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   393
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   394
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   395
        case PROP_STATUS_FLAGS:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   396
            bitstring_init(&bit_string);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   397
            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
   398
            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
   399
            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
   400
            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
   401
                AO_Descr[object_index].Out_Of_Service);
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
            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
   404
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   405
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   406
        case PROP_EVENT_STATE:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   407
            apdu_len =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   408
                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
   409
            break;
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
        case PROP_OUT_OF_SERVICE:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   412
            state = AO_Descr[object_index].Out_Of_Service;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   413
            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
   414
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   415
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   416
        case PROP_PRIORITY_ARRAY:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   417
            BACnet_encode_array(AO_Descr[object_index].Present_Value,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   418
                                BACNET_MAX_PRIORITY,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   419
                                AO_VALUE_IS_NULL,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   420
                                encode_application_real)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   421
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   422
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   423
//      case PROP_CURRENT_COMMAND_PRIORITY: {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   424
//          unsigned i = Analog_Output_Current_Command_Priority(rpdata->object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   425
//          if (i == 0)  apdu_len = encode_application_null    (&apdu[0]);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   426
//          else         apdu_len = encode_application_unsigned(&apdu[0], i);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   427
//          break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   428
//      }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   429
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   430
        case PROP_RELINQUISH_DEFAULT:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   431
            real_value = AO_VALUE_RELINQUISH_DEFAULT;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   432
            apdu_len = encode_application_real(&apdu[0], real_value);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   433
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   434
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   435
        case PROP_UNITS:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   436
            apdu_len =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   437
                encode_application_enumerated(&apdu[0], AO_Descr[object_index].Units);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   438
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   439
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   440
//      case PROP_PROPERTY_LIST:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   441
//          BACnet_encode_array(Analog_Output_Properties_List,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   442
//                              property_list_count(Analog_Output_Properties_List),
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   443
//                              retfalse, encode_application_enumerated);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   444
//          break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   445
        default:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   446
            rpdata->error_class = ERROR_CLASS_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   447
            rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   448
            apdu_len = BACNET_STATUS_ERROR;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   449
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   450
    }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   451
    /*  only array properties can have array options */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   452
    if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   453
        (rpdata->object_property != PROP_EVENT_TIME_STAMPS) &&
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   454
//      (rpdata->object_property != PROP_PROPERTY_LIST) &&
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   455
        (rpdata->array_index != BACNET_ARRAY_ALL)) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   456
        rpdata->error_class = ERROR_CLASS_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   457
        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
   458
        apdu_len = BACNET_STATUS_ERROR;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   459
    }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   460
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   461
    return apdu_len;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   462
}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   463
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   464
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   465
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   466
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   467
/* returns true if successful */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   468
/* 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
   469
bool Analog_Output_Write_Property(
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   470
    BACNET_WRITE_PROPERTY_DATA * wp_data)
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
    bool status = false;        /* return value */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   473
    unsigned int object_index = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   474
    int len = 0;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   475
    BACNET_APPLICATION_DATA_VALUE value;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   476
    ANALOG_OUTPUT_DESCR *CurrentAO;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   477
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   478
    /* decode the some of the request */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   479
    len =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   480
        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
   481
        wp_data->application_data_len, &value);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   482
    /* FIXME: len < application_data_len: more data? */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   483
    if (len < 0) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   484
        /* 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
   485
        wp_data->error_class = ERROR_CLASS_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   486
        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
   487
        return false;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   488
    }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   489
    if ((wp_data->object_property != PROP_PRIORITY_ARRAY) &&
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   490
        (wp_data->object_property != PROP_EVENT_TIME_STAMPS) &&
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   491
        (wp_data->array_index != BACNET_ARRAY_ALL)) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   492
        /*  only array properties can have array options */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   493
        wp_data->error_class = ERROR_CLASS_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   494
        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
   495
        return false;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   496
    }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   497
    object_index = Analog_Output_Instance_To_Index(wp_data->object_instance);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   498
    if (object_index < MAX_ANALOG_OUTPUTS)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   499
        CurrentAO = &AO_Descr[object_index];
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   500
    else
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   501
        return false;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   502
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   503
    switch (wp_data->object_property) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   504
        case PROP_PRESENT_VALUE:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   505
            if (value.tag == BACNET_APPLICATION_TAG_REAL) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   506
                if (Analog_Output_Present_Value_Set(wp_data->object_instance,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   507
                        value.type.Real, wp_data->priority)) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   508
                    status = true;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   509
                } else if (wp_data->priority == 6) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   510
                    /* Command priority 6 is reserved for use by Minimum On/Off
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   511
                       algorithm and may not be used for other purposes in any
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   512
                       object. */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   513
                    wp_data->error_class = ERROR_CLASS_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   514
                    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
   515
                } else {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   516
                    wp_data->error_class = ERROR_CLASS_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   517
                    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
   518
                }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   519
            } else {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   520
                status =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   521
                    WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   522
                    &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
   523
                if (status) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   524
                    status =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   525
                        Analog_Output_Present_Value_Relinquish
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   526
                        (wp_data->object_instance, wp_data->priority);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   527
                }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   528
                if (!status) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   529
                    wp_data->error_class = ERROR_CLASS_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   530
                    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
   531
                }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   532
            }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   533
            break;
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
        case PROP_OUT_OF_SERVICE:
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
            bool Previous_Out_Of_Service = CurrentAO->Out_Of_Service;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   538
            status =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   539
                WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   540
                &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
   541
            if (status) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   542
                CurrentAO->Out_Of_Service = value.type.Boolean;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   543
                if (Previous_Out_Of_Service && !CurrentAO->Out_Of_Service)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   544
                    /* 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
   545
                    /* 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
   546
                     * currently in the PLC...
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   547
                     */
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   548
                    CurrentAO->Present_Value[BACNET_MAX_PRIORITY-1] =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   549
                                             *(CurrentAO->Located_Var_ptr);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   550
            }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   551
            break;
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
        case PROP_UNITS:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   555
            status =
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   556
                WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   557
                &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
   558
            if (status) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   559
                CurrentAO->Units = value.type.Enumerated;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   560
            }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   561
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   562
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   563
        case PROP_OBJECT_IDENTIFIER:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   564
        case PROP_OBJECT_NAME:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   565
        case PROP_OBJECT_TYPE:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   566
        case PROP_STATUS_FLAGS:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   567
        case PROP_EVENT_STATE:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   568
        case PROP_DESCRIPTION:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   569
        case PROP_RELINQUISH_DEFAULT:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   570
        case PROP_PRIORITY_ARRAY:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   571
//      case PROP_PROPERTY_LIST:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   572
//      case PROP_CURRENT_COMMAND_PRIORITY:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   573
            wp_data->error_class = ERROR_CLASS_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   574
            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
   575
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   576
        default:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   577
            wp_data->error_class = ERROR_CLASS_PROPERTY;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   578
            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
   579
            break;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   580
    }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   581
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   582
    return status;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   583
}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   584
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   585
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   586
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   587
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   588
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   589
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   590
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   591
/********************************************/
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   592
/** Functions required for Beremiz plugin  **/
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   593
/********************************************/
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   594
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   595
void  Analog_Output_Copy_Present_Value_to_Located_Var(void) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   596
    unsigned i;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   597
    for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   598
        // 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
   599
        if (AO_Descr[i].Out_Of_Service)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   600
            continue;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   601
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   602
        // copy the value
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   603
        *(AO_Descr[i].Located_Var_ptr) = Analog_Output_Present_Value(AO_Descr[i].Object_Identifier);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   604
    }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   605
}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   606
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   607
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   608
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   609
void  Analog_Output_Copy_Located_Var_to_Present_Value(void) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   610
    unsigned i;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   611
    for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) {
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   612
        // 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
   613
        if (AO_Descr[i].Out_Of_Service)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   614
            continue;
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   615
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   616
        // copy the value
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   617
        AO_Descr[i].Present_Value[BACNET_MAX_PRIORITY-1] = *(AO_Descr[i].Located_Var_ptr);
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   618
    }
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   619
}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   620