AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/demo/object/command.c
int Command_Read_Property(
    BACNET_READ_PROPERTY_DATA * rpdata)
{
    int apdu_len = 0;   /* return value */
    int len = 0;
    BACNET_CHARACTER_STRING char_string;
    unsigned object_index = 0;
    uint8_t *apdu = NULL;
    uint16_t apdu_max = 0;
    COMMAND_DESCR *CurrentCommand;

    if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
        (rpdata->application_data_len == 0)) {
        return 0;
    }
    apdu_max = rpdata->application_data_len;
    object_index = Command_Instance_To_Index(rpdata->object_instance);
    if (object_index < MAX_COMMANDS) {
        CurrentCommand = &Command_Descr[object_index];
    } else {
        return false;
    }

    apdu = rpdata->application_data;
    switch ((int) rpdata->object_property) {
        case PROP_OBJECT_IDENTIFIER:
            apdu_len =
                encode_application_object_id(&apdu[0], OBJECT_COMMAND,
                rpdata->object_instance);
            break;

        case PROP_OBJECT_NAME:
        case PROP_DESCRIPTION:
            Command_Object_Name(rpdata->object_instance, &char_string);
            apdu_len =
                encode_application_character_string(&apdu[0], &char_string);
            break;

        case PROP_OBJECT_TYPE:
            apdu_len = encode_application_enumerated(&apdu[0], OBJECT_COMMAND);
            break;

        case PROP_PRESENT_VALUE:
            apdu_len =
                encode_application_unsigned(&apdu[0],
                Command_Present_Value(rpdata->object_instance));
            break;
        case PROP_IN_PROCESS:
            apdu_len =
                encode_application_boolean(&apdu[0],
                Command_In_Process(rpdata->object_instance));
            break;
        case PROP_ALL_WRITES_SUCCESSFUL:
            apdu_len =
                encode_application_boolean(&apdu[0],
                Command_All_Writes_Successful(rpdata->object_instance));
            break;
        case PROP_ACTION:
            /* TODO */
            if (rpdata->array_index == 0)
                apdu_len = encode_application_unsigned(&apdu[0], MAX_COMMAND_ACTIONS);
            else if (rpdata->array_index == BACNET_ARRAY_ALL) {
                int i;
                for (i = 0; i < MAX_COMMAND_ACTIONS; i++) {
                    BACNET_ACTION_LIST *Curr_CL_Member =
                        &CurrentCommand->Action[0];
                    /* another loop, for aditional actions in the list */
                    for (; Curr_CL_Member != NULL;
                        Curr_CL_Member = Curr_CL_Member->next) {
                        len =
                            cl_encode_apdu(&apdu[apdu_len],
                            &CurrentCommand->Action[0]);
                        apdu_len += len;
                        /* assume the next one is of the same length, which need not be the case */
                        if ((i != MAX_COMMAND_ACTIONS - 1) &&
                            (apdu_len + len) >= apdu_max) {
                            rpdata->error_code =
                                ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
                            apdu_len = BACNET_STATUS_ABORT;
                            break;
                        }
                    }
                }
            } else {
                if (rpdata->array_index < MAX_COMMAND_ACTIONS) {
                    BACNET_ACTION_LIST *Curr_CL_Member =
                        &CurrentCommand->Action[rpdata->array_index];
                    /* another loop, for aditional actions in the list */
                    for (; Curr_CL_Member != NULL;
                        Curr_CL_Member = Curr_CL_Member->next) {
                        len =
                            cl_encode_apdu(&apdu[apdu_len],
                            &CurrentCommand->Action[0]);
                        apdu_len += len;
                        /* assume the next one is of the same length, which need not be the case */
                        if ((apdu_len + len) >= apdu_max) {
                            rpdata->error_code =
                                ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
                            apdu_len = BACNET_STATUS_ABORT;
                            break;
                        }
                    }
                } else {
                    rpdata->error_class = ERROR_CLASS_PROPERTY;
                    rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
                    apdu_len = BACNET_STATUS_ERROR;
                }
            }
            break;
        default:
            rpdata->error_class = ERROR_CLASS_PROPERTY;
            rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
            apdu_len = BACNET_STATUS_ERROR;
            break;
    }
    /*  only array properties can have array options */
    if ((apdu_len >= 0) && (rpdata->object_property != PROP_ACTION)
        && (rpdata->array_index != BACNET_ARRAY_ALL)) {
        rpdata->error_class = ERROR_CLASS_PROPERTY;
        rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
        apdu_len = BACNET_STATUS_ERROR;
    }

    return apdu_len;
}
/**
 * ReadProperty handler for this object.  For the given ReadProperty
 * data, the application_data is loaded or the error flags are set.
 *
 * @param  rpdata - BACNET_READ_PROPERTY_DATA data, including
 * requested data and space for the reply, or error response.
 *
 * @return number of APDU bytes in the response, or
 * BACNET_STATUS_ERROR on error.
 */
