Fix datatype conversion errors found by splint. Fix Binary input/value set. (#672)
This commit is contained in:
+126
-57
@@ -49,12 +49,15 @@ static binary_input_write_present_value_callback
|
||||
Binary_Input_Write_Present_Value_Callback;
|
||||
|
||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||
static const int Properties_Required[] = { PROP_OBJECT_IDENTIFIER,
|
||||
PROP_OBJECT_NAME, PROP_OBJECT_TYPE, PROP_PRESENT_VALUE, PROP_STATUS_FLAGS,
|
||||
PROP_EVENT_STATE, PROP_OUT_OF_SERVICE, PROP_POLARITY, -1 };
|
||||
static const int Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE,
|
||||
PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE,
|
||||
PROP_OUT_OF_SERVICE, PROP_POLARITY, -1
|
||||
};
|
||||
|
||||
static const int Properties_Optional[] = { PROP_RELIABILITY,
|
||||
PROP_DESCRIPTION, PROP_ACTIVE_TEXT, PROP_INACTIVE_TEXT, -1 };
|
||||
static const int Properties_Optional[] = { PROP_RELIABILITY, PROP_DESCRIPTION,
|
||||
PROP_ACTIVE_TEXT, PROP_INACTIVE_TEXT,
|
||||
-1 };
|
||||
|
||||
static const int Properties_Proprietary[] = { -1 };
|
||||
|
||||
@@ -140,6 +143,70 @@ unsigned Binary_Input_Instance_To_Index(uint32_t object_instance)
|
||||
return Keylist_Index(Object_List, object_instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert from boolean to BACNET_BINARY_PV enumeration
|
||||
* @param value - boolean value
|
||||
* @return BACNET_BINARY_PV enumeration
|
||||
*/
|
||||
static BACNET_BINARY_PV Binary_Present_Value(bool value)
|
||||
{
|
||||
BACNET_BINARY_PV binary_value = BINARY_INACTIVE;
|
||||
|
||||
if (value) {
|
||||
binary_value = BINARY_ACTIVE;
|
||||
}
|
||||
|
||||
return binary_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert from BACNET_BINARY_PV enumeration to boolean
|
||||
* @param binary_value BACNET_BINARY_PV enumeration
|
||||
* @return boolean value
|
||||
*/
|
||||
static bool Binary_Present_Value_Boolean(BACNET_BINARY_PV binary_value)
|
||||
{
|
||||
bool boolean_value = false;
|
||||
|
||||
if (binary_value == BINARY_ACTIVE) {
|
||||
boolean_value = true;
|
||||
}
|
||||
|
||||
return boolean_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert from boolean to BACNET_POLARITY enumeration
|
||||
* @param value - boolean value
|
||||
* @return BACNET_POLARITY enumeration
|
||||
*/
|
||||
static BACNET_POLARITY Binary_Polarity(bool value)
|
||||
{
|
||||
BACNET_POLARITY polarity = POLARITY_NORMAL;
|
||||
|
||||
if (value) {
|
||||
polarity = POLARITY_REVERSE;
|
||||
}
|
||||
|
||||
return polarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert from BACNET_POLARITY enumeration to boolean
|
||||
* @param binary_value BACNET_POLARITY enumeration
|
||||
* @return boolean value
|
||||
*/
|
||||
static bool Binary_Polarity_Boolean(BACNET_POLARITY polarity)
|
||||
{
|
||||
bool boolean_value = false;
|
||||
|
||||
if (polarity == POLARITY_REVERSE) {
|
||||
boolean_value = true;
|
||||
}
|
||||
|
||||
return boolean_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, determines the present-value
|
||||
*
|
||||
@@ -154,8 +221,8 @@ BACNET_BINARY_PV Binary_Input_Present_Value(uint32_t object_instance)
|
||||
|
||||
pObject = Binary_Input_Object(object_instance);
|
||||
if (pObject) {
|
||||
value = pObject->Present_Value;
|
||||
if (pObject->Polarity != POLARITY_NORMAL) {
|
||||
value = Binary_Present_Value(pObject->Present_Value);
|
||||
if (Binary_Polarity(pObject->Polarity) != POLARITY_NORMAL) {
|
||||
if (value == BINARY_INACTIVE) {
|
||||
value = BINARY_ACTIVE;
|
||||
} else {
|
||||
@@ -176,7 +243,7 @@ static void Binary_Input_Present_Value_COV_Detect(
|
||||
struct object_data *pObject, BACNET_BINARY_PV value)
|
||||
{
|
||||
if (pObject) {
|
||||
if (pObject->Present_Value != value) {
|
||||
if (Binary_Present_Value(pObject->Present_Value) != value) {
|
||||
pObject->Change_Of_Value = true;
|
||||
}
|
||||
}
|
||||
@@ -202,7 +269,8 @@ bool Binary_Input_Out_Of_Service(uint32_t object_instance)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, sets the out-of-service property value
|
||||
* @brief For a given object instance-number, sets the out-of-service property
|
||||
* value
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param value - boolean out-of-service value
|
||||
* @return true if the out-of-service property value was set
|
||||
@@ -223,12 +291,12 @@ void Binary_Input_Out_Of_Service_Set(uint32_t object_instance, bool value)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the reliability property value
|
||||
* @brief For a given object instance-number, returns the reliability property
|
||||
* value
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return reliability property value
|
||||
*/
|
||||
BACNET_RELIABILITY Binary_Input_Reliability(
|
||||
uint32_t object_instance)
|
||||
BACNET_RELIABILITY Binary_Input_Reliability(uint32_t object_instance)
|
||||
{
|
||||
BACNET_RELIABILITY value = RELIABILITY_NO_FAULT_DETECTED;
|
||||
struct object_data *pObject;
|
||||
@@ -339,7 +407,8 @@ void Binary_Input_Change_Of_Value_Clear(uint32_t object_instance)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, loads the value_list with the COV data.
|
||||
* @brief For a given object instance-number, loads the value_list with the COV
|
||||
* data.
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param value_list - list of COV data
|
||||
* @return true if the value list is encoded
|
||||
@@ -361,11 +430,10 @@ bool Binary_Input_Encode_Value_List(
|
||||
fault = true;
|
||||
}
|
||||
out_of_service = pObject->Out_Of_Service;
|
||||
if (pObject->Present_Value) {
|
||||
present_value = BINARY_ACTIVE;
|
||||
}
|
||||
status = cov_value_list_encode_enumerated(value_list, present_value,
|
||||
in_alarm, fault, overridden, out_of_service);
|
||||
present_value = Binary_Present_Value(pObject->Present_Value);
|
||||
status = cov_value_list_encode_enumerated(
|
||||
value_list, present_value, in_alarm, fault, overridden,
|
||||
out_of_service);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -386,7 +454,8 @@ bool Binary_Input_Present_Value_Set(
|
||||
pObject = Binary_Input_Object(object_instance);
|
||||
if (pObject) {
|
||||
if (value <= MAX_BINARY_PV) {
|
||||
if (pObject->Polarity != POLARITY_NORMAL) {
|
||||
/* de-polarize */
|
||||
if (Binary_Polarity(pObject->Polarity) != POLARITY_NORMAL) {
|
||||
if (value == BINARY_INACTIVE) {
|
||||
value = BINARY_ACTIVE;
|
||||
} else {
|
||||
@@ -394,7 +463,7 @@ bool Binary_Input_Present_Value_Set(
|
||||
}
|
||||
}
|
||||
Binary_Input_Present_Value_COV_Detect(pObject, value);
|
||||
pObject->Present_Value = true;
|
||||
pObject->Present_Value = Binary_Present_Value_Boolean(value);
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
@@ -413,7 +482,8 @@ bool Binary_Input_Present_Value_Set(
|
||||
* @return true if values are within range and present-value is set.
|
||||
*/
|
||||
static bool Binary_Input_Present_Value_Write(
|
||||
uint32_t object_instance, BACNET_BINARY_PV value,
|
||||
uint32_t object_instance,
|
||||
BACNET_BINARY_PV value,
|
||||
BACNET_ERROR_CLASS *error_class,
|
||||
BACNET_ERROR_CODE *error_code)
|
||||
{
|
||||
@@ -425,9 +495,9 @@ static bool Binary_Input_Present_Value_Write(
|
||||
if (pObject) {
|
||||
if (value <= MAX_BINARY_PV) {
|
||||
if (pObject->Write_Enabled) {
|
||||
old_value = pObject->Present_Value;
|
||||
old_value = Binary_Present_Value(pObject->Present_Value);
|
||||
Binary_Input_Present_Value_COV_Detect(pObject, value);
|
||||
pObject->Present_Value = value;
|
||||
pObject->Present_Value = Binary_Present_Value_Boolean(value);
|
||||
if (pObject->Out_Of_Service) {
|
||||
/* The physical point that the object represents
|
||||
is not in service. This means that changes to the
|
||||
@@ -471,11 +541,13 @@ bool Binary_Input_Object_Name(
|
||||
pObject = Binary_Input_Object(object_instance);
|
||||
if (pObject) {
|
||||
if (pObject->Object_Name == NULL) {
|
||||
snprintf(text, sizeof(text), "BINARY INPUT %lu",
|
||||
snprintf(
|
||||
text, sizeof(text), "BINARY INPUT %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
} else {
|
||||
status = characterstring_init_ansi(object_name, pObject->Object_Name);
|
||||
status =
|
||||
characterstring_init_ansi(object_name, pObject->Object_Name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,7 +588,7 @@ BACNET_POLARITY Binary_Input_Polarity(uint32_t object_instance)
|
||||
|
||||
pObject = Binary_Input_Object(object_instance);
|
||||
if (pObject) {
|
||||
polarity = pObject->Polarity;
|
||||
polarity = Binary_Polarity(pObject->Polarity);
|
||||
}
|
||||
|
||||
return polarity;
|
||||
@@ -536,7 +608,7 @@ bool Binary_Input_Polarity_Set(
|
||||
|
||||
pObject = Binary_Input_Object(object_instance);
|
||||
if (pObject) {
|
||||
pObject->Polarity = polarity;
|
||||
pObject->Polarity = Binary_Polarity_Boolean(polarity);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -585,12 +657,12 @@ bool Binary_Input_Description_Set(uint32_t object_instance, char *new_name)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the inactive-text property value
|
||||
* @brief For a given object instance-number, returns the inactive-text property
|
||||
* value
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return inactive-text property value
|
||||
*/
|
||||
char *Binary_Input_Inactive_Text(
|
||||
uint32_t object_instance)
|
||||
char *Binary_Input_Inactive_Text(uint32_t object_instance)
|
||||
{
|
||||
char *name = NULL;
|
||||
struct object_data *pObject;
|
||||
@@ -604,14 +676,13 @@ char *Binary_Input_Inactive_Text(
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, sets the inactive-text property value
|
||||
* @brief For a given object instance-number, sets the inactive-text property
|
||||
* value
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param new_name - holds the inactive-text to be set
|
||||
* @return true if the inactive-text property value was set
|
||||
*/
|
||||
bool Binary_Input_Inactive_Text_Set(
|
||||
uint32_t object_instance,
|
||||
char *new_name)
|
||||
bool Binary_Input_Inactive_Text_Set(uint32_t object_instance, char *new_name)
|
||||
{
|
||||
bool status = false;
|
||||
struct object_data *pObject;
|
||||
@@ -626,12 +697,12 @@ bool Binary_Input_Inactive_Text_Set(
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the active-text property value
|
||||
* @brief For a given object instance-number, returns the active-text property
|
||||
* value
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return active-text property value
|
||||
*/
|
||||
char *Binary_Input_Active_Text(
|
||||
uint32_t object_instance)
|
||||
*/
|
||||
char *Binary_Input_Active_Text(uint32_t object_instance)
|
||||
{
|
||||
char *name = NULL;
|
||||
struct object_data *pObject;
|
||||
@@ -642,18 +713,16 @@ char *Binary_Input_Active_Text(
|
||||
}
|
||||
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, sets the active-text property value
|
||||
* @brief For a given object instance-number, sets the active-text property
|
||||
* value
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param new_name - holds the active-text to be set
|
||||
* @return true if the active-text property value was set
|
||||
*/
|
||||
bool Binary_Input_Active_Text_Set(
|
||||
uint32_t object_instance,
|
||||
char *new_name)
|
||||
bool Binary_Input_Active_Text_Set(uint32_t object_instance, char *new_name)
|
||||
{
|
||||
bool status = false;
|
||||
struct object_data *pObject;
|
||||
@@ -702,8 +771,7 @@ int Binary_Input_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_OBJECT_TYPE:
|
||||
apdu_len =
|
||||
encode_application_enumerated(&apdu[0], Object_Type);
|
||||
apdu_len = encode_application_enumerated(&apdu[0], Object_Type);
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
apdu_len = encode_application_enumerated(
|
||||
@@ -737,19 +805,22 @@ int Binary_Input_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
&apdu[0], Binary_Input_Reliability(rpdata->object_instance));
|
||||
break;
|
||||
case PROP_DESCRIPTION:
|
||||
characterstring_init_ansi(&char_string,
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
Binary_Input_Description(rpdata->object_instance));
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_ACTIVE_TEXT:
|
||||
characterstring_init_ansi(&char_string,
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
Binary_Input_Active_Text(rpdata->object_instance));
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_INACTIVE_TEXT:
|
||||
characterstring_init_ansi(&char_string,
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
Binary_Input_Inactive_Text(rpdata->object_instance));
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
@@ -806,10 +877,9 @@ bool Binary_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
status = write_property_type_valid(
|
||||
wp_data, &value, BACNET_APPLICATION_TAG_ENUMERATED);
|
||||
if (status) {
|
||||
status =
|
||||
Binary_Input_Present_Value_Write(wp_data->object_instance,
|
||||
value.type.Enumerated,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
status = Binary_Input_Present_Value_Write(
|
||||
wp_data->object_instance, value.type.Enumerated,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
}
|
||||
break;
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
@@ -825,7 +895,8 @@ bool Binary_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
wp_data, &value, BACNET_APPLICATION_TAG_ENUMERATED);
|
||||
if (status) {
|
||||
if (value.type.Enumerated < MAX_POLARITY) {
|
||||
Binary_Input_Polarity_Set(wp_data->object_instance,
|
||||
Binary_Input_Polarity_Set(
|
||||
wp_data->object_instance,
|
||||
(BACNET_POLARITY)value.type.Enumerated);
|
||||
} else {
|
||||
status = false;
|
||||
@@ -836,10 +907,8 @@ bool Binary_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
break;
|
||||
default:
|
||||
if (property_lists_member(
|
||||
Properties_Required,
|
||||
Properties_Optional,
|
||||
Properties_Proprietary,
|
||||
wp_data->object_property)) {
|
||||
Properties_Required, Properties_Optional,
|
||||
Properties_Proprietary, wp_data->object_property)) {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
} else {
|
||||
|
||||
+106
-30
@@ -47,12 +47,16 @@ static binary_value_write_present_value_callback
|
||||
Binary_Value_Write_Present_Value_Callback;
|
||||
|
||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||
static const int Binary_Value_Properties_Required[] = { PROP_OBJECT_IDENTIFIER,
|
||||
PROP_OBJECT_NAME, PROP_OBJECT_TYPE, PROP_PRESENT_VALUE, PROP_STATUS_FLAGS,
|
||||
PROP_EVENT_STATE, PROP_OUT_OF_SERVICE, -1 };
|
||||
static const int Binary_Value_Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME,
|
||||
PROP_OBJECT_TYPE, PROP_PRESENT_VALUE,
|
||||
PROP_STATUS_FLAGS, PROP_EVENT_STATE,
|
||||
PROP_OUT_OF_SERVICE, -1
|
||||
};
|
||||
|
||||
static const int Binary_Value_Properties_Optional[] = { PROP_DESCRIPTION,
|
||||
PROP_RELIABILITY, PROP_ACTIVE_TEXT, PROP_INACTIVE_TEXT, -1 };
|
||||
static const int Binary_Value_Properties_Optional[] = {
|
||||
PROP_DESCRIPTION, PROP_RELIABILITY, PROP_ACTIVE_TEXT, PROP_INACTIVE_TEXT, -1
|
||||
};
|
||||
|
||||
static const int Binary_Value_Properties_Proprietary[] = { -1 };
|
||||
|
||||
@@ -138,6 +142,70 @@ unsigned Binary_Value_Instance_To_Index(uint32_t object_instance)
|
||||
return Keylist_Index(Object_List, object_instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert from boolean to BACNET_BINARY_PV enumeration
|
||||
* @param value - boolean value
|
||||
* @return BACNET_BINARY_PV enumeration
|
||||
*/
|
||||
static BACNET_BINARY_PV Binary_Present_Value(bool value)
|
||||
{
|
||||
BACNET_BINARY_PV binary_value = BINARY_INACTIVE;
|
||||
|
||||
if (value) {
|
||||
binary_value = BINARY_ACTIVE;
|
||||
}
|
||||
|
||||
return binary_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert from BACNET_BINARY_PV enumeration to boolean
|
||||
* @param binary_value BACNET_BINARY_PV enumeration
|
||||
* @return boolean value
|
||||
*/
|
||||
static bool Binary_Present_Value_Boolean(BACNET_BINARY_PV binary_value)
|
||||
{
|
||||
bool boolean_value = false;
|
||||
|
||||
if (binary_value == BINARY_ACTIVE) {
|
||||
boolean_value = true;
|
||||
}
|
||||
|
||||
return boolean_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert from boolean to BACNET_POLARITY enumeration
|
||||
* @param value - boolean value
|
||||
* @return BACNET_POLARITY enumeration
|
||||
*/
|
||||
static BACNET_POLARITY Binary_Polarity(bool value)
|
||||
{
|
||||
BACNET_POLARITY polarity = POLARITY_NORMAL;
|
||||
|
||||
if (value) {
|
||||
polarity = POLARITY_REVERSE;
|
||||
}
|
||||
|
||||
return polarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert from BACNET_POLARITY enumeration to boolean
|
||||
* @param binary_value BACNET_POLARITY enumeration
|
||||
* @return boolean value
|
||||
*/
|
||||
static bool Binary_Polarity_Boolean(BACNET_POLARITY polarity)
|
||||
{
|
||||
bool boolean_value = false;
|
||||
|
||||
if (polarity == POLARITY_REVERSE) {
|
||||
boolean_value = true;
|
||||
}
|
||||
|
||||
return boolean_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given object instance-number, return the present value.
|
||||
*
|
||||
@@ -152,8 +220,8 @@ BACNET_BINARY_PV Binary_Value_Present_Value(uint32_t object_instance)
|
||||
|
||||
pObject = Binary_Value_Object(object_instance);
|
||||
if (pObject) {
|
||||
value = pObject->Present_Value;
|
||||
if (pObject->Polarity != POLARITY_NORMAL) {
|
||||
value = Binary_Present_Value(pObject->Present_Value);
|
||||
if (Binary_Polarity(pObject->Polarity) != POLARITY_NORMAL) {
|
||||
if (value == BINARY_INACTIVE) {
|
||||
value = BINARY_ACTIVE;
|
||||
} else {
|
||||
@@ -174,7 +242,7 @@ static void Binary_Value_Present_Value_COV_Detect(
|
||||
struct object_data *pObject, BACNET_BINARY_PV value)
|
||||
{
|
||||
if (pObject) {
|
||||
if (pObject->Present_Value != value) {
|
||||
if (Binary_Present_Value(pObject->Present_Value) != value) {
|
||||
pObject->Change_Of_Value = true;
|
||||
}
|
||||
}
|
||||
@@ -222,12 +290,12 @@ void Binary_Value_Out_Of_Service_Set(uint32_t object_instance, bool value)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief For a given object instance-number, returns the reliability property value
|
||||
* @brief For a given object instance-number, returns the reliability property
|
||||
* value
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @return reliability property value
|
||||
*/
|
||||
BACNET_RELIABILITY Binary_Value_Reliability(
|
||||
uint32_t object_instance)
|
||||
BACNET_RELIABILITY Binary_Value_Reliability(uint32_t object_instance)
|
||||
{
|
||||
BACNET_RELIABILITY value = RELIABILITY_NO_FAULT_DETECTED;
|
||||
struct object_data *pObject;
|
||||
@@ -364,8 +432,9 @@ bool Binary_Value_Encode_Value_List(
|
||||
if (pObject->Present_Value) {
|
||||
present_value = BINARY_ACTIVE;
|
||||
}
|
||||
status = cov_value_list_encode_enumerated(value_list, present_value,
|
||||
in_alarm, fault, overridden, out_of_service);
|
||||
status = cov_value_list_encode_enumerated(
|
||||
value_list, present_value, in_alarm, fault, overridden,
|
||||
out_of_service);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -386,7 +455,8 @@ bool Binary_Value_Present_Value_Set(
|
||||
pObject = Binary_Value_Object(object_instance);
|
||||
if (pObject) {
|
||||
if (value <= MAX_BINARY_PV) {
|
||||
if (pObject->Polarity != POLARITY_NORMAL) {
|
||||
/* de-polarize */
|
||||
if (Binary_Polarity(pObject->Polarity) != POLARITY_NORMAL) {
|
||||
if (value == BINARY_INACTIVE) {
|
||||
value = BINARY_ACTIVE;
|
||||
} else {
|
||||
@@ -394,7 +464,7 @@ bool Binary_Value_Present_Value_Set(
|
||||
}
|
||||
}
|
||||
Binary_Value_Present_Value_COV_Detect(pObject, value);
|
||||
pObject->Present_Value = true;
|
||||
pObject->Present_Value = Binary_Present_Value_Boolean(value);
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
@@ -412,7 +482,8 @@ bool Binary_Value_Present_Value_Set(
|
||||
*
|
||||
* @return true if values are within range and present-value is set.
|
||||
*/
|
||||
static bool Binary_Value_Present_Value_Write(uint32_t object_instance,
|
||||
static bool Binary_Value_Present_Value_Write(
|
||||
uint32_t object_instance,
|
||||
BACNET_BINARY_PV value,
|
||||
BACNET_ERROR_CLASS *error_class,
|
||||
BACNET_ERROR_CODE *error_code)
|
||||
@@ -425,9 +496,9 @@ static bool Binary_Value_Present_Value_Write(uint32_t object_instance,
|
||||
if (pObject) {
|
||||
if (value <= MAX_BINARY_PV) {
|
||||
if (pObject->Write_Enabled) {
|
||||
old_value = pObject->Present_Value;
|
||||
old_value = Binary_Present_Value(pObject->Present_Value);
|
||||
Binary_Value_Present_Value_COV_Detect(pObject, value);
|
||||
pObject->Present_Value = value;
|
||||
pObject->Present_Value = Binary_Present_Value_Boolean(value);
|
||||
if (pObject->Out_Of_Service) {
|
||||
/* The physical point that the object represents
|
||||
is not in service. This means that changes to the
|
||||
@@ -471,7 +542,8 @@ bool Binary_Value_Object_Name(
|
||||
pObject = Binary_Value_Object(object_instance);
|
||||
if (pObject) {
|
||||
if (pObject->Object_Name == NULL) {
|
||||
snprintf(text, sizeof(text), "BINARY INPUT %lu",
|
||||
snprintf(
|
||||
text, sizeof(text), "BINARY INPUT %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
} else {
|
||||
@@ -517,7 +589,7 @@ BACNET_POLARITY Binary_Value_Polarity(uint32_t object_instance)
|
||||
|
||||
pObject = Binary_Value_Object(object_instance);
|
||||
if (pObject) {
|
||||
polarity = pObject->Polarity;
|
||||
polarity = Binary_Polarity(pObject->Polarity);
|
||||
}
|
||||
|
||||
return polarity;
|
||||
@@ -537,7 +609,7 @@ bool Binary_Value_Polarity_Set(
|
||||
|
||||
pObject = Binary_Value_Object(object_instance);
|
||||
if (pObject) {
|
||||
pObject->Polarity = polarity;
|
||||
pObject->Polarity = Binary_Polarity_Boolean(polarity);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -738,19 +810,22 @@ int Binary_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
&apdu[0], Binary_Value_Reliability(rpdata->object_instance));
|
||||
break;
|
||||
case PROP_DESCRIPTION:
|
||||
characterstring_init_ansi(&char_string,
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
Binary_Value_Description(rpdata->object_instance));
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_ACTIVE_TEXT:
|
||||
characterstring_init_ansi(&char_string,
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
Binary_Value_Active_Text(rpdata->object_instance));
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
break;
|
||||
case PROP_INACTIVE_TEXT:
|
||||
characterstring_init_ansi(&char_string,
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
Binary_Value_Inactive_Text(rpdata->object_instance));
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
@@ -816,10 +891,9 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
status = write_property_type_valid(
|
||||
wp_data, &value, BACNET_APPLICATION_TAG_ENUMERATED);
|
||||
if (status) {
|
||||
status =
|
||||
Binary_Value_Present_Value_Write(wp_data->object_instance,
|
||||
value.type.Enumerated,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
status = Binary_Value_Present_Value_Write(
|
||||
wp_data->object_instance, value.type.Enumerated,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
}
|
||||
break;
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
@@ -835,7 +909,8 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
wp_data, &value, BACNET_APPLICATION_TAG_ENUMERATED);
|
||||
if (status) {
|
||||
if (value.type.Enumerated < MAX_POLARITY) {
|
||||
Binary_Value_Polarity_Set(wp_data->object_instance,
|
||||
Binary_Value_Polarity_Set(
|
||||
wp_data->object_instance,
|
||||
(BACNET_POLARITY)value.type.Enumerated);
|
||||
} else {
|
||||
status = false;
|
||||
@@ -845,7 +920,8 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (property_lists_member(Binary_Value_Properties_Required,
|
||||
if (property_lists_member(
|
||||
Binary_Value_Properties_Required,
|
||||
Binary_Value_Properties_Optional,
|
||||
Binary_Value_Properties_Proprietary,
|
||||
wp_data->object_property)) {
|
||||
|
||||
@@ -51,12 +51,14 @@ struct object_data {
|
||||
/* Key List for storing the object data sorted by instance number */
|
||||
static OS_Keylist Object_List;
|
||||
/* callback for present value writes */
|
||||
static calendar_write_present_value_callback Calendar_Write_Present_Value_Callback;
|
||||
static calendar_write_present_value_callback
|
||||
Calendar_Write_Present_Value_Callback;
|
||||
|
||||
/* These three arrays are used by the ReadPropertyMultiple handler */
|
||||
static const int Calendar_Properties_Required[] = { PROP_OBJECT_IDENTIFIER,
|
||||
PROP_OBJECT_NAME, PROP_OBJECT_TYPE, PROP_PRESENT_VALUE, PROP_DATE_LIST,
|
||||
-1 };
|
||||
static const int Calendar_Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE,
|
||||
PROP_PRESENT_VALUE, PROP_DATE_LIST, -1
|
||||
};
|
||||
|
||||
static const int Calendar_Properties_Optional[] = { PROP_DESCRIPTION, -1 };
|
||||
|
||||
@@ -64,8 +66,8 @@ static const int Calendar_Properties_Proprietary[] = { -1 };
|
||||
|
||||
/* standard properties that are arrays for this object,
|
||||
but not necessary supported in this object */
|
||||
static const int BACnetARRAY_Properties[] = {
|
||||
PROP_PRIORITY_ARRAY, PROP_TAGS, -1 };
|
||||
static const int BACnetARRAY_Properties[] = { PROP_PRIORITY_ARRAY, PROP_TAGS,
|
||||
-1 };
|
||||
|
||||
/**
|
||||
* Returns the list of required, optional, and proprietary properties.
|
||||
@@ -166,7 +168,8 @@ unsigned Calendar_Instance_To_Index(uint32_t object_instance)
|
||||
*
|
||||
* @return true if values are within range and present-value is set.
|
||||
*/
|
||||
static bool Calendar_Present_Value_Write(uint32_t object_instance,
|
||||
static bool Calendar_Present_Value_Write(
|
||||
uint32_t object_instance,
|
||||
bool old_value,
|
||||
bool value,
|
||||
uint8_t priority,
|
||||
@@ -220,8 +223,8 @@ static void Calendar_Date_List_Clean(OS_Keylist list)
|
||||
*
|
||||
* @return Calendar entity.
|
||||
*/
|
||||
BACNET_CALENDAR_ENTRY *Calendar_Date_List_Get(
|
||||
uint32_t object_instance, uint8_t index)
|
||||
BACNET_CALENDAR_ENTRY *
|
||||
Calendar_Date_List_Get(uint32_t object_instance, uint8_t index)
|
||||
{
|
||||
BACNET_CALENDAR_ENTRY *entry = NULL;
|
||||
struct object_data *pObject;
|
||||
@@ -242,8 +245,8 @@ BACNET_CALENDAR_ENTRY *Calendar_Date_List_Get(
|
||||
*
|
||||
* @return true if the entity is add successfully.
|
||||
*/
|
||||
bool Calendar_Date_List_Add(uint32_t object_instance,
|
||||
BACNET_CALENDAR_ENTRY *value)
|
||||
bool Calendar_Date_List_Add(
|
||||
uint32_t object_instance, BACNET_CALENDAR_ENTRY *value)
|
||||
{
|
||||
bool st = false;
|
||||
BACNET_CALENDAR_ENTRY *entry;
|
||||
@@ -253,7 +256,7 @@ bool Calendar_Date_List_Add(uint32_t object_instance,
|
||||
if (!pObject) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
entry = calloc(1, sizeof(BACNET_CALENDAR_ENTRY));
|
||||
if (!entry) {
|
||||
return false;
|
||||
@@ -381,7 +384,7 @@ bool Calendar_Object_Name(
|
||||
{
|
||||
bool status = false;
|
||||
struct object_data *pObject;
|
||||
char name_text[16] = "CALENDAR-4194303";
|
||||
char name_text[32] = "CALENDAR-4194303";
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
@@ -389,7 +392,8 @@ bool Calendar_Object_Name(
|
||||
status =
|
||||
characterstring_init_ansi(object_name, pObject->Object_Name);
|
||||
} else {
|
||||
snprintf(name_text, sizeof(name_text), "CALENDAR-%u", object_instance);
|
||||
snprintf(
|
||||
name_text, sizeof(name_text), "CALENDAR-%u", object_instance);
|
||||
status = characterstring_init_ansi(object_name, name_text);
|
||||
}
|
||||
}
|
||||
@@ -471,11 +475,9 @@ bool Calendar_Description_Set(uint32_t object_instance, char *new_name)
|
||||
* @param object_property - object-property to be checked
|
||||
* @return true if the property is a BACnetARRAY property
|
||||
*/
|
||||
static bool BACnetARRAY_Property(
|
||||
int object_property)
|
||||
static bool BACnetARRAY_Property(int object_property)
|
||||
{
|
||||
return property_list_member(
|
||||
BACnetARRAY_Properties, object_property);
|
||||
return property_list_member(BACnetARRAY_Properties, object_property);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -537,8 +539,7 @@ int Calendar_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
break;
|
||||
}
|
||||
/* only array properties can have array options */
|
||||
if ((apdu_len >= 0) &&
|
||||
(!BACnetARRAY_Property(rpdata->object_property)) &&
|
||||
if ((apdu_len >= 0) && (!BACnetARRAY_Property(rpdata->object_property)) &&
|
||||
(rpdata->array_index != BACNET_ARRAY_ALL)) {
|
||||
rpdata->error_class = ERROR_CLASS_PROPERTY;
|
||||
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
|
||||
@@ -593,8 +594,7 @@ bool Calendar_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
while (iOffset < wp_data->application_data_len) {
|
||||
len = bacnet_calendar_entry_decode(
|
||||
&wp_data->application_data[iOffset],
|
||||
wp_data->application_data_len - iOffset,
|
||||
&entry);
|
||||
wp_data->application_data_len - iOffset, &entry);
|
||||
if (len == BACNET_STATUS_REJECT) {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||
@@ -604,16 +604,15 @@ bool Calendar_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
Calendar_Date_List_Add(wp_data->object_instance, &entry);
|
||||
}
|
||||
pv = Calendar_Present_Value(wp_data->object_instance);
|
||||
status = Calendar_Present_Value_Write(wp_data->object_instance,
|
||||
pv_old, pv, wp_data->priority, &wp_data->error_class,
|
||||
&wp_data->error_code);
|
||||
status = Calendar_Present_Value_Write(
|
||||
wp_data->object_instance, pv_old, pv, wp_data->priority,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
break;
|
||||
default:
|
||||
if (property_lists_member(
|
||||
Calendar_Properties_Required,
|
||||
Calendar_Properties_Optional,
|
||||
Calendar_Properties_Proprietary,
|
||||
wp_data->object_property)) {
|
||||
Calendar_Properties_Required, Calendar_Properties_Optional,
|
||||
Calendar_Properties_Proprietary,
|
||||
wp_data->object_property)) {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
} else {
|
||||
@@ -710,7 +709,7 @@ uint32_t Calendar_Create(uint32_t object_instance)
|
||||
}
|
||||
pObject->Object_Name = NULL;
|
||||
pObject->Description = NULL;
|
||||
pObject->Present_Value = false;
|
||||
pObject->Present_Value = false;
|
||||
pObject->Date_List = Keylist_Create();
|
||||
pObject->Changed = false;
|
||||
pObject->Write_Enabled = false;
|
||||
|
||||
@@ -796,6 +796,7 @@ static void Color_Fade_To_Color_Handler(
|
||||
{
|
||||
BACNET_XY_COLOR old_value;
|
||||
struct object_data *pObject;
|
||||
float x1, x2, x3, y1, y3;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (!pObject) {
|
||||
@@ -819,14 +820,17 @@ static void Color_Fade_To_Color_Handler(
|
||||
pObject->Color_Command.transit.fade_time = 0;
|
||||
} else {
|
||||
/* fading */
|
||||
pObject->Tracking_Value.x_coordinate = linear_interpolate(0,
|
||||
milliseconds, pObject->Color_Command.transit.fade_time,
|
||||
old_value.x_coordinate,
|
||||
pObject->Color_Command.target.color.x_coordinate);
|
||||
pObject->Tracking_Value.y_coordinate = linear_interpolate(0,
|
||||
milliseconds, pObject->Color_Command.transit.fade_time,
|
||||
old_value.y_coordinate,
|
||||
pObject->Color_Command.target.color.y_coordinate);
|
||||
x1 = 0.0f;
|
||||
x2 = (float)milliseconds;
|
||||
x3 = (float)pObject->Color_Command.transit.fade_time;
|
||||
y1 = old_value.x_coordinate;
|
||||
y3 = pObject->Color_Command.target.color.x_coordinate;
|
||||
pObject->Tracking_Value.x_coordinate = linear_interpolate(x1, x2,
|
||||
x3, y1, y3);
|
||||
y1 = old_value.y_coordinate;
|
||||
y3 = pObject->Color_Command.target.color.y_coordinate;
|
||||
pObject->Tracking_Value.y_coordinate = linear_interpolate(x1, x2,
|
||||
x3, y1, y3);
|
||||
pObject->Color_Command.transit.fade_time -= milliseconds;
|
||||
pObject->In_Progress =
|
||||
BACNET_COLOR_OPERATION_IN_PROGRESS_FADE_ACTIVE;
|
||||
|
||||
@@ -87,24 +87,39 @@ static lighting_output_write_present_value_callback
|
||||
/* These arrays are used by the ReadPropertyMultiple handler and
|
||||
property-list property (as of protocol-revision 14) */
|
||||
static const int Lighting_Output_Properties_Required[] = {
|
||||
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE,
|
||||
PROP_PRESENT_VALUE, PROP_TRACKING_VALUE, PROP_LIGHTING_COMMAND,
|
||||
PROP_IN_PROGRESS, PROP_STATUS_FLAGS, PROP_OUT_OF_SERVICE,
|
||||
PROP_BLINK_WARN_ENABLE, PROP_EGRESS_TIME, PROP_EGRESS_ACTIVE,
|
||||
PROP_DEFAULT_FADE_TIME, PROP_DEFAULT_RAMP_RATE, PROP_DEFAULT_STEP_INCREMENT,
|
||||
PROP_PRIORITY_ARRAY, PROP_RELINQUISH_DEFAULT,
|
||||
PROP_OBJECT_IDENTIFIER,
|
||||
PROP_OBJECT_NAME,
|
||||
PROP_OBJECT_TYPE,
|
||||
PROP_PRESENT_VALUE,
|
||||
PROP_TRACKING_VALUE,
|
||||
PROP_LIGHTING_COMMAND,
|
||||
PROP_IN_PROGRESS,
|
||||
PROP_STATUS_FLAGS,
|
||||
PROP_OUT_OF_SERVICE,
|
||||
PROP_BLINK_WARN_ENABLE,
|
||||
PROP_EGRESS_TIME,
|
||||
PROP_EGRESS_ACTIVE,
|
||||
PROP_DEFAULT_FADE_TIME,
|
||||
PROP_DEFAULT_RAMP_RATE,
|
||||
PROP_DEFAULT_STEP_INCREMENT,
|
||||
PROP_PRIORITY_ARRAY,
|
||||
PROP_RELINQUISH_DEFAULT,
|
||||
PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY,
|
||||
#if (BACNET_PROTOCOL_REVISION >= 17)
|
||||
PROP_CURRENT_COMMAND_PRIORITY,
|
||||
#endif
|
||||
-1
|
||||
};
|
||||
static const int Lighting_Output_Properties_Optional[] = { PROP_DESCRIPTION,
|
||||
static const int Lighting_Output_Properties_Optional[] = {
|
||||
PROP_DESCRIPTION,
|
||||
PROP_TRANSITION,
|
||||
#if (BACNET_PROTOCOL_REVISION >= 24)
|
||||
PROP_COLOR_OVERRIDE, PROP_COLOR_REFERENCE, PROP_OVERRIDE_COLOR_REFERENCE,
|
||||
PROP_COLOR_OVERRIDE,
|
||||
PROP_COLOR_REFERENCE,
|
||||
PROP_OVERRIDE_COLOR_REFERENCE,
|
||||
#endif
|
||||
-1 };
|
||||
-1
|
||||
};
|
||||
|
||||
static const int Lighting_Output_Properties_Proprietary[] = { -1 };
|
||||
|
||||
@@ -229,8 +244,8 @@ float Lighting_Output_Present_Value(uint32_t object_instance)
|
||||
* 0 to N for individual array members
|
||||
* @return the priority-array active status for the specific priority
|
||||
*/
|
||||
static bool Priority_Array_Active(
|
||||
struct object_data *pObject, BACNET_ARRAY_INDEX priority)
|
||||
static bool
|
||||
Priority_Array_Active(struct object_data *pObject, BACNET_ARRAY_INDEX priority)
|
||||
{
|
||||
bool active = false;
|
||||
|
||||
@@ -275,8 +290,8 @@ static float Priority_Array_Next_Value(
|
||||
* 0 to N for individual array members
|
||||
* @return The priority-array value for the specific priority
|
||||
*/
|
||||
static float Priority_Array_Value(
|
||||
struct object_data *pObject, BACNET_ARRAY_INDEX priority)
|
||||
static float
|
||||
Priority_Array_Value(struct object_data *pObject, BACNET_ARRAY_INDEX priority)
|
||||
{
|
||||
float real_value = 0.0;
|
||||
|
||||
@@ -352,8 +367,8 @@ static unsigned Present_Value_Priority(struct object_data *pObject)
|
||||
*
|
||||
* @return true if values are within range and present-value is set.
|
||||
*/
|
||||
static bool Present_Value_Relinquish(
|
||||
struct object_data *pObject, unsigned priority)
|
||||
static bool
|
||||
Present_Value_Relinquish(struct object_data *pObject, unsigned priority)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
@@ -378,8 +393,8 @@ static bool Present_Value_Relinquish(
|
||||
*
|
||||
* @return true if values are within range and present-value is set.
|
||||
*/
|
||||
static bool Present_Value_Set(
|
||||
struct object_data *pObject, float value, unsigned priority)
|
||||
static bool
|
||||
Present_Value_Set(struct object_data *pObject, float value, unsigned priority)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
@@ -455,7 +470,8 @@ bool Lighting_Output_Present_Value_Set(
|
||||
*
|
||||
* @return true if values are within range and present-value is set.
|
||||
*/
|
||||
static bool Lighting_Output_Present_Value_Write(uint32_t object_instance,
|
||||
static bool Lighting_Output_Present_Value_Write(
|
||||
uint32_t object_instance,
|
||||
float value,
|
||||
uint8_t priority,
|
||||
BACNET_ERROR_CLASS *error_class,
|
||||
@@ -503,7 +519,8 @@ static bool Lighting_Output_Present_Value_Write(uint32_t object_instance,
|
||||
(Priority_Array_Active(pObject, priority - 1)) &&
|
||||
(isgreater(
|
||||
Priority_Array_Value(pObject, priority - 1), 0.0)) &&
|
||||
(isgreater(Priority_Array_Next_Value(pObject, priority - 1),
|
||||
(isgreater(
|
||||
Priority_Array_Next_Value(pObject, priority - 1),
|
||||
0.0))) {
|
||||
/* The blink-warn notification shall not occur,
|
||||
and the value at the specified priority shall be
|
||||
@@ -531,7 +548,8 @@ static bool Lighting_Output_Present_Value_Write(uint32_t object_instance,
|
||||
(Priority_Array_Active(pObject, priority - 1)) &&
|
||||
(isgreater(
|
||||
Priority_Array_Value(pObject, priority - 1), 0.0)) &&
|
||||
(isgreater(Priority_Array_Next_Value(pObject, priority - 1),
|
||||
(isgreater(
|
||||
Priority_Array_Next_Value(pObject, priority - 1),
|
||||
0.0))) {
|
||||
/* The blink-warn notification shall not occur and
|
||||
the value 0.0% written at the specified
|
||||
@@ -547,8 +565,8 @@ static bool Lighting_Output_Present_Value_Write(uint32_t object_instance,
|
||||
Present_Value_Set(pObject, 0.0, priority);
|
||||
}
|
||||
status = true;
|
||||
} else if (isgreaterequal(value, 0.0) &&
|
||||
islessequal(value, 100.0)) {
|
||||
} else if (
|
||||
isgreaterequal(value, 0.0) && islessequal(value, 100.0)) {
|
||||
Present_Value_Set(pObject, value, priority);
|
||||
current_priority = Present_Value_Priority(pObject);
|
||||
if (priority <= current_priority) {
|
||||
@@ -559,7 +577,8 @@ static bool Lighting_Output_Present_Value_Write(uint32_t object_instance,
|
||||
pObject->Default_Fade_Time;
|
||||
pObject->Lighting_Command.operation =
|
||||
BACNET_LIGHTS_FADE_TO;
|
||||
} else if (pObject->Transition ==
|
||||
} else if (
|
||||
pObject->Transition ==
|
||||
BACNET_LIGHTING_TRANSITION_RAMP) {
|
||||
pObject->Lighting_Command.ramp_rate =
|
||||
pObject->Default_Ramp_Rate;
|
||||
@@ -650,18 +669,19 @@ static bool Lighting_Output_Present_Value_Relinquish_Write(
|
||||
if (old_priority != new_priority) {
|
||||
if (new_priority > BACNET_MAX_PRIORITY) {
|
||||
/* BACNET_LIGHTS_WARN_RELINQUISH? */
|
||||
value = Lighting_Output_Relinquish_Default(object_instance);
|
||||
value = (float)Lighting_Output_Relinquish_Default(
|
||||
object_instance);
|
||||
} else {
|
||||
value =
|
||||
Lighting_Output_Present_Value_Priority(object_instance);
|
||||
value = (float)Lighting_Output_Present_Value_Priority(
|
||||
object_instance);
|
||||
}
|
||||
/* we have priority - configure the Lighting Command */
|
||||
if (pObject->Transition == BACNET_LIGHTING_TRANSITION_FADE) {
|
||||
pObject->Lighting_Command.fade_time =
|
||||
pObject->Default_Fade_Time;
|
||||
pObject->Lighting_Command.operation = BACNET_LIGHTS_FADE_TO;
|
||||
} else if (pObject->Transition ==
|
||||
BACNET_LIGHTING_TRANSITION_RAMP) {
|
||||
} else if (
|
||||
pObject->Transition == BACNET_LIGHTING_TRANSITION_RAMP) {
|
||||
pObject->Lighting_Command.ramp_rate =
|
||||
pObject->Default_Ramp_Rate;
|
||||
pObject->Lighting_Command.operation = BACNET_LIGHTS_RAMP_TO;
|
||||
@@ -707,7 +727,8 @@ bool Lighting_Output_Object_Name(
|
||||
status =
|
||||
characterstring_init_ansi(object_name, pObject->Object_Name);
|
||||
} else {
|
||||
snprintf(name_text, sizeof(name_text), "LIGHTING-OUTPUT-%u",
|
||||
snprintf(
|
||||
name_text, sizeof(name_text), "LIGHTING-OUTPUT-%u",
|
||||
object_instance);
|
||||
status = characterstring_init_ansi(object_name, name_text);
|
||||
}
|
||||
@@ -837,8 +858,8 @@ bool Lighting_Output_Lighting_Command(
|
||||
*
|
||||
* @return the in-progress value of this object instance.
|
||||
*/
|
||||
BACNET_LIGHTING_IN_PROGRESS Lighting_Output_In_Progress(
|
||||
uint32_t object_instance)
|
||||
BACNET_LIGHTING_IN_PROGRESS
|
||||
Lighting_Output_In_Progress(uint32_t object_instance)
|
||||
{
|
||||
BACNET_LIGHTING_IN_PROGRESS value = BACNET_LIGHTING_IDLE;
|
||||
struct object_data *pObject;
|
||||
@@ -1085,7 +1106,8 @@ bool Lighting_Output_Default_Fade_Time_Set(
|
||||
*
|
||||
* @return true if values are within range and present-value is set.
|
||||
*/
|
||||
static bool Lighting_Output_Default_Fade_Time_Write(uint32_t object_instance,
|
||||
static bool Lighting_Output_Default_Fade_Time_Write(
|
||||
uint32_t object_instance,
|
||||
uint32_t value,
|
||||
uint8_t priority,
|
||||
BACNET_ERROR_CLASS *error_class,
|
||||
@@ -1163,15 +1185,16 @@ bool Lighting_Output_Default_Ramp_Rate_Set(
|
||||
* Handle a WriteProperty to a specific property.
|
||||
*
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param value - property value to be written
|
||||
* @param percent_per_second - property value to be written
|
||||
* @param priority - priority-array index value 1..16
|
||||
* @param error_class - the BACnet error class
|
||||
* @param error_code - BACnet Error code
|
||||
*
|
||||
* @return true if values are within range and present-value is set.
|
||||
*/
|
||||
static bool Lighting_Output_Default_Ramp_Rate_Write(uint32_t object_instance,
|
||||
float value,
|
||||
static bool Lighting_Output_Default_Ramp_Rate_Write(
|
||||
uint32_t object_instance,
|
||||
float percent_per_second,
|
||||
uint8_t priority,
|
||||
BACNET_ERROR_CLASS *error_class,
|
||||
BACNET_ERROR_CODE *error_code)
|
||||
@@ -1182,8 +1205,8 @@ static bool Lighting_Output_Default_Ramp_Rate_Write(uint32_t object_instance,
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (pObject) {
|
||||
(void)priority;
|
||||
if ((value >= 0.1) && (value <= 100.0)) {
|
||||
pObject->Default_Fade_Time = value;
|
||||
if ((percent_per_second >= 0.1) && (percent_per_second <= 100.0)) {
|
||||
pObject->Default_Ramp_Rate = percent_per_second;
|
||||
status = true;
|
||||
} else {
|
||||
*error_class = ERROR_CLASS_PROPERTY;
|
||||
@@ -1470,7 +1493,8 @@ bool Lighting_Output_Transition_Set(
|
||||
*
|
||||
* @return true if values are within range and present-value is set.
|
||||
*/
|
||||
static bool Lighting_Output_Transition_Write(uint32_t object_instance,
|
||||
static bool Lighting_Output_Transition_Write(
|
||||
uint32_t object_instance,
|
||||
uint32_t value,
|
||||
uint8_t priority,
|
||||
BACNET_ERROR_CLASS *error_class,
|
||||
@@ -1773,9 +1797,10 @@ int Lighting_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
apdu, Lighting_Output_Transition(rpdata->object_instance));
|
||||
break;
|
||||
case PROP_PRIORITY_ARRAY:
|
||||
apdu_len = bacnet_array_encode(rpdata->object_instance,
|
||||
rpdata->array_index, Lighting_Output_Priority_Array_Encode,
|
||||
BACNET_MAX_PRIORITY, apdu, apdu_size);
|
||||
apdu_len = bacnet_array_encode(
|
||||
rpdata->object_instance, rpdata->array_index,
|
||||
Lighting_Output_Priority_Array_Encode, BACNET_MAX_PRIORITY,
|
||||
apdu, apdu_size);
|
||||
if (apdu_len == BACNET_STATUS_ABORT) {
|
||||
rpdata->error_code =
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
@@ -1806,7 +1831,8 @@ int Lighting_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
#endif
|
||||
#if (BACNET_PROTOCOL_REVISION >= 24)
|
||||
case PROP_COLOR_OVERRIDE:
|
||||
apdu_len = encode_application_boolean(&apdu[0],
|
||||
apdu_len = encode_application_boolean(
|
||||
&apdu[0],
|
||||
Lighting_Output_Color_Override(rpdata->object_instance));
|
||||
break;
|
||||
case PROP_COLOR_REFERENCE:
|
||||
@@ -1823,7 +1849,8 @@ int Lighting_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
break;
|
||||
#endif
|
||||
case PROP_DESCRIPTION:
|
||||
characterstring_init_ansi(&char_string,
|
||||
characterstring_init_ansi(
|
||||
&char_string,
|
||||
Lighting_Output_Description(rpdata->object_instance));
|
||||
apdu_len =
|
||||
encode_application_character_string(&apdu[0], &char_string);
|
||||
@@ -1950,10 +1977,10 @@ bool Lighting_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
status = write_property_type_valid(
|
||||
wp_data, &value, BACNET_APPLICATION_TAG_ENUMERATED);
|
||||
if (status) {
|
||||
status =
|
||||
Lighting_Output_Transition_Write(wp_data->object_instance,
|
||||
value.type.Enumerated, wp_data->priority,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
status = Lighting_Output_Transition_Write(
|
||||
wp_data->object_instance, value.type.Enumerated,
|
||||
wp_data->priority, &wp_data->error_class,
|
||||
&wp_data->error_code);
|
||||
}
|
||||
break;
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
@@ -1997,11 +2024,12 @@ bool Lighting_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
* @param milliseconds - number of milliseconds elapsed since previously
|
||||
* called. Works best when called about every 10 milliseconds.
|
||||
*/
|
||||
static void Lighting_Output_Fade_Handler(
|
||||
uint32_t object_instance, uint16_t milliseconds)
|
||||
static void
|
||||
Lighting_Output_Fade_Handler(uint32_t object_instance, uint16_t milliseconds)
|
||||
{
|
||||
struct object_data *pObject;
|
||||
float old_value;
|
||||
float x1, x2, x3, y1, y3;
|
||||
|
||||
pObject = Keylist_Data(Object_List, object_instance);
|
||||
if (!pObject) {
|
||||
@@ -2015,7 +2043,8 @@ static void Lighting_Output_Fade_Handler(
|
||||
pObject->Lighting_Command.operation = BACNET_LIGHTS_STOP;
|
||||
pObject->Lighting_Command.fade_time = 0;
|
||||
} else {
|
||||
if (!islessgreater(pObject->Tracking_Value,
|
||||
if (!islessgreater(
|
||||
pObject->Tracking_Value,
|
||||
pObject->Lighting_Command.target_level)) {
|
||||
/* stop fading */
|
||||
pObject->Tracking_Value = pObject->Lighting_Command.target_level;
|
||||
@@ -2024,9 +2053,12 @@ static void Lighting_Output_Fade_Handler(
|
||||
pObject->Lighting_Command.fade_time = 0;
|
||||
} else {
|
||||
/* fading */
|
||||
pObject->Tracking_Value = linear_interpolate(0, milliseconds,
|
||||
pObject->Lighting_Command.fade_time, old_value,
|
||||
pObject->Lighting_Command.target_level);
|
||||
x1 = 0.0f;
|
||||
x2 = (float)milliseconds;
|
||||
x3 = (float)pObject->Lighting_Command.fade_time;
|
||||
y1 = old_value;
|
||||
y3 = pObject->Lighting_Command.target_level;
|
||||
pObject->Tracking_Value = linear_interpolate(x1, x2, x3, y1, y3);
|
||||
pObject->Lighting_Command.fade_time -= milliseconds;
|
||||
pObject->In_Progress = BACNET_LIGHTING_FADE_ACTIVE;
|
||||
}
|
||||
@@ -2052,8 +2084,8 @@ static void Lighting_Output_Fade_Handler(
|
||||
* @param object_instance - object-instance number of the object
|
||||
* @param milliseconds - number of milliseconds elapsed
|
||||
*/
|
||||
static void Lighting_Output_Ramp_Handler(
|
||||
uint32_t object_instance, uint16_t milliseconds)
|
||||
static void
|
||||
Lighting_Output_Ramp_Handler(uint32_t object_instance, uint16_t milliseconds)
|
||||
{
|
||||
float old_value, target_value, min_value, max_value, step_value, steps;
|
||||
struct object_data *pObject;
|
||||
@@ -2077,9 +2109,11 @@ static void Lighting_Output_Ramp_Handler(
|
||||
if (milliseconds <= 1000) {
|
||||
/* percent per second */
|
||||
steps = linear_interpolate(
|
||||
0, milliseconds, 1000, 0, pObject->Lighting_Command.ramp_rate);
|
||||
0.0f, (float)milliseconds, 1000.0f, 0.0f,
|
||||
pObject->Lighting_Command.ramp_rate);
|
||||
} else {
|
||||
steps = (milliseconds * pObject->Lighting_Command.ramp_rate) / 1000;
|
||||
steps = ((float)milliseconds * pObject->Lighting_Command.ramp_rate) /
|
||||
1000.0f;
|
||||
}
|
||||
if (!islessgreater(pObject->Tracking_Value, target_value)) {
|
||||
/* stop ramping */
|
||||
|
||||
+18
-14
@@ -558,7 +558,7 @@ bool lighting_command_from_ascii(
|
||||
bool status = false;
|
||||
BACNET_LIGHTING_OPERATION operation = BACNET_LIGHTS_NONE;
|
||||
unsigned a = 0;
|
||||
float b = 0.0, c = 0.0, d = 0.0;
|
||||
float b = 0.0, c = 0.0, d = 0.0, min = 0.0, max = 0.0;
|
||||
int count;
|
||||
|
||||
if (!value) {
|
||||
@@ -600,7 +600,7 @@ bool lighting_command_from_ascii(
|
||||
/* (100..86400000) OPTIONAL */
|
||||
if (isgreaterequal(c, 100.0) && islessequal(c, 86400000.0)) {
|
||||
value->use_fade_time = true;
|
||||
value->fade_time = c;
|
||||
value->fade_time = (uint32_t)c;
|
||||
} else {
|
||||
value->use_fade_time = false;
|
||||
}
|
||||
@@ -608,10 +608,11 @@ bool lighting_command_from_ascii(
|
||||
value->use_fade_time = false;
|
||||
}
|
||||
if (count >= 4) {
|
||||
if (isgreaterequal(d, BACNET_MIN_PRIORITY) &&
|
||||
islessequal(d, BACNET_MAX_PRIORITY)) {
|
||||
min = (float)BACNET_MIN_PRIORITY;
|
||||
max = (float)BACNET_MAX_PRIORITY;
|
||||
if (isgreaterequal(d, min) && islessequal(d, max)) {
|
||||
value->use_priority = true;
|
||||
value->priority = d;
|
||||
value->priority = (uint8_t)d;
|
||||
} else {
|
||||
value->use_priority = false;
|
||||
}
|
||||
@@ -647,10 +648,11 @@ bool lighting_command_from_ascii(
|
||||
value->use_ramp_rate = false;
|
||||
}
|
||||
if (count >= 4) {
|
||||
if (isgreaterequal(d, BACNET_MIN_PRIORITY) &&
|
||||
islessequal(d, BACNET_MAX_PRIORITY)) {
|
||||
min = (float)BACNET_MIN_PRIORITY;
|
||||
max = (float)BACNET_MAX_PRIORITY;
|
||||
if (isgreaterequal(d, min) && islessequal(d, max)) {
|
||||
value->use_priority = true;
|
||||
value->priority = d;
|
||||
value->priority = (uint8_t)d;
|
||||
} else {
|
||||
value->use_priority = false;
|
||||
}
|
||||
@@ -678,10 +680,11 @@ bool lighting_command_from_ascii(
|
||||
value->step_increment = false;
|
||||
}
|
||||
if (count >= 3) {
|
||||
if (isgreaterequal(c, BACNET_MIN_PRIORITY) &&
|
||||
islessequal(c, BACNET_MAX_PRIORITY)) {
|
||||
min = (float)BACNET_MIN_PRIORITY;
|
||||
max = (float)BACNET_MAX_PRIORITY;
|
||||
if (isgreaterequal(c, min) && islessequal(c, max)) {
|
||||
value->use_priority = true;
|
||||
value->priority = c;
|
||||
value->priority = (uint8_t)c;
|
||||
} else {
|
||||
value->use_priority = false;
|
||||
}
|
||||
@@ -699,10 +702,11 @@ bool lighting_command_from_ascii(
|
||||
case BACNET_LIGHTS_STOP:
|
||||
value->operation = operation;
|
||||
if (count >= 2) {
|
||||
if (isgreaterequal(b, BACNET_MIN_PRIORITY) &&
|
||||
islessequal(b, BACNET_MAX_PRIORITY)) {
|
||||
min = (float)BACNET_MIN_PRIORITY;
|
||||
max = (float)BACNET_MAX_PRIORITY;
|
||||
if (isgreaterequal(b, min) && islessequal(b, max)) {
|
||||
value->use_priority = true;
|
||||
value->priority = b;
|
||||
value->priority = (uint8_t)b;
|
||||
} else {
|
||||
value->use_priority = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user