Merged revision(s) 2770 from branches/releases/bacnet-stack-0-8-0:

Changed present-value to be a float, and removed priority array example from Analog Value demo object.
........
This commit is contained in:
skarg
2014-08-28 15:13:04 +00:00
parent cf738fea8f
commit 5f08d69cc6
2 changed files with 22 additions and 132 deletions
+20 -126
View File
@@ -46,13 +46,6 @@
#define MAX_ANALOG_VALUES 4 #define MAX_ANALOG_VALUES 4
#endif #endif
/* we choose to have a NULL level in our system represented by */
/* a particular value. When the priorities are not in use, they */
/* will be relinquished (i.e. set to the NULL level). */
#define ANALOG_LEVEL_NULL 255
ANALOG_VALUE_DESCR AV_Descr[MAX_ANALOG_VALUES]; ANALOG_VALUE_DESCR AV_Descr[MAX_ANALOG_VALUES];
/* These three arrays are used by the ReadPropertyMultiple handler */ /* These three arrays are used by the ReadPropertyMultiple handler */
@@ -70,8 +63,6 @@ static const int Analog_Value_Properties_Required[] = {
static const int Analog_Value_Properties_Optional[] = { static const int Analog_Value_Properties_Optional[] = {
PROP_DESCRIPTION, PROP_DESCRIPTION,
PROP_PRIORITY_ARRAY,
PROP_RELINQUISH_DEFAULT,
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
PROP_TIME_DELAY, PROP_TIME_DELAY,
PROP_NOTIFICATION_CLASS, PROP_NOTIFICATION_CLASS,
@@ -113,11 +104,8 @@ void Analog_Value_Init(
for (i = 0; i < MAX_ANALOG_VALUES; i++) { for (i = 0; i < MAX_ANALOG_VALUES; i++) {
memset(&AV_Descr[i], 0x00, sizeof(ANALOG_VALUE_DESCR)); memset(&AV_Descr[i], 0x00, sizeof(ANALOG_VALUE_DESCR));
/* initialize all the analog output priority arrays to NULL */ AV_Descr[i].Present_Value = 0.0;
for (j = 0; j < BACNET_MAX_PRIORITY; j++) { AV_Descr[i].Units = UNITS_NO_UNITS;
AV_Descr[i].Priority_Array[j] = ANALOG_LEVEL_NULL;
}
AV_Descr[i].Units = UNITS_PERCENT;
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
AV_Descr[i].Event_State = EVENT_STATE_NORMAL; AV_Descr[i].Event_State = EVENT_STATE_NORMAL;
/* notification class not connected */ /* notification class not connected */
@@ -184,55 +172,41 @@ unsigned Analog_Value_Instance_To_Index(
return index; return index;
} }
/**
* For a given object instance-number, sets the present-value at a given
* priority 1..16.
*
* @param object_instance - object-instance number of the object
* @param value - floating point analog value
* @param priority - priority 1..16
*
* @return true if values are within range and present-value is set.
*/
bool Analog_Value_Present_Value_Set( bool Analog_Value_Present_Value_Set(
uint32_t object_instance, uint32_t object_instance,
float value, float value,
uint8_t priority) uint8_t priority)
{ {
ANALOG_VALUE_DESCR *CurrentAV;
unsigned index = 0; unsigned index = 0;
bool status = false; bool status = false;
index = Analog_Value_Instance_To_Index(object_instance); index = Analog_Value_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_VALUES) { if (index < MAX_ANALOG_VALUES) {
CurrentAV = &AV_Descr[index]; AV_Descr[index].Present_Value = value;
if (priority && (priority <= BACNET_MAX_PRIORITY) && status = true;
(priority != 6 /* reserved */ ) &&
(value >= 0.0) && (value <= 100.0)) {
CurrentAV->Priority_Array[priority - 1] = (uint8_t) value;
/* Note: you could set the physical output here to the next
highest priority, or to the relinquish default if no
priorities are set.
However, if Out of Service is TRUE, then don't set the
physical output. This comment may apply to the
main loop (i.e. check out of service before changing output) */
status = true;
}
} }
return status; return status;
} }
float Analog_Value_Present_Value( float Analog_Value_Present_Value(
uint32_t object_instance) uint32_t object_instance)
{ {
ANALOG_VALUE_DESCR *CurrentAV;
float value = 0; float value = 0;
unsigned index = 0; unsigned index = 0;
unsigned i = 0;
index = Analog_Value_Instance_To_Index(object_instance); index = Analog_Value_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_VALUES) { if (index < MAX_ANALOG_VALUES) {
CurrentAV = &AV_Descr[index]; value = AV_Descr[index].Present_Value;
/* When all the priorities are level null, the present value returns */
/* the Relinquish Default value */
value = CurrentAV->Relinquish_Default;
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
if (CurrentAV->Priority_Array[i] != ANALOG_LEVEL_NULL) {
value = CurrentAV->Priority_Array[i];
break;
}
}
} }
return value; return value;
@@ -344,58 +318,6 @@ int Analog_Value_Read_Property(
encode_application_enumerated(&apdu[0], CurrentAV->Units); encode_application_enumerated(&apdu[0], CurrentAV->Units);
break; break;
case PROP_PRIORITY_ARRAY:
/* Array element zero is the number of elements in the array */
if (rpdata->array_index == 0)
apdu_len =
encode_application_unsigned(&apdu[0], BACNET_MAX_PRIORITY);
/* if no index was specified, then try to encode the entire list */
/* into one packet. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) {
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
/* FIXME: check if we have room before adding it to APDU */
if (CurrentAV->Priority_Array[i] == ANALOG_LEVEL_NULL)
len = encode_application_null(&apdu[apdu_len]);
else {
real_value = CurrentAV->Priority_Array[i];
len =
encode_application_real(&apdu[apdu_len],
real_value);
}
/* add it if we have room */
if ((apdu_len + len) < MAX_APDU)
apdu_len += len;
else {
rpdata->error_class = ERROR_CLASS_SERVICES;
rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
apdu_len = BACNET_STATUS_ERROR;
break;
}
}
} else {
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (CurrentAV->Priority_Array[rpdata->array_index - 1]
== ANALOG_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]);
else {
real_value =
CurrentAV->Priority_Array[rpdata->array_index - 1];
apdu_len =
encode_application_real(&apdu[0], real_value);
}
} else {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = BACNET_STATUS_ERROR;
}
}
break;
case PROP_RELINQUISH_DEFAULT:
real_value = CurrentAV->Relinquish_Default;
apdu_len = encode_application_real(&apdu[0], real_value);
break;
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
case PROP_TIME_DELAY: case PROP_TIME_DELAY:
apdu_len = apdu_len =
@@ -543,8 +465,6 @@ bool Analog_Value_Write_Property(
{ {
bool status = false; /* return value */ bool status = false; /* return value */
unsigned int object_index = 0; unsigned int object_index = 0;
unsigned int priority = 0;
uint8_t level = ANALOG_LEVEL_NULL;
int len = 0; int len = 0;
BACNET_APPLICATION_DATA_VALUE value; BACNET_APPLICATION_DATA_VALUE value;
ANALOG_VALUE_DESCR *CurrentAV; ANALOG_VALUE_DESCR *CurrentAV;
@@ -594,27 +514,9 @@ bool Analog_Value_Write_Property(
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
} }
} else { } else {
status = status = false;
WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, wp_data->error_class = ERROR_CLASS_PROPERTY;
&wp_data->error_class, &wp_data->error_code); wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
if (status) {
level = ANALOG_LEVEL_NULL;
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
CurrentAV->Priority_Array[priority] = level;
/* Note: you could set the physical output here to the next
highest priority, or to the relinquish default if no
priorities are set.
However, if Out of Service is TRUE, then don't set the
physical output. This comment may apply to the
main loop (i.e. check out of service before changing output) */
} else {
status = false;
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
}
} }
break; break;
@@ -636,15 +538,6 @@ bool Analog_Value_Write_Property(
} }
break; break;
case PROP_RELINQUISH_DEFAULT:
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL,
&wp_data->error_class, &wp_data->error_code);
if (status) {
CurrentAV->Relinquish_Default = value.type.Real;
}
break;
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
case PROP_TIME_DELAY: case PROP_TIME_DELAY:
status = status =
@@ -757,7 +650,6 @@ bool Analog_Value_Write_Property(
case PROP_STATUS_FLAGS: case PROP_STATUS_FLAGS:
case PROP_EVENT_STATE: case PROP_EVENT_STATE:
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
case PROP_PRIORITY_ARRAY:
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
case PROP_ACKED_TRANSITIONS: case PROP_ACKED_TRANSITIONS:
case PROP_EVENT_TIME_STAMPS: case PROP_EVENT_TIME_STAMPS:
@@ -765,6 +657,8 @@ bool Analog_Value_Write_Property(
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;
break; break;
case PROP_RELINQUISH_DEFAULT:
case PROP_PRIORITY_ARRAY:
default: default:
wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY; wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
+2 -6
View File
@@ -46,12 +46,8 @@ extern "C" {
typedef struct analog_value_descr { typedef struct analog_value_descr {
unsigned Event_State:3; unsigned Event_State:3;
bool Out_Of_Service; bool Out_Of_Service;
uint8_t Units; uint16_t Units;
/* Here is our Priority Array. They are supposed to be Real, but */ float Present_Value;
/* we don't have that kind of memory, so we will use a single byte */
/* and load a Real for returning the value when asked. */
uint8_t Priority_Array[BACNET_MAX_PRIORITY];
float Relinquish_Default;
#if defined(INTRINSIC_REPORTING) #if defined(INTRINSIC_REPORTING)
uint32_t Time_Delay; uint32_t Time_Delay;
uint32_t Notification_Class; uint32_t Notification_Class;