AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/demo/object/command.c
bool Command_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;
    /* 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? */
    if (len < 0) {
        /* error while decoding - a value larger than we can handle */
        wp_data->error_class = ERROR_CLASS_PROPERTY;
        wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
        return false;
    }
    /*  only array properties can have array options */
    if ((wp_data->object_property != PROP_ACTION) &&
        (wp_data->array_index != BACNET_ARRAY_ALL)) {
        wp_data->error_class = ERROR_CLASS_PROPERTY;
        wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
        return false;
    }
    object_index = Command_Instance_To_Index(wp_data->object_instance);
    if (object_index >= MAX_COMMANDS) {
        return false;
    }

    switch ((int) wp_data->object_property) {
        case PROP_PRESENT_VALUE:
            status =
                WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
                &wp_data->error_class, &wp_data->error_code);
            if (status) {
                if (value.type.Unsigned_Int >= MAX_COMMAND_ACTIONS) {
                    wp_data->error_class = ERROR_CLASS_PROPERTY;
                    wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
                    return false;
                }
                Command_Present_Value_Set(wp_data->object_instance,
                    value.type.Unsigned_Int);
            } else {
                wp_data->error_class = ERROR_CLASS_PROPERTY;
                wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
                status = false;
            }

            break;

        case PROP_OBJECT_IDENTIFIER:
        case PROP_OBJECT_NAME:
        case PROP_OBJECT_TYPE:
        case PROP_IN_PROCESS:
        case PROP_ALL_WRITES_SUCCESSFUL:
        case PROP_ACTION:
            wp_data->error_class = ERROR_CLASS_PROPERTY;
            wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
            break;
        default:
            wp_data->error_class = ERROR_CLASS_PROPERTY;
            wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
            break;
    }

    return status;
}
/**
 * WriteProperty handler for this object.  For the given WriteProperty
 * data, the application_data is loaded or the error flags are set.
 *
 * @param  wp_data - BACNET_WRITE_PROPERTY_DATA data, including
 * requested data and space for the reply, or error response.
 *
 * @return false if an error is loaded, true if no errors
 */
WriteProperty handler for this object.  For the given WriteProperty
data, the application_data is loaded or the error flags are set.

@param  wp_data - BACNET_WRITE_PROPERTY_DATA data, including
requested data and space for the reply, or error response.

@return false if an error is loaded, true if no errors
WriteProperty handler for this object . For the given WriteProperty data the application_data is loaded or the error flags are set . @param wp_data - BACNET_WRITE_PROPERTY_DATA data including requested data and space for the reply or error response . @return false if an error is loaded true if no errors
bool Command_Write_Property(
    BACNET_WRITE_PROPERTY_DATA * wp_data)
{
    bool status = false;        
    unsigned int object_index = 0;
    int len = 0;
    BACNET_APPLICATION_DATA_VALUE value;
    len =
        bacapp_decode_application_data(wp_data->application_data,
        wp_data->application_data_len, &value);
    if (len < 0) {
        wp_data->error_class = ERROR_CLASS_PROPERTY;
        wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
        return false;
    }
    if ((wp_data->object_property != PROP_ACTION) &&
        (wp_data->array_index != BACNET_ARRAY_ALL)) {
        wp_data->error_class = ERROR_CLASS_PROPERTY;
        wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
        return false;
    }
    object_index = Command_Instance_To_Index(wp_data->object_instance);
    if (object_index >= MAX_COMMANDS) {
        return false;
    }
    switch ((int) wp_data->object_property) {
        case PROP_PRESENT_VALUE:
            status =
                WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT,
                &wp_data->error_class, &wp_data->error_code);
            if (status) {
                if (value.type.Unsigned_Int >= MAX_COMMAND_ACTIONS) {
                    wp_data->error_class = ERROR_CLASS_PROPERTY;
                    wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
                    return false;
                }
                Command_Present_Value_Set(wp_data->object_instance,
                    value.type.Unsigned_Int);
            } else {
                wp_data->error_class = ERROR_CLASS_PROPERTY;
                wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
                status = false;
            }
            break;
        case PROP_OBJECT_IDENTIFIER:
        case PROP_OBJECT_NAME:
        case PROP_OBJECT_TYPE:
        case PROP_IN_PROCESS:
        case PROP_ALL_WRITES_SUCCESSFUL:
        case PROP_ACTION:
            wp_data->error_class = ERROR_CLASS_PROPERTY;
            wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
            break;
        default:
            wp_data->error_class = ERROR_CLASS_PROPERTY;
            wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
            break;
    }
    return status;
}
bool Command_Write_Property ( BACNET_WRITE_PROPERTY_DATA * wp_data ) { bool status = false ; unsigned int object_index = 0 ; int len = 0 ; BACNET_APPLICATION_DATA_VALUE value ; len = bacapp_decode_application_data ( wp_data -> application_data , wp_data -> application_data_len , & value ) ; if ( len < 0 ) { wp_data -> error_class = ERROR_CLASS_PROPERTY ; wp_data -> error_code = ERROR_CODE_VALUE_OUT_OF_RANGE ; return false ; } if ( ( wp_data -> object_property != PROP_ACTION ) && ( wp_data -> array_index != BACNET_ARRAY_ALL ) ) { wp_data -> error_class = ERROR_CLASS_PROPERTY ; wp_data -> error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY ; return false ; } object_index = Command_Instance_To_Index ( wp_data -> object_instance ) ; if ( object_index >= MAX_COMMANDS ) { return false ; } switch ( ( int ) wp_data -> object_property ) { case PROP_PRESENT_VALUE : status = WPValidateArgType ( & value , BACNET_APPLICATION_TAG_UNSIGNED_INT , & wp_data -> error_class , & wp_data -> error_code ) ; if ( status ) { if ( value . type . Unsigned_Int >= MAX_COMMAND_ACTIONS ) { wp_data -> error_class = ERROR_CLASS_PROPERTY ; wp_data -> error_code = ERROR_CODE_VALUE_OUT_OF_RANGE ; return false ; } Command_Present_Value_Set ( wp_data -> object_instance , value . type . Unsigned_Int ) ; } else { wp_data -> error_class = ERROR_CLASS_PROPERTY ; wp_data -> error_code = ERROR_CODE_WRITE_ACCESS_DENIED ; status = false ; } break ; case PROP_OBJECT_IDENTIFIER : case PROP_OBJECT_NAME : case PROP_OBJECT_TYPE : case PROP_IN_PROCESS : case PROP_ALL_WRITES_SUCCESSFUL : case PROP_ACTION : wp_data -> error_class = ERROR_CLASS_PROPERTY ; wp_data -> error_code = ERROR_CODE_WRITE_ACCESS_DENIED ; break ; default : wp_data -> error_class = ERROR_CLASS_PROPERTY ; wp_data -> error_code = ERROR_CODE_UNKNOWN_PROPERTY ; break ; } return status ; }
WriteProperty handler for this object.
WriteProperty handler for this object .
/* return value */ /* decode the some of the request */ /* FIXME: len < application_data_len: more data? */ /* error while decoding - a value larger than we can handle */ /*  only array properties can have array options */