AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/src/bacapp.c
bool bacapp_parse_application_data(
    BACNET_APPLICATION_TAG tag_number,
    const char *argv,
    BACNET_APPLICATION_DATA_VALUE * value)
{
    int hour, min, sec, hundredths;
    int year, month, day, wday;
    int object_type = 0;
    uint32_t instance = 0;
    bool status = false;
    long long_value = 0;
    unsigned long unsigned_long_value = 0;
    double double_value = 0.0;
    int count = 0;

    if (value && (tag_number < MAX_BACNET_APPLICATION_TAG)) {
        status = true;
        value->tag = tag_number;
        switch (tag_number) {
            case BACNET_APPLICATION_TAG_BOOLEAN:
                long_value = strtol(argv, NULL, 0);
                if (long_value)
                    value->type.Boolean = true;
                else
                    value->type.Boolean = false;
                break;
            case BACNET_APPLICATION_TAG_UNSIGNED_INT:
                unsigned_long_value = strtoul(argv, NULL, 0);
                value->type.Unsigned_Int = unsigned_long_value;
                break;
            case BACNET_APPLICATION_TAG_SIGNED_INT:
                long_value = strtol(argv, NULL, 0);
                value->type.Signed_Int = long_value;
                break;
            case BACNET_APPLICATION_TAG_REAL:
                double_value = strtod(argv, NULL);
                value->type.Real = (float) double_value;
                break;
#if defined (BACAPP_DOUBLE)
            case BACNET_APPLICATION_TAG_DOUBLE:
                double_value = strtod(argv, NULL);
                value->type.Double = double_value;
                break;
#endif
            case BACNET_APPLICATION_TAG_OCTET_STRING:
#if PRINT_ENABLED       /* Apparently ain't necessarily so. */
                status =
                    octetstring_init_ascii_hex(&value->type.Octet_String,
                    argv);
#endif
                break;
            case BACNET_APPLICATION_TAG_CHARACTER_STRING:
                status =
                    characterstring_init_ansi(&value->type.Character_String,
                    (char *) argv);
                break;
            case BACNET_APPLICATION_TAG_BIT_STRING:
#if PRINT_ENABLED
                status = bitstring_init_ascii(&value->type.Bit_String, argv);
#endif
                break;
            case BACNET_APPLICATION_TAG_ENUMERATED:
                unsigned_long_value = strtoul(argv, NULL, 0);
                value->type.Enumerated = unsigned_long_value;
                break;
            case BACNET_APPLICATION_TAG_DATE:
                count =
                    sscanf(argv, "%4d/%3d/%3d:%3d", &year, &month, &day,
                    &wday);
                if (count == 3) {
                    datetime_set_date(&value->type.Date, (uint16_t) year,
                        (uint8_t) month, (uint8_t) day);
                } else if (count == 4) {
                    value->type.Date.year = (uint16_t) year;
                    value->type.Date.month = (uint8_t) month;
                    value->type.Date.day = (uint8_t) day;
                    value->type.Date.wday = (uint8_t) wday;
                } else {
                    status = false;
                }
                break;
            case BACNET_APPLICATION_TAG_TIME:
                count =
                    sscanf(argv, "%3d:%3d:%3d.%3d", &hour, &min, &sec,
                    &hundredths);
                if (count == 4) {
                    value->type.Time.hour = (uint8_t) hour;
                    value->type.Time.min = (uint8_t) min;
                    value->type.Time.sec = (uint8_t) sec;
                    value->type.Time.hundredths = (uint8_t) hundredths;
                } else if (count == 3) {
                    value->type.Time.hour = (uint8_t) hour;
                    value->type.Time.min = (uint8_t) min;
                    value->type.Time.sec = (uint8_t) sec;
                    value->type.Time.hundredths = 0;
                } else if (count == 2) {
                    value->type.Time.hour = (uint8_t) hour;
                    value->type.Time.min = (uint8_t) min;
                    value->type.Time.sec = 0;
                    value->type.Time.hundredths = 0;
                } else {
                    status = false;
                }
                break;
            case BACNET_APPLICATION_TAG_OBJECT_ID:
                count = sscanf(argv, "%4d:%7d", &object_type, &instance);
                if (count == 2) {
                    value->type.Object_Id.type = (uint16_t) object_type;
                    value->type.Object_Id.instance = instance;
                } else {
                    status = false;
                }
                break;
            case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
                /* FIXME: add parsing for lighting command */
                break;
            default:
                break;
        }
        value->next = NULL;
    }

    return status;
}
/* used to load the app data struct with the proper data
   converted from a command line argument */
