AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/demo/epics/main.c
void PrintReadPropertyData(
    BACNET_OBJECT_TYPE object_type,
    uint32_t object_instance,
    BACNET_PROPERTY_REFERENCE * rpm_property)
{
    BACNET_OBJECT_PROPERTY_VALUE object_value;  /* for bacapp printing */
    BACNET_APPLICATION_DATA_VALUE *value, *old_value;
    bool print_brace = false;
    KEY object_list_element;
    bool isSequence = false;    /* Ie, will need bracketing braces {} */

    if (rpm_property == NULL) {
        fprintf(stdout, "    -- Null Property data \n");
        return;
    }
    value = rpm_property->value;
    if (value == NULL) {
        /* Then we print the error information */
        fprintf(stdout, "?  -- BACnet Error: %s: %s\n",
            bactext_error_class_name((int) rpm_property->error.error_class),
            bactext_error_code_name((int) rpm_property->error.error_code));
        return;
    }
    object_value.object_type = object_type;
    object_value.object_instance = object_instance;
    if ((value != NULL) && (value->next != NULL)) {
        /* Then this is an array of values.
         * But are we showing Values?  We (VTS3) want ? instead of {?,?} to show up. */
        switch (rpm_property->propertyIdentifier) {
                /* Screen the Properties that can be arrays or Sequences */
            case PROP_PRESENT_VALUE:
            case PROP_PRIORITY_ARRAY:
                if (!ShowValues) {
                    fprintf(stdout, "? \n");
                    /* We want the Values freed below, but don't want to
                     * print anything for them.  To achieve this, swap
                     * out the Property for a non-existent Property
                     * and catch that below.  */
                    rpm_property->propertyIdentifier =
                        PROP_PROTOCOL_CONFORMANCE_CLASS;
                    break;
                }
                if (object_type == OBJECT_DATETIME_VALUE)
                    break;      /* A special case - no braces for this pair */
                /* Else, fall through to normal processing. */
            default:
                /* Normal array: open brace */
                fprintf(stdout, "{ ");
                print_brace = true;     /* remember to close it */
                break;
        }
    }

    if (!Using_Walked_List)
        Walked_List_Index = Walked_List_Length = 0;     /* In case we need this. */
    /* value(s) loop until there is no "next" ... */
    while (value != NULL) {
        object_value.object_property = rpm_property->propertyIdentifier;
        object_value.array_index = rpm_property->propertyArrayIndex;
        object_value.value = value;
        switch (rpm_property->propertyIdentifier) {
                /* These are all arrays, so they open and close with braces */
            case PROP_OBJECT_LIST:
            case PROP_STATE_TEXT:
            case PROP_STRUCTURED_OBJECT_LIST:
            case PROP_SUBORDINATE_ANNOTATIONS:
            case PROP_SUBORDINATE_LIST:
                if (Using_Walked_List) {
                    if ((rpm_property->propertyArrayIndex == 0) &&
                        (value->tag == BACNET_APPLICATION_TAG_UNSIGNED_INT)) {
                        /* Grab the value of the Object List length - don't print it! */
                        Walked_List_Length = value->type.Unsigned_Int;
                        if (rpm_property->propertyIdentifier ==
                            PROP_OBJECT_LIST)
                            Object_List_Length = value->type.Unsigned_Int;
                        break;
                    } else
                        assert(Walked_List_Index == (uint32_t)
                            rpm_property->propertyArrayIndex);
                } else {
                    Walked_List_Index++;
                    /* If we got the whole Object List array in one RP call, keep
                     * the Index and List_Length in sync as we cycle through. */
                    if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST)
                        Object_List_Length = ++Object_List_Index;
                }
                if (Walked_List_Index == 1) {
                    /* If the array is empty (nothing for this first entry),
                     * Make it VTS3-friendly and don't show "Null" as a value. */
                    if (value->tag == BACNET_APPLICATION_TAG_NULL) {
                        fprintf(stdout, "?\n        ");
                        break;
                    }

                    /* Open this Array of Objects for the first entry (unless
                     * opening brace has already printed, since this is an array
                     * of values[] ) */
                    if (value->next == NULL)
                        fprintf(stdout, "{ \n        ");
                    else
                        fprintf(stdout, "\n        ");
                }

                if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) {
                    if (value->tag != BACNET_APPLICATION_TAG_OBJECT_ID) {
                        assert(value->tag == BACNET_APPLICATION_TAG_OBJECT_ID); /* Something not right here */
                        break;
                    }
                    /* Store the object list so we can interrogate
                       each object. */
                    object_list_element =
                        KEY_ENCODE(value->type.Object_Id.type,
                        value->type.Object_Id.instance);
                    /* We don't have anything to put in the data pointer
                     * yet, so just leave it null.  The key is Key here. */
                    Keylist_Data_Add(Object_List, object_list_element, NULL);
                } else if (rpm_property->propertyIdentifier == PROP_STATE_TEXT) {
                    /* Make sure it fits within 31 chars for original VTS3 limitation.
                     * If longer, take first 15 dash, and last 15 chars. */
                    if (value->type.Character_String.length > 31) {
                        int iLast15idx =
                            value->type.Character_String.length - 15;
                        value->type.Character_String.value[15] = '-';
                        memcpy(&value->type.Character_String.value[16],
                            &value->type.Character_String.value[iLast15idx],
                            15);
                        value->type.Character_String.value[31] = 0;
                        value->type.Character_String.length = 31;
                    }
                } else if (rpm_property->propertyIdentifier ==
                    PROP_SUBORDINATE_LIST) {
                    if (value->tag != BACNET_APPLICATION_TAG_OBJECT_ID) {
                        assert(value->tag == BACNET_APPLICATION_TAG_OBJECT_ID); /* Something not right here */
                        break;
                    }
                    /* TODO: handle Sequence of { Device ObjID, Object ID }, */
                    isSequence = true;
                }

                /* If the object is a Sequence, it needs its own bracketing braces */
                if (isSequence)
                    fprintf(stdout, "{");
                bacapp_print_value(stdout, &object_value);
                if (isSequence)
                    fprintf(stdout, "}");

                if ((Walked_List_Index < Walked_List_Length) ||
                    (value->next != NULL)) {
                    /* There are more. */
                    fprintf(stdout, ", ");
                    if (!(Walked_List_Index % 3))
                        fprintf(stdout, "\n        ");
                } else {
                    fprintf(stdout, " } \n");
                }
                break;

            case PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED:
            case PROP_PROTOCOL_SERVICES_SUPPORTED:
                PrettyPrintPropertyValue(stdout, &object_value);
                break;

                /* Our special non-existent case; do nothing further here. */
            case PROP_PROTOCOL_CONFORMANCE_CLASS:
                break;

            default:
                /* First, if this is a date type, it needs a different format
                 * for VTS, so pretty print it. */
                if (ShowValues &&
                    (object_value.value->tag == BACNET_APPLICATION_TAG_DATE)) {
                    /* This would be PROP_LOCAL_DATE, or OBJECT_DATETIME_VALUE,
                     * or OBJECT_DATE_VALUE                     */
                    PrettyPrintPropertyValue(stdout, &object_value);
                } else {
                    /* Some properties are presented just as '?' in an EPICS;
                     * screen these out here, unless ShowValues is true.  */
                    switch (rpm_property->propertyIdentifier) {
                        case PROP_DEVICE_ADDRESS_BINDING:
                            /* Make it VTS3-friendly and don't show "Null"
                             * as a value. */
                            if (value->tag == BACNET_APPLICATION_TAG_NULL) {
                                fprintf(stdout, "?");
                                break;
                            }
                            /* Else, fall through for normal processing. */
                        case PROP_DAYLIGHT_SAVINGS_STATUS:
                        case PROP_LOCAL_TIME:
                        case PROP_LOCAL_DATE:  /* Only if !ShowValues */
                        case PROP_PRESENT_VALUE:
                        case PROP_PRIORITY_ARRAY:
                        case PROP_RELIABILITY:
                        case PROP_UTC_OFFSET:
                        case PROP_DATABASE_REVISION:
                            if (!ShowValues) {
                                fprintf(stdout, "?");
                                break;
                            }
                            /* Else, fall through and print value: */
                        default:
                            bacapp_print_value(stdout, &object_value);
                            break;
                    }
                }
                if (value->next != NULL) {
                    /* there's more! */
                    fprintf(stdout, ",");
                } else {
                    if (print_brace) {
                        /* Closing brace for this multi-valued array */
                        fprintf(stdout, " }");
                    }
                    CheckIsWritableProperty(object_type,        /* object_instance, */
                        rpm_property);
                    fprintf(stdout, "\n");
                }
                break;
        }

        old_value = value;
        value = value->next;    /* next or NULL */
        free(old_value);
    }   /* End while loop */

}
/** Print out the value(s) for one Property.
 * This function may be called repeatedly for one property if we are walking
 * through a list (Using_Walked_List is True) to show just one value of the
 * array per call.
 *
 * @param object_type [in] The BACnet Object type of this object.
 * @param object_instance [in] The ID number for this object.
 * @param rpm_property [in] Points to structure holding the Property,
 *                          Value, and Error information.
 */
Print out the value(s) for one Property.
This function may be called repeatedly for one property if we are walking
through a list (Using_Walked_List is True) to show just one value of the
array per call.

@param object_type [in] The BACnet Object type of this object.
@param object_instance [in] The ID number for this object.
@param rpm_property [in] Points to structure holding the Property,
Value, and Error information.
Print out the value ( s ) for one Property . This function may be called repeatedly for one property if we are walking through a list ( Using_Walked_List is True ) to show just one value of the array per call . @param object_type [ in ] The BACnet Object type of this object . @param object_instance [ in ] The ID number for this object . @param rpm_property [ in ] Points to structure holding the Property Value and Error information .
void PrintReadPropertyData(
    BACNET_OBJECT_TYPE object_type,
    uint32_t object_instance,
    BACNET_PROPERTY_REFERENCE * rpm_property)
{
    BACNET_OBJECT_PROPERTY_VALUE object_value;  
    BACNET_APPLICATION_DATA_VALUE *value, *old_value;
    bool print_brace = false;
    KEY object_list_element;
    bool isSequence = false;    
    if (rpm_property == NULL) {
        fprintf(stdout, "    -- Null Property data \n");
        return;
    }
    value = rpm_property->value;
    if (value == NULL) {
        fprintf(stdout, "?  -- BACnet Error: %s: %s\n",
            bactext_error_class_name((int) rpm_property->error.error_class),
            bactext_error_code_name((int) rpm_property->error.error_code));
        return;
    }
    object_value.object_type = object_type;
    object_value.object_instance = object_instance;
    if ((value != NULL) && (value->next != NULL)) {
        switch (rpm_property->propertyIdentifier) {
            case PROP_PRESENT_VALUE:
            case PROP_PRIORITY_ARRAY:
                if (!ShowValues) {
                    fprintf(stdout, "? \n");
                    rpm_property->propertyIdentifier =
                        PROP_PROTOCOL_CONFORMANCE_CLASS;
                    break;
                }
                if (object_type == OBJECT_DATETIME_VALUE)
                    break;      
            default:
                fprintf(stdout, "{ ");
                print_brace = true;     
                break;
        }
    }
    if (!Using_Walked_List)
        Walked_List_Index = Walked_List_Length = 0;     
    while (value != NULL) {
        object_value.object_property = rpm_property->propertyIdentifier;
        object_value.array_index = rpm_property->propertyArrayIndex;
        object_value.value = value;
        switch (rpm_property->propertyIdentifier) {
            case PROP_OBJECT_LIST:
            case PROP_STATE_TEXT:
            case PROP_STRUCTURED_OBJECT_LIST:
            case PROP_SUBORDINATE_ANNOTATIONS:
            case PROP_SUBORDINATE_LIST:
                if (Using_Walked_List) {
                    if ((rpm_property->propertyArrayIndex == 0) &&
                        (value->tag == BACNET_APPLICATION_TAG_UNSIGNED_INT)) {
                        Walked_List_Length = value->type.Unsigned_Int;
                        if (rpm_property->propertyIdentifier ==
                            PROP_OBJECT_LIST)
                            Object_List_Length = value->type.Unsigned_Int;
                        break;
                    } else
                        assert(Walked_List_Index == (uint32_t)
                            rpm_property->propertyArrayIndex);
                } else {
                    Walked_List_Index++;
                    if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST)
                        Object_List_Length = ++Object_List_Index;
                }
                if (Walked_List_Index == 1) {
                    if (value->tag == BACNET_APPLICATION_TAG_NULL) {
                        fprintf(stdout, "?\n        ");
                        break;
                    }
                    if (value->next == NULL)
                        fprintf(stdout, "{ \n        ");
                    else
                        fprintf(stdout, "\n        ");
                }
                if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) {
                    if (value->tag != BACNET_APPLICATION_TAG_OBJECT_ID) {
                        assert(value->tag == BACNET_APPLICATION_TAG_OBJECT_ID); 
                        break;
                    }
                    object_list_element =
                        KEY_ENCODE(value->type.Object_Id.type,
                        value->type.Object_Id.instance);
                    Keylist_Data_Add(Object_List, object_list_element, NULL);
                } else if (rpm_property->propertyIdentifier == PROP_STATE_TEXT) {
                    if (value->type.Character_String.length > 31) {
                        int iLast15idx =
                            value->type.Character_String.length - 15;
                        value->type.Character_String.value[15] = '-';
                        memcpy(&value->type.Character_String.value[16],
                            &value->type.Character_String.value[iLast15idx],
                            15);
                        value->type.Character_String.value[31] = 0;
                        value->type.Character_String.length = 31;
                    }
                } else if (rpm_property->propertyIdentifier ==
                    PROP_SUBORDINATE_LIST) {
                    if (value->tag != BACNET_APPLICATION_TAG_OBJECT_ID) {
                        assert(value->tag == BACNET_APPLICATION_TAG_OBJECT_ID); 
                        break;
                    }
                    isSequence = true;
                }
                if (isSequence)
                    fprintf(stdout, "{");
                bacapp_print_value(stdout, &object_value);
                if (isSequence)
                    fprintf(stdout, "}");
                if ((Walked_List_Index < Walked_List_Length) ||
                    (value->next != NULL)) {
                    fprintf(stdout, ", ");
                    if (!(Walked_List_Index % 3))
                        fprintf(stdout, "\n        ");
                } else {
                    fprintf(stdout, " } \n");
                }
                break;
            case PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED:
            case PROP_PROTOCOL_SERVICES_SUPPORTED:
                PrettyPrintPropertyValue(stdout, &object_value);
                break;
            case PROP_PROTOCOL_CONFORMANCE_CLASS:
                break;
            default:
                if (ShowValues &&
                    (object_value.value->tag == BACNET_APPLICATION_TAG_DATE)) {
                    PrettyPrintPropertyValue(stdout, &object_value);
                } else {
                    switch (rpm_property->propertyIdentifier) {
                        case PROP_DEVICE_ADDRESS_BINDING:
                            if (value->tag == BACNET_APPLICATION_TAG_NULL) {
                                fprintf(stdout, "?");
                                break;
                            }
                        case PROP_DAYLIGHT_SAVINGS_STATUS:
                        case PROP_LOCAL_TIME:
                        case PROP_LOCAL_DATE:  
                        case PROP_PRESENT_VALUE:
                        case PROP_PRIORITY_ARRAY:
                        case PROP_RELIABILITY:
                        case PROP_UTC_OFFSET:
                        case PROP_DATABASE_REVISION:
                            if (!ShowValues) {
                                fprintf(stdout, "?");
                                break;
                            }
                        default:
                            bacapp_print_value(stdout, &object_value);
                            break;
                    }
                }
                if (value->next != NULL) {
                    fprintf(stdout, ",");
                } else {
                    if (print_brace) {
                        fprintf(stdout, " }");
                    }
                    CheckIsWritableProperty(object_type,        
                        rpm_property);
                    fprintf(stdout, "\n");
                }
                break;
        }
        old_value = value;
        value = value->next;    
        free(old_value);
    }   
}
void PrintReadPropertyData ( BACNET_OBJECT_TYPE object_type , uint32_t object_instance , BACNET_PROPERTY_REFERENCE * rpm_property ) { BACNET_OBJECT_PROPERTY_VALUE object_value ; BACNET_APPLICATION_DATA_VALUE * value , * old_value ; bool print_brace = false ; KEY object_list_element ; bool isSequence = false ; if ( rpm_property == NULL ) { fprintf ( stdout , " \n " ) ; return ; } value = rpm_property -> value ; if ( value == NULL ) { fprintf ( stdout , " \n " , bactext_error_class_name ( ( int ) rpm_property -> error . error_class ) , bactext_error_code_name ( ( int ) rpm_property -> error . error_code ) ) ; return ; } object_value . object_type = object_type ; object_value . object_instance = object_instance ; if ( ( value != NULL ) && ( value -> next != NULL ) ) { switch ( rpm_property -> propertyIdentifier ) { case PROP_PRESENT_VALUE : case PROP_PRIORITY_ARRAY : if ( ! ShowValues ) { fprintf ( stdout , " \n " ) ; rpm_property -> propertyIdentifier = PROP_PROTOCOL_CONFORMANCE_CLASS ; break ; } if ( object_type == OBJECT_DATETIME_VALUE ) break ; default : fprintf ( stdout , " " ) ; print_brace = true ; break ; } } if ( ! Using_Walked_List ) Walked_List_Index = Walked_List_Length = 0 ; while ( value != NULL ) { object_value . object_property = rpm_property -> propertyIdentifier ; object_value . array_index = rpm_property -> propertyArrayIndex ; object_value . value = value ; switch ( rpm_property -> propertyIdentifier ) { case PROP_OBJECT_LIST : case PROP_STATE_TEXT : case PROP_STRUCTURED_OBJECT_LIST : case PROP_SUBORDINATE_ANNOTATIONS : case PROP_SUBORDINATE_LIST : if ( Using_Walked_List ) { if ( ( rpm_property -> propertyArrayIndex == 0 ) && ( value -> tag == BACNET_APPLICATION_TAG_UNSIGNED_INT ) ) { Walked_List_Length = value -> type . Unsigned_Int ; if ( rpm_property -> propertyIdentifier == PROP_OBJECT_LIST ) Object_List_Length = value -> type . Unsigned_Int ; break ; } else assert ( Walked_List_Index == ( uint32_t ) rpm_property -> propertyArrayIndex ) ; } else { Walked_List_Index ++ ; if ( rpm_property -> propertyIdentifier == PROP_OBJECT_LIST ) Object_List_Length = ++ Object_List_Index ; } if ( Walked_List_Index == 1 ) { if ( value -> tag == BACNET_APPLICATION_TAG_NULL ) { fprintf ( stdout , " \n " ) ; break ; } if ( value -> next == NULL ) fprintf ( stdout , " \n " ) ; else fprintf ( stdout , " \n " ) ; } if ( rpm_property -> propertyIdentifier == PROP_OBJECT_LIST ) { if ( value -> tag != BACNET_APPLICATION_TAG_OBJECT_ID ) { assert ( value -> tag == BACNET_APPLICATION_TAG_OBJECT_ID ) ; break ; } object_list_element = KEY_ENCODE ( value -> type . Object_Id . type , value -> type . Object_Id . instance ) ; Keylist_Data_Add ( Object_List , object_list_element , NULL ) ; } else if ( rpm_property -> propertyIdentifier == PROP_STATE_TEXT ) { if ( value -> type . Character_String . length > 31 ) { int iLast15idx = value -> type . Character_String . length - 15 ; value -> type . Character_String . value [ 15 ] = ' ' ; memcpy ( & value -> type . Character_String . value [ 16 ] , & value -> type . Character_String . value [ iLast15idx ] , 15 ) ; value -> type . Character_String . value [ 31 ] = 0 ; value -> type . Character_String . length = 31 ; } } else if ( rpm_property -> propertyIdentifier == PROP_SUBORDINATE_LIST ) { if ( value -> tag != BACNET_APPLICATION_TAG_OBJECT_ID ) { assert ( value -> tag == BACNET_APPLICATION_TAG_OBJECT_ID ) ; break ; } isSequence = true ; } if ( isSequence ) fprintf ( stdout , " " ) ; bacapp_print_value ( stdout , & object_value ) ; if ( isSequence ) fprintf ( stdout , " " ) ; if ( ( Walked_List_Index < Walked_List_Length ) || ( value -> next != NULL ) ) { fprintf ( stdout , " " ) ; if ( ! ( Walked_List_Index % 3 ) ) fprintf ( stdout , " \n " ) ; } else { fprintf ( stdout , " \n " ) ; } break ; case PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED : case PROP_PROTOCOL_SERVICES_SUPPORTED : PrettyPrintPropertyValue ( stdout , & object_value ) ; break ; case PROP_PROTOCOL_CONFORMANCE_CLASS : break ; default : if ( ShowValues && ( object_value . value -> tag == BACNET_APPLICATION_TAG_DATE ) ) { PrettyPrintPropertyValue ( stdout , & object_value ) ; } else { switch ( rpm_property -> propertyIdentifier ) { case PROP_DEVICE_ADDRESS_BINDING : if ( value -> tag == BACNET_APPLICATION_TAG_NULL ) { fprintf ( stdout , " " ) ; break ; } case PROP_DAYLIGHT_SAVINGS_STATUS : case PROP_LOCAL_TIME : case PROP_LOCAL_DATE : case PROP_PRESENT_VALUE : case PROP_PRIORITY_ARRAY : case PROP_RELIABILITY : case PROP_UTC_OFFSET : case PROP_DATABASE_REVISION : if ( ! ShowValues ) { fprintf ( stdout , " " ) ; break ; } default : bacapp_print_value ( stdout , & object_value ) ; break ; } } if ( value -> next != NULL ) { fprintf ( stdout , " " ) ; } else { if ( print_brace ) { fprintf ( stdout , " " ) ; } CheckIsWritableProperty ( object_type , rpm_property ) ; fprintf ( stdout , " \n " ) ; } break ; } old_value = value ; value = value -> next ; free ( old_value ) ; } }
Print out the value(s) for one Property.
Print out the value ( s ) for one Property .
/* for bacapp printing */ /* Ie, will need bracketing braces {} */ /* Then we print the error information */ /* Then this is an array of values.
         * But are we showing Values?  We (VTS3) want ? instead of {?,?} to show up. */ /* Screen the Properties that can be arrays or Sequences */ /* We want the Values freed below, but don't want to
                     * print anything for them.  To achieve this, swap
                     * out the Property for a non-existent Property
                     * and catch that below.  */ /* A special case - no braces for this pair */ /* Else, fall through to normal processing. */ /* Normal array: open brace */ /* remember to close it */ /* In case we need this. */ /* value(s) loop until there is no "next" ... */ /* These are all arrays, so they open and close with braces */ /* Grab the value of the Object List length - don't print it! */ /* If we got the whole Object List array in one RP call, keep
                     * the Index and List_Length in sync as we cycle through. */ /* If the array is empty (nothing for this first entry),
                     * Make it VTS3-friendly and don't show "Null" as a value. */ /* Open this Array of Objects for the first entry (unless
                     * opening brace has already printed, since this is an array
                     * of values[] ) */ /* Something not right here */ /* Store the object list so we can interrogate
                       each object. */ /* We don't have anything to put in the data pointer
                     * yet, so just leave it null.  The key is Key here. */ /* Make sure it fits within 31 chars for original VTS3 limitation.
                     * If longer, take first 15 dash, and last 15 chars. */ /* Something not right here */ /* TODO: handle Sequence of { Device ObjID, Object ID }, */ /* If the object is a Sequence, it needs its own bracketing braces */ /* There are more. */ /* Our special non-existent case; do nothing further here. */ /* First, if this is a date type, it needs a different format
                 * for VTS, so pretty print it. */ /* This would be PROP_LOCAL_DATE, or OBJECT_DATETIME_VALUE,
                     * or OBJECT_DATE_VALUE                     */ /* Some properties are presented just as '?' in an EPICS;
                     * screen these out here, unless ShowValues is true.  */ /* Make it VTS3-friendly and don't show "Null"
                             * as a value. */ /* Else, fall through for normal processing. */ /* Only if !ShowValues */ /* Else, fall through and print value: */ /* there's more! */ /* Closing brace for this multi-valued array */ /* object_instance, */ /* next or NULL */ /* End while loop */