From 15cdb72e550457ebbe78d314fec33ae1380296d7 Mon Sep 17 00:00:00 2001 From: skarg Date: Tue, 24 Jan 2006 15:15:17 +0000 Subject: [PATCH] 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. --- bacnet-stack/bacdef.h | 4 +++- bacnet-stack/demo/object/ao.c | 16 ++++++++-------- bacnet-stack/wp.c | 15 ++++++++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/bacnet-stack/bacdef.h b/bacnet-stack/bacdef.h index cdacaa13..6ae01fad 100644 --- a/bacnet-stack/bacdef.h +++ b/bacnet-stack/bacdef.h @@ -49,7 +49,9 @@ #define BACNET_ARRAY_LENGTH_INDEX 0 #define BACNET_ARRAY_ALL (~0) // 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 #define MAX_OBJECT_NAME 10 diff --git a/bacnet-stack/demo/object/ao.c b/bacnet-stack/demo/object/ao.c index b63f5eb6..edd056ff 100644 --- a/bacnet-stack/demo/object/ao.c +++ b/bacnet-stack/demo/object/ao.c @@ -46,7 +46,7 @@ // 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 // 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 // without changing the physical output 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 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; } @@ -128,7 +128,7 @@ static float Analog_Output_Present_Value(uint32_t object_instance) index = Analog_Output_Instance_To_Index(object_instance); 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) { @@ -200,13 +200,13 @@ int Analog_Output_Encode_Property_APDU( case PROP_PRIORITY_ARRAY: // Array element zero is the number of elements in the array 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 // into one packet. else if (array_index == BACNET_ARRAY_ALL) { 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 if (Analog_Output_Level[object_index][i] == AO_LEVEL_NULL) @@ -231,7 +231,7 @@ int Analog_Output_Encode_Property_APDU( else { 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) 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) { priority = wp_data->priority; - if (priority && (priority <= BACNET_MAX_PRIORITIES) && + if (priority && (priority <= BACNET_MAX_PRIORITY) && (priority != 6 /* reserved */) && (wp_data->value.type.Real >= 0.0) && (wp_data->value.type.Real <= 100.0)) @@ -320,7 +320,7 @@ bool Analog_Output_Write_Property( object_index = Analog_Output_Instance_To_Index( wp_data->object_instance); priority = wp_data->priority; - if (priority && (priority <= BACNET_MAX_PRIORITIES)) + if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; Analog_Output_Level[object_index][priority] = level; diff --git a/bacnet-stack/wp.c b/bacnet-stack/wp.c index 8582212b..4b3c51f0 100644 --- a/bacnet-stack/wp.c +++ b/bacnet-stack/wp.c @@ -66,7 +66,7 @@ int wp_encode_apdu( apdu_len += bacapp_encode_application_data(&apdu[apdu_len], &data->value); apdu_len += encode_closing_tag(&apdu[apdu_len], 3); // 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, data->priority); } @@ -133,8 +133,8 @@ int wp_decode_service_request( return -1; // a tag number of 3 is not extended so only one octet len++; - // Tag 4: optional Priority - data->priority = BACNET_MAX_PRIORITIES; + // Tag 4: optional Priority - assumed MAX if not explicitly set + data->priority = BACNET_MAX_PRIORITY; if ((unsigned)len < apdu_len) { tag_len = decode_tag_number_and_value(&apdu[len], @@ -143,8 +143,13 @@ int wp_decode_service_request( { len += tag_len; len = decode_unsigned(&apdu[len], len_value_type, &unsigned_value); - /* FIXME: bounds check */ - data->priority = (uint8_t)unsigned_value; + if ((unsigned_value >= BACNET_MIN_PRIORITY) && + (unsigned_value <= BACNET_MAX_PRIORITY)) + { + data->priority = (uint8_t)unsigned_value; + } + else + return -1; } } }