Added write present value callbacks for Analog Value and Integer Value basic object examples. (#956)
This commit is contained in:
@@ -32,6 +32,9 @@
|
|||||||
static OS_Keylist Object_List;
|
static OS_Keylist Object_List;
|
||||||
/* common object type */
|
/* common object type */
|
||||||
static const BACNET_OBJECT_TYPE Object_Type = OBJECT_ANALOG_VALUE;
|
static const BACNET_OBJECT_TYPE Object_Type = OBJECT_ANALOG_VALUE;
|
||||||
|
/* callback for present value writes */
|
||||||
|
static analog_value_write_present_value_callback
|
||||||
|
Analog_Value_Write_Present_Value_Callback;
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||||
@@ -922,6 +925,7 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
|||||||
{
|
{
|
||||||
bool status = false; /* return value */
|
bool status = false; /* return value */
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
float old_value = 0.0f;
|
||||||
BACNET_APPLICATION_DATA_VALUE value = { 0 };
|
BACNET_APPLICATION_DATA_VALUE value = { 0 };
|
||||||
ANALOG_VALUE_DESCR *CurrentAV;
|
ANALOG_VALUE_DESCR *CurrentAV;
|
||||||
|
|
||||||
@@ -962,13 +966,23 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
|||||||
object. */
|
object. */
|
||||||
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;
|
||||||
} else if (Analog_Value_Present_Value_Set(
|
|
||||||
wp_data->object_instance, value.type.Real,
|
|
||||||
wp_data->priority)) {
|
|
||||||
status = true;
|
|
||||||
} else {
|
} else {
|
||||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
old_value =
|
||||||
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
Analog_Value_Present_Value(wp_data->object_instance);
|
||||||
|
if (Analog_Value_Present_Value_Set(
|
||||||
|
wp_data->object_instance, value.type.Real,
|
||||||
|
wp_data->priority)) {
|
||||||
|
status = true;
|
||||||
|
if (Analog_Value_Write_Present_Value_Callback) {
|
||||||
|
Analog_Value_Write_Present_Value_Callback(
|
||||||
|
wp_data->object_instance, old_value,
|
||||||
|
Analog_Value_Present_Value(
|
||||||
|
wp_data->object_instance));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||||
|
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1101,6 +1115,16 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets a callback used when present-value is written from BACnet
|
||||||
|
* @param cb - callback used to provide indications
|
||||||
|
*/
|
||||||
|
void Analog_Value_Write_Present_Value_Callback_Set(
|
||||||
|
analog_value_write_present_value_callback cb)
|
||||||
|
{
|
||||||
|
Analog_Value_Write_Present_Value_Callback = cb;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Analog Value intrinsic reporting function.
|
* @brief Analog Value intrinsic reporting function.
|
||||||
* @param object_instance [in] BACnet object-instance number of the object
|
* @param object_instance [in] BACnet object-instance number of the object
|
||||||
|
|||||||
@@ -55,6 +55,15 @@ typedef struct analog_value_descr {
|
|||||||
#endif
|
#endif
|
||||||
} ANALOG_VALUE_DESCR;
|
} ANALOG_VALUE_DESCR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Callback for gateway write present value request
|
||||||
|
* @param object_instance - object-instance number of the object
|
||||||
|
* @param old_value - floating point analog value prior to write
|
||||||
|
* @param value - floating point analog value of the write
|
||||||
|
*/
|
||||||
|
typedef void (*analog_value_write_present_value_callback)(
|
||||||
|
uint32_t object_instance, float old_value, float value);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
@@ -84,6 +93,10 @@ int Analog_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata);
|
|||||||
BACNET_STACK_EXPORT
|
BACNET_STACK_EXPORT
|
||||||
bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data);
|
bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void Analog_Value_Write_Present_Value_Callback_Set(
|
||||||
|
analog_value_write_present_value_callback cb);
|
||||||
|
|
||||||
BACNET_STACK_EXPORT
|
BACNET_STACK_EXPORT
|
||||||
bool Analog_Value_Present_Value_Set(
|
bool Analog_Value_Present_Value_Set(
|
||||||
uint32_t object_instance, float value, uint8_t priority);
|
uint32_t object_instance, float value, uint8_t priority);
|
||||||
|
|||||||
@@ -32,6 +32,9 @@
|
|||||||
static OS_Keylist Object_List = NULL;
|
static OS_Keylist Object_List = NULL;
|
||||||
/* common object type */
|
/* common object type */
|
||||||
static const BACNET_OBJECT_TYPE Object_Type = OBJECT_INTEGER_VALUE;
|
static const BACNET_OBJECT_TYPE Object_Type = OBJECT_INTEGER_VALUE;
|
||||||
|
/* callback for present value writes */
|
||||||
|
static integer_value_write_present_value_callback
|
||||||
|
Integer_Value_Write_Present_Value_Callback;
|
||||||
|
|
||||||
struct integer_object {
|
struct integer_object {
|
||||||
bool Out_Of_Service : 1;
|
bool Out_Of_Service : 1;
|
||||||
@@ -537,6 +540,7 @@ bool Integer_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
|||||||
{
|
{
|
||||||
bool status = false; /* return value */
|
bool status = false; /* return value */
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
int32_t old_value = 0;
|
||||||
BACNET_APPLICATION_DATA_VALUE value = { 0 };
|
BACNET_APPLICATION_DATA_VALUE value = { 0 };
|
||||||
|
|
||||||
/* decode the some of the request */
|
/* decode the some of the request */
|
||||||
@@ -554,9 +558,16 @@ bool Integer_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
|||||||
status = write_property_type_valid(
|
status = write_property_type_valid(
|
||||||
wp_data, &value, BACNET_APPLICATION_TAG_SIGNED_INT);
|
wp_data, &value, BACNET_APPLICATION_TAG_SIGNED_INT);
|
||||||
if (status) {
|
if (status) {
|
||||||
|
old_value =
|
||||||
|
Integer_Value_Present_Value(wp_data->object_instance);
|
||||||
Integer_Value_Present_Value_Set(
|
Integer_Value_Present_Value_Set(
|
||||||
wp_data->object_instance, value.type.Signed_Int,
|
wp_data->object_instance, value.type.Signed_Int,
|
||||||
wp_data->priority);
|
wp_data->priority);
|
||||||
|
if (Integer_Value_Write_Present_Value_Callback) {
|
||||||
|
Integer_Value_Write_Present_Value_Callback(
|
||||||
|
wp_data->object_instance, old_value,
|
||||||
|
Integer_Value_Present_Value(wp_data->object_instance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PROP_COV_INCREMENT:
|
case PROP_COV_INCREMENT:
|
||||||
@@ -593,6 +604,16 @@ bool Integer_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets a callback used when present-value is written from BACnet
|
||||||
|
* @param cb - callback used to provide indications
|
||||||
|
*/
|
||||||
|
void Integer_Value_Write_Present_Value_Callback_Set(
|
||||||
|
integer_value_write_present_value_callback cb)
|
||||||
|
{
|
||||||
|
Integer_Value_Write_Present_Value_Callback = cb;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief For a given object instance-number, determines the COV status
|
* @brief For a given object instance-number, determines the COV status
|
||||||
* @param object_instance - object-instance number of the object
|
* @param object_instance - object-instance number of the object
|
||||||
|
|||||||
@@ -20,6 +20,15 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Callback for gateway write present value request
|
||||||
|
* @param object_instance - object-instance number of the object
|
||||||
|
* @param old_value - integer preset-value prior to write
|
||||||
|
* @param value - integer preset-value of the write
|
||||||
|
*/
|
||||||
|
typedef void (*integer_value_write_present_value_callback)(
|
||||||
|
uint32_t object_instance, int32_t old_value, int32_t value);
|
||||||
|
|
||||||
BACNET_STACK_EXPORT
|
BACNET_STACK_EXPORT
|
||||||
void Integer_Value_Property_Lists(
|
void Integer_Value_Property_Lists(
|
||||||
const int **pRequired, const int **pOptional, const int **pProprietary);
|
const int **pRequired, const int **pOptional, const int **pProprietary);
|
||||||
@@ -46,6 +55,10 @@ int Integer_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata);
|
|||||||
BACNET_STACK_EXPORT
|
BACNET_STACK_EXPORT
|
||||||
bool Integer_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data);
|
bool Integer_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void Integer_Value_Write_Present_Value_Callback_Set(
|
||||||
|
integer_value_write_present_value_callback cb);
|
||||||
|
|
||||||
BACNET_STACK_EXPORT
|
BACNET_STACK_EXPORT
|
||||||
bool Integer_Value_Present_Value_Set(
|
bool Integer_Value_Present_Value_Set(
|
||||||
uint32_t object_instance, int32_t value, uint8_t priority);
|
uint32_t object_instance, int32_t value, uint8_t priority);
|
||||||
|
|||||||
Reference in New Issue
Block a user