Added device WriteProperty callback for non-volatile storing in basic device examples. (#728)
This commit is contained in:
@@ -591,6 +591,7 @@ static uint32_t Database_Revision = 0;
|
|||||||
/* Profile_Name */
|
/* Profile_Name */
|
||||||
static BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_IDLE;
|
static BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_IDLE;
|
||||||
static const char *Reinit_Password = "filister";
|
static const char *Reinit_Password = "filister";
|
||||||
|
static write_property_function Device_Write_Property_Store_Callback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the ReinitializeDevice password
|
* @brief Sets the ReinitializeDevice password
|
||||||
@@ -1901,6 +1902,26 @@ static bool Device_Write_Property_Object_Name(
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the callback for a WriteProperty successful operation
|
||||||
|
* @param cb [in] The function to be called, or NULL to disable
|
||||||
|
*/
|
||||||
|
void Device_Write_Property_Store_Callback_Set(
|
||||||
|
write_property_function cb)
|
||||||
|
{
|
||||||
|
Device_Write_Property_Store_Callback = cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Store the value of a property when WriteProperty is successful
|
||||||
|
*/
|
||||||
|
static void Device_Write_Property_Store(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||||
|
{
|
||||||
|
if (Device_Write_Property_Store_Callback) {
|
||||||
|
(void)Device_Write_Property_Store_Callback(wp_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Looks up the requested Object and Property, and set the new Value in it,
|
/** Looks up the requested Object and Property, and set the new Value in it,
|
||||||
* if allowed.
|
* if allowed.
|
||||||
* If the Object or Property can't be found, sets the error class and code.
|
* If the Object or Property can't be found, sets the error class and code.
|
||||||
@@ -1936,6 +1957,9 @@ bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
|||||||
} else {
|
} else {
|
||||||
status = pObject->Object_Write_Property(wp_data);
|
status = pObject->Object_Write_Property(wp_data);
|
||||||
}
|
}
|
||||||
|
if (status) {
|
||||||
|
Device_Write_Property_Store(wp_data);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||||
|
|||||||
@@ -471,6 +471,9 @@ extern "C" {
|
|||||||
BACNET_STACK_EXPORT
|
BACNET_STACK_EXPORT
|
||||||
bool Device_Write_Property_Local(
|
bool Device_Write_Property_Local(
|
||||||
BACNET_WRITE_PROPERTY_DATA * wp_data);
|
BACNET_WRITE_PROPERTY_DATA * wp_data);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void Device_Write_Property_Store_Callback_Set(
|
||||||
|
write_property_function cb);
|
||||||
|
|
||||||
#if defined(INTRINSIC_REPORTING)
|
#if defined(INTRINSIC_REPORTING)
|
||||||
BACNET_STACK_EXPORT
|
BACNET_STACK_EXPORT
|
||||||
|
|||||||
@@ -350,6 +350,7 @@ static uint32_t Database_Revision;
|
|||||||
static BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_IDLE;
|
static BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_IDLE;
|
||||||
static BACNET_CHARACTER_STRING Reinit_Password;
|
static BACNET_CHARACTER_STRING Reinit_Password;
|
||||||
static const char *BACnet_Version = BACNET_VERSION_TEXT;
|
static const char *BACnet_Version = BACNET_VERSION_TEXT;
|
||||||
|
static write_property_function Device_Write_Property_Store_Callback;
|
||||||
|
|
||||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||||
static const int Device_Properties_Required[] = { PROP_OBJECT_IDENTIFIER,
|
static const int Device_Properties_Required[] = { PROP_OBJECT_IDENTIFIER,
|
||||||
@@ -1386,33 +1387,24 @@ static bool Device_Write_Property_Object_Name(
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device_Write_Property_Store(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
/**
|
||||||
|
* @brief Set the callback for a WriteProperty successful operation
|
||||||
|
* @param cb [in] The function to be called, or NULL to disable
|
||||||
|
*/
|
||||||
|
void Device_Write_Property_Store_Callback_Set(
|
||||||
|
write_property_function cb)
|
||||||
{
|
{
|
||||||
BACNET_ARRAY_INDEX array_index;
|
Device_Write_Property_Store_Callback = cb;
|
||||||
BACNET_PROPERTY_ID object_property;
|
}
|
||||||
|
|
||||||
if (property_list_bacnet_array_member(wp_data->object_type,
|
/**
|
||||||
wp_data->object_property)) {
|
* @brief Store the value of a property when WriteProperty is successful
|
||||||
array_index = wp_data->array_index;
|
*/
|
||||||
object_property = wp_data->object_property;
|
static void Device_Write_Property_Store(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||||
} else if (wp_data->object_property == PROP_PRESENT_VALUE) {
|
{
|
||||||
/* indirect Priority_Array write */
|
if (Device_Write_Property_Store_Callback) {
|
||||||
if (Device_Objects_Property_List_Member(wp_data->object_type,
|
(void)Device_Write_Property_Store_Callback(wp_data);
|
||||||
wp_data->object_instance,
|
|
||||||
PROP_PRIORITY_ARRAY)) {
|
|
||||||
array_index = wp_data->priority;
|
|
||||||
object_property = PROP_PRIORITY_ARRAY;
|
|
||||||
} else {
|
|
||||||
object_property = wp_data->object_property;
|
|
||||||
array_index = BACNET_ARRAY_ALL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
object_property = wp_data->object_property;
|
|
||||||
array_index = wp_data->array_index;
|
|
||||||
}
|
}
|
||||||
//bacnet_data_store(wp_data->object_type, wp_data->object_instance,
|
|
||||||
// object_property, array_index, wp_data->application_data,
|
|
||||||
// wp_data->application_data_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Looks up the requested Object and Property, and set the new Value in it,
|
/** Looks up the requested Object and Property, and set the new Value in it,
|
||||||
|
|||||||
Reference in New Issue
Block a user