From bfc82bd07db713f9209bf2541f6a43240e41e21b Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 8 Feb 2007 21:57:47 +0000 Subject: [PATCH] Changed array element 0 to be more clear in the code. --- bacnet-stack/bacdef.h | 1 - bacnet-stack/demo/object/ao.c | 2 +- bacnet-stack/demo/object/av.c | 2 +- bacnet-stack/demo/object/bo.c | 2 +- bacnet-stack/demo/object/bv.c | 2 +- bacnet-stack/demo/object/device.c | 2 +- bacnet-stack/demo/object/lc.c | 45 ++++++++++++++++++++++---- bacnet-stack/demo/object/mso.c | 2 +- bacnet-stack/ports/pic18/device.c | 2 +- bacnet-stack/ports/pic18f6720/device.c | 2 +- 10 files changed, 46 insertions(+), 16 deletions(-) diff --git a/bacnet-stack/bacdef.h b/bacnet-stack/bacdef.h index dc489ed6..dc7efe04 100644 --- a/bacnet-stack/bacdef.h +++ b/bacnet-stack/bacdef.h @@ -50,7 +50,6 @@ /* large BACnet Object Type */ #define BACNET_MAX_OBJECT (0x3FF) /* Array index 0=size of array, n=array element n, MAX=all array elements */ -#define BACNET_ARRAY_LENGTH_INDEX 0 #define BACNET_ARRAY_ALL (~0) /* Priority Array for commandable objects */ #define BACNET_NO_PRIORITY 0 diff --git a/bacnet-stack/demo/object/ao.c b/bacnet-stack/demo/object/ao.c index 29546f5d..e8c4b113 100644 --- a/bacnet-stack/demo/object/ao.c +++ b/bacnet-stack/demo/object/ao.c @@ -207,7 +207,7 @@ int Analog_Output_Encode_Property_APDU(uint8_t * apdu, break; case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY); /* if no index was specified, then try to encode the entire list */ diff --git a/bacnet-stack/demo/object/av.c b/bacnet-stack/demo/object/av.c index 4eaaa8a6..022ce72c 100644 --- a/bacnet-stack/demo/object/av.c +++ b/bacnet-stack/demo/object/av.c @@ -205,7 +205,7 @@ int Analog_Value_Encode_Property_APDU(uint8_t * apdu, break; case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY); /* if no index was specified, then try to encode the entire list */ diff --git a/bacnet-stack/demo/object/bo.c b/bacnet-stack/demo/object/bo.c index 67fe8ed7..a323b33b 100644 --- a/bacnet-stack/demo/object/bo.c +++ b/bacnet-stack/demo/object/bo.c @@ -201,7 +201,7 @@ int Binary_Output_Encode_Property_APDU(uint8_t * apdu, break; case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY); /* if no index was specified, then try to encode the entire list */ diff --git a/bacnet-stack/demo/object/bv.c b/bacnet-stack/demo/object/bv.c index deb25273..b915d8dc 100644 --- a/bacnet-stack/demo/object/bv.c +++ b/bacnet-stack/demo/object/bv.c @@ -200,7 +200,7 @@ int Binary_Value_Encode_Property_APDU(uint8_t * apdu, break; case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY); /* if no index was specified, then try to encode the entire list */ diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index 9d46114f..7ac7d35d 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -709,7 +709,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu, case PROP_OBJECT_LIST: count = Device_Object_List_Count(); /* Array element zero is the number of objects in the list */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], count); /* if no index was specified, then try to encode the entire list */ /* into one packet. Note that more than likely you will have */ diff --git a/bacnet-stack/demo/object/lc.c b/bacnet-stack/demo/object/lc.c index a472950e..ffab22ba 100644 --- a/bacnet-stack/demo/object/lc.c +++ b/bacnet-stack/demo/object/lc.c @@ -38,17 +38,22 @@ #include "lc.h" #include "wp.h" -/* number of objects */ -#define MAX_LOAD_CONTROLS 6 +/* number of demo objects */ +#define MAX_LOAD_CONTROLS 4 /* indicates the current load shedding state of the object */ static BACNET_SHED_STATE Present_Value[MAX_LOAD_CONTROLS]; - + +/* load control objects are required to support LEVEL */ typedef enum BACnetShedLevelType { BACNET_SHED_TYPE_PERCENT, /* Unsigned */ BACNET_SHED_TYPE_LEVEL, /* Unsigned */ BACNET_SHED_TYPE_AMOUNT /* REAL */ } BACNET_SHED_LEVEL_TYPE; + +#define DEFAULT_VALUE_PERCENT 100 +#define DEFAULT_VALUE_LEVEL 0 +#define DEFAULT_VALUE_AMOUNT 0 /* The shed levels for the LEVEL choice of BACnetShedLevel that have meaning for this particular Load Control object. */ @@ -265,7 +270,30 @@ void Load_Control_State_Machine(int object_index) } switch (state[object_index]) { - case SHED_REQUEST_PENDING: + case SHED_REQUEST_PENDING: + /* request to cancel using default values? */ + switch (Requested_Shed_Level[object_index].type) { + case BACNET_SHED_TYPE_PERCENT: + if (Requested_Shed_Level[object_index].value.percent == + DEFAULT_VALUE_PERCENT) + state[object_index] = SHED_INACTIVE; + break; + case BACNET_SHED_TYPE_AMOUNT: + if (Requested_Shed_Level[object_index].value.amount == + DEFAULT_VALUE_AMOUNT) + state[object_index] = SHED_INACTIVE; + break; + case BACNET_SHED_TYPE_LEVEL: + default: + if (Requested_Shed_Level[object_index].value.level == + DEFAULT_VALUE_LEVEL) + state[object_index] = SHED_INACTIVE; + break; + } + if (state[object_index] == SHED_INACTIVE) + break; + /* request to cancel using wildcards in start time? */ + /* cancel because current time is after start time + duration? */ Update_Current_Time(&Current_Time); datetime_copy(&End_Time[object_index], &Start_Time[object_index]); datetime_add_minutes(&End_Time[object_index], @@ -476,7 +504,7 @@ int Load_Control_Encode_Property_APDU(uint8_t * apdu, break; case PROP_SHED_LEVELS: /* Array element zero is the number of elements in the array */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], MAX_SHED_LEVELS); /* if no index was specified, then try to encode the entire list */ /* into one packet. */ @@ -510,7 +538,7 @@ int Load_Control_Encode_Property_APDU(uint8_t * apdu, break; case PROP_SHED_LEVEL_DESCRIPTIONS: /* Array element zero is the number of elements in the array */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], MAX_SHED_LEVELS); /* if no index was specified, then try to encode the entire list */ /* into one packet. */ @@ -583,17 +611,20 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, wp_data->application_data_len, &value, PROP_REQUESTED_SHED_LEVEL); if (value.tag == 0) { - /* percent - Unsigned */ + /* percent - Unsigned */ + Requested_Shed_Level[object_index].type = BACNET_SHED_TYPE_PERCENT; Requested_Shed_Level[object_index].value.percent = value.type.Unsigned_Int; status = true; } else if (value.tag == 1) { /* level - Unsigned */ + Requested_Shed_Level[object_index].type = BACNET_SHED_TYPE_LEVEL; Requested_Shed_Level[object_index].value.level = value.type.Unsigned_Int; status = true; } else if (value.tag == 2) { /* amount - REAL */ + Requested_Shed_Level[object_index].type = BACNET_SHED_TYPE_AMOUNT; Requested_Shed_Level[object_index].value.amount = value.type.Real; status = true; diff --git a/bacnet-stack/demo/object/mso.c b/bacnet-stack/demo/object/mso.c index adfb1eea..4c0395e9 100644 --- a/bacnet-stack/demo/object/mso.c +++ b/bacnet-stack/demo/object/mso.c @@ -203,7 +203,7 @@ int Multistate_Output_Encode_Property_APDU(uint8_t * apdu, break; case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY); /* if no index was specified, then try to encode the entire list */ diff --git a/bacnet-stack/ports/pic18/device.c b/bacnet-stack/ports/pic18/device.c index aacf011c..d5e68405 100644 --- a/bacnet-stack/ports/pic18/device.c +++ b/bacnet-stack/ports/pic18/device.c @@ -251,7 +251,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu, case PROP_OBJECT_LIST: count = Device_Object_List_Count(); /* Array element zero is the number of objects in the list */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], count); /* if no index was specified, then try to encode the entire list */ /* into one packet. Note that more than likely you will have */ diff --git a/bacnet-stack/ports/pic18f6720/device.c b/bacnet-stack/ports/pic18f6720/device.c index fbf2b2bb..9b12c1bb 100644 --- a/bacnet-stack/ports/pic18f6720/device.c +++ b/bacnet-stack/ports/pic18f6720/device.c @@ -343,7 +343,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu, case PROP_OBJECT_LIST: count = Device_Object_List_Count(); /* Array element zero is the number of objects in the list */ - if (array_index == BACNET_ARRAY_LENGTH_INDEX) + if (array_index == 0) apdu_len = encode_tagged_unsigned(&apdu[0], count); /* if no index was specified, then try to encode the entire list */ /* into one packet. Note that more than likely you will have */