diff --git a/bacnet-stack/demo/epics/Makefile b/bacnet-stack/demo/epics/Makefile index cae78439..82ddbad6 100644 --- a/bacnet-stack/demo/epics/Makefile +++ b/bacnet-stack/demo/epics/Makefile @@ -12,6 +12,7 @@ BACNET_DEFINES = -DBACFILE=1 -DPRINT_ENABLED=1 -DBACAPP_ALL DEFINES = $(BACNET_DEFINES) $(BACDL_DEFINE) # Directories +BACNET_SOURCE = ../../src BACNET_PORT = ../../ports/linux BACNET_INCLUDE = ../../include # BACnet Library @@ -24,7 +25,9 @@ LIBRARIES=-lc,-lgcc,-lm,-L=$(BACNET_LIB_DIR),-l$(BACNET_LIB_NAME) CFLAGS = -Wall -g $(INCLUDES) $(DEFINES) LFLAGS = -Wl,-Map=$(TARGET).map,$(LIBRARIES) -SRCS = main.c +SRCS = main.c \ + $(BACNET_SOURCE)/keylist.c \ + $(BACNET_SOURCE)/key.c OBJS = ${SRCS:.c=.o} diff --git a/bacnet-stack/demo/epics/main.c b/bacnet-stack/demo/epics/main.c index f6afc735..f01b360f 100644 --- a/bacnet-stack/demo/epics/main.c +++ b/bacnet-stack/demo/epics/main.c @@ -54,17 +54,29 @@ /* buffer used for receive */ static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; -/* global variables used in this file */ +/* target information converted from command line */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; -static bool Error_Detected = false; static BACNET_ADDRESS Target_Address; - +/* any errors are picked up in main loop */ +static bool Error_Detected = false; +/* any valid data returned is put here */ typedef struct BACnet_RP_Service_Data_t { bool new_data; BACNET_CONFIRMED_SERVICE_ACK_DATA service_data; BACNET_READ_PROPERTY_DATA data; } BACNET_RP_SERVICE_DATA; static BACNET_RP_SERVICE_DATA Read_Property_Data; +/* We get the length of the object list, + and then get the objects one at a time */ +static uint32_t Object_List_Length = 0; +static uint32_t Object_List_Index = 0; +/* object that we are currently printing */ +static OS_Keylist Object_List; +static BACNET_OBJECT_ID Object_List_Element; + +#if !defined(PRINT_ERRORS) +#define PRINT_ERRORS 1 +#endif /* FIXME: keep the object list in here */ /* static OS_Keylist Object_List; */ @@ -78,7 +90,7 @@ static void MyErrorHandler( /* FIXME: verify src and invoke id */ (void) src; (void) invoke_id; -#if 1 +#if PRINT_ERRORS printf("BACnet Error: %s: %s\r\n", bactext_error_class_name(error_class), bactext_error_code_name(error_code)); #else @@ -98,7 +110,7 @@ void MyAbortHandler( (void) src; (void) invoke_id; (void) server; -#if 1 +#if PRINT_ERRORS printf("BACnet Abort: %s\r\n", bactext_abort_reason_name(abort_reason)); #else (void) abort_reason; @@ -114,7 +126,7 @@ void MyRejectHandler( /* FIXME: verify src and invoke id */ (void) src; (void) invoke_id; -#if 1 +#if PRINT_ERRORS printf("BACnet Reject: %s\r\n", bactext_reject_reason_name(reject_reason)); #else (void) reject_reason; @@ -131,6 +143,7 @@ void PrintReadPropertyData( int application_data_len; bool first_value = true; bool print_brace = false; + KEY object_list_element; if (data) { #if 0 @@ -158,7 +171,35 @@ void PrintReadPropertyData( fprintf(stdout, "{"); print_brace = true; } - bacapp_print_value(stdout, &value, data->object_property); + /* Grab the value of the Device Object List length - don't print it! */ + if (data->object_property == PROP_OBJECT_LIST) { + if ((data->array_index == 0) && + (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT)) { + Object_List_Length = value.type.Unsigned_Int; + fprintf(stdout, "{"); + } else { + if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { + /* FIXME: 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); + + } + bacapp_print_value(stdout, &value, data->object_property); + if (Object_List_Index <= Object_List_Length) { + fprintf(stdout, ","); + if (!(Object_List_Index%4)) { + fprintf(stdout, "\r\n "); + } + } else { + fprintf(stdout, "}"); + fprintf(stdout, "\r\n"); + } + } + } else { + bacapp_print_value(stdout, &value, data->object_property); + } if (len) { if (len < application_data_len) { application_data += len; @@ -172,7 +213,9 @@ void PrintReadPropertyData( } if (print_brace) fprintf(stdout, "}"); - fprintf(stdout, "\r\n"); + if (data->object_property != PROP_OBJECT_LIST) { + fprintf(stdout, "\r\n"); + } } } @@ -232,12 +275,35 @@ static uint8_t Read_Properties( } if (pRequired[index] != -1) { - printf(" %s: ", bactext_property_name(pRequired[index])); - invoke_id = - Send_Read_Property_Request(device_instance, OBJECT_DEVICE, - device_instance, pRequired[index], BACNET_ARRAY_ALL); - if (invoke_id) { - index++; + if (pRequired[index] == PROP_OBJECT_LIST) { + if (Object_List_Length == 0) { + printf(" %s: ", bactext_property_name(pRequired[index])); + invoke_id = + Send_Read_Property_Request(device_instance, OBJECT_DEVICE, + device_instance, PROP_OBJECT_LIST, 0); + if (invoke_id) { + Object_List_Index = 1; + } + } else { + invoke_id = + Send_Read_Property_Request(device_instance, OBJECT_DEVICE, + device_instance, PROP_OBJECT_LIST, Object_List_Index); + if (invoke_id) { + Object_List_Index++; + if (Object_List_Index > Object_List_Length) { + /* go on to next property */ + index++; + } + } + } + } else { + printf(" %s: ", bactext_property_name(pRequired[index])); + invoke_id = + Send_Read_Property_Request(device_instance, OBJECT_DEVICE, + device_instance, pRequired[index], BACNET_ARRAY_ALL); + if (invoke_id) { + index++; + } } } @@ -261,7 +327,7 @@ static void Init_DataLink(void) datalink_set(NULL); } #endif - + #if defined(BACDL_BIP) pEnv = getenv("BACNET_IP_PORT"); if (pEnv) { @@ -362,6 +428,7 @@ int main( } /* setup my info */ Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); + Object_List = Keylist_Create(); address_init(); Init_Service_Handlers(); Init_DataLink(); diff --git a/bacnet-stack/demo/epics/makefile.b32 b/bacnet-stack/demo/epics/makefile.b32 index dd9c0bcf..c6b4f3c9 100644 --- a/bacnet-stack/demo/epics/makefile.b32 +++ b/bacnet-stack/demo/epics/makefile.b32 @@ -24,6 +24,7 @@ BACNET_LIB_DIR = ..\..\lib BACNET_LIB = $(BACNET_LIB_DIR)\bacnet.lib # directories +BACNET_SOURCE = ..\..\src BACNET_PORT = ..\..\ports\win32 BACNET_INCLUDE = ..\..\include INCLUDES = \ @@ -37,7 +38,9 @@ BACNET_DEFINES = -DPRINT_ENABLED=1 -DBACAPP_ALL BACDL_DEFINE=-DBACDL_BIP=1 DEFINES = $(BACNET_DEFINES) $(BACDL_DEFINE) -SRCS = main.c +SRCS = main.c \ + $(BACNET_SOURCE)\keylist.c \ + $(BACNET_SOURCE)\key.c OBJS = $(SRCS:.c=.obj) diff --git a/bacnet-stack/src/keylist.c b/bacnet-stack/src/keylist.c index 77ac9b95..cb5fdf2e 100644 --- a/bacnet-stack/src/keylist.c +++ b/bacnet-stack/src/keylist.c @@ -404,39 +404,6 @@ void Keylist_Delete( #include "ctest.h" -/* test the encode and decode macros */ -void testKeySample( - Test * pTest) -{ - int type, id; - int type_list[] = - { 0, 1, KEY_TYPE_MAX / 2, KEY_TYPE_MAX - 2, KEY_TYPE_MAX - 1, -1 }; - int id_list[] = - { 0, 1, KEY_ID_MAX / 2, KEY_ID_MAX - 2, KEY_ID_MAX - 1, -1 }; - int type_index = 0; - int id_index = 0; - int decoded_type, decoded_id; - KEY key; - - while (type_list[type_index] != -1) { - while (id_list[id_index] != -1) { - type = type_list[type_index]; - id = id_list[id_index]; - key = KEY_ENCODE(type, id); - decoded_type = KEY_DECODE_TYPE(key); - decoded_id = KEY_DECODE_ID(key); - ct_test(pTest, decoded_type == type); - ct_test(pTest, decoded_id == id); - - id_index++; - } - id_index = 0; - type_index++; - } - - return; -} - /* test the FIFO */ void testKeyListFIFO( Test * pTest) @@ -729,8 +696,6 @@ int main( assert(rc); rc = ct_addTestFunction(pTest, testKeyListDataKey); assert(rc); - rc = ct_addTestFunction(pTest, testKeySample); - assert(rc); rc = ct_addTestFunction(pTest, testKeyListDataIndex); assert(rc); rc = ct_addTestFunction(pTest, testKeyListLarge);