AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/src/bacapp.c
int bacapp_decode_data(
    uint8_t * apdu,
    uint8_t tag_data_type,
    uint32_t len_value_type,
    BACNET_APPLICATION_DATA_VALUE * value)
{
    int len = 0;

    if (apdu && value) {
        switch (tag_data_type) {
#if defined (BACAPP_NULL)
            case BACNET_APPLICATION_TAG_NULL:
                /* nothing else to do */
                break;
#endif
#if defined (BACAPP_BOOLEAN)
            case BACNET_APPLICATION_TAG_BOOLEAN:
                value->type.Boolean = decode_boolean(len_value_type);
                break;
#endif
#if defined (BACAPP_UNSIGNED)
            case BACNET_APPLICATION_TAG_UNSIGNED_INT:
                len =
                    decode_unsigned(&apdu[0], len_value_type,
                    &value->type.Unsigned_Int);
                break;
#endif
#if defined (BACAPP_SIGNED)
            case BACNET_APPLICATION_TAG_SIGNED_INT:
                len =
                    decode_signed(&apdu[0], len_value_type,
                    &value->type.Signed_Int);
                break;
#endif
#if defined (BACAPP_REAL)
            case BACNET_APPLICATION_TAG_REAL:
                len =
                    decode_real_safe(&apdu[0], len_value_type,
                    &(value->type.Real));
                break;
#endif
#if defined (BACAPP_DOUBLE)
            case BACNET_APPLICATION_TAG_DOUBLE:
                len =
                    decode_double_safe(&apdu[0], len_value_type,
                    &(value->type.Double));
                break;
#endif
#if defined (BACAPP_OCTET_STRING)
            case BACNET_APPLICATION_TAG_OCTET_STRING:
                len =
                    decode_octet_string(&apdu[0], len_value_type,
                    &value->type.Octet_String);
                break;
#endif
#if defined (BACAPP_CHARACTER_STRING)
            case BACNET_APPLICATION_TAG_CHARACTER_STRING:
                len =
                    decode_character_string(&apdu[0], len_value_type,
                    &value->type.Character_String);
                break;
#endif
#if defined (BACAPP_BIT_STRING)
            case BACNET_APPLICATION_TAG_BIT_STRING:
                len =
                    decode_bitstring(&apdu[0], len_value_type,
                    &value->type.Bit_String);
                break;
#endif
#if defined (BACAPP_ENUMERATED)
            case BACNET_APPLICATION_TAG_ENUMERATED:
                len =
                    decode_enumerated(&apdu[0], len_value_type,
                    &value->type.Enumerated);
                break;
#endif
#if defined (BACAPP_DATE)
            case BACNET_APPLICATION_TAG_DATE:
                len =
                    decode_date_safe(&apdu[0], len_value_type,
                    &value->type.Date);
                break;
#endif
#if defined (BACAPP_TIME)
            case BACNET_APPLICATION_TAG_TIME:
                len =
                    decode_bacnet_time_safe(&apdu[0], len_value_type,
                    &value->type.Time);
                break;
#endif
#if defined (BACAPP_OBJECT_ID)
            case BACNET_APPLICATION_TAG_OBJECT_ID:
                {
                    uint16_t object_type = 0;
                    uint32_t instance = 0;
                    len =
                        decode_object_id_safe(&apdu[0], len_value_type,
                        &object_type, &instance);
                    value->type.Object_Id.type = object_type;
                    value->type.Object_Id.instance = instance;
                }
                break;
#endif
#if defined (BACAPP_LIGHTING_COMMAND)
            case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
                len =
                    lighting_command_decode(
                        &apdu[0], len_value_type,
                        &value->type.Lighting_Command);
                break;
#endif
            default:
                break;
        }
    }

    if ((len == 0) && (tag_data_type != BACNET_APPLICATION_TAG_NULL) &&
        (tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN) &&
        (tag_data_type != BACNET_APPLICATION_TAG_OCTET_STRING)) {
        /* indicate that we were not able to decode the value */
        value->tag = MAX_BACNET_APPLICATION_TAG;
    }
    return len;
}
/* decode the data and store it into value.
   Return the number of octets consumed. */
decode the data and store it into value.
Return the number of octets consumed.
decode the data and store it into value . Return the number of octets consumed .
int bacapp_decode_data(
    uint8_t * apdu,
    uint8_t tag_data_type,
    uint32_t len_value_type,
    BACNET_APPLICATION_DATA_VALUE * value)
{
    int len = 0;
    if (apdu && value) {
        switch (tag_data_type) {
#if defined (BACAPP_NULL)
            case BACNET_APPLICATION_TAG_NULL:
                break;
#endif
#if defined (BACAPP_BOOLEAN)
            case BACNET_APPLICATION_TAG_BOOLEAN:
                value->type.Boolean = decode_boolean(len_value_type);
                break;
#endif
#if defined (BACAPP_UNSIGNED)
            case BACNET_APPLICATION_TAG_UNSIGNED_INT:
                len =
                    decode_unsigned(&apdu[0], len_value_type,
                    &value->type.Unsigned_Int);
                break;
#endif
#if defined (BACAPP_SIGNED)
            case BACNET_APPLICATION_TAG_SIGNED_INT:
                len =
                    decode_signed(&apdu[0], len_value_type,
                    &value->type.Signed_Int);
                break;
#endif
#if defined (BACAPP_REAL)
            case BACNET_APPLICATION_TAG_REAL:
                len =
                    decode_real_safe(&apdu[0], len_value_type,
                    &(value->type.Real));
                break;
#endif
#if defined (BACAPP_DOUBLE)
            case BACNET_APPLICATION_TAG_DOUBLE:
                len =
                    decode_double_safe(&apdu[0], len_value_type,
                    &(value->type.Double));
                break;
#endif
#if defined (BACAPP_OCTET_STRING)
            case BACNET_APPLICATION_TAG_OCTET_STRING:
                len =
                    decode_octet_string(&apdu[0], len_value_type,
                    &value->type.Octet_String);
                break;
#endif
#if defined (BACAPP_CHARACTER_STRING)
            case BACNET_APPLICATION_TAG_CHARACTER_STRING:
                len =
                    decode_character_string(&apdu[0], len_value_type,
                    &value->type.Character_String);
                break;
#endif
#if defined (BACAPP_BIT_STRING)
            case BACNET_APPLICATION_TAG_BIT_STRING:
                len =
                    decode_bitstring(&apdu[0], len_value_type,
                    &value->type.Bit_String);
                break;
#endif
#if defined (BACAPP_ENUMERATED)
            case BACNET_APPLICATION_TAG_ENUMERATED:
                len =
                    decode_enumerated(&apdu[0], len_value_type,
                    &value->type.Enumerated);
                break;
#endif
#if defined (BACAPP_DATE)
            case BACNET_APPLICATION_TAG_DATE:
                len =
                    decode_date_safe(&apdu[0], len_value_type,
                    &value->type.Date);
                break;
#endif
#if defined (BACAPP_TIME)
            case BACNET_APPLICATION_TAG_TIME:
                len =
                    decode_bacnet_time_safe(&apdu[0], len_value_type,
                    &value->type.Time);
                break;
#endif
#if defined (BACAPP_OBJECT_ID)
            case BACNET_APPLICATION_TAG_OBJECT_ID:
                {
                    uint16_t object_type = 0;
                    uint32_t instance = 0;
                    len =
                        decode_object_id_safe(&apdu[0], len_value_type,
                        &object_type, &instance);
                    value->type.Object_Id.type = object_type;
                    value->type.Object_Id.instance = instance;
                }
                break;
#endif
#if defined (BACAPP_LIGHTING_COMMAND)
            case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
                len =
                    lighting_command_decode(
                        &apdu[0], len_value_type,
                        &value->type.Lighting_Command);
                break;
#endif
            default:
                break;
        }
    }
    if ((len == 0) && (tag_data_type != BACNET_APPLICATION_TAG_NULL) &&
        (tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN) &&
        (tag_data_type != BACNET_APPLICATION_TAG_OCTET_STRING)) {
        value->tag = MAX_BACNET_APPLICATION_TAG;
    }
    return len;
}
int bacapp_decode_data ( uint8_t * apdu , uint8_t tag_data_type , uint32_t len_value_type , BACNET_APPLICATION_DATA_VALUE * value ) { int len = 0 ; if ( apdu && value ) { switch ( tag_data_type ) { #if defined ( BACAPP_NULL ) case BACNET_APPLICATION_TAG_NULL : break ; #endif #if defined ( BACAPP_BOOLEAN ) case BACNET_APPLICATION_TAG_BOOLEAN : value -> type . Boolean = decode_boolean ( len_value_type ) ; break ; #endif #if defined ( BACAPP_UNSIGNED ) case BACNET_APPLICATION_TAG_UNSIGNED_INT : len = decode_unsigned ( & apdu [ 0 ] , len_value_type , & value -> type . Unsigned_Int ) ; break ; #endif #if defined ( BACAPP_SIGNED ) case BACNET_APPLICATION_TAG_SIGNED_INT : len = decode_signed ( & apdu [ 0 ] , len_value_type , & value -> type . Signed_Int ) ; break ; #endif #if defined ( BACAPP_REAL ) case BACNET_APPLICATION_TAG_REAL : len = decode_real_safe ( & apdu [ 0 ] , len_value_type , & ( value -> type . Real ) ) ; break ; #endif #if defined ( BACAPP_DOUBLE ) case BACNET_APPLICATION_TAG_DOUBLE : len = decode_double_safe ( & apdu [ 0 ] , len_value_type , & ( value -> type . Double ) ) ; break ; #endif #if defined ( BACAPP_OCTET_STRING ) case BACNET_APPLICATION_TAG_OCTET_STRING : len = decode_octet_string ( & apdu [ 0 ] , len_value_type , & value -> type . Octet_String ) ; break ; #endif #if defined ( BACAPP_CHARACTER_STRING ) case BACNET_APPLICATION_TAG_CHARACTER_STRING : len = decode_character_string ( & apdu [ 0 ] , len_value_type , & value -> type . Character_String ) ; break ; #endif #if defined ( BACAPP_BIT_STRING ) case BACNET_APPLICATION_TAG_BIT_STRING : len = decode_bitstring ( & apdu [ 0 ] , len_value_type , & value -> type . Bit_String ) ; break ; #endif #if defined ( BACAPP_ENUMERATED ) case BACNET_APPLICATION_TAG_ENUMERATED : len = decode_enumerated ( & apdu [ 0 ] , len_value_type , & value -> type . Enumerated ) ; break ; #endif #if defined ( BACAPP_DATE ) case BACNET_APPLICATION_TAG_DATE : len = decode_date_safe ( & apdu [ 0 ] , len_value_type , & value -> type . Date ) ; break ; #endif #if defined ( BACAPP_TIME ) case BACNET_APPLICATION_TAG_TIME : len = decode_bacnet_time_safe ( & apdu [ 0 ] , len_value_type , & value -> type . Time ) ; break ; #endif #if defined ( BACAPP_OBJECT_ID ) case BACNET_APPLICATION_TAG_OBJECT_ID : { uint16_t object_type = 0 ; uint32_t instance = 0 ; len = decode_object_id_safe ( & apdu [ 0 ] , len_value_type , & object_type , & instance ) ; value -> type . Object_Id . type = object_type ; value -> type . Object_Id . instance = instance ; } break ; #endif #if defined ( BACAPP_LIGHTING_COMMAND ) case BACNET_APPLICATION_TAG_LIGHTING_COMMAND : len = lighting_command_decode ( & apdu [ 0 ] , len_value_type , & value -> type . Lighting_Command ) ; break ; #endif default : break ; } } if ( ( len == 0 ) && ( tag_data_type != BACNET_APPLICATION_TAG_NULL ) && ( tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN ) && ( tag_data_type != BACNET_APPLICATION_TAG_OCTET_STRING ) ) { value -> tag = MAX_BACNET_APPLICATION_TAG ; } return len ; }
decode the data and store it into value.
decode the data and store it into value .
/* nothing else to do */ /* indicate that we were not able to decode the value */