AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/src/bacapp.c
bool bacapp_decode_application_data_safe(
    uint8_t * new_apdu,
    uint32_t new_apdu_len,
    BACNET_APPLICATION_DATA_VALUE * value)
{
    /* The static variables that store the apdu buffer between function calls */
    static uint8_t *apdu = NULL;
    static uint32_t apdu_len_remaining = 0;
    static uint32_t apdu_len = 0;
    int len = 0;
    int tag_len = 0;
    uint8_t tag_number = 0;
    uint32_t len_value_type = 0;

    bool ret = false;

    if (new_apdu != NULL) {
        apdu = new_apdu;
        apdu_len_remaining = new_apdu_len;
        apdu_len = 0;
    }

    if (value && apdu_len_remaining > 0 &&
        !IS_CONTEXT_SPECIFIC(apdu[apdu_len])) {
        value->context_specific = false;
        tag_len =
            decode_tag_number_and_value_safe(&apdu[apdu_len],
            apdu_len_remaining, &tag_number, &len_value_type);
        /* If tag_len is zero, then the tag information is truncated */
        if (tag_len) {
            apdu_len += tag_len;
            apdu_len_remaining -= tag_len;
            /* The tag is boolean then len_value_type is interpreted as value, not length, so dont bother
             ** checking with apdu_len_remaining */
            if (tag_number == BACNET_APPLICATION_TAG_BOOLEAN ||
                len_value_type <= apdu_len_remaining) {
                value->tag = tag_number;
                len =
                    bacapp_decode_data(&apdu[apdu_len], tag_number,
                    len_value_type, value);
                apdu_len += len;
                apdu_len_remaining -= len;

                ret = true;
            }
        }
        value->next = NULL;
    }


    return ret;
}
/*
** Usage: Similar to strtok. Call function the first time with new_apdu and new_adu_len set to apdu buffer
** to be processed. Subsequent calls should pass in NULL.
**
** Returns true if a application message is correctly parsed.
** Returns false if no more application messages are available.
**
** This function is NOT thread safe.
**
** Notes: The _safe suffix is there because the function should be relatively safe against buffer overruns.
**
*/
Similar to strtok. Call function the first time with new_apdu and new_adu_len set to apdu buffer
to be processed. Subsequent calls should pass in NULL.

Returns true if a application message is correctly parsed.
Returns false if no more application messages are available.

This function is NOT thread safe.

The _safe suffix is there because the function should be relatively safe against buffer overruns.
Similar to strtok . Call function the first time with new_apdu and new_adu_len set to apdu buffer to be processed . Subsequent calls should pass in NULL . Returns true if a application message is correctly parsed . Returns false if no more application messages are available . This function is NOT thread safe . The _safe suffix is there because the function should be relatively safe against buffer overruns .
bool bacapp_decode_application_data_safe(
    uint8_t * new_apdu,
    uint32_t new_apdu_len,
    BACNET_APPLICATION_DATA_VALUE * value)
{
    static uint8_t *apdu = NULL;
    static uint32_t apdu_len_remaining = 0;
    static uint32_t apdu_len = 0;
    int len = 0;
    int tag_len = 0;
    uint8_t tag_number = 0;
    uint32_t len_value_type = 0;
    bool ret = false;
    if (new_apdu != NULL) {
        apdu = new_apdu;
        apdu_len_remaining = new_apdu_len;
        apdu_len = 0;
    }
    if (value && apdu_len_remaining > 0 &&
        !IS_CONTEXT_SPECIFIC(apdu[apdu_len])) {
        value->context_specific = false;
        tag_len =
            decode_tag_number_and_value_safe(&apdu[apdu_len],
            apdu_len_remaining, &tag_number, &len_value_type);
        if (tag_len) {
            apdu_len += tag_len;
            apdu_len_remaining -= tag_len;
            if (tag_number == BACNET_APPLICATION_TAG_BOOLEAN ||
                len_value_type <= apdu_len_remaining) {
                value->tag = tag_number;
                len =
                    bacapp_decode_data(&apdu[apdu_len], tag_number,
                    len_value_type, value);
                apdu_len += len;
                apdu_len_remaining -= len;
                ret = true;
            }
        }
        value->next = NULL;
    }
    return ret;
}
bool bacapp_decode_application_data_safe ( uint8_t * new_apdu , uint32_t new_apdu_len , BACNET_APPLICATION_DATA_VALUE * value ) { static uint8_t * apdu = NULL ; static uint32_t apdu_len_remaining = 0 ; static uint32_t apdu_len = 0 ; int len = 0 ; int tag_len = 0 ; uint8_t tag_number = 0 ; uint32_t len_value_type = 0 ; bool ret = false ; if ( new_apdu != NULL ) { apdu = new_apdu ; apdu_len_remaining = new_apdu_len ; apdu_len = 0 ; } if ( value && apdu_len_remaining > 0 && ! IS_CONTEXT_SPECIFIC ( apdu [ apdu_len ] ) ) { value -> context_specific = false ; tag_len = decode_tag_number_and_value_safe ( & apdu [ apdu_len ] , apdu_len_remaining , & tag_number , & len_value_type ) ; if ( tag_len ) { apdu_len += tag_len ; apdu_len_remaining -= tag_len ; if ( tag_number == BACNET_APPLICATION_TAG_BOOLEAN || len_value_type <= apdu_len_remaining ) { value -> tag = tag_number ; len = bacapp_decode_data ( & apdu [ apdu_len ] , tag_number , len_value_type , value ) ; apdu_len += len ; apdu_len_remaining -= len ; ret = true ; } } value -> next = NULL ; } return ret ; }
Usage: Similar to strtok.
Usage : Similar to strtok .
/* The static variables that store the apdu buffer between function calls */ /* If tag_len is zero, then the tag information is truncated */ /* The tag is boolean then len_value_type is interpreted as value, not length, so dont bother
             ** checking with apdu_len_remaining */