AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/src/rp.c
int rp_ack_decode_service_request(
    uint8_t * apdu,
    int apdu_len,       /* total length of the apdu */
    BACNET_READ_PROPERTY_DATA * rpdata)
{
    uint8_t tag_number = 0;
    uint32_t len_value_type = 0;
    int tag_len = 0;    /* length of tag decode */
    int len = 0;        /* total length of decodes */
    uint16_t object = 0;        /* object type */
    uint32_t property = 0;      /* for decoding */
    uint32_t array_value = 0;   /* for decoding */

    /* FIXME: check apdu_len against the len during decode   */
    /* Tag 0: Object ID */
    if (!decode_is_context_tag(&apdu[0], 0))
        return -1;
    len = 1;
    len += decode_object_id(&apdu[len], &object, &rpdata->object_instance);
    rpdata->object_type = (BACNET_OBJECT_TYPE) object;
    /* Tag 1: Property ID */
    len +=
        decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
    if (tag_number != 1)
        return -1;
    len += decode_enumerated(&apdu[len], len_value_type, &property);
    rpdata->object_property = (BACNET_PROPERTY_ID) property;
    /* Tag 2: Optional Array Index */
    tag_len =
        decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
    if (tag_number == 2) {
        len += tag_len;
        len += decode_unsigned(&apdu[len], len_value_type, &array_value);
        rpdata->array_index = array_value;
    } else
        rpdata->array_index = BACNET_ARRAY_ALL;
    /* Tag 3: opening context tag */
    if (decode_is_opening_tag_number(&apdu[len], 3)) {
        /* a tag number of 3 is not extended so only one octet */
        len++;
        /* don't decode the application tag number or its data here */
        rpdata->application_data = &apdu[len];
        rpdata->application_data_len = apdu_len - len - 1 /*closing tag */ ;
        /* len includes the data and the closing tag */
        len = apdu_len;
    } else {
        return -1;
    }

    return len;
}
/** Decode the ReadProperty reply and store the result for one Property in a
 *  BACNET_READ_PROPERTY_DATA structure.
 *  This leaves the value(s) in the application_data buffer to be decoded later;
 *  the application_data field points into the apdu buffer (is not allocated).
 *
 * @param apdu [in] The apdu portion of the ACK reply.
 * @param apdu_len [in] The total length of the apdu.
 * @param rpdata [out] The structure holding the partially decoded result.
 * @return Number of decoded bytes (could be less than apdu_len),
 * 			or -1 on decoding error.
 */
Decode the ReadProperty reply and store the result for one Property in a
BACNET_READ_PROPERTY_DATA structure.
This leaves the value(s) in the application_data buffer to be decoded later;
the application_data field points into the apdu buffer (is not allocated).

@param apdu [in] The apdu portion of the ACK reply.
@param apdu_len [in] The total length of the apdu.
@param rpdata [out] The structure holding the partially decoded result.
@return Number of decoded bytes (could be less than apdu_len),
or -1 on decoding error.
Decode the ReadProperty reply and store the result for one Property in a BACNET_READ_PROPERTY_DATA structure . This leaves the value ( s ) in the application_data buffer to be decoded later ; the application_data field points into the apdu buffer ( is not allocated ) . @param apdu [ in ] The apdu portion of the ACK reply . @param apdu_len [ in ] The total length of the apdu . @param rpdata [ out ] The structure holding the partially decoded result . @return Number of decoded bytes ( could be less than apdu_len ) or - 1 on decoding error .
int rp_ack_decode_service_request(
    uint8_t * apdu,
    int apdu_len,       
    BACNET_READ_PROPERTY_DATA * rpdata)
{
    uint8_t tag_number = 0;
    uint32_t len_value_type = 0;
    int tag_len = 0;    
    int len = 0;        
    uint16_t object = 0;        
    uint32_t property = 0;      
    uint32_t array_value = 0;   
    if (!decode_is_context_tag(&apdu[0], 0))
        return -1;
    len = 1;
    len += decode_object_id(&apdu[len], &object, &rpdata->object_instance);
    rpdata->object_type = (BACNET_OBJECT_TYPE) object;
    len +=
        decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
    if (tag_number != 1)
        return -1;
    len += decode_enumerated(&apdu[len], len_value_type, &property);
    rpdata->object_property = (BACNET_PROPERTY_ID) property;
    tag_len =
        decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
    if (tag_number == 2) {
        len += tag_len;
        len += decode_unsigned(&apdu[len], len_value_type, &array_value);
        rpdata->array_index = array_value;
    } else
        rpdata->array_index = BACNET_ARRAY_ALL;
    if (decode_is_opening_tag_number(&apdu[len], 3)) {
        len++;
        rpdata->application_data = &apdu[len];
        rpdata->application_data_len = apdu_len - len - 1  ;
        len = apdu_len;
    } else {
        return -1;
    }
    return len;
}
int rp_ack_decode_service_request ( uint8_t * apdu , int apdu_len , BACNET_READ_PROPERTY_DATA * rpdata ) { uint8_t tag_number = 0 ; uint32_t len_value_type = 0 ; int tag_len = 0 ; int len = 0 ; uint16_t object = 0 ; uint32_t property = 0 ; uint32_t array_value = 0 ; if ( ! decode_is_context_tag ( & apdu [ 0 ] , 0 ) ) return -1 ; len = 1 ; len += decode_object_id ( & apdu [ len ] , & object , & rpdata -> object_instance ) ; rpdata -> object_type = ( BACNET_OBJECT_TYPE ) object ; len += decode_tag_number_and_value ( & apdu [ len ] , & tag_number , & len_value_type ) ; if ( tag_number != 1 ) return -1 ; len += decode_enumerated ( & apdu [ len ] , len_value_type , & property ) ; rpdata -> object_property = ( BACNET_PROPERTY_ID ) property ; tag_len = decode_tag_number_and_value ( & apdu [ len ] , & tag_number , & len_value_type ) ; if ( tag_number == 2 ) { len += tag_len ; len += decode_unsigned ( & apdu [ len ] , len_value_type , & array_value ) ; rpdata -> array_index = array_value ; } else rpdata -> array_index = BACNET_ARRAY_ALL ; if ( decode_is_opening_tag_number ( & apdu [ len ] , 3 ) ) { len ++ ; rpdata -> application_data = & apdu [ len ] ; rpdata -> application_data_len = apdu_len - len - 1 ; len = apdu_len ; } else { return -1 ; } return len ; }
Decode the ReadProperty reply and store the result for one Property in a
  BACNET_READ_PROPERTY_DATA structure.
Decode the ReadProperty reply and store the result for one Property in a BACNET_READ_PROPERTY_DATA structure .
/* total length of the apdu */ /* length of tag decode */ /* total length of decodes */ /* object type */ /* for decoding */ /* for decoding */ /* FIXME: check apdu_len against the len during decode   */ /* Tag 0: Object ID */ /* Tag 1: Property ID */ /* Tag 2: Optional Array Index */ /* Tag 3: opening context tag */ /* a tag number of 3 is not extended so only one octet */ /* don't decode the application tag number or its data here */ /*closing tag */ /* len includes the data and the closing tag */