Indented using indent script.

This commit is contained in:
skarg
2010-05-04 21:06:26 +00:00
parent b2368acc27
commit 710cfccfef
134 changed files with 2901 additions and 3035 deletions
+6 -9
View File
@@ -160,7 +160,7 @@ char *Analog_Input_Name(
index = Analog_Input_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_INPUTS) {
sprintf(text_string, "ANALOG INPUT %lu", (unsigned long)index);
sprintf(text_string, "ANALOG INPUT %lu", (unsigned long) index);
return text_string;
}
@@ -170,15 +170,14 @@ char *Analog_Input_Name(
/* return apdu length, or -1 on error */
/* assumption - object has already exists */
int Analog_Input_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int apdu_len = 0; /* return value */
BACNET_BIT_STRING bit_string;
BACNET_CHARACTER_STRING char_string;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -242,8 +241,7 @@ int Analog_Input_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = -1;
@@ -276,7 +274,7 @@ void testAnalogInput(
Analog_Input_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ANALOG_INPUT;
rpdata.object_type = OBJECT_ANALOG_INPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -284,8 +282,7 @@ void testAnalogInput(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+25 -26
View File
@@ -259,7 +259,8 @@ char *Analog_Output_Name(
static char text_string[32] = ""; /* okay for single thread */
if (object_instance < MAX_ANALOG_OUTPUTS) {
sprintf(text_string, "ANALOG OUTPUT %lu", (unsigned long)object_instance);
sprintf(text_string, "ANALOG OUTPUT %lu",
(unsigned long) object_instance);
return text_string;
}
@@ -268,7 +269,7 @@ char *Analog_Output_Name(
/* return apdu len, or -1 on error */
int Analog_Output_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int len = 0;
int apdu_len = 0; /* return value */
@@ -280,8 +281,7 @@ int Analog_Output_Read_Property(
bool state = false;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -320,7 +320,8 @@ int Analog_Output_Read_Property(
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
break;
case PROP_OUT_OF_SERVICE:
object_index = Analog_Output_Instance_To_Index(rpdata->object_instance);
object_index =
Analog_Output_Instance_To_Index(rpdata->object_instance);
state = Analog_Output_Out_Of_Service[object_index];
apdu_len = encode_application_boolean(&apdu[0], state);
break;
@@ -361,12 +362,13 @@ int Analog_Output_Read_Property(
object_index =
Analog_Output_Instance_To_Index(rpdata->object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Analog_Output_Level[object_index][rpdata->array_index - 1] ==
AO_LEVEL_NULL)
if (Analog_Output_Level[object_index][rpdata->array_index -
1] == AO_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]);
else {
real_value =
Analog_Output_Level[object_index][rpdata->array_index - 1];
Analog_Output_Level[object_index][rpdata->
array_index - 1];
apdu_len =
encode_application_real(&apdu[0], real_value);
}
@@ -388,8 +390,7 @@ int Analog_Output_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->object_property != PROP_PRIORITY_ARRAY) &&
if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
@@ -435,29 +436,28 @@ bool Analog_Output_Write_Property(
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class, &wp_data->error_code);
if (status) {
level = AO_LEVEL_NULL;
object_index =
Analog_Output_Instance_To_Index(wp_data->object_instance);
Analog_Output_Instance_To_Index(wp_data->
object_instance);
status =
Analog_Output_Present_Value_Relinquish
(wp_data->object_instance, wp_data->priority);
Analog_Output_Present_Value_Relinquish(wp_data->
object_instance, wp_data->priority);
if (!status) {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
}
}
}
}
break;
case PROP_OUT_OF_SERVICE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
object_index =
Analog_Output_Instance_To_Index(wp_data->object_instance);
@@ -494,7 +494,7 @@ void testAnalogOutput(
Analog_Output_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ANALOG_OUTPUT;
rpdata.object_type = OBJECT_ANALOG_OUTPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -502,8 +502,7 @@ void testAnalogOutput(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+25 -24
View File
@@ -207,7 +207,8 @@ char *Analog_Value_Name(
static char text_string[32] = ""; /* okay for single thread */
if (object_instance < MAX_ANALOG_VALUES) {
sprintf(text_string, "ANALOG VALUE %lu", (unsigned long)object_instance);
sprintf(text_string, "ANALOG VALUE %lu",
(unsigned long) object_instance);
return text_string;
}
@@ -216,7 +217,7 @@ char *Analog_Value_Name(
/* return apdu len, or -1 on error */
int Analog_Value_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int len = 0;
int apdu_len = 0; /* return value */
@@ -228,8 +229,7 @@ int Analog_Value_Read_Property(
bool state = false;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -268,7 +268,8 @@ int Analog_Value_Read_Property(
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
break;
case PROP_OUT_OF_SERVICE:
object_index = Analog_Value_Instance_To_Index(rpdata->object_instance);
object_index =
Analog_Value_Instance_To_Index(rpdata->object_instance);
state = Analog_Value_Out_Of_Service[object_index];
apdu_len = encode_application_boolean(&apdu[0], state);
break;
@@ -283,7 +284,8 @@ int Analog_Value_Read_Property(
/* if no index was specified, then try to encode the entire list */
/* into one packet. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) {
object_index = Analog_Value_Instance_To_Index(rpdata->object_instance);
object_index =
Analog_Value_Instance_To_Index(rpdata->object_instance);
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
/* FIXME: check if we have room before adding it to APDU */
if (Analog_Value_Level[object_index][i] ==
@@ -306,14 +308,16 @@ int Analog_Value_Read_Property(
}
}
} else {
object_index = Analog_Value_Instance_To_Index(rpdata->object_instance);
object_index =
Analog_Value_Instance_To_Index(rpdata->object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Analog_Value_Level[object_index][rpdata->array_index - 1] ==
ANALOG_LEVEL_NULL)
if (Analog_Value_Level[object_index][rpdata->array_index -
1] == ANALOG_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]);
else {
real_value =
Analog_Value_Level[object_index][rpdata->array_index - 1];
Analog_Value_Level[object_index][rpdata->
array_index - 1];
apdu_len =
encode_application_real(&apdu[0], real_value);
}
@@ -335,8 +339,7 @@ int Analog_Value_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->object_property != PROP_PRIORITY_ARRAY) &&
if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
@@ -383,14 +386,14 @@ bool Analog_Value_Write_Property(
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class, &wp_data->error_code);
if (status) {
level = ANALOG_LEVEL_NULL;
object_index =
Analog_Value_Instance_To_Index(wp_data->object_instance);
Analog_Value_Instance_To_Index(wp_data->
object_instance);
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
@@ -410,10 +413,9 @@ bool Analog_Value_Write_Property(
}
break;
case PROP_OUT_OF_SERVICE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
object_index =
Analog_Value_Instance_To_Index(wp_data->object_instance);
@@ -449,7 +451,7 @@ void testAnalog_Value(
Analog_Value_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_ANALOG_VALUE;
rpdata.object_type = OBJECT_ANALOG_VALUE;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -457,8 +459,7 @@ void testAnalog_Value(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+10 -12
View File
@@ -185,7 +185,7 @@ static unsigned bacfile_file_size(
/* return the number of bytes used, or -1 on error */
int bacfile_read_property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int apdu_len = 0; /* return value */
char text_string[32] = { "" };
@@ -194,8 +194,7 @@ int bacfile_read_property(
BACNET_TIME btime;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -207,7 +206,8 @@ int bacfile_read_property(
rpdata->object_instance);
break;
case PROP_OBJECT_NAME:
sprintf(text_string, "FILE %lu", (unsigned long)rpdata->object_instance);
sprintf(text_string, "FILE %lu",
(unsigned long) rpdata->object_instance);
characterstring_init_ansi(&char_string, text_string);
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
@@ -302,10 +302,9 @@ bool bacfile_write_property(
property shall be logical TRUE only if no changes have been
made to the file data by internal processes or through File
Access Services since the last time the object was archived. */
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
if (value.type.Boolean) {
/* FIXME: do something to wp_data->object_instance */
@@ -318,10 +317,9 @@ bool bacfile_write_property(
/* If the file size can be changed by writing to the file,
and File_Access_Method is STREAM_ACCESS, then this property
shall be writable. */
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
/* FIXME: do something with value.type.Unsigned
to wp_data->object_instance */
+14 -18
View File
@@ -39,7 +39,7 @@
#include "bi.h"
#include "handlers.h"
#ifndef MAX_BINARY_INPUTS
#ifndef MAX_BINARY_INPUTS
#define MAX_BINARY_INPUTS 5
#endif
@@ -287,7 +287,8 @@ char *Binary_Input_Name(
static char text_string[32] = ""; /* okay for single thread */
if (object_instance < MAX_BINARY_INPUTS) {
sprintf(text_string, "BINARY INPUT %lu", (unsigned long)object_instance);
sprintf(text_string, "BINARY INPUT %lu",
(unsigned long) object_instance);
return text_string;
}
@@ -297,7 +298,7 @@ char *Binary_Input_Name(
/* return apdu length, or -1 on error */
/* assumption - object already exists, and has been bounds checked */
int Binary_Input_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int apdu_len = 0; /* return value */
BACNET_BIT_STRING bit_string;
@@ -305,8 +306,7 @@ int Binary_Input_Read_Property(
BACNET_POLARITY polarity = POLARITY_NORMAL;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -370,8 +370,7 @@ int Binary_Input_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = -1;
@@ -396,10 +395,9 @@ bool Binary_Input_Write_Property(
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_PRESENT_VALUE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_ENUMERATED,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED,
&wp_data->error_class, &wp_data->error_code);
if (status) {
if (value.type.Enumerated <= MAX_BINARY_PV) {
Binary_Input_Present_Value_Set(wp_data->object_instance,
@@ -412,10 +410,9 @@ bool Binary_Input_Write_Property(
}
break;
case PROP_OUT_OF_SERVICE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
Binary_Input_Out_Of_Service_Set(wp_data->object_instance,
value.type.Boolean);
@@ -449,7 +446,7 @@ void testBinaryInput(
Binary_Input_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_BINARY_INPUT;
rpdata.object_type = OBJECT_BINARY_INPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -457,8 +454,7 @@ void testBinaryInput(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+25 -25
View File
@@ -183,7 +183,8 @@ char *Binary_Output_Name(
static char text_string[32] = ""; /* okay for single thread */
if (object_instance < MAX_BINARY_OUTPUTS) {
sprintf(text_string, "BINARY OUTPUT %lu", (unsigned long)object_instance);
sprintf(text_string, "BINARY OUTPUT %lu",
(unsigned long) object_instance);
return text_string;
}
@@ -192,7 +193,7 @@ char *Binary_Output_Name(
/* return apdu len, or -1 on error */
int Binary_Output_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int len = 0;
int apdu_len = 0; /* return value */
@@ -205,8 +206,7 @@ int Binary_Output_Read_Property(
bool state = false;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -231,7 +231,8 @@ int Binary_Output_Read_Property(
encode_application_enumerated(&apdu[0], OBJECT_BINARY_OUTPUT);
break;
case PROP_PRESENT_VALUE:
present_value = Binary_Output_Present_Value(rpdata->object_instance);
present_value =
Binary_Output_Present_Value(rpdata->object_instance);
apdu_len = encode_application_enumerated(&apdu[0], present_value);
break;
case PROP_STATUS_FLAGS:
@@ -249,7 +250,8 @@ int Binary_Output_Read_Property(
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
break;
case PROP_OUT_OF_SERVICE:
object_index = Binary_Output_Instance_To_Index(rpdata->object_instance);
object_index =
Binary_Output_Instance_To_Index(rpdata->object_instance);
state = Binary_Output_Out_Of_Service[object_index];
apdu_len = encode_application_boolean(&apdu[0], state);
break;
@@ -290,12 +292,13 @@ int Binary_Output_Read_Property(
object_index =
Binary_Output_Instance_To_Index(rpdata->object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Binary_Output_Level[object_index][rpdata->array_index - 1] ==
BINARY_NULL)
if (Binary_Output_Level[object_index][rpdata->array_index -
1] == BINARY_NULL)
apdu_len = encode_application_null(&apdu[apdu_len]);
else {
present_value =
Binary_Output_Level[object_index][rpdata->array_index - 1];
Binary_Output_Level[object_index][rpdata->
array_index - 1];
apdu_len =
encode_application_enumerated(&apdu[apdu_len],
present_value);
@@ -329,8 +332,7 @@ int Binary_Output_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->object_property != PROP_PRIORITY_ARRAY) &&
if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
@@ -369,8 +371,8 @@ bool Binary_Output_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) {
level = (BACNET_BINARY_PV) value.type.Enumerated;
object_index =
Binary_Output_Instance_To_Index
(wp_data->object_instance);
Binary_Output_Instance_To_Index(wp_data->
object_instance);
priority--;
Binary_Output_Level[object_index][priority] = level;
/* Note: you could set the physical output here if we
@@ -390,14 +392,14 @@ bool Binary_Output_Write_Property(
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class, &wp_data->error_code);
if (status) {
level = BINARY_NULL;
object_index =
Binary_Output_Instance_To_Index(wp_data->object_instance);
Binary_Output_Instance_To_Index(wp_data->
object_instance);
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
@@ -417,10 +419,9 @@ bool Binary_Output_Write_Property(
}
break;
case PROP_OUT_OF_SERVICE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
object_index =
Binary_Output_Instance_To_Index(wp_data->object_instance);
@@ -457,7 +458,7 @@ void testBinaryOutput(
Binary_Output_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_BINARY_OUTPUT;
rpdata.object_type = OBJECT_BINARY_OUTPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -465,8 +466,7 @@ void testBinaryOutput(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+31 -28
View File
@@ -180,7 +180,8 @@ char *Binary_Value_Name(
static char text_string[32] = ""; /* okay for single thread */
if (object_instance < MAX_BINARY_VALUES) {
sprintf(text_string, "BINARY VALUE %lu", (unsigned long)object_instance);
sprintf(text_string, "BINARY VALUE %lu",
(unsigned long) object_instance);
return text_string;
}
@@ -189,7 +190,7 @@ char *Binary_Value_Name(
/* return apdu len, or -1 on error */
int Binary_Value_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int len = 0;
int apdu_len = 0; /* return value */
@@ -201,8 +202,7 @@ int Binary_Value_Read_Property(
bool state = false;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -227,7 +227,8 @@ int Binary_Value_Read_Property(
encode_application_enumerated(&apdu[0], OBJECT_BINARY_VALUE);
break;
case PROP_PRESENT_VALUE:
present_value = Binary_Value_Present_Value(rpdata->object_instance);
present_value =
Binary_Value_Present_Value(rpdata->object_instance);
apdu_len = encode_application_enumerated(&apdu[0], present_value);
break;
case PROP_STATUS_FLAGS:
@@ -245,7 +246,8 @@ int Binary_Value_Read_Property(
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
break;
case PROP_OUT_OF_SERVICE:
object_index = Binary_Value_Instance_To_Index(rpdata->object_instance);
object_index =
Binary_Value_Instance_To_Index(rpdata->object_instance);
state = Binary_Value_Out_Of_Service[object_index];
apdu_len = encode_application_boolean(&apdu[0], state);
break;
@@ -257,7 +259,8 @@ int Binary_Value_Read_Property(
/* if no index was specified, then try to encode the entire list */
/* into one packet. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) {
object_index = Binary_Value_Instance_To_Index(rpdata->object_instance);
object_index =
Binary_Value_Instance_To_Index(rpdata->object_instance);
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
/* FIXME: check if we have room before adding it to APDU */
if (Binary_Value_Level[object_index][i] == BINARY_NULL)
@@ -279,14 +282,16 @@ int Binary_Value_Read_Property(
}
}
} else {
object_index = Binary_Value_Instance_To_Index(rpdata->object_instance);
object_index =
Binary_Value_Instance_To_Index(rpdata->object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Binary_Value_Level[object_index][rpdata->array_index] ==
BINARY_NULL)
if (Binary_Value_Level[object_index][rpdata->
array_index] == BINARY_NULL)
apdu_len = encode_application_null(&apdu[apdu_len]);
else {
present_value =
Binary_Value_Level[object_index][rpdata->array_index];
Binary_Value_Level[object_index][rpdata->
array_index];
apdu_len =
encode_application_enumerated(&apdu[apdu_len],
present_value);
@@ -310,8 +315,7 @@ int Binary_Value_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->object_property != PROP_PRIORITY_ARRAY) &&
if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
@@ -350,8 +354,8 @@ bool Binary_Value_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) {
level = (BACNET_BINARY_PV) value.type.Enumerated;
object_index =
Binary_Value_Instance_To_Index
(wp_data->object_instance);
Binary_Value_Instance_To_Index(wp_data->
object_instance);
priority--;
Binary_Value_Level[object_index][priority] = level;
/* Note: you could set the physical output here if we
@@ -371,14 +375,14 @@ bool Binary_Value_Write_Property(
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class, &wp_data->error_code);
if (status) {
level = BINARY_NULL;
object_index =
Binary_Value_Instance_To_Index(wp_data->object_instance);
Binary_Value_Instance_To_Index(wp_data->
object_instance);
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
@@ -398,12 +402,12 @@ bool Binary_Value_Write_Property(
}
break;
case PROP_OUT_OF_SERVICE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
object_index = Binary_Value_Instance_To_Index(wp_data->object_instance);
object_index =
Binary_Value_Instance_To_Index(wp_data->object_instance);
Binary_Value_Out_Of_Service[object_index] = value.type.Boolean;
}
break;
@@ -436,7 +440,7 @@ void testBinary_Value(
Binary_Value_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_BINARY_VALUE;
rpdata.object_type = OBJECT_BINARY_VALUE;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -444,8 +448,7 @@ void testBinary_Value(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+234 -329
View File
@@ -29,7 +29,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <string.h> /* for memmove */
#include <time.h> /* for timezone, localtime */
#include <time.h> /* for timezone, localtime */
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
@@ -70,7 +70,7 @@ long int timezone;
/* forward prototypes */
static int Device_Read_Property_Local(
BACNET_READ_PROPERTY_DATA *rpdata);
BACNET_READ_PROPERTY_DATA * rpdata);
static bool Device_Write_Property_Local(
BACNET_WRITE_PROPERTY_DATA * wp_data);
@@ -82,7 +82,7 @@ static bool Device_Write_Property_Local(
* for each Object type.
* In both appearance and operation, this group of functions acts like
* they are member functions of a C++ Object base class.
*/
*/
static struct object_functions {
BACNET_OBJECT_TYPE Object_Type;
object_init_function Object_Init;
@@ -95,154 +95,76 @@ static struct object_functions {
rpm_property_lists_function Object_RPM_List;
rr_info_function Object_RR_Info;
object_iterate_function Object_Iterator;
} Object_Table[] =
{
{OBJECT_DEVICE,
NULL,
Device_Count,
Device_Index_To_Instance,
Device_Valid_Object_Instance_Number,
Device_Name,
Device_Read_Property_Local,
Device_Write_Property_Local,
Device_Property_Lists,
DeviceGetRRInfo,
NULL},
{OBJECT_ANALOG_INPUT,
Analog_Input_Init,
Analog_Input_Count,
Analog_Input_Index_To_Instance,
Analog_Input_Valid_Instance,
Analog_Input_Name,
Analog_Input_Read_Property,
NULL,
Analog_Input_Property_Lists,
NULL,
NULL},
{OBJECT_ANALOG_OUTPUT,
Analog_Output_Init,
Analog_Output_Count,
Analog_Output_Index_To_Instance,
Analog_Output_Valid_Instance,
Analog_Output_Name,
Analog_Output_Read_Property,
Analog_Output_Write_Property,
Analog_Output_Property_Lists,
NULL,
NULL},
{OBJECT_ANALOG_VALUE,
Analog_Value_Init,
Analog_Value_Count,
Analog_Value_Index_To_Instance,
Analog_Value_Valid_Instance,
Analog_Value_Name,
Analog_Value_Read_Property,
Analog_Value_Write_Property,
Analog_Value_Property_Lists,
NULL,
NULL},
{OBJECT_BINARY_INPUT,
Binary_Input_Init,
Binary_Input_Count,
Binary_Input_Index_To_Instance,
Binary_Input_Valid_Instance,
Binary_Input_Name,
Binary_Input_Read_Property,
NULL,
Binary_Input_Property_Lists,
NULL,
NULL},
{OBJECT_BINARY_OUTPUT,
Binary_Output_Init,
Binary_Output_Count,
Binary_Output_Index_To_Instance,
Binary_Output_Valid_Instance,
Binary_Output_Name,
Binary_Output_Read_Property,
Binary_Output_Write_Property,
Binary_Output_Property_Lists,
NULL,
NULL},
{OBJECT_BINARY_VALUE,
Binary_Value_Init,
Binary_Value_Count,
Binary_Value_Index_To_Instance,
Binary_Value_Valid_Instance,
Binary_Value_Name,
Binary_Value_Read_Property,
Binary_Value_Write_Property,
Binary_Value_Property_Lists,
NULL,
NULL},
{OBJECT_LIFE_SAFETY_POINT,
Life_Safety_Point_Init,
Life_Safety_Point_Count,
Life_Safety_Point_Index_To_Instance,
Life_Safety_Point_Valid_Instance,
Life_Safety_Point_Name,
Life_Safety_Point_Read_Property,
Life_Safety_Point_Write_Property,
Life_Safety_Point_Property_Lists,
NULL,
NULL},
{OBJECT_LOAD_CONTROL,
Load_Control_Init,
Load_Control_Count,
Load_Control_Index_To_Instance,
Load_Control_Valid_Instance,
Load_Control_Name,
Load_Control_Read_Property,
Load_Control_Write_Property,
Load_Control_Property_Lists,
NULL,
NULL},
{OBJECT_MULTI_STATE_OUTPUT,
Multistate_Output_Init,
Multistate_Output_Count,
Multistate_Output_Index_To_Instance,
Multistate_Output_Valid_Instance,
Multistate_Output_Name,
Multistate_Output_Read_Property,
Multistate_Output_Write_Property,
Multistate_Output_Property_Lists,
NULL,
NULL},
{OBJECT_MULTI_STATE_INPUT,
Multistate_Input_Init,
Multistate_Input_Count,
Multistate_Input_Index_To_Instance,
Multistate_Input_Valid_Instance,
Multistate_Input_Name,
Multistate_Input_Read_Property,
Multistate_Input_Write_Property,
Multistate_Input_Property_Lists,
NULL,
NULL},
{OBJECT_TRENDLOG,
Trend_Log_Init,
Trend_Log_Count,
Trend_Log_Index_To_Instance,
Trend_Log_Valid_Instance,
Trend_Log_Name,
Trend_Log_Read_Property,
Trend_Log_Write_Property,
Trend_Log_Property_Lists,
TrendLogGetRRInfo,
NULL},
} Object_Table[] = {
{
OBJECT_DEVICE, NULL, Device_Count, Device_Index_To_Instance,
Device_Valid_Object_Instance_Number, Device_Name,
Device_Read_Property_Local, Device_Write_Property_Local,
Device_Property_Lists, DeviceGetRRInfo, NULL}, {
OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count,
Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance,
Analog_Input_Name, Analog_Input_Read_Property, NULL,
Analog_Input_Property_Lists, NULL, NULL}, {
OBJECT_ANALOG_OUTPUT, Analog_Output_Init, Analog_Output_Count,
Analog_Output_Index_To_Instance, Analog_Output_Valid_Instance,
Analog_Output_Name, Analog_Output_Read_Property,
Analog_Output_Write_Property, Analog_Output_Property_Lists,
NULL, NULL}, {
OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count,
Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance,
Analog_Value_Name, Analog_Value_Read_Property,
Analog_Value_Write_Property, Analog_Value_Property_Lists, NULL,
NULL}, {
OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count,
Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance,
Binary_Input_Name, Binary_Input_Read_Property, NULL,
Binary_Input_Property_Lists, NULL, NULL}, {
OBJECT_BINARY_OUTPUT, Binary_Output_Init, Binary_Output_Count,
Binary_Output_Index_To_Instance, Binary_Output_Valid_Instance,
Binary_Output_Name, Binary_Output_Read_Property,
Binary_Output_Write_Property, Binary_Output_Property_Lists,
NULL, NULL}, {
OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count,
Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance,
Binary_Value_Name, Binary_Value_Read_Property,
Binary_Value_Write_Property, Binary_Value_Property_Lists, NULL,
NULL}, {
OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Init,
Life_Safety_Point_Count, Life_Safety_Point_Index_To_Instance,
Life_Safety_Point_Valid_Instance, Life_Safety_Point_Name,
Life_Safety_Point_Read_Property,
Life_Safety_Point_Write_Property,
Life_Safety_Point_Property_Lists, NULL, NULL}, {
OBJECT_LOAD_CONTROL, Load_Control_Init, Load_Control_Count,
Load_Control_Index_To_Instance, Load_Control_Valid_Instance,
Load_Control_Name, Load_Control_Read_Property,
Load_Control_Write_Property, Load_Control_Property_Lists, NULL,
NULL}, {
OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init,
Multistate_Output_Count, Multistate_Output_Index_To_Instance,
Multistate_Output_Valid_Instance, Multistate_Output_Name,
Multistate_Output_Read_Property,
Multistate_Output_Write_Property,
Multistate_Output_Property_Lists, NULL, NULL}, {
OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init,
Multistate_Input_Count, Multistate_Input_Index_To_Instance,
Multistate_Input_Valid_Instance, Multistate_Input_Name,
Multistate_Input_Read_Property,
Multistate_Input_Write_Property,
Multistate_Input_Property_Lists, NULL, NULL}, {
OBJECT_TRENDLOG, Trend_Log_Init, Trend_Log_Count,
Trend_Log_Index_To_Instance, Trend_Log_Valid_Instance,
Trend_Log_Name, Trend_Log_Read_Property,
Trend_Log_Write_Property, Trend_Log_Property_Lists,
TrendLogGetRRInfo, NULL},
#if defined(BACFILE)
{OBJECT_FILE,
bacfile_init,
bacfile_count,
bacfile_index_to_instance,
bacfile_valid_instance,
bacfile_name,
bacfile_read_property,
bacfile_write_property,
BACfile_Property_Lists,
NULL},
{
OBJECT_FILE, bacfile_init, bacfile_count, bacfile_index_to_instance,
bacfile_valid_instance, bacfile_name, bacfile_read_property,
bacfile_write_property, BACfile_Property_Lists, NULL},
#endif
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
{
MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
};
/** Glue function to let the Device object, when called by a handler,
@@ -252,7 +174,7 @@ static struct object_functions {
* @return Pointer to the group of object helper functions that implement this
* type of Object.
*/
static struct object_functions * Device_Objects_Find_Functions(
static struct object_functions *Device_Objects_Find_Functions(
BACNET_OBJECT_TYPE Object_Type)
{
struct object_functions *pObject = NULL;
@@ -261,13 +183,13 @@ static struct object_functions * Device_Objects_Find_Functions(
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
/* handle each object type */
if (pObject->Object_Type == Object_Type) {
return(pObject);
return (pObject);
}
pObject++;
}
return(NULL);
return (NULL);
}
/** Try to find a rr_info_function helper function for the requested object type.
@@ -281,12 +203,11 @@ static struct object_functions * Device_Objects_Find_Functions(
*/
rr_info_function Device_Objects_RR_Info(
BACNET_OBJECT_TYPE object_type)
{
struct object_functions *pObject = NULL;
pObject = Device_Objects_Find_Functions(object_type);
return(pObject != NULL ? pObject->Object_RR_Info : NULL);
return (pObject != NULL ? pObject->Object_RR_Info : NULL);
}
static unsigned property_list_count(
@@ -332,21 +253,22 @@ void Device_Objects_Property_List(
pObject = Device_Objects_Find_Functions(object_type);
if ((pObject != NULL) && (pObject->Object_RPM_List != NULL)) {
pObject->Object_RPM_List(
&pPropertyList->Required.pList,
&pPropertyList->Optional.pList,
&pPropertyList->Proprietary.pList);
pObject->Object_RPM_List(&pPropertyList->Required.pList,
&pPropertyList->Optional.pList, &pPropertyList->Proprietary.pList);
}
/* Fetch the counts if available otherwise zero them */
pPropertyList->Required.count = pPropertyList->Required.pList == NULL
? 0 : property_list_count(pPropertyList->Required.pList);
pPropertyList->Required.count =
pPropertyList->Required.pList ==
NULL ? 0 : property_list_count(pPropertyList->Required.pList);
pPropertyList->Optional.count = pPropertyList->Optional.pList == NULL
? 0 : property_list_count(pPropertyList->Optional.pList);
pPropertyList->Proprietary.count = pPropertyList->Proprietary.pList == NULL
? 0 : property_list_count(pPropertyList->Proprietary.pList);
pPropertyList->Optional.count =
pPropertyList->Optional.pList ==
NULL ? 0 : property_list_count(pPropertyList->Optional.pList);
pPropertyList->Proprietary.count =
pPropertyList->Proprietary.pList ==
NULL ? 0 : property_list_count(pPropertyList->Proprietary.pList);
return;
}
@@ -364,8 +286,8 @@ void Device_Objects_Property_List(
* On failure, the error class and code will be set.
* @return True if succeeds (password is correct), else False.
*/
bool Device_Reinitialize(
BACNET_REINITIALIZE_DEVICE_DATA *rd_data)
bool Device_Reinitialize(
BACNET_REINITIALIZE_DEVICE_DATA * rd_data)
{
bool status = false;
@@ -398,7 +320,7 @@ bool Device_Reinitialize(
rd_data->error_class = ERROR_CLASS_SECURITY;
rd_data->error_code = ERROR_CODE_PASSWORD_FAILURE;
}
return status;
}
@@ -493,8 +415,8 @@ static char Description[MAX_DEV_DESC_LEN + 1] = "server";
/* static uint8_t Max_Segments_Accepted = 0; */
/* VT_Classes_Supported */
/* Active_VT_Sessions */
static BACNET_TIME Local_Time; /* rely on OS, if there is one */
static BACNET_DATE Local_Date; /* rely on OS, if there is one */
static BACNET_TIME Local_Time; /* rely on OS, if there is one */
static BACNET_DATE Local_Date; /* rely on OS, if there is one */
/* NOTE: BACnet UTC Offset is inverse of common practice.
If your UTC offset is -5hours of GMT,
then BACnet UTC offset is +5hours.
@@ -517,7 +439,8 @@ static uint32_t Database_Revision = 0;
/* Slave_Address_Binding */
/* Profile_Name */
unsigned Device_Count(void)
unsigned Device_Count(
void)
{
return 1;
}
@@ -551,8 +474,7 @@ bool Device_Set_Object_Instance_Number(
/* Make the change and update the database revision */
Object_Instance_Number = object_id;
Device_Inc_Database_Revision();
}
else
} else
status = false;
return status;
@@ -572,7 +494,7 @@ char *Device_Name(
if (object_instance == Object_Instance_Number) {
return My_Object_Name;
}
return NULL;
}
@@ -612,12 +534,12 @@ int Device_Set_System_Status(
BACNET_DEVICE_STATUS status,
bool local)
{
int result = 0; /*return value - 0 = ok, -1 = bad value, -2 = not allowed */
int result = 0; /*return value - 0 = ok, -1 = bad value, -2 = not allowed */
/* We limit the options available depending on whether the source is
* internal or external. */
if(local) {
switch(status) {
if (local) {
switch (status) {
case STATUS_OPERATIONAL:
case STATUS_OPERATIONAL_READ_ONLY:
case STATUS_DOWNLOAD_REQUIRED:
@@ -626,7 +548,7 @@ int Device_Set_System_Status(
System_Status = status;
break;
/* Don't support backup at present so don't allow setting */
/* Don't support backup at present so don't allow setting */
case STATUS_BACKUP_IN_PROGRESS:
result = -2;
break;
@@ -636,30 +558,30 @@ int Device_Set_System_Status(
break;
}
} else {
switch(status) {
/* Allow these for the moment as a way to easily alter
* overall device operation. The lack of password protection
* or other authentication makes allowing writes to this
* property a risky facility to provide.
*/
switch (status) {
/* Allow these for the moment as a way to easily alter
* overall device operation. The lack of password protection
* or other authentication makes allowing writes to this
* property a risky facility to provide.
*/
case STATUS_OPERATIONAL:
case STATUS_OPERATIONAL_READ_ONLY:
case STATUS_NON_OPERATIONAL:
System_Status = status;
break;
/* Don't allow outsider set this - it should probably
* be set if the device config is incomplete or
* corrupted or perhaps after some sort of operator
* wipe operation.
*/
/* Don't allow outsider set this - it should probably
* be set if the device config is incomplete or
* corrupted or perhaps after some sort of operator
* wipe operation.
*/
case STATUS_DOWNLOAD_REQUIRED:
/* Don't allow outsider set this - it should be set
* internally at the start of a multi packet download
* perhaps indirectly via PT or WF to a config file.
*/
/* Don't allow outsider set this - it should be set
* internally at the start of a multi packet download
* perhaps indirectly via PT or WF to a config file.
*/
case STATUS_DOWNLOAD_IN_PROGRESS:
/* Don't support backup at present so don't allow setting */
/* Don't support backup at present so don't allow setting */
case STATUS_BACKUP_IN_PROGRESS:
result = -2;
break;
@@ -670,7 +592,7 @@ int Device_Set_System_Status(
}
}
return(result);
return (result);
}
const char *Device_Vendor_Name(
@@ -880,28 +802,29 @@ bool Device_Object_List_Identifier(
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
if (pObject->Object_Count) {
object_index -= count;
count = pObject->Object_Count();
if (object_index < count) {
/* Use the iterator function if available otherwise
count = pObject->Object_Count();
if (object_index < count) {
/* Use the iterator function if available otherwise
* look for the index to instance to get the ID */
if(pObject->Object_Iterator) {
if (pObject->Object_Iterator) {
/* First find the first object */
temp_index = pObject->Object_Iterator(~0);
/* Then step through the objects to find the nth */
while(object_index != 0) {
temp_index = pObject->Object_Iterator(temp_index);
while (object_index != 0) {
temp_index = pObject->Object_Iterator(temp_index);
object_index--;
}
/* set the object_index up before falling through to next bit */
object_index = temp_index;
}
if(pObject->Object_Index_To_Instance) {
*object_type = pObject->Object_Type;
*instance = pObject->Object_Index_To_Instance(object_index);
if (pObject->Object_Index_To_Instance) {
*object_type = pObject->Object_Type;
*instance =
pObject->Object_Index_To_Instance(object_index);
status = true;
break;
}
}
break;
}
}
}
pObject++;
}
@@ -965,18 +888,19 @@ char *Device_Valid_Object_Id(
pObject = Device_Objects_Find_Functions(object_type);
if ((pObject != NULL) && (pObject->Object_Name != NULL))
name = pObject->Object_Name(object_instance);
return name;
}
static void Update_Current_Time(void)
static void Update_Current_Time(
void)
{
struct tm *tblock = NULL;
#if defined(_MSC_VER)
#if defined(_MSC_VER)
time_t tTemp;
#else
#else
struct timeval tv;
#endif
#endif
/*
struct tm
@@ -990,46 +914,36 @@ int tm_wday Day of week [0,6] (Sunday =0).
int tm_yday Day of year [0,365].
int tm_isdst Daylight Savings flag.
*/
#if defined(_MSC_VER)
#if defined(_MSC_VER)
time(&tTemp);
tblock = localtime(&tTemp);
#else
if (gettimeofday(&tv, NULL) == 0) {
#else
if (gettimeofday(&tv, NULL) == 0) {
tblock = localtime(&tv.tv_sec);
}
#endif
#endif
if (tblock) {
datetime_set_date(
&Local_Date,
(uint16_t) tblock->tm_year+1900,
(uint8_t) tblock->tm_mon+1,
(uint8_t) tblock->tm_mday);
#if !defined(_MSC_VER)
datetime_set_time(
&Local_Time,
(uint8_t) tblock->tm_hour,
(uint8_t) tblock->tm_min,
(uint8_t) tblock->tm_sec,
(uint8_t)(tv.tv_usec / 10000));
#else
datetime_set_time(
&Local_Time,
(uint8_t) tblock->tm_hour,
(uint8_t) tblock->tm_min,
(uint8_t) tblock->tm_sec,
0);
#endif
datetime_set_date(&Local_Date, (uint16_t) tblock->tm_year + 1900,
(uint8_t) tblock->tm_mon + 1, (uint8_t) tblock->tm_mday);
#if !defined(_MSC_VER)
datetime_set_time(&Local_Time, (uint8_t) tblock->tm_hour,
(uint8_t) tblock->tm_min, (uint8_t) tblock->tm_sec,
(uint8_t) (tv.tv_usec / 10000));
#else
datetime_set_time(&Local_Time, (uint8_t) tblock->tm_hour,
(uint8_t) tblock->tm_min, (uint8_t) tblock->tm_sec, 0);
#endif
if (tblock->tm_isdst) {
Daylight_Savings_Status = true;
} else {
Daylight_Savings_Status = false;
}
/* note: timezone is declared in <time.h> stdlib. */
UTC_Offset = timezone/60;
UTC_Offset = timezone / 60;
} else {
datetime_date_wildcard_set(&Local_Date);
datetime_time_wildcard_set(&Local_Time);
datetime_time_wildcard_set(&Local_Time);
Daylight_Savings_Status = false;
}
}
@@ -1037,7 +951,7 @@ int tm_isdst Daylight Savings flag.
/* return the length of the apdu encoded or -1 for error or
-2 for abort message */
static int Device_Read_Property_Local(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int apdu_len = 0; /* return value */
int len = 0; /* apdu len intermediate value */
@@ -1051,8 +965,7 @@ static int Device_Read_Property_Local(
struct object_functions *pObject = NULL;
bool found = false;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -1162,8 +1075,7 @@ static int Device_Read_Property_Local(
pObject = &Object_Table[0];
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
if ((pObject->Object_Count) &&
(pObject->Object_Count() > 0)) {
if ((pObject->Object_Count) && (pObject->Object_Count() > 0)) {
bitstring_set_bit(&bit_string, pObject->Object_Type, true);
}
pObject++;
@@ -1181,9 +1093,8 @@ static int Device_Read_Property_Local(
/* your maximum APDU size. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) {
for (i = 1; i <= count; i++) {
found = Device_Object_List_Identifier(
i,
&object_type,
found =
Device_Object_List_Identifier(i, &object_type,
&instance);
if (found) {
len =
@@ -1206,10 +1117,9 @@ static int Device_Read_Property_Local(
}
}
} else {
found = Device_Object_List_Identifier(
rpdata->array_index,
&object_type,
&instance);
found =
Device_Object_List_Identifier(rpdata->array_index,
&object_type, &instance);
if (found) {
apdu_len =
encode_application_object_id(&apdu[0], object_type,
@@ -1265,8 +1175,7 @@ static int Device_Read_Property_Local(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->object_property != PROP_OBJECT_LIST) &&
if ((apdu_len >= 0) && (rpdata->object_property != PROP_OBJECT_LIST) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
@@ -1285,7 +1194,7 @@ static int Device_Read_Property_Local(
* @return The length of the APDU on success, else -1
*/
int Device_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int apdu_len = -1;
struct object_functions *pObject = NULL;
@@ -1295,7 +1204,7 @@ int Device_Read_Property(
rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT;
pObject = Device_Objects_Find_Functions(rpdata->object_type);
if (pObject != NULL) {
if (pObject->Object_Valid_Instance &&
if (pObject->Object_Valid_Instance &&
pObject->Object_Valid_Instance(rpdata->object_instance)) {
if (pObject->Object_Read_Property) {
apdu_len = pObject->Object_Read_Property(rpdata);
@@ -1329,13 +1238,13 @@ static bool Device_Write_Property_Local(
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_OBJECT_IDENTIFIER:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_OBJECT_ID,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_OBJECT_ID,
&wp_data->error_class, &wp_data->error_code);
if (status) {
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 */
} else {
status = false;
@@ -1345,43 +1254,39 @@ static bool Device_Write_Property_Local(
}
break;
case PROP_NUMBER_OF_APDU_RETRIES:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
/* FIXME: bounds check? */
apdu_retries_set((uint8_t) value.type.Unsigned_Int);
}
break;
case PROP_APDU_TIMEOUT:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
/* FIXME: bounds check? */
apdu_timeout_set((uint16_t) value.type.Unsigned_Int);
}
break;
case PROP_VENDOR_IDENTIFIER:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
/* FIXME: bounds check? */
Device_Set_Vendor_Identifier((uint16_t) value.
type.Unsigned_Int);
Device_Set_Vendor_Identifier((uint16_t) value.type.
Unsigned_Int);
}
break;
case PROP_SYSTEM_STATUS:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_ENUMERATED,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED,
&wp_data->error_class, &wp_data->error_code);
if (status) {
temp = Device_Set_System_Status((BACNET_DEVICE_STATUS)
temp = Device_Set_System_Status((BACNET_DEVICE_STATUS)
value.type.Enumerated, false);
if (temp != 0) {
status = false;
@@ -1389,62 +1294,63 @@ static bool Device_Write_Property_Local(
if (temp == -1) {
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else {
wp_data->error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
wp_data->error_code =
ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
}
}
}
break;
case PROP_OBJECT_NAME:
status = WPValidateString(&value,
MAX_DEV_NAME_LEN,
false,
&wp_data->error_class,
&wp_data->error_code);
if (status) {
Device_Set_Object_Name(characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String));
status =
WPValidateString(&value, MAX_DEV_NAME_LEN, false,
&wp_data->error_class, &wp_data->error_code);
if (status) {
Device_Set_Object_Name(characterstring_value(&value.type.
Character_String),
characterstring_length(&value.type.Character_String));
}
break;
case PROP_LOCATION:
status = WPValidateString(&value,
MAX_DEV_LOC_LEN,
true,
status =
WPValidateString(&value, MAX_DEV_LOC_LEN, true,
&wp_data->error_class, &wp_data->error_code);
if (status) {
Device_Set_Location(characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String));
if (status) {
Device_Set_Location(characterstring_value(&value.type.
Character_String),
characterstring_length(&value.type.Character_String));
}
break;
case PROP_DESCRIPTION:
status = WPValidateString(&value,
MAX_DEV_DESC_LEN,
true,
&wp_data->error_class,
&wp_data->error_code);
if (status) {
Device_Set_Description(characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String));
status =
WPValidateString(&value, MAX_DEV_DESC_LEN, true,
&wp_data->error_class, &wp_data->error_code);
if (status) {
Device_Set_Description(characterstring_value(&value.type.
Character_String),
characterstring_length(&value.type.Character_String));
}
break;
case PROP_MODEL_NAME:
status = WPValidateString(&value,
MAX_DEV_MOD_LEN,
true,
&wp_data->error_class,
&wp_data->error_code);
if (status) {
Device_Set_Model_Name(characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String));
status =
WPValidateString(&value, MAX_DEV_MOD_LEN, true,
&wp_data->error_class, &wp_data->error_code);
if (status) {
Device_Set_Model_Name(characterstring_value(&value.type.
Character_String),
characterstring_length(&value.type.Character_String));
}
break;
#if defined(BACDL_MSTP)
case PROP_MAX_INFO_FRAMES:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
if (value.type.Unsigned_Int <= 255) {
dlmstp_set_max_info_frames((uint8_t) value.
type.Unsigned_Int);
dlmstp_set_max_info_frames((uint8_t) value.type.
Unsigned_Int);
} else {
status = false;
wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -1453,10 +1359,9 @@ static bool Device_Write_Property_Local(
}
break;
case PROP_MAX_MASTER:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
if ((value.type.Unsigned_Int > 0) &&
(value.type.Unsigned_Int <= 127)) {
@@ -1490,7 +1395,7 @@ static bool Device_Write_Property_Local(
bool Device_Write_Property(
BACNET_WRITE_PROPERTY_DATA * wp_data)
{
bool status = false; /* Ever the pessamist! */
bool status = false; /* Ever the pessamist! */
struct object_functions *pObject = NULL;
/* initialize the default return values */
@@ -1498,7 +1403,7 @@ bool Device_Write_Property(
wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT;
pObject = Device_Objects_Find_Functions(wp_data->object_type);
if (pObject != NULL) {
if (pObject->Object_Valid_Instance &&
if (pObject->Object_Valid_Instance &&
pObject->Object_Valid_Instance(wp_data->object_instance)) {
if (pObject->Object_Write_Property) {
status = pObject->Object_Write_Property(wp_data);
@@ -1515,7 +1420,7 @@ bool Device_Write_Property(
wp_data->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE;
}
return(status);
return (status);
}
@@ -1537,12 +1442,12 @@ void Device_Init(
}
bool DeviceGetRRInfo(
BACNET_READ_RANGE_DATA *pRequest, /* Info on the request */
RR_PROP_INFO *pInfo) /* Where to put the response */
{
bool status = false; /* return value */
switch(pRequest->object_property) {
BACNET_READ_RANGE_DATA * pRequest, /* Info on the request */
RR_PROP_INFO * pInfo)
{ /* Where to put the response */
bool status = false; /* return value */
switch (pRequest->object_property) {
case PROP_VT_CLASSES_SUPPORTED:
case PROP_ACTIVE_VT_SESSIONS:
case PROP_LIST_OF_SESSION_KEYS:
@@ -1553,7 +1458,7 @@ bool DeviceGetRRInfo(
case PROP_UTC_TIME_SYNCHRONIZATION_RECIPIENTS:
pInfo->RequestTypes = RR_BY_POSITION;
pRequest->error_class = ERROR_CLASS_PROPERTY;
pRequest->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
pRequest->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
break;
case PROP_DEVICE_ADDRESS_BINDING:
@@ -1561,15 +1466,15 @@ bool DeviceGetRRInfo(
pInfo->Handler = rr_address_list_encode;
status = true;
break;
case PROP_ACTIVE_COV_SUBSCRIPTIONS:
pInfo->RequestTypes = RR_BY_POSITION;
pRequest->error_class = ERROR_CLASS_PROPERTY;
pRequest->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
pRequest->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
break;
default:
pRequest->error_class = ERROR_CLASS_SERVICES;
pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST;
pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST;
break;
}
+26 -33
View File
@@ -199,7 +199,7 @@ void Load_Control_Init(
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 */
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;
@@ -680,7 +680,7 @@ void Load_Control_State_Machine_Handler(
/* return apdu len, or -1 on error */
int Load_Control_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int len = 0;
int apdu_len = 0; /* return value */
@@ -692,8 +692,7 @@ int Load_Control_Read_Property(
bool state = false;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -933,7 +932,7 @@ bool Load_Control_Write_Property(
unsigned int object_index = 0;
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
BACNET_DATE TempDate; /* build here in case of error in time half of datetime */
BACNET_DATE TempDate; /* build here in case of error in time half of datetime */
/* decode the some of the request */
len =
@@ -980,23 +979,22 @@ bool Load_Control_Write_Property(
break;
case PROP_START_TIME:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_DATE,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_DATE,
&wp_data->error_class, &wp_data->error_code);
if (!status) {
/* don't continue if we don't have a valid date */
break;
}
/* Hold the date until we are sure the time is also there */
TempDate = value.type.Date;
len = bacapp_decode_application_data(wp_data->application_data + len,
len =
bacapp_decode_application_data(wp_data->application_data + len,
wp_data->application_data_len - len, &value);
if (len) {
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_TIME,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_TIME,
&wp_data->error_class, &wp_data->error_code);
if (status) {
/* Write time and date and set written flag */
Start_Time[object_index].date = TempDate;
@@ -1011,10 +1009,9 @@ bool Load_Control_Write_Property(
break;
case PROP_SHED_DURATION:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
Shed_Duration[object_index] = value.type.Unsigned_Int;
Load_Control_Request_Written[object_index] = true;
@@ -1022,10 +1019,9 @@ bool Load_Control_Write_Property(
break;
case PROP_DUTY_WINDOW:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
Duty_Window[object_index] = value.type.Unsigned_Int;
Load_Control_Request_Written[object_index] = true;
@@ -1033,10 +1029,9 @@ bool Load_Control_Write_Property(
break;
case PROP_SHED_LEVELS:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
/* re-write the size of the array? */
if (wp_data->array_index == 0) {
@@ -1059,10 +1054,9 @@ bool Load_Control_Write_Property(
break;
case PROP_ENABLE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
Load_Control_Enable[object_index] = value.type.Boolean;
}
@@ -1477,7 +1471,7 @@ void testLoadControl(
Load_Control_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_LOAD_CONTROL;
rpdata.object_type = OBJECT_LOAD_CONTROL;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -1485,8 +1479,7 @@ void testLoadControl(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+30 -32
View File
@@ -28,7 +28,7 @@
/* WARNING! This object is still BACnet DRAFT status!
If you need to implement in a real product, you will
need to modify the new OBJECT type and properties to
be in the proprietrary range to be BACnet compliant */
be in the proprietrary range to be BACnet compliant */
#include <stdbool.h>
#include <stdint.h>
@@ -152,7 +152,7 @@ int Lighting_Output_Decode_Lighting_Command(
apdu_len += len;
len =
decode_enumerated(&apdu[apdu_len], len_value_type,
(uint32_t *)&data->operation);
(uint32_t *) & data->operation);
apdu_len += len;
/* Tag 1: level - OPTIONAL */
if (decode_is_context_tag(&apdu[apdu_len], 1)) {
@@ -162,7 +162,7 @@ int Lighting_Output_Decode_Lighting_Command(
apdu_len += len;
len = decode_real(&apdu[apdu_len], &real_value);
apdu_len += len;
data->level = (uint8_t)real_value;
data->level = (uint8_t) real_value;
/* FIXME: are we going to flag errors in decoding values here? */
}
/* FIXME: finish me! */
@@ -359,7 +359,7 @@ char *Lighting_Output_Name(
/* return apdu len, or -1 on error */
int Lighting_Output_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int len = 0;
int apdu_len = 0; /* return value */
@@ -371,8 +371,7 @@ int Lighting_Output_Read_Property(
bool state = false;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -398,11 +397,13 @@ int Lighting_Output_Read_Property(
OBJECT_LIGHTING_OUTPUT);
break;
case PROP_PRESENT_VALUE:
real_value = Lighting_Output_Present_Value(rpdata->object_instance);
real_value =
Lighting_Output_Present_Value(rpdata->object_instance);
apdu_len = encode_application_real(&apdu[0], real_value);
break;
case PROP_PROGRESS_VALUE:
real_value = Lighting_Output_Progress_Value(rpdata->object_instance);
real_value =
Lighting_Output_Progress_Value(rpdata->object_instance);
apdu_len = encode_application_real(&apdu[0], real_value);
break;
case PROP_LIGHTING_COMMAND:
@@ -423,7 +424,8 @@ int Lighting_Output_Read_Property(
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
break;
case PROP_OUT_OF_SERVICE:
object_index = Lighting_Output_Instance_To_Index(rpdata->object_instance);
object_index =
Lighting_Output_Instance_To_Index(rpdata->object_instance);
state = Lighting_Output_Out_Of_Service[object_index];
apdu_len = encode_application_boolean(&apdu[0], state);
break;
@@ -465,13 +467,13 @@ int Lighting_Output_Read_Property(
object_index =
Lighting_Output_Instance_To_Index(rpdata->object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Lighting_Output_Level[object_index][rpdata->array_index - 1] ==
LIGHTING_LEVEL_NULL)
if (Lighting_Output_Level[object_index][rpdata->
array_index - 1] == LIGHTING_LEVEL_NULL)
apdu_len = encode_application_null(&apdu[0]);
else {
real_value =
Lighting_Output_Level[object_index][rpdata->array_index -
1];
Lighting_Output_Level[object_index][rpdata->
array_index - 1];
apdu_len =
encode_application_real(&apdu[0], real_value);
}
@@ -494,8 +496,7 @@ int Lighting_Output_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->object_property != PROP_PRIORITY_ARRAY) &&
if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
@@ -541,18 +542,17 @@ bool Lighting_Output_Write_Property(
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class, &wp_data->error_code);
if (status) {
level = LIGHTING_LEVEL_NULL;
object_index =
Lighting_Output_Instance_To_Index
(wp_data->object_instance);
Lighting_Output_Instance_To_Index(wp_data->
object_instance);
status =
Lighting_Output_Present_Value_Relinquish
(wp_data->object_instance, wp_data->priority);
Lighting_Output_Present_Value_Relinquish(wp_data->
object_instance, 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
@@ -574,14 +574,13 @@ bool Lighting_Output_Write_Property(
&Lighting_Command[wp_data->object_instance]);
break;
case PROP_OUT_OF_SERVICE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
object_index =
Lighting_Output_Instance_To_Index
(wp_data->object_instance);
Lighting_Output_Instance_To_Index(wp_data->
object_instance);
Lighting_Output_Out_Of_Service[object_index] =
value.type.Boolean;
}
@@ -615,7 +614,7 @@ void testLightingOutput(
Lighting_Output_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_LIGHTING_OUTPUT;
rpdata.object_type = OBJECT_LIGHTING_OUTPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -623,8 +622,7 @@ void testLightingOutput(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+17 -21
View File
@@ -188,7 +188,7 @@ char *Life_Safety_Point_Name(
/* return apdu len, or -1 on error */
int Life_Safety_Point_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int len = 0;
int apdu_len = 0; /* return value */
@@ -203,8 +203,7 @@ int Life_Safety_Point_Read_Property(
BACNET_RELIABILITY reliability = RELIABILITY_NO_FAULT_DETECTED;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -228,7 +227,8 @@ int Life_Safety_Point_Read_Property(
OBJECT_LIFE_SAFETY_POINT);
break;
case PROP_PRESENT_VALUE:
present_value = Life_Safety_Point_Present_Value(rpdata->object_instance);
present_value =
Life_Safety_Point_Present_Value(rpdata->object_instance);
apdu_len = encode_application_enumerated(&apdu[0], present_value);
break;
case PROP_STATUS_FLAGS:
@@ -286,8 +286,7 @@ int Life_Safety_Point_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
apdu_len = -1;
@@ -313,15 +312,14 @@ bool Life_Safety_Point_Write_Property(
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_MODE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_ENUMERATED,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED,
&wp_data->error_class, &wp_data->error_code);
if (status) {
if (value.type.Enumerated <= MAX_LIFE_SAFETY_MODE) {
object_index =
Life_Safety_Point_Instance_To_Index
(wp_data->object_instance);
Life_Safety_Point_Instance_To_Index(wp_data->
object_instance);
Life_Safety_Point_Mode[object_index] =
value.type.Enumerated;
} else {
@@ -332,14 +330,13 @@ bool Life_Safety_Point_Write_Property(
}
break;
case PROP_OUT_OF_SERVICE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
object_index =
Life_Safety_Point_Instance_To_Index
(wp_data->object_instance);
Life_Safety_Point_Instance_To_Index(wp_data->
object_instance);
Life_Safety_Point_Out_Of_Service[object_index] =
value.type.Boolean;
}
@@ -373,7 +370,7 @@ void testLifeSafetyPoint(
Life_Safety_Point_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_LIFE_SAFETY_POINT;
rpdata.object_type = OBJECT_LIFE_SAFETY_POINT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -381,8 +378,7 @@ void testLifeSafetyPoint(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+27 -27
View File
@@ -318,7 +318,7 @@ bool Multistate_Input_State_Text_Set(
/* return apdu len, or -1 on error */
int Multistate_Input_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int len = 0;
int apdu_len = 0; /* return value */
@@ -330,8 +330,7 @@ int Multistate_Input_Read_Property(
bool state = false;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -362,7 +361,8 @@ int Multistate_Input_Read_Property(
OBJECT_MULTI_STATE_INPUT);
break;
case PROP_PRESENT_VALUE:
present_value = Multistate_Input_Present_Value(rpdata->object_instance);
present_value =
Multistate_Input_Present_Value(rpdata->object_instance);
apdu_len = encode_application_unsigned(&apdu[0], present_value);
break;
case PROP_STATUS_FLAGS:
@@ -380,7 +380,8 @@ int Multistate_Input_Read_Property(
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
break;
case PROP_OUT_OF_SERVICE:
object_index = Multistate_Input_Instance_To_Index(rpdata->object_instance);
object_index =
Multistate_Input_Instance_To_Index(rpdata->object_instance);
state = Out_Of_Service[object_index];
apdu_len = encode_application_boolean(&apdu[0], state);
break;
@@ -399,10 +400,12 @@ int Multistate_Input_Read_Property(
/* if no index was specified, then try to encode the entire list */
/* into one packet. */
object_index =
Multistate_Input_Instance_To_Index(rpdata->object_instance);
Multistate_Input_Instance_To_Index(rpdata->
object_instance);
for (i = 0; i < MULTISTATE_NUMBER_OF_STATES; i++) {
characterstring_init_ansi(&char_string,
Multistate_Input_State_Text(rpdata->object_instance, i));
Multistate_Input_State_Text(rpdata->object_instance,
i));
/* FIXME: this might go beyond MAX_APDU length! */
len =
encode_application_character_string(&apdu[apdu_len],
@@ -419,11 +422,12 @@ int Multistate_Input_Read_Property(
}
} else {
object_index =
Multistate_Input_Instance_To_Index(rpdata->object_instance);
Multistate_Input_Instance_To_Index(rpdata->
object_instance);
if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) {
characterstring_init_ansi(&char_string,
Multistate_Input_State_Text(rpdata->object_instance,
rpdata->array_index-1));
rpdata->array_index - 1));
apdu_len =
encode_application_character_string(&apdu[0],
&char_string);
@@ -441,8 +445,7 @@ int Multistate_Input_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->object_property != PROP_STATE_TEXT) &&
if ((apdu_len >= 0) && (rpdata->object_property != PROP_STATE_TEXT) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
@@ -469,15 +472,14 @@ bool Multistate_Input_Write_Property(
/* FIXME: len == 0: unable to decode? */
switch (wp_data->object_property) {
case PROP_PRESENT_VALUE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
&wp_data->error_class, &wp_data->error_code);
if (status) {
if (Out_Of_Service[object_index]) {
status = Multistate_Input_Present_Value_Set(
wp_data->object_instance,
value.type.Unsigned_Int);
status =
Multistate_Input_Present_Value_Set(wp_data->
object_instance, value.type.Unsigned_Int);
if (!status) {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
@@ -490,14 +492,13 @@ bool Multistate_Input_Write_Property(
}
break;
case PROP_OUT_OF_SERVICE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
object_index =
Multistate_Input_Instance_To_Index
(wp_data->object_instance);
Multistate_Input_Instance_To_Index(wp_data->
object_instance);
Out_Of_Service[object_index] = value.type.Boolean;
}
break;
@@ -530,7 +531,7 @@ void testMultistateInput(
Multistate_Input_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_MULTI_STATE_INPUT;
rpdata.object_type = OBJECT_MULTI_STATE_INPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -538,8 +539,7 @@ void testMultistateInput(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
+27 -29
View File
@@ -195,7 +195,7 @@ char *Multistate_Output_Name(
/* return apdu len, or -1 on error */
int Multistate_Output_Read_Property(
BACNET_READ_PROPERTY_DATA *rpdata)
BACNET_READ_PROPERTY_DATA * rpdata)
{
int len = 0;
int apdu_len = 0; /* return value */
@@ -207,8 +207,7 @@ int Multistate_Output_Read_Property(
bool state = false;
uint8_t *apdu = NULL;
if ((rpdata == NULL) ||
(rpdata->application_data == NULL) ||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
(rpdata->application_data_len == 0)) {
return 0;
}
@@ -234,7 +233,8 @@ int Multistate_Output_Read_Property(
OBJECT_MULTI_STATE_OUTPUT);
break;
case PROP_PRESENT_VALUE:
present_value = Multistate_Output_Present_Value(rpdata->object_instance);
present_value =
Multistate_Output_Present_Value(rpdata->object_instance);
apdu_len = encode_application_unsigned(&apdu[0], present_value);
break;
case PROP_STATUS_FLAGS:
@@ -266,7 +266,8 @@ int Multistate_Output_Read_Property(
/* into one packet. */
else if (rpdata->array_index == BACNET_ARRAY_ALL) {
object_index =
Multistate_Output_Instance_To_Index(rpdata->object_instance);
Multistate_Output_Instance_To_Index(rpdata->
object_instance);
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
/* FIXME: check if we have room before adding it to APDU */
if (Multistate_Output_Level[object_index][i] ==
@@ -291,15 +292,16 @@ int Multistate_Output_Read_Property(
}
} else {
object_index =
Multistate_Output_Instance_To_Index(rpdata->object_instance);
Multistate_Output_Instance_To_Index(rpdata->
object_instance);
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
if (Multistate_Output_Level[object_index][rpdata->array_index -
1] == MULTISTATE_NULL)
if (Multistate_Output_Level[object_index][rpdata->
array_index - 1] == MULTISTATE_NULL)
apdu_len = encode_application_null(&apdu[0]);
else {
present_value =
Multistate_Output_Level[object_index][rpdata->array_index -
1];
Multistate_Output_Level[object_index][rpdata->
array_index - 1];
apdu_len =
encode_application_unsigned(&apdu[0],
present_value);
@@ -329,8 +331,7 @@ int Multistate_Output_Read_Property(
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(rpdata->object_property != PROP_PRIORITY_ARRAY) &&
if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
@@ -369,8 +370,8 @@ bool Multistate_Output_Write_Property(
(value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) {
level = value.type.Unsigned_Int;
object_index =
Multistate_Output_Instance_To_Index
(wp_data->object_instance);
Multistate_Output_Instance_To_Index(wp_data->
object_instance);
priority--;
Multistate_Output_Level[object_index][priority] =
(uint8_t) level;
@@ -391,15 +392,14 @@ bool Multistate_Output_Write_Property(
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL,
&wp_data->error_class, &wp_data->error_code);
if (status) {
level = MULTISTATE_NULL;
object_index =
Multistate_Output_Instance_To_Index
(wp_data->object_instance);
Multistate_Output_Instance_To_Index(wp_data->
object_instance);
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
@@ -420,14 +420,13 @@ bool Multistate_Output_Write_Property(
}
break;
case PROP_OUT_OF_SERVICE:
status = WPValidateArgType(&value,
BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class,
&wp_data->error_code);
status =
WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN,
&wp_data->error_class, &wp_data->error_code);
if (status) {
object_index =
Multistate_Output_Instance_To_Index
(wp_data->object_instance);
Multistate_Output_Instance_To_Index(wp_data->
object_instance);
Multistate_Output_Out_Of_Service[object_index] =
value.type.Boolean;
}
@@ -461,7 +460,7 @@ void testMultistateOutput(
Multistate_Output_Init();
rpdata.application_data = &apdu[0];
rpdata.application_data_len = sizeof(apdu);
rpdata.object_type = OBJECT_MULTI_STATE_OUTPUT;
rpdata.object_type = OBJECT_MULTI_STATE_OUTPUT;
rpdata.object_instance = 1;
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
@@ -469,8 +468,7 @@ void testMultistateOutput(
ct_test(pTest, len != 0);
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
len =
decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance);
ct_test(pTest, decoded_type == rpdata.object_type);
ct_test(pTest, decoded_instance == rpdata.object_instance);
File diff suppressed because it is too large Load Diff