Simplified write property code using new validation helper functions in h_wp.c.

Buffered date portion when writing to start time property so that failure in time portion wouldn't leave partially written date/time.
Flagged missing code in write property for shed levels and placed error response there.
This commit is contained in:
petermcs
2010-02-04 13:42:56 +00:00
parent a076bca5dc
commit 818ddefae5
+26 -40
View File
@@ -39,6 +39,7 @@
#include "lc.h" #include "lc.h"
#include "ao.h" #include "ao.h"
#include "wp.h" #include "wp.h"
#include "handlers.h"
/* number of demo objects */ /* number of demo objects */
#define MAX_LOAD_CONTROLS 4 #define MAX_LOAD_CONTROLS 4
@@ -943,6 +944,7 @@ bool Load_Control_Write_Property(
unsigned int object_index = 0; unsigned int object_index = 0;
int len = 0; int len = 0;
BACNET_APPLICATION_DATA_VALUE value; BACNET_APPLICATION_DATA_VALUE value;
BACNET_DATE TempDate; /* build here in case of error in time half of datetime */
Load_Control_Init(); Load_Control_Init();
if (!Load_Control_Valid_Instance(wp_data->object_instance)) { if (!Load_Control_Valid_Instance(wp_data->object_instance)) {
@@ -993,53 +995,38 @@ bool Load_Control_Write_Property(
Load_Control_Request_Written[object_index] = true; Load_Control_Request_Written[object_index] = true;
} }
break; break;
case PROP_START_TIME: case PROP_START_TIME:
if (value.tag == BACNET_APPLICATION_TAG_DATE) { if((status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_DATE, error_class, error_code)) == false)
memcpy(&Start_Time[object_index].date, &value.type.Date,
sizeof(value.type.Date));
Start_Time_Property_Written[object_index] = true;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
if (!status)
break; break;
len = /* Hold the date until we are sure the time is also there */
bacapp_decode_application_data(wp_data->application_data + len, TempDate = value.type.Date;
len = bacapp_decode_application_data(wp_data->application_data + len,
wp_data->application_data_len - len, &value); wp_data->application_data_len - len, &value);
if (len && value.tag == BACNET_APPLICATION_TAG_TIME) { if (len && ((status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_TIME, error_class, error_code)) == true)) {
memcpy(&Start_Time[object_index].time, &value.type.Time, /* Write time and date and set written flag */
sizeof(value.type.Time)); Start_Time[object_index].date = TempDate;
status = true; Start_Time[object_index].time = value.type.Time;
} else { Start_Time_Property_Written[object_index] = true;
status = false;
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
} }
break; break;
case PROP_SHED_DURATION: case PROP_SHED_DURATION:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) { if((status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, error_class, error_code)) == true) {
Shed_Duration[object_index] = value.type.Unsigned_Int; Shed_Duration[object_index] = value.type.Unsigned_Int;
Load_Control_Request_Written[object_index] = true; Load_Control_Request_Written[object_index] = true;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
} }
break; break;
case PROP_DUTY_WINDOW: case PROP_DUTY_WINDOW:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) { if((status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, error_class, error_code)) == true) {
Duty_Window[object_index] = value.type.Unsigned_Int; Duty_Window[object_index] = value.type.Unsigned_Int;
Load_Control_Request_Written[object_index] = true; Load_Control_Request_Written[object_index] = true;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
} }
break; break;
case PROP_SHED_LEVELS: case PROP_SHED_LEVELS:
if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) { if(WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, error_class, error_code) == true) {
/* re-write the size of the array? */ /* re-write the size of the array? */
if (wp_data->array_index == 0) { if (wp_data->array_index == 0) {
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
@@ -1052,21 +1039,20 @@ bool Load_Control_Write_Property(
value.type.Unsigned_Int; value.type.Unsigned_Int;
status = true; status = true;
} else { } else {
/* FIXME: Something's missing from here so I'll just put in
* a place holder error here for the moment*/
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_OTHER;
} }
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
} }
break; break;
case PROP_ENABLE: case PROP_ENABLE:
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) { if((status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, error_class, error_code)) == true)
Load_Control_Enable[object_index] = value.type.Boolean; Load_Control_Enable[object_index] = value.type.Boolean;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
break; break;
default: default:
*error_class = ERROR_CLASS_PROPERTY; *error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED; *error_code = ERROR_CODE_WRITE_ACCESS_DENIED;