Bugfix/issues 1082 AddListElement and RemoveListElement and Notification Class object (#1083)
* Fixed AddListElement and RemoveListElement which were checking the wrong return value from Device object. * Fixed decoding of ListElement Tag 0: Object ID instance. * Fixed Notification_Class_Add_List_Element() and Notification_Class_Remove_List_Element() element counter index, and empty slot detection. * Added bacnet_recipient_device_set() and bacnet_recipient_address_set() API * Added unit test coverage for Notification Class object.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* @file
|
||||
* @author Krzysztof Malorny <malornykrzysztof@gmail.com>
|
||||
* @author Ed Hague <edward@bac-test.com>
|
||||
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||
* @date 2011, 2018
|
||||
* @brief A basic BACnet Notification Class object
|
||||
* @copyright SPDX-License-Identifier: MIT
|
||||
@@ -38,28 +39,28 @@ static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES];
|
||||
static uint8_t Event_Buffer[MAX_APDU];
|
||||
|
||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||
static const int Notification_Properties_Required[] = {
|
||||
static const int Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME,
|
||||
PROP_OBJECT_TYPE, PROP_NOTIFICATION_CLASS,
|
||||
PROP_PRIORITY, PROP_ACK_REQUIRED,
|
||||
PROP_RECIPIENT_LIST, -1
|
||||
};
|
||||
|
||||
static const int Notification_Properties_Optional[] = { PROP_DESCRIPTION, -1 };
|
||||
static const int Properties_Optional[] = { PROP_DESCRIPTION, -1 };
|
||||
|
||||
static const int Notification_Properties_Proprietary[] = { -1 };
|
||||
static const int Properties_Proprietary[] = { -1 };
|
||||
|
||||
void Notification_Class_Property_Lists(
|
||||
const int **pRequired, const int **pOptional, const int **pProprietary)
|
||||
{
|
||||
if (pRequired) {
|
||||
*pRequired = Notification_Properties_Required;
|
||||
*pRequired = Properties_Required;
|
||||
}
|
||||
if (pOptional) {
|
||||
*pOptional = Notification_Properties_Optional;
|
||||
*pOptional = Properties_Optional;
|
||||
}
|
||||
if (pProprietary) {
|
||||
*pProprietary = Notification_Properties_Proprietary;
|
||||
*pProprietary = Properties_Proprietary;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -248,6 +249,7 @@ int Notification_Class_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
Destination = &CurrentNotify->Recipient_List[idx];
|
||||
Recipient = &Destination->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(Recipient)) {
|
||||
/* unused slot denoted by wildcard */
|
||||
apdu_len += bacnet_destination_encode(NULL, Destination);
|
||||
}
|
||||
}
|
||||
@@ -266,6 +268,7 @@ int Notification_Class_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
Destination = &CurrentNotify->Recipient_List[idx];
|
||||
Recipient = &Destination->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(Recipient)) {
|
||||
/* unused slot denoted by wildcard */
|
||||
apdu_len +=
|
||||
bacnet_destination_encode(&apdu[apdu_len], Destination);
|
||||
}
|
||||
@@ -428,19 +431,16 @@ bool Notification_Class_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
}
|
||||
status = true;
|
||||
break;
|
||||
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
case PROP_OBJECT_NAME:
|
||||
case PROP_OBJECT_TYPE:
|
||||
case PROP_DESCRIPTION:
|
||||
case PROP_NOTIFICATION_CLASS:
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
break;
|
||||
|
||||
default:
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
if (property_lists_member(
|
||||
Properties_Required, Properties_Optional,
|
||||
Properties_Proprietary, wp_data->object_property)) {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -673,6 +673,7 @@ void Notification_Class_common_reporting_function(
|
||||
pBacDest = &CurrentNotify->Recipient_List[0];
|
||||
for (index = 0; index < NC_MAX_RECIPIENTS; index++, pBacDest++) {
|
||||
if (bacnet_recipient_device_wildcard(&pBacDest->Recipient)) {
|
||||
/* unused slots denoted by wildcard */
|
||||
continue;
|
||||
}
|
||||
if (IsRecipientActive(pBacDest, event_data->toState)) {
|
||||
@@ -827,6 +828,7 @@ int Notification_Class_Add_List_Element(BACNET_LIST_ELEMENT_DATA *list_element)
|
||||
d1 = ¬ification->Recipient_List[index];
|
||||
r1 = &d1->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(r1)) {
|
||||
/* unused slots denoted by wildcard */
|
||||
element_count++;
|
||||
}
|
||||
}
|
||||
@@ -836,7 +838,8 @@ int Notification_Class_Add_List_Element(BACNET_LIST_ELEMENT_DATA *list_element)
|
||||
application_data_len = list_element->application_data_len;
|
||||
while (application_data_len > 0) {
|
||||
len = bacnet_destination_decode(
|
||||
application_data, application_data_len, &recipient_list[index]);
|
||||
application_data, application_data_len,
|
||||
&recipient_list[new_element_count]);
|
||||
if (len > 0) {
|
||||
new_element_count++;
|
||||
application_data_len -= len;
|
||||
@@ -907,7 +910,8 @@ int Notification_Class_Add_List_Element(BACNET_LIST_ELEMENT_DATA *list_element)
|
||||
BACNET_RECIPIENT *r2;
|
||||
d2 = ¬ification->Recipient_List[j];
|
||||
r2 = &d2->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(r2)) {
|
||||
if (bacnet_recipient_device_wildcard(r2)) {
|
||||
/* unused slot denoted by wildcard */
|
||||
bacnet_destination_copy(d2, d1);
|
||||
break;
|
||||
}
|
||||
@@ -984,6 +988,7 @@ int Notification_Class_Remove_List_Element(
|
||||
d1 = ¬ification->Recipient_List[index];
|
||||
r1 = &d1->Recipient;
|
||||
if (!bacnet_recipient_device_wildcard(r1)) {
|
||||
/* unused slot denoted by wildcard */
|
||||
element_count++;
|
||||
}
|
||||
}
|
||||
@@ -992,7 +997,8 @@ int Notification_Class_Remove_List_Element(
|
||||
application_data_len = list_element->application_data_len;
|
||||
while (application_data_len > 0) {
|
||||
len = bacnet_destination_decode(
|
||||
application_data, application_data_len, &recipient_list[index]);
|
||||
application_data, application_data_len,
|
||||
&recipient_list[remove_element_count]);
|
||||
if (len > 0) {
|
||||
remove_element_count++;
|
||||
application_data_len -= len;
|
||||
|
||||
Reference in New Issue
Block a user