Added diagnostic debug to load control object for verification.
This commit is contained in:
+242
-200
@@ -35,26 +35,26 @@
|
|||||||
#include "datetime.h"
|
#include "datetime.h"
|
||||||
#include "bacenum.h"
|
#include "bacenum.h"
|
||||||
#include "config.h" /* the custom stuff */
|
#include "config.h" /* the custom stuff */
|
||||||
#include "lc.h"
|
#include "lc.h"
|
||||||
#include "ao.h"
|
#include "ao.h"
|
||||||
#include "wp.h"
|
#include "wp.h"
|
||||||
|
|
||||||
/* number of demo objects */
|
/* number of demo objects */
|
||||||
#define MAX_LOAD_CONTROLS 4
|
#define MAX_LOAD_CONTROLS 4
|
||||||
|
|
||||||
/* indicates the current load shedding state of the object */
|
/* indicates the current load shedding state of the object */
|
||||||
static BACNET_SHED_STATE Present_Value[MAX_LOAD_CONTROLS];
|
static BACNET_SHED_STATE Present_Value[MAX_LOAD_CONTROLS];
|
||||||
|
|
||||||
/* load control objects are required to support LEVEL */
|
/* load control objects are required to support LEVEL */
|
||||||
typedef enum BACnetShedLevelType {
|
typedef enum BACnetShedLevelType {
|
||||||
BACNET_SHED_TYPE_PERCENT, /* Unsigned */
|
BACNET_SHED_TYPE_PERCENT, /* Unsigned */
|
||||||
BACNET_SHED_TYPE_LEVEL, /* Unsigned */
|
BACNET_SHED_TYPE_LEVEL, /* Unsigned */
|
||||||
BACNET_SHED_TYPE_AMOUNT /* REAL */
|
BACNET_SHED_TYPE_AMOUNT /* REAL */
|
||||||
} BACNET_SHED_LEVEL_TYPE;
|
} BACNET_SHED_LEVEL_TYPE;
|
||||||
|
|
||||||
#define DEFAULT_VALUE_PERCENT 100
|
#define DEFAULT_VALUE_PERCENT 100
|
||||||
#define DEFAULT_VALUE_LEVEL 0
|
#define DEFAULT_VALUE_LEVEL 0
|
||||||
#define DEFAULT_VALUE_AMOUNT 0
|
#define DEFAULT_VALUE_AMOUNT 0
|
||||||
|
|
||||||
/* The shed levels for the LEVEL choice of BACnetShedLevel
|
/* The shed levels for the LEVEL choice of BACnetShedLevel
|
||||||
that have meaning for this particular Load Control object. */
|
that have meaning for this particular Load Control object. */
|
||||||
@@ -91,8 +91,8 @@ static uint32_t Duty_Window[MAX_LOAD_CONTROLS];
|
|||||||
/* indicates and controls whether the Load Control object is
|
/* indicates and controls whether the Load Control object is
|
||||||
currently enabled to respond to load shed requests. */
|
currently enabled to respond to load shed requests. */
|
||||||
static bool Load_Control_Enable[MAX_LOAD_CONTROLS];
|
static bool Load_Control_Enable[MAX_LOAD_CONTROLS];
|
||||||
|
|
||||||
/* indicates when the object receives a write to any of the properties
|
/* indicates when the object receives a write to any of the properties
|
||||||
Requested_Shed_Level, Shed_Duration, Duty_Window */
|
Requested_Shed_Level, Shed_Duration, Duty_Window */
|
||||||
static bool Load_Control_Request_Written[MAX_LOAD_CONTROLS];
|
static bool Load_Control_Request_Written[MAX_LOAD_CONTROLS];
|
||||||
/* indicates when the object receives a write to Start_Time */
|
/* indicates when the object receives a write to Start_Time */
|
||||||
@@ -118,12 +118,12 @@ static char *Shed_Level_Descriptions[MAX_SHED_LEVELS] = {
|
|||||||
"dim lights 20%",
|
"dim lights 20%",
|
||||||
"dim lights 30%"
|
"dim lights 30%"
|
||||||
};
|
};
|
||||||
static float Shed_Level_Values[MAX_SHED_LEVELS] = {
|
static float Shed_Level_Values[MAX_SHED_LEVELS] = {
|
||||||
90.0,
|
90.0,
|
||||||
80.0,
|
80.0,
|
||||||
70.0
|
70.0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* we need to have our arrays initialized before answering any calls */
|
/* we need to have our arrays initialized before answering any calls */
|
||||||
static bool Load_Control_Initialized = false;
|
static bool Load_Control_Initialized = false;
|
||||||
@@ -139,7 +139,7 @@ void Load_Control_Init(void)
|
|||||||
Present_Value[i] = BACNET_SHED_INACTIVE;
|
Present_Value[i] = BACNET_SHED_INACTIVE;
|
||||||
Requested_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL;
|
Requested_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL;
|
||||||
Requested_Shed_Level[i].value.level = 0;
|
Requested_Shed_Level[i].value.level = 0;
|
||||||
datetime_wildcard_set(&Start_Time[i]);
|
datetime_wildcard_set(&Start_Time[i]);
|
||||||
Shed_Duration[i] = 0;
|
Shed_Duration[i] = 0;
|
||||||
Duty_Window[i] = 0;
|
Duty_Window[i] = 0;
|
||||||
Load_Control_Enable[i] = true;
|
Load_Control_Enable[i] = true;
|
||||||
@@ -257,124 +257,135 @@ struct tm {
|
|||||||
(uint16_t)tblock->tm_year,
|
(uint16_t)tblock->tm_year,
|
||||||
(uint8_t)tblock->tm_mon,
|
(uint8_t)tblock->tm_mon,
|
||||||
(uint8_t)tblock->tm_mday,
|
(uint8_t)tblock->tm_mday,
|
||||||
(uint8_t)tblock->tm_hour,
|
(uint8_t)tblock->tm_hour,
|
||||||
(uint8_t)tblock->tm_min,
|
(uint8_t)tblock->tm_min,
|
||||||
(uint8_t)tblock->tm_sec, 0);
|
(uint8_t)tblock->tm_sec, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert the shed level request into an Analog Output Present_Value */
|
/* convert the shed level request into an Analog Output Present_Value */
|
||||||
static float Requested_Shed_Level_Value(int object_index)
|
static float Requested_Shed_Level_Value(int object_index)
|
||||||
{
|
{
|
||||||
unsigned shed_level_index = 0;
|
unsigned shed_level_index = 0;
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
float requested_level = 0.0;
|
float requested_level = 0.0;
|
||||||
|
|
||||||
switch (Requested_Shed_Level[object_index].type) {
|
switch (Requested_Shed_Level[object_index].type) {
|
||||||
case BACNET_SHED_TYPE_PERCENT:
|
case BACNET_SHED_TYPE_PERCENT:
|
||||||
requested_level = (float)Requested_Shed_Level[object_index].value.percent;
|
requested_level = (float)Requested_Shed_Level[object_index].value.percent;
|
||||||
break;
|
break;
|
||||||
case BACNET_SHED_TYPE_AMOUNT:
|
case BACNET_SHED_TYPE_AMOUNT:
|
||||||
/* Assumptions: wattage is linear with analog output level */
|
/* Assumptions: wattage is linear with analog output level */
|
||||||
requested_level = Full_Duty_Baseline[object_index] - Requested_Shed_Level[object_index].value.amount;
|
requested_level = Full_Duty_Baseline[object_index] - Requested_Shed_Level[object_index].value.amount;
|
||||||
requested_level /= Full_Duty_Baseline[object_index];
|
requested_level /= Full_Duty_Baseline[object_index];
|
||||||
requested_level *= 100.0;
|
requested_level *= 100.0;
|
||||||
break;
|
break;
|
||||||
case BACNET_SHED_TYPE_LEVEL:
|
case BACNET_SHED_TYPE_LEVEL:
|
||||||
default:
|
default:
|
||||||
for (i = 0; i < MAX_SHED_LEVELS; i++) {
|
for (i = 0; i < MAX_SHED_LEVELS; i++) {
|
||||||
if (Shed_Levels[object_index][i] <= Requested_Shed_Level[object_index].value.level)
|
if (Shed_Levels[object_index][i] <= Requested_Shed_Level[object_index].value.level)
|
||||||
shed_level_index = i;
|
shed_level_index = i;
|
||||||
}
|
}
|
||||||
requested_level = Shed_Level_Values[shed_level_index];
|
requested_level = Shed_Level_Values[shed_level_index];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return requested_level;
|
return requested_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Shed_Level_Copy(BACNET_SHED_LEVEL *dest, BACNET_SHED_LEVEL *src)
|
static void Shed_Level_Copy(BACNET_SHED_LEVEL *dest, BACNET_SHED_LEVEL *src)
|
||||||
{
|
{
|
||||||
if (dest && src) {
|
if (dest && src) {
|
||||||
dest->type = src->type;
|
dest->type = src->type;
|
||||||
switch (src->type) {
|
switch (src->type) {
|
||||||
case BACNET_SHED_TYPE_PERCENT:
|
case BACNET_SHED_TYPE_PERCENT:
|
||||||
dest->value.percent = src->value.percent;
|
dest->value.percent = src->value.percent;
|
||||||
break;
|
break;
|
||||||
case BACNET_SHED_TYPE_AMOUNT:
|
case BACNET_SHED_TYPE_AMOUNT:
|
||||||
dest->value.amount = src->value.amount;
|
dest->value.amount = src->value.amount;
|
||||||
break;
|
break;
|
||||||
case BACNET_SHED_TYPE_LEVEL:
|
case BACNET_SHED_TYPE_LEVEL:
|
||||||
default:
|
default:
|
||||||
dest->value.level = src->value.level;
|
dest->value.level = src->value.level;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Shed_Level_Default_Set(BACNET_SHED_LEVEL *dest, BACNET_SHED_LEVEL_TYPE type)
|
static void Shed_Level_Default_Set(BACNET_SHED_LEVEL *dest, BACNET_SHED_LEVEL_TYPE type)
|
||||||
{
|
{
|
||||||
if (dest) {
|
if (dest) {
|
||||||
dest->type = type;
|
dest->type = type;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BACNET_SHED_TYPE_PERCENT:
|
case BACNET_SHED_TYPE_PERCENT:
|
||||||
dest->value.percent = 100;
|
dest->value.percent = 100;
|
||||||
break;
|
break;
|
||||||
case BACNET_SHED_TYPE_AMOUNT:
|
case BACNET_SHED_TYPE_AMOUNT:
|
||||||
dest->value.amount = 0.0;
|
dest->value.amount = 0.0;
|
||||||
break;
|
break;
|
||||||
case BACNET_SHED_TYPE_LEVEL:
|
case BACNET_SHED_TYPE_LEVEL:
|
||||||
default:
|
default:
|
||||||
dest->value.level = 0;
|
dest->value.level = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool Able_To_Meet_Shed_Request(int object_index)
|
static bool Able_To_Meet_Shed_Request(int object_index)
|
||||||
{
|
{
|
||||||
float level = 0.0;
|
float level = 0.0;
|
||||||
float requested_level = 0.0;
|
float requested_level = 0.0;
|
||||||
unsigned priority = 0;
|
unsigned priority = 0;
|
||||||
bool status = false;
|
bool status = false;
|
||||||
int object_instance = 0;
|
int object_instance = 0;
|
||||||
|
|
||||||
/* This demo is going to use the Analog Outputs as their Load */
|
/* This demo is going to use the Analog Outputs as their Load */
|
||||||
object_instance = object_index;
|
object_instance = object_index;
|
||||||
priority = Analog_Output_Present_Value_Priority(object_instance);
|
priority = Analog_Output_Present_Value_Priority(object_instance);
|
||||||
/* we are controlling at Priority 4 - can we control the output? */
|
/* we are controlling at Priority 4 - can we control the output? */
|
||||||
if (priority >= 4) {
|
if (priority >= 4) {
|
||||||
/* is the level able to be lowered? */
|
/* is the level able to be lowered? */
|
||||||
requested_level = Requested_Shed_Level_Value(object_index);
|
requested_level = Requested_Shed_Level_Value(object_index);
|
||||||
level = Analog_Output_Present_Value(object_instance);
|
level = Analog_Output_Present_Value(object_instance);
|
||||||
if (level >= requested_level) {
|
if (level >= requested_level) {
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum load_control_state {
|
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;
|
||||||
@@ -408,7 +421,7 @@ void Load_Control_State_Machine(int object_index)
|
|||||||
Load_Control_State[object_index] = SHED_INACTIVE;
|
Load_Control_State[object_index] = SHED_INACTIVE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* cancel because current time is after start time + duration? */
|
/* cancel because current time is after start time + duration? */
|
||||||
Update_Current_Time(&Current_Time);
|
Update_Current_Time(&Current_Time);
|
||||||
datetime_copy(&End_Time[object_index], &Start_Time[object_index]);
|
datetime_copy(&End_Time[object_index], &Start_Time[object_index]);
|
||||||
@@ -418,45 +431,47 @@ 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;
|
||||||
}
|
}
|
||||||
diff = datetime_compare(&Current_Time, &Start_Time[object_index]);
|
diff = datetime_compare(&Current_Time, &Start_Time[object_index]);
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
/* current time prior to start time */
|
/* current time prior to start time */
|
||||||
/* ReconfigurePending */
|
/* ReconfigurePending */
|
||||||
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]);
|
||||||
Shed_Level_Default_Set(
|
Shed_Level_Default_Set(
|
||||||
&Actual_Shed_Level[object_index],
|
&Actual_Shed_Level[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(
|
||||||
&Expected_Shed_Level[object_index],
|
&Expected_Shed_Level[object_index],
|
||||||
&Requested_Shed_Level[object_index]);
|
&Requested_Shed_Level[object_index]);
|
||||||
Analog_Output_Present_Value_Set(object_index,
|
Analog_Output_Present_Value_Set(object_index,
|
||||||
Requested_Shed_Level_Value(object_index), 4);
|
Requested_Shed_Level_Value(object_index), 4);
|
||||||
Shed_Level_Copy(
|
Shed_Level_Copy(
|
||||||
&Actual_Shed_Level[object_index],
|
&Actual_Shed_Level[object_index],
|
||||||
&Requested_Shed_Level[object_index]);
|
&Requested_Shed_Level[object_index]);
|
||||||
Load_Control_State[object_index] = SHED_COMPLIANT;
|
Load_Control_State[object_index] = SHED_COMPLIANT;
|
||||||
} else {
|
} else {
|
||||||
/* CannotMeetShed */
|
/* CannotMeetShed */
|
||||||
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);
|
||||||
Shed_Level_Default_Set(
|
Shed_Level_Default_Set(
|
||||||
&Actual_Shed_Level[object_index],
|
&Actual_Shed_Level[object_index],
|
||||||
Requested_Shed_Level[object_index].type);
|
Requested_Shed_Level[object_index].type);
|
||||||
Load_Control_State[object_index] = SHED_NON_COMPLIANT;
|
Load_Control_State[object_index] = SHED_NON_COMPLIANT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SHED_NON_COMPLIANT:
|
case SHED_NON_COMPLIANT:
|
||||||
Update_Current_Time(&Current_Time);
|
Update_Current_Time(&Current_Time);
|
||||||
datetime_copy(&End_Time[object_index], &Start_Time[object_index]);
|
datetime_copy(&End_Time[object_index], &Start_Time[object_index]);
|
||||||
datetime_add_minutes(&End_Time[object_index],
|
datetime_add_minutes(&End_Time[object_index],
|
||||||
@@ -464,71 +479,78 @@ 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 */
|
||||||
Load_Control_Request_Written[object_index] = false;
|
printf("Load Control[%d]:Control Property written\n",object_index);
|
||||||
Start_Time_Property_Written[object_index] = false;
|
Load_Control_Request_Written[object_index] = false;
|
||||||
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
|
Start_Time_Property_Written[object_index] = false;
|
||||||
|
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Able_To_Meet_Shed_Request(object_index)) {
|
if (Able_To_Meet_Shed_Request(object_index)) {
|
||||||
/* CanNowComplyWithShed */
|
/* CanNowComplyWithShed */
|
||||||
Shed_Level_Copy(
|
printf("Load Control[%d]:Able to meet Shed Request\n",object_index);
|
||||||
&Expected_Shed_Level[object_index],
|
Shed_Level_Copy(
|
||||||
&Requested_Shed_Level[object_index]);
|
&Expected_Shed_Level[object_index],
|
||||||
Analog_Output_Present_Value_Set(object_index,
|
&Requested_Shed_Level[object_index]);
|
||||||
Requested_Shed_Level_Value(object_index), 4);
|
Analog_Output_Present_Value_Set(object_index,
|
||||||
Shed_Level_Copy(
|
Requested_Shed_Level_Value(object_index), 4);
|
||||||
&Actual_Shed_Level[object_index],
|
Shed_Level_Copy(
|
||||||
&Requested_Shed_Level[object_index]);
|
&Actual_Shed_Level[object_index],
|
||||||
Load_Control_State[object_index] = SHED_COMPLIANT;
|
&Requested_Shed_Level[object_index]);
|
||||||
|
Load_Control_State[object_index] = SHED_COMPLIANT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SHED_COMPLIANT:
|
case SHED_COMPLIANT:
|
||||||
Update_Current_Time(&Current_Time);
|
Update_Current_Time(&Current_Time);
|
||||||
datetime_copy(&End_Time[object_index], &Start_Time[object_index]);
|
datetime_copy(&End_Time[object_index], &Start_Time[object_index]);
|
||||||
datetime_add_minutes(&End_Time[object_index],
|
datetime_add_minutes(&End_Time[object_index],
|
||||||
Shed_Duration[object_index]);
|
Shed_Duration[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 */
|
||||||
datetime_wildcard_set(&Start_Time[i]);
|
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
|
||||||
|
datetime_wildcard_set(&Start_Time[i]);
|
||||||
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 */
|
||||||
Load_Control_Request_Written[object_index] = false;
|
printf("Load Control[%d]:Control Property written\n",object_index);
|
||||||
Start_Time_Property_Written[object_index] = false;
|
Load_Control_Request_Written[object_index] = false;
|
||||||
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
|
Start_Time_Property_Written[object_index] = false;
|
||||||
|
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!Able_To_Meet_Shed_Request(object_index)) {
|
if (!Able_To_Meet_Shed_Request(object_index)) {
|
||||||
/* CanNoLongerComplyWithShed */
|
/* CanNoLongerComplyWithShed */
|
||||||
Shed_Level_Default_Set(
|
printf("Load Control[%d]:Not able to meet Shed Request\n",object_index);
|
||||||
&Expected_Shed_Level[object_index],
|
Shed_Level_Default_Set(
|
||||||
Requested_Shed_Level[object_index].type);
|
&Expected_Shed_Level[object_index],
|
||||||
Shed_Level_Default_Set(
|
Requested_Shed_Level[object_index].type);
|
||||||
&Actual_Shed_Level[object_index],
|
Shed_Level_Default_Set(
|
||||||
Requested_Shed_Level[object_index].type);
|
&Actual_Shed_Level[object_index],
|
||||||
|
Requested_Shed_Level[object_index].type);
|
||||||
Load_Control_State[object_index] = SHED_NON_COMPLIANT;
|
Load_Control_State[object_index] = SHED_NON_COMPLIANT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
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],
|
||||||
&Requested_Shed_Level[object_index]);
|
&Requested_Shed_Level[object_index]);
|
||||||
Shed_Level_Default_Set(
|
Shed_Level_Default_Set(
|
||||||
&Actual_Shed_Level[object_index],
|
&Actual_Shed_Level[object_index],
|
||||||
Requested_Shed_Level[object_index].type);
|
Requested_Shed_Level[object_index].type);
|
||||||
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
|
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -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];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -792,7 +828,7 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
|||||||
wp_data->application_data_len,
|
wp_data->application_data_len,
|
||||||
&value, PROP_REQUESTED_SHED_LEVEL);
|
&value, PROP_REQUESTED_SHED_LEVEL);
|
||||||
if (value.tag == 0) {
|
if (value.tag == 0) {
|
||||||
/* percent - Unsigned */
|
/* percent - Unsigned */
|
||||||
Requested_Shed_Level[object_index].type = BACNET_SHED_TYPE_PERCENT;
|
Requested_Shed_Level[object_index].type = BACNET_SHED_TYPE_PERCENT;
|
||||||
Requested_Shed_Level[object_index].value.percent =
|
Requested_Shed_Level[object_index].value.percent =
|
||||||
value.type.Unsigned_Int;
|
value.type.Unsigned_Int;
|
||||||
@@ -813,9 +849,9 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
|||||||
/* error! */
|
/* error! */
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
if (status) {
|
if (status) {
|
||||||
Load_Control_Request_Written[object_index] = true;
|
Load_Control_Request_Written[object_index] = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PROP_START_TIME:
|
case PROP_START_TIME:
|
||||||
@@ -905,31 +941,37 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "ctest.h"
|
#include "ctest.h"
|
||||||
|
|
||||||
void testLoadControlStateMachine(Test * pTest)
|
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_APPLICATION_DATA_VALUE value;
|
||||||
|
|
||||||
BACNET_ERROR_CLASS error_class;
|
BACNET_ERROR_CLASS error_class;
|
||||||
|
|
||||||
BACNET_ERROR_CODE error_code;
|
BACNET_ERROR_CODE error_code;
|
||||||
|
|
||||||
bool status = false;
|
bool status = false;
|
||||||
|
|
||||||
|
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||||
|
|
||||||
|
|
||||||
|
/* validate the triggers for each state change */
|
||||||
|
for (j = 0; j < 20; j++) {
|
||||||
|
Load_Control_State_Machine_Handler();
|
||||||
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
|
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
|
||||||
|
ct_test(pTest, Load_Control_State[i] == SHED_INACTIVE);
|
||||||
|
}
|
||||||
/* validate the triggers for each state change */
|
}
|
||||||
for (j = 0; j < 20; j++) {
|
|
||||||
Load_Control_State_Machine_Handler();
|
/**/
|
||||||
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
|
status = Load_Control_Write_Property(&wp_data, &error_class, &error_code);
|
||||||
ct_test(pTest, Load_Control_State[i] == SHED_INACTIVE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testLoadControl(Test * pTest)
|
void testLoadControl(Test * pTest)
|
||||||
@@ -969,7 +1011,7 @@ int main(void)
|
|||||||
pTest = ct_create("BACnet Load Control", NULL);
|
pTest = ct_create("BACnet Load Control", NULL);
|
||||||
/* individual tests */
|
/* individual tests */
|
||||||
rc = ct_addTestFunction(pTest, testLoadControl);
|
rc = ct_addTestFunction(pTest, testLoadControl);
|
||||||
Test *pTest;
|
assert(rc);
|
||||||
rc = ct_addTestFunction(pTest, testLoadControlStateMachine);
|
rc = ct_addTestFunction(pTest, testLoadControlStateMachine);
|
||||||
assert(rc);
|
assert(rc);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user