From f68780ea5ed610be09a09e0256f2bf09869fd822 Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 9 Feb 2006 17:29:47 +0000 Subject: [PATCH] Added Code::Blocks project for read property demo. Added value decoding and display for read property demo. Removed the I-Am at the beginning of read property demo. --- bacnet-stack/demo/handler/h_rp_a.c | 45 ++++ bacnet-stack/demo/readprop/bacrp.cbp | 369 ++++++++++++++++++++++++++ bacnet-stack/demo/readprop/readprop.c | 24 +- 3 files changed, 425 insertions(+), 13 deletions(-) create mode 100644 bacnet-stack/demo/readprop/bacrp.cbp diff --git a/bacnet-stack/demo/handler/h_rp_a.c b/bacnet-stack/demo/handler/h_rp_a.c index 35f97331..b0d23530 100644 --- a/bacnet-stack/demo/handler/h_rp_a.c +++ b/bacnet-stack/demo/handler/h_rp_a.c @@ -44,8 +44,16 @@ /* for debugging... */ static void PrintReadPropertyData(BACNET_READ_PROPERTY_DATA *data) { + BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */ + int len = 0; + uint8_t *application_data; + int application_data_len; + bool first_value = true; + bool print_brace = false; + if (data) { + #if 0 if (data->array_index == BACNET_ARRAY_ALL) fprintf(stderr,"%s #%u %s\n", bactext_object_type_name(data->object_type), @@ -57,6 +65,41 @@ static void PrintReadPropertyData(BACNET_READ_PROPERTY_DATA *data) data->object_instance, bactext_property_name(data->object_property), data->array_index); + #endif + application_data = data->application_data; + application_data_len = data->application_data_len; + /* value? need to loop until all of the len is gone... */ + for (;;) + { + len = bacapp_decode_application_data( + application_data, + application_data_len, + &value); + if (first_value && (len < application_data_len)) + { + first_value = false; + fprintf(stdout,"{"); + print_brace = true; + } + bacapp_print_value(stdout,&value,data->object_property); + if (len) + { + if (len < application_data_len) + { + application_data += len; + application_data_len -= len; + /* there's more! */ + fprintf(stdout,","); + } + else + break; + } + else + break; + } + if (print_brace) + fprintf(stdout,"}"); + fprintf(stdout,"\r\n"); } } @@ -75,7 +118,9 @@ void handler_read_property_ack( service_request, service_len, &data); + #if 0 fprintf(stderr,"Received Read-Property Ack!\n"); + #endif if (len > 0) PrintReadPropertyData(&data); } diff --git a/bacnet-stack/demo/readprop/bacrp.cbp b/bacnet-stack/demo/readprop/bacrp.cbp new file mode 100644 index 00000000..570a5ad0 --- /dev/null +++ b/bacnet-stack/demo/readprop/bacrp.cbp @@ -0,0 +1,369 @@ + + + + + + + diff --git a/bacnet-stack/demo/readprop/readprop.c b/bacnet-stack/demo/readprop/readprop.c index 51465b10..0b5ae923 100644 --- a/bacnet-stack/demo/readprop/readprop.c +++ b/bacnet-stack/demo/readprop/readprop.c @@ -71,10 +71,8 @@ static void MyErrorHandler( /* FIXME: verify src and invoke id */ (void)src; (void)invoke_id; - printf("\r\nBACnet Error!\r\n"); - printf("Error Class: %s\r\n", - bactext_error_class_name(error_class)); - printf("Error Code: %s\r\n", + printf("BACnet Error: %s: %s\r\n", + bactext_error_class_name(error_class), bactext_error_code_name(error_code)); Error_Detected = true; } @@ -87,8 +85,7 @@ void MyAbortHandler( /* FIXME: verify src and invoke id */ (void)src; (void)invoke_id; - printf("\r\nBACnet Abort!\r\n"); - printf("Abort Reason: %s\r\n", + printf("BACnet Abort: %s\r\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } @@ -101,15 +98,14 @@ void MyRejectHandler( /* FIXME: verify src and invoke id */ (void)src; (void)invoke_id; - printf("\r\nBACnet Reject!\r\n"); - printf("Reject Reason: %s\r\n", + printf("BACnet Reject: %s\r\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } static void Init_Service_Handlers(void) { - /* we need to handle who-is + /* we need to handle who-is to support dynamic device binding to us */ apdu_set_unconfirmed_handler( SERVICE_UNCONFIRMED_WHO_IS, @@ -147,12 +143,12 @@ int main(int argc, char *argv[]) unsigned timeout = 100; // milliseconds unsigned max_apdu = 0; time_t elapsed_seconds = 0; - time_t last_seconds = 0; + time_t last_seconds = 0; time_t current_seconds = 0; time_t timeout_seconds = 0; uint8_t invoke_id = 0; bool found = false; - + if (argc < 5) { printf("%s device-instance object-type object-instance property [index]\r\n", @@ -190,7 +186,7 @@ int main(int argc, char *argv[]) Target_Object_Property,MAX_BACNET_PROPERTY_ID+1); return 1; } - + /* setup my info */ Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); address_init(); @@ -204,6 +200,8 @@ int main(int argc, char *argv[]) last_seconds = time(NULL); timeout_seconds = (Device_APDU_Timeout() / 1000) * Device_Number_Of_APDU_Retries(); + /* no need to spam the world */ + I_Am_Request = false; /* try to bind with the device */ Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance); /* loop forever */ @@ -246,7 +244,7 @@ int main(int argc, char *argv[]) &Target_Address); if (found) { - if (invoke_id == 0) + if (invoke_id == 0) { invoke_id = Send_Read_Property_Request( Target_Device_Object_Instance,