Edouard@2020: /**************************************************************************
Edouard@2020: *
Edouard@2020: * Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
Edouard@2020: * Copyright (C) 2017 Mario de Sousa <msousa@fe.up.pt>
Edouard@2020: *
Edouard@2020: * Permission is hereby granted, free of charge, to any person obtaining
Edouard@2020: * a copy of this software and associated documentation files (the
Edouard@2020: * "Software"), to deal in the Software without restriction, including
Edouard@2020: * without limitation the rights to use, copy, modify, merge, publish,
Edouard@2020: * distribute, sublicense, and/or sell copies of the Software, and to
Edouard@2020: * permit persons to whom the Software is furnished to do so, subject to
Edouard@2020: * the following conditions:
Edouard@2020: *
Edouard@2020: * The above copyright notice and this permission notice shall be included
Edouard@2020: * in all copies or substantial portions of the Software.
Edouard@2020: *
Edouard@2020: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Edouard@2020: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Edouard@2020: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Edouard@2020: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
Edouard@2020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
Edouard@2020: * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
Edouard@2020: * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Edouard@2020: *
Edouard@2020: *********************************************************************/
Edouard@2020: 
Edouard@2020: /** device.h Defines functions for handling all BACnet objects belonging
Edouard@2020:  *                 to a BACnet device, as well as Device-specific properties. */
Edouard@2020: 
Edouard@2020: #ifndef DEVICE_H
Edouard@2020: #define DEVICE_H
Edouard@2020: 
Edouard@2020: #include <stdbool.h>
Edouard@2020: #include <stdint.h>
Edouard@2020: #include "bacdef.h"
Edouard@2020: #include "bacenum.h"
Edouard@2020: #include "wp.h"
Edouard@2020: #include "rd.h"
Edouard@2020: #include "rp.h"
Edouard@2020: #include "rpm.h"
Edouard@2020: #include "readrange.h"
Edouard@2020: 
Edouard@2020: /** Called so a BACnet object can perform any necessary initialization.
Edouard@2020:  */
Edouard@2020: typedef void (
Edouard@2020:     *object_init_function) (
Edouard@2020:     void);
Edouard@2020: 
Edouard@2020: /** Counts the number of objects of this type.
Edouard@2020:  * return: Count of implemented objects of this type.
Edouard@2020:  */
Edouard@2020: typedef unsigned (
Edouard@2020:     *object_count_function) (
Edouard@2020:     void);
Edouard@2020: 
Edouard@2020: /** Maps an object index position to its corresponding BACnet object instance number.
Edouard@2020:  * param: index [in] The index of the object, in the array of objects of its type.
Edouard@2020:  * return: The BACnet object instance number to be used in a BACNET_OBJECT_ID.
Edouard@2020:  */
Edouard@2020: typedef uint32_t(
Edouard@2020:     *object_index_to_instance_function)
Edouard@2020:         (
Edouard@2020:     unsigned index);
Edouard@2020: 
Edouard@2020: /** Provides the BACnet Object_Name for a given object instance of this type.
Edouard@2020:  * param: object_instance [in] The object instance number to be looked up.
Edouard@2020:  * param: object_name [in,out] Pointer to a character_string structure that
Edouard@2020:  *         will hold a copy of the object name if this is a valid object_instance.
Edouard@2020:  * return: True if the object_instance is valid and object_name has been
Edouard@2020:  *         filled with a copy of the Object's name.
Edouard@2020:  */
Edouard@2020: typedef bool(
Edouard@2020:     *object_name_function)
Edouard@2020:         (
Edouard@2020:     uint32_t object_instance,
Edouard@2020:     BACNET_CHARACTER_STRING * object_name);
Edouard@2020: 
Edouard@2020: /** Look in the table of objects of this type, and see if this is a valid
Edouard@2020:  *  instance number.
Edouard@2020:  * param: [in] The object instance number to be looked up.
Edouard@2020:  * return: True if the object instance refers to a valid object of this type.
Edouard@2020:  */
Edouard@2020: typedef bool(
Edouard@2020:     *object_valid_instance_function) (
Edouard@2020:     uint32_t object_instance);
Edouard@2020: 
Edouard@2020: /** Helper function to step through an array of objects and find either the
Edouard@2020:  * first one or the next one of a given type. Used to step through an array
Edouard@2020:  * of objects which is not necessarily contiguious for each type i.e. the
Edouard@2020:  * index for the 'n'th object of a given type is not necessarily 'n'.
Edouard@2020:  * param: [in] The index of the current object or a value of ~0 to indicate
Edouard@2020:  * start at the beginning.
Edouard@2020:  * return: The index of the next object of the required type or ~0 (all bits
Edouard@2020:  * == 1) to indicate no more objects found.
Edouard@2020:  */
Edouard@2020: typedef unsigned (
Edouard@2020:     *object_iterate_function) (
Edouard@2020:     unsigned current_index);
Edouard@2020: 
Edouard@2020: /** Look in the table of objects of this type, and get the COV Value List.
Edouard@2020:  * param: [in] The object instance number to be looked up.
Edouard@2020:  * param: [out] The value list
Edouard@2020:  * return: True if the object instance supports this feature, and has changed.
Edouard@2020:  */
Edouard@2020: typedef bool(
Edouard@2020:     *object_value_list_function) (
Edouard@2020:     uint32_t object_instance,
Edouard@2020:     BACNET_PROPERTY_VALUE * value_list);
Edouard@2020: 
Edouard@2020: /** Look in the table of objects for this instance to see if value changed.
Edouard@2020:  * param: [in] The object instance number to be looked up.
Edouard@2020:  * return: True if the object instance has changed.
Edouard@2020:  */
Edouard@2020: typedef bool(
Edouard@2020:     *object_cov_function) (
Edouard@2020:     uint32_t object_instance);
Edouard@2020: 
Edouard@2020: /** Look in the table of objects for this instance to clear the changed flag.
Edouard@2020:  * param: [in] The object instance number to be looked up.
Edouard@2020:  */
Edouard@2020: typedef void (
Edouard@2020:     *object_cov_clear_function) (
Edouard@2020:     uint32_t object_instance);
Edouard@2020: 
Edouard@2020: /** Intrinsic Reporting funcionality.
Edouard@2020:  * param: [in] Object instance.
Edouard@2020:  */
Edouard@2020: typedef void (
Edouard@2020:     *object_intrinsic_reporting_function) (
Edouard@2020:     uint32_t object_instance);
Edouard@2020: 
Edouard@2020: 
Edouard@2020: /** Defines the group of object helper functions for any supported Object.
Edouard@2020:  * Each Object must provide some implementation of each of these helpers
Edouard@2020:  * in order to properly support the handlers.  Eg, the ReadProperty handler
Edouard@2020:  * handler_read_property() relies on the instance of Object_Read_Property
Edouard@2020:  * for each Object type, or configure the function as NULL.
Edouard@2020:  * In both appearance and operation, this group of functions acts like
Edouard@2020:  * they are member functions of a C++ Object base class.
Edouard@2020:  */
Edouard@2020: typedef struct object_functions {
Edouard@2020:     BACNET_OBJECT_TYPE Object_Type;
Edouard@2020:     object_init_function Object_Init;
Edouard@2020:     object_count_function Object_Count;
Edouard@2020:     object_index_to_instance_function Object_Index_To_Instance;
Edouard@2020:     object_valid_instance_function Object_Valid_Instance;
Edouard@2020:     object_name_function Object_Name;
Edouard@2020:     read_property_function Object_Read_Property;
Edouard@2020:     write_property_function Object_Write_Property;
Edouard@2020:     rpm_property_lists_function Object_RPM_List;
Edouard@2020:     rr_info_function Object_RR_Info;
Edouard@2020:     object_iterate_function Object_Iterator;
Edouard@2020:     object_value_list_function Object_Value_List;
Edouard@2020:     object_cov_function Object_COV;
Edouard@2020:     object_cov_clear_function Object_COV_Clear;
Edouard@2020:     object_intrinsic_reporting_function Object_Intrinsic_Reporting;
Edouard@2020: } object_functions_t;
Edouard@2020: 
Edouard@2020: /* String Lengths for Device Object properties that may be changed
Edouard@2020:  * (written to) over the BACnet network.
Edouard@2020:  * Maximum sizes excluding nul terminator .
Edouard@2020:  */
Edouard@2020: #define STRLEN_X(minlen, str)  (((minlen)>sizeof(str))?(minlen):sizeof(str))
msousa@2649: #define MAX_DEV_NAME_LEN STRLEN_X(%(BACnet_Param_String_Size)d, "%(BACnet_Device_Name)s")     /* Device name         */
msousa@2649: #define MAX_DEV_LOC_LEN  STRLEN_X(%(BACnet_Param_String_Size)d, BACNET_DEVICE_LOCATION)       /* Device location     */
msousa@2649: #define MAX_DEV_MOD_LEN  STRLEN_X(%(BACnet_Param_String_Size)d, BACNET_DEVICE_MODEL_NAME)     /* Device model name   */
msousa@2649: #define MAX_DEV_VER_LEN  STRLEN_X(%(BACnet_Param_String_Size)d, BACNET_DEVICE_APPSOFT_VER)    /* Device application software version */
msousa@2649: #define MAX_DEV_DESC_LEN STRLEN_X(%(BACnet_Param_String_Size)d, BACNET_DEVICE_DESCRIPTION)    /* Device description  */
msousa@2649: 
Edouard@2020: 
Edouard@2020: /** Structure to define the Object Properties common to all Objects. */
Edouard@2020: typedef struct commonBacObj_s {
Edouard@2020: 
Edouard@2020:     /** The BACnet type of this object (ie, what class is this object from?).
Edouard@2020:      * This property, of type BACnetObjectType, indicates membership in a
Edouard@2020:      * particular object type class. Each inherited class will be of one type.
Edouard@2020:      */
Edouard@2020:     BACNET_OBJECT_TYPE mObject_Type;
Edouard@2020: 
Edouard@2020:     /** The instance number for this class instance. */
Edouard@2020:     uint32_t Object_Instance_Number;
Edouard@2020: 
Edouard@2020:     /** Object Name; must be unique.
Edouard@2020:      * This property, of type CharacterString, shall represent a name for
Edouard@2020:      * the object that is unique within the BACnet Device that maintains it.
Edouard@2020:      */
Edouard@2020:     char Object_Name[MAX_DEV_NAME_LEN];
Edouard@2020: 
Edouard@2020: } COMMON_BAC_OBJECT;
Edouard@2020: 
Edouard@2020: 
Edouard@2020: /** Structure to define the Properties of Device Objects which distinguish
Edouard@2020:  *  one instance from another.
Edouard@2020:  *  This structure only defines fields for properties that are unique to
Edouard@2020:  *  a given Device object.  The rest may be fixed in device.c or hard-coded
Edouard@2020:  *  into the read-property encoding.
Edouard@2020:  *  This may be useful for implementations which manage multiple Devices,
Edouard@2020:  *  eg, a Gateway.
Edouard@2020:  */
Edouard@2020: typedef struct devObj_s {
Edouard@2020:     /** The BACnet Device Address for this device; ->len depends on DLL type. */
Edouard@2020:     BACNET_ADDRESS bacDevAddr;
Edouard@2020: 
Edouard@2020:     /** Structure for the Object Properties common to all Objects. */
Edouard@2020:     COMMON_BAC_OBJECT bacObj;
Edouard@2020: 
Edouard@2020:     /** Device Description. */
Edouard@2020:     char Description[MAX_DEV_DESC_LEN];
Edouard@2020: 
Edouard@2020:     /** The upcounter that shows if the Device ID or object structure has changed. */
Edouard@2020:     uint32_t Database_Revision;
Edouard@2020: } DEVICE_OBJECT_DATA;
Edouard@2020: 
Edouard@2020: 
Edouard@2020: #ifdef __cplusplus
Edouard@2020: extern "C" {
Edouard@2020: #endif /* __cplusplus */
Edouard@2020: 
Edouard@2020:     void Device_Init(
Edouard@2020:         const char * Device_Object_Name);
Edouard@2020: 
Edouard@2020:     bool Device_Reinitialize(
Edouard@2020:         BACNET_REINITIALIZE_DEVICE_DATA * rd_data);
Edouard@2020: 
Edouard@2020:     BACNET_REINITIALIZED_STATE Device_Reinitialized_State(
Edouard@2020:         void);
Edouard@2020: 
Edouard@2020:     rr_info_function Device_Objects_RR_Info(
Edouard@2020:         BACNET_OBJECT_TYPE object_type);
Edouard@2020: 
Edouard@2020:     void Device_getCurrentDateTime(
Edouard@2020:         BACNET_DATE_TIME * DateTime);
Edouard@2020:     int32_t Device_UTC_Offset(void);
Edouard@2020:     bool Device_Daylight_Savings_Status(void);
Edouard@2020: 
Edouard@2020:     void Device_Property_Lists(
Edouard@2020:         const int **pRequired,
Edouard@2020:         const int **pOptional,
Edouard@2020:         const int **pProprietary);
Edouard@2020:     void Device_Objects_Property_List(
Edouard@2020:         BACNET_OBJECT_TYPE object_type,
Edouard@2020:         struct special_property_list_t *pPropertyList);
Edouard@2020:     /* functions to support COV */
Edouard@2020:     bool Device_Encode_Value_List(
Edouard@2020:         BACNET_OBJECT_TYPE object_type,
Edouard@2020:         uint32_t object_instance,
Edouard@2020:         BACNET_PROPERTY_VALUE * value_list);
Edouard@2020:     bool Device_Value_List_Supported(
Edouard@2020:         BACNET_OBJECT_TYPE object_type);
Edouard@2020:     bool Device_COV(
Edouard@2020:         BACNET_OBJECT_TYPE object_type,
Edouard@2020:         uint32_t object_instance);
Edouard@2020:     void Device_COV_Clear(
Edouard@2020:         BACNET_OBJECT_TYPE object_type,
Edouard@2020:         uint32_t object_instance);
Edouard@2020: 
Edouard@2020:     uint32_t Device_Object_Instance_Number(
Edouard@2020:         void);
Edouard@2020:     bool Device_Set_Object_Instance_Number(
Edouard@2020:         uint32_t object_id);
Edouard@2020:     bool Device_Valid_Object_Instance_Number(
Edouard@2020:         uint32_t object_id);
Edouard@2020:     unsigned Device_Object_List_Count(
Edouard@2020:         void);
Edouard@2020:     bool Device_Object_List_Identifier(
Edouard@2020:         unsigned array_index,
Edouard@2020:         int *object_type,
Edouard@2020:         uint32_t * instance);
Edouard@2020: 
Edouard@2020:     unsigned Device_Count(
Edouard@2020:         void);
Edouard@2020:     uint32_t Device_Index_To_Instance(
Edouard@2020:         unsigned index);
Edouard@2020: 
Edouard@2020:     bool Device_Object_Name(
Edouard@2020:         uint32_t object_instance,
Edouard@2020:         BACNET_CHARACTER_STRING * object_name);
Edouard@2020:     bool Device_Set_Object_Name(
Edouard@2020:         BACNET_CHARACTER_STRING * object_name);
Edouard@2020:     /* Copy a child object name, given its ID. */
Edouard@2020:     bool Device_Object_Name_Copy(
Edouard@2020:         BACNET_OBJECT_TYPE object_type,
Edouard@2020:         uint32_t object_instance,
Edouard@2020:         BACNET_CHARACTER_STRING * object_name);
Edouard@2020:     bool Device_Object_Name_ANSI_Init(const char * value);
Edouard@2020: 
Edouard@2020:     BACNET_DEVICE_STATUS Device_System_Status(
Edouard@2020:         void);
Edouard@2020:     int Device_Set_System_Status(
Edouard@2020:         BACNET_DEVICE_STATUS status,
Edouard@2020:         bool local);
Edouard@2020: 
Edouard@2020:     const char *Device_Vendor_Name(
Edouard@2020:         void);
Edouard@2020: 
Edouard@2020:     uint16_t Device_Vendor_Identifier(
Edouard@2020:         void);
Edouard@2020:     void Device_Set_Vendor_Identifier(
Edouard@2020:         uint16_t vendor_id);
Edouard@2020: 
Edouard@2020:     const char *Device_Model_Name(
Edouard@2020:         void);
Edouard@2020:     bool Device_Set_Model_Name(
Edouard@2020:         const char *name,
Edouard@2020:         size_t length);
Edouard@2020: 
Edouard@2020:     const char *Device_Firmware_Revision(
Edouard@2020:         void);
Edouard@2020: 
Edouard@2020:     const char *Device_Application_Software_Version(
Edouard@2020:         void);
Edouard@2020:     bool Device_Set_Application_Software_Version(
Edouard@2020:         const char *name,
Edouard@2020:         size_t length);
Edouard@2020: 
Edouard@2020:     const char *Device_Description(
Edouard@2020:         void);
Edouard@2020:     bool Device_Set_Description(
Edouard@2020:         const char *name,
Edouard@2020:         size_t length);
Edouard@2020: 
Edouard@2020:     const char *Device_Location(
Edouard@2020:         void);
Edouard@2020:     bool Device_Set_Location(
Edouard@2020:         const char *name,
Edouard@2020:         size_t length);
Edouard@2020: 
Edouard@2020:     /* some stack-centric constant values - no set methods */
Edouard@2020:     uint8_t Device_Protocol_Version(
Edouard@2020:         void);
Edouard@2020:     uint8_t Device_Protocol_Revision(
Edouard@2020:         void);
Edouard@2020:     BACNET_SEGMENTATION Device_Segmentation_Supported(
Edouard@2020:         void);
Edouard@2020: 
Edouard@2020:     uint32_t Device_Database_Revision(
Edouard@2020:         void);
Edouard@2020:     void Device_Set_Database_Revision(
Edouard@2020:         uint32_t revision);
Edouard@2020:     void Device_Inc_Database_Revision(
Edouard@2020:         void);
Edouard@2020: 
Edouard@2020:     bool Device_Valid_Object_Name(
Edouard@2020:         BACNET_CHARACTER_STRING * object_name,
Edouard@2020:         int *object_type,
Edouard@2020:         uint32_t * object_instance);
Edouard@2020:     bool Device_Valid_Object_Id(
Edouard@2020:         int object_type,
Edouard@2020:         uint32_t object_instance);
Edouard@2020: 
Edouard@2020:     int Device_Read_Property(
Edouard@2020:         BACNET_READ_PROPERTY_DATA * rpdata);
Edouard@2020:     bool Device_Write_Property(
Edouard@2020:         BACNET_WRITE_PROPERTY_DATA * wp_data);
Edouard@2020: 
Edouard@2020:     bool DeviceGetRRInfo(
Edouard@2020:         BACNET_READ_RANGE_DATA * pRequest,      /* Info on the request */
Edouard@2020:         RR_PROP_INFO * pInfo);  /* Where to put the information */
Edouard@2020: 
Edouard@2020:     int Device_Read_Property_Local(
Edouard@2020:         BACNET_READ_PROPERTY_DATA * rpdata);
Edouard@2020:     bool Device_Write_Property_Local(
Edouard@2020:         BACNET_WRITE_PROPERTY_DATA * wp_data);
Edouard@2020: 
Edouard@2020: 
Edouard@2020: 
Edouard@2020: #ifdef __cplusplus
Edouard@2020: }
Edouard@2020: #endif /* __cplusplus */
Edouard@2020: #endif