AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/demo/epics/main.c
bool PrettyPrintPropertyValue(
    FILE * stream,
    BACNET_OBJECT_PROPERTY_VALUE * object_value)
{
    BACNET_APPLICATION_DATA_VALUE *value = NULL;
    bool status = true; /*return value */
    size_t len = 0, i = 0, j = 0;
    BACNET_PROPERTY_ID property = PROP_ALL;
    char short_month[4];

    value = object_value->value;
    property = object_value->object_property;
    if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_BIT_STRING) &&
        ((property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) ||
            (property == PROP_PROTOCOL_SERVICES_SUPPORTED))) {
        len = bitstring_bits_used(&value->type.Bit_String);
        fprintf(stream, "( \n        ");
        for (i = 0; i < len; i++) {
            fprintf(stream, "%s", bitstring_bit(&value->type.Bit_String,
                    (uint8_t) i) ? "T" : "F");
            if (i < len - 1)
                fprintf(stream, ",");
            else
                fprintf(stream, " ");
            /* Tried with 8 per line, but with the comments, got way too long. */
            if ((i == (len - 1)) || ((i % 4) == 3)) {   /* line break every 4 */
                fprintf(stream, "   -- ");      /* EPICS comments begin with "--" */
                /* Now rerun the same 4 bits, but print labels for true ones */
                for (j = i - (i % 4); j <= i; j++) {
                    if (bitstring_bit(&value->type.Bit_String, (uint8_t) j)) {
                        if (property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) {
                            fprintf(stream, " %s,",
                                bactext_object_type_name(j));
                        } else {
                            /* PROP_PROTOCOL_SERVICES_SUPPORTED */
                            fprintf(stream, " %s,",
                                protocol_services_supported_text(j));
                        }
                    } else      /* not supported */
                        fprintf(stream, ",");
                }
                fprintf(stream, "\n        ");
            }
        }
        fprintf(stream, ") \n");
    } else if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_DATE)) {
        /* eg, property == PROP_LOCAL_DATE
         * VTS needs (3-Aug-2011,4) or (8/3/11,4), so we'll use the
         * clearer, international form. */
        strncpy(short_month, bactext_month_name(value->type.Date.month), 3);
        short_month[3] = 0;
        fprintf(stream, "(%u-%3s-%u, %u)", (unsigned) value->type.Date.day,
            short_month, (unsigned) value->type.Date.year,
            (unsigned) value->type.Date.wday);
    } else if (value != NULL) {
        assert(false);  /* How did I get here?  Fix your code. */
        /* Meanwhile, a fallback plan */
        status = bacapp_print_value(stdout, object_value);
    } else
        fprintf(stream, "? \n");

    return status;
}
/** Provide a nicer output for Supported Services and Object Types bitfields
 * and Date fields.
 * We have to override the library's normal bitfield print because the
 * EPICS format wants just T and F, and we want to provide (as comments)
 * the names of the active types.
 * These bitfields use opening and closing parentheses instead of braces.
 * We also limit the output to 4 bit fields per line.
 *
 * @param stream [in] Normally stdout
 * @param object_value [in] The structure holding this property's description
 *                          and value.
 * @return True if success.  Or otherwise.
 */
Provide a nicer output for Supported Services and Object Types bitfields
and Date fields.
We have to override the library's normal bitfield print because the
EPICS format wants just T and F, and we want to provide (as comments)
the names of the active types.
These bitfields use opening and closing parentheses instead of braces.
We also limit the output to 4 bit fields per line.

@param stream [in] Normally stdout
@param object_value [in] The structure holding this property's description
and value.
@return True if success.  Or otherwise.
Provide a nicer output for Supported Services and Object Types bitfields and Date fields . We have to override the library ' s normal bitfield print because the EPICS format wants just T and F and we want to provide ( as comments ) the names of the active types . These bitfields use opening and closing parentheses instead of braces . We also limit the output to 4 bit fields per line . @param stream [ in ] Normally stdout @param object_value [ in ] The structure holding this property ' s description and value . @return True if success . Or otherwise .
bool PrettyPrintPropertyValue(
    FILE * stream,
    BACNET_OBJECT_PROPERTY_VALUE * object_value)
{
    BACNET_APPLICATION_DATA_VALUE *value = NULL;
    bool status = true; 
    size_t len = 0, i = 0, j = 0;
    BACNET_PROPERTY_ID property = PROP_ALL;
    char short_month[4];
    value = object_value->value;
    property = object_value->object_property;
    if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_BIT_STRING) &&
        ((property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) ||
            (property == PROP_PROTOCOL_SERVICES_SUPPORTED))) {
        len = bitstring_bits_used(&value->type.Bit_String);
        fprintf(stream, "( \n        ");
        for (i = 0; i < len; i++) {
            fprintf(stream, "%s", bitstring_bit(&value->type.Bit_String,
                    (uint8_t) i) ? "T" : "F");
            if (i < len - 1)
                fprintf(stream, ",");
            else
                fprintf(stream, " ");
            if ((i == (len - 1)) || ((i % 4) == 3)) {   
                fprintf(stream, "   -- ");      
                for (j = i - (i % 4); j <= i; j++) {
                    if (bitstring_bit(&value->type.Bit_String, (uint8_t) j)) {
                        if (property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) {
                            fprintf(stream, " %s,",
                                bactext_object_type_name(j));
                        } else {
                            fprintf(stream, " %s,",
                                protocol_services_supported_text(j));
                        }
                    } else      
                        fprintf(stream, ",");
                }
                fprintf(stream, "\n        ");
            }
        }
        fprintf(stream, ") \n");
    } else if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_DATE)) {
        strncpy(short_month, bactext_month_name(value->type.Date.month), 3);
        short_month[3] = 0;
        fprintf(stream, "(%u-%3s-%u, %u)", (unsigned) value->type.Date.day,
            short_month, (unsigned) value->type.Date.year,
            (unsigned) value->type.Date.wday);
    } else if (value != NULL) {
        assert(false);  
        status = bacapp_print_value(stdout, object_value);
    } else
        fprintf(stream, "? \n");
    return status;
}
bool PrettyPrintPropertyValue ( FILE * stream , BACNET_OBJECT_PROPERTY_VALUE * object_value ) { BACNET_APPLICATION_DATA_VALUE * value = NULL ; bool status = true ; size_t len = 0 , i = 0 , j = 0 ; BACNET_PROPERTY_ID property = PROP_ALL ; char short_month [ 4 ] ; value = object_value -> value ; property = object_value -> object_property ; if ( ( value != NULL ) && ( value -> tag == BACNET_APPLICATION_TAG_BIT_STRING ) && ( ( property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED ) || ( property == PROP_PROTOCOL_SERVICES_SUPPORTED ) ) ) { len = bitstring_bits_used ( & value -> type . Bit_String ) ; fprintf ( stream , " \n " ) ; for ( i = 0 ; i < len ; i ++ ) { fprintf ( stream , " " , bitstring_bit ( & value -> type . Bit_String , ( uint8_t ) i ) ? " " : " " ) ; if ( i < len - 1 ) fprintf ( stream , " " ) ; else fprintf ( stream , " " ) ; if ( ( i == ( len - 1 ) ) || ( ( i % 4 ) == 3 ) ) { fprintf ( stream , " " ) ; for ( j = i - ( i % 4 ) ; j <= i ; j ++ ) { if ( bitstring_bit ( & value -> type . Bit_String , ( uint8_t ) j ) ) { if ( property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED ) { fprintf ( stream , " " , bactext_object_type_name ( j ) ) ; } else { fprintf ( stream , " " , protocol_services_supported_text ( j ) ) ; } } else fprintf ( stream , " " ) ; } fprintf ( stream , " \n " ) ; } } fprintf ( stream , " \n " ) ; } else if ( ( value != NULL ) && ( value -> tag == BACNET_APPLICATION_TAG_DATE ) ) { strncpy ( short_month , bactext_month_name ( value -> type . Date . month ) , 3 ) ; short_month [ 3 ] = 0 ; fprintf ( stream , " " , ( unsigned ) value -> type . Date . day , short_month , ( unsigned ) value -> type . Date . year , ( unsigned ) value -> type . Date . wday ) ; } else if ( value != NULL ) { assert ( false ) ; status = bacapp_print_value ( stdout , object_value ) ; } else fprintf ( stream , " \n " ) ; return status ; }
Provide a nicer output for Supported Services and Object Types bitfields
 and Date fields.
Provide a nicer output for Supported Services and Object Types bitfields and Date fields .
/*return value */ /* Tried with 8 per line, but with the comments, got way too long. */ /* line break every 4 */ /* EPICS comments begin with "--" */ /* Now rerun the same 4 bits, but print labels for true ones */ /* PROP_PROTOCOL_SERVICES_SUPPORTED */ /* not supported */ /* eg, property == PROP_LOCAL_DATE
         * VTS needs (3-Aug-2011,4) or (8/3/11,4), so we'll use the
         * clearer, international form. */ /* How did I get here?  Fix your code. */ /* Meanwhile, a fallback plan */