Added diagnostic debug to load control object for verification.

This commit is contained in:
skarg
2007-02-22 22:25:11 +00:00
parent f36425de09
commit ada921d5f3
+59 -17
View File
@@ -358,23 +358,34 @@ typedef enum load_control_state {
SHED_INACTIVE, SHED_INACTIVE,
SHED_REQUEST_PENDING, SHED_REQUEST_PENDING,
SHED_NON_COMPLIANT, SHED_NON_COMPLIANT,
SHED_COMPLIANT SHED_COMPLIANT,
MAX_LOAD_CONTROL_STATE
} LOAD_CONTROL_STATE; } LOAD_CONTROL_STATE;
static LOAD_CONTROL_STATE Load_Control_State[MAX_LOAD_CONTROLS]; static LOAD_CONTROL_STATE Load_Control_State[MAX_LOAD_CONTROLS];
static LOAD_CONTROL_STATE Load_Control_State_Previously[MAX_LOAD_CONTROLS];
static void Print_Load_Control_State(int object_index)
{
char *Load_Control_State_Text[MAX_LOAD_CONTROLS] = {
"SHED_INACTIVE",
"SHED_REQUEST_PENDING",
"SHED_NON_COMPLIANT",
"SHED_COMPLIANT"
};
if (object_index < MAX_LOAD_CONTROLS) {
if (Load_Control_State[object_index] < MAX_LOAD_CONTROL_STATE) {
printf("Load Control[%d]=%s\n",object_index,
Load_Control_State_Text[Load_Control_State[object_index]]);
}
}
}
void Load_Control_State_Machine(int object_index) void Load_Control_State_Machine(int object_index)
{ {
static bool initialized = false;
unsigned i = 0; /* loop counter */ unsigned i = 0; /* loop counter */
int diff = 0; /* used for datetime comparison */ int diff = 0; /* used for datetime comparison */
if (!initialized) {
initialized = true;
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
Load_Control_State[i] = SHED_INACTIVE;
}
}
switch (Load_Control_State[object_index]) { switch (Load_Control_State[object_index]) {
case SHED_REQUEST_PENDING: case SHED_REQUEST_PENDING:
if (Load_Control_Request_Written[object_index]) { if (Load_Control_Request_Written[object_index]) {
@@ -398,8 +409,10 @@ void Load_Control_State_Machine(int object_index)
Load_Control_State[object_index] = SHED_INACTIVE; Load_Control_State[object_index] = SHED_INACTIVE;
break; break;
} }
if (Load_Control_State[object_index] == SHED_INACTIVE) if (Load_Control_State[object_index] == SHED_INACTIVE) {
printf("Load Control[%d]:Requested Shed Level=Default\n",object_index);
break; break;
}
} }
if (Start_Time_Property_Written[object_index]) { if (Start_Time_Property_Written[object_index]) {
Start_Time_Property_Written[object_index] = false; Start_Time_Property_Written[object_index] = false;
@@ -418,6 +431,7 @@ void Load_Control_State_Machine(int object_index)
if (diff < 0) { if (diff < 0) {
/* CancelShed */ /* CancelShed */
/* FIXME: stop shedding! i.e. relinquish */ /* FIXME: stop shedding! i.e. relinquish */
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
Load_Control_State[object_index] = SHED_INACTIVE; Load_Control_State[object_index] = SHED_INACTIVE;
break; break;
} }
@@ -433,6 +447,7 @@ void Load_Control_State_Machine(int object_index)
Requested_Shed_Level[object_index].type); Requested_Shed_Level[object_index].type);
} else if (diff > 0) { } else if (diff > 0) {
/* current time after to start time */ /* current time after to start time */
printf("Load Control[%d]:Current Time is after Start Time\n",object_index);
/* AbleToMeetShed */ /* AbleToMeetShed */
if (Able_To_Meet_Shed_Request(object_index)) { if (Able_To_Meet_Shed_Request(object_index)) {
Shed_Level_Copy( Shed_Level_Copy(
@@ -464,12 +479,14 @@ void Load_Control_State_Machine(int object_index)
diff = datetime_compare(&End_Time[object_index], &Current_Time); diff = datetime_compare(&End_Time[object_index], &Current_Time);
if (diff < 0) { if (diff < 0) {
/* FinishedUnsuccessfulShed */ /* FinishedUnsuccessfulShed */
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
Load_Control_State[object_index] = SHED_INACTIVE; Load_Control_State[object_index] = SHED_INACTIVE;
break; break;
} }
if (Load_Control_Request_Written[object_index] || if (Load_Control_Request_Written[object_index] ||
Start_Time_Property_Written[object_index]) { Start_Time_Property_Written[object_index]) {
/* UnsuccessfulShedReconfigured */ /* UnsuccessfulShedReconfigured */
printf("Load Control[%d]:Control Property written\n",object_index);
Load_Control_Request_Written[object_index] = false; Load_Control_Request_Written[object_index] = false;
Start_Time_Property_Written[object_index] = false; Start_Time_Property_Written[object_index] = false;
Load_Control_State[object_index] = SHED_REQUEST_PENDING; Load_Control_State[object_index] = SHED_REQUEST_PENDING;
@@ -477,6 +494,7 @@ void Load_Control_State_Machine(int object_index)
} }
if (Able_To_Meet_Shed_Request(object_index)) { if (Able_To_Meet_Shed_Request(object_index)) {
/* CanNowComplyWithShed */ /* CanNowComplyWithShed */
printf("Load Control[%d]:Able to meet Shed Request\n",object_index);
Shed_Level_Copy( Shed_Level_Copy(
&Expected_Shed_Level[object_index], &Expected_Shed_Level[object_index],
&Requested_Shed_Level[object_index]); &Requested_Shed_Level[object_index]);
@@ -496,6 +514,7 @@ void Load_Control_State_Machine(int object_index)
diff = datetime_compare(&End_Time[object_index], &Current_Time); diff = datetime_compare(&End_Time[object_index], &Current_Time);
if (diff < 0) { if (diff < 0) {
/* FinishedSuccessfulShed */ /* FinishedSuccessfulShed */
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
datetime_wildcard_set(&Start_Time[i]); datetime_wildcard_set(&Start_Time[i]);
Load_Control_State[object_index] = SHED_INACTIVE; Load_Control_State[object_index] = SHED_INACTIVE;
break; break;
@@ -503,6 +522,7 @@ void Load_Control_State_Machine(int object_index)
if (Load_Control_Request_Written[object_index] || if (Load_Control_Request_Written[object_index] ||
Start_Time_Property_Written[object_index]) { Start_Time_Property_Written[object_index]) {
/* UnsuccessfulShedReconfigured */ /* UnsuccessfulShedReconfigured */
printf("Load Control[%d]:Control Property written\n",object_index);
Load_Control_Request_Written[object_index] = false; Load_Control_Request_Written[object_index] = false;
Start_Time_Property_Written[object_index] = false; Start_Time_Property_Written[object_index] = false;
Load_Control_State[object_index] = SHED_REQUEST_PENDING; Load_Control_State[object_index] = SHED_REQUEST_PENDING;
@@ -510,6 +530,7 @@ void Load_Control_State_Machine(int object_index)
} }
if (!Able_To_Meet_Shed_Request(object_index)) { if (!Able_To_Meet_Shed_Request(object_index)) {
/* CanNoLongerComplyWithShed */ /* CanNoLongerComplyWithShed */
printf("Load Control[%d]:Not able to meet Shed Request\n",object_index);
Shed_Level_Default_Set( Shed_Level_Default_Set(
&Expected_Shed_Level[object_index], &Expected_Shed_Level[object_index],
Requested_Shed_Level[object_index].type); Requested_Shed_Level[object_index].type);
@@ -522,6 +543,7 @@ void Load_Control_State_Machine(int object_index)
case SHED_INACTIVE: case SHED_INACTIVE:
default: default:
if (Start_Time_Property_Written[object_index]) { if (Start_Time_Property_Written[object_index]) {
printf("Load Control[%d]:Start Time written\n",object_index);
Start_Time_Property_Written[object_index] = false; Start_Time_Property_Written[object_index] = false;
Shed_Level_Copy( Shed_Level_Copy(
&Expected_Shed_Level[object_index], &Expected_Shed_Level[object_index],
@@ -541,10 +563,24 @@ void Load_Control_State_Machine(int object_index)
void Load_Control_State_Machine_Handler(void) void Load_Control_State_Machine_Handler(void)
{ {
unsigned i = 0; unsigned i = 0;
static bool initialized = false;
Load_Control_Init(); Load_Control_Init();
if (!initialized) {
initialized = true;
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
Load_Control_State[i] = SHED_INACTIVE;
Load_Control_State_Previously[i] = SHED_INACTIVE;
}
}
for (i = 0; i < MAX_LOAD_CONTROLS; i++) { for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
Load_Control_State_Machine(i); Load_Control_State_Machine(i);
if (Load_Control_State[i] != Load_Control_State_Previously[i]) {
Print_Load_Control_State(i);
Load_Control_State_Previously[i] = Load_Control_State[i];
}
} }
} }
@@ -910,13 +946,19 @@ void testLoadControlStateMachine(Test * pTest)
{ {
unsigned i = 0, j = 0; unsigned i = 0, j = 0;
Load_Control_Init(); Load_Control_Init();
BACNET_APPLICATION_DATA_VALUE value;
BACNET_ERROR_CLASS error_class;
BACNET_APPLICATION_DATA_VALUE value;
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
bool status = false;
BACNET_WRITE_PROPERTY_DATA wp_data;
/* validate the triggers for each state change */
for (j = 0; j < 20; j++) { for (j = 0; j < 20; j++) {
Load_Control_State_Machine_Handler(); Load_Control_State_Machine_Handler();
for (i = 0; i < MAX_LOAD_CONTROLS; i++) { for (i = 0; i < MAX_LOAD_CONTROLS; i++) {