From c0843c8134f72faff182c808f672a08a22a5a07e Mon Sep 17 00:00:00 2001 From: skarg Date: Tue, 8 Oct 2013 15:57:41 +0000 Subject: [PATCH] added channel object to proplist. Added unit test to proplist. --- bacnet-stack/include/proplist.h | 7 ++ bacnet-stack/src/proplist.c | 142 +++++++++++++++++++++++++++++++- bacnet-stack/test.mak | 7 +- 3 files changed, 152 insertions(+), 4 deletions(-) diff --git a/bacnet-stack/include/proplist.h b/bacnet-stack/include/proplist.h index 523a4364..2ef6e933 100644 --- a/bacnet-stack/include/proplist.h +++ b/bacnet-stack/include/proplist.h @@ -42,6 +42,13 @@ extern "C" { void property_list_special( BACNET_OBJECT_TYPE object_type, struct special_property_list_t *pPropertyList); + BACNET_PROPERTY_ID property_list_special_property( + BACNET_OBJECT_TYPE object_type, + BACNET_PROPERTY_ID special_property, + unsigned index); + unsigned property_list_special_count( + BACNET_OBJECT_TYPE object_type, + BACNET_PROPERTY_ID special_property); #ifdef __cplusplus } diff --git a/bacnet-stack/src/proplist.c b/bacnet-stack/src/proplist.c index 3e801182..dcec2710 100644 --- a/bacnet-stack/src/proplist.c +++ b/bacnet-stack/src/proplist.c @@ -408,6 +408,30 @@ static const int Calendar_Properties_Optional[] = { -1 }; +static const int Channel_Properties_Required[] = { + PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_LAST_PRIORITY, + PROP_WRITE_STATUS, + PROP_STATUS_FLAGS, + PROP_OUT_OF_SERVICE, + PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES, + PROP_CHANNEL_NUMBER, + PROP_CONTROL_GROUPS, + -1 +}; + +static const int Channel_Properties_Optional[] = { + PROP_DESCRIPTION, + PROP_RELIABILITY, + PROP_EXECUTION_DELAY, + PROP_ALLOW_GROUP_DELAY_INHIBIT, + PROP_PROFILE_NAME, + -1 +}; + static const int Command_Properties_Required[] = { PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, @@ -698,7 +722,11 @@ static const int File_Properties_Optional[] = { -1 }; -/* Function that returns the number of properties in a list +/** + * Function that returns the number of BACnet object properties in a list + * + * @param pList - array of type 'int' that is a list of BACnet object + * properties, terminated by a '-1' value. */ unsigned property_list_count( const int *pList) @@ -715,8 +743,14 @@ unsigned property_list_count( return property_count; } -/* Function that returns the list of Required or Optional properties +/** + * Function that returns the list of Required or Optional properties * of known standard objects. + * + * @param object_type - enumerated BACNET_OBJECT_TYPE + * @param pPropertyList - returns a pointer to two '-1' terminated arrays of + * type 'int' that contain BACnet object properties for the given object + * type. */ void property_list_special( BACNET_OBJECT_TYPE object_type, @@ -768,6 +802,10 @@ void property_list_special( pPropertyList->Required.pList = Calendar_Properties_Required; pPropertyList->Optional.pList = Calendar_Properties_Optional; break; + case OBJECT_CHANNEL: + pPropertyList->Required.pList = Channel_Properties_Required; + pPropertyList->Optional.pList = Channel_Properties_Optional; + break; case OBJECT_COMMAND: pPropertyList->Required.pList = Command_Properties_Required; pPropertyList->Optional.pList = Command_Properties_Optional; @@ -851,6 +889,8 @@ void property_list_special( case OBJECT_POSITIVE_INTEGER_VALUE: case OBJECT_TIME_PATTERN_VALUE: case OBJECT_TIME_VALUE: + case OBJECT_NOTIFICATION_FORWARDER: + case OBJECT_ALERT_ENROLLMENT: pPropertyList->Required.pList = Default_Properties_Required; pPropertyList->Optional.pList = NULL; pPropertyList->Proprietary.pList = NULL; @@ -876,6 +916,73 @@ void property_list_special( return; } +BACNET_PROPERTY_ID property_list_special_property( + BACNET_OBJECT_TYPE object_type, + BACNET_PROPERTY_ID special_property, + unsigned index) +{ + int property = -1; /* return value */ + unsigned required, optional, proprietary; + struct special_property_list_t PropertyList = {{0}}; + + property_list_special(object_type, &PropertyList); + required = PropertyList.Required.count; + optional = PropertyList.Optional.count; + proprietary = PropertyList.Proprietary.count; + if (special_property == PROP_ALL) { + if (index < required) { + if (PropertyList.Required.pList) { + property = PropertyList.Required.pList[index]; + } + } else if (index < (required + optional)) { + if (PropertyList.Optional.pList) { + index -= required; + property = PropertyList.Optional.pList[index]; + } + } else if (index < (required + optional + proprietary)) { + if (PropertyList.Proprietary.pList) { + index -= (required + optional); + property = PropertyList.Proprietary.pList[index]; + } + } + } else if (special_property == PROP_REQUIRED) { + if (index < required) { + if (PropertyList.Required.pList) { + property = PropertyList.Required.pList[index]; + } + } + } else if (special_property == PROP_OPTIONAL) { + if (index < optional) { + if (PropertyList.Optional.pList) { + property = PropertyList.Optional.pList[index]; + } + } + } + + return (BACNET_PROPERTY_ID) property; +} + +unsigned property_list_special_count( + BACNET_OBJECT_TYPE object_type, + BACNET_PROPERTY_ID special_property) +{ + unsigned count = 0; /* return value */ + struct special_property_list_t PropertyList = {{0}}; + + property_list_special(object_type, &PropertyList); + if (special_property == PROP_ALL) { + count = + PropertyList.Required.count + PropertyList.Optional.count + + PropertyList.Proprietary.count; + } else if (special_property == PROP_REQUIRED) { + count = PropertyList.Required.count; + } else if (special_property == PROP_OPTIONAL) { + count = PropertyList.Optional.count; + } + + return count; +} + #ifdef TEST #include #include @@ -884,7 +991,36 @@ void property_list_special( void testPropList( Test * pTest) { - ct_test(pTest, 0); + unsigned i = 0, j = 0; + unsigned count = 0; + BACNET_PROPERTY_ID property = MAX_BACNET_PROPERTY_ID; + unsigned object_id = 0, object_name = 0, object_type = 0; + + for (i = 0; i < PROPRIETARY_BACNET_OBJECT_TYPE; i++) { + count = property_list_special_count((BACNET_OBJECT_TYPE)i, PROP_ALL); + ct_test(pTest, count >= 3); + object_id = 0; + object_name = 0; + object_type = 0; + for (j = 0; j < count; j++) { + property = property_list_special_property( + (BACNET_OBJECT_TYPE)i, + PROP_ALL, + j); + if (property == PROP_OBJECT_TYPE) { + object_type++; + } + if (property == PROP_OBJECT_IDENTIFIER) { + object_id++; + } + if (property == PROP_OBJECT_NAME) { + object_name++; + } + } + ct_test(pTest, object_type == 1); + ct_test(pTest, object_id == 1); + ct_test(pTest, object_name == 1); + } } #ifdef TEST_PROPLIST diff --git a/bacnet-stack/test.mak b/bacnet-stack/test.mak index 7dd152f6..2e5208b1 100644 --- a/bacnet-stack/test.mak +++ b/bacnet-stack/test.mak @@ -11,7 +11,7 @@ LOGFILE = test.log all: abort address arf awf bacapp bacdcode bacerror bacint bacstr \ cov crc datetime dcc event filename fifo getevent iam ihave \ - indtext keylist key memcopy npdu ptransfer \ + indtext keylist key memcopy npdu proplist ptransfer \ rd reject ringbuf rp rpm sbuf timesync \ whohas whois wp objects @@ -141,6 +141,11 @@ npdu: logfile test/npdu.mak ( ./test/npdu >> ${LOGFILE} ) $(MAKE) -s -C test -f npdu.mak clean +proplist: logfile test/proplist.mak + $(MAKE) -s -C test -f proplist.mak clean all + ( ./test/proplist >> ${LOGFILE} ) + $(MAKE) -s -C test -f proplist.mak clean + ptransfer: logfile test/ptransfer.mak $(MAKE) -s -C test -f ptransfer.mak clean all ( ./test/ptransfer >> ${LOGFILE} )