Changed the BACnet priority defines to include the definition of NO Priority for this particular stack. Added min and max priority, and checking during write property.

This commit is contained in:
skarg
2006-01-24 15:15:17 +00:00
parent a27446c4d1
commit 15cdb72e55
3 changed files with 21 additions and 14 deletions
+3 -1
View File
@@ -49,7 +49,9 @@
#define BACNET_ARRAY_LENGTH_INDEX 0 #define BACNET_ARRAY_LENGTH_INDEX 0
#define BACNET_ARRAY_ALL (~0) #define BACNET_ARRAY_ALL (~0)
// Priority Array for commandable objects // Priority Array for commandable objects
#define BACNET_MAX_PRIORITIES 16 #define BACNET_NO_PRIORITY 0
#define BACNET_MIN_PRIORITY 1
#define BACNET_MAX_PRIORITY 16
// embedded systems need fixed name sizes // embedded systems need fixed name sizes
#define MAX_OBJECT_NAME 10 #define MAX_OBJECT_NAME 10
+8 -8
View File
@@ -46,7 +46,7 @@
// Here is our Priority Array. They are supposed to be Real, but // Here is our Priority Array. They are supposed to be Real, but
// we don't have that kind of memory, so we will use a single byte // 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. // and load a Real for returning the value when asked.
static uint8_t Analog_Output_Level[MAX_ANALOG_OUTPUTS][BACNET_MAX_PRIORITIES]; static uint8_t Analog_Output_Level[MAX_ANALOG_OUTPUTS][BACNET_MAX_PRIORITY];
// Writable out-of-service allows others to play with our Present Value // Writable out-of-service allows others to play with our Present Value
// without changing the physical output // without changing the physical output
static bool Analog_Output_Out_Of_Service[MAX_ANALOG_OUTPUTS]; static bool Analog_Output_Out_Of_Service[MAX_ANALOG_OUTPUTS];
@@ -65,7 +65,7 @@ void Analog_Output_Init(void)
// initialize all the analog output priority arrays to NULL // initialize all the analog output priority arrays to NULL
for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) for (i = 0; i < MAX_ANALOG_OUTPUTS; i++)
{ {
for (j = 0; j < BACNET_MAX_PRIORITIES; j++) for (j = 0; j < BACNET_MAX_PRIORITY; j++)
{ {
Analog_Output_Level[i][j] = AO_LEVEL_NULL; Analog_Output_Level[i][j] = AO_LEVEL_NULL;
} }
@@ -128,7 +128,7 @@ static float Analog_Output_Present_Value(uint32_t object_instance)
index = Analog_Output_Instance_To_Index(object_instance); index = Analog_Output_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_OUTPUTS) if (index < MAX_ANALOG_OUTPUTS)
{ {
for (i = 0; i < BACNET_MAX_PRIORITIES; i++) for (i = 0; i < BACNET_MAX_PRIORITY; i++)
{ {
if (Analog_Output_Level[index][i] != AO_LEVEL_NULL) if (Analog_Output_Level[index][i] != AO_LEVEL_NULL)
{ {
@@ -200,13 +200,13 @@ int Analog_Output_Encode_Property_APDU(
case PROP_PRIORITY_ARRAY: case PROP_PRIORITY_ARRAY:
// Array element zero is the number of elements in the array // Array element zero is the number of elements in the array
if (array_index == BACNET_ARRAY_LENGTH_INDEX) if (array_index == BACNET_ARRAY_LENGTH_INDEX)
apdu_len = encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITIES); apdu_len = encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY);
// if no index was specified, then try to encode the entire list // if no index was specified, then try to encode the entire list
// into one packet. // into one packet.
else if (array_index == BACNET_ARRAY_ALL) else if (array_index == BACNET_ARRAY_ALL)
{ {
object_index = Analog_Output_Instance_To_Index(object_instance); object_index = Analog_Output_Instance_To_Index(object_instance);
for (i = 0; i < BACNET_MAX_PRIORITIES; i++) for (i = 0; i < BACNET_MAX_PRIORITY; i++)
{ {
// FIXME: check if we have room before adding it to APDU // FIXME: check if we have room before adding it to APDU
if (Analog_Output_Level[object_index][i] == AO_LEVEL_NULL) if (Analog_Output_Level[object_index][i] == AO_LEVEL_NULL)
@@ -231,7 +231,7 @@ int Analog_Output_Encode_Property_APDU(
else else
{ {
object_index = Analog_Output_Instance_To_Index(object_instance); object_index = Analog_Output_Instance_To_Index(object_instance);
if (array_index <= BACNET_MAX_PRIORITIES) if (array_index <= BACNET_MAX_PRIORITY)
{ {
if (Analog_Output_Level[object_index][array_index] == AO_LEVEL_NULL) if (Analog_Output_Level[object_index][array_index] == AO_LEVEL_NULL)
len = encode_tagged_null(&apdu[apdu_len]); len = encode_tagged_null(&apdu[apdu_len]);
@@ -288,7 +288,7 @@ bool Analog_Output_Write_Property(
if (wp_data->value.tag == BACNET_APPLICATION_TAG_REAL) if (wp_data->value.tag == BACNET_APPLICATION_TAG_REAL)
{ {
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITIES) && if (priority && (priority <= BACNET_MAX_PRIORITY) &&
(priority != 6 /* reserved */) && (priority != 6 /* reserved */) &&
(wp_data->value.type.Real >= 0.0) && (wp_data->value.type.Real >= 0.0) &&
(wp_data->value.type.Real <= 100.0)) (wp_data->value.type.Real <= 100.0))
@@ -320,7 +320,7 @@ bool Analog_Output_Write_Property(
object_index = Analog_Output_Instance_To_Index( object_index = Analog_Output_Instance_To_Index(
wp_data->object_instance); wp_data->object_instance);
priority = wp_data->priority; priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITIES)) if (priority && (priority <= BACNET_MAX_PRIORITY))
{ {
priority--; priority--;
Analog_Output_Level[object_index][priority] = level; Analog_Output_Level[object_index][priority] = level;
+9 -4
View File
@@ -66,7 +66,7 @@ int wp_encode_apdu(
apdu_len += bacapp_encode_application_data(&apdu[apdu_len], &data->value); apdu_len += bacapp_encode_application_data(&apdu[apdu_len], &data->value);
apdu_len += encode_closing_tag(&apdu[apdu_len], 3); apdu_len += encode_closing_tag(&apdu[apdu_len], 3);
// optional priority - 0 if not set, 1..16 if set // optional priority - 0 if not set, 1..16 if set
if (data->priority) if (data->priority != BACNET_NO_PRIORITY)
apdu_len += encode_context_unsigned(&apdu[apdu_len], 4, apdu_len += encode_context_unsigned(&apdu[apdu_len], 4,
data->priority); data->priority);
} }
@@ -133,8 +133,8 @@ int wp_decode_service_request(
return -1; return -1;
// a tag number of 3 is not extended so only one octet // a tag number of 3 is not extended so only one octet
len++; len++;
// Tag 4: optional Priority // Tag 4: optional Priority - assumed MAX if not explicitly set
data->priority = BACNET_MAX_PRIORITIES; data->priority = BACNET_MAX_PRIORITY;
if ((unsigned)len < apdu_len) if ((unsigned)len < apdu_len)
{ {
tag_len = decode_tag_number_and_value(&apdu[len], tag_len = decode_tag_number_and_value(&apdu[len],
@@ -143,9 +143,14 @@ int wp_decode_service_request(
{ {
len += tag_len; len += tag_len;
len = decode_unsigned(&apdu[len], len_value_type, &unsigned_value); len = decode_unsigned(&apdu[len], len_value_type, &unsigned_value);
/* FIXME: bounds check */ if ((unsigned_value >= BACNET_MIN_PRIORITY) &&
(unsigned_value <= BACNET_MAX_PRIORITY))
{
data->priority = (uint8_t)unsigned_value; data->priority = (uint8_t)unsigned_value;
} }
else
return -1;
}
} }
} }