ReadProperty handler for this object.  For the given ReadProperty
data, the application_data is loaded or the error flags are set.

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

@return number of APDU bytes in the response, or
BACNET_STATUS_ERROR on error.
ReadProperty handler for this object . For the given ReadProperty data the application_data is loaded or the error flags are set . @param rpdata - BACNET_READ_PROPERTY_DATA data including requested data and space for the reply or error response . @return number of APDU bytes in the response or BACNET_STATUS_ERROR on error .
int Command_Read_Property(
    BACNET_READ_PROPERTY_DATA * rpdata)
{
    int apdu_len = 0;   
    int len = 0;
    BACNET_CHARACTER_STRING char_string;
    unsigned object_index = 0;
    uint8_t *apdu = NULL;
    uint16_t apdu_max = 0;
    COMMAND_DESCR *CurrentCommand;
    if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
        (rpdata->application_data_len == 0)) {
        return 0;
    }
    apdu_max = rpdata->application_data_len;
    object_index = Command_Instance_To_Index(rpdata->object_instance);
    if (object_index < MAX_COMMANDS) {
        CurrentCommand = &Command_Descr[object_index];
    } else {
        return false;
    }
    apdu = rpdata->application_data;
    switch ((int) rpdata->object_property) {
        case PROP_OBJECT_IDENTIFIER:
            apdu_len =
                encode_application_object_id(&apdu[0], OBJECT_COMMAND,
                rpdata->object_instance);
            break;
        case PROP_OBJECT_NAME:
        case PROP_DESCRIPTION:
            Command_Object_Name(rpdata->object_instance, &char_string);
            apdu_len =
                encode_application_character_string(&apdu[0], &char_string);
            break;
        case PROP_OBJECT_TYPE:
            apdu_len = encode_application_enumerated(&apdu[0], OBJECT_COMMAND);
            break;
        case PROP_PRESENT_VALUE:
            apdu_len =
                encode_application_unsigned(&apdu[0],
                Command_Present_Value(rpdata->object_instance));
            break;
        case PROP_IN_PROCESS:
            apdu_len =
                encode_application_boolean(&apdu[0],
                Command_In_Process(rpdata->object_instance));
            break;
        case PROP_ALL_WRITES_SUCCESSFUL:
            apdu_len =
                encode_application_boolean(&apdu[0],
                Command_All_Writes_Successful(rpdata->object_instance));
            break;
        case PROP_ACTION:
            if (rpdata->array_index == 0)
                apdu_len = encode_application_unsigned(&apdu[0], MAX_COMMAND_ACTIONS);
            else if (rpdata->array_index == BACNET_ARRAY_ALL) {
                int i;
                for (i = 0; i < MAX_COMMAND_ACTIONS; i++) {
                    BACNET_ACTION_LIST *Curr_CL_Member =
                        &CurrentCommand->Action[0];
                    for (; Curr_CL_Member != NULL;
                        Curr_CL_Member = Curr_CL_Member->next) {
                        len =
                            cl_encode_apdu(&apdu[apdu_len],
                            &CurrentCommand->Action[0]);
                        apdu_len += len;
                        if ((i != MAX_COMMAND_ACTIONS - 1) &&
                            (apdu_len + len) >= apdu_max) {
                            rpdata->error_code =
                                ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
                            apdu_len = BACNET_STATUS_ABORT;
                            break;
                        }
                    }
                }
            } else {
                if (rpdata->array_index < MAX_COMMAND_ACTIONS) {
                    BACNET_ACTION_LIST *Curr_CL_Member =
                        &CurrentCommand->Action[rpdata->array_index];
                    for (; Curr_CL_Member != NULL;
                        Curr_CL_Member = Curr_CL_Member->next) {
                        len =
                            cl_encode_apdu(&apdu[apdu_len],
                            &CurrentCommand->Action[0]);
                        apdu_len += len;
                        if ((apdu_len + len) >= apdu_max) {
                            rpdata->error_code =
                                ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
                            apdu_len = BACNET_STATUS_ABORT;
                            break;
                        }
                    }
                } else {
                    rpdata->error_class = ERROR_CLASS_PROPERTY;
                    rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
                    apdu_len = BACNET_STATUS_ERROR;
                }
            }
            break;
        default:
            rpdata->error_class = ERROR_CLASS_PROPERTY;
            rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY;
            apdu_len = BACNET_STATUS_ERROR;
            break;
    }
    if ((apdu_len >= 0) && (rpdata->object_property != PROP_ACTION)
        && (rpdata->array_index != BACNET_ARRAY_ALL)) {
        rpdata->error_class = ERROR_CLASS_PROPERTY;
        rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
        apdu_len = BACNET_STATUS_ERROR;
    }
    return apdu_len;
}
int Command_Read_Property ( BACNET_READ_PROPERTY_DATA * rpdata ) { int apdu_len = 0 ; int len = 0 ; BACNET_CHARACTER_STRING char_string ; unsigned object_index = 0 ; uint8_t * apdu = NULL ; uint16_t apdu_max = 0 ; COMMAND_DESCR * CurrentCommand ; if ( ( rpdata == NULL ) || ( rpdata -> application_data == NULL ) || ( rpdata -> application_data_len == 0 ) ) { return 0 ; } apdu_max = rpdata -> application_data_len ; object_index = Command_Instance_To_Index ( rpdata -> object_instance ) ; if ( object_index < MAX_COMMANDS ) { CurrentCommand = & Command_Descr [ object_index ] ; } else { return false ; } apdu = rpdata -> application_data ; switch ( ( int ) rpdata -> object_property ) { case PROP_OBJECT_IDENTIFIER : apdu_len = encode_application_object_id ( & apdu [ 0 ] , OBJECT_COMMAND , rpdata -> object_instance ) ; break ; case PROP_OBJECT_NAME : case PROP_DESCRIPTION : Command_Object_Name ( rpdata -> object_instance , & char_string ) ; apdu_len = encode_application_character_string ( & apdu [ 0 ] , & char_string ) ; break ; case PROP_OBJECT_TYPE : apdu_len = encode_application_enumerated ( & apdu [ 0 ] , OBJECT_COMMAND ) ; break ; case PROP_PRESENT_VALUE : apdu_len = encode_application_unsigned ( & apdu [ 0 ] , Command_Present_Value ( rpdata -> object_instance ) ) ; break ; case PROP_IN_PROCESS : apdu_len = encode_application_boolean ( & apdu [ 0 ] , Command_In_Process ( rpdata -> object_instance ) ) ; break ; case PROP_ALL_WRITES_SUCCESSFUL : apdu_len = encode_application_boolean ( & apdu [ 0 ] , Command_All_Writes_Successful ( rpdata -> object_instance ) ) ; break ; case PROP_ACTION : if ( rpdata -> array_index == 0 ) apdu_len = encode_application_unsigned ( & apdu [ 0 ] , MAX_COMMAND_ACTIONS ) ; else if ( rpdata -> array_index == BACNET_ARRAY_ALL ) { int i ; for ( i = 0 ; i < MAX_COMMAND_ACTIONS ; i ++ ) { BACNET_ACTION_LIST * Curr_CL_Member = & CurrentCommand -> Action [ 0 ] ; for ( ; Curr_CL_Member != NULL ; Curr_CL_Member = Curr_CL_Member -> next ) { len = cl_encode_apdu ( & apdu [ apdu_len ] , & CurrentCommand -> Action [ 0 ] ) ; apdu_len += len ; if ( ( i != MAX_COMMAND_ACTIONS - 1 ) && ( apdu_len + len ) >= apdu_max ) { rpdata -> error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED ; apdu_len = BACNET_STATUS_ABORT ; break ; } } } } else { if ( rpdata -> array_index < MAX_COMMAND_ACTIONS ) { BACNET_ACTION_LIST * Curr_CL_Member = & CurrentCommand -> Action [ rpdata -> array_index ] ; for ( ; Curr_CL_Member != NULL ; Curr_CL_Member = Curr_CL_Member -> next ) { len = cl_encode_apdu ( & apdu [ apdu_len ] , & CurrentCommand -> Action [ 0 ] ) ; apdu_len += len ; if ( ( apdu_len + len ) >= apdu_max ) { rpdata -> error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED ; apdu_len = BACNET_STATUS_ABORT ; break ; } } } else { rpdata -> error_class = ERROR_CLASS_PROPERTY ; rpdata -> error_code = ERROR_CODE_INVALID_ARRAY_INDEX ; apdu_len = BACNET_STATUS_ERROR ; } } break ; default : rpdata -> error_class = ERROR_CLASS_PROPERTY ; rpdata -> error_code = ERROR_CODE_UNKNOWN_PROPERTY ; apdu_len = BACNET_STATUS_ERROR ; break ; } if ( ( apdu_len >= 0 ) && ( rpdata -> object_property != PROP_ACTION ) && ( rpdata -> array_index != BACNET_ARRAY_ALL ) ) { rpdata -> error_class = ERROR_CLASS_PROPERTY ; rpdata -> error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY ; apdu_len = BACNET_STATUS_ERROR ; } return apdu_len ; }
ReadProperty handler for this object.
ReadProperty handler for this object .
/* return value */ /* TODO */ /* another loop, for aditional actions in the list */ /* assume the next one is of the same length, which need not be the case */ /* another loop, for aditional actions in the list */ /* assume the next one is of the same length, which need not be the case */ /*  only array properties can have array options */