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:
@@ -94,6 +94,36 @@ bool bacnet_recipient_same(
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the BACnetRecipient complex data to a device
|
||||
* @param dest - BACnetRecipient structure
|
||||
* @param object_type - BACnetObjectType enumeration value
|
||||
* @param instance - BACnetObjectInstance value
|
||||
*/
|
||||
void bacnet_recipient_device_set(
|
||||
BACNET_RECIPIENT *dest, BACNET_OBJECT_TYPE object_type, uint32_t instance)
|
||||
{
|
||||
if (dest) {
|
||||
dest->tag = BACNET_RECIPIENT_TAG_DEVICE;
|
||||
dest->type.device.type = object_type;
|
||||
dest->type.device.instance = instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the BACnetRecipient complex data to an address
|
||||
* @param dest - BACnetRecipient structure
|
||||
* @param address - BACnetAddress structure
|
||||
*/
|
||||
void bacnet_recipient_address_set(
|
||||
BACNET_RECIPIENT *dest, const BACNET_ADDRESS *address)
|
||||
{
|
||||
if (dest && address) {
|
||||
dest->tag = BACNET_RECIPIENT_TAG_ADDRESS;
|
||||
bacnet_address_copy(&dest->type.address, address);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copy the BACnetRecipient complex data from src to dest
|
||||
* @param src - BACnetRecipient 1 structure
|
||||
|
||||
@@ -82,6 +82,12 @@ void bacnet_destination_copy(
|
||||
BACNET_DESTINATION *dest, const BACNET_DESTINATION *src);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void bacnet_recipient_device_set(
|
||||
BACNET_RECIPIENT *dest, BACNET_OBJECT_TYPE object_type, uint32_t instance);
|
||||
BACNET_STACK_EXPORT
|
||||
void bacnet_recipient_address_set(
|
||||
BACNET_RECIPIENT *dest, const BACNET_ADDRESS *address);
|
||||
BACNET_STACK_EXPORT
|
||||
void bacnet_recipient_copy(BACNET_RECIPIENT *dest, const BACNET_RECIPIENT *src);
|
||||
BACNET_STACK_EXPORT
|
||||
bool bacnet_recipient_same(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -23,7 +23,9 @@ extern "C" {
|
||||
#define NC_RESCAN_RECIPIENTS_SECS 60
|
||||
|
||||
/* max "length" of recipient_list */
|
||||
#ifndef NC_MAX_RECIPIENTS
|
||||
#define NC_MAX_RECIPIENTS 10
|
||||
#endif
|
||||
|
||||
#if defined(INTRINSIC_REPORTING)
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ void handler_add_list_element(
|
||||
status = false;
|
||||
}
|
||||
if (status) {
|
||||
if (Device_Add_List_Element(&list_element)) {
|
||||
if (Device_Add_List_Element(&list_element) >= 0) {
|
||||
len = encode_simple_ack(
|
||||
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
|
||||
SERVICE_CONFIRMED_ADD_LIST_ELEMENT);
|
||||
@@ -202,7 +202,7 @@ void handler_remove_list_element(
|
||||
status = false;
|
||||
}
|
||||
if (status) {
|
||||
if (Device_Remove_List_Element(&list_element)) {
|
||||
if (Device_Remove_List_Element(&list_element) >= 0) {
|
||||
len = encode_simple_ack(
|
||||
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
|
||||
SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT);
|
||||
|
||||
@@ -143,6 +143,7 @@ int list_element_decode_service_request(
|
||||
len += decode_object_id(&apdu[len], &object_type, &object_instance);
|
||||
if (list_element) {
|
||||
list_element->object_type = object_type;
|
||||
list_element->object_instance = object_instance;
|
||||
}
|
||||
/* Tag 1: Property ID */
|
||||
len +=
|
||||
|
||||
Reference in New Issue
Block a user