Feature/add basic structured view object (#641)
* Added basic structured view object and unit test. Added example structured view into server example. * Removed creation of objects from basic device object into the server example
This commit is contained in:
+61
-12
@@ -2048,9 +2048,58 @@ typedef enum BACnetNodeType {
|
||||
BACNET_NODE_COLLECTION = 8,
|
||||
BACNET_NODE_PROPERTY = 9,
|
||||
BACNET_NODE_FUNCTIONAL = 10,
|
||||
BACNET_NODE_OTHER = 11
|
||||
BACNET_NODE_OTHER = 11,
|
||||
BACNET_NODE_SUBSYSTEM = 12,
|
||||
BACNET_NODE_BUILDING = 13,
|
||||
BACNET_NODE_FLOOR = 14,
|
||||
BACNET_NODE_SECTION = 15,
|
||||
BACNET_NODE_MODULE = 16,
|
||||
BACNET_NODE_TREE = 17,
|
||||
BACNET_NODE_MEMBER = 18,
|
||||
BACNET_NODE_PROTOCOL = 19,
|
||||
BACNET_NODE_ROOM = 20,
|
||||
BACNET_NODE_ZONE = 21
|
||||
} BACNET_NODE_TYPE;
|
||||
|
||||
typedef enum BACnetRelationship {
|
||||
BACNET_RELATIONSHIP_UNKNOWN = 0,
|
||||
BACNET_RELATIONSHIP_DEFAULT = 1,
|
||||
BACNET_RELATIONSHIP_CONTAINS = 2,
|
||||
BACNET_RELATIONSHIP_CONTAINED_BY = 3,
|
||||
BACNET_RELATIONSHIP_USES = 4,
|
||||
BACNET_RELATIONSHIP_USED_BY = 5,
|
||||
BACNET_RELATIONSHIP_COMMANDS = 6,
|
||||
BACNET_RELATIONSHIP_COMMANDED_BY = 7,
|
||||
BACNET_RELATIONSHIP_ADJUSTS = 8,
|
||||
BACNET_RELATIONSHIP_ADJUSTED_BY = 9,
|
||||
BACNET_RELATIONSHIP_INGRESS = 10,
|
||||
BACNET_RELATIONSHIP_EGRESS = 11,
|
||||
BACNET_RELATIONSHIP_SUPPLIES_AIR = 12,
|
||||
BACNET_RELATIONSHIP_RECEIVES_AIR = 13,
|
||||
BACNET_RELATIONSHIP_SUPPLIES_HOT_AIR = 14,
|
||||
BACNET_RELATIONSHIP_RECEIVES_HOT_AIR = 15,
|
||||
BACNET_RELATIONSHIP_SUPPLIES_COOL_AIR = 16,
|
||||
BACNET_RELATIONSHIP_RECEIVES_COOL_AIR = 17,
|
||||
BACNET_RELATIONSHIP_SUPPLIES_POWER = 18,
|
||||
BACNET_RELATIONSHIP_RECEIVES_POWER = 19,
|
||||
BACNET_RELATIONSHIP_SUPPLIES_GAS = 20,
|
||||
BACNET_RELATIONSHIP_RECEIVES_GAS = 21,
|
||||
BACNET_RELATIONSHIP_SUPPLIES_WATER = 22,
|
||||
BACNET_RELATIONSHIP_RECEIVES_WATER = 23,
|
||||
BACNET_RELATIONSHIP_SUPPLIES_HOT_WATER = 24,
|
||||
BACNET_RELATIONSHIP_RECEIVES_HOT_WATER = 25,
|
||||
BACNET_RELATIONSHIP_SUPPLIES_COOL_WATER = 26,
|
||||
BACNET_RELATIONSHIP_RECEIVES_COOL_WATER = 27,
|
||||
BACNET_RELATIONSHIP_SUPPLIES_STEAM = 28,
|
||||
BACNET_RELATIONSHIP_RECEIVES_STEAM = 29,
|
||||
BACNET_RELATIONSHIP_RESERVED_MAX = 1023,
|
||||
BACNET_RELATIONSHIP_PROPRIETARY_MIN = 1024,
|
||||
BACNET_RELATIONSHIP_PROPRIETARY_MAX = 65535
|
||||
/* Enumerated values 0-1023 are reserved for definition by ASHRAE.
|
||||
Enumerated values 1024-65535 may be used by others subject
|
||||
to the procedures and constraints described in Clause 23. */
|
||||
} BACNET_RELATIONSHIP;
|
||||
|
||||
typedef enum BACnetShedState {
|
||||
BACNET_SHED_INACTIVE = 0,
|
||||
BACNET_SHED_REQUEST_PENDING = 1,
|
||||
@@ -2107,8 +2156,8 @@ typedef enum BACnetBinaryLightingPV {
|
||||
BINARY_LIGHTING_PV_WARN_RELINQUISH = 4,
|
||||
BINARY_LIGHTING_PV_STOP = 5,
|
||||
BINARY_LIGHTING_PV_MAX = 6,
|
||||
/* -- Enumerated values 0-63 are reserved for definition by ASHRAE.
|
||||
-- Enumerated values 64-255 may be used by others
|
||||
/* -- Enumerated values 0-63 are reserved for definition by ASHRAE.
|
||||
-- Enumerated values 64-255 may be used by others
|
||||
-- subject to the procedures and constraints described in Clause 23. */
|
||||
BINARY_LIGHTING_PV_PROPRIETARY_MIN = 64,
|
||||
BINARY_LIGHTING_PV_PROPRIETARY_MAX = 255
|
||||
@@ -2315,8 +2364,8 @@ typedef enum BACnetAccessZoneOccupancyState {
|
||||
ACCESS_ZONE_OCCUPANCY_STATE_ABOVE_UPPER_LIMIT = 4,
|
||||
ACCESS_ZONE_OCCUPANCY_STATE_DISABLED = 5,
|
||||
ACCESS_ZONE_OCCUPANCY_STATE_NOT_SUPPORTED = 6,
|
||||
/* Enumerated values 0-63 are reserved for definition by ASHRAE.
|
||||
Enumerated values 64-65535 may be used by others subject
|
||||
/* Enumerated values 0-63 are reserved for definition by ASHRAE.
|
||||
Enumerated values 64-65535 may be used by others subject
|
||||
to the procedures and constraints described in Clause 23. */
|
||||
ACCESS_ZONE_OCCUPANCY_STATE_PROPRIETARY_MIN = 64,
|
||||
ACCESS_ZONE_OCCUPANCY_STATE_PROPRIETARY_MAX = 65535
|
||||
@@ -2624,18 +2673,18 @@ typedef enum BACnetEscalatorFault {
|
||||
ESCALATOR_FAULT_PROPRIETARY_MAX = 65535
|
||||
} BACNET_ESCALATOR_FAULT;
|
||||
|
||||
typedef enum BACnetEscalatorMode {
|
||||
typedef enum BACnetEscalatorMode {
|
||||
ESCALATOR_MODE_UNKNOWN = 0,
|
||||
ESCALATOR_MODE_STOP = 1,
|
||||
ESCALATOR_MODE_UP = 2,
|
||||
ESCALATOR_MODE_STOP = 1,
|
||||
ESCALATOR_MODE_UP = 2,
|
||||
ESCALATOR_MODE_DOWN = 3,
|
||||
ESCALATOR_MODE_INSPECTION = 4,
|
||||
ESCALATOR_MODE_INSPECTION = 4,
|
||||
ESCALATOR_MODE_OUT_OF_SERVICE = 5,
|
||||
/* Enumerated values 0-1023 are reserved for definition by ASHRAE.
|
||||
Enumerated values 1024-65535 may be used by others subject to
|
||||
the procedures and constraints described in Clause 23. */
|
||||
ESCALATOR_MODE_PROPRIETARY_MIN = 1024,
|
||||
ESCALATOR_MODE_PROPRIETARY_MAX = 65535
|
||||
ESCALATOR_MODE_PROPRIETARY_MAX = 65535
|
||||
} BACNET_ESCALATOR_MODE;
|
||||
|
||||
typedef enum BACnetEscalatorOperationDirection {
|
||||
@@ -2779,8 +2828,8 @@ typedef enum BACnetAuditOperation {
|
||||
/* Enumerated values 0-31 are reserved for definition by ASHRAE.
|
||||
Enumerated values 32-63 may be used by others subject to
|
||||
the procedures and constraints described in Clause 23.
|
||||
|
||||
The enumerated values match the bit positions in
|
||||
|
||||
The enumerated values match the bit positions in
|
||||
BACnetAuditOperationFlags. */
|
||||
AUDIT_OPERATION_PROPRIETARY_MIN = 32,
|
||||
AUDIT_OPERATION_PROPRIETARY_MAX = 63
|
||||
|
||||
@@ -39,11 +39,14 @@
|
||||
#include "bacnet/basic/object/bo.h"
|
||||
#include "bacnet/basic/object/bv.h"
|
||||
#include "bacnet/basic/object/calendar.h"
|
||||
#include "bacnet/basic/object/channel.h"
|
||||
#include "bacnet/basic/object/command.h"
|
||||
#include "bacnet/basic/object/csv.h"
|
||||
#include "bacnet/basic/object/iv.h"
|
||||
#include "bacnet/basic/object/lc.h"
|
||||
#if (BACNET_PROTOCOL_REVISION >= 14)
|
||||
#include "bacnet/basic/object/channel.h"
|
||||
#include "bacnet/basic/object/lo.h"
|
||||
#endif
|
||||
#include "bacnet/basic/object/lsp.h"
|
||||
#include "bacnet/basic/object/lsz.h"
|
||||
#include "bacnet/basic/object/ms-input.h"
|
||||
@@ -55,6 +58,7 @@
|
||||
#include "bacnet/basic/object/osv.h"
|
||||
#include "bacnet/basic/object/piv.h"
|
||||
#include "bacnet/basic/object/schedule.h"
|
||||
#include "bacnet/basic/object/structured_view.h"
|
||||
#include "bacnet/basic/object/time_value.h"
|
||||
#include "bacnet/basic/object/trendlog.h"
|
||||
#if defined(INTRINSIC_REPORTING)
|
||||
@@ -78,6 +82,7 @@ extern bool Routed_Device_Write_Property_Local(
|
||||
/* may be overridden by outside table */
|
||||
static object_functions_t *Object_Table;
|
||||
|
||||
/* clang format off */
|
||||
static object_functions_t My_Object_Table[] = {
|
||||
{ OBJECT_DEVICE, NULL /* Init - don't init Device or it will recourse! */,
|
||||
Device_Count, Device_Index_To_Instance,
|
||||
@@ -111,7 +116,7 @@ static object_functions_t My_Object_Table[] = {
|
||||
Analog_Output_Index_To_Instance, Analog_Output_Valid_Instance,
|
||||
Analog_Output_Object_Name, Analog_Output_Read_Property,
|
||||
Analog_Output_Write_Property, Analog_Output_Property_Lists,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */,
|
||||
Analog_Output_Encode_Value_List, Analog_Output_Change_Of_Value,
|
||||
Analog_Output_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */,
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
@@ -138,7 +143,7 @@ static object_functions_t My_Object_Table[] = {
|
||||
Binary_Output_Index_To_Instance, Binary_Output_Valid_Instance,
|
||||
Binary_Output_Object_Name, Binary_Output_Read_Property,
|
||||
Binary_Output_Write_Property, Binary_Output_Property_Lists,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */,
|
||||
Binary_Output_Encode_Value_List, Binary_Output_Change_Of_Value,
|
||||
Binary_Output_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */,
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
@@ -147,7 +152,7 @@ static object_functions_t My_Object_Table[] = {
|
||||
Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance,
|
||||
Binary_Value_Object_Name, Binary_Value_Read_Property,
|
||||
Binary_Value_Write_Property, Binary_Value_Property_Lists,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */,
|
||||
Binary_Value_Encode_Value_List, Binary_Value_Change_Of_Value,
|
||||
Binary_Value_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */,
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
@@ -227,7 +232,7 @@ static object_functions_t My_Object_Table[] = {
|
||||
Multistate_Input_Index_To_Instance, Multistate_Input_Valid_Instance,
|
||||
Multistate_Input_Object_Name, Multistate_Input_Read_Property,
|
||||
Multistate_Input_Write_Property, Multistate_Input_Property_Lists,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */,
|
||||
Multistate_Input_Encode_Value_List, Multistate_Input_Change_Of_Value,
|
||||
Multistate_Input_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */,
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
@@ -237,7 +242,7 @@ static object_functions_t My_Object_Table[] = {
|
||||
Multistate_Output_Valid_Instance, Multistate_Output_Object_Name,
|
||||
Multistate_Output_Read_Property, Multistate_Output_Write_Property,
|
||||
Multistate_Output_Property_Lists, NULL /* ReadRangeInfo */,
|
||||
NULL /* Iterator */,
|
||||
NULL /* Iterator */,
|
||||
Multistate_Output_Encode_Value_List, Multistate_Output_Change_Of_Value,
|
||||
Multistate_Output_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */,
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
@@ -343,6 +348,14 @@ static object_functions_t My_Object_Table[] = {
|
||||
NULL /* Intrinsic Reporting */, NULL /* Add_List_Element */,
|
||||
NULL /* Remove_List_Element */, NULL /* Create */, NULL /* Delete */,
|
||||
NULL /* Timer */ },
|
||||
{ OBJECT_STRUCTURED_VIEW, Structured_View_Init, Structured_View_Count,
|
||||
Structured_View_Index_To_Instance, Structured_View_Valid_Instance,
|
||||
Structured_View_Object_Name, Structured_View_Read_Property,
|
||||
NULL /* Write_Property */, Structured_View_Property_Lists,
|
||||
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
|
||||
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
Structured_View_Create, Structured_View_Delete, NULL /* Timer */ },
|
||||
{ OBJECT_TIME_VALUE, Time_Value_Init, Time_Value_Count,
|
||||
Time_Value_Index_To_Instance, Time_Value_Valid_Instance,
|
||||
Time_Value_Object_Name, Time_Value_Read_Property,
|
||||
@@ -368,6 +381,7 @@ static object_functions_t My_Object_Table[] = {
|
||||
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
|
||||
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
|
||||
};
|
||||
/* clang format on */
|
||||
|
||||
/** Glue function to let the Device object, when called by a handler,
|
||||
* lookup which Object type needs to be invoked.
|
||||
@@ -462,16 +476,19 @@ void Device_Objects_Property_List(BACNET_OBJECT_TYPE object_type,
|
||||
return;
|
||||
}
|
||||
|
||||
/* clang format off */
|
||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||
static const int Device_Properties_Required[] = { PROP_OBJECT_IDENTIFIER,
|
||||
PROP_OBJECT_NAME, PROP_OBJECT_TYPE, PROP_SYSTEM_STATUS, PROP_VENDOR_NAME,
|
||||
PROP_VENDOR_IDENTIFIER, PROP_MODEL_NAME, PROP_FIRMWARE_REVISION,
|
||||
PROP_APPLICATION_SOFTWARE_VERSION, PROP_PROTOCOL_VERSION,
|
||||
PROP_PROTOCOL_REVISION, PROP_PROTOCOL_SERVICES_SUPPORTED,
|
||||
PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, PROP_OBJECT_LIST,
|
||||
PROP_MAX_APDU_LENGTH_ACCEPTED, PROP_SEGMENTATION_SUPPORTED,
|
||||
PROP_APDU_TIMEOUT, PROP_NUMBER_OF_APDU_RETRIES, PROP_DEVICE_ADDRESS_BINDING,
|
||||
PROP_DATABASE_REVISION, -1 };
|
||||
static const int Device_Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE,
|
||||
PROP_SYSTEM_STATUS, PROP_VENDOR_NAME, PROP_VENDOR_IDENTIFIER,
|
||||
PROP_MODEL_NAME, PROP_FIRMWARE_REVISION, PROP_APPLICATION_SOFTWARE_VERSION,
|
||||
PROP_PROTOCOL_VERSION, PROP_PROTOCOL_REVISION,
|
||||
PROP_PROTOCOL_SERVICES_SUPPORTED, PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED,
|
||||
PROP_OBJECT_LIST, PROP_MAX_APDU_LENGTH_ACCEPTED,
|
||||
PROP_SEGMENTATION_SUPPORTED, PROP_APDU_TIMEOUT,
|
||||
PROP_NUMBER_OF_APDU_RETRIES, PROP_DEVICE_ADDRESS_BINDING,
|
||||
PROP_DATABASE_REVISION, -1
|
||||
};
|
||||
|
||||
static const int Device_Properties_Optional[] = {
|
||||
#if defined(BACDL_MSTP)
|
||||
@@ -486,7 +503,10 @@ static const int Device_Properties_Optional[] = {
|
||||
-1
|
||||
};
|
||||
|
||||
static const int Device_Properties_Proprietary[] = { -1 };
|
||||
static const int Device_Properties_Proprietary[] = {
|
||||
-1
|
||||
};
|
||||
/* clang format on */
|
||||
|
||||
void Device_Property_Lists(
|
||||
const int **pRequired, const int **pOptional, const int **pProprietary)
|
||||
@@ -2231,16 +2251,6 @@ void Device_Init(object_functions_t *object_table)
|
||||
}
|
||||
pObject++;
|
||||
}
|
||||
/* create some dynamically created objects as examples */
|
||||
if (!object_table) {
|
||||
pObject = Object_Table;
|
||||
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
|
||||
if (pObject->Object_Create) {
|
||||
pObject->Object_Create(BACNET_MAX_INSTANCE);
|
||||
}
|
||||
pObject++;
|
||||
}
|
||||
}
|
||||
#if (BACNET_PROTOCOL_REVISION >= 14)
|
||||
Channel_Write_Property_Internal_Callback_Set(Device_Write_Property);
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,882 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||
* @date May 2024
|
||||
* @brief Structured View object is an object that provides a container
|
||||
* to hold references to subordinate objects, which may include other
|
||||
* Structured View objects, thereby allowing multilevel hierarchies
|
||||
* to be created.
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
/* BACnet Stack defines - first */
|
||||
#include "bacnet/bacdef.h"
|
||||
/* BACnet Stack API */
|
||||
#include "bacnet/bacdcode.h"
|
||||
#include "bacnet/bacerror.h"
|
||||
#include "bacnet/bacapp.h"
|
||||
#include "bacnet/bactext.h"
|
||||
#include "bacnet/apdu.h"
|
||||
#include "bacnet/npdu.h"
|
||||
#include "bacnet/abort.h"
|
||||
#include "bacnet/proplist.h"
|
||||
#include "bacnet/reject.h"
|
||||
#include "bacnet/rp.h"
|
||||
#include "bacnet/basic/services.h"
|
||||
#include "bacnet/basic/sys/keylist.h"
|
||||
/* me! */
|
||||
#include "structured_view.h"
|
||||
|
||||
struct object_data {
|
||||
const char *Object_Name;
|
||||
const char *Description;
|
||||
BACNET_NODE_TYPE Node_Type;
|
||||
const char *Node_Subtype;
|
||||
BACNET_SUBORDINATE_DATA *Subordinate_List;
|
||||
BACNET_RELATIONSHIP Default_Subordinate_Relationship;
|
||||
BACNET_DEVICE_OBJECT_REFERENCE Represents;
|
||||
};
|
||||
|
||||
/* Key List for storing the object data sorted by instance number */
|
||||
static OS_Keylist Object_List;
|
||||
|
||||
/* clang-format off */
|
||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||
static const int Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE,
|
||||
PROP_NODE_TYPE, PROP_SUBORDINATE_LIST,
|
||||
-1
|
||||
};
|
||||
|
||||
static const int Properties_Optional[] = {
|
||||
PROP_DESCRIPTION, PROP_NODE_SUBTYPE, PROP_SUBORDINATE_ANNOTATIONS,
|
||||
PROP_SUBORDINATE_NODE_TYPES, PROP_SUBORDINATE_RELATIONSHIPS,
|
||||
PROP_DEFAULT_SUBORDINATE_RELATIONSHIP,
|
||||
PROP_REPRESENTS,
|
||||
-1
|
||||
};
|
||||
|
||||
static const int Properties_Proprietary[] = {
|
||||
-1
|
||||
};
|
||||
|
||||
/* standard properties that are arrays for this object,
|
||||
but not necessary supported in this object */
|
||||
static const int BACnetARRAY_Properties[] = {
|
||||
PROP_SUBORDINATE_LIST, PROP_SUBORDINATE_ANNOTATIONS, PROP_SUBORDINATE_TAGS,
|
||||
PROP_SUBORDINATE_NODE_TYPES, PROP_SUBORDINATE_RELATIONSHIPS, PROP_TAGS,
|
||||
-1
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/**
|
||||
* Returns the list of required, optional, and proprietary properties.
|
||||
* Used by ReadPropertyMultiple service.
|
||||
*
|
||||
* @param pRequired - pointer to list of int terminated by -1, of
|
||||
* BACnet required properties for this object.
|
||||
* @param pOptional - pointer to list of int terminated by -1, of
|
||||
* BACnet optkional properties for this object.
|
||||
* @param pProprietary - pointer to list of int terminated by -1, of
|
||||
* BACnet proprietary properties for this object.
|
||||
*/
|
||||
void Structured_View_Property_Lists(
|
||||
const int **pRequired, const int **pOptional, const int **pProprietary)
|
||||
{
|
||||
if (pRequired) {
|
||||
*pRequired = Properties_Required;
|
||||
}
|
||||
if (pOptional) {
|
||||
*pOptional = Properties_Optional;
|
||||
}
|
||||
if (pProprietary) {
|
||||
*pProprietary = Properties_Proprietary;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a given Structured View instance is valid
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
*
|
||||
* @return true if the instance is valid, and false if not
|
||||
*/
|
||||
bool Structured_View_Valid_Instance(uint32_t object_instance)
|
||||
{
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the number of Structured View objects
|
||||
*
|
||||
* @return Number of Structured View objects
|
||||
*/
|
||||
unsigned Structured_View_Count(void)
|
||||
{
|
||||
return Keylist_Count(Object_List);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the object instance-number for a given 0..(N-1) index
|
||||
* of Structured View objects where N is Structured_View_Count().
|
||||
*
|
||||
* @param index - 0..(N-1) where N is Structured_View_Count()
|
||||
*
|
||||
* @return object instance-number for the given index
|
||||
*/
|
||||
uint32_t Structured_View_Index_To_Instance(unsigned index)
|
||||
{
|
||||
KEY key = UINT32_MAX;
|
||||
|
||||
Keylist_Index_Key(Object_List, index, &key);
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, determines a 0..(N-1) index
|
||||
* of Structured View objects where N is Structured_View_Count().
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
*
|
||||
* @return index for the given instance-number, or Structured_View_Count()
|
||||
* if not valid.
|
||||
*/
|
||||
unsigned Structured_View_Instance_To_Index(uint32_t object_instance)
|
||||
{
|
||||
return Keylist_Index(Object_List, object_instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, loads the object-name into
|
||||
* a characterstring. Note that the object name must be unique
|
||||
* within this device.
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param object_name - holds the object-name retrieved
|
||||
*
|
||||
* @return true if object-name was retrieved
|
||||
*/
|
||||
bool Structured_View_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
bool status = false;
|
||||
struct object_data *pObject;
|
||||
char name_text[24] = "Structured-View-4194303";
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
if (pObject->Object_Name) {
|
||||
status =
|
||||
characterstring_init_ansi(object_name, pObject->Object_Name);
|
||||
} else {
|
||||
snprintf(
|
||||
name_text, sizeof(name_text), "Structured-View-%u",
|
||||
object_instance);
|
||||
status = characterstring_init_ansi(object_name, name_text);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, sets the object-name
|
||||
* Note that the object name must be unique within this device.
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param new_name - holds the object-name to be set
|
||||
*
|
||||
* @return true if object-name was set
|
||||
*/
|
||||
bool Structured_View_Name_Set(uint32_t object_instance, char *new_name)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject && new_name) {
|
||||
status = true;
|
||||
pObject->Object_Name = new_name;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, returns the description
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
*
|
||||
* @return description text or NULL if not found
|
||||
*/
|
||||
char *Structured_View_Description(uint32_t object_instance)
|
||||
{
|
||||
char *name = NULL;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
if (pObject->Description) {
|
||||
name = (char *)pObject->Description;
|
||||
} else {
|
||||
name = "";
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, sets the description
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param new_name - holds the description to be set
|
||||
*
|
||||
* @return true if object-name was set
|
||||
*/
|
||||
bool Structured_View_Description_Set(uint32_t object_instance, char *new_name)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
status = true;
|
||||
pObject->Description = new_name;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the Node_Type
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return Node_Type or BACNET_NODE_UNKNOWN if not found
|
||||
*/
|
||||
BACNET_NODE_TYPE Structured_View_Node_Type(uint32_t object_instance)
|
||||
{
|
||||
BACNET_NODE_TYPE node_type = BACNET_NODE_UNKNOWN;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
node_type = pObject->Node_Type;
|
||||
}
|
||||
|
||||
return node_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, sets the Node_Type
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param node_type - holds the Node_Type to be set
|
||||
* @return true if Node_Type was set
|
||||
*/
|
||||
bool Structured_View_Node_Type_Set(
|
||||
uint32_t object_instance, BACNET_NODE_TYPE node_type)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
status = true;
|
||||
pObject->Node_Type = node_type;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the Node_Subtype
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return Node_Subtype text or NULL if not found
|
||||
*/
|
||||
char *Structured_View_Node_Subtype(uint32_t object_instance)
|
||||
{
|
||||
char *name = NULL;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
if (pObject->Description) {
|
||||
name = (char *)pObject->Node_Subtype;
|
||||
} else {
|
||||
name = "";
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, sets the Node_Subtype
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param new_name - holds the Node_Subtype to be set
|
||||
* @return true if Node_Subtype was set
|
||||
*/
|
||||
bool Structured_View_Node_Subtype_Set(uint32_t object_instance, char *new_name)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
status = true;
|
||||
pObject->Description = new_name;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the Subordinate_List
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return Subordinate_List or NULL if not found
|
||||
*/
|
||||
BACNET_SUBORDINATE_DATA *
|
||||
Structured_View_Subordinate_List(uint32_t object_instance)
|
||||
{
|
||||
BACNET_SUBORDINATE_DATA *subordinate_list = NULL;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
subordinate_list = pObject->Subordinate_List;
|
||||
}
|
||||
|
||||
return subordinate_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, sets the Subordinate_List
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param subordinate_list - holds the Subordinate_List to be set
|
||||
*/
|
||||
void Structured_View_Subordinate_List_Set(
|
||||
uint32_t object_instance, BACNET_SUBORDINATE_DATA *subordinate_list)
|
||||
{
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
pObject->Subordinate_List = subordinate_list;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the
|
||||
* Default_Subordinate_Relationship
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return Default_Subordinate_Relationship or BACNET_RELATIONSHIP_DEFAULT if
|
||||
* not found
|
||||
*/
|
||||
BACNET_RELATIONSHIP
|
||||
Structured_View_Default_Subordinate_Relationship(uint32_t object_instance)
|
||||
{
|
||||
BACNET_RELATIONSHIP relationship = BACNET_RELATIONSHIP_DEFAULT;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
relationship = pObject->Default_Subordinate_Relationship;
|
||||
}
|
||||
|
||||
return relationship;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, sets the
|
||||
* Default_Subordinate_Relationship
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param relationship - holds the Default_Subordinate_Relationship to be set
|
||||
* @return true if Default_Subordinate_Relationship was set
|
||||
*/
|
||||
bool Structured_View_Default_Subordinate_Relationship_Set(
|
||||
uint32_t object_instance, BACNET_RELATIONSHIP relationship)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
status = true;
|
||||
pObject->Default_Subordinate_Relationship = relationship;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the Represents
|
||||
* property value
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return Represents or NULL if not found
|
||||
*/
|
||||
BACNET_DEVICE_OBJECT_REFERENCE *
|
||||
Structured_View_Represents(uint32_t object_instance)
|
||||
{
|
||||
BACNET_DEVICE_OBJECT_REFERENCE *represents = NULL;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
represents = &pObject->Represents;
|
||||
}
|
||||
|
||||
return represents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, sets the Represents
|
||||
* property value
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param represents - holds the Represents to be set
|
||||
* @return true if Represents was set
|
||||
*/
|
||||
bool Structured_View_Represents_Set(
|
||||
uint32_t object_instance, BACNET_DEVICE_OBJECT_REFERENCE *represents)
|
||||
{
|
||||
bool status = false; /* return value */
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
status = true;
|
||||
pObject->Represents = *represents;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the number of
|
||||
* Subordinate_List elements
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return number of Subordinate_List elements
|
||||
*/
|
||||
unsigned int Structured_View_Subordinate_List_Count(uint32_t object_instance)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
BACNET_SUBORDINATE_DATA *subordinate_list = NULL;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
subordinate_list = pObject->Subordinate_List;
|
||||
while (subordinate_list) {
|
||||
count++;
|
||||
subordinate_list = subordinate_list->next;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the number of
|
||||
* Subordinate_List elements
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param array_index [in] array index requested:
|
||||
* 0 to N for individual array members
|
||||
* @return Subordinate_List element or NULL if not found
|
||||
*/
|
||||
BACNET_SUBORDINATE_DATA *Structured_View_Subordinate_List_Member(
|
||||
uint32_t object_instance, BACNET_ARRAY_INDEX array_index)
|
||||
{
|
||||
BACNET_ARRAY_INDEX index = 0;
|
||||
BACNET_SUBORDINATE_DATA *subordinate_list = NULL;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
subordinate_list = pObject->Subordinate_List;
|
||||
while (subordinate_list) {
|
||||
if (index == array_index) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
subordinate_list = subordinate_list->next;
|
||||
}
|
||||
}
|
||||
|
||||
return subordinate_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode a BACnetARRAY property element
|
||||
* @param object_instance [in] BACnet network port object instance number
|
||||
* @param array_index [in] array index requested:
|
||||
* 0 to N for individual array members
|
||||
* @param apdu [out] Buffer in which the APDU contents are built, or NULL to
|
||||
* return the length of buffer if it had been built
|
||||
* @return The length of the apdu encoded or
|
||||
* BACNET_STATUS_ERROR for ERROR_CODE_INVALID_ARRAY_INDEX
|
||||
*/
|
||||
int Structured_View_Subordinate_List_Element_Encode(
|
||||
uint32_t object_instance, BACNET_ARRAY_INDEX array_index, uint8_t *apdu)
|
||||
{
|
||||
int apdu_len = BACNET_STATUS_ERROR;
|
||||
BACNET_DEVICE_OBJECT_REFERENCE value = { 0 };
|
||||
BACNET_SUBORDINATE_DATA *subordinate_list = NULL;
|
||||
|
||||
subordinate_list =
|
||||
Structured_View_Subordinate_List_Member(object_instance, array_index);
|
||||
if (subordinate_list) {
|
||||
/* BACnetDeviceObjectReference */
|
||||
value.deviceIdentifier.type = OBJECT_DEVICE;
|
||||
value.deviceIdentifier.instance = subordinate_list->Device_Instance;
|
||||
value.objectIdentifier.type = subordinate_list->Object_Type;
|
||||
value.objectIdentifier.instance = subordinate_list->Object_Instance;
|
||||
apdu_len = bacapp_encode_device_obj_ref(apdu, &value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode a BACnetARRAY property element
|
||||
* @param object_instance [in] BACnet network port object instance number
|
||||
* @param array_index [in] array index requested:
|
||||
* 0 to N for individual array members
|
||||
* @param apdu [out] Buffer in which the APDU contents are built, or NULL to
|
||||
* return the length of buffer if it had been built
|
||||
* @return The length of the apdu encoded or
|
||||
* BACNET_STATUS_ERROR for ERROR_CODE_INVALID_ARRAY_INDEX
|
||||
*/
|
||||
int Structured_View_Subordinate_Annotations_Element_Encode(
|
||||
uint32_t object_instance, BACNET_ARRAY_INDEX array_index, uint8_t *apdu)
|
||||
{
|
||||
int apdu_len = BACNET_STATUS_ERROR;
|
||||
BACNET_CHARACTER_STRING value = { 0 };
|
||||
BACNET_SUBORDINATE_DATA *subordinate_list = NULL;
|
||||
|
||||
subordinate_list =
|
||||
Structured_View_Subordinate_List_Member(object_instance, array_index);
|
||||
if (subordinate_list) {
|
||||
/* BACnetCharacterString */
|
||||
characterstring_init_ansi(&value, subordinate_list->Annotations);
|
||||
apdu_len = encode_application_character_string(apdu, &value);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode a BACnetARRAY property element
|
||||
* @param object_instance [in] BACnet network port object instance number
|
||||
* @param array_index [in] array index requested:
|
||||
* 0 to N for individual array members
|
||||
* @param apdu [out] Buffer in which the APDU contents are built, or NULL to
|
||||
* return the length of buffer if it had been built
|
||||
* @return The length of the apdu encoded or
|
||||
* BACNET_STATUS_ERROR for ERROR_CODE_INVALID_ARRAY_INDEX
|
||||
*/
|
||||
int Structured_View_Subordinate_Node_Types_Element_Encode(
|
||||
uint32_t object_instance, BACNET_ARRAY_INDEX array_index, uint8_t *apdu)
|
||||
{
|
||||
int apdu_len = BACNET_STATUS_ERROR;
|
||||
BACNET_SUBORDINATE_DATA *subordinate_list = NULL;
|
||||
|
||||
subordinate_list =
|
||||
Structured_View_Subordinate_List_Member(object_instance, array_index);
|
||||
if (subordinate_list) {
|
||||
/* BACnetNodeType */
|
||||
apdu_len =
|
||||
encode_application_enumerated(apdu, subordinate_list->Node_Type);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode a BACnetARRAY property element
|
||||
* @param object_instance [in] BACnet network port object instance number
|
||||
* @param array_index [in] array index requested:
|
||||
* 0 to N for individual array members
|
||||
* @param apdu [out] Buffer in which the APDU contents are built, or NULL to
|
||||
* return the length of buffer if it had been built
|
||||
* @return The length of the apdu encoded or
|
||||
* BACNET_STATUS_ERROR for ERROR_CODE_INVALID_ARRAY_INDEX
|
||||
*/
|
||||
int Structured_View_Subordinate_Relationships_Element_Encode(
|
||||
uint32_t object_instance, BACNET_ARRAY_INDEX array_index, uint8_t *apdu)
|
||||
{
|
||||
int apdu_len = BACNET_STATUS_ERROR;
|
||||
BACNET_SUBORDINATE_DATA *subordinate_list = NULL;
|
||||
|
||||
subordinate_list =
|
||||
Structured_View_Subordinate_List_Member(object_instance, array_index);
|
||||
if (subordinate_list) {
|
||||
/* BACnetRelationship */
|
||||
apdu_len =
|
||||
encode_application_enumerated(apdu, subordinate_list->Relationship);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Determine if the object property is a BACnetARRAY property
|
||||
* @param object_property - object-property to be checked
|
||||
* @return true if the property is a BACnetARRAY property
|
||||
*/
|
||||
static bool BACnetARRAY_Property(int object_property)
|
||||
{
|
||||
return property_list_member(BACnetARRAY_Properties, object_property);
|
||||
}
|
||||
|
||||
/**
|
||||
* ReadProperty handler for this object. For the given ReadProperty
|
||||
* data, the application_data is loaded or the error flags are set.
|
||||
*
|
||||
* @param rpdata - BACNET_READ_PROPERTY_DATA data, including
|
||||
* requested data and space for the reply, or error response.
|
||||
*
|
||||
* @return number of APDU bytes in the response, or
|
||||
* BACNET_STATUS_ERROR on error.
|
||||
*/
|
||||
int Structured_View_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
{
|
||||
int apdu_len = 0; /* return value */
|
||||
BACNET_CHARACTER_STRING char_string;
|
||||
uint32_t count = 0;
|
||||
uint8_t *apdu = NULL;
|
||||
uint16_t apdu_max = 0;
|
||||
|
||||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
|
||||
(rpdata->application_data_len == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
apdu = rpdata->application_data;
|
||||
apdu_max = rpdata->application_data_len;
|
||||
switch (rpdata->object_property) {
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
apdu_len = encode_application_object_id(
|
||||
&apdu[0], rpdata->object_type, rpdata->object_instance);
|
||||
break;
|
||||
case PROP_OBJECT_NAME:
|
||||
Structured_View_Object_Name(rpdata->object_instance, &char_string);
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_OBJECT_TYPE:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0], rpdata->object_type);
|
||||
break;
|
||||
case PROP_NODE_TYPE:
|
||||
apdu_len = encode_application_enumerated(
|
||||
&apdu[0], Structured_View_Node_Type(rpdata->object_instance));
|
||||
break;
|
||||
case PROP_SUBORDINATE_LIST:
|
||||
count =
|
||||
Structured_View_Subordinate_List_Count(rpdata->object_instance);
|
||||
apdu_len = bacnet_array_encode(
|
||||
rpdata->object_instance, rpdata->array_index,
|
||||
Structured_View_Subordinate_List_Element_Encode, count, apdu,
|
||||
apdu_max);
|
||||
if (apdu_len == BACNET_STATUS_ABORT) {
|
||||
rpdata->error_code =
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
} else if (apdu_len == BACNET_STATUS_ERROR) {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
||||
}
|
||||
break;
|
||||
case PROP_DESCRIPTION:
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
Structured_View_Description(rpdata->object_instance));
|
||||
apdu_len = encode_application_character_string(apdu, &char_string);
|
||||
break;
|
||||
case PROP_NODE_SUBTYPE:
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
Structured_View_Node_Subtype(rpdata->object_instance));
|
||||
apdu_len = encode_application_character_string(apdu, &char_string);
|
||||
break;
|
||||
case PROP_SUBORDINATE_ANNOTATIONS:
|
||||
count =
|
||||
Structured_View_Subordinate_List_Count(rpdata->object_instance);
|
||||
apdu_len = bacnet_array_encode(
|
||||
rpdata->object_instance, rpdata->array_index,
|
||||
Structured_View_Subordinate_Annotations_Element_Encode, count,
|
||||
apdu, apdu_max);
|
||||
if (apdu_len == BACNET_STATUS_ABORT) {
|
||||
rpdata->error_code =
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
} else if (apdu_len == BACNET_STATUS_ERROR) {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
||||
}
|
||||
break;
|
||||
case PROP_SUBORDINATE_NODE_TYPES:
|
||||
count =
|
||||
Structured_View_Subordinate_List_Count(rpdata->object_instance);
|
||||
apdu_len = bacnet_array_encode(
|
||||
rpdata->object_instance, rpdata->array_index,
|
||||
Structured_View_Subordinate_Node_Types_Element_Encode, count,
|
||||
apdu, apdu_max);
|
||||
if (apdu_len == BACNET_STATUS_ABORT) {
|
||||
rpdata->error_code =
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
} else if (apdu_len == BACNET_STATUS_ERROR) {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
||||
}
|
||||
break;
|
||||
case PROP_SUBORDINATE_RELATIONSHIPS:
|
||||
count =
|
||||
Structured_View_Subordinate_List_Count(rpdata->object_instance);
|
||||
apdu_len = bacnet_array_encode(
|
||||
rpdata->object_instance, rpdata->array_index,
|
||||
Structured_View_Subordinate_Relationships_Element_Encode, count,
|
||||
apdu, apdu_max);
|
||||
if (apdu_len == BACNET_STATUS_ABORT) {
|
||||
rpdata->error_code =
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
} else if (apdu_len == BACNET_STATUS_ERROR) {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
||||
}
|
||||
break;
|
||||
case PROP_DEFAULT_SUBORDINATE_RELATIONSHIP:
|
||||
apdu_len = encode_application_enumerated(
|
||||
&apdu[0],
|
||||
Structured_View_Default_Subordinate_Relationship(
|
||||
rpdata->object_instance));
|
||||
break;
|
||||
case PROP_REPRESENTS:
|
||||
apdu_len = bacapp_encode_device_obj_ref(
|
||||
&apdu[0], Structured_View_Represents(rpdata->object_instance));
|
||||
break;
|
||||
default:
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
break;
|
||||
}
|
||||
/* only array properties can have array options */
|
||||
if ((apdu_len >= 0) && (!BACnetARRAY_Property(rpdata->object_property)) &&
|
||||
(rpdata->array_index != BACNET_ARRAY_ALL)) {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Structured View object
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return object_instance if the object is created, else BACNET_MAX_INSTANCE
|
||||
*/
|
||||
uint32_t Structured_View_Create(uint32_t object_instance)
|
||||
{
|
||||
struct object_data *pObject = NULL;
|
||||
int index = 0;
|
||||
|
||||
if (object_instance > BACNET_MAX_INSTANCE) {
|
||||
return BACNET_MAX_INSTANCE;
|
||||
} else if (object_instance == BACNET_MAX_INSTANCE) {
|
||||
/* wildcard instance */
|
||||
/* the Object_Identifier property of the newly created object
|
||||
shall be initialized to a value that is unique within the
|
||||
responding BACnet-user device. The method used to generate
|
||||
the object identifier is a local matter.*/
|
||||
object_instance = Keylist_Next_Empty_Key(Object_List, 1);
|
||||
}
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (!pObject) {
|
||||
pObject = calloc(1, sizeof(struct object_data));
|
||||
if (!pObject) {
|
||||
return BACNET_MAX_INSTANCE;
|
||||
}
|
||||
pObject->Object_Name = NULL;
|
||||
pObject->Description = NULL;
|
||||
pObject->Node_Subtype = NULL;
|
||||
pObject->Subordinate_List = NULL;
|
||||
pObject->Default_Subordinate_Relationship = BACNET_RELATIONSHIP_DEFAULT;
|
||||
pObject->Represents.deviceIdentifier.type = OBJECT_NONE;
|
||||
pObject->Represents.deviceIdentifier.instance = BACNET_MAX_INSTANCE;
|
||||
pObject->Represents.objectIdentifier.type = OBJECT_DEVICE;
|
||||
pObject->Represents.objectIdentifier.instance = BACNET_MAX_INSTANCE;
|
||||
pObject->Node_Type = BACNET_NODE_UNKNOWN;
|
||||
/* add to list */
|
||||
index = Keylist_Data_Add(Object_List, object_instance, pObject);
|
||||
if (index < 0) {
|
||||
free(pObject);
|
||||
return BACNET_MAX_INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
return object_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an Structured View object
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return true if the object is deleted
|
||||
*/
|
||||
bool Structured_View_Delete(uint32_t object_instance)
|
||||
{
|
||||
bool status = false;
|
||||
struct object_data *pObject = NULL;
|
||||
|
||||
pObject = Keylist_Data_Delete(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
free(pObject);
|
||||
status = true;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all the Time Values and their data
|
||||
*/
|
||||
void Structured_View_Cleanup(void)
|
||||
{
|
||||
struct object_data *pObject;
|
||||
|
||||
if (Object_List) {
|
||||
do {
|
||||
pObject = Keylist_Data_Pop(Object_List);
|
||||
if (pObject) {
|
||||
free(pObject);
|
||||
}
|
||||
} while (pObject);
|
||||
Keylist_Delete(Object_List);
|
||||
Object_List = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Structured View object data
|
||||
*/
|
||||
void Structured_View_Init(void)
|
||||
{
|
||||
Object_List = Keylist_Create();
|
||||
if (Object_List) {
|
||||
atexit(Structured_View_Cleanup);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* @file
|
||||
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||
* @date May 2024
|
||||
* @brief API for a Structured View object used by a BACnet device object
|
||||
* @section LICENSE
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef BACNET_STRUCTURED_VIEW_OBJECT_H
|
||||
#define BACNET_STRUCTURED_VIEW_OBJECT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
/* BACnet Stack defines - first */
|
||||
#include "bacnet/bacdef.h"
|
||||
/* BACnet Stack API */
|
||||
#include "bacnet/bacerror.h"
|
||||
#include "bacnet/bacstr.h"
|
||||
#include "bacnet/bacdevobjpropref.h"
|
||||
#include "bacnet/rp.h"
|
||||
|
||||
struct BACnetSubordinateData;
|
||||
typedef struct BACnetSubordinateData {
|
||||
uint32_t Device_Instance;
|
||||
BACNET_OBJECT_TYPE Object_Type;
|
||||
uint32_t Object_Instance;
|
||||
const char *Annotations;
|
||||
BACNET_NODE_TYPE Node_Type;
|
||||
BACNET_RELATIONSHIP Relationship;
|
||||
/* simple linked list */
|
||||
struct BACnetSubordinateData *next;
|
||||
} BACNET_SUBORDINATE_DATA;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void Structured_View_Property_Lists(
|
||||
const int **pRequired, const int **pOptional, const int **pProprietary);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Structured_View_Valid_Instance(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
unsigned Structured_View_Count(void);
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t Structured_View_Index_To_Instance(unsigned index);
|
||||
BACNET_STACK_EXPORT
|
||||
unsigned Structured_View_Instance_To_Index(uint32_t object_instance);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Structured_View_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Structured_View_Name_Set(uint32_t object_instance, char *new_name);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
int Structured_View_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
char *Structured_View_Description(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Structured_View_Description_Set(uint32_t object_instance, char *new_name);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
BACNET_NODE_TYPE Structured_View_Node_Type(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Structured_View_Node_Type_Set(
|
||||
uint32_t object_instance, BACNET_NODE_TYPE node_type);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
char *Structured_View_Node_Subtype(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Structured_View_Node_Subtype_Set(uint32_t object_instance, char *new_name);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
BACNET_SUBORDINATE_DATA *
|
||||
Structured_View_Subordinate_List(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
void Structured_View_Subordinate_List_Set(
|
||||
uint32_t object_instance, BACNET_SUBORDINATE_DATA *subordinate_list);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
BACNET_RELATIONSHIP
|
||||
Structured_View_Default_Subordinate_Relationship(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Structured_View_Default_Subordinate_Relationship_Set(
|
||||
uint32_t object_instance, BACNET_RELATIONSHIP relationship);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
BACNET_DEVICE_OBJECT_REFERENCE *
|
||||
Structured_View_Represents(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Structured_View_Represents_Set(
|
||||
uint32_t object_instance, BACNET_DEVICE_OBJECT_REFERENCE *represents);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint32_t Structured_View_Create(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Structured_View_Delete(uint32_t object_instance);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void Structured_View_Cleanup(void);
|
||||
BACNET_STACK_EXPORT
|
||||
void Structured_View_Init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
Reference in New Issue
Block a user