used to load the app data struct with the proper data
converted from a command line argument
used to load the app data struct with the proper data converted from a command line argument
bool bacapp_parse_application_data(
    BACNET_APPLICATION_TAG tag_number,
    const char *argv,
    BACNET_APPLICATION_DATA_VALUE * value)
{
    int hour, min, sec, hundredths;
    int year, month, day, wday;
    int object_type = 0;
    uint32_t instance = 0;
    bool status = false;
    long long_value = 0;
    unsigned long unsigned_long_value = 0;
    double double_value = 0.0;
    int count = 0;
    if (value && (tag_number < MAX_BACNET_APPLICATION_TAG)) {
        status = true;
        value->tag = tag_number;
        switch (tag_number) {
            case BACNET_APPLICATION_TAG_BOOLEAN:
                long_value = strtol(argv, NULL, 0);
                if (long_value)
                    value->type.Boolean = true;
                else
                    value->type.Boolean = false;
                break;
            case BACNET_APPLICATION_TAG_UNSIGNED_INT:
                unsigned_long_value = strtoul(argv, NULL, 0);
                value->type.Unsigned_Int = unsigned_long_value;
                break;
            case BACNET_APPLICATION_TAG_SIGNED_INT:
                long_value = strtol(argv, NULL, 0);
                value->type.Signed_Int = long_value;
                break;
            case BACNET_APPLICATION_TAG_REAL:
                double_value = strtod(argv, NULL);
                value->type.Real = (float) double_value;
                break;
#if defined (BACAPP_DOUBLE)
            case BACNET_APPLICATION_TAG_DOUBLE:
                double_value = strtod(argv, NULL);
                value->type.Double = double_value;
                break;
#endif
            case BACNET_APPLICATION_TAG_OCTET_STRING:
#if PRINT_ENABLED       
                status =
                    octetstring_init_ascii_hex(&value->type.Octet_String,
                    argv);
#endif
                break;
            case BACNET_APPLICATION_TAG_CHARACTER_STRING:
                status =
                    characterstring_init_ansi(&value->type.Character_String,
                    (char *) argv);
                break;
            case BACNET_APPLICATION_TAG_BIT_STRING:
#if PRINT_ENABLED
                status = bitstring_init_ascii(&value->type.Bit_String, argv);
#endif
                break;
            case BACNET_APPLICATION_TAG_ENUMERATED:
                unsigned_long_value = strtoul(argv, NULL, 0);
                value->type.Enumerated = unsigned_long_value;
                break;
            case BACNET_APPLICATION_TAG_DATE:
                count =
                    sscanf(argv, "%4d/%3d/%3d:%3d", &year, &month, &day,
                    &wday);
                if (count == 3) {
                    datetime_set_date(&value->type.Date, (uint16_t) year,
                        (uint8_t) month, (uint8_t) day);
                } else if (count == 4) {
                    value->type.Date.year = (uint16_t) year;
                    value->type.Date.month = (uint8_t) month;
                    value->type.Date.day = (uint8_t) day;
                    value->type.Date.wday = (uint8_t) wday;
                } else {
                    status = false;
                }
                break;
            case BACNET_APPLICATION_TAG_TIME:
                count =
                    sscanf(argv, "%3d:%3d:%3d.%3d", &hour, &min, &sec,
                    &hundredths);
                if (count == 4) {
                    value->type.Time.hour = (uint8_t) hour;
                    value->type.Time.min = (uint8_t) min;
                    value->type.Time.sec = (uint8_t) sec;
                    value->type.Time.hundredths = (uint8_t) hundredths;
                } else if (count == 3) {
                    value->type.Time.hour = (uint8_t) hour;
                    value->type.Time.min = (uint8_t) min;
                    value->type.Time.sec = (uint8_t) sec;
                    value->type.Time.hundredths = 0;
                } else if (count == 2) {
                    value->type.Time.hour = (uint8_t) hour;
                    value->type.Time.min = (uint8_t) min;
                    value->type.Time.sec = 0;
                    value->type.Time.hundredths = 0;
                } else {
                    status = false;
                }
                break;
            case BACNET_APPLICATION_TAG_OBJECT_ID:
                count = sscanf(argv, "%4d:%7d", &object_type, &instance);
                if (count == 2) {
                    value->type.Object_Id.type = (uint16_t) object_type;
                    value->type.Object_Id.instance = instance;
                } else {
                    status = false;
                }
                break;
            case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
                break;
            default:
                break;
        }
        value->next = NULL;
    }
    return status;
}
bool bacapp_parse_application_data ( BACNET_APPLICATION_TAG tag_number , const char * argv , BACNET_APPLICATION_DATA_VALUE * value ) { int hour , min , sec , hundredths ; int year , month , day , wday ; int object_type = 0 ; uint32_t instance = 0 ; bool status = false ; long long_value = 0 ; unsigned long unsigned_long_value = 0 ; double double_value = 0.0 ; int count = 0 ; if ( value && ( tag_number < MAX_BACNET_APPLICATION_TAG ) ) { status = true ; value -> tag = tag_number ; switch ( tag_number ) { case BACNET_APPLICATION_TAG_BOOLEAN : long_value = strtol ( argv , NULL , 0 ) ; if ( long_value ) value -> type . Boolean = true ; else value -> type . Boolean = false ; break ; case BACNET_APPLICATION_TAG_UNSIGNED_INT : unsigned_long_value = strtoul ( argv , NULL , 0 ) ; value -> type . Unsigned_Int = unsigned_long_value ; break ; case BACNET_APPLICATION_TAG_SIGNED_INT : long_value = strtol ( argv , NULL , 0 ) ; value -> type . Signed_Int = long_value ; break ; case BACNET_APPLICATION_TAG_REAL : double_value = strtod ( argv , NULL ) ; value -> type . Real = ( float ) double_value ; break ; #if defined ( BACAPP_DOUBLE ) case BACNET_APPLICATION_TAG_DOUBLE : double_value = strtod ( argv , NULL ) ; value -> type . Double = double_value ; break ; #endif case BACNET_APPLICATION_TAG_OCTET_STRING : #if PRINT_ENABLED status = octetstring_init_ascii_hex ( & value -> type . Octet_String , argv ) ; #endif break ; case BACNET_APPLICATION_TAG_CHARACTER_STRING : status = characterstring_init_ansi ( & value -> type . Character_String , ( char * ) argv ) ; break ; case BACNET_APPLICATION_TAG_BIT_STRING : #if PRINT_ENABLED status = bitstring_init_ascii ( & value -> type . Bit_String , argv ) ; #endif break ; case BACNET_APPLICATION_TAG_ENUMERATED : unsigned_long_value = strtoul ( argv , NULL , 0 ) ; value -> type . Enumerated = unsigned_long_value ; break ; case BACNET_APPLICATION_TAG_DATE : count = sscanf ( argv , " " , & year , & month , & day , & wday ) ; if ( count == 3 ) { datetime_set_date ( & value -> type . Date , ( uint16_t ) year , ( uint8_t ) month , ( uint8_t ) day ) ; } else if ( count == 4 ) { value -> type . Date . year = ( uint16_t ) year ; value -> type . Date . month = ( uint8_t ) month ; value -> type . Date . day = ( uint8_t ) day ; value -> type . Date . wday = ( uint8_t ) wday ; } else { status = false ; } break ; case BACNET_APPLICATION_TAG_TIME : count = sscanf ( argv , " " , & hour , & min , & sec , & hundredths ) ; if ( count == 4 ) { value -> type . Time . hour = ( uint8_t ) hour ; value -> type . Time . min = ( uint8_t ) min ; value -> type . Time . sec = ( uint8_t ) sec ; value -> type . Time . hundredths = ( uint8_t ) hundredths ; } else if ( count == 3 ) { value -> type . Time . hour = ( uint8_t ) hour ; value -> type . Time . min = ( uint8_t ) min ; value -> type . Time . sec = ( uint8_t ) sec ; value -> type . Time . hundredths = 0 ; } else if ( count == 2 ) { value -> type . Time . hour = ( uint8_t ) hour ; value -> type . Time . min = ( uint8_t ) min ; value -> type . Time . sec = 0 ; value -> type . Time . hundredths = 0 ; } else { status = false ; } break ; case BACNET_APPLICATION_TAG_OBJECT_ID : count = sscanf ( argv , " " , & object_type , & instance ) ; if ( count == 2 ) { value -> type . Object_Id . type = ( uint16_t ) object_type ; value -> type . Object_Id . instance = instance ; } else { status = false ; } break ; case BACNET_APPLICATION_TAG_LIGHTING_COMMAND : break ; default : break ; } value -> next = NULL ; } return status ; }
used to load the app data struct with the proper data
converted from a command line argument
used to load the app data struct with the proper data converted from a command line argument
/* Apparently ain't necessarily so. */ /* FIXME: add parsing for lighting command */