Standardized the comments and indentation using the comment.sh and indent.sh scripts.

This commit is contained in:
skarg
2007-02-02 02:25:15 +00:00
parent 5e7c88b171
commit 71d59fbb8b
42 changed files with 5623 additions and 5690 deletions
+1 -2
View File
@@ -54,8 +54,7 @@ static uint8_t Temp_Buf[MAX_APDU] = { 0 };
void handler_read_property(uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_DATA * service_data)
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data)
{
BACNET_READ_PROPERTY_DATA data;
int len = 0;
+2 -2
View File
@@ -67,11 +67,11 @@ static void PrintReadPropertyData(BACNET_READ_PROPERTY_DATA * data)
#endif
application_data = data->application_data;
application_data_len = data->application_data_len;
/* FIXME: what if application_data_len is bigger than 255? */
/* FIXME: what if application_data_len is bigger than 255? */
/* value? need to loop until all of the len is gone... */
for (;;) {
len = bacapp_decode_application_data(application_data,
(uint8_t)application_data_len, &value);
(uint8_t) application_data_len, &value);
if (first_value && (len < application_data_len)) {
first_value = false;
fprintf(stdout, "{");
+2 -1
View File
@@ -259,7 +259,8 @@ void handler_write_property(uint8_t * service_request,
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
error_code);
#if PRINT_ENABLED
fprintf(stderr, "Sending Write Access Error for Load Control!\n");
fprintf(stderr,
"Sending Write Access Error for Load Control!\n");
#endif
}
break;
+2 -1
View File
@@ -89,7 +89,8 @@ uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */
max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len);
&npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
+4 -3
View File
@@ -81,8 +81,8 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */
data.object_property = object_property;
data.array_index = array_index;
data.application_data_len =
bacapp_encode_application_data(
&data.application_data[0],object_value);
bacapp_encode_application_data(&data.application_data[0],
object_value);
data.priority = priority;
len = wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
invoke_id, &data);
@@ -94,7 +94,8 @@ uint8_t Send_Write_Property_Request(uint32_t device_id, /* destination device */
max_apdu in the address binding table. */
if ((unsigned) pdu_len < max_apdu) {
tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest,
&npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len);
&npdu_data, &Handler_Transmit_Buffer[0],
(uint16_t) pdu_len);
bytes_sent =
datalink_send_pdu(&dest, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len);
+2 -2
View File
@@ -84,7 +84,7 @@ int Analog_Input_Encode_Property_APDU(uint8_t * apdu,
int apdu_len = 0; /* return value */
BACNET_BIT_STRING bit_string;
BACNET_CHARACTER_STRING char_string;
float value = (float)3.14;
float value = (float) 3.14;
(void) array_index;
switch (property) {
@@ -122,7 +122,7 @@ int Analog_Input_Encode_Property_APDU(uint8_t * apdu,
apdu_len = encode_tagged_enumerated(&apdu[0], UNITS_PERCENT);
break;
case 9997:
apdu_len = encode_tagged_real(&apdu[0], (float)90.510);
apdu_len = encode_tagged_real(&apdu[0], (float) 90.510);
break;
case 9998:
apdu_len = encode_tagged_unsigned(&apdu[0], 90);
+6 -9
View File
@@ -161,7 +161,7 @@ int Analog_Output_Encode_Property_APDU(uint8_t * apdu,
int apdu_len = 0; /* return value */
BACNET_BIT_STRING bit_string;
BACNET_CHARACTER_STRING char_string;
float real_value = (float)1.414;
float real_value = (float) 1.414;
unsigned object_index = 0;
unsigned i = 0;
bool state = false;
@@ -237,12 +237,12 @@ int Analog_Output_Encode_Property_APDU(uint8_t * apdu,
object_index =
Analog_Output_Instance_To_Index(object_instance);
if (array_index <= BACNET_MAX_PRIORITY) {
if (Analog_Output_Level[object_index][array_index-1] ==
if (Analog_Output_Level[object_index][array_index - 1] ==
AO_LEVEL_NULL)
apdu_len = encode_tagged_null(&apdu[0]);
else {
real_value =
Analog_Output_Level[object_index][array_index-1];
Analog_Output_Level[object_index][array_index - 1];
apdu_len = encode_tagged_real(&apdu[0], real_value);
}
} else {
@@ -285,10 +285,8 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data,
wp_data->application_data_len,
&value);
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
@@ -300,8 +298,7 @@ bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
object. */
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
(priority != 6 /* reserved */ ) &&
(value.type.Real >= 0.0) &&
(value.type.Real <= 100.0)) {
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
level = (uint8_t) value.type.Real;
object_index =
Analog_Output_Instance_To_Index(wp_data->
+12 -16
View File
@@ -31,7 +31,7 @@
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
#include "bacapp.h"
#include "bacapp.h"
#include "config.h" /* the custom stuff */
#include "wp.h"
@@ -160,7 +160,7 @@ int Analog_Value_Encode_Property_APDU(uint8_t * apdu,
int apdu_len = 0; /* return value */
BACNET_BIT_STRING bit_string;
BACNET_CHARACTER_STRING char_string;
float real_value = (float)1.414;
float real_value = (float) 1.414;
unsigned object_index = 0;
unsigned i = 0;
bool state = false;
@@ -234,12 +234,12 @@ int Analog_Value_Encode_Property_APDU(uint8_t * apdu,
} else {
object_index = Analog_Value_Instance_To_Index(object_instance);
if (array_index <= BACNET_MAX_PRIORITY) {
if (Analog_Value_Level[object_index][array_index-1] ==
if (Analog_Value_Level[object_index][array_index - 1] ==
ANALOG_LEVEL_NULL)
apdu_len = encode_tagged_null(&apdu[0]);
else {
real_value =
Analog_Value_Level[object_index][array_index-1];
Analog_Value_Level[object_index][array_index - 1];
apdu_len = encode_tagged_real(&apdu[0], real_value);
}
} else {
@@ -272,8 +272,8 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
unsigned int object_index = 0;
unsigned int priority = 0;
uint8_t level = ANALOG_LEVEL_NULL;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
Analog_Value_Init();
if (!Analog_Value_Valid_Instance(wp_data->object_instance)) {
@@ -282,12 +282,10 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data,
wp_data->application_data_len,
&value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_PRESENT_VALUE:
if (value.tag == BACNET_APPLICATION_TAG_REAL) {
@@ -297,8 +295,7 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
object. */
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
(priority != 6 /* reserved */ ) &&
(value.type.Real >= 0.0) &&
(value.type.Real <= 100.0)) {
(value.type.Real >= 0.0) && (value.type.Real <= 100.0)) {
level = (uint8_t) value.type.Real;
object_index =
Analog_Value_Instance_To_Index(wp_data->
@@ -349,8 +346,7 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
object_index =
Analog_Value_Instance_To_Index(wp_data->object_instance);
Analog_Value_Out_Of_Service[object_index] =
value.type.Boolean;
Analog_Value_Out_Of_Service[object_index] = value.type.Boolean;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
+2 -4
View File
@@ -232,10 +232,8 @@ bool bacfile_write_property(BACNET_WRITE_PROPERTY_DATA * wp_data,
}
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data,
wp_data->application_data_len,
&value);
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
+7 -9
View File
@@ -30,7 +30,7 @@
#include <stdio.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
#include "bacenum.h"
#include "bacapp.h"
#include "config.h" /* the custom stuff */
#include "wp.h"
@@ -273,8 +273,8 @@ bool Binary_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
unsigned int object_index = 0;
unsigned int priority = 0;
BACNET_BINARY_PV level = BINARY_NULL;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
Binary_Output_Init();
if (!Binary_Output_Valid_Instance(wp_data->object_instance)) {
@@ -283,12 +283,10 @@ bool Binary_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data,
wp_data->application_data_len,
&value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_PRESENT_VALUE:
if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
+8 -11
View File
@@ -30,7 +30,7 @@
#include <stdio.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
#include "bacenum.h"
#include "bacapp.h"
#include "config.h" /* the custom stuff */
#include "wp.h"
@@ -270,8 +270,8 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
unsigned int object_index = 0;
unsigned int priority = 0;
BACNET_BINARY_PV level = BINARY_NULL;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
Binary_Value_Init();
if (!Binary_Value_Valid_Instance(wp_data->object_instance)) {
@@ -280,12 +280,10 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data,
wp_data->application_data_len,
&value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_PRESENT_VALUE:
if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
@@ -347,8 +345,7 @@ bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
object_index =
Binary_Value_Instance_To_Index(wp_data->object_instance);
Binary_Value_Out_Of_Service[object_index] =
value.type.Boolean;
Binary_Value_Out_Of_Service[object_index] = value.type.Boolean;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
+9 -13
View File
@@ -796,18 +796,16 @@ bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data,
wp_data->application_data_len,
&value);
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(
value.type.Object_Id.instance))) {
(Device_Set_Object_Instance_Number(value.type.Object_Id.
instance))) {
/* FIXME: we could send an I-Am broadcast to let the world know */
status = true;
} else {
@@ -835,8 +833,7 @@ bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
case PROP_APDU_TIMEOUT:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
/* FIXME: bounds check? */
Device_Set_APDU_Timeout((uint16_t) value.type.
Unsigned_Int);
Device_Set_APDU_Timeout((uint16_t) value.type.Unsigned_Int);
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
@@ -870,13 +867,12 @@ bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
uint8_t encoding;
encoding =
characterstring_encoding(&value.type.
Character_String);
characterstring_encoding(&value.type.Character_String);
if (encoding == CHARACTER_ANSI_X34) {
status =
Device_Set_Object_Name(
characterstring_value(&value.type.Character_String),
characterstring_length(&value.type.Character_String));
Device_Set_Object_Name(characterstring_value(&value.
type.Character_String),
characterstring_length(&value.type.Character_String));
if (!status) {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
+312 -328
View File
@@ -28,86 +28,86 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h> /* for memcpy */
#include <string.h> /* for memcpy */
#include <time.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "datetime.h"
#include "bacenum.h"
#include "config.h" /* the custom stuff */
#include "config.h" /* the custom stuff */
#include "lc.h"
#include "wp.h"
/* number of objects */
#define MAX_LOAD_CONTROLS 6
/* indicates the current load shedding state of the object */
static BACNET_SHED_STATE Present_Value[MAX_LOAD_CONTROLS];
typedef enum BACnetShedLevelType {
BACNET_SHED_TYPE_PERCENT, /* Unsigned */
BACNET_SHED_TYPE_LEVEL, /* Unsigned */
BACNET_SHED_TYPE_AMOUNT /* REAL */
} BACNET_SHED_LEVEL_TYPE;
/* The shed levels for the LEVEL choice of BACnetShedLevel
that have meaning for this particular Load Control object. */
#define MAX_SHED_LEVELS 3
typedef struct {
BACNET_SHED_LEVEL_TYPE type;
union {
unsigned level;
unsigned percent;
float amount;
} value;
} BACNET_SHED_LEVEL;
/* indicates the desired load shedding */
static BACNET_SHED_LEVEL Requested_Shed_Level[MAX_LOAD_CONTROLS];
/* Indicates the amount of power that the object expects
to be able to shed in response to a load shed request. */
static BACNET_SHED_LEVEL Expected_Shed_Level[MAX_LOAD_CONTROLS];
/* Indicates the actual amount of power being shed in response
to a load shed request. */
static BACNET_SHED_LEVEL Actual_Shed_Level[MAX_LOAD_CONTROLS];
/* indicates the start of the duty window in which the load controlled
by the Load Control object must be compliant with the requested shed. */
static BACNET_DATE_TIME Start_Time[MAX_LOAD_CONTROLS];
static BACNET_DATE_TIME End_Time[MAX_LOAD_CONTROLS];
static BACNET_DATE_TIME Previous_Start_Time[MAX_LOAD_CONTROLS];
static BACNET_DATE_TIME Current_Time;
/* indicates the duration of the load shed action,
starting at Start_Time in minutes */
static uint32_t Shed_Duration[MAX_LOAD_CONTROLS];
/* indicates the time window used for load shed accounting in minutes */
static uint32_t Duty_Window[MAX_LOAD_CONTROLS];
/* indicates and controls whether the Load Control object is
currently enabled to respond to load shed requests. */
static bool Load_Control_Enable[MAX_LOAD_CONTROLS];
/* optional: indicates the baseline power consumption value
for the sheddable load controlled by this object,
if a fixed baseline is used.
The units of Full_Duty_Baseline are kilowatts.*/
static float Full_Duty_Baseline[MAX_LOAD_CONTROLS];
/* Represents the shed levels for the LEVEL choice of
BACnetShedLevel that have meaning for this particular
Load Control object. */
static unsigned Shed_Levels[MAX_LOAD_CONTROLS][MAX_SHED_LEVELS];
/* represents a description of the shed levels that the
Load Control object can take on. It is the same for
all the load control objects in this example device. */
static char *Shed_Level_Descriptions[MAX_SHED_LEVELS] = {
"dim lights 10%",
"dim lights 20%",
"dim lights 30%"
};
#define MAX_LOAD_CONTROLS 6
/* indicates the current load shedding state of the object */
static BACNET_SHED_STATE Present_Value[MAX_LOAD_CONTROLS];
typedef enum BACnetShedLevelType {
BACNET_SHED_TYPE_PERCENT, /* Unsigned */
BACNET_SHED_TYPE_LEVEL, /* Unsigned */
BACNET_SHED_TYPE_AMOUNT /* REAL */
} BACNET_SHED_LEVEL_TYPE;
/* The shed levels for the LEVEL choice of BACnetShedLevel
that have meaning for this particular Load Control object. */
#define MAX_SHED_LEVELS 3
typedef struct {
BACNET_SHED_LEVEL_TYPE type;
union {
unsigned level;
unsigned percent;
float amount;
} value;
} BACNET_SHED_LEVEL;
/* indicates the desired load shedding */
static BACNET_SHED_LEVEL Requested_Shed_Level[MAX_LOAD_CONTROLS];
/* Indicates the amount of power that the object expects
to be able to shed in response to a load shed request. */
static BACNET_SHED_LEVEL Expected_Shed_Level[MAX_LOAD_CONTROLS];
/* Indicates the actual amount of power being shed in response
to a load shed request. */
static BACNET_SHED_LEVEL Actual_Shed_Level[MAX_LOAD_CONTROLS];
/* indicates the start of the duty window in which the load controlled
by the Load Control object must be compliant with the requested shed. */
static BACNET_DATE_TIME Start_Time[MAX_LOAD_CONTROLS];
static BACNET_DATE_TIME End_Time[MAX_LOAD_CONTROLS];
static BACNET_DATE_TIME Previous_Start_Time[MAX_LOAD_CONTROLS];
static BACNET_DATE_TIME Current_Time;
/* indicates the duration of the load shed action,
starting at Start_Time in minutes */
static uint32_t Shed_Duration[MAX_LOAD_CONTROLS];
/* indicates the time window used for load shed accounting in minutes */
static uint32_t Duty_Window[MAX_LOAD_CONTROLS];
/* indicates and controls whether the Load Control object is
currently enabled to respond to load shed requests. */
static bool Load_Control_Enable[MAX_LOAD_CONTROLS];
/* optional: indicates the baseline power consumption value
for the sheddable load controlled by this object,
if a fixed baseline is used.
The units of Full_Duty_Baseline are kilowatts.*/
static float Full_Duty_Baseline[MAX_LOAD_CONTROLS];
/* Represents the shed levels for the LEVEL choice of
BACnetShedLevel that have meaning for this particular
Load Control object. */
static unsigned Shed_Levels[MAX_LOAD_CONTROLS][MAX_SHED_LEVELS];
/* represents a description of the shed levels that the
Load Control object can take on. It is the same for
all the load control objects in this example device. */
static char *Shed_Level_Descriptions[MAX_SHED_LEVELS] = {
"dim lights 10%",
"dim lights 20%",
"dim lights 30%"
};
/* we need to have our arrays initialized before answering any calls */
static bool Load_Control_Initialized = false;
@@ -117,26 +117,27 @@ void Load_Control_Init(void)
if (!Load_Control_Initialized) {
Load_Control_Initialized = true;
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
/* FIXME: load saved data? */
Present_Value[i] = BACNET_SHED_INACTIVE;
Requested_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL;
Requested_Shed_Level[i].value.level = 0;
datetime_set_values(&Start_Time[i],0,0,0,0,0,0,0);
datetime_set_values(&Previous_Start_Time[i],0,0,0,0,0,0,0);
Shed_Duration[i] = 0;
Duty_Window[i] = 0;
Load_Control_Enable[i] = true;
Full_Duty_Baseline[i] = 0.0;
for (j = 0; j < MAX_SHED_LEVELS; j++) {
/* FIXME: fake data for lighting application */
/* The array shall be ordered by increasing shed amount. */
Shed_Levels[i][j] = 90 - (j * (30/MAX_SHED_LEVELS));
}
Expected_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL;
Expected_Shed_Level[i].value.level = 0;
Actual_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL;
Actual_Shed_Level[i].value.level = 0;
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
/* FIXME: load saved data? */
Present_Value[i] = BACNET_SHED_INACTIVE;
Requested_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL;
Requested_Shed_Level[i].value.level = 0;
datetime_set_values(&Start_Time[i], 0, 0, 0, 0, 0, 0, 0);
datetime_set_values(&Previous_Start_Time[i], 0, 0, 0, 0, 0, 0,
0);
Shed_Duration[i] = 0;
Duty_Window[i] = 0;
Load_Control_Enable[i] = true;
Full_Duty_Baseline[i] = 0.0;
for (j = 0; j < MAX_SHED_LEVELS; j++) {
/* FIXME: fake data for lighting application */
/* The array shall be ordered by increasing shed amount. */
Shed_Levels[i][j] = 90 - (j * (30 / MAX_SHED_LEVELS));
}
Expected_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL;
Expected_Shed_Level[i].value.level = 0;
Actual_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL;
Actual_Shed_Level[i].value.level = 0;
}
}
@@ -186,7 +187,8 @@ unsigned Load_Control_Instance_To_Index(uint32_t object_instance)
return index;
}
static BACNET_SHED_STATE Load_Control_Present_Value(uint32_t object_instance)
static BACNET_SHED_STATE Load_Control_Present_Value(uint32_t
object_instance)
{
BACNET_SHED_STATE value = BACNET_SHED_INACTIVE;
unsigned index = 0;
@@ -194,7 +196,7 @@ static BACNET_SHED_STATE Load_Control_Present_Value(uint32_t object_instance)
Load_Control_Init();
index = Load_Control_Instance_To_Index(object_instance);
if (index < MAX_LOAD_CONTROLS) {
value = Present_Value[index];
value = Present_Value[index];
}
return value;
@@ -217,63 +219,58 @@ static void Update_Current_Time(BACNET_DATE_TIME * bdatetime)
{
time_t timer;
struct tm *tblock;
/*
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
*/
timer = time(NULL);
tblock = localtime(&timer);
datetime_set_values(
bdatetime,
tblock->tm_year,
tblock->tm_mon,
tblock->tm_mday,
tblock->tm_hour,
tblock->tm_min,
tblock->tm_sec,
0);
}
typedef enum load_control_state
{
SHED_INACTIVE,
SHED_REQUEST_PENDING,
SHED_NON_COMPLIANT,
SHED_COMPLIANT
/*
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
*/
timer = time(NULL);
tblock = localtime(&timer);
datetime_set_values(bdatetime,
tblock->tm_year,
tblock->tm_mon,
tblock->tm_mday,
tblock->tm_hour, tblock->tm_min, tblock->tm_sec, 0);
}
typedef enum load_control_state {
SHED_INACTIVE,
SHED_REQUEST_PENDING,
SHED_NON_COMPLIANT,
SHED_COMPLIANT
} LOAD_CONTROL_STATE;
void Load_Control_State_Machine(int object_index)
{
static LOAD_CONTROL_STATE state[MAX_LOAD_CONTROLS];
static bool initialized = false;
unsigned i = 0; /* loop counter */
int diff = 0; /* used for datetime comparison */
unsigned i = 0; /* loop counter */
int diff = 0; /* used for datetime comparison */
if (!initialized) {
initialized = true;
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
state[i] = SHED_INACTIVE;
}
initialized = true;
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
state[i] = SHED_INACTIVE;
}
}
switch (state[object_index])
{
case SHED_REQUEST_PENDING:
switch (state[object_index]) {
case SHED_REQUEST_PENDING:
Update_Current_Time(&Current_Time);
datetime_copy(&End_Time[object_index],&Start_Time[object_index]);
datetime_add_minutes(&End_Time[object_index], Shed_Duration[object_index]);
diff = datetime_compare(&End_Time[object_index],&Current_Time);
datetime_copy(&End_Time[object_index], &Start_Time[object_index]);
datetime_add_minutes(&End_Time[object_index],
Shed_Duration[object_index]);
diff = datetime_compare(&End_Time[object_index], &Current_Time);
if (diff < 0) {
/* CancelShed */
/* FIXME: stop shedding! i.e. relinquish */
@@ -286,12 +283,12 @@ void Load_Control_State_Machine(int object_index)
}
break;
case SHED_NON_COMPLIANT:
case SHED_NON_COMPLIANT:
break;
case SHED_COMPLIANT:
case SHED_COMPLIANT:
break;
case SHED_INACTIVE:
default:
case SHED_INACTIVE:
default:
diff = datetime_compare(&Previous_Start_Time[object_index],
&Start_Time[object_index]);
if (diff != 0) {
@@ -301,25 +298,24 @@ void Load_Control_State_Machine(int object_index)
/* FIXME: calculate your Actual Shed Level */
Expected_Shed_Level[object_index].type =
Requested_Shed_Level[object_index].type;
switch (Requested_Shed_Level[object_index].type)
{
case BACNET_SHED_TYPE_PERCENT:
Actual_Shed_Level[object_index].value.percent =
Expected_Shed_Level[object_index].value.percent =
Requested_Shed_Level[object_index].value.percent;
break;
case BACNET_SHED_TYPE_AMOUNT:
Actual_Shed_Level[object_index].value.amount =
Expected_Shed_Level[object_index].value.amount =
Requested_Shed_Level[object_index].value.amount;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
Actual_Shed_Level[object_index].value.level =
Expected_Shed_Level[object_index].value.level =
Requested_Shed_Level[object_index].value.level;
break;
}
switch (Requested_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT:
Actual_Shed_Level[object_index].value.percent =
Expected_Shed_Level[object_index].value.percent =
Requested_Shed_Level[object_index].value.percent;
break;
case BACNET_SHED_TYPE_AMOUNT:
Actual_Shed_Level[object_index].value.amount =
Expected_Shed_Level[object_index].value.amount =
Requested_Shed_Level[object_index].value.amount;
break;
case BACNET_SHED_TYPE_LEVEL:
default:
Actual_Shed_Level[object_index].value.level =
Expected_Shed_Level[object_index].value.level =
Requested_Shed_Level[object_index].value.level;
break;
}
state[object_index] = SHED_REQUEST_PENDING;
}
break;
@@ -332,7 +328,7 @@ void Load_Control_State_Machine(int object_index)
void Load_Control_State_Machine_Handler(void)
{
unsigned i = 0;
for (i = 0; i < MAX_LOAD_CONTROLS; i++) {
Load_Control_State_Machine(i);
}
@@ -365,33 +361,33 @@ int Load_Control_Encode_Property_APDU(uint8_t * apdu,
characterstring_init_ansi(&char_string,
Load_Control_Name(object_instance));
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
break;
break;
case PROP_OBJECT_TYPE:
apdu_len = encode_tagged_enumerated(&apdu[0], OBJECT_LOAD_CONTROL);
break;
/* optional property
case PROP_DESCRIPTION:
characterstring_init_ansi(&char_string,"optional description");
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
break;
*/
/* optional property
case PROP_DESCRIPTION:
characterstring_init_ansi(&char_string,"optional description");
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
break;
*/
case PROP_PRESENT_VALUE:
enumeration = Load_Control_Present_Value(object_instance);
apdu_len = encode_tagged_enumerated(&apdu[0], enumeration);
break;
case PROP_STATUS_FLAGS:
bitstring_init(&bit_string);
/* IN_ALARM - Logical FALSE (0) if the Event_State property
bitstring_init(&bit_string);
/* IN_ALARM - Logical FALSE (0) if the Event_State property
has a value of NORMAL, otherwise logical TRUE (1). */
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false);
/* FAULT - Logical TRUE (1) if the Reliability property is
present and does not have a value of NO_FAULT_DETECTED,
bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false);
/* FAULT - Logical TRUE (1) if the Reliability property is
present and does not have a value of NO_FAULT_DETECTED,
otherwise logical FALSE (0). */
bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false);
/* OVERRIDDEN - Logical TRUE (1) if the point has been
overridden by some mechanism local to the BACnet Device,
otherwise logical FALSE (0).*/
bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false);
bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false);
/* OVERRIDDEN - Logical TRUE (1) if the point has been
overridden by some mechanism local to the BACnet Device,
otherwise logical FALSE (0). */
bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false);
/* OUT_OF_SERVICE - This bit shall always be Logical FALSE (0). */
bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, false);
apdu_len = encode_tagged_bitstring(&apdu[0], &bit_string);
@@ -400,95 +396,92 @@ int Load_Control_Encode_Property_APDU(uint8_t * apdu,
apdu_len = encode_tagged_enumerated(&apdu[0], EVENT_STATE_NORMAL);
break;
case PROP_REQUESTED_SHED_LEVEL:
switch (Requested_Shed_Level[object_index].type)
{
case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0,
Requested_Shed_Level[object_index].value.percent);
break;
case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2,
Requested_Shed_Level[object_index].value.amount);
break;
case BACNET_SHED_TYPE_LEVEL:
default:
apdu_len = encode_context_unsigned(&apdu[0], 1,
Requested_Shed_Level[object_index].value.level);
break;
}
break;
case PROP_START_TIME:
len = encode_tagged_date(&apdu[0],
&Start_Time[object_index].date);
apdu_len = len;
len = encode_tagged_time(&apdu[apdu_len],
&Start_Time[object_index].time);
apdu_len += len;
break;
case PROP_SHED_DURATION:
apdu_len = encode_tagged_unsigned(&apdu[0],
switch (Requested_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0,
Requested_Shed_Level[object_index].value.percent);
break;
case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2,
Requested_Shed_Level[object_index].value.amount);
break;
case BACNET_SHED_TYPE_LEVEL:
default:
apdu_len = encode_context_unsigned(&apdu[0], 1,
Requested_Shed_Level[object_index].value.level);
break;
}
break;
case PROP_START_TIME:
len = encode_tagged_date(&apdu[0], &Start_Time[object_index].date);
apdu_len = len;
len = encode_tagged_time(&apdu[apdu_len],
&Start_Time[object_index].time);
apdu_len += len;
break;
case PROP_SHED_DURATION:
apdu_len = encode_tagged_unsigned(&apdu[0],
Shed_Duration[object_index]);
break;
case PROP_DUTY_WINDOW:
apdu_len = encode_tagged_unsigned(&apdu[0],
break;
case PROP_DUTY_WINDOW:
apdu_len = encode_tagged_unsigned(&apdu[0],
Duty_Window[object_index]);
break;
case PROP_ENABLE:
break;
case PROP_ENABLE:
state = Load_Control_Enable[object_index];
apdu_len = encode_tagged_boolean(&apdu[0], state);
break;
case PROP_FULL_DUTY_BASELINE: /* optional */
break;
case PROP_FULL_DUTY_BASELINE: /* optional */
apdu_len = encode_tagged_real(&apdu[0],
Full_Duty_Baseline[object_index]);
break;
case PROP_EXPECTED_SHED_LEVEL:
switch (Expected_Shed_Level[object_index].type)
{
case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0,
Expected_Shed_Level[object_index].value.percent);
break;
case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2,
Expected_Shed_Level[object_index].value.amount);
break;
case BACNET_SHED_TYPE_LEVEL:
default:
apdu_len = encode_context_unsigned(&apdu[0], 1,
Expected_Shed_Level[object_index].value.level);
break;
}
break;
case PROP_ACTUAL_SHED_LEVEL:
switch (Actual_Shed_Level[object_index].type)
{
case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0,
Actual_Shed_Level[object_index].value.percent);
break;
case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2,
Actual_Shed_Level[object_index].value.amount);
break;
case BACNET_SHED_TYPE_LEVEL:
default:
apdu_len = encode_context_unsigned(&apdu[0], 1,
Actual_Shed_Level[object_index].value.level);
break;
}
break;
break;
case PROP_EXPECTED_SHED_LEVEL:
switch (Expected_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0,
Expected_Shed_Level[object_index].value.percent);
break;
case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2,
Expected_Shed_Level[object_index].value.amount);
break;
case BACNET_SHED_TYPE_LEVEL:
default:
apdu_len = encode_context_unsigned(&apdu[0], 1,
Expected_Shed_Level[object_index].value.level);
break;
}
break;
case PROP_ACTUAL_SHED_LEVEL:
switch (Actual_Shed_Level[object_index].type) {
case BACNET_SHED_TYPE_PERCENT:
apdu_len = encode_context_unsigned(&apdu[0], 0,
Actual_Shed_Level[object_index].value.percent);
break;
case BACNET_SHED_TYPE_AMOUNT:
apdu_len = encode_context_real(&apdu[0], 2,
Actual_Shed_Level[object_index].value.amount);
break;
case BACNET_SHED_TYPE_LEVEL:
default:
apdu_len = encode_context_unsigned(&apdu[0], 1,
Actual_Shed_Level[object_index].value.level);
break;
}
break;
case PROP_SHED_LEVELS:
/* 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], MAX_SHED_LEVELS);
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. */
else if (array_index == BACNET_ARRAY_ALL) {
apdu_len = 0;
for (i = 0; i < MAX_SHED_LEVELS; i++) {
/* FIXME: check if we have room before adding it to APDU */
len = encode_tagged_unsigned(&apdu[apdu_len], Shed_Levels[object_index][i]);
len =
encode_tagged_unsigned(&apdu[apdu_len],
Shed_Levels[object_index][i]);
/* add it if we have room */
if ((apdu_len + len) < MAX_APDU)
apdu_len += len;
@@ -501,20 +494,19 @@ int Load_Control_Encode_Property_APDU(uint8_t * apdu,
}
} else {
if (array_index <= MAX_SHED_LEVELS) {
apdu_len = encode_tagged_unsigned(&apdu[0],
Shed_Levels[object_index][array_index-1]);
apdu_len = encode_tagged_unsigned(&apdu[0],
Shed_Levels[object_index][array_index - 1]);
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
apdu_len = -1;
}
}
break;
break;
case PROP_SHED_LEVEL_DESCRIPTIONS:
/* 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], MAX_SHED_LEVELS);
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. */
else if (array_index == BACNET_ARRAY_ALL) {
@@ -523,7 +515,7 @@ int Load_Control_Encode_Property_APDU(uint8_t * apdu,
/* FIXME: check if we have room before adding it to APDU */
characterstring_init_ansi(&char_string,
Shed_Level_Descriptions[i]);
len = encode_tagged_character_string(&apdu[apdu_len],
len = encode_tagged_character_string(&apdu[apdu_len],
&char_string);
/* add it if we have room */
if ((apdu_len + len) < MAX_APDU)
@@ -538,8 +530,8 @@ int Load_Control_Encode_Property_APDU(uint8_t * apdu,
} else {
if (array_index <= MAX_SHED_LEVELS) {
characterstring_init_ansi(&char_string,
Shed_Level_Descriptions[array_index-1]);
apdu_len = encode_tagged_character_string(&apdu[0],
Shed_Level_Descriptions[array_index - 1]);
apdu_len = encode_tagged_character_string(&apdu[0],
&char_string);
} else {
*error_class = ERROR_CLASS_PROPERTY;
@@ -547,7 +539,7 @@ int Load_Control_Encode_Property_APDU(uint8_t * apdu,
apdu_len = -1;
}
}
break;
break;
default:
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_UNKNOWN_PROPERTY;
@@ -565,7 +557,7 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
bool status = false; /* return value */
unsigned int object_index = 0;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
BACNET_APPLICATION_DATA_VALUE value;
Load_Control_Init();
if (!Load_Control_Valid_Instance(wp_data->object_instance)) {
@@ -574,111 +566,103 @@ bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data,
wp_data->application_data_len,
&value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
object_index = Load_Control_Instance_To_Index(wp_data->object_instance);
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
object_index =
Load_Control_Instance_To_Index(wp_data->object_instance);
switch (wp_data->object_property) {
case PROP_REQUESTED_SHED_LEVEL:
len = bacapp_decode_context_data(
wp_data->application_data,
wp_data->application_data_len,
&value, PROP_REQUESTED_SHED_LEVEL);
if (value.tag == 0) {
/* percent - Unsigned */
case PROP_REQUESTED_SHED_LEVEL:
len = bacapp_decode_context_data(wp_data->application_data,
wp_data->application_data_len,
&value, PROP_REQUESTED_SHED_LEVEL);
if (value.tag == 0) {
/* percent - Unsigned */
Requested_Shed_Level[object_index].value.percent =
value.type.Unsigned_Int;
value.type.Unsigned_Int;
status = true;
} else if (value.tag == 1) {
/* level - Unsigned */
} else if (value.tag == 1) {
/* level - Unsigned */
Requested_Shed_Level[object_index].value.level =
value.type.Unsigned_Int;
value.type.Unsigned_Int;
status = true;
} else if (value.tag == 2) {
/* amount - REAL */
} else if (value.tag == 2) {
/* amount - REAL */
Requested_Shed_Level[object_index].value.amount =
value.type.Real;
value.type.Real;
status = true;
} else {
/* error! */
} else {
/* error! */
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
break;
case PROP_START_TIME:
if (value.tag == BACNET_APPLICATION_TAG_DATE) {
memcpy(&Start_Time[object_index].date,
&value.type.Date,sizeof(value.type.Date));
case PROP_START_TIME:
if (value.tag == BACNET_APPLICATION_TAG_DATE) {
memcpy(&Start_Time[object_index].date,
&value.type.Date, sizeof(value.type.Date));
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
if (!status)
break;
len = bacapp_decode_application_data(
wp_data->application_data + len,
wp_data->application_data_len - len,
&value);
if (len && value.tag == BACNET_APPLICATION_TAG_TIME) {
memcpy(&Start_Time[object_index].time,
&value.type.Time,sizeof(value.type.Time));
}
if (!status)
break;
len =
bacapp_decode_application_data(wp_data->application_data + len,
wp_data->application_data_len - len, &value);
if (len && value.tag == BACNET_APPLICATION_TAG_TIME) {
memcpy(&Start_Time[object_index].time,
&value.type.Time, sizeof(value.type.Time));
status = true;
} else {
status = false;
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
}
break;
case PROP_SHED_DURATION:
case PROP_SHED_DURATION:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
Shed_Duration[object_index] =
value.type.Unsigned_Int;
Shed_Duration[object_index] = value.type.Unsigned_Int;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
}
break;
case PROP_DUTY_WINDOW:
case PROP_DUTY_WINDOW:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
Duty_Window[object_index] =
value.type.Unsigned_Int;
Duty_Window[object_index] = value.type.Unsigned_Int;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
}
break;
case PROP_SHED_LEVELS:
case PROP_SHED_LEVELS:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
/* re-write the size of the array? */
if (wp_data->array_index == 0) {
/* re-write the size of the array? */
if (wp_data->array_index == 0) {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
else if (wp_data->array_index == BACNET_ARRAY_ALL) {
/* FIXME: write entire array */
status = true;
}
else if (wp_data->array_index <= MAX_SHED_LEVELS) {
Shed_Levels[object_index][wp_data->array_index-1] =
} else if (wp_data->array_index == BACNET_ARRAY_ALL) {
/* FIXME: write entire array */
status = true;
} else if (wp_data->array_index <= MAX_SHED_LEVELS) {
Shed_Levels[object_index][wp_data->array_index - 1] =
value.type.Unsigned_Int;
status = true;
} else {
}
status = true;
} else {
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
break;
case PROP_ENABLE:
}
break;
case PROP_ENABLE:
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
Load_Control_Enable[object_index] =
value.type.Boolean;
Load_Control_Enable[object_index] = value.type.Boolean;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
+7 -9
View File
@@ -30,7 +30,7 @@
#include <stdio.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
#include "bacenum.h"
#include "bacapp.h"
#include "config.h" /* the custom stuff */
#include "wp.h"
@@ -244,8 +244,8 @@ bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
{
bool status = false; /* return value */
unsigned int object_index = 0;
int len = 0;
unsigned int object_index = 0;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
Life_Safety_Point_Init();
@@ -254,12 +254,10 @@ bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data,
wp_data->application_data_len,
&value);
/* FIXME: len < application_data_len: more data? */
/* decode the some of the request */
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_MODE:
+17 -18
View File
@@ -30,7 +30,7 @@
#include <stdio.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
#include "bacenum.h"
#include "bacapp.h"
#include "config.h" /* the custom stuff */
#include "wp.h"
@@ -237,15 +237,15 @@ int Multistate_Output_Encode_Property_APDU(uint8_t * apdu,
object_index =
Multistate_Output_Instance_To_Index(object_instance);
if (array_index <= BACNET_MAX_PRIORITY) {
if (Multistate_Output_Level[object_index][array_index-1] ==
MULTISTATE_NULL)
if (Multistate_Output_Level[object_index][array_index -
1] == MULTISTATE_NULL)
apdu_len = encode_tagged_null(&apdu[0]);
else {
present_value =
Multistate_Output_Level[object_index][array_index-1];
Multistate_Output_Level[object_index][array_index -
1];
apdu_len =
encode_tagged_unsigned(&apdu[0],
present_value);
encode_tagged_unsigned(&apdu[0], present_value);
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
@@ -282,8 +282,8 @@ bool Multistate_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
unsigned int object_index = 0;
unsigned int priority = 0;
uint32_t level = 0;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
Multistate_Output_Init();
if (!Multistate_Output_Valid_Instance(wp_data->object_instance)) {
@@ -292,12 +292,10 @@ bool Multistate_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
return false;
}
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data,
wp_data->application_data_len,
&value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
len = bacapp_decode_application_data(wp_data->application_data,
wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_PRESENT_VALUE:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
@@ -307,14 +305,14 @@ bool Multistate_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
object. */
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
(priority != 6 /* reserved */ ) &&
(value.type.Unsigned_Int <=
MULTISTATE_NUMBER_OF_STATES)) {
(value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) {
level = value.type.Unsigned_Int;
object_index =
Multistate_Output_Instance_To_Index(wp_data->
object_instance);
priority--;
Multistate_Output_Level[object_index][priority] = (uint8_t)level;
Multistate_Output_Level[object_index][priority] =
(uint8_t) level;
/* Note: you could set the physical output here if we
are the highest priority.
However, if Out of Service is TRUE, then don't set the
@@ -339,7 +337,8 @@ bool Multistate_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
Multistate_Output_Level[object_index][priority] = (uint8_t)level;
Multistate_Output_Level[object_index][priority] =
(uint8_t) level;
/* Note: you could set the physical output here to the next
highest priority, or to the relinquish default if no
priorities are set.
+67 -66
View File
@@ -162,72 +162,73 @@ int main(int argc, char *argv[])
printf("Usage: %s device-instance object-type object-instance "
"property tag value [priority] [index]\r\n",
filename_remove_path(argv[0]));
if ((argc > 1) && (strcmp(argv[1],"--help") == 0)) {
printf("device-instance:\r\n"
"BACnet Device Object Instance number that you are trying to\r\n"
"communicate to. This number will be used to try and bind with\r\n"
"the device using Who-Is and I-Am services. For example, if you were\r\n"
"writing to Device Object 123, the device-instance would be 123.\r\n"
"\r\n"
"object-type:\r\n"
"The object type is the integer value of the enumeration\r\n"
"BACNET_OBJECT_TYPE in bacenum.h. It is the object that you are\r\n"
"writing to. For example if you were writing to Analog Output 2, \r\n"
"the object-type would be 1.\r\n"
"\r\n"
"object-instance:\r\n"
"This is the object instance number of the object that you are \r\n"
"writing to. For example, if you were writing to Analog Output 2, \r\n"
"the object-instance would be 2.\r\n"
"\r\n"
"property:\r\n"
"The property is an integer value of the enumeration \r\n"
"BACNET_PROPERTY_ID in bacenum.h. It is the property you are \r\n"
"writing to. For example, if you were writing to the Present Value\r\n"
"property, you would use 85 as the property.\r\n"
"\r\n"
"tag:\r\n"
"Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \r\n"
"in bacenum.h. It is the data type of the value that you are\r\n"
"writing. For example, if you were writing a REAL value, you would \r\n"
"use a tag of 4."
"\r\n"
"value:\r\n"
"The value is an ASCII representation of some type of data that you\r\n"
"are writing. It is encoded using the tag information provided. For\r\n"
"example, if you were writing a REAL value of 100.0, you would use \r\n"
"100.0 as the value.\r\n"
"\r\n"
"[priority]:\r\n"
"This optional parameter is used for setting the priority of the\r\n"
"write. If no priority is given, none is sent, and the BACnet \r\n"
"standard requires that the value is written at the lowest \r\n"
"priority (16) if the object property supports priorities.\r\n"
"\r\n"
"[index]\r\n"
"This optional integer parameter is the index number of an array.\r\n"
"If the property is an array, individual elements can be written\r\n"
"to if supported.\r\n"
"\r\n"
"Here is a brief overview of BACnet property and tags:\r\n"
"Certain properties are expected to be written with certain \r\n"
"application tags, so you probably need to know which ones to use\r\n"
"with each property of each object. It is almost safe to say that\r\n"
"given a property and an object and a table, the tag could be looked\r\n"
"up automatically. There may be a few exceptions to this, such as\r\n"
"the Any property type in the schedule object and the Present Value\r\n"
"accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\r\n"
"the demo to use this kind of table - but I also wanted to be able\r\n"
"to do negative testing by passing the wrong tag and have the server\r\n"
"return a reject message.\r\n"
"\r\n"
"Example:\r\n"
"If you want send a 100 to the Present-Value in the Analog Output\r\n"
"at priority 16, you could send the following command:\r\n"
"%s 123 1 0 85 4 100\r\n"
"You could also send a relinquish command:\r\n"
"%s 123 1 0 85 0 0\r\n",
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
printf("device-instance:\r\n"
"BACnet Device Object Instance number that you are trying to\r\n"
"communicate to. This number will be used to try and bind with\r\n"
"the device using Who-Is and I-Am services. For example, if you were\r\n"
"writing to Device Object 123, the device-instance would be 123.\r\n"
"\r\n"
"object-type:\r\n"
"The object type is the integer value of the enumeration\r\n"
"BACNET_OBJECT_TYPE in bacenum.h. It is the object that you are\r\n"
"writing to. For example if you were writing to Analog Output 2, \r\n"
"the object-type would be 1.\r\n"
"\r\n"
"object-instance:\r\n"
"This is the object instance number of the object that you are \r\n"
"writing to. For example, if you were writing to Analog Output 2, \r\n"
"the object-instance would be 2.\r\n"
"\r\n"
"property:\r\n"
"The property is an integer value of the enumeration \r\n"
"BACNET_PROPERTY_ID in bacenum.h. It is the property you are \r\n"
"writing to. For example, if you were writing to the Present Value\r\n"
"property, you would use 85 as the property.\r\n"
"\r\n"
"tag:\r\n"
"Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \r\n"
"in bacenum.h. It is the data type of the value that you are\r\n"
"writing. For example, if you were writing a REAL value, you would \r\n"
"use a tag of 4."
"\r\n"
"value:\r\n"
"The value is an ASCII representation of some type of data that you\r\n"
"are writing. It is encoded using the tag information provided. For\r\n"
"example, if you were writing a REAL value of 100.0, you would use \r\n"
"100.0 as the value.\r\n"
"\r\n"
"[priority]:\r\n"
"This optional parameter is used for setting the priority of the\r\n"
"write. If no priority is given, none is sent, and the BACnet \r\n"
"standard requires that the value is written at the lowest \r\n"
"priority (16) if the object property supports priorities.\r\n"
"\r\n"
"[index]\r\n"
"This optional integer parameter is the index number of an array.\r\n"
"If the property is an array, individual elements can be written\r\n"
"to if supported.\r\n"
"\r\n"
"Here is a brief overview of BACnet property and tags:\r\n"
"Certain properties are expected to be written with certain \r\n"
"application tags, so you probably need to know which ones to use\r\n"
"with each property of each object. It is almost safe to say that\r\n"
"given a property and an object and a table, the tag could be looked\r\n"
"up automatically. There may be a few exceptions to this, such as\r\n"
"the Any property type in the schedule object and the Present Value\r\n"
"accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\r\n"
"the demo to use this kind of table - but I also wanted to be able\r\n"
"to do negative testing by passing the wrong tag and have the server\r\n"
"return a reject message.\r\n"
"\r\n"
"Example:\r\n"
"If you want send a 100 to the Present-Value in the Analog Output\r\n"
"at priority 16, you could send the following command:\r\n"
"%s 123 1 0 85 4 100\r\n"
"You could also send a relinquish command:\r\n"
"%s 123 1 0 85 0 0\r\n",
filename_remove_path(argv[0]),
filename_remove_path(argv[0]));
}
return 0;
}