AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/src/rp.c
int rp_ack_encode_apdu_init(
    uint8_t * apdu,
    uint8_t invoke_id,
    BACNET_READ_PROPERTY_DATA * rpdata)
{
    int len = 0;        /* length of each encoding */
    int apdu_len = 0;   /* total length of the apdu, return value */

    if (apdu) {
        apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */
        apdu[1] = invoke_id;    /* original invoke id from request */
        apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY;      /* service choice */
        apdu_len = 3;

        /* service ack follows */
        len =
            encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type,
            rpdata->object_instance);
        apdu_len += len;
        len =
            encode_context_enumerated(&apdu[apdu_len], 1,
            rpdata->object_property);
        apdu_len += len;
        /* context 2 array index is optional */
        if (rpdata->array_index != BACNET_ARRAY_ALL) {
            len =
                encode_context_unsigned(&apdu[apdu_len], 2,
                rpdata->array_index);
            apdu_len += len;
        }
        len = encode_opening_tag(&apdu[apdu_len], 3);
        apdu_len += len;
    }

    return apdu_len;
}
/* alternate method to encode the ack without extra buffer */
alternate method to encode the ack without extra buffer
alternate method to encode the ack without extra buffer
int rp_ack_encode_apdu_init(
    uint8_t * apdu,
    uint8_t invoke_id,
    BACNET_READ_PROPERTY_DATA * rpdata)
{
    int len = 0;        
    int apdu_len = 0;   
    if (apdu) {
        apdu[0] = PDU_TYPE_COMPLEX_ACK; 
        apdu[1] = invoke_id;    
        apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY;      
        apdu_len = 3;
        len =
            encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type,
            rpdata->object_instance);
        apdu_len += len;
        len =
            encode_context_enumerated(&apdu[apdu_len], 1,
            rpdata->object_property);
        apdu_len += len;
        if (rpdata->array_index != BACNET_ARRAY_ALL) {
            len =
                encode_context_unsigned(&apdu[apdu_len], 2,
                rpdata->array_index);
            apdu_len += len;
        }
        len = encode_opening_tag(&apdu[apdu_len], 3);
        apdu_len += len;
    }
    return apdu_len;
}
int rp_ack_encode_apdu_init ( uint8_t * apdu , uint8_t invoke_id , BACNET_READ_PROPERTY_DATA * rpdata ) { int len = 0 ; int apdu_len = 0 ; if ( apdu ) { apdu [ 0 ] = PDU_TYPE_COMPLEX_ACK ; apdu [ 1 ] = invoke_id ; apdu [ 2 ] = SERVICE_CONFIRMED_READ_PROPERTY ; apdu_len = 3 ; len = encode_context_object_id ( & apdu [ apdu_len ] , 0 , rpdata -> object_type , rpdata -> object_instance ) ; apdu_len += len ; len = encode_context_enumerated ( & apdu [ apdu_len ] , 1 , rpdata -> object_property ) ; apdu_len += len ; if ( rpdata -> array_index != BACNET_ARRAY_ALL ) { len = encode_context_unsigned ( & apdu [ apdu_len ] , 2 , rpdata -> array_index ) ; apdu_len += len ; } len = encode_opening_tag ( & apdu [ apdu_len ] , 3 ) ; apdu_len += len ; } return apdu_len ; }
alternate method to encode the ack without extra buffer
alternate method to encode the ack without extra buffer
/* length of each encoding */ /* total length of the apdu, return value */ /* complex ACK service */ /* original invoke id from request */ /* service choice */ /* service ack follows */ /* context 2 array index is optional */