Ran the indent and comment script to standardize the source files.

This commit is contained in:
skarg
2007-02-23 02:14:50 +00:00
parent ada921d5f3
commit 1386b41f2d
21 changed files with 983 additions and 987 deletions
+17 -21
View File
@@ -139,9 +139,9 @@ float Analog_Output_Present_Value(uint32_t object_instance)
unsigned Analog_Output_Present_Value_Priority(uint32_t object_instance)
{
unsigned index = 0; /* instance to index conversion */
unsigned i = 0; /* loop counter */
unsigned priority = 0; /* return value */
unsigned index = 0; /* instance to index conversion */
unsigned i = 0; /* loop counter */
unsigned priority = 0; /* return value */
Analog_Output_Init();
index = Analog_Output_Instance_To_Index(object_instance);
@@ -157,20 +157,18 @@ unsigned Analog_Output_Present_Value_Priority(uint32_t object_instance)
return priority;
}
bool Analog_Output_Present_Value_Set(
uint32_t object_instance,
float value,
unsigned priority)
bool Analog_Output_Present_Value_Set(uint32_t object_instance,
float value, unsigned priority)
{
unsigned index = 0;
bool status = false;
index = Analog_Output_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_OUTPUTS) {
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
(priority != 6 /* reserved */ ) &&
(value >= 0.0) && (value <= 100.0)) {
Analog_Output_Level[index][priority] = (uint8_t)value;
Analog_Output_Level[index][priority] = (uint8_t) value;
/* Note: you could set the physical output here to the next
highest priority, or to the relinquish default if no
priorities are set.
@@ -180,17 +178,16 @@ bool Analog_Output_Present_Value_Set(
status = true;
}
}
return status;
}
bool Analog_Output_Present_Value_Relinquish(
uint32_t object_instance,
bool Analog_Output_Present_Value_Relinquish(uint32_t object_instance,
int priority)
{
unsigned index = 0;
bool status = false;
index = Analog_Output_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_OUTPUTS) {
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
@@ -205,7 +202,7 @@ bool Analog_Output_Present_Value_Relinquish(
status = true;
}
}
return status;
}
@@ -366,10 +363,9 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
/* Command priority 6 is reserved for use by Minimum On/Off
algorithm and may not be used for other purposes in any
object. */
status = Analog_Output_Present_Value_Set(
wp_data->object_instance,
value.type.Real,
wp_data->priority);
status =
Analog_Output_Present_Value_Set(wp_data->object_instance,
value.type.Real, wp_data->priority);
if (wp_data->priority == 6) {
/* Command priority 6 is reserved for use by Minimum On/Off
algorithm and may not be used for other purposes in any
@@ -384,9 +380,9 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
level = AO_LEVEL_NULL;
object_index =
Analog_Output_Instance_To_Index(wp_data->object_instance);
status = Analog_Output_Present_Value_Relinquish(
wp_data->object_instance,
wp_data->priority);
status =
Analog_Output_Present_Value_Relinquish(wp_data->
object_instance, wp_data->priority);
if (!status) {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
+6 -8
View File
@@ -40,15 +40,13 @@ extern "C" {
uint32_t Analog_Output_Index_To_Instance(unsigned index);
char *Analog_Output_Name(uint32_t object_instance);
float Analog_Output_Present_Value(uint32_t object_instance);
unsigned Analog_Output_Present_Value_Priority(uint32_t object_instance);
bool Analog_Output_Present_Value_Set(
uint32_t object_instance,
float value,
unsigned priority);
bool Analog_Output_Present_Value_Relinquish(
uint32_t object_instance,
unsigned Analog_Output_Present_Value_Priority(uint32_t
object_instance);
bool Analog_Output_Present_Value_Set(uint32_t object_instance,
float value, unsigned priority);
bool Analog_Output_Present_Value_Relinquish(uint32_t object_instance,
int priority);
int Analog_Output_Encode_Property_APDU(uint8_t * apdu,
uint32_t object_instance,
+137 -128
View File
@@ -143,7 +143,7 @@ void Load_Control_Init(void)
Shed_Duration[i] = 0;
Duty_Window[i] = 0;
Load_Control_Enable[i] = true;
Full_Duty_Baseline[i] = 1.500; /* kilowatts */
Full_Duty_Baseline[i] = 1.500; /* kilowatts */
for (j = 0; j < MAX_SHED_LEVELS; j++) {
/* FIXME: fake data for lighting application */
/* The array shall be ordered by increasing shed amount. */
@@ -254,12 +254,11 @@ struct tm {
timer = time(NULL);
tblock = localtime(&timer);
datetime_set_values(bdatetime,
(uint16_t)tblock->tm_year,
(uint8_t)tblock->tm_mon,
(uint8_t)tblock->tm_mday,
(uint8_t)tblock->tm_hour,
(uint8_t)tblock->tm_min,
(uint8_t)tblock->tm_sec, 0);
(uint16_t) tblock->tm_year,
(uint8_t) tblock->tm_mon,
(uint8_t) tblock->tm_mday,
(uint8_t) tblock->tm_hour,
(uint8_t) tblock->tm_min, (uint8_t) tblock->tm_sec, 0);
}
/* convert the shed level request into an Analog Output Present_Value */
@@ -270,62 +269,68 @@ static float Requested_Shed_Level_Value(int object_index)
float requested_level = 0.0;
switch (Requested_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT:
requested_level = (float)Requested_Shed_Level[object_index].value.percent;
break;
case BACNET_SHED_TYPE_AMOUNT:
/* 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_level *= 100.0;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
for (i = 0; i < MAX_SHED_LEVELS; i++) {
if (Shed_Levels[object_index][i] <= Requested_Shed_Level[object_index].value.level)
shed_level_index = i;
}
requested_level = Shed_Level_Values[shed_level_index];
break;
case BACNET_SHED_TYPE_PERCENT:
requested_level =
(float) Requested_Shed_Level[object_index].value.percent;
break;
case BACNET_SHED_TYPE_AMOUNT:
/* 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_level *= 100.0;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
for (i = 0; i < MAX_SHED_LEVELS; i++) {
if (Shed_Levels[object_index][i] <=
Requested_Shed_Level[object_index].value.level)
shed_level_index = i;
}
requested_level = Shed_Level_Values[shed_level_index];
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) {
dest->type = src->type;
switch (src->type) {
case BACNET_SHED_TYPE_PERCENT:
dest->value.percent = src->value.percent;
break;
case BACNET_SHED_TYPE_AMOUNT:
dest->value.amount = src->value.amount;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
dest->value.level = src->value.level;
break;
case BACNET_SHED_TYPE_PERCENT:
dest->value.percent = src->value.percent;
break;
case BACNET_SHED_TYPE_AMOUNT:
dest->value.amount = src->value.amount;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
dest->value.level = src->value.level;
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) {
dest->type = type;
switch (type) {
case BACNET_SHED_TYPE_PERCENT:
dest->value.percent = 100;
break;
case BACNET_SHED_TYPE_AMOUNT:
dest->value.amount = 0.0;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
dest->value.level = 0;
break;
case BACNET_SHED_TYPE_PERCENT:
dest->value.percent = 100;
break;
case BACNET_SHED_TYPE_AMOUNT:
dest->value.amount = 0.0;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
dest->value.level = 0;
break;
}
}
}
@@ -337,7 +342,7 @@ static bool Able_To_Meet_Shed_Request(int object_index)
unsigned priority = 0;
bool status = false;
int object_instance = 0;
/* This demo is going to use the Analog Outputs as their Load */
object_instance = object_index;
priority = Analog_Output_Present_Value_Priority(object_instance);
@@ -350,8 +355,8 @@ static bool Able_To_Meet_Shed_Request(int object_index)
status = true;
}
}
return status;
return status;
}
typedef enum load_control_state {
@@ -367,15 +372,15 @@ 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"
"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,
printf("Load Control[%d]=%s\n", object_index,
Load_Control_State_Text[Load_Control_State[object_index]]);
}
}
@@ -387,42 +392,43 @@ void Load_Control_State_Machine(int object_index)
int diff = 0; /* used for datetime comparison */
switch (Load_Control_State[object_index]) {
case SHED_REQUEST_PENDING:
if (Load_Control_Request_Written[object_index]) {
Load_Control_Request_Written[object_index] = false;
/* 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)
Load_Control_State[object_index] = SHED_INACTIVE;
break;
case BACNET_SHED_TYPE_AMOUNT:
if (Requested_Shed_Level[object_index].value.amount ==
DEFAULT_VALUE_AMOUNT)
Load_Control_State[object_index] = SHED_INACTIVE;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
if (Requested_Shed_Level[object_index].value.level ==
DEFAULT_VALUE_LEVEL)
Load_Control_State[object_index] = SHED_INACTIVE;
break;
}
if (Load_Control_State[object_index] == SHED_INACTIVE) {
printf("Load Control[%d]:Requested Shed Level=Default\n",object_index);
break;
case SHED_REQUEST_PENDING:
if (Load_Control_Request_Written[object_index]) {
Load_Control_Request_Written[object_index] = false;
/* 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)
Load_Control_State[object_index] = SHED_INACTIVE;
break;
case BACNET_SHED_TYPE_AMOUNT:
if (Requested_Shed_Level[object_index].value.amount ==
DEFAULT_VALUE_AMOUNT)
Load_Control_State[object_index] = SHED_INACTIVE;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
if (Requested_Shed_Level[object_index].value.level ==
DEFAULT_VALUE_LEVEL)
Load_Control_State[object_index] = SHED_INACTIVE;
break;
}
if (Load_Control_State[object_index] == SHED_INACTIVE) {
printf("Load Control[%d]:Requested Shed Level=Default\n",
object_index);
break;
}
}
if (Start_Time_Property_Written[object_index]) {
Start_Time_Property_Written[object_index] = false;
/* request to cancel using wildcards in start time? */
if (datetime_wildcard(&Start_Time[object_index])) {
Start_Time_Property_Written[object_index] = false;
/* request to cancel using wildcards in start time? */
if (datetime_wildcard(&Start_Time[object_index])) {
Load_Control_State[object_index] = SHED_INACTIVE;
break;
}
}
}
/* cancel because current time is after start time + duration? */
/* 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],
@@ -431,7 +437,9 @@ void Load_Control_State_Machine(int object_index)
if (diff < 0) {
/* CancelShed */
/* FIXME: stop shedding! i.e. relinquish */
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
printf
("Load Control[%d]:Current Time is after Start Time + Duration\n",
object_index);
Load_Control_State[object_index] = SHED_INACTIVE;
break;
}
@@ -439,33 +447,28 @@ void Load_Control_State_Machine(int object_index)
if (diff < 0) {
/* current time prior to start time */
/* ReconfigurePending */
Shed_Level_Copy(
&Expected_Shed_Level[object_index],
Shed_Level_Copy(&Expected_Shed_Level[object_index],
&Requested_Shed_Level[object_index]);
Shed_Level_Default_Set(
&Actual_Shed_Level[object_index],
Shed_Level_Default_Set(&Actual_Shed_Level[object_index],
Requested_Shed_Level[object_index].type);
} else if (diff > 0) {
/* current time after to start time */
printf("Load Control[%d]:Current Time is after Start Time\n",object_index);
printf("Load Control[%d]:Current Time is after Start Time\n",
object_index);
/* AbleToMeetShed */
if (Able_To_Meet_Shed_Request(object_index)) {
Shed_Level_Copy(
&Expected_Shed_Level[object_index],
Shed_Level_Copy(&Expected_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);
Shed_Level_Copy(
&Actual_Shed_Level[object_index],
Shed_Level_Copy(&Actual_Shed_Level[object_index],
&Requested_Shed_Level[object_index]);
Load_Control_State[object_index] = SHED_COMPLIANT;
} else {
/* CannotMeetShed */
Shed_Level_Default_Set(
&Expected_Shed_Level[object_index],
Shed_Level_Default_Set(&Expected_Shed_Level[object_index],
Requested_Shed_Level[object_index].type);
Shed_Level_Default_Set(
&Actual_Shed_Level[object_index],
Shed_Level_Default_Set(&Actual_Shed_Level[object_index],
Requested_Shed_Level[object_index].type);
Load_Control_State[object_index] = SHED_NON_COMPLIANT;
}
@@ -479,14 +482,17 @@ void Load_Control_State_Machine(int object_index)
diff = datetime_compare(&End_Time[object_index], &Current_Time);
if (diff < 0) {
/* FinishedUnsuccessfulShed */
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
printf
("Load Control[%d]:Current Time is after Start Time + Duration\n",
object_index);
Load_Control_State[object_index] = SHED_INACTIVE;
break;
}
if (Load_Control_Request_Written[object_index] ||
if (Load_Control_Request_Written[object_index] ||
Start_Time_Property_Written[object_index]) {
/* UnsuccessfulShedReconfigured */
printf("Load Control[%d]:Control Property written\n",object_index);
printf("Load Control[%d]:Control Property written\n",
object_index);
Load_Control_Request_Written[object_index] = false;
Start_Time_Property_Written[object_index] = false;
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
@@ -494,14 +500,13 @@ void Load_Control_State_Machine(int object_index)
}
if (Able_To_Meet_Shed_Request(object_index)) {
/* CanNowComplyWithShed */
printf("Load Control[%d]:Able to meet Shed Request\n",object_index);
Shed_Level_Copy(
&Expected_Shed_Level[object_index],
printf("Load Control[%d]:Able to meet Shed Request\n",
object_index);
Shed_Level_Copy(&Expected_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);
Shed_Level_Copy(
&Actual_Shed_Level[object_index],
Shed_Level_Copy(&Actual_Shed_Level[object_index],
&Requested_Shed_Level[object_index]);
Load_Control_State[object_index] = SHED_COMPLIANT;
}
@@ -514,15 +519,18 @@ void Load_Control_State_Machine(int object_index)
diff = datetime_compare(&End_Time[object_index], &Current_Time);
if (diff < 0) {
/* FinishedSuccessfulShed */
printf("Load Control[%d]:Current Time is after Start Time + Duration\n",object_index);
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;
break;
}
if (Load_Control_Request_Written[object_index] ||
Start_Time_Property_Written[object_index]) {
if (Load_Control_Request_Written[object_index] ||
Start_Time_Property_Written[object_index]) {
/* UnsuccessfulShedReconfigured */
printf("Load Control[%d]:Control Property written\n",object_index);
printf("Load Control[%d]:Control Property written\n",
object_index);
Load_Control_Request_Written[object_index] = false;
Start_Time_Property_Written[object_index] = false;
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
@@ -530,12 +538,11 @@ void Load_Control_State_Machine(int object_index)
}
if (!Able_To_Meet_Shed_Request(object_index)) {
/* CanNoLongerComplyWithShed */
printf("Load Control[%d]:Not able to meet Shed Request\n",object_index);
Shed_Level_Default_Set(
&Expected_Shed_Level[object_index],
printf("Load Control[%d]:Not able to meet Shed Request\n",
object_index);
Shed_Level_Default_Set(&Expected_Shed_Level[object_index],
Requested_Shed_Level[object_index].type);
Shed_Level_Default_Set(
&Actual_Shed_Level[object_index],
Shed_Level_Default_Set(&Actual_Shed_Level[object_index],
Requested_Shed_Level[object_index].type);
Load_Control_State[object_index] = SHED_NON_COMPLIANT;
}
@@ -543,13 +550,11 @@ void Load_Control_State_Machine(int object_index)
case SHED_INACTIVE:
default:
if (Start_Time_Property_Written[object_index]) {
printf("Load Control[%d]:Start Time written\n",object_index);
printf("Load Control[%d]:Start Time written\n", object_index);
Start_Time_Property_Written[object_index] = false;
Shed_Level_Copy(
&Expected_Shed_Level[object_index],
Shed_Level_Copy(&Expected_Shed_Level[object_index],
&Requested_Shed_Level[object_index]);
Shed_Level_Default_Set(
&Actual_Shed_Level[object_index],
Shed_Level_Default_Set(&Actual_Shed_Level[object_index],
Requested_Shed_Level[object_index].type);
Load_Control_State[object_index] = SHED_REQUEST_PENDING;
}
@@ -829,19 +834,22 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
&value, PROP_REQUESTED_SHED_LEVEL);
if (value.tag == 0) {
/* 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 =
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].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].type =
BACNET_SHED_TYPE_AMOUNT;
Requested_Shed_Level[object_index].value.amount =
value.type.Real;
status = true;
@@ -966,8 +974,9 @@ void testLoadControlStateMachine(Test * pTest)
}
}
/**/
status = Load_Control_Write_Property(&wp_data, &error_class, &error_code);
/**/
status =
Load_Control_Write_Property(&wp_data, &error_class, &error_code);
+1 -1
View File
@@ -34,7 +34,7 @@
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void Load_Control_State_Machine_Handler(void);
bool Load_Control_Valid_Instance(uint32_t object_instance);