Changed bacnet name duplicate check to allow to rewrite with the same name to the same object without duplicate name error.
This commit is contained in:
@@ -157,7 +157,7 @@ static bool bacnet_name_isvalid(
|
|||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool bacnet_name_save(
|
bool bacnet_name_save(
|
||||||
uint16_t offset,
|
uint16_t offset,
|
||||||
uint8_t encoding,
|
uint8_t encoding,
|
||||||
char *str,
|
char *str,
|
||||||
@@ -200,8 +200,10 @@ bool bacnet_name_set(
|
|||||||
return bacnet_name_save(offset, encoding, str, length);
|
return bacnet_name_save(offset, encoding, str, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bacnet_name_write(
|
bool bacnet_name_write_unique(
|
||||||
uint16_t offset,
|
uint16_t offset,
|
||||||
|
int object_type,
|
||||||
|
uint32_t object_instance,
|
||||||
BACNET_CHARACTER_STRING * char_string,
|
BACNET_CHARACTER_STRING * char_string,
|
||||||
BACNET_ERROR_CLASS * error_class,
|
BACNET_ERROR_CLASS * error_class,
|
||||||
BACNET_ERROR_CODE * error_code)
|
BACNET_ERROR_CODE * error_code)
|
||||||
@@ -209,18 +211,26 @@ bool bacnet_name_write(
|
|||||||
bool status = false;
|
bool status = false;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
uint8_t encoding = 0;
|
uint8_t encoding = 0;
|
||||||
|
int duplicate_type = 0;
|
||||||
|
uint32_t duplicate_instance = 0;
|
||||||
|
|
||||||
length = characterstring_length(char_string);
|
length = characterstring_length(char_string);
|
||||||
|
|
||||||
if (length < 1) {
|
if (length < 1) {
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||||
} else if (length <= NV_EEPROM_NAME_SIZE) {
|
} else if (length <= NV_EEPROM_NAME_SIZE) {
|
||||||
encoding = characterstring_encoding(char_string);
|
encoding = characterstring_encoding(char_string);
|
||||||
if (encoding < MAX_CHARACTER_STRING_ENCODING) {
|
if (encoding < MAX_CHARACTER_STRING_ENCODING) {
|
||||||
if (Device_Valid_Object_Name(char_string, NULL, NULL)) {
|
if (Device_Valid_Object_Name(char_string,
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
&duplicate_type, &duplicate_instance)) {
|
||||||
*error_code = ERROR_CODE_DUPLICATE_NAME;
|
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 {
|
} else {
|
||||||
status = bacnet_name_set(offset, char_string);
|
status = bacnet_name_set(offset, char_string);
|
||||||
if (status) {
|
if (status) {
|
||||||
@@ -243,7 +253,7 @@ bool bacnet_name_write(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* no required minumum length or duplicate checking */
|
/* no required minumum length or duplicate checking */
|
||||||
bool bacnet_name_write_other(
|
bool bacnet_name_write(
|
||||||
uint16_t offset,
|
uint16_t offset,
|
||||||
BACNET_CHARACTER_STRING * char_string,
|
BACNET_CHARACTER_STRING * char_string,
|
||||||
BACNET_ERROR_CLASS * error_class,
|
BACNET_ERROR_CLASS * error_class,
|
||||||
|
|||||||
@@ -37,17 +37,24 @@ extern "C" {
|
|||||||
void bacnet_name_init(
|
void bacnet_name_init(
|
||||||
uint16_t eeprom_offset,
|
uint16_t eeprom_offset,
|
||||||
char *default_string);
|
char *default_string);
|
||||||
|
bool bacnet_name_save(
|
||||||
|
uint16_t offset,
|
||||||
|
uint8_t encoding,
|
||||||
|
char *str,
|
||||||
|
uint8_t length);
|
||||||
void bacnet_name(
|
void bacnet_name(
|
||||||
uint16_t eeprom_offset,
|
uint16_t eeprom_offset,
|
||||||
BACNET_CHARACTER_STRING * char_string,
|
BACNET_CHARACTER_STRING * char_string,
|
||||||
char *default_string);
|
char *default_string);
|
||||||
bool bacnet_name_write(
|
bool bacnet_name_write_unique(
|
||||||
uint16_t offset,
|
uint16_t offset,
|
||||||
|
int object_type,
|
||||||
|
uint32_t object_instance,
|
||||||
BACNET_CHARACTER_STRING * char_string,
|
BACNET_CHARACTER_STRING * char_string,
|
||||||
BACNET_ERROR_CLASS * error_class,
|
BACNET_ERROR_CLASS * error_class,
|
||||||
BACNET_ERROR_CODE * error_code);
|
BACNET_ERROR_CODE * error_code);
|
||||||
/* no required minumum length or duplicate checking */
|
/* no required minumum length or duplicate checking */
|
||||||
bool bacnet_name_write_other(
|
bool bacnet_name_write(
|
||||||
uint16_t offset,
|
uint16_t offset,
|
||||||
BACNET_CHARACTER_STRING * char_string,
|
BACNET_CHARACTER_STRING * char_string,
|
||||||
BACNET_ERROR_CLASS * error_class,
|
BACNET_ERROR_CLASS * error_class,
|
||||||
|
|||||||
@@ -902,9 +902,12 @@ bool Device_Write_Property_Local(
|
|||||||
break;
|
break;
|
||||||
case PROP_OBJECT_NAME:
|
case PROP_OBJECT_NAME:
|
||||||
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||||
status =
|
status = bacnet_name_write_unique(
|
||||||
bacnet_name_write(NV_EEPROM_DEVICE_NAME,
|
NV_EEPROM_DEVICE_NAME,
|
||||||
&value.type.Character_String, &wp_data->error_class,
|
value.type.Object_Id.type,
|
||||||
|
value.type.Object_Id.instance,
|
||||||
|
&value.type.Character_String,
|
||||||
|
&wp_data->error_class,
|
||||||
&wp_data->error_code);
|
&wp_data->error_code);
|
||||||
} else {
|
} else {
|
||||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||||
@@ -914,7 +917,7 @@ bool Device_Write_Property_Local(
|
|||||||
case PROP_DESCRIPTION:
|
case PROP_DESCRIPTION:
|
||||||
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||||
status =
|
status =
|
||||||
bacnet_name_write_other(NV_EEPROM_DEVICE_DESCRIPTION,
|
bacnet_name_write(NV_EEPROM_DEVICE_DESCRIPTION,
|
||||||
&value.type.Character_String, &wp_data->error_class,
|
&value.type.Character_String, &wp_data->error_class,
|
||||||
&wp_data->error_code);
|
&wp_data->error_code);
|
||||||
} else {
|
} else {
|
||||||
@@ -925,7 +928,7 @@ bool Device_Write_Property_Local(
|
|||||||
case PROP_LOCATION:
|
case PROP_LOCATION:
|
||||||
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||||
status =
|
status =
|
||||||
bacnet_name_write_other(NV_EEPROM_DEVICE_LOCATION,
|
bacnet_name_write(NV_EEPROM_DEVICE_LOCATION,
|
||||||
&value.type.Character_String, &wp_data->error_class,
|
&value.type.Character_String, &wp_data->error_class,
|
||||||
&wp_data->error_code);
|
&wp_data->error_code);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user