From af5d5290013444b4506c06a2b7e14fbec38d5de5 Mon Sep 17 00:00:00 2001 From: skarg Date: Mon, 14 Jan 2013 16:29:42 +0000 Subject: [PATCH] Fixed write-property to object-name property in demo application to fix for BTL 135.1-2009-9.22.2.8 - Reading an object name and writing it straight back gives a 'duplicate name' error. Thank you, Ed! --- bacnet-stack/demo/object/device.c | 23 +++++++++++++++-------- bacnet-stack/demo/object/ms-input.c | 29 ++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index c4b479ef..334cc7e9 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -1425,6 +1425,8 @@ bool Device_Write_Property_Local( bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; + int object_type = 0; + uint32_t object_instance = 0; int temp; /* decode the some of the request */ @@ -1515,15 +1517,20 @@ bool Device_Write_Property_Local( characterstring_capacity(&My_Object_Name), false, &wp_data->error_class, &wp_data->error_code); if (status) { - /* All the object names in a device must be unique. - Disallow setting the Device Object Name to any objects in - the device. */ + /* All the object names in a device must be unique */ if (Device_Valid_Object_Name(&value.type.Character_String, - NULL, NULL)) { - status = false; - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; - } else { + &object_type, &object_instance)) { + if ((object_type == wp_data->object_type) && + (object_instance == wp_data->object_instance)) { + /* okay to set my name as the same name */ + status = true; + } else { + status = false; + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; + } + } + if (status) { Device_Set_Object_Name(&value.type.Character_String); } } diff --git a/bacnet-stack/demo/object/ms-input.c b/bacnet-stack/demo/object/ms-input.c index c9f853b5..0dbf498e 100644 --- a/bacnet-stack/demo/object/ms-input.c +++ b/bacnet-stack/demo/object/ms-input.c @@ -35,6 +35,7 @@ #include "config.h" /* the custom stuff */ #include "rp.h" #include "wp.h" +#include "device.h" #include "ms-input.h" #include "handlers.h" @@ -623,6 +624,8 @@ bool Multistate_Input_Write_Property( BACNET_APPLICATION_DATA_VALUE value; uint32_t max_states = 0; uint32_t array_index = 0; + int object_type = 0; + uint32_t object_instance = 0; /* decode the first chunk of the request */ len = @@ -645,11 +648,27 @@ bool Multistate_Input_Write_Property( switch (wp_data->object_property) { case PROP_OBJECT_NAME: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - status = Multistate_Input_Object_Name_Write( - wp_data->object_instance, - &value.type.Character_String, - &wp_data->error_class, - &wp_data->error_code); + /* All the object names in a device must be unique */ + if (Device_Valid_Object_Name(&value.type.Character_String, + &object_type, &object_instance)) { + if ((object_type == wp_data->object_type) && + (object_instance == wp_data->object_instance)) { + status = true; + } else { + status = false; + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; + } + } else { + status = true; + } + if (status) { + status = Multistate_Input_Object_Name_Write( + wp_data->object_instance, + &value.type.Character_String, + &wp_data->error_class, + &wp_data->error_code); + } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;