From 35e953ba8b9cf54d3c3f1d77ea6e952c06e55078 Mon Sep 17 00:00:00 2001 From: skarg Date: Sat, 5 May 2012 03:28:34 +0000 Subject: [PATCH] Changed bacnet name duplicate check to allow to rewrite with the same name to the same object without duplicate name error. --- bacnet-stack/ports/bdk-atxx4-mstp/bname.c | 24 +++++++++++++++------- bacnet-stack/ports/bdk-atxx4-mstp/bname.h | 11 ++++++++-- bacnet-stack/ports/bdk-atxx4-mstp/device.c | 13 +++++++----- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bname.c b/bacnet-stack/ports/bdk-atxx4-mstp/bname.c index ac04cfe7..3108e851 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bname.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bname.c @@ -157,7 +157,7 @@ static bool bacnet_name_isvalid( return valid; } -static bool bacnet_name_save( +bool bacnet_name_save( uint16_t offset, uint8_t encoding, char *str, @@ -200,8 +200,10 @@ bool bacnet_name_set( return bacnet_name_save(offset, encoding, str, length); } -bool bacnet_name_write( +bool bacnet_name_write_unique( uint16_t offset, + int object_type, + uint32_t object_instance, BACNET_CHARACTER_STRING * char_string, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) @@ -209,18 +211,26 @@ bool bacnet_name_write( bool status = false; size_t length = 0; uint8_t encoding = 0; + int duplicate_type = 0; + uint32_t duplicate_instance = 0; length = characterstring_length(char_string); - if (length < 1) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } else if (length <= NV_EEPROM_NAME_SIZE) { encoding = characterstring_encoding(char_string); if (encoding < MAX_CHARACTER_STRING_ENCODING) { - if (Device_Valid_Object_Name(char_string, NULL, NULL)) { - *error_class = ERROR_CLASS_PROPERTY; - *error_code = ERROR_CODE_DUPLICATE_NAME; + if (Device_Valid_Object_Name(char_string, + &duplicate_type, &duplicate_instance)) { + if ((duplicate_type == object_type) && + (duplicate_instance == object_instance)) { + /* writing same name to same object */ + status = true; + } else { + *error_class = ERROR_CLASS_PROPERTY; + *error_code = ERROR_CODE_DUPLICATE_NAME; + } } else { status = bacnet_name_set(offset, char_string); if (status) { @@ -243,7 +253,7 @@ bool bacnet_name_write( } /* no required minumum length or duplicate checking */ -bool bacnet_name_write_other( +bool bacnet_name_write( uint16_t offset, BACNET_CHARACTER_STRING * char_string, BACNET_ERROR_CLASS * error_class, diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bname.h b/bacnet-stack/ports/bdk-atxx4-mstp/bname.h index 71c1b7f9..37d3be80 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bname.h +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bname.h @@ -37,17 +37,24 @@ extern "C" { void bacnet_name_init( uint16_t eeprom_offset, char *default_string); + bool bacnet_name_save( + uint16_t offset, + uint8_t encoding, + char *str, + uint8_t length); void bacnet_name( uint16_t eeprom_offset, BACNET_CHARACTER_STRING * char_string, char *default_string); - bool bacnet_name_write( + bool bacnet_name_write_unique( uint16_t offset, + int object_type, + uint32_t object_instance, BACNET_CHARACTER_STRING * char_string, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code); /* no required minumum length or duplicate checking */ - bool bacnet_name_write_other( + bool bacnet_name_write( uint16_t offset, BACNET_CHARACTER_STRING * char_string, BACNET_ERROR_CLASS * error_class, diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/device.c b/bacnet-stack/ports/bdk-atxx4-mstp/device.c index 1443ce29..13e0e674 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/device.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/device.c @@ -902,9 +902,12 @@ bool Device_Write_Property_Local( break; case PROP_OBJECT_NAME: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - status = - bacnet_name_write(NV_EEPROM_DEVICE_NAME, - &value.type.Character_String, &wp_data->error_class, + status = bacnet_name_write_unique( + NV_EEPROM_DEVICE_NAME, + value.type.Object_Id.type, + value.type.Object_Id.instance, + &value.type.Character_String, + &wp_data->error_class, &wp_data->error_code); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -914,7 +917,7 @@ bool Device_Write_Property_Local( case PROP_DESCRIPTION: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { status = - bacnet_name_write_other(NV_EEPROM_DEVICE_DESCRIPTION, + bacnet_name_write(NV_EEPROM_DEVICE_DESCRIPTION, &value.type.Character_String, &wp_data->error_class, &wp_data->error_code); } else { @@ -925,7 +928,7 @@ bool Device_Write_Property_Local( case PROP_LOCATION: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { status = - bacnet_name_write_other(NV_EEPROM_DEVICE_LOCATION, + bacnet_name_write(NV_EEPROM_DEVICE_LOCATION, &value.type.Character_String, &wp_data->error_class, &wp_data->error_code); } else {