Added API for extending the basic Device object and children with proprietary properties for ReadProperty and WriteProperty services. (#1238)
* Added callback API for extending the basic Device object and children with proprietary properties for ReadProperty and WriteProperty services. The callback API includes a function to get the specific proprietary property list for any specific object instance in the device, functions to handle the ReadProperty or WriteProperty of the proprietary property. * Added a new property_list_function typedef to proplist.h for proprietary property list callbacks * Removed the object-specific proprietary property implementation from the Loop object * Added test coverage in the Device test validating the proprietary property API usage
This commit is contained in:
+6
-1
@@ -40,8 +40,11 @@ The git repositories are hosted at the following sites:
|
||||
|
||||
### Added
|
||||
|
||||
* Added API for extending the basic Device object and children with
|
||||
proprietary properties for ReadProperty and WriteProperty services. (#1238)
|
||||
* Added octet and character string buffer codecs to used with fixed
|
||||
size buffers that are not declared as BACNET_OCTET_STRING or BACNET_CHARACTER_STRING. (#1237)
|
||||
size buffers that are not declared as BACNET_OCTET_STRING
|
||||
or BACNET_CHARACTER_STRING. (#1237)
|
||||
* Added CreateObject and DeleteObject for basic Accumulator objects and
|
||||
WriteProperty handling for object-name, scale, out-of-service, units,
|
||||
and max-pres-value. (#1234)
|
||||
@@ -146,6 +149,8 @@ The git repositories are hosted at the following sites:
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed the basic Schedule object to set the correct present-value
|
||||
based on the Device object date and time. (#1236)
|
||||
* Fixed dlenv_init() for BACnet/SC. bsc_register_as_node() was blocking
|
||||
when the hub was not reachable. Added API so that BACnet/SC
|
||||
node can register via thread that is reponsible for connecting
|
||||
|
||||
@@ -532,6 +532,69 @@ static object_functions_t My_Object_Table[] = {
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* Proprietary property callback functions to enable proprietary
|
||||
properties while reusing the basic objects as-is. */
|
||||
static property_list_function Property_List_Proprietary_Callback;
|
||||
static write_property_function Write_Property_Proprietary_Callback;
|
||||
static read_property_function Read_Property_Proprietary_Callback;
|
||||
|
||||
/**
|
||||
* @brief Sets a callback used when the object supports proprietary properties.
|
||||
* @param cb - callback used to provide proprietary properties service handling.
|
||||
*/
|
||||
void Device_Property_List_Proprietary_Callback_Set(property_list_function cb)
|
||||
{
|
||||
Property_List_Proprietary_Callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a callback used when the object supports proprietary properties.
|
||||
* @param cb - callback used to provide proprietary properties service handling.
|
||||
*/
|
||||
void Device_Read_Property_Proprietary_Callback_Set(read_property_function cb)
|
||||
{
|
||||
Read_Property_Proprietary_Callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a callback used when the object supports proprietary properties.
|
||||
* @param cb - callback used to provide proprietary properties service handling.
|
||||
*/
|
||||
void Device_Write_Property_Proprietary_Callback_Set(write_property_function cb)
|
||||
{
|
||||
Write_Property_Proprietary_Callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the given property is a member of the proprietary property
|
||||
* list for the given object type and instance.
|
||||
* @param object_type - the type of the object.
|
||||
* @param object_instance - the instance number of the object.
|
||||
* @param object_property - the property to check for membership in the
|
||||
* proprietary property list.
|
||||
* @return true if the property is a member of the proprietary property list,
|
||||
* false otherwise.
|
||||
*/
|
||||
bool Device_Property_Proprietary_Member(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
BACNET_PROPERTY_ID object_property)
|
||||
{
|
||||
bool status = false;
|
||||
const int32_t *proprietary_property_list = NULL;
|
||||
|
||||
if (Property_List_Proprietary_Callback) {
|
||||
status = Property_List_Proprietary_Callback(
|
||||
object_type, object_instance, &proprietary_property_list);
|
||||
}
|
||||
if (status) {
|
||||
status =
|
||||
property_list_member(proprietary_property_list, object_property);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/** Glue function to let the Device object, when called by a handler,
|
||||
* lookup which Object type needs to be invoked.
|
||||
* @ingroup ObjHelpers
|
||||
@@ -593,6 +656,7 @@ void Device_Objects_Property_List(
|
||||
struct special_property_list_t *pPropertyList)
|
||||
{
|
||||
struct object_functions *pObject = NULL;
|
||||
const int32_t *proprietary_property_list = NULL;
|
||||
|
||||
(void)object_instance;
|
||||
pPropertyList->Required.pList = NULL;
|
||||
@@ -620,6 +684,12 @@ void Device_Objects_Property_List(
|
||||
? 0
|
||||
: property_list_count(pPropertyList->Optional.pList);
|
||||
|
||||
if (Property_List_Proprietary_Callback) {
|
||||
if (Property_List_Proprietary_Callback(
|
||||
object_type, object_instance, &proprietary_property_list)) {
|
||||
pPropertyList->Proprietary.pList = proprietary_property_list;
|
||||
}
|
||||
}
|
||||
pPropertyList->Proprietary.count = pPropertyList->Proprietary.pList == NULL
|
||||
? 0
|
||||
: property_list_count(pPropertyList->Proprietary.pList);
|
||||
@@ -2305,8 +2375,17 @@ static int Read_Property_Common(
|
||||
rpdata, property_list.Required.pList, property_list.Optional.pList,
|
||||
property_list.Proprietary.pList);
|
||||
#endif
|
||||
} else if (pObject->Object_Read_Property) {
|
||||
apdu_len = pObject->Object_Read_Property(rpdata);
|
||||
} else {
|
||||
if (Read_Property_Proprietary_Callback &&
|
||||
Device_Property_Proprietary_Member(
|
||||
rpdata->object_type, rpdata->object_instance,
|
||||
rpdata->object_property)) {
|
||||
apdu_len = Read_Property_Proprietary_Callback(rpdata);
|
||||
} else {
|
||||
if (pObject->Object_Read_Property) {
|
||||
apdu_len = pObject->Object_Read_Property(rpdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
@@ -2755,7 +2834,14 @@ bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
status = Device_Write_Property_Object_Name(
|
||||
wp_data, pObject->Object_Write_Property);
|
||||
} else {
|
||||
status = pObject->Object_Write_Property(wp_data);
|
||||
if (Write_Property_Proprietary_Callback &&
|
||||
Device_Property_Proprietary_Member(
|
||||
wp_data->object_type, wp_data->object_instance,
|
||||
wp_data->object_property)) {
|
||||
status = Write_Property_Proprietary_Callback(wp_data);
|
||||
} else {
|
||||
status = pObject->Object_Write_Property(wp_data);
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
Device_Write_Property_Store(wp_data);
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
#include "bacnet/create_object.h"
|
||||
#include "bacnet/delete_object.h"
|
||||
#include "bacnet/list_element.h"
|
||||
#include "bacnet/wp.h"
|
||||
#include "bacnet/proplist.h"
|
||||
#include "bacnet/rd.h"
|
||||
#include "bacnet/rp.h"
|
||||
#include "bacnet/rpm.h"
|
||||
#include "bacnet/readrange.h"
|
||||
#include "bacnet/wp.h"
|
||||
|
||||
/** Called so a BACnet object can perform any necessary initialization.
|
||||
* @ingroup ObjHelpers
|
||||
@@ -456,6 +457,13 @@ bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data);
|
||||
BACNET_STACK_EXPORT
|
||||
void Device_Write_Property_Store_Callback_Set(write_property_function cb);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void Device_Property_List_Proprietary_Callback_Set(property_list_function cb);
|
||||
BACNET_STACK_EXPORT
|
||||
void Device_Read_Property_Proprietary_Callback_Set(read_property_function cb);
|
||||
BACNET_STACK_EXPORT
|
||||
void Device_Write_Property_Proprietary_Callback_Set(write_property_function cb);
|
||||
|
||||
#if defined(INTRINSIC_REPORTING)
|
||||
BACNET_STACK_EXPORT
|
||||
void Device_local_reporting(void);
|
||||
|
||||
@@ -120,9 +120,6 @@ static const int32_t Properties_Optional[] = {
|
||||
|
||||
/* handling for proprietary properties */
|
||||
static const int32_t Properties_Proprietary[] = { -1 };
|
||||
static const int32_t *Properties_Proprietary_Extended;
|
||||
static write_property_function Write_Property_Proprietary_Callback;
|
||||
static read_property_function Read_Property_Proprietary_Callback;
|
||||
|
||||
/* Every object shall have a Writable Property_List property
|
||||
which is a BACnetARRAY of property identifiers,
|
||||
@@ -177,11 +174,7 @@ void Loop_Property_Lists(
|
||||
*pOptional = Properties_Optional;
|
||||
}
|
||||
if (pProprietary) {
|
||||
if (Properties_Proprietary_Extended) {
|
||||
*pProprietary = Properties_Proprietary_Extended;
|
||||
} else {
|
||||
*pProprietary = Properties_Proprietary;
|
||||
}
|
||||
*pProprietary = Properties_Proprietary;
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -217,35 +210,6 @@ static bool Loop_Property_Lists_Member(int object_property)
|
||||
pRequired, pOptional, pProprietary, object_property);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a list of proprietary properties.
|
||||
* Used by ReadProperty/WriteProperty and Multiple services.
|
||||
* @param pProprietary - pointer to list of int terminated by -1, of
|
||||
* BACnet proprietary properties for this object.
|
||||
*/
|
||||
void Loop_Proprietary_Property_List_Set(const int32_t *pProprietary)
|
||||
{
|
||||
Properties_Proprietary_Extended = pProprietary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a callback used when the object supports proprietary properties.
|
||||
* @param cb - callback used to provide proprietary properties service handling.
|
||||
*/
|
||||
void Loop_Read_Property_Proprietary_Callback_Set(read_property_function cb)
|
||||
{
|
||||
Read_Property_Proprietary_Callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a callback used when the object supports proprietary properties.
|
||||
* @param cb - callback used to provide proprietary properties service handling.
|
||||
*/
|
||||
void Loop_Write_Property_Proprietary_Callback_Set(write_property_function cb)
|
||||
{
|
||||
Write_Property_Proprietary_Callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets an object from the list using an instance number as the key
|
||||
* @param object_instance - object-instance number of the object
|
||||
@@ -1627,13 +1591,9 @@ int Loop_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
apdu_len = encode_application_real(&apdu[0], real_value);
|
||||
break;
|
||||
default:
|
||||
if (Read_Property_Proprietary_Callback) {
|
||||
apdu_len = Read_Property_Proprietary_Callback(rpdata);
|
||||
} else {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
}
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1958,12 +1918,8 @@ bool Loop_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
break;
|
||||
default:
|
||||
if (Loop_Property_Lists_Member(wp_data->object_property)) {
|
||||
if (Write_Property_Proprietary_Callback) {
|
||||
status = Write_Property_Proprietary_Callback(wp_data);
|
||||
} else {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -46,13 +46,6 @@ BACNET_STACK_EXPORT
|
||||
void Loop_Writable_Property_List(
|
||||
uint32_t object_instance, const int32_t **properties);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Proprietary_Property_List_Set(const int32_t *pProprietary);
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Read_Property_Proprietary_Callback_Set(read_property_function cb);
|
||||
BACNET_STACK_EXPORT
|
||||
void Loop_Write_Property_Proprietary_Callback_Set(write_property_function cb);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
bool Loop_Valid_Instance(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
|
||||
@@ -930,6 +930,69 @@ static object_functions_t My_Object_Table[] = {
|
||||
}
|
||||
};
|
||||
|
||||
/* Proprietary property callback functions to enable proprietary
|
||||
properties while reusing the basic objects as-is. */
|
||||
static property_list_function Property_List_Proprietary_Callback;
|
||||
static write_property_function Write_Property_Proprietary_Callback;
|
||||
static read_property_function Read_Property_Proprietary_Callback;
|
||||
|
||||
/**
|
||||
* @brief Sets a callback used when the object supports proprietary properties.
|
||||
* @param cb - callback used to provide proprietary properties service handling.
|
||||
*/
|
||||
void Device_Property_List_Proprietary_Callback_Set(property_list_function cb)
|
||||
{
|
||||
Property_List_Proprietary_Callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a callback used when the object supports proprietary properties.
|
||||
* @param cb - callback used to provide proprietary properties service handling.
|
||||
*/
|
||||
void Device_Read_Property_Proprietary_Callback_Set(read_property_function cb)
|
||||
{
|
||||
Read_Property_Proprietary_Callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a callback used when the object supports proprietary properties.
|
||||
* @param cb - callback used to provide proprietary properties service handling.
|
||||
*/
|
||||
void Device_Write_Property_Proprietary_Callback_Set(write_property_function cb)
|
||||
{
|
||||
Write_Property_Proprietary_Callback = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the given property is a member of the proprietary property
|
||||
* list for the given object type and instance.
|
||||
* @param object_type - the type of the object.
|
||||
* @param object_instance - the instance number of the object.
|
||||
* @param object_property - the property to check for membership in the
|
||||
* proprietary property list.
|
||||
* @return true if the property is a member of the proprietary property list,
|
||||
* false otherwise.
|
||||
*/
|
||||
bool Device_Property_Proprietary_Member(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
BACNET_PROPERTY_ID object_property)
|
||||
{
|
||||
bool status = false;
|
||||
const int32_t *proprietary_property_list = NULL;
|
||||
|
||||
if (Property_List_Proprietary_Callback) {
|
||||
status = Property_List_Proprietary_Callback(
|
||||
object_type, object_instance, &proprietary_property_list);
|
||||
}
|
||||
if (status) {
|
||||
status =
|
||||
property_list_member(proprietary_property_list, object_property);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/** Glue function to let the Device object, when called by a handler,
|
||||
* lookup which Object type needs to be invoked.
|
||||
* @ingroup ObjHelpers
|
||||
@@ -991,6 +1054,7 @@ void Device_Objects_Property_List(
|
||||
struct special_property_list_t *pPropertyList)
|
||||
{
|
||||
struct object_functions *pObject = NULL;
|
||||
const int32_t *proprietary_property_list = NULL;
|
||||
|
||||
(void)object_instance;
|
||||
pPropertyList->Required.pList = NULL;
|
||||
@@ -1018,6 +1082,12 @@ void Device_Objects_Property_List(
|
||||
? 0
|
||||
: property_list_count(pPropertyList->Optional.pList);
|
||||
|
||||
if (Property_List_Proprietary_Callback) {
|
||||
if (Property_List_Proprietary_Callback(
|
||||
object_type, object_instance, &proprietary_property_list)) {
|
||||
pPropertyList->Proprietary.pList = proprietary_property_list;
|
||||
}
|
||||
}
|
||||
pPropertyList->Proprietary.count = pPropertyList->Proprietary.pList == NULL
|
||||
? 0
|
||||
: property_list_count(pPropertyList->Proprietary.pList);
|
||||
@@ -1165,6 +1235,8 @@ void Device_Property_Lists(
|
||||
const int32_t **pOptional,
|
||||
const int32_t **pProprietary)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
if (pRequired) {
|
||||
*pRequired = Device_Properties_Required;
|
||||
}
|
||||
@@ -1172,7 +1244,16 @@ void Device_Property_Lists(
|
||||
*pOptional = Device_Properties_Optional;
|
||||
}
|
||||
if (pProprietary) {
|
||||
*pProprietary = Device_Properties_Proprietary;
|
||||
if (Property_List_Proprietary_Callback) {
|
||||
instance = Device_Object_Instance_Number();
|
||||
if (Property_List_Proprietary_Callback(
|
||||
OBJECT_DEVICE, instance, pProprietary)) {
|
||||
} else {
|
||||
*pProprietary = Device_Properties_Proprietary;
|
||||
}
|
||||
} else {
|
||||
*pProprietary = Device_Properties_Proprietary;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -2631,8 +2712,17 @@ static int Read_Property_Common(
|
||||
rpdata, property_list.Required.pList, property_list.Optional.pList,
|
||||
property_list.Proprietary.pList);
|
||||
#endif
|
||||
} else if (pObject->Object_Read_Property) {
|
||||
apdu_len = pObject->Object_Read_Property(rpdata);
|
||||
} else {
|
||||
if (Read_Property_Proprietary_Callback &&
|
||||
Device_Property_Proprietary_Member(
|
||||
rpdata->object_type, rpdata->object_instance,
|
||||
rpdata->object_property)) {
|
||||
apdu_len = Read_Property_Proprietary_Callback(rpdata);
|
||||
} else {
|
||||
if (pObject->Object_Read_Property) {
|
||||
apdu_len = pObject->Object_Read_Property(rpdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
@@ -3083,7 +3173,14 @@ bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
status = Device_Write_Property_Object_Name(
|
||||
wp_data, pObject->Object_Write_Property);
|
||||
} else {
|
||||
status = pObject->Object_Write_Property(wp_data);
|
||||
if (Write_Property_Proprietary_Callback &&
|
||||
Device_Property_Proprietary_Member(
|
||||
wp_data->object_type, wp_data->object_instance,
|
||||
wp_data->object_property)) {
|
||||
status = Write_Property_Proprietary_Callback(wp_data);
|
||||
} else {
|
||||
status = pObject->Object_Write_Property(wp_data);
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
Device_Write_Property_Store(wp_data);
|
||||
|
||||
@@ -26,6 +26,24 @@ struct special_property_list_t {
|
||||
struct property_list_t Proprietary;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Callback function type for fetching a property list for a given
|
||||
* object instance.
|
||||
* @param object_type [in] The BACNET_OBJECT_TYPE of the object instance
|
||||
* to fetch the property list for.
|
||||
* @param object_instance [in] The object instance number of the object
|
||||
* to fetch the property list for.
|
||||
* @param pPropertyList [out] Pointer to a property list to be
|
||||
* filled with the property list for this object instance.
|
||||
* @return True if the object instance is valid and the property list has been
|
||||
* filled in, false if the object instance is not valid or the property list
|
||||
* could not be filled in.
|
||||
*/
|
||||
typedef bool (*property_list_function)(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
const int32_t **property_list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -8,11 +8,139 @@
|
||||
#include <zephyr/ztest.h>
|
||||
#include <bacnet/basic/object/device.h>
|
||||
#include <bacnet/bactext.h>
|
||||
#include <bacnet/proplist.h>
|
||||
|
||||
/**
|
||||
* @addtogroup bacnet_tests
|
||||
* @{
|
||||
*/
|
||||
static int32_t Proprietary_Properties[] = { 512, 513, -1 };
|
||||
static uint8_t Proprietary_Serial_Number[16] = {
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Test implementation that returns the proprietary properties list.
|
||||
* @param object_type [in] The BACNET_OBJECT_TYPE of the object instance
|
||||
* to fetch the property list for.
|
||||
* @param object_instance [in] The object instance number of the object
|
||||
* to fetch the property list for.
|
||||
* @param pPropertyList [out] Pointer to a property list to be
|
||||
* filled with the property list for this object instance.
|
||||
* @return True if the object instance is valid and the property list has been
|
||||
* filled in, false if the object instance is not valid or the property list
|
||||
* could not be filled in.
|
||||
*/
|
||||
static bool Property_List_Proprietary(
|
||||
BACNET_OBJECT_TYPE object_type,
|
||||
uint32_t object_instance,
|
||||
const int32_t **property_list)
|
||||
{
|
||||
(void)object_type;
|
||||
(void)object_instance;
|
||||
*property_list = Proprietary_Properties;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief WriteProperty handler for this objects proprietary properties.
|
||||
* For the given WriteProperty data, the application_data is loaded
|
||||
* or the error code and class are set and the return value is false.
|
||||
* @param data - BACNET_WRITE_PROPERTY_DATA data, including
|
||||
* requested data and space for the reply, or error response.
|
||||
* @return false if an error is loaded, true if no errors
|
||||
*/
|
||||
static bool Write_Property_Proprietary(BACNET_WRITE_PROPERTY_DATA *data)
|
||||
{
|
||||
bool status = false;
|
||||
int apdu_len = 0;
|
||||
uint8_t *apdu = NULL;
|
||||
size_t apdu_size = 0;
|
||||
BACNET_OCTET_STRING octet_value = { 0 };
|
||||
|
||||
if ((data == NULL) || (data->application_data_len == 0)) {
|
||||
return false;
|
||||
}
|
||||
/* none of our proprietary properties are arrays */
|
||||
apdu = data->application_data;
|
||||
apdu_size = data->application_data_len;
|
||||
switch ((int)data->object_property) {
|
||||
case 512:
|
||||
apdu_len = bacnet_octet_string_application_decode(
|
||||
apdu, apdu_size, &octet_value);
|
||||
if (apdu_len > 0) {
|
||||
octetstring_copy_value(
|
||||
Proprietary_Serial_Number,
|
||||
sizeof(Proprietary_Serial_Number), &octet_value);
|
||||
status = true;
|
||||
} else if (apdu_len == 0) {
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||
} else {
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_INVALID_DATA_ENCODING;
|
||||
}
|
||||
break;
|
||||
case 513:
|
||||
default:
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ReadProperty handler for this objects proprietary properties.
|
||||
* For the given ReadProperty data, the application_data is loaded
|
||||
* or the error code and class are set and the return value is
|
||||
* BACNET_STATUS_ERROR.
|
||||
* @param data - BACNET_READ_PROPERTY_DATA data, including
|
||||
* requested data and space for the reply, or error response.
|
||||
* @return number of bytes in the reply 0..N, or BACNET_STATUS_ERROR
|
||||
*/
|
||||
static int Read_Property_Proprietary(BACNET_READ_PROPERTY_DATA *data)
|
||||
{
|
||||
int apdu_len = 0;
|
||||
uint8_t *apdu = NULL;
|
||||
size_t apdu_size = 0;
|
||||
BACNET_OCTET_STRING octet_value = { 0 };
|
||||
BACNET_UNSIGNED_INTEGER unsigned_value = 42;
|
||||
|
||||
if ((data == NULL) || (data->application_data == NULL) ||
|
||||
(data->application_data_len == 0)) {
|
||||
return 0;
|
||||
}
|
||||
/* none of our proprietary properties are arrays */
|
||||
if (data->array_index != BACNET_ARRAY_ALL) {
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
return BACNET_STATUS_ERROR;
|
||||
}
|
||||
apdu = data->application_data;
|
||||
apdu_size = data->application_data_len;
|
||||
switch ((int)data->object_property) {
|
||||
case 512:
|
||||
octetstring_init(
|
||||
&octet_value, Proprietary_Serial_Number,
|
||||
sizeof(Proprietary_Serial_Number));
|
||||
apdu_len = bacnet_octet_string_application_encode(
|
||||
apdu, apdu_size, &octet_value);
|
||||
break;
|
||||
case 513:
|
||||
apdu_len = bacnet_unsigned_application_encode(
|
||||
apdu, apdu_size, unsigned_value);
|
||||
break;
|
||||
default:
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test ReadProperty API
|
||||
@@ -26,6 +154,7 @@ static void test_Device_Data_Sharing(void)
|
||||
BACNET_WRITE_PROPERTY_DATA wpdata = { 0 };
|
||||
/* for decode value data */
|
||||
BACNET_APPLICATION_DATA_VALUE value = { 0 };
|
||||
struct special_property_list_t property_list = { 0 };
|
||||
const int32_t *pRequired = NULL;
|
||||
const int32_t *pOptional = NULL;
|
||||
const int32_t *pProprietary = NULL;
|
||||
@@ -35,11 +164,23 @@ static void test_Device_Data_Sharing(void)
|
||||
Device_Init(NULL);
|
||||
count = Device_Count();
|
||||
zassert_true(count > 0, NULL);
|
||||
|
||||
/* add some proprietary properties */
|
||||
Device_Property_List_Proprietary_Callback_Set(Property_List_Proprietary);
|
||||
Device_Read_Property_Proprietary_Callback_Set(Read_Property_Proprietary);
|
||||
Device_Write_Property_Proprietary_Callback_Set(Write_Property_Proprietary);
|
||||
/* configure for ReadProperty test */
|
||||
rpdata.application_data = &apdu[0];
|
||||
rpdata.application_data_len = sizeof(apdu);
|
||||
rpdata.object_type = OBJECT_DEVICE;
|
||||
rpdata.object_instance = Device_Index_To_Instance(0);
|
||||
Device_Property_Lists(&pRequired, &pOptional, &pProprietary);
|
||||
/* get the property lists */
|
||||
Device_Objects_Property_List(
|
||||
OBJECT_DEVICE, rpdata.object_instance, &property_list);
|
||||
pRequired = property_list.Required.pList;
|
||||
pOptional = property_list.Optional.pList;
|
||||
pProprietary = property_list.Proprietary.pList;
|
||||
/* test the ReadProperty and WriteProperty handling for every property */
|
||||
while ((*pRequired) != -1) {
|
||||
rpdata.object_property = *pRequired;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
@@ -112,6 +253,40 @@ static void test_Device_Data_Sharing(void)
|
||||
}
|
||||
pOptional++;
|
||||
}
|
||||
while ((*pProprietary) != -1) {
|
||||
rpdata.object_property = *pProprietary;
|
||||
rpdata.array_index = BACNET_ARRAY_ALL;
|
||||
len = Device_Read_Property(&rpdata);
|
||||
zassert_not_equal(
|
||||
len, BACNET_STATUS_ERROR,
|
||||
"property '%s': failed to ReadProperty!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
if (len > 0) {
|
||||
test_len = bacapp_decode_known_property(
|
||||
rpdata.application_data, (uint8_t)rpdata.application_data_len,
|
||||
&value, rpdata.object_type, rpdata.object_property);
|
||||
zassert_equal(
|
||||
test_len, len, "property '%s': ReadProperty decode failure!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
/* check WriteProperty properties */
|
||||
wpdata.object_type = rpdata.object_type;
|
||||
wpdata.object_instance = rpdata.object_instance;
|
||||
wpdata.object_property = rpdata.object_property;
|
||||
wpdata.array_index = rpdata.array_index;
|
||||
memcpy(&wpdata.application_data, rpdata.application_data, MAX_APDU);
|
||||
wpdata.application_data_len = len;
|
||||
wpdata.error_code = ERROR_CODE_SUCCESS;
|
||||
status = Device_Write_Property(&wpdata);
|
||||
if (!status) {
|
||||
/* verify WriteProperty property is known */
|
||||
zassert_not_equal(
|
||||
wpdata.error_code, ERROR_CODE_UNKNOWN_PROPERTY,
|
||||
"property '%s': WriteProperty Unknown!\n",
|
||||
bactext_property_name(rpdata.object_property));
|
||||
}
|
||||
}
|
||||
pProprietary++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,108 +49,6 @@ static void Loop_Write_Property_Notification_Callback(
|
||||
sizeof(BACNET_WRITE_PROPERTY_DATA));
|
||||
}
|
||||
|
||||
static int Proprietary_Properties[] = { 512, 513, -1 };
|
||||
static uint8_t Proprietary_Serial_Number[16];
|
||||
|
||||
/**
|
||||
* @brief WriteProperty handler for this objects proprietary properties.
|
||||
* For the given WriteProperty data, the application_data is loaded
|
||||
* or the error code and class are set and the return value is false.
|
||||
* @param data - BACNET_WRITE_PROPERTY_DATA data, including
|
||||
* requested data and space for the reply, or error response.
|
||||
* @return false if an error is loaded, true if no errors
|
||||
*/
|
||||
static bool Write_Property_Proprietary(BACNET_WRITE_PROPERTY_DATA *data)
|
||||
{
|
||||
bool status = false;
|
||||
int apdu_len = 0;
|
||||
uint8_t *apdu = NULL;
|
||||
size_t apdu_size = 0;
|
||||
BACNET_OCTET_STRING octet_value = { 0 };
|
||||
|
||||
switch ((int)data->object_property) {
|
||||
case 512:
|
||||
apdu_len = bacnet_octet_string_application_decode(
|
||||
apdu, apdu_size, &octet_value);
|
||||
if (apdu_len > 0) {
|
||||
octetstring_copy_value(
|
||||
Proprietary_Serial_Number,
|
||||
sizeof(Proprietary_Serial_Number), &octet_value);
|
||||
status = true;
|
||||
} else if (apdu_len == 0) {
|
||||
status = false;
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||
|
||||
} else {
|
||||
status = false;
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_INVALID_DATA_ENCODING;
|
||||
}
|
||||
break;
|
||||
case 513:
|
||||
default:
|
||||
status = false;
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ReadProperty handler for this objects proprietary properties.
|
||||
* For the given ReadProperty data, the application_data is loaded
|
||||
* or the error code and class are set and the return value is
|
||||
* BACNET_STATUS_ERROR.
|
||||
* @param data - BACNET_READ_PROPERTY_DATA data, including
|
||||
* requested data and space for the reply, or error response.
|
||||
* @return false if an error is loaded, true if no errors
|
||||
*/
|
||||
static int Read_Property_Proprietary(BACNET_READ_PROPERTY_DATA *data)
|
||||
{
|
||||
int apdu_len = 0;
|
||||
uint8_t *apdu = NULL;
|
||||
size_t apdu_size = 0;
|
||||
BACNET_OCTET_STRING octet_value = { 0 };
|
||||
BACNET_UNSIGNED_INTEGER unsigned_value = 0;
|
||||
|
||||
if ((data == NULL) || (data->application_data == NULL) ||
|
||||
(data->application_data_len == 0)) {
|
||||
return 0;
|
||||
}
|
||||
/* none of our proprietary properties are arrays */
|
||||
if (data->array_index != BACNET_ARRAY_ALL) {
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
return BACNET_STATUS_ERROR;
|
||||
}
|
||||
apdu = data->application_data;
|
||||
apdu_size = data->application_data_len;
|
||||
switch ((int)data->object_property) {
|
||||
case 512:
|
||||
octetstring_init(
|
||||
&octet_value, Proprietary_Serial_Number,
|
||||
sizeof(Proprietary_Serial_Number));
|
||||
apdu_len = bacnet_octet_string_application_encode(
|
||||
apdu, apdu_size, &octet_value);
|
||||
break;
|
||||
case 513:
|
||||
unsigned_value = Loop_Size();
|
||||
apdu_len = bacnet_unsigned_application_encode(
|
||||
apdu, apdu_size, unsigned_value);
|
||||
break;
|
||||
default:
|
||||
data->error_class = ERROR_CLASS_PROPERTY;
|
||||
data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
|
||||
apdu_len = BACNET_STATUS_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test
|
||||
*/
|
||||
@@ -203,10 +101,6 @@ static void test_Loop_Read_Write(void)
|
||||
/* reliability and status flags */
|
||||
status = Loop_Reliability_Set(instance, RELIABILITY_PROCESS_ERROR);
|
||||
zassert_true(status, NULL);
|
||||
/* add some proprietary properties */
|
||||
Loop_Proprietary_Property_List_Set(Proprietary_Properties);
|
||||
Loop_Read_Property_Proprietary_Callback_Set(Read_Property_Proprietary);
|
||||
Loop_Write_Property_Proprietary_Callback_Set(Write_Property_Proprietary);
|
||||
/* perform a general test for RP/WP */
|
||||
bacnet_object_properties_read_write_test(
|
||||
OBJECT_LOOP, instance, Loop_Property_Lists, Loop_Read_Property,
|
||||
|
||||
Reference in New Issue
Block a user