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:
@@ -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