From ba3242aafdb7d3d6eb5e0480410e10d06fbf48a2 Mon Sep 17 00:00:00 2001 From: skarg Date: Wed, 13 Mar 2013 22:17:13 +0000 Subject: [PATCH] indented using indent.sh script to get uniform looking code for release --- bacnet-stack/demo/dcc/main.c | 3 +- bacnet-stack/demo/epics/main.c | 31 +- bacnet-stack/demo/handler/dlenv.c | 4 +- bacnet-stack/demo/handler/h_ccov.c | 4 +- bacnet-stack/demo/handler/h_cov.c | 33 +- bacnet-stack/demo/handler/h_gas_a.c | 17 +- bacnet-stack/demo/handler/h_rpm_a.c | 12 +- bacnet-stack/demo/handler/h_ucov.c | 4 +- bacnet-stack/demo/handler/h_whohas.c | 5 +- bacnet-stack/demo/handler/h_wpm.c | 7 +- bacnet-stack/demo/handler/s_ptransfer.c | 2 +- bacnet-stack/demo/handler/s_rp.c | 11 +- bacnet-stack/demo/handler/s_wp.c | 5 +- bacnet-stack/demo/mstpcap/main.c | 6 +- bacnet-stack/demo/object/ai.c | 140 +- bacnet-stack/demo/object/ao.c | 8 +- bacnet-stack/demo/object/av.c | 140 +- bacnet-stack/demo/object/bo.c | 8 +- bacnet-stack/demo/object/bv.c | 8 +- bacnet-stack/demo/object/csv.c | 12 +- bacnet-stack/demo/object/device.c | 30 +- bacnet-stack/demo/object/device.h | 8 +- bacnet-stack/demo/object/gw_device.c | 8 +- bacnet-stack/demo/object/lo.c | 16 +- bacnet-stack/demo/object/lsp.c | 8 +- bacnet-stack/demo/object/ms-input.c | 106 +- bacnet-stack/demo/object/mso.c | 20 +- bacnet-stack/demo/object/msv.c | 12 +- bacnet-stack/demo/object/nc.c | 107 +- bacnet-stack/demo/object/trendlog.c | 14 +- bacnet-stack/demo/perl/perl_bindings.c | 8 +- bacnet-stack/demo/readbdt/main.c | 15 +- bacnet-stack/demo/readprop/main.c | 3 +- bacnet-stack/demo/router/ipmodule.c | 649 ++++---- bacnet-stack/demo/router/ipmodule.h | 42 +- bacnet-stack/demo/router/main.c | 1320 +++++++++-------- bacnet-stack/demo/router/msgqueue.c | 99 +- bacnet-stack/demo/router/msgqueue.h | 49 +- bacnet-stack/demo/router/mstpmodule.c | 227 ++- bacnet-stack/demo/router/mstpmodule.h | 4 +- bacnet-stack/demo/router/network_layer.c | 510 ++++--- bacnet-stack/demo/router/network_layer.h | 28 +- bacnet-stack/demo/router/portthread.c | 148 +- bacnet-stack/demo/router/portthread.h | 101 +- bacnet-stack/demo/server/main.c | 4 +- bacnet-stack/demo/uptransfer/main.c | 4 +- bacnet-stack/demo/whohas/main.c | 52 +- bacnet-stack/demo/whois/main.c | 408 +++-- bacnet-stack/demo/writefile/main.c | 7 +- bacnet-stack/demo/writeprop/main.c | 3 +- bacnet-stack/include/bacdef.h | 60 +- bacnet-stack/include/bacenum.h | 12 +- bacnet-stack/include/bvlc.h | 2 +- bacnet-stack/include/client.h | 2 +- bacnet-stack/include/datalink.h | 2 +- bacnet-stack/include/datetime.h | 4 +- bacnet-stack/include/dcc.h | 8 +- bacnet-stack/include/event.h | 8 +- bacnet-stack/include/fifo.h | 36 +- bacnet-stack/include/handlers.h | 17 +- bacnet-stack/include/mstp.h | 8 +- bacnet-stack/include/readrange.h | 4 +- bacnet-stack/include/ringbuf.h | 16 +- bacnet-stack/include/rp.h | 4 +- bacnet-stack/include/timesync.h | 14 +- bacnet-stack/ports/at91sam7s/av.c | 4 +- bacnet-stack/ports/at91sam7s/bv.c | 4 +- bacnet-stack/ports/at91sam7s/device.c | 12 +- bacnet-stack/ports/at91sam7s/timer.c | 2 +- bacnet-stack/ports/atmega168/bv.c | 4 +- bacnet-stack/ports/atmega168/device.c | 4 +- bacnet-stack/ports/atmega8/bv.c | 4 +- bacnet-stack/ports/bdk-atxx4-mstp/ai.c | 6 +- bacnet-stack/ports/bdk-atxx4-mstp/av.c | 6 +- bacnet-stack/ports/bdk-atxx4-mstp/bacnet.c | 3 +- bacnet-stack/ports/bdk-atxx4-mstp/bi.c | 10 +- bacnet-stack/ports/bdk-atxx4-mstp/bo.c | 14 +- .../ports/bdk-atxx4-mstp/bootloader/defines.h | 4 +- .../ports/bdk-atxx4-mstp/bootloader/flash.h | 78 +- .../ports/bdk-atxx4-mstp/bootloader/main.c | 4 +- bacnet-stack/ports/bdk-atxx4-mstp/device.c | 24 +- bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c | 13 +- bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h | 10 +- bacnet-stack/ports/bsd/bip-init.c | 69 +- bacnet-stack/ports/bsd/net.h | 12 +- bacnet-stack/ports/linux/dlmstp.c | 4 +- bacnet-stack/ports/linux/dlmstp_linux.c | 591 ++++---- bacnet-stack/ports/linux/dlmstp_linux.h | 144 +- bacnet-stack/ports/linux/net.h | 12 +- bacnet-stack/ports/linux/rs485.c | 286 ++-- bacnet-stack/ports/lwip/bip.c | 27 +- bacnet-stack/ports/lwip/net.h | 16 +- bacnet-stack/ports/pic18f6720/ai.c | 3 +- bacnet-stack/ports/pic18f6720/av.c | 4 +- bacnet-stack/ports/pic18f6720/bv.c | 7 +- bacnet-stack/ports/pic18f6720/device.c | 18 +- bacnet-stack/ports/pic18f6720/mstp.c | 11 +- bacnet-stack/ports/rtos32/bip-init.c | 3 +- bacnet-stack/ports/rx62n/bo.c | 4 +- bacnet-stack/ports/rx62n/device.c | 16 +- bacnet-stack/ports/stm32f10x/bo.c | 4 +- bacnet-stack/ports/stm32f10x/device.c | 12 +- bacnet-stack/ports/stm32f10x/rs485.c | 2 +- bacnet-stack/ports/win32/dlmstp.c | 6 +- bacnet-stack/src/address.c | 6 +- bacnet-stack/src/bacaddr.c | 5 +- bacnet-stack/src/bacapp.c | 28 +- bacnet-stack/src/bacdcode.c | 6 +- bacnet-stack/src/bacstr.c | 2 +- bacnet-stack/src/bactext.c | 5 +- bacnet-stack/src/bip.c | 5 +- bacnet-stack/src/bvlc.c | 9 +- bacnet-stack/src/datetime.c | 11 +- bacnet-stack/src/event.c | 281 ++-- bacnet-stack/src/fifo.c | 39 +- bacnet-stack/src/get_alarm_sum.c | 14 +- bacnet-stack/src/mstp.c | 60 +- bacnet-stack/src/ringbuf.c | 20 +- bacnet-stack/src/rp.c | 4 +- bacnet-stack/src/timesync.c | 62 +- 120 files changed, 3382 insertions(+), 3299 deletions(-) diff --git a/bacnet-stack/demo/dcc/main.c b/bacnet-stack/demo/dcc/main.c index e62843d5..464c2fb4 100644 --- a/bacnet-stack/demo/dcc/main.c +++ b/bacnet-stack/demo/dcc/main.c @@ -211,7 +211,8 @@ int main( } /* at least one second has passed */ if (current_seconds != last_seconds) - tsm_timer_milliseconds((uint16_t)((current_seconds - last_seconds) * 1000)); + tsm_timer_milliseconds((uint16_t) ((current_seconds - + last_seconds) * 1000)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ diff --git a/bacnet-stack/demo/epics/main.c b/bacnet-stack/demo/epics/main.c index b95298c9..84cb1690 100644 --- a/bacnet-stack/demo/epics/main.c +++ b/bacnet-stack/demo/epics/main.c @@ -141,7 +141,8 @@ static struct property_value_list_t Property_Value_List[] = { {-1, NULL} }; -static BACNET_APPLICATION_DATA_VALUE *object_property_value(int32_t property_id) +static BACNET_APPLICATION_DATA_VALUE *object_property_value( + int32_t property_id) { BACNET_APPLICATION_DATA_VALUE *value = NULL; int32_t index = 0; @@ -414,8 +415,10 @@ void CheckIsWritableProperty( bIsWritable = true; } } else if (object_type == OBJECT_NETWORK_SECURITY) { - if ((rpm_property->propertyIdentifier == PROP_BASE_DEVICE_SECURITY_POLICY) || - (rpm_property->propertyIdentifier == PROP_NETWORK_ACCESS_SECURITY_POLICIES) || + if ((rpm_property->propertyIdentifier == + PROP_BASE_DEVICE_SECURITY_POLICY) || + (rpm_property->propertyIdentifier == + PROP_NETWORK_ACCESS_SECURITY_POLICIES) || (rpm_property->propertyIdentifier == PROP_SECURITY_TIME_WINDOW) || (rpm_property->propertyIdentifier == PROP_PACKET_REORDER_TIME) || (rpm_property->propertyIdentifier == PROP_LAST_KEY_SERVER) || @@ -434,7 +437,8 @@ void CheckIsWritableProperty( } -static const char *protocol_services_supported_text(size_t bit_index) +static const char *protocol_services_supported_text( + size_t bit_index) { bool is_confirmed = false; size_t text_index = 0; @@ -1154,9 +1158,8 @@ void PrintHeading( (value->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING)) { printf("Product Description: \"%s\"\r\n\r\n", characterstring_value(&value->type.Character_String)); - }else { - printf( - "Product Description: " + } else { + printf("Product Description: " "\"your product description here\"\r\n\r\n"); } printf("BIBBs Supported:\r\n"); @@ -1220,7 +1223,8 @@ void PrintHeading( printf("-- SubscribeCOVProperty Initiate Execute\r\n"); #ifdef BAC_ROUTING if (Target_Address.net == 0) { - printf("-- Note: The following Routing Services are Supported:\r\n"); + printf + ("-- Note: The following Routing Services are Supported:\r\n"); printf("-- Who-Is-Router-To-Network Initiate Execute\r\n"); printf("-- I-Am-Router-To-Network Initiate Execute\r\n"); printf("-- Initialize-Routing-Table Execute\r\n"); @@ -1441,7 +1445,8 @@ int main( current_seconds = time(NULL); /* Has at least one second passed ? */ if (current_seconds != last_seconds) { - tsm_timer_milliseconds((uint16_t)((current_seconds - last_seconds) * 1000)); + tsm_timer_milliseconds((uint16_t) ((current_seconds - + last_seconds) * 1000)); } /* OK to proceed; see what we are up to now */ @@ -1629,11 +1634,11 @@ int main( (Request_Invoke_ID == Read_Property_Multiple_Data.service_data.invoke_id)) { Read_Property_Multiple_Data.new_data = false; - PrintReadPropertyData - (Read_Property_Multiple_Data.rpm_data->object_type, + PrintReadPropertyData(Read_Property_Multiple_Data. + rpm_data->object_type, Read_Property_Multiple_Data.rpm_data->object_instance, - Read_Property_Multiple_Data. - rpm_data->listOfProperties); + Read_Property_Multiple_Data.rpm_data-> + listOfProperties); if (tsm_invoke_id_free(Request_Invoke_ID)) { Request_Invoke_ID = 0; } else { diff --git a/bacnet-stack/demo/handler/dlenv.c b/bacnet-stack/demo/handler/dlenv.c index 3a00628b..67d71709 100644 --- a/bacnet-stack/demo/handler/dlenv.c +++ b/bacnet-stack/demo/handler/dlenv.c @@ -150,7 +150,7 @@ int dlenv_register_as_foreign_device( if (retval < 0) fprintf(stderr, "FAILED to Register with BBMD at %s \n", inet_ntoa(addr)); - BBMD_Timer_Seconds = (uint16_t)bbmd_timetolive_seconds; + BBMD_Timer_Seconds = (uint16_t) bbmd_timetolive_seconds; } bbmd_result = retval; @@ -176,7 +176,7 @@ void dlenv_maintenance_timer( BBMD_Timer_Seconds -= elapsed_seconds; } if (BBMD_Timer_Seconds == 0) { - (void)dlenv_register_as_foreign_device(); + (void) dlenv_register_as_foreign_device(); /* If that failed (negative), maybe just a network issue. * If nothing happened (0), may be un/misconfigured. * Set up to try again later in all cases. */ diff --git a/bacnet-stack/demo/handler/h_ccov.c b/bacnet-stack/demo/handler/h_ccov.c index 0dc26789..1f1d33cf 100644 --- a/bacnet-stack/demo/handler/h_ccov.c +++ b/bacnet-stack/demo/handler/h_ccov.c @@ -125,8 +125,8 @@ void handler_ccov_notification( fprintf(stderr, "CCOV: "); if (pProperty_value->propertyIdentifier < 512) { fprintf(stderr, "%s ", - bactext_property_name(pProperty_value-> - propertyIdentifier)); + bactext_property_name + (pProperty_value->propertyIdentifier)); } else { fprintf(stderr, "proprietary %u ", pProperty_value->propertyIdentifier); diff --git a/bacnet-stack/demo/handler/h_cov.c b/bacnet-stack/demo/handler/h_cov.c index fffb49cf..e2ba46b4 100644 --- a/bacnet-stack/demo/handler/h_cov.c +++ b/bacnet-stack/demo/handler/h_cov.c @@ -311,7 +311,7 @@ static bool cov_list_subscribe( /* From BACnet Standard 135-2010-13.14.2 ...Cancellations that are issued for which no matching COV context can be found shall succeed as if a context had - existed, returning 'Result(+)'.*/ + existed, returning 'Result(+)'. */ found = true; } } @@ -406,10 +406,10 @@ static void cov_lifetime_expiration_handler( /* expire the subscription */ #if PRINT_ENABLED fprintf(stderr, "COVtimer: PID=%u ", - COV_Subscriptions[index].subscriberProcessIdentifier); + COV_Subscriptions[index].subscriberProcessIdentifier); fprintf(stderr, "%s %u ", - bactext_object_type_name( - COV_Subscriptions[index].monitoredObjectIdentifier.type), + bactext_object_type_name(COV_Subscriptions[index]. + monitoredObjectIdentifier.type), COV_Subscriptions[index].monitoredObjectIdentifier.instance); fprintf(stderr, "time remaining=%u seconds ", COV_Subscriptions[index].lifetime); @@ -497,13 +497,13 @@ void handler_cov_task( object_type = (BACNET_OBJECT_TYPE) COV_Subscriptions[index].monitoredObjectIdentifier.type; object_instance = - COV_Subscriptions[index].monitoredObjectIdentifier. - instance; + COV_Subscriptions[index]. + monitoredObjectIdentifier.instance; status = Device_COV(object_type, object_instance); if (status) { COV_Subscriptions[index].flag.send_requested = true; #if PRINT_ENABLED - fprintf(stderr,"COVtask: Marking...\n"); + fprintf(stderr, "COVtask: Marking...\n"); #endif } } @@ -520,8 +520,8 @@ void handler_cov_task( object_type = (BACNET_OBJECT_TYPE) COV_Subscriptions[index].monitoredObjectIdentifier.type; object_instance = - COV_Subscriptions[index].monitoredObjectIdentifier. - instance; + COV_Subscriptions[index]. + monitoredObjectIdentifier.instance; Device_COV_Clear(object_type, object_instance); } index++; @@ -537,8 +537,9 @@ void handler_cov_task( (COV_Subscriptions[index].invokeID)) { if (tsm_invoke_id_free(COV_Subscriptions[index].invokeID)) { COV_Subscriptions[index].invokeID = 0; - } else if (tsm_invoke_id_failed(COV_Subscriptions[index]. - invokeID)) { + } else + if (tsm_invoke_id_failed(COV_Subscriptions + [index].invokeID)) { tsm_free_invoke_id(COV_Subscriptions[index].invokeID); COV_Subscriptions[index].invokeID = 0; } @@ -566,13 +567,13 @@ void handler_cov_task( } if (send) { object_type = (BACNET_OBJECT_TYPE) - COV_Subscriptions[index].monitoredObjectIdentifier. - type; + COV_Subscriptions[index]. + monitoredObjectIdentifier.type; object_instance = - COV_Subscriptions[index].monitoredObjectIdentifier. - instance; + COV_Subscriptions[index]. + monitoredObjectIdentifier.instance; #if PRINT_ENABLED - fprintf(stderr,"COVtask: Sending...\n"); + fprintf(stderr, "COVtask: Sending...\n"); #endif /* configure the linked list for the two properties */ value_list[0].next = &value_list[1]; diff --git a/bacnet-stack/demo/handler/h_gas_a.c b/bacnet-stack/demo/handler/h_gas_a.c index a44f6634..0073cd31 100644 --- a/bacnet-stack/demo/handler/h_gas_a.c +++ b/bacnet-stack/demo/handler/h_gas_a.c @@ -56,24 +56,23 @@ * decoded from the APDU header of this message. */ void get_alarm_summary_ack_handler( - uint8_t *service_request, + uint8_t * service_request, uint16_t service_len, - BACNET_ADDRESS *src, - BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) + BACNET_ADDRESS * src, + BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) { uint16_t apdu_len = 0; uint16_t len = 0; BACNET_GET_ALARM_SUMMARY_DATA data; - while(service_len - len){ - apdu_len = get_alarm_summary_ack_decode_apdu_data( - &service_request[len], - service_len - len, - &data); + while (service_len - len) { + apdu_len = + get_alarm_summary_ack_decode_apdu_data(&service_request[len], + service_len - len, &data); len += apdu_len; - if(apdu_len > 0){ + if (apdu_len > 0) { /* FIXME: Add code to process data */ } else { break; diff --git a/bacnet-stack/demo/handler/h_rpm_a.c b/bacnet-stack/demo/handler/h_rpm_a.c index 0744fef4..0669c966 100644 --- a/bacnet-stack/demo/handler/h_rpm_a.c +++ b/bacnet-stack/demo/handler/h_rpm_a.c @@ -221,8 +221,8 @@ void rpm_ack_print_data( #if PRINT_ENABLED if (listOfProperties->propertyIdentifier < 512) { fprintf(stdout, " %s: ", - bactext_property_name - (listOfProperties->propertyIdentifier)); + bactext_property_name(listOfProperties-> + propertyIdentifier)); } else { fprintf(stdout, " proprietary %u: ", (unsigned) listOfProperties->propertyIdentifier); @@ -269,10 +269,10 @@ void rpm_ack_print_data( #if PRINT_ENABLED /* AccessError */ fprintf(stdout, "BACnet Error: %s: %s\r\n", - bactext_error_class_name((int) listOfProperties->error. - error_class), - bactext_error_code_name((int) listOfProperties->error. - error_code)); + bactext_error_class_name((int) listOfProperties-> + error.error_class), + bactext_error_code_name((int) listOfProperties-> + error.error_code)); #endif } listOfProperties = listOfProperties->next; diff --git a/bacnet-stack/demo/handler/h_ucov.c b/bacnet-stack/demo/handler/h_ucov.c index 6b872b5a..f5c198e0 100644 --- a/bacnet-stack/demo/handler/h_ucov.c +++ b/bacnet-stack/demo/handler/h_ucov.c @@ -104,8 +104,8 @@ void handler_ucov_notification( fprintf(stderr, "UCOV: "); if (pProperty_value->propertyIdentifier < 512) { fprintf(stderr, "%s ", - bactext_property_name(pProperty_value-> - propertyIdentifier)); + bactext_property_name + (pProperty_value->propertyIdentifier)); } else { fprintf(stderr, "proprietary %u ", pProperty_value->propertyIdentifier); diff --git a/bacnet-stack/demo/handler/h_whohas.c b/bacnet-stack/demo/handler/h_whohas.c index a817fe17..8dbd4d31 100644 --- a/bacnet-stack/demo/handler/h_whohas.c +++ b/bacnet-stack/demo/handler/h_whohas.c @@ -65,8 +65,9 @@ static void match_name_or_object( } else { /* valid object_name copy in my device? */ found = - Device_Object_Name_Copy((BACNET_OBJECT_TYPE) data->object. - identifier.type, data->object.identifier.instance, &object_name); + Device_Object_Name_Copy((BACNET_OBJECT_TYPE) data-> + object.identifier.type, data->object.identifier.instance, + &object_name); if (found) { Send_I_Have(Device_Object_Instance_Number(), (BACNET_OBJECT_TYPE) data->object.identifier.type, diff --git a/bacnet-stack/demo/handler/h_wpm.c b/bacnet-stack/demo/handler/h_wpm.c index ee47c1d1..1a7ef92c 100644 --- a/bacnet-stack/demo/handler/h_wpm.c +++ b/bacnet-stack/demo/handler/h_wpm.c @@ -175,10 +175,9 @@ void handler_write_property_multiple( fprintf(stderr, "WPM: Sending Abort!\n"); #endif } else if (len == BACNET_STATUS_ERROR) { - apdu_len = wpm_error_ack_encode_apdu( - &Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, - &wp_data); + apdu_len = + wpm_error_ack_encode_apdu(&Handler_Transmit_Buffer[npdu_len], + service_data->invoke_id, &wp_data); #if PRINT_ENABLED fprintf(stderr, "WPM: Sending Error!\n"); #endif diff --git a/bacnet-stack/demo/handler/s_ptransfer.c b/bacnet-stack/demo/handler/s_ptransfer.c index e608649b..0720120f 100644 --- a/bacnet-stack/demo/handler/s_ptransfer.c +++ b/bacnet-stack/demo/handler/s_ptransfer.c @@ -97,7 +97,7 @@ uint8_t Send_Private_Transfer_Request( block->cMyByte2); len += encode_application_real(&pt_req_buffer[len], block->fMyReal); - characterstring_init_ansi(&bsTemp, (char *)block->sMyString); + characterstring_init_ansi(&bsTemp, (char *) block->sMyString); len += encode_application_character_string(&pt_req_buffer[len], &bsTemp); diff --git a/bacnet-stack/demo/handler/s_rp.c b/bacnet-stack/demo/handler/s_rp.c index 96d37049..7213317f 100644 --- a/bacnet-stack/demo/handler/s_rp.c +++ b/bacnet-stack/demo/handler/s_rp.c @@ -60,7 +60,7 @@ * @return invoke id of outgoing message, or 0 if device is not bound or no tsm available */ uint8_t Send_Read_Property_Request_Address( - BACNET_ADDRESS *dest, + BACNET_ADDRESS * dest, uint16_t max_apdu, BACNET_OBJECT_TYPE object_type, uint32_t object_instance, @@ -149,7 +149,7 @@ uint8_t Send_Read_Property_Request( BACNET_PROPERTY_ID object_property, uint32_t array_index) { - BACNET_ADDRESS dest = {0}; + BACNET_ADDRESS dest = { 0 }; unsigned max_apdu = 0; uint8_t invoke_id = 0; bool status = false; @@ -157,10 +157,9 @@ uint8_t Send_Read_Property_Request( /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); if (status) { - invoke_id = Send_Read_Property_Request_Address( - &dest, max_apdu, object_type, - object_instance, object_property, - array_index); + invoke_id = + Send_Read_Property_Request_Address(&dest, max_apdu, object_type, + object_instance, object_property, array_index); } return invoke_id; diff --git a/bacnet-stack/demo/handler/s_wp.c b/bacnet-stack/demo/handler/s_wp.c index 80f8daeb..d65d4b57 100644 --- a/bacnet-stack/demo/handler/s_wp.c +++ b/bacnet-stack/demo/handler/s_wp.c @@ -157,8 +157,9 @@ uint8_t Send_Write_Property_Request( #if PRINT_ENABLED_DEBUG fprintf(stderr, "WriteProperty service: " "%s tag=%d\n", (object_value->context_specific ? "context" : "application"), - (int) (object_value->context_specific ? object_value-> - context_tag : object_value->tag)); + (int) (object_value-> + context_specific ? object_value->context_tag : object_value-> + tag)); #endif len = bacapp_encode_data(&application_data[apdu_len], object_value); if ((len + apdu_len) < MAX_APDU) { diff --git a/bacnet-stack/demo/mstpcap/main.c b/bacnet-stack/demo/mstpcap/main.c index 414eacb2..93464a03 100644 --- a/bacnet-stack/demo/mstpcap/main.c +++ b/bacnet-stack/demo/mstpcap/main.c @@ -316,13 +316,13 @@ static void packet_statistics_clear( } static uint32_t Timer_Silence( - void * pArg) + void *pArg) { return timer_milliseconds(TIMER_SILENCE); } static void Timer_Silence_Reset( - void * pArg) + void *pArg) { timer_reset(TIMER_SILENCE); } @@ -823,7 +823,7 @@ int main( if (test_global_header(argv[2])) { while (read_received_packet(mstp_port)) { packet_count++; - fprintf(stderr, "\r%u packets", (unsigned)packet_count); + fprintf(stderr, "\r%u packets", (unsigned) packet_count); } if (packet_count) { packet_statistics_print(); diff --git a/bacnet-stack/demo/object/ai.c b/bacnet-stack/demo/object/ai.c index d6983f76..df7a75e0 100644 --- a/bacnet-stack/demo/object/ai.c +++ b/bacnet-stack/demo/object/ai.c @@ -352,11 +352,11 @@ int Analog_Input_Read_Property( case PROP_LIMIT_ENABLE: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, 0, - (CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : - false); + (CurrentAI-> + Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false); bitstring_set_bit(&bit_string, 1, - (CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : - false); + (CurrentAI-> + Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -364,14 +364,14 @@ int Analog_Input_Read_Property( case PROP_EVENT_ENABLE: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - (CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : - false); + (CurrentAI-> + Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false); bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, - (CurrentAI->Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : - false); + (CurrentAI-> + Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false); bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, - (CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : - false); + (CurrentAI-> + Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -379,8 +379,8 @@ int Analog_Input_Read_Property( case PROP_ACKED_TRANSITIONS: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - CurrentAI-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); + CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked); bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, @@ -637,7 +637,7 @@ bool Analog_Input_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { - switch ((BACNET_NOTIFY_TYPE)value.type.Enumerated) { + switch ((BACNET_NOTIFY_TYPE) value.type.Enumerated) { case NOTIFY_EVENT: CurrentAI->Notify_Type = 1; break; @@ -922,17 +922,17 @@ void Analog_Input_Intrinsic_Reporting( event_data.notificationParams.outOfRange.exceedingValue = PresentVal; /* Status_Flags of the referenced object. */ - bitstring_init(&event_data.notificationParams. - outOfRange.statusFlags); - bitstring_set_bit(&event_data.notificationParams. - outOfRange.statusFlags, STATUS_FLAG_IN_ALARM, + bitstring_init(&event_data.notificationParams.outOfRange. + statusFlags); + bitstring_set_bit(&event_data.notificationParams.outOfRange. + statusFlags, STATUS_FLAG_IN_ALARM, CurrentAI->Event_State ? true : false); - bitstring_set_bit(&event_data.notificationParams. - outOfRange.statusFlags, STATUS_FLAG_FAULT, false); - bitstring_set_bit(&event_data.notificationParams. - outOfRange.statusFlags, STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&event_data.notificationParams. - outOfRange.statusFlags, STATUS_FLAG_OUT_OF_SERVICE, + bitstring_set_bit(&event_data.notificationParams.outOfRange. + statusFlags, STATUS_FLAG_FAULT, false); + bitstring_set_bit(&event_data.notificationParams.outOfRange. + statusFlags, STATUS_FLAG_OVERRIDDEN, false); + bitstring_set_bit(&event_data.notificationParams.outOfRange. + statusFlags, STATUS_FLAG_OUT_OF_SERVICE, CurrentAI->Out_Of_Service); /* Deadband used for limit checking. */ event_data.notificationParams.outOfRange.deadband = @@ -952,30 +952,24 @@ void Analog_Input_Intrinsic_Reporting( case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - CurrentAI-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = - false; - CurrentAI-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp = - event_data.timeStamp.value.dateTime; + CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked = false; + CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + Time_Stamp = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_FAULT: - CurrentAI-> - Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = - false; - CurrentAI-> - Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp = - event_data.timeStamp.value.dateTime; + CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT]. + bIsAcked = false; + CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT]. + Time_Stamp = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_NORMAL: - CurrentAI-> - Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = - false; - CurrentAI-> - Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp = - event_data.timeStamp.value.dateTime; + CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL]. + bIsAcked = false; + CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL]. + Time_Stamp = event_data.timeStamp.value.dateTime; break; } } @@ -1002,12 +996,12 @@ int Analog_Input_Event_Information( /* Acked_Transitions property, which has at least one of the bits (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */ IsNotAckedTransitions = - (AI_Descr[index]. - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == - false) | (AI_Descr[index]. - Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == - false) | (AI_Descr[index]. - Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false); + (AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked == + false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT]. + bIsAcked == + false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL]. + bIsAcked == false); } else return -1; /* end of list */ @@ -1022,8 +1016,8 @@ int Analog_Input_Event_Information( bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, - AI_Descr[index]. - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); + AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked); bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_FAULT, AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); @@ -1041,14 +1035,14 @@ int Analog_Input_Event_Information( /* Event Enable */ bitstring_init(&getevent_data->eventEnable); bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, - (AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : - false); + (AI_Descr[index]. + Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false); bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT, - (AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : - false); + (AI_Descr[index]. + Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false); bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL, - (AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : - false); + (AI_Descr[index]. + Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false); /* Event Priorities */ Notification_Class_Get_Priorities(AI_Descr[index].Notification_Class, getevent_data->eventPriorities); @@ -1068,8 +1062,8 @@ int Analog_Input_Alarm_Ack( object_index = - Analog_Input_Instance_To_Index(alarmack_data-> - eventObjectIdentifier.instance); + Analog_Input_Instance_To_Index(alarmack_data->eventObjectIdentifier. + instance); if (object_index < MAX_ANALOG_INPUTS) CurrentAI = &AI_Descr[object_index]; @@ -1082,22 +1076,22 @@ int Analog_Input_Alarm_Ack( case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - if (CurrentAI-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { + if (CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked == false) { if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAI->Acked_Transitions - [TRANSITION_TO_OFFNORMAL].Time_Stamp, + if (datetime_compare(&CurrentAI-> + Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } /* FIXME: Send ack notification */ - CurrentAI-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = true; + CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked = true; } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; @@ -1111,8 +1105,8 @@ int Analog_Input_Alarm_Ack( *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAI->Acked_Transitions - [TRANSITION_TO_FAULT].Time_Stamp, + if (datetime_compare(&CurrentAI-> + Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; @@ -1134,8 +1128,8 @@ int Analog_Input_Alarm_Ack( *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAI->Acked_Transitions - [TRANSITION_TO_NORMAL].Time_Stamp, + if (datetime_compare(&CurrentAI-> + Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; @@ -1180,16 +1174,16 @@ int Analog_Input_Alarm_Summary( bitstring_init(&getalarm_data->acknowledgedTransitions); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, - AI_Descr[index]. - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); + AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, TRANSITION_TO_FAULT, - AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT]. - bIsAcked); + AI_Descr[index]. + Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, - AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL]. - bIsAcked); + AI_Descr[index]. + Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); return 1; /* active alarm */ } else diff --git a/bacnet-stack/demo/object/ao.c b/bacnet-stack/demo/object/ao.c index 720b095e..99f687ae 100644 --- a/bacnet-stack/demo/object/ao.c +++ b/bacnet-stack/demo/object/ao.c @@ -451,11 +451,11 @@ bool Analog_Output_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { object_index = - Analog_Output_Instance_To_Index(wp_data-> - object_instance); + Analog_Output_Instance_To_Index + (wp_data->object_instance); status = - Analog_Output_Present_Value_Relinquish(wp_data-> - object_instance, wp_data->priority); + Analog_Output_Present_Value_Relinquish + (wp_data->object_instance, wp_data->priority); if (!status) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; diff --git a/bacnet-stack/demo/object/av.c b/bacnet-stack/demo/object/av.c index 8999d8a1..76d920af 100644 --- a/bacnet-stack/demo/object/av.c +++ b/bacnet-stack/demo/object/av.c @@ -424,11 +424,11 @@ int Analog_Value_Read_Property( case PROP_LIMIT_ENABLE: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, 0, - (CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : - false); + (CurrentAV-> + Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false); bitstring_set_bit(&bit_string, 1, - (CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : - false); + (CurrentAV-> + Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -436,14 +436,14 @@ int Analog_Value_Read_Property( case PROP_EVENT_ENABLE: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - (CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : - false); + (CurrentAV-> + Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false); bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, - (CurrentAV->Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : - false); + (CurrentAV-> + Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false); bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, - (CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : - false); + (CurrentAV-> + Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -451,8 +451,8 @@ int Analog_Value_Read_Property( case PROP_ACKED_TRANSITIONS: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - CurrentAV-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); + CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked); bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, @@ -735,7 +735,7 @@ bool Analog_Value_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { - switch ((BACNET_NOTIFY_TYPE)value.type.Enumerated) { + switch ((BACNET_NOTIFY_TYPE) value.type.Enumerated) { case NOTIFY_EVENT: CurrentAV->Notify_Type = 1; break; @@ -1017,17 +1017,17 @@ void Analog_Value_Intrinsic_Reporting( event_data.notificationParams.outOfRange.exceedingValue = PresentVal; /* Status_Flags of the referenced object. */ - bitstring_init(&event_data.notificationParams. - outOfRange.statusFlags); - bitstring_set_bit(&event_data.notificationParams. - outOfRange.statusFlags, STATUS_FLAG_IN_ALARM, + bitstring_init(&event_data.notificationParams.outOfRange. + statusFlags); + bitstring_set_bit(&event_data.notificationParams.outOfRange. + statusFlags, STATUS_FLAG_IN_ALARM, CurrentAV->Event_State ? true : false); - bitstring_set_bit(&event_data.notificationParams. - outOfRange.statusFlags, STATUS_FLAG_FAULT, false); - bitstring_set_bit(&event_data.notificationParams. - outOfRange.statusFlags, STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&event_data.notificationParams. - outOfRange.statusFlags, STATUS_FLAG_OUT_OF_SERVICE, + bitstring_set_bit(&event_data.notificationParams.outOfRange. + statusFlags, STATUS_FLAG_FAULT, false); + bitstring_set_bit(&event_data.notificationParams.outOfRange. + statusFlags, STATUS_FLAG_OVERRIDDEN, false); + bitstring_set_bit(&event_data.notificationParams.outOfRange. + statusFlags, STATUS_FLAG_OUT_OF_SERVICE, CurrentAV->Out_Of_Service); /* Deadband used for limit checking. */ event_data.notificationParams.outOfRange.deadband = @@ -1047,30 +1047,24 @@ void Analog_Value_Intrinsic_Reporting( case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - CurrentAV-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = - false; - CurrentAV-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp = - event_data.timeStamp.value.dateTime; + CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked = false; + CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + Time_Stamp = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_FAULT: - CurrentAV-> - Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = - false; - CurrentAV-> - Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp = - event_data.timeStamp.value.dateTime; + CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT]. + bIsAcked = false; + CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT]. + Time_Stamp = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_NORMAL: - CurrentAV-> - Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = - false; - CurrentAV-> - Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp = - event_data.timeStamp.value.dateTime; + CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL]. + bIsAcked = false; + CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL]. + Time_Stamp = event_data.timeStamp.value.dateTime; break; } } @@ -1097,12 +1091,12 @@ int Analog_Value_Event_Information( /* Acked_Transitions property, which has at least one of the bits (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */ IsNotAckedTransitions = - (AV_Descr[index]. - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == - false) | (AV_Descr[index]. - Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == - false) | (AV_Descr[index]. - Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false); + (AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked == + false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT]. + bIsAcked == + false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL]. + bIsAcked == false); } else return -1; /* end of list */ @@ -1117,8 +1111,8 @@ int Analog_Value_Event_Information( bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, - AV_Descr[index]. - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); + AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked); bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_FAULT, AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); @@ -1136,14 +1130,14 @@ int Analog_Value_Event_Information( /* Event Enable */ bitstring_init(&getevent_data->eventEnable); bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, - (AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : - false); + (AV_Descr[index]. + Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false); bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT, - (AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : - false); + (AV_Descr[index]. + Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false); bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL, - (AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : - false); + (AV_Descr[index]. + Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false); /* Event Priorities */ Notification_Class_Get_Priorities(AV_Descr[index].Notification_Class, getevent_data->eventPriorities); @@ -1162,8 +1156,8 @@ int Analog_Value_Alarm_Ack( object_index = - Analog_Value_Instance_To_Index(alarmack_data-> - eventObjectIdentifier.instance); + Analog_Value_Instance_To_Index(alarmack_data->eventObjectIdentifier. + instance); if (object_index < MAX_ANALOG_VALUES) CurrentAV = &AV_Descr[object_index]; @@ -1176,22 +1170,22 @@ int Analog_Value_Alarm_Ack( case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - if (CurrentAV-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { + if (CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked == false) { if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAV->Acked_Transitions - [TRANSITION_TO_OFFNORMAL].Time_Stamp, + if (datetime_compare(&CurrentAV-> + Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } /* Clean transitions flag. */ - CurrentAV-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = true; + CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked = true; } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; @@ -1205,8 +1199,8 @@ int Analog_Value_Alarm_Ack( *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAV->Acked_Transitions - [TRANSITION_TO_NORMAL].Time_Stamp, + if (datetime_compare(&CurrentAV-> + Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; @@ -1228,8 +1222,8 @@ int Analog_Value_Alarm_Ack( *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAV->Acked_Transitions - [TRANSITION_TO_FAULT].Time_Stamp, + if (datetime_compare(&CurrentAV-> + Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; @@ -1277,16 +1271,16 @@ int Analog_Value_Alarm_Summary( bitstring_init(&getalarm_data->acknowledgedTransitions); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, - AV_Descr[index]. - Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); + AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, TRANSITION_TO_FAULT, - AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT]. - bIsAcked); + AV_Descr[index]. + Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, - AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL]. - bIsAcked); + AV_Descr[index]. + Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); return 1; /* active alarm */ } else diff --git a/bacnet-stack/demo/object/bo.c b/bacnet-stack/demo/object/bo.c index 9255b91d..1b0fcd49 100644 --- a/bacnet-stack/demo/object/bo.c +++ b/bacnet-stack/demo/object/bo.c @@ -383,8 +383,8 @@ bool Binary_Output_Write_Property( (value.type.Enumerated <= MAX_BINARY_PV)) { level = (BACNET_BINARY_PV) value.type.Enumerated; object_index = - Binary_Output_Instance_To_Index(wp_data-> - object_instance); + Binary_Output_Instance_To_Index + (wp_data->object_instance); priority--; Binary_Output_Level[object_index][priority] = level; /* Note: you could set the physical output here if we @@ -410,8 +410,8 @@ bool Binary_Output_Write_Property( if (status) { level = BINARY_NULL; object_index = - Binary_Output_Instance_To_Index(wp_data-> - object_instance); + Binary_Output_Instance_To_Index + (wp_data->object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; diff --git a/bacnet-stack/demo/object/bv.c b/bacnet-stack/demo/object/bv.c index 231e094d..e841fabf 100644 --- a/bacnet-stack/demo/object/bv.c +++ b/bacnet-stack/demo/object/bv.c @@ -366,8 +366,8 @@ bool Binary_Value_Write_Property( (value.type.Enumerated <= MAX_BINARY_PV)) { level = (BACNET_BINARY_PV) value.type.Enumerated; object_index = - Binary_Value_Instance_To_Index(wp_data-> - object_instance); + Binary_Value_Instance_To_Index + (wp_data->object_instance); priority--; Binary_Value_Level[object_index][priority] = level; /* Note: you could set the physical output here if we @@ -393,8 +393,8 @@ bool Binary_Value_Write_Property( if (status) { level = BINARY_NULL; object_index = - Binary_Value_Instance_To_Index(wp_data-> - object_instance); + Binary_Value_Instance_To_Index + (wp_data->object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; diff --git a/bacnet-stack/demo/object/csv.c b/bacnet-stack/demo/object/csv.c index 7662158a..abe73584 100644 --- a/bacnet-stack/demo/object/csv.c +++ b/bacnet-stack/demo/object/csv.c @@ -357,8 +357,8 @@ int CharacterString_Value_Read_Property( break; case PROP_OUT_OF_SERVICE: object_index = - CharacterString_Value_Instance_To_Index(rpdata-> - object_instance); + CharacterString_Value_Instance_To_Index + (rpdata->object_instance); state = Out_Of_Service[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; @@ -406,8 +406,8 @@ bool CharacterString_Value_Write_Property( &wp_data->error_code); if (status) { status = - CharacterString_Value_Present_Value_Set(wp_data-> - object_instance, &value.type.Character_String); + CharacterString_Value_Present_Value_Set + (wp_data->object_instance, &value.type.Character_String); if (!status) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; @@ -419,8 +419,8 @@ bool CharacterString_Value_Write_Property( WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, &wp_data->error_class, &wp_data->error_code); if (status) { - CharacterString_Value_Out_Of_Service_Set(wp_data-> - object_instance, value.type.Boolean); + CharacterString_Value_Out_Of_Service_Set + (wp_data->object_instance, value.type.Boolean); } break; case PROP_OBJECT_IDENTIFIER: diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index 77aaf452..a8f97cb2 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -1161,8 +1161,8 @@ int Device_Read_Property_Local( { int apdu_len = 0; /* return value */ int len = 0; /* apdu len intermediate value */ - BACNET_BIT_STRING bit_string = {0}; - BACNET_CHARACTER_STRING char_string = {0}; + BACNET_BIT_STRING bit_string = { 0 }; + BACNET_CHARACTER_STRING char_string = { 0 }; unsigned i = 0; int object_type = 0; uint32_t instance = 0; @@ -1454,8 +1454,8 @@ bool Device_Write_Property_Local( &wp_data->error_class, &wp_data->error_code); if (status) { if ((value.type.Object_Id.type == OBJECT_DEVICE) && - (Device_Set_Object_Instance_Number(value.type.Object_Id. - instance))) { + (Device_Set_Object_Instance_Number(value.type. + Object_Id.instance))) { /* FIXME: we could send an I-Am broadcast to let the world know */ } else { status = false; @@ -1488,8 +1488,8 @@ bool Device_Write_Property_Local( &wp_data->error_class, &wp_data->error_code); if (status) { /* FIXME: bounds check? */ - Device_Set_Vendor_Identifier((uint16_t) value.type. - Unsigned_Int); + Device_Set_Vendor_Identifier((uint16_t) value. + type.Unsigned_Int); } break; case PROP_SYSTEM_STATUS: @@ -1519,7 +1519,7 @@ bool Device_Write_Property_Local( if (status) { /* All the object names in a device must be unique */ if (Device_Valid_Object_Name(&value.type.Character_String, - &object_type, &object_instance)) { + &object_type, &object_instance)) { if ((object_type == wp_data->object_type) && (object_instance == wp_data->object_instance)) { /* writing same name to same object */ @@ -1539,8 +1539,8 @@ bool Device_Write_Property_Local( WPValidateString(&value, MAX_DEV_LOC_LEN, true, &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Location(characterstring_value(&value.type. - Character_String), + Device_Set_Location(characterstring_value(&value. + type.Character_String), characterstring_length(&value.type.Character_String)); } break; @@ -1550,8 +1550,8 @@ bool Device_Write_Property_Local( WPValidateString(&value, MAX_DEV_DESC_LEN, true, &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Description(characterstring_value(&value.type. - Character_String), + Device_Set_Description(characterstring_value(&value. + type.Character_String), characterstring_length(&value.type.Character_String)); } break; @@ -1560,8 +1560,8 @@ bool Device_Write_Property_Local( WPValidateString(&value, MAX_DEV_MOD_LEN, true, &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Model_Name(characterstring_value(&value.type. - Character_String), + Device_Set_Model_Name(characterstring_value(&value. + type.Character_String), characterstring_length(&value.type.Character_String)); } break; @@ -1573,8 +1573,8 @@ bool Device_Write_Property_Local( &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Unsigned_Int <= 255) { - dlmstp_set_max_info_frames((uint8_t) value.type. - Unsigned_Int); + dlmstp_set_max_info_frames((uint8_t) value. + type.Unsigned_Int); } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; diff --git a/bacnet-stack/demo/object/device.h b/bacnet-stack/demo/object/device.h index 92656e9b..85c222c8 100644 --- a/bacnet-stack/demo/object/device.h +++ b/bacnet-stack/demo/object/device.h @@ -440,15 +440,11 @@ extern "C" { * - The interface between the implemented Objects and the BAC-stack services, * specifically the handlers, which are mediated through function calls to * the Device object. - */ - -/** @defgroup ObjHelpers Object Helper Functions + *//** @defgroup ObjHelpers Object Helper Functions * @ingroup ObjFrmwk * This section describes the function templates for the helper functions that * provide common object support. - */ - -/** @defgroup ObjIntf Handler-to-Object Interface Functions + *//** @defgroup ObjIntf Handler-to-Object Interface Functions * @ingroup ObjFrmwk * This section describes the fairly limited set of functions that link the * BAC-stack handlers to the BACnet Object instances. All of these calls are diff --git a/bacnet-stack/demo/object/gw_device.c b/bacnet-stack/demo/object/gw_device.c index fcb7226b..456722d8 100644 --- a/bacnet-stack/demo/object/gw_device.c +++ b/bacnet-stack/demo/object/gw_device.c @@ -492,8 +492,8 @@ bool Routed_Device_Write_Property_Local( &wp_data->error_class, &wp_data->error_code); if (status) { if ((value.type.Object_Id.type == OBJECT_DEVICE) && - (Routed_Device_Set_Object_Instance_Number(value. - type.Object_Id.instance))) { + (Routed_Device_Set_Object_Instance_Number(value.type. + Object_Id.instance))) { /* FIXME: we could send an I-Am broadcast to let the world know */ } else { status = false; @@ -507,8 +507,8 @@ bool Routed_Device_Write_Property_Local( WPValidateString(&value, MAX_DEV_NAME_LEN, false, &wp_data->error_class, &wp_data->error_code); if (status) { - Routed_Device_Set_Object_Name(characterstring_encoding - (&value.type.Character_String), + Routed_Device_Set_Object_Name(characterstring_encoding(&value. + type.Character_String), characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String)); } diff --git a/bacnet-stack/demo/object/lo.c b/bacnet-stack/demo/object/lo.c index 399593df..4374c34f 100644 --- a/bacnet-stack/demo/object/lo.c +++ b/bacnet-stack/demo/object/lo.c @@ -466,8 +466,8 @@ int Lighting_Output_Read_Property( object_index = Lighting_Output_Instance_To_Index(rpdata->object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { - if (Lighting_Output_Level[object_index][rpdata-> - array_index - 1] == LIGHTING_LEVEL_NULL) + if (Lighting_Output_Level[object_index][rpdata->array_index + - 1] == LIGHTING_LEVEL_NULL) apdu_len = encode_application_null(&apdu[0]); else { real_value = Lighting_Output_Level[object_index] @@ -551,11 +551,11 @@ bool Lighting_Output_Write_Property( if (status) { level = LIGHTING_LEVEL_NULL; object_index = - Lighting_Output_Instance_To_Index(wp_data-> - object_instance); + Lighting_Output_Instance_To_Index + (wp_data->object_instance); status = - Lighting_Output_Present_Value_Relinquish(wp_data-> - object_instance, wp_data->priority); + Lighting_Output_Present_Value_Relinquish + (wp_data->object_instance, wp_data->priority); if (wp_data->priority == 6) { /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any @@ -582,8 +582,8 @@ bool Lighting_Output_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { object_index = - Lighting_Output_Instance_To_Index(wp_data-> - object_instance); + Lighting_Output_Instance_To_Index + (wp_data->object_instance); Lighting_Output_Out_Of_Service[object_index] = value.type.Boolean; } diff --git a/bacnet-stack/demo/object/lsp.c b/bacnet-stack/demo/object/lsp.c index b2b3a00d..efb81522 100644 --- a/bacnet-stack/demo/object/lsp.c +++ b/bacnet-stack/demo/object/lsp.c @@ -338,8 +338,8 @@ bool Life_Safety_Point_Write_Property( if (status) { if (value.type.Enumerated <= MAX_LIFE_SAFETY_MODE) { object_index = - Life_Safety_Point_Instance_To_Index(wp_data-> - object_instance); + Life_Safety_Point_Instance_To_Index + (wp_data->object_instance); Life_Safety_Point_Mode[object_index] = value.type.Enumerated; } else { @@ -355,8 +355,8 @@ bool Life_Safety_Point_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { object_index = - Life_Safety_Point_Instance_To_Index(wp_data-> - object_instance); + Life_Safety_Point_Instance_To_Index + (wp_data->object_instance); Life_Safety_Point_Out_Of_Service[object_index] = value.type.Boolean; } diff --git a/bacnet-stack/demo/object/ms-input.c b/bacnet-stack/demo/object/ms-input.c index d2c97393..bda34faf 100644 --- a/bacnet-stack/demo/object/ms-input.c +++ b/bacnet-stack/demo/object/ms-input.c @@ -262,9 +262,9 @@ bool Multistate_Input_Description_Set( static bool Multistate_Input_Description_Write( uint32_t object_instance, - BACNET_CHARACTER_STRING *char_string, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code) + BACNET_CHARACTER_STRING * char_string, + BACNET_ERROR_CLASS * error_class, + BACNET_ERROR_CODE * error_code) { unsigned index = 0; /* offset from instance lookup */ size_t length = 0; @@ -277,10 +277,9 @@ static bool Multistate_Input_Description_Write( if (length <= sizeof(Object_Description[index])) { encoding = characterstring_encoding(char_string); if (encoding == CHARACTER_UTF8) { - status = characterstring_ansi_copy( - Object_Description[index], - sizeof(Object_Description[index]), - char_string); + status = + characterstring_ansi_copy(Object_Description[index], + sizeof(Object_Description[index]), char_string); if (!status) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; @@ -346,9 +345,9 @@ bool Multistate_Input_Name_Set( static bool Multistate_Input_Object_Name_Write( uint32_t object_instance, - BACNET_CHARACTER_STRING *char_string, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code) + BACNET_CHARACTER_STRING * char_string, + BACNET_ERROR_CLASS * error_class, + BACNET_ERROR_CODE * error_code) { unsigned index = 0; /* offset from instance lookup */ size_t length = 0; @@ -361,10 +360,9 @@ static bool Multistate_Input_Object_Name_Write( if (length <= sizeof(Object_Name[index])) { encoding = characterstring_encoding(char_string); if (encoding == CHARACTER_UTF8) { - status = characterstring_ansi_copy( - Object_Name[index], - sizeof(Object_Name[index]), - char_string); + status = + characterstring_ansi_copy(Object_Name[index], + sizeof(Object_Name[index]), char_string); if (!status) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; @@ -434,9 +432,9 @@ bool Multistate_Input_State_Text_Set( static bool Multistate_Input_State_Text_Write( uint32_t object_instance, uint32_t state_index, - BACNET_CHARACTER_STRING *char_string, - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code) + BACNET_CHARACTER_STRING * char_string, + BACNET_ERROR_CLASS * error_class, + BACNET_ERROR_CODE * error_code) { unsigned index = 0; /* offset from instance lookup */ size_t length = 0; @@ -451,10 +449,9 @@ static bool Multistate_Input_State_Text_Write( if (length <= sizeof(State_Text[index][state_index])) { encoding = characterstring_encoding(char_string); if (encoding == CHARACTER_UTF8) { - status = characterstring_ansi_copy( - State_Text[index][state_index], - sizeof(State_Text[index][state_index]), - char_string); + status = + characterstring_ansi_copy(State_Text[index][state_index], + sizeof(State_Text[index][state_index]), char_string); if (!status) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; @@ -562,7 +559,8 @@ int Multistate_Input_Read_Property( } else if (rpdata->array_index == BACNET_ARRAY_ALL) { /* if no index was specified, then try to encode the entire list */ /* into one packet. */ - max_states = Multistate_Input_Max_States(rpdata->object_instance); + max_states = + Multistate_Input_Max_States(rpdata->object_instance); for (i = 1; i <= max_states; i++) { characterstring_init_ansi(&char_string, Multistate_Input_State_Text(rpdata->object_instance, @@ -582,7 +580,8 @@ int Multistate_Input_Read_Property( } } } else { - max_states = Multistate_Input_Max_States(rpdata->object_instance); + max_states = + Multistate_Input_Max_States(rpdata->object_instance); if (rpdata->array_index <= max_states) { characterstring_init_ansi(&char_string, Multistate_Input_State_Text(rpdata->object_instance, @@ -650,7 +649,7 @@ bool Multistate_Input_Write_Property( if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { /* All the object names in a device must be unique */ if (Device_Valid_Object_Name(&value.type.Character_String, - &object_type, &object_instance)) { + &object_type, &object_instance)) { if ((object_type == wp_data->object_type) && (object_instance == wp_data->object_instance)) { /* writing same name to same object */ @@ -661,11 +660,10 @@ bool Multistate_Input_Write_Property( wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; } } else { - status = Multistate_Input_Object_Name_Write( - wp_data->object_instance, - &value.type.Character_String, - &wp_data->error_class, - &wp_data->error_code); + status = + Multistate_Input_Object_Name_Write(wp_data-> + object_instance, &value.type.Character_String, + &wp_data->error_class, &wp_data->error_code); } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -674,11 +672,10 @@ bool Multistate_Input_Write_Property( break; case PROP_DESCRIPTION: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - status = Multistate_Input_Description_Write( - wp_data->object_instance, - &value.type.Character_String, - &wp_data->error_class, - &wp_data->error_code); + status = + Multistate_Input_Description_Write(wp_data-> + object_instance, &value.type.Character_String, + &wp_data->error_class, &wp_data->error_code); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; @@ -690,8 +687,8 @@ bool Multistate_Input_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { status = - Multistate_Input_Present_Value_Set(wp_data-> - object_instance, value.type.Unsigned_Int); + Multistate_Input_Present_Value_Set + (wp_data->object_instance, value.type.Unsigned_Int); if (!status) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; @@ -716,44 +713,43 @@ bool Multistate_Input_Write_Property( wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; } else if (wp_data->array_index == BACNET_ARRAY_ALL) { - max_states = Multistate_Input_Max_States( - wp_data->object_instance); + max_states = + Multistate_Input_Max_States(wp_data->object_instance); array_index = 1; element_len = len; do { if (element_len) { - status = Multistate_Input_State_Text_Write( - wp_data->object_instance, - array_index, + status = + Multistate_Input_State_Text_Write(wp_data-> + object_instance, array_index, &value.type.Character_String, - &wp_data->error_class, - &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); } max_states--; array_index++; if (max_states) { - element_len = bacapp_decode_application_data( - &wp_data->application_data[len], - wp_data->application_data_len-len, - &value); + element_len = + bacapp_decode_application_data(&wp_data-> + application_data[len], + wp_data->application_data_len - len, &value); if (element_len < 0) { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + wp_data->error_code = + ERROR_CODE_VALUE_OUT_OF_RANGE; break; } len += element_len; } } while (max_states); } else { - max_states = Multistate_Input_Max_States( - wp_data->object_instance); + max_states = + Multistate_Input_Max_States(wp_data->object_instance); if (wp_data->array_index <= max_states) { - status = Multistate_Input_State_Text_Write( - wp_data->object_instance, - wp_data->array_index, + status = + Multistate_Input_State_Text_Write(wp_data-> + object_instance, wp_data->array_index, &value.type.Character_String, - &wp_data->error_class, - &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; diff --git a/bacnet-stack/demo/object/mso.c b/bacnet-stack/demo/object/mso.c index f1320542..87759b1d 100644 --- a/bacnet-stack/demo/object/mso.c +++ b/bacnet-stack/demo/object/mso.c @@ -268,8 +268,8 @@ int Multistate_Output_Read_Property( /* into one packet. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { object_index = - Multistate_Output_Instance_To_Index(rpdata-> - object_instance); + Multistate_Output_Instance_To_Index + (rpdata->object_instance); for (i = 0; i < BACNET_MAX_PRIORITY; i++) { /* FIXME: check if we have room before adding it to APDU */ if (Multistate_Output_Level[object_index][i] == @@ -294,8 +294,8 @@ int Multistate_Output_Read_Property( } } else { object_index = - Multistate_Output_Instance_To_Index(rpdata-> - object_instance); + Multistate_Output_Instance_To_Index + (rpdata->object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { if (Multistate_Output_Level[object_index] [rpdata->array_index - 1] == MULTISTATE_NULL) @@ -386,8 +386,8 @@ bool Multistate_Output_Write_Property( (value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) { level = value.type.Unsigned_Int; object_index = - Multistate_Output_Instance_To_Index(wp_data-> - object_instance); + Multistate_Output_Instance_To_Index + (wp_data->object_instance); priority--; Multistate_Output_Level[object_index][priority] = (uint8_t) level; @@ -414,8 +414,8 @@ bool Multistate_Output_Write_Property( if (status) { level = MULTISTATE_NULL; object_index = - Multistate_Output_Instance_To_Index(wp_data-> - object_instance); + Multistate_Output_Instance_To_Index + (wp_data->object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; @@ -441,8 +441,8 @@ bool Multistate_Output_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { object_index = - Multistate_Output_Instance_To_Index(wp_data-> - object_instance); + Multistate_Output_Instance_To_Index + (wp_data->object_instance); Multistate_Output_Out_Of_Service[object_index] = value.type.Boolean; } diff --git a/bacnet-stack/demo/object/msv.c b/bacnet-stack/demo/object/msv.c index 3457df80..1293b0e5 100644 --- a/bacnet-stack/demo/object/msv.c +++ b/bacnet-stack/demo/object/msv.c @@ -438,8 +438,8 @@ int Multistate_Value_Read_Property( /* if no index was specified, then try to encode the entire list */ /* into one packet. */ object_index = - Multistate_Value_Instance_To_Index(rpdata-> - object_instance); + Multistate_Value_Instance_To_Index + (rpdata->object_instance); for (i = 1; i <= MULTISTATE_NUMBER_OF_STATES; i++) { characterstring_init_ansi(&char_string, Multistate_Value_State_Text(rpdata->object_instance, @@ -460,8 +460,8 @@ int Multistate_Value_Read_Property( } } else { object_index = - Multistate_Value_Instance_To_Index(rpdata-> - object_instance); + Multistate_Value_Instance_To_Index + (rpdata->object_instance); if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) { characterstring_init_ansi(&char_string, Multistate_Value_State_Text(rpdata->object_instance, @@ -528,8 +528,8 @@ bool Multistate_Value_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { status = - Multistate_Value_Present_Value_Set(wp_data-> - object_instance, value.type.Unsigned_Int); + Multistate_Value_Present_Value_Set + (wp_data->object_instance, value.type.Unsigned_Int); if (!status) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; diff --git a/bacnet-stack/demo/object/nc.c b/bacnet-stack/demo/object/nc.c index 28e4658a..bf3dacdc 100644 --- a/bacnet-stack/demo/object/nc.c +++ b/bacnet-stack/demo/object/nc.c @@ -189,8 +189,8 @@ int Notification_Class_Read_Property( apdu = rpdata->application_data; CurrentNotify = - &NC_Info[Notification_Class_Instance_To_Index - (rpdata->object_instance)]; + &NC_Info[Notification_Class_Instance_To_Index(rpdata-> + object_instance)]; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: @@ -400,8 +400,8 @@ bool Notification_Class_Write_Property( CurrentNotify = - &NC_Info[Notification_Class_Instance_To_Index - (wp_data->object_instance)]; + &NC_Info[Notification_Class_Instance_To_Index(wp_data-> + object_instance)]; /* decode the some of the request */ @@ -467,8 +467,9 @@ bool Notification_Class_Write_Property( while (iOffset < wp_data->application_data_len) { /* Decode Valid Days */ len = - bacapp_decode_application_data(&wp_data->application_data - [iOffset], wp_data->application_data_len, &value); + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], wp_data->application_data_len, + &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { @@ -491,8 +492,9 @@ bool Notification_Class_Write_Property( iOffset += len; /* Decode From Time */ len = - bacapp_decode_application_data(&wp_data->application_data - [iOffset], wp_data->application_data_len, &value); + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], wp_data->application_data_len, + &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) { /* Bad decode, wrong tag or following required parameter missing */ @@ -506,8 +508,9 @@ bool Notification_Class_Write_Property( iOffset += len; /* Decode To Time */ len = - bacapp_decode_application_data(&wp_data->application_data - [iOffset], wp_data->application_data_len, &value); + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], wp_data->application_data_len, + &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) { /* Bad decode, wrong tag or following required parameter missing */ @@ -526,8 +529,9 @@ bool Notification_Class_Write_Property( RECIPIENT_TYPE_DEVICE; /* Decode Network Number */ len = - bacapp_decode_context_data(&wp_data->application_data - [iOffset], wp_data->application_data_len, &value, + bacapp_decode_context_data(&wp_data-> + application_data[iOffset], + wp_data->application_data_len, &value, PROP_RECIPIENT_LIST); if ((len == 0) || @@ -538,21 +542,21 @@ bool Notification_Class_Write_Property( return false; } /* store value */ - TmpNotify.Recipient_List[idx].Recipient. - _.DeviceIdentifier = value.type.Object_Id.instance; + TmpNotify.Recipient_List[idx].Recipient._. + DeviceIdentifier = value.type.Object_Id.instance; iOffset += len; } /* opening tag [1] - Recipient */ - else if (decode_is_opening_tag_number - (&wp_data->application_data[iOffset], 1)) { + else if (decode_is_opening_tag_number(&wp_data-> + application_data[iOffset], 1)) { iOffset++; TmpNotify.Recipient_List[idx].Recipient.RecipientType = RECIPIENT_TYPE_ADDRESS; /* Decode Network Number */ len = - bacapp_decode_application_data - (&wp_data->application_data[iOffset], + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], wp_data->application_data_len, &value); if ((len == 0) || @@ -569,8 +573,8 @@ bool Notification_Class_Write_Property( iOffset += len; /* Decode Address */ len = - bacapp_decode_application_data - (&wp_data->application_data[iOffset], + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], wp_data->application_data_len, &value); if ((len == 0) || @@ -581,16 +585,16 @@ bool Notification_Class_Write_Property( return false; } /* store value */ - if (TmpNotify.Recipient_List[idx].Recipient._. - Address.net == 0) { - memcpy(TmpNotify.Recipient_List[idx].Recipient. - _.Address.mac, value.type.Octet_String.value, + if (TmpNotify.Recipient_List[idx].Recipient._.Address. + net == 0) { + memcpy(TmpNotify.Recipient_List[idx].Recipient._. + Address.mac, value.type.Octet_String.value, value.type.Octet_String.length); - TmpNotify.Recipient_List[idx].Recipient._. - Address.mac_len = value.type.Octet_String.length; + TmpNotify.Recipient_List[idx].Recipient._.Address. + mac_len = value.type.Octet_String.length; } else { - memcpy(TmpNotify.Recipient_List[idx].Recipient. - _.Address.adr, value.type.Octet_String.value, + memcpy(TmpNotify.Recipient_List[idx].Recipient._. + Address.adr, value.type.Octet_String.value, value.type.Octet_String.length); TmpNotify.Recipient_List[idx].Recipient._.Address.len = value.type.Octet_String.length; @@ -598,8 +602,8 @@ bool Notification_Class_Write_Property( iOffset += len; /* closing tag [1] - Recipient */ - if (decode_is_closing_tag_number(&wp_data->application_data - [iOffset], 1)) + if (decode_is_closing_tag_number(&wp_data-> + application_data[iOffset], 1)) iOffset++; else { /* Bad decode, wrong tag or following required parameter missing */ @@ -616,8 +620,9 @@ bool Notification_Class_Write_Property( /* Process Identifier */ len = - bacapp_decode_application_data(&wp_data->application_data - [iOffset], wp_data->application_data_len, &value); + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], wp_data->application_data_len, + &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) { @@ -633,8 +638,9 @@ bool Notification_Class_Write_Property( iOffset += len; /* Issue Confirmed Notifications */ len = - bacapp_decode_application_data(&wp_data->application_data - [iOffset], wp_data->application_data_len, &value); + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], wp_data->application_data_len, + &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) { @@ -650,8 +656,9 @@ bool Notification_Class_Write_Property( iOffset += len; /* Transitions */ len = - bacapp_decode_application_data(&wp_data->application_data - [iOffset], wp_data->application_data_len, &value); + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], wp_data->application_data_len, + &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { @@ -692,16 +699,16 @@ bool Notification_Class_Write_Property( CurrentNotify->Recipient_List[idx] = TmpNotify.Recipient_List[idx]; - if (CurrentNotify->Recipient_List[idx]. - Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { + if (CurrentNotify->Recipient_List[idx].Recipient. + RecipientType == RECIPIENT_TYPE_DEVICE) { /* copy Device_ID */ DeviceID = - CurrentNotify->Recipient_List[idx].Recipient. - _.DeviceIdentifier; + CurrentNotify->Recipient_List[idx].Recipient._. + DeviceIdentifier; address_bind_request(DeviceID, &max_apdu, &src); - } else if (CurrentNotify->Recipient_List[idx]. - Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { + } else if (CurrentNotify->Recipient_List[idx].Recipient. + RecipientType == RECIPIENT_TYPE_ADDRESS) { /* copy Address */ /* src = CurrentNotify->Recipient_List[idx].Recipient._.Address; */ /* address_bind_request(BACNET_MAX_INSTANCE, &max_apdu, &src); */ @@ -824,16 +831,16 @@ void Notification_Class_common_reporting_function( event_data->priority = CurrentNotify->Priority[TRANSITION_TO_NORMAL]; event_data->ackRequired = - (CurrentNotify->Ack_Required & TRANSITION_TO_NORMAL_MASKED) ? - true : false; + (CurrentNotify-> + Ack_Required & TRANSITION_TO_NORMAL_MASKED) ? true : false; break; case EVENT_STATE_FAULT: event_data->priority = CurrentNotify->Priority[TRANSITION_TO_FAULT]; event_data->ackRequired = - (CurrentNotify->Ack_Required & TRANSITION_TO_FAULT_MASKED) ? - true : false; + (CurrentNotify-> + Ack_Required & TRANSITION_TO_FAULT_MASKED) ? true : false; break; case EVENT_STATE_OFFNORMAL: @@ -918,13 +925,13 @@ void Notification_Class_find_recipient( RECIPIENT_TYPE_DEVICE) { /* Device ID */ DeviceID = - CurrentNotify->Recipient_List[idx].Recipient. - _.DeviceIdentifier; + CurrentNotify->Recipient_List[idx].Recipient._. + DeviceIdentifier; /* Send who_ is request only when address of device is unknown. */ if (!address_bind_request(DeviceID, &max_apdu, &src)) Send_WhoIs(DeviceID, DeviceID); - } else if (CurrentNotify->Recipient_List[idx]. - Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { + } else if (CurrentNotify->Recipient_List[idx].Recipient. + RecipientType == RECIPIENT_TYPE_ADDRESS) { } } diff --git a/bacnet-stack/demo/object/trendlog.c b/bacnet-stack/demo/object/trendlog.c index 40461153..c48f78ef 100644 --- a/bacnet-stack/demo/object/trendlog.c +++ b/bacnet-stack/demo/object/trendlog.c @@ -743,9 +743,9 @@ bool Trend_Log_Write_Property( if (wp_data->application_data_len != 0) { iOffset += len; len = - bacapp_decode_context_data(&wp_data-> - application_data[iOffset], wp_data->application_data_len, - &value, PROP_LOG_DEVICE_OBJECT_PROPERTY); + bacapp_decode_context_data(&wp_data->application_data + [iOffset], wp_data->application_data_len, &value, + PROP_LOG_DEVICE_OBJECT_PROPERTY); if ((len == 0) || ((value.context_tag != 2) && (value.context_tag != 3))) { /* Bad decode or wrong tag */ @@ -762,8 +762,8 @@ bool Trend_Log_Write_Property( if (wp_data->application_data_len != 0) { iOffset += len; len = - bacapp_decode_context_data(&wp_data-> - application_data[iOffset], + bacapp_decode_context_data + (&wp_data->application_data[iOffset], wp_data->application_data_len, &value, PROP_LOG_DEVICE_OBJECT_PROPERTY); if ((len == 0) || (value.context_tag != 3)) { @@ -1105,8 +1105,8 @@ int rr_trend_log_encode( pRequest->ItemCount = 0; /* Start out with nothing */ /* Bail out now if nowt - should never happen for a Trend Log but ... */ - if (LogInfo[Trend_Log_Instance_To_Index(pRequest->object_instance)]. - ulRecordCount == 0) + if (LogInfo[Trend_Log_Instance_To_Index(pRequest-> + object_instance)].ulRecordCount == 0) return (0); if ((pRequest->RequestType == RR_BY_POSITION) || diff --git a/bacnet-stack/demo/perl/perl_bindings.c b/bacnet-stack/demo/perl/perl_bindings.c index 5c0fb281..25442664 100644 --- a/bacnet-stack/demo/perl/perl_bindings.c +++ b/bacnet-stack/demo/perl/perl_bindings.c @@ -223,10 +223,10 @@ void rpm_ack_extract_data( } else { /* AccessError */ sprintf(ackString, "BACnet Error: %s: %s", - bactext_error_class_name((int) listOfProperties->error. - error_class), - bactext_error_code_name((int) listOfProperties->error. - error_code)); + bactext_error_class_name((int) listOfProperties-> + error.error_class), + bactext_error_code_name((int) listOfProperties-> + error.error_code)); LogError(ackString); } listOfProperties = listOfProperties->next; diff --git a/bacnet-stack/demo/readbdt/main.c b/bacnet-stack/demo/readbdt/main.c index aebc785c..0d07e10c 100644 --- a/bacnet-stack/demo/readbdt/main.c +++ b/bacnet-stack/demo/readbdt/main.c @@ -126,16 +126,14 @@ int main( return 0; } if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { - printf("Send a Read-Broadcast-Distribution-Table message to a BBMD.\r\n" - "\r\n" - "IP:\r\n" + printf + ("Send a Read-Broadcast-Distribution-Table message to a BBMD.\r\n" + "\r\n" "IP:\r\n" "IP address of the BBMD in dotted decimal notation\r\n" "[port]\r\n" - "optional BACnet/IP port number (default=47808=0xBAC0)\r\n" - "\r\n" + "optional BACnet/IP port number (default=47808=0xBAC0)\r\n" "\r\n" "To send a Read-Broadcast-Distribution-Table message to a BBMD\r\n" - "at 192.168.0.1 using port 47808:\r\n" - "%s 192.168.0.1 47808\r\n", + "at 192.168.0.1 using port 47808:\r\n" "%s 192.168.0.1 47808\r\n", filename_remove_path(argv[0])); return 0; } @@ -143,8 +141,7 @@ int main( if (argc > 1) { Target_BBMD_Address = inet_addr(argv[1]); if (Target_BBMD_Address == (-1)) { - fprintf(stderr, "IP=%s - failed to convert address.\r\n", - argv[1]); + fprintf(stderr, "IP=%s - failed to convert address.\r\n", argv[1]); return 1; } } diff --git a/bacnet-stack/demo/readprop/main.c b/bacnet-stack/demo/readprop/main.c index 4e7e00fc..214d78cd 100644 --- a/bacnet-stack/demo/readprop/main.c +++ b/bacnet-stack/demo/readprop/main.c @@ -258,7 +258,8 @@ int main( /* at least one second has passed */ if (current_seconds != last_seconds) - tsm_timer_milliseconds((uint16_t)((current_seconds - last_seconds) * 1000)); + tsm_timer_milliseconds((uint16_t) ((current_seconds - + last_seconds) * 1000)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ diff --git a/bacnet-stack/demo/router/ipmodule.c b/bacnet-stack/demo/router/ipmodule.c index 6d7f1132..46d154cf 100644 --- a/bacnet-stack/demo/router/ipmodule.c +++ b/bacnet-stack/demo/router/ipmodule.c @@ -21,9 +21,10 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #include "bacint.h" #ifdef TEST_PACKET - uint8_t test_packet[]={0x81, 0x0a, 0x00, 0x16, /* BVLC header */ - 0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */ - 0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19, 0x55}; /* APDU */ +uint8_t test_packet[] = { 0x81, 0x0a, 0x00, 0x16, /* BVLC header */ + 0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */ + 0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19, 0x55 +}; /* APDU */ #endif extern int get_local_address_ioctl( @@ -31,345 +32,371 @@ extern int get_local_address_ioctl( struct in_addr *addr, int request); -void* dl_ip_thread(void *pArgs) { - MSGBOX_ID msgboxid; - BACMSG msg_storage, *bacmsg = NULL; - MSG_DATA *msg_data; - ROUTER_PORT *port = (ROUTER_PORT*)pArgs; - IP_DATA ip_data; /* port specific parameters */ - BACNET_ADDRESS address = { 0 }; - int status; - uint8_t shutdown = 0; - - /* initialize router port */ - if (!dl_ip_init(port, &ip_data)) { - port->state = INIT_FAILED; - return NULL; - } - - /* allocate buffer */ - ip_data.max_buff = MAX_BIP_MPDU; - ip_data.buff = (uint8_t*)malloc(ip_data.max_buff); - - if (ip_data.buff == NULL) { - port->state = INIT_FAILED; - return NULL; - } - - msgboxid = create_msgbox(); - if (msgboxid == INVALID_MSGBOX_ID) { - PRINT(ERROR, "Error: Failed to create message box"); - port->state = INIT_FAILED; - return NULL; - } - - port->port_id = msgboxid; - port->state = RUNNING; - - while (!shutdown) { - - /* check for incoming messages */ - bacmsg = recv_from_msgbox(port->port_id, &msg_storage); - - if (bacmsg) { - switch(bacmsg->type) { - case DATA: { - msg_data = (MSG_DATA*)bacmsg->data; - memmove(&address.net, &msg_data->dest.net, 2); - memmove(&address.mac_len, &msg_data->dest.len, 1); - memmove(&address.mac[0], &msg_data->dest.adr[0], MAX_MAC_LEN); - - dl_ip_send(&ip_data, &address, msg_data->pdu, msg_data->pdu_len); - - check_data(msg_data); - - break; - } - - case SERVICE: { - switch(bacmsg->subtype) { - case SHUTDOWN: - del_msgbox(port->port_id); - shutdown = 1; - break; - default: - break; - } - break; - } - - default: - break; - } - } else { - status = dl_ip_recv(&ip_data, &msg_data, &address, 1000); - if (status > 0) { - memmove(&msg_data->src.len, &address.mac_len, 1); - memmove(&msg_data->src.adr[0], &address.mac[0], MAX_MAC_LEN); - msg_storage.origin = port->port_id; - msg_storage.type = DATA; - msg_storage.data = msg_data; - - if (!send_to_msgbox(port->main_id, &msg_storage)) { - free_data(msg_data); - } - } - } - } - - /* cleanup procedure */ - dl_ip_cleanup(&ip_data); - port->state = FINISHED; - return NULL; -} - -bool dl_ip_init(ROUTER_PORT *port, - IP_DATA *ip_data) { - struct sockaddr_in sin; - int socket_opt = 0; - int status = 0; /* for error checking */ - - /* setup port for later use */ - ip_data->port = htons(port->params.bip_params.port); - - /* get local address */ - status = get_local_address_ioctl(port->iface, &ip_data->local_addr, SIOCGIFADDR); - if (status < 0) { - return false; - } - /* get broadcast address */ - status = get_local_address_ioctl(port->iface, &ip_data->broadcast_addr, SIOCGIFBRDADDR); - if (status < 0) { - return false; - } - - ip_data->socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (ip_data->socket < 0) - return false; - - /* setup socket options */ - - socket_opt = 1; - status = setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt, sizeof(socket_opt)); - if (status < 0) { - close(ip_data->socket); - return false; - } - - status = setsockopt(ip_data->socket, SOL_SOCKET, SO_BROADCAST, &socket_opt, sizeof(socket_opt)); - if (status < 0) { - close(ip_data->socket); - return false; - } - - /* bind the socket to the local port number */ - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_ANY); - sin.sin_port = ip_data->port; - - memset(&sin.sin_zero, '\0', sizeof(sin.sin_zero)); - - status = bind(ip_data->socket, (const struct sockaddr *) &sin, sizeof(struct sockaddr)); - if (status < 0) { - close(ip_data->socket); - return false; - } - - /* add BIP address to router port structure */ - memcpy(&port->route_info.mac[0], &ip_data->local_addr.s_addr, 4); - memcpy(&port->route_info.mac[4], &port->params.bip_params.port, 2); - port->route_info.mac_len = 6; - - PRINT(INFO, "Interface: %s\n", port->iface); - PRINT(INFO, "IP Address: %s\n", inet_ntoa(ip_data->local_addr)); - PRINT(INFO, "IP Broadcast Address: %s\n", inet_ntoa(ip_data->broadcast_addr)); - PRINT(INFO, "UDP Port: 0x%04X [%hu]\n", (port->params.bip_params.port), - (port->params.bip_params.port)); - - return true; -} - -int dl_ip_send(IP_DATA *data, - BACNET_ADDRESS *dest, - uint8_t *pdu, - unsigned pdu_len) +void *dl_ip_thread( + void *pArgs) { - struct sockaddr_in bip_dest = { 0 }; - int buff_len = 0; - int bytes_sent = 0; + MSGBOX_ID msgboxid; + BACMSG msg_storage, *bacmsg = NULL; + MSG_DATA *msg_data; + ROUTER_PORT *port = (ROUTER_PORT *) pArgs; + IP_DATA ip_data; /* port specific parameters */ + BACNET_ADDRESS address = { 0 }; + int status; + uint8_t shutdown = 0; - if (data->socket < 0) - return -1; + /* initialize router port */ + if (!dl_ip_init(port, &ip_data)) { + port->state = INIT_FAILED; + return NULL; + } - data->buff[0] = BVLL_TYPE_BACNET_IP; - bip_dest.sin_family = AF_INET; - if (dest->net == BACNET_BROADCAST_NETWORK) { - /* broadcast */ - bip_dest.sin_addr.s_addr = data->broadcast_addr.s_addr; - bip_dest.sin_port = data->port; - data->buff[1] = BVLC_ORIGINAL_BROADCAST_NPDU; - } else if (dest->mac_len == 6) { - memcpy(&bip_dest.sin_addr.s_addr, &dest->mac[0], 4); - memcpy(&bip_dest.sin_port, &dest->mac[4], 2); - data->buff[1] = BVLC_ORIGINAL_UNICAST_NPDU; - } else { - /* invalid address */ - return -1; - } + /* allocate buffer */ + ip_data.max_buff = MAX_BIP_MPDU; + ip_data.buff = (uint8_t *) malloc(ip_data.max_buff); - buff_len = 2; - buff_len += - encode_unsigned16(&data->buff[buff_len], - (uint16_t) (pdu_len + 4 /*inclusive*/ )); - memcpy(&data->buff[buff_len], pdu, pdu_len); - buff_len += pdu_len; + if (ip_data.buff == NULL) { + port->state = INIT_FAILED; + return NULL; + } - /* send the packet */ - bytes_sent = - sendto(data->socket, (char *) data->buff, buff_len, 0, - (struct sockaddr *) &bip_dest, sizeof(struct sockaddr)); + msgboxid = create_msgbox(); + if (msgboxid == INVALID_MSGBOX_ID) { + PRINT(ERROR, "Error: Failed to create message box"); + port->state = INIT_FAILED; + return NULL; + } - PRINT(DEBUG, "send to %s\n", inet_ntoa(bip_dest.sin_addr)); + port->port_id = msgboxid; + port->state = RUNNING; - return bytes_sent; + while (!shutdown) { + + /* check for incoming messages */ + bacmsg = recv_from_msgbox(port->port_id, &msg_storage); + + if (bacmsg) { + switch (bacmsg->type) { + case DATA:{ + msg_data = (MSG_DATA *) bacmsg->data; + memmove(&address.net, &msg_data->dest.net, 2); + memmove(&address.mac_len, &msg_data->dest.len, 1); + memmove(&address.mac[0], &msg_data->dest.adr[0], + MAX_MAC_LEN); + + dl_ip_send(&ip_data, &address, msg_data->pdu, + msg_data->pdu_len); + + check_data(msg_data); + + break; + } + + case SERVICE:{ + switch (bacmsg->subtype) { + case SHUTDOWN: + del_msgbox(port->port_id); + shutdown = 1; + break; + default: + break; + } + break; + } + + default: + break; + } + } else { + status = dl_ip_recv(&ip_data, &msg_data, &address, 1000); + if (status > 0) { + memmove(&msg_data->src.len, &address.mac_len, 1); + memmove(&msg_data->src.adr[0], &address.mac[0], MAX_MAC_LEN); + msg_storage.origin = port->port_id; + msg_storage.type = DATA; + msg_storage.data = msg_data; + + if (!send_to_msgbox(port->main_id, &msg_storage)) { + free_data(msg_data); + } + } + } + } + + /* cleanup procedure */ + dl_ip_cleanup(&ip_data); + port->state = FINISHED; + return NULL; +} + +bool dl_ip_init( + ROUTER_PORT * port, + IP_DATA * ip_data) +{ + struct sockaddr_in sin; + int socket_opt = 0; + int status = 0; /* for error checking */ + + /* setup port for later use */ + ip_data->port = htons(port->params.bip_params.port); + + /* get local address */ + status = + get_local_address_ioctl(port->iface, &ip_data->local_addr, + SIOCGIFADDR); + if (status < 0) { + return false; + } + /* get broadcast address */ + status = + get_local_address_ioctl(port->iface, &ip_data->broadcast_addr, + SIOCGIFBRDADDR); + if (status < 0) { + return false; + } + + ip_data->socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (ip_data->socket < 0) + return false; + + /* setup socket options */ + + socket_opt = 1; + status = + setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt, + sizeof(socket_opt)); + if (status < 0) { + close(ip_data->socket); + return false; + } + + status = + setsockopt(ip_data->socket, SOL_SOCKET, SO_BROADCAST, &socket_opt, + sizeof(socket_opt)); + if (status < 0) { + close(ip_data->socket); + return false; + } + + /* bind the socket to the local port number */ + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl(INADDR_ANY); + sin.sin_port = ip_data->port; + + memset(&sin.sin_zero, '\0', sizeof(sin.sin_zero)); + + status = + bind(ip_data->socket, (const struct sockaddr *) &sin, + sizeof(struct sockaddr)); + if (status < 0) { + close(ip_data->socket); + return false; + } + + /* add BIP address to router port structure */ + memcpy(&port->route_info.mac[0], &ip_data->local_addr.s_addr, 4); + memcpy(&port->route_info.mac[4], &port->params.bip_params.port, 2); + port->route_info.mac_len = 6; + + PRINT(INFO, "Interface: %s\n", port->iface); + PRINT(INFO, "IP Address: %s\n", inet_ntoa(ip_data->local_addr)); + PRINT(INFO, "IP Broadcast Address: %s\n", + inet_ntoa(ip_data->broadcast_addr)); + PRINT(INFO, "UDP Port: 0x%04X [%hu]\n", (port->params.bip_params.port), + (port->params.bip_params.port)); + + return true; +} + +int dl_ip_send( + IP_DATA * data, + BACNET_ADDRESS * dest, + uint8_t * pdu, + unsigned pdu_len) +{ + struct sockaddr_in bip_dest = { 0 }; + int buff_len = 0; + int bytes_sent = 0; + + if (data->socket < 0) + return -1; + + data->buff[0] = BVLL_TYPE_BACNET_IP; + bip_dest.sin_family = AF_INET; + if (dest->net == BACNET_BROADCAST_NETWORK) { + /* broadcast */ + bip_dest.sin_addr.s_addr = data->broadcast_addr.s_addr; + bip_dest.sin_port = data->port; + data->buff[1] = BVLC_ORIGINAL_BROADCAST_NPDU; + } else if (dest->mac_len == 6) { + memcpy(&bip_dest.sin_addr.s_addr, &dest->mac[0], 4); + memcpy(&bip_dest.sin_port, &dest->mac[4], 2); + data->buff[1] = BVLC_ORIGINAL_UNICAST_NPDU; + } else { + /* invalid address */ + return -1; + } + + buff_len = 2; + buff_len += + encode_unsigned16(&data->buff[buff_len], + (uint16_t) (pdu_len + 4 /*inclusive */ )); + memcpy(&data->buff[buff_len], pdu, pdu_len); + buff_len += pdu_len; + + /* send the packet */ + bytes_sent = + sendto(data->socket, (char *) data->buff, buff_len, 0, + (struct sockaddr *) &bip_dest, sizeof(struct sockaddr)); + + PRINT(DEBUG, "send to %s\n", inet_ntoa(bip_dest.sin_addr)); + + return bytes_sent; } int dl_ip_recv( - IP_DATA *data, - MSG_DATA **msg_data, - BACNET_ADDRESS *src, - unsigned timeout) + IP_DATA * data, + MSG_DATA ** msg_data, + BACNET_ADDRESS * src, + unsigned timeout) { - int received_bytes = 0; - uint16_t buff_len = 0; /* return value */ - fd_set read_fds; - struct timeval select_timeout; - struct sockaddr_in sin = { 0 }; - socklen_t sin_len = sizeof(sin); + int received_bytes = 0; + uint16_t buff_len = 0; /* return value */ + fd_set read_fds; + struct timeval select_timeout; + struct sockaddr_in sin = { 0 }; + socklen_t sin_len = sizeof(sin); - /* make sure the socket is open */ - if (data->socket < 0) - return 0; + /* make sure the socket is open */ + if (data->socket < 0) + return 0; - if (timeout >= 1000) { - select_timeout.tv_sec = timeout / 1000; - select_timeout.tv_usec = 1000 * (timeout - select_timeout.tv_sec * 1000); - } else { - select_timeout.tv_sec = 0; - select_timeout.tv_usec = 1000 * timeout; - } + if (timeout >= 1000) { + select_timeout.tv_sec = timeout / 1000; + select_timeout.tv_usec = + 1000 * (timeout - select_timeout.tv_sec * 1000); + } else { + select_timeout.tv_sec = 0; + select_timeout.tv_usec = 1000 * timeout; + } - FD_ZERO(&read_fds); - FD_SET(data->socket, &read_fds); + FD_ZERO(&read_fds); + FD_SET(data->socket, &read_fds); #ifdef TEST_PACKET - received_bytes = sizeof(test_packet); - memmove(data->buff, &test_packet, received_bytes); - sin.sin_addr.s_addr = 0x7E1D40A; sin.sin_port = 0xC0BA; + received_bytes = sizeof(test_packet); + memmove(data->buff, &test_packet, received_bytes); + sin.sin_addr.s_addr = 0x7E1D40A; + sin.sin_port = 0xC0BA; #else - int ret = select(data->socket + 1, &read_fds, NULL, NULL, &select_timeout); - /* see if there is a packet for us */ - if (ret > 0) - received_bytes = - recvfrom(data->socket, (char *) &data->buff[0], data->max_buff, 0, - (struct sockaddr *) &sin, &sin_len); - else - return 0; + int ret = select(data->socket + 1, &read_fds, NULL, NULL, &select_timeout); + /* see if there is a packet for us */ + if (ret > 0) + received_bytes = + recvfrom(data->socket, (char *) &data->buff[0], data->max_buff, 0, + (struct sockaddr *) &sin, &sin_len); + else + return 0; #endif - PRINT(DEBUG, "received from %s\n", inet_ntoa(sin.sin_addr)); + PRINT(DEBUG, "received from %s\n", inet_ntoa(sin.sin_addr)); - /* check for errors */ - if (received_bytes <= 0) { - return 0; - } + /* check for errors */ + if (received_bytes <= 0) { + return 0; + } - /* the signature of a BACnet/IP packet */ - if (data->buff[0] != BVLL_TYPE_BACNET_IP) - return 0; + /* the signature of a BACnet/IP packet */ + if (data->buff[0] != BVLL_TYPE_BACNET_IP) + return 0; - switch (data->buff[1]) { - case BVLC_ORIGINAL_UNICAST_NPDU: - case BVLC_ORIGINAL_BROADCAST_NPDU: { - if ((sin.sin_addr.s_addr == data->local_addr.s_addr) && - (sin.sin_port == data->port)) { - buff_len = 0; + switch (data->buff[1]) { + case BVLC_ORIGINAL_UNICAST_NPDU: + case BVLC_ORIGINAL_BROADCAST_NPDU:{ + if ((sin.sin_addr.s_addr == data->local_addr.s_addr) && + (sin.sin_port == data->port)) { + buff_len = 0; - PRINT(DEBUG, "BIP: src is me. Discarded!\n"); + PRINT(DEBUG, "BIP: src is me. Discarded!\n"); - } else { - src->mac_len = 6; - memcpy(&src->mac[0], &sin.sin_addr.s_addr, 4); - memcpy(&src->mac[4], &sin.sin_port, 2); + } else { + src->mac_len = 6; + memcpy(&src->mac[0], &sin.sin_addr.s_addr, 4); + memcpy(&src->mac[4], &sin.sin_port, 2); - (void) decode_unsigned16(&data->buff[2], &buff_len); - /* subtract off the BVLC header */ - buff_len -= 4; - if (buff_len < data->max_buff) { - /* allocate data message stucture */ - (*msg_data) = (MSG_DATA*)malloc(sizeof(MSG_DATA)); - (*msg_data)->pdu_len = buff_len; - (*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len); - /* fill up data message structure */ - memmove(&(*msg_data)->pdu[0], &data->buff[4], (*msg_data)->pdu_len); - memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS)); - } - /* ignore packets that are too large */ - else { - buff_len = 0; + (void) decode_unsigned16(&data->buff[2], &buff_len); + /* subtract off the BVLC header */ + buff_len -= 4; + if (buff_len < data->max_buff) { + /* allocate data message stucture */ + (*msg_data) = (MSG_DATA *) malloc(sizeof(MSG_DATA)); + (*msg_data)->pdu_len = buff_len; + (*msg_data)->pdu = + (uint8_t *) malloc((*msg_data)->pdu_len); + /* fill up data message structure */ + memmove(&(*msg_data)->pdu[0], &data->buff[4], + (*msg_data)->pdu_len); + memmove(&(*msg_data)->src, src, + sizeof(BACNET_ADDRESS)); + } + /* ignore packets that are too large */ + else { + buff_len = 0; - PRINT(ERROR, "BIP: PDU too large. Discarded!.\n"); + PRINT(ERROR, "BIP: PDU too large. Discarded!.\n"); - } - } - } - break; + } + } + } + break; - case BVLC_FORWARDED_NPDU: { - memcpy(&sin.sin_addr.s_addr, &data->buff[4], 4); - memcpy(&sin.sin_port, &data->buff[8], 2); - if ((sin.sin_addr.s_addr == data->local_addr.s_addr) && - (sin.sin_port == data->port)) { - buff_len = 0; - } else { - src->mac_len = 6; - memcpy(&src->mac[0], &sin.sin_addr.s_addr, 4); - memcpy(&src->mac[4], &sin.sin_port, 2); + case BVLC_FORWARDED_NPDU:{ + memcpy(&sin.sin_addr.s_addr, &data->buff[4], 4); + memcpy(&sin.sin_port, &data->buff[8], 2); + if ((sin.sin_addr.s_addr == data->local_addr.s_addr) && + (sin.sin_port == data->port)) { + buff_len = 0; + } else { + src->mac_len = 6; + memcpy(&src->mac[0], &sin.sin_addr.s_addr, 4); + memcpy(&src->mac[4], &sin.sin_port, 2); - (void) decode_unsigned16(&data->buff[2], &buff_len); - /* subtract off the BVLC header */ - buff_len -= 10; - if (buff_len < data->max_buff) { - /* allocate data message stucture */ - (*msg_data) = (MSG_DATA*)malloc(sizeof(MSG_DATA)); - (*msg_data)->pdu_len = buff_len; - (*msg_data)->pdu = (uint8_t*)malloc((*msg_data)->pdu_len); - /* fill up data message structure */ - memmove(&(*msg_data)->pdu, &data->buff[4+6], (*msg_data)->pdu_len); - memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS)); - } else { - /* ignore packets that are too large */ - buff_len = 0; - } - } - } - break; - default: + (void) decode_unsigned16(&data->buff[2], &buff_len); + /* subtract off the BVLC header */ + buff_len -= 10; + if (buff_len < data->max_buff) { + /* allocate data message stucture */ + (*msg_data) = (MSG_DATA *) malloc(sizeof(MSG_DATA)); + (*msg_data)->pdu_len = buff_len; + (*msg_data)->pdu = + (uint8_t *) malloc((*msg_data)->pdu_len); + /* fill up data message structure */ + memmove(&(*msg_data)->pdu, &data->buff[4 + 6], + (*msg_data)->pdu_len); + memmove(&(*msg_data)->src, src, + sizeof(BACNET_ADDRESS)); + } else { + /* ignore packets that are too large */ + buff_len = 0; + } + } + } + break; + default: - PRINT(ERROR, "BIP: BVLC discarded!\n"); + PRINT(ERROR, "BIP: BVLC discarded!\n"); - break; - } - return buff_len; + break; + } + return buff_len; } void dl_ip_cleanup( - IP_DATA *ip_data) { - /* free buffer */ - if (ip_data->buff) - free(ip_data->buff); - /* close socket */ - if (ip_data->socket > 0) - close(ip_data->socket); - return; + IP_DATA * ip_data) +{ + /* free buffer */ + if (ip_data->buff) + free(ip_data->buff); + /* close socket */ + if (ip_data->socket > 0) + close(ip_data->socket); + return; } - diff --git a/bacnet-stack/demo/router/ipmodule.h b/bacnet-stack/demo/router/ipmodule.h index ddf48265..85adea1e 100644 --- a/bacnet-stack/demo/router/ipmodule.h +++ b/bacnet-stack/demo/router/ipmodule.h @@ -26,36 +26,36 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #define MAX_BIP_PDU (MAX_NPDU + MAX_BIP_APDU) #define MAX_BIP_MPDU (MAX_HEADER + MAX_BIP_PDU) - typedef struct ip_data { - int socket; - uint16_t port; - struct in_addr local_addr; - struct in_addr broadcast_addr; - uint8_t *buff; - uint16_t max_buff; - } IP_DATA; +typedef struct ip_data { + int socket; + uint16_t port; + struct in_addr local_addr; + struct in_addr broadcast_addr; + uint8_t *buff; + uint16_t max_buff; +} IP_DATA; -void* dl_ip_thread( - void *pArgs); +void *dl_ip_thread( + void *pArgs); bool dl_ip_init( - ROUTER_PORT *port, - IP_DATA *data); + ROUTER_PORT * port, + IP_DATA * data); int dl_ip_send( - IP_DATA *data, - BACNET_ADDRESS *dest, - uint8_t *pdu, - unsigned pdu_len); + IP_DATA * data, + BACNET_ADDRESS * dest, + uint8_t * pdu, + unsigned pdu_len); int dl_ip_recv( - IP_DATA *data, - MSG_DATA **msg, /* on recieve fill up message */ - BACNET_ADDRESS *src, - unsigned timeout); + IP_DATA * data, + MSG_DATA ** msg, /* on recieve fill up message */ + BACNET_ADDRESS * src, + unsigned timeout); void dl_ip_cleanup( - IP_DATA *data); + IP_DATA * data); #endif /* end of UDPMODULE_H */ diff --git a/bacnet-stack/demo/router/main.c b/bacnet-stack/demo/router/main.c index 45029262..3535af2f 100644 --- a/bacnet-stack/demo/router/main.c +++ b/bacnet-stack/demo/router/main.c @@ -24,9 +24,9 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #include #include #include -#include /* read config files */ -#include /* for getopt */ -#include /* used in kbhit() */ +#include /* read config files */ +#include /* for getopt */ +#include /* used in kbhit() */ #include #include #include @@ -42,735 +42,802 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #define KEY_ESC 27 -ROUTER_PORT *head = NULL; /* pointer to list of router ports */ +ROUTER_PORT *head = NULL; /* pointer to list of router ports */ int port_count; -void print_help(); +void print_help( + ); bool read_config( - char *filepath); + char *filepath); bool parse_cmd( - int argc, - char *argv[]); + int argc, + char *argv[]); void init_port_threads( - ROUTER_PORT* port_list); + ROUTER_PORT * port_list); -bool init_router(); +bool init_router( + ); -void cleanup(); +void cleanup( + ); void print_msg( - BACMSG *msg); + BACMSG * msg); uint16_t process_msg( - BACMSG *msg, - MSG_DATA *data, - uint8_t **buff); + BACMSG * msg, + MSG_DATA * data, + uint8_t ** buff); -uint16_t get_next_free_dnet(); +uint16_t get_next_free_dnet( + ); -int kbhit(); +int kbhit( + ); inline bool is_network_msg( - BACMSG *msg); + BACMSG * msg); int main( int argc, char *argv[]) { - printf("I am router\n"); + printf("I am router\n"); - ROUTER_PORT *port; - BACMSG msg_storage, *bacmsg = NULL; - MSG_DATA *msg_data = NULL; - uint8_t *buff = NULL; - int16_t buff_len = 0; + ROUTER_PORT *port; + BACMSG msg_storage, *bacmsg = NULL; + MSG_DATA *msg_data = NULL; + uint8_t *buff = NULL; + int16_t buff_len = 0; - atexit(cleanup); + atexit(cleanup); - if (!parse_cmd(argc, argv)) - { - printf("parse cmd failed\r\n"); - return -1; - } + if (!parse_cmd(argc, argv)) { + printf("parse cmd failed\r\n"); + return -1; + } - if(!init_router()) - { - printf("init_router failed\r\n"); - return -1; - } + if (!init_router()) { + printf("init_router failed\r\n"); + return -1; + } - send_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, msg_data, &buff, NULL); + send_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, msg_data, + &buff, NULL); - while (true) { - if(kbhit()) { - char ch = getchar(); - if (ch == KEY_ESC) { - PRINT(INFO, "Received shutdown. Exiting...\n"); - break; - } - } + while (true) { + if (kbhit()) { + char ch = getchar(); + if (ch == KEY_ESC) { + PRINT(INFO, "Received shutdown. Exiting...\n"); + break; + } + } - bacmsg = recv_from_msgbox(head->main_id, &msg_storage); - if (bacmsg) { - switch (bacmsg->type) { - case DATA: - { - MSGBOX_ID msg_src = bacmsg->origin; + bacmsg = recv_from_msgbox(head->main_id, &msg_storage); + if (bacmsg) { + switch (bacmsg->type) { + case DATA: + { + MSGBOX_ID msg_src = bacmsg->origin; - /* allocate message structure */ - msg_data = malloc(sizeof(MSG_DATA)); - if (!msg_data) { - PRINT(ERROR, "Error: Could not allocate memory\n"); - break; - } + /* allocate message structure */ + msg_data = malloc(sizeof(MSG_DATA)); + if (!msg_data) { + PRINT(ERROR, "Error: Could not allocate memory\n"); + break; + } - print_msg(bacmsg); + print_msg(bacmsg); - if (is_network_msg(bacmsg)) { - buff_len = process_network_message(bacmsg, msg_data, &buff); - if (buff_len == 0) { - free_data(bacmsg->data); - break; - } - } else { - buff_len = process_msg(bacmsg, msg_data, &buff); - } + if (is_network_msg(bacmsg)) { + buff_len = + process_network_message(bacmsg, msg_data, + &buff); + if (buff_len == 0) { + free_data(bacmsg->data); + break; + } + } else { + buff_len = process_msg(bacmsg, msg_data, &buff); + } - /* if buff_len */ - /* >0 - form new message and send */ - /* =-1 - try to find next router */ - /* other value - discard message */ + /* if buff_len */ + /* >0 - form new message and send */ + /* =-1 - try to find next router */ + /* other value - discard message */ - if (buff_len > 0) { - /* form new message */ - msg_data->pdu = buff; - msg_data->pdu_len = buff_len; - msg_storage.origin = head->main_id; - msg_storage.type = DATA; - msg_storage.data = msg_data; + if (buff_len > 0) { + /* form new message */ + msg_data->pdu = buff; + msg_data->pdu_len = buff_len; + msg_storage.origin = head->main_id; + msg_storage.type = DATA; + msg_storage.data = msg_data; - print_msg(bacmsg); + print_msg(bacmsg); - if (is_network_msg(bacmsg)) { - msg_data->ref_count = 1; - send_to_msgbox(msg_src, &msg_storage); - } else if (msg_data->dest.net != BACNET_BROADCAST_NETWORK) { - msg_data->ref_count = 1; - port = find_dnet(msg_data->dest.net, &msg_data->dest); - send_to_msgbox(port->port_id, &msg_storage); - } else { - port = head; - msg_data->ref_count = port_count - 1; - while (port != NULL) { - if (port->port_id == msg_src || port->state == FINISHED) { - port = port->next; - continue; - } - send_to_msgbox(port->port_id, &msg_storage); - port = port->next; - } - } - } else if (buff_len == -1) { - uint16_t net = msg_data->dest.net; /* NET to find */ - PRINT(INFO, "Searching NET...\n"); - send_network_message(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, msg_data, &buff, &net); - } else { - /* if invalid message send Reject-Message-To-Network */ - PRINT(ERROR, "Error: Invalid message\n"); - free_data(msg_data); - } - } - break; - case SERVICE: - default: - break; - } - } - } + if (is_network_msg(bacmsg)) { + msg_data->ref_count = 1; + send_to_msgbox(msg_src, &msg_storage); + } else if (msg_data->dest.net != + BACNET_BROADCAST_NETWORK) { + msg_data->ref_count = 1; + port = + find_dnet(msg_data->dest.net, + &msg_data->dest); + send_to_msgbox(port->port_id, &msg_storage); + } else { + port = head; + msg_data->ref_count = port_count - 1; + while (port != NULL) { + if (port->port_id == msg_src || + port->state == FINISHED) { + port = port->next; + continue; + } + send_to_msgbox(port->port_id, + &msg_storage); + port = port->next; + } + } + } else if (buff_len == -1) { + uint16_t net = msg_data->dest.net; /* NET to find */ + PRINT(INFO, "Searching NET...\n"); + send_network_message + (NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, + msg_data, &buff, &net); + } else { + /* if invalid message send Reject-Message-To-Network */ + PRINT(ERROR, "Error: Invalid message\n"); + free_data(msg_data); + } + } + break; + case SERVICE: + default: + break; + } + } + } - return 0; + return 0; } -void print_help() +void print_help( + ) { - printf("Usage: router [init_parameters]\n" - "\ninit_method:\n" - "-c, --config \n\tinitialize router with a configuration file (.cfg) located at \n" - "-D, --device [params]\n\tinitialize a device using an interface specified with\n\t[params]\n" - "\ninit_parameters:\n" - "-n, --network \n\tspecify device network number\n" - "-P, --port \n\tspecify udp port for BIP device\n" - "-m, --mac [max_master] [max_frames]\n\tspecify MSTP port parameters\n" - "-b, --baud \n\tspecify MSTP port baud rate\n" - "-p, --parity \n\tspecify MSTP port parity\n" - "-d, --databits <5|6|7|8>\n\tspecify MSTP port databits\n" - "-s, --stopbits <1|2>\n\tspecify MSTP port stopbits\n"); + printf("Usage: router [init_parameters]\n" "\ninit_method:\n" + "-c, --config \n\tinitialize router with a configuration file (.cfg) located at \n" + "-D, --device [params]\n\tinitialize a device using an interface specified with\n\t[params]\n" + "\ninit_parameters:\n" + "-n, --network \n\tspecify device network number\n" + "-P, --port \n\tspecify udp port for BIP device\n" + "-m, --mac [max_master] [max_frames]\n\tspecify MSTP port parameters\n" + "-b, --baud \n\tspecify MSTP port baud rate\n" + "-p, --parity \n\tspecify MSTP port parity\n" + "-d, --databits <5|6|7|8>\n\tspecify MSTP port databits\n" + "-s, --stopbits <1|2>\n\tspecify MSTP port stopbits\n"); } bool read_config( - char *filepath) + char *filepath) { - config_t cfg; - config_setting_t *setting; - ROUTER_PORT *current = head; - int result, fd; + config_t cfg; + config_setting_t *setting; + ROUTER_PORT *current = head; + int result, fd; - config_init(&cfg); + config_init(&cfg); - /* open configuration file */ - if (!config_read_file(&cfg, filepath)) { - PRINT(ERROR, "Config file error: %d - %s\n", config_error_line(&cfg), config_error_text(&cfg)); - config_destroy(&cfg); - return false; - } + /* open configuration file */ + if (!config_read_file(&cfg, filepath)) { + PRINT(ERROR, "Config file error: %d - %s\n", config_error_line(&cfg), + config_error_text(&cfg)); + config_destroy(&cfg); + return false; + } - /* get router "port" count */ - setting = config_lookup(&cfg, "ports"); - if (setting != NULL) { - int count = config_setting_length(setting); - int i; + /* get router "port" count */ + setting = config_lookup(&cfg, "ports"); + if (setting != NULL) { + int count = config_setting_length(setting); + int i; - /* lookup and initialize router "port" parameters */ - for (i = 0; i < count; i++) { - const char *dev_type; - const char *iface; - long int param; - const char *str_param; - config_setting_t *port = config_setting_get_elem(setting, i); + /* lookup and initialize router "port" parameters */ + for (i = 0; i < count; i++) { + const char *dev_type; + const char *iface; + long int param; + const char *str_param; + config_setting_t *port = config_setting_get_elem(setting, i); - /* create new list node to store port information */ - if (head == NULL) { - head = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT)); - head->next = NULL; - current = head; - } else { - ROUTER_PORT *tmp = current; - current = current->next; - current = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT)); - current->next = NULL; - tmp->next = current; - } + /* create new list node to store port information */ + if (head == NULL) { + head = (ROUTER_PORT *) malloc(sizeof(ROUTER_PORT)); + head->next = NULL; + current = head; + } else { + ROUTER_PORT *tmp = current; + current = current->next; + current = (ROUTER_PORT *) malloc(sizeof(ROUTER_PORT)); + current->next = NULL; + tmp->next = current; + } - port_count++; - config_setting_lookup_string(port, "device_type", &dev_type); - printf("dev_type = %s\r\n", dev_type); - if (strcmp(dev_type, "bip") == 0) { - current->type = BIP; + port_count++; + config_setting_lookup_string(port, "device_type", &dev_type); + printf("dev_type = %s\r\n", dev_type); + if (strcmp(dev_type, "bip") == 0) { + current->type = BIP; - result = config_setting_lookup_string(port, "device", &iface); - if (result) { - current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char)); - strcpy(current->iface, iface); + result = config_setting_lookup_string(port, "device", &iface); + if (result) { + current->iface = + (char *) malloc((strlen(iface) + 1) * sizeof(char)); + strcpy(current->iface, iface); - /* check if interface is valid */ - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd) { - struct ifreq ifr; - strncpy(ifr.ifr_name, current->iface, sizeof(ifr.ifr_name)-1); - result = ioctl(fd, SIOCGIFADDR, &ifr); - if (result != -1) { - close(fd); - } else { - PRINT(ERROR, "Error: Invalid interface for BIP device\n"); - return false; - } - } - } else { - current->iface = "eth0"; - } + /* check if interface is valid */ + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd) { + struct ifreq ifr; + strncpy(ifr.ifr_name, current->iface, + sizeof(ifr.ifr_name) - 1); + result = ioctl(fd, SIOCGIFADDR, &ifr); + if (result != -1) { + close(fd); + } else { + PRINT(ERROR, + "Error: Invalid interface for BIP device\n"); + return false; + } + } + } else { + current->iface = "eth0"; + } - result = config_setting_lookup_int(port, "port", (int*)¶m); - if (result) { - current->params.bip_params.port = param; - } else { - current->params.bip_params.port = 0xBAC0; - } - result = config_setting_lookup_int(port, "network", (int*)¶m); - if (result) { - current->route_info.net = param; - } else { - current->route_info.net = get_next_free_dnet(); - } + result = + config_setting_lookup_int(port, "port", (int *) ¶m); + if (result) { + current->params.bip_params.port = param; + } else { + current->params.bip_params.port = 0xBAC0; + } + result = + config_setting_lookup_int(port, "network", (int *) ¶m); + if (result) { + current->route_info.net = param; + } else { + current->route_info.net = get_next_free_dnet(); + } - } else if (strcmp(dev_type, "mstp") == 0) { - current->type = MSTP; + } else if (strcmp(dev_type, "mstp") == 0) { + current->type = MSTP; - result = config_setting_lookup_string(port, "device", &iface); - if (result) { - current->iface = (char*)malloc((strlen(iface) + 1)*sizeof(char)); - strcpy(current->iface, iface); + result = config_setting_lookup_string(port, "device", &iface); + if (result) { + current->iface = + (char *) malloc((strlen(iface) + 1) * sizeof(char)); + strcpy(current->iface, iface); - /* check if interface is valid */ - fd = open(current->iface, O_NOCTTY | O_NONBLOCK); - if (fd != -1) { - close(fd); - } else { - PRINT(ERROR, "Error: Invalid interface for MSTP device\n"); - return false; - } - } else { - current->iface = "/dev/ttyS0"; - } - result = config_setting_lookup_int(port, "mac", (int*)¶m); - if (result) { - current->route_info.mac[0] = param; - current->route_info.mac_len = 1; - } else { - current->route_info.mac[0] = 127; - current->route_info.mac_len = 1; - } - result = config_setting_lookup_int(port, "max_master", (int*)¶m); - if (result) { - current->params.mstp_params.max_master = param; - } else { - current->params.mstp_params.max_master = 127; - } - result = config_setting_lookup_int(port, "max_frames", (int*)¶m); - if (result) { - current->params.mstp_params.max_frames = param; - } else { - current->params.mstp_params.max_frames = 1; - } - result = config_setting_lookup_int(port, "baud", (int*)¶m); - if (result) { - current->params.mstp_params.baudrate = param; - } else { - current->params.mstp_params.baudrate = 9600; - } - result = config_setting_lookup_string(port, "parity", &str_param); - if (result) { - switch(str_param[0]){ - case 'E': - current->params.mstp_params.parity = PARITY_EVEN; - break; - case 'O': - current->params.mstp_params.parity = PARITY_ODD; - break; - default: - current->params.mstp_params.parity = PARITY_NONE; - break; - } - } else { - current->params.mstp_params.parity = PARITY_NONE; - } - result = config_setting_lookup_int(port, "databits", (int*)¶m); - if (result && param >= 5 && param <= 8) { - current->params.mstp_params.databits = param; - } else { - current->params.mstp_params.databits = 8; - } - result = config_setting_lookup_int(port, "stopbits", (int*)¶m); - if (result && param >= 1 && param <= 2) { - current->params.mstp_params.stopbits = param; - } else { - current->params.mstp_params.stopbits = 1; - } - result = config_setting_lookup_int(port, "network", (int*)¶m); - if (result) { - current->route_info.net = param; - } else { - current->route_info.net = get_next_free_dnet(); - } + /* check if interface is valid */ + fd = open(current->iface, O_NOCTTY | O_NONBLOCK); + if (fd != -1) { + close(fd); + } else { + PRINT(ERROR, + "Error: Invalid interface for MSTP device\n"); + return false; + } + } else { + current->iface = "/dev/ttyS0"; + } + result = + config_setting_lookup_int(port, "mac", (int *) ¶m); + if (result) { + current->route_info.mac[0] = param; + current->route_info.mac_len = 1; + } else { + current->route_info.mac[0] = 127; + current->route_info.mac_len = 1; + } + result = + config_setting_lookup_int(port, "max_master", + (int *) ¶m); + if (result) { + current->params.mstp_params.max_master = param; + } else { + current->params.mstp_params.max_master = 127; + } + result = + config_setting_lookup_int(port, "max_frames", + (int *) ¶m); + if (result) { + current->params.mstp_params.max_frames = param; + } else { + current->params.mstp_params.max_frames = 1; + } + result = + config_setting_lookup_int(port, "baud", (int *) ¶m); + if (result) { + current->params.mstp_params.baudrate = param; + } else { + current->params.mstp_params.baudrate = 9600; + } + result = + config_setting_lookup_string(port, "parity", &str_param); + if (result) { + switch (str_param[0]) { + case 'E': + current->params.mstp_params.parity = PARITY_EVEN; + break; + case 'O': + current->params.mstp_params.parity = PARITY_ODD; + break; + default: + current->params.mstp_params.parity = PARITY_NONE; + break; + } + } else { + current->params.mstp_params.parity = PARITY_NONE; + } + result = + config_setting_lookup_int(port, "databits", + (int *) ¶m); + if (result && param >= 5 && param <= 8) { + current->params.mstp_params.databits = param; + } else { + current->params.mstp_params.databits = 8; + } + result = + config_setting_lookup_int(port, "stopbits", + (int *) ¶m); + if (result && param >= 1 && param <= 2) { + current->params.mstp_params.stopbits = param; + } else { + current->params.mstp_params.stopbits = 1; + } + result = + config_setting_lookup_int(port, "network", (int *) ¶m); + if (result) { + current->route_info.net = param; + } else { + current->route_info.net = get_next_free_dnet(); + } - } else { - PRINT(ERROR, "Error: %s unsuported\n", dev_type); - return false; - } - } - } - else { - config_destroy(&cfg); - return false; - } + } else { + PRINT(ERROR, "Error: %s unsuported\n", dev_type); + return false; + } + } + } else { + config_destroy(&cfg); + return false; + } - config_destroy(&cfg); - printf("cmd file parse success\r\n"); - return true; + config_destroy(&cfg); + printf("cmd file parse success\r\n"); + return true; } bool parse_cmd( - int argc, - char *argv[]) + int argc, + char *argv[]) { - const char *optString = "hc:D:"; - const char *bipString = "p:n:D:"; - const char *mstpString = "m:b:p:d:s:n:D:"; - const struct option Options[] = { - { "config", required_argument, NULL, 'c' }, - { "device", required_argument, NULL, 'D' }, - { "network", required_argument, NULL, 'n' }, - { "port", required_argument, NULL, 'P' }, - { "mac", required_argument, NULL, 'm' }, - { "baud", required_argument, NULL, 'b' }, - { "parity", required_argument, NULL, 'p' }, - { "databits", required_argument, NULL, 'd' }, - { "stopbits", required_argument, NULL, 's' }, - { "help", no_argument, NULL, 'h' }, - { NULL, no_argument, NULL, 0 }, - }; + const char *optString = "hc:D:"; + const char *bipString = "p:n:D:"; + const char *mstpString = "m:b:p:d:s:n:D:"; + const struct option Options[] = { + {"config", required_argument, NULL, 'c'}, + {"device", required_argument, NULL, 'D'}, + {"network", required_argument, NULL, 'n'}, + {"port", required_argument, NULL, 'P'}, + {"mac", required_argument, NULL, 'm'}, + {"baud", required_argument, NULL, 'b'}, + {"parity", required_argument, NULL, 'p'}, + {"databits", required_argument, NULL, 'd'}, + {"stopbits", required_argument, NULL, 's'}, + {"help", no_argument, NULL, 'h'}, + {NULL, no_argument, NULL, 0}, + }; - int opt, dev_opt, index, result, fd; - ROUTER_PORT *current = head; + int opt, dev_opt, index, result, fd; + ROUTER_PORT *current = head; - if (argc < 2) - print_help(); + if (argc < 2) + print_help(); - /* begin checking cmd parameters */ - opt = getopt_long(argc, argv, optString, Options, &index); - printf("opt = %c\r\n", opt); - while (opt != -1) { - switch(opt) { - case 'h': - print_help(); - return false; - break; - case 'c': - return read_config(optarg); - break; - case 'D': + /* begin checking cmd parameters */ + opt = getopt_long(argc, argv, optString, Options, &index); + printf("opt = %c\r\n", opt); + while (opt != -1) { + switch (opt) { + case 'h': + print_help(); + return false; + break; + case 'c': + return read_config(optarg); + break; + case 'D': - /* create new list node to store port information */ - if (head == NULL) { - head = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT)); - head->next = NULL; - current = head; - } else { - ROUTER_PORT *tmp = current; - current = current->next; - current = (ROUTER_PORT*)malloc(sizeof(ROUTER_PORT)); - current->next = NULL; - tmp->next = current; - } + /* create new list node to store port information */ + if (head == NULL) { + head = (ROUTER_PORT *) malloc(sizeof(ROUTER_PORT)); + head->next = NULL; + current = head; + } else { + ROUTER_PORT *tmp = current; + current = current->next; + current = (ROUTER_PORT *) malloc(sizeof(ROUTER_PORT)); + current->next = NULL; + tmp->next = current; + } - port_count++; - if (strcmp(optarg, "bip") == 0) { - current->type = BIP; + port_count++; + if (strcmp(optarg, "bip") == 0) { + current->type = BIP; - if (optind < argc && argv[optind][0] != '-') { - current->iface = argv[optind]; - } else { - current->iface = "eth0"; - } + if (optind < argc && argv[optind][0] != '-') { + current->iface = argv[optind]; + } else { + current->iface = "eth0"; + } - /* setup default parameters */ - current->params.bip_params.port = 0xBAC0; /* 47808 */ - current->route_info.net = get_next_free_dnet(); + /* setup default parameters */ + current->params.bip_params.port = 0xBAC0; /* 47808 */ + current->route_info.net = get_next_free_dnet(); - /* check if interface is valid */ - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd) { - struct ifreq ifr; - strncpy(ifr.ifr_name, current->iface, sizeof(ifr.ifr_name)-1); - result = ioctl(fd, SIOCGIFADDR, &ifr); - if (result != -1) { - close(fd); - } else { - PRINT(ERROR, "Error: Invalid interface for BIP device \n"); - return false; - } - } + /* check if interface is valid */ + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd) { + struct ifreq ifr; + strncpy(ifr.ifr_name, current->iface, + sizeof(ifr.ifr_name) - 1); + result = ioctl(fd, SIOCGIFADDR, &ifr); + if (result != -1) { + close(fd); + } else { + PRINT(ERROR, + "Error: Invalid interface for BIP device \n"); + return false; + } + } - dev_opt = getopt_long(argc, argv, bipString, Options, &index); - while (dev_opt != -1 && dev_opt != 'd') { - switch(dev_opt) { - case 'P': - result = atoi(optarg); - if (result) { - current->params.bip_params.port = (uint16_t)result; - } else { - current->params.bip_params.port = 0xBAC0; /* 47808 */ - } - break; - case 'n': - result = atoi(optarg); - if (result) { - current->route_info.net = (uint16_t)result; - } else { - current->route_info.net = port_count; - } - break; - } - dev_opt = getopt_long(argc, argv, bipString, Options, &index); - } - opt = dev_opt; - } else if (strcmp(optarg, "mstp") == 0) { - current->type = MSTP; + dev_opt = + getopt_long(argc, argv, bipString, Options, &index); + while (dev_opt != -1 && dev_opt != 'd') { + switch (dev_opt) { + case 'P': + result = atoi(optarg); + if (result) { + current->params.bip_params.port = + (uint16_t) result; + } else { + current->params.bip_params.port = 0xBAC0; /* 47808 */ + } + break; + case 'n': + result = atoi(optarg); + if (result) { + current->route_info.net = + (uint16_t) result; + } else { + current->route_info.net = port_count; + } + break; + } + dev_opt = + getopt_long(argc, argv, bipString, Options, + &index); + } + opt = dev_opt; + } else if (strcmp(optarg, "mstp") == 0) { + current->type = MSTP; - if (optind < argc && argv[optind][0] != '-') { - current->iface = argv[optind]; - } else { - current->iface = "/dev/ttyS0"; - } + if (optind < argc && argv[optind][0] != '-') { + current->iface = argv[optind]; + } else { + current->iface = "/dev/ttyS0"; + } - /* check if interface is valid */ - fd = open(current->iface, O_NOCTTY | O_NONBLOCK); - if (fd != -1) { - close(fd); - } else { - PRINT(ERROR, "Error: Invalid interface for MSTP device\n"); - return false; - } + /* check if interface is valid */ + fd = open(current->iface, O_NOCTTY | O_NONBLOCK); + if (fd != -1) { + close(fd); + } else { + PRINT(ERROR, + "Error: Invalid interface for MSTP device\n"); + return false; + } - /* setup default parameters */ - current->route_info.mac[0] = 127; - current->route_info.mac_len = 1; - current->params.mstp_params.max_master = 127; - current->params.mstp_params.max_frames = 1; - current->params.mstp_params.baudrate = 9600; - current->params.mstp_params.parity = PARITY_NONE; - current->params.mstp_params.databits = 8; - current->params.mstp_params.stopbits = 1; - current->route_info.net = get_next_free_dnet(); + /* setup default parameters */ + current->route_info.mac[0] = 127; + current->route_info.mac_len = 1; + current->params.mstp_params.max_master = 127; + current->params.mstp_params.max_frames = 1; + current->params.mstp_params.baudrate = 9600; + current->params.mstp_params.parity = PARITY_NONE; + current->params.mstp_params.databits = 8; + current->params.mstp_params.stopbits = 1; + current->route_info.net = get_next_free_dnet(); - dev_opt = getopt_long(argc, argv, mstpString, Options, &index); - while (dev_opt != -1 && dev_opt != 'D') { - switch(dev_opt) { - case 'm': - result = atoi(optarg); - if (result) { - current->route_info.mac[0] = (uint8_t)result; - } - if (argv[optind][0] != '-') { - current->params.mstp_params.max_master = (uint8_t)atoi(argv[optind]); - if (current->params.mstp_params.max_master < current->route_info.mac[0]) - current->params.mstp_params.max_master = current->route_info.mac[0]; + dev_opt = + getopt_long(argc, argv, mstpString, Options, &index); + while (dev_opt != -1 && dev_opt != 'D') { + switch (dev_opt) { + case 'm': + result = atoi(optarg); + if (result) { + current->route_info.mac[0] = + (uint8_t) result; + } + if (argv[optind][0] != '-') { + current->params.mstp_params.max_master = + (uint8_t) atoi(argv[optind]); + if (current->params.mstp_params. + max_master < + current->route_info.mac[0]) + current->params.mstp_params. + max_master = + current->route_info.mac[0]; - if (argv[optind+1][0] != '-') { - current->params.mstp_params.max_frames = (uint8_t)atoi(argv[optind+1]); - } - } - break; - case 'b': - result = atoi(optarg); - if (result) { - current->params.mstp_params.baudrate = (uint32_t)result; - } - break; - case 'p': - switch(optarg[0]){ - case 'E': - current->params.mstp_params.parity = PARITY_EVEN; - break; - case 'O': - current->params.mstp_params.parity = PARITY_ODD; - break; - default: - current->params.mstp_params.parity = PARITY_NONE; - break; - } - break; - case 'd': - result = atoi(optarg); - if (result >= 5 && result <= 8) { - current->params.mstp_params.databits = (uint8_t)result; - } - break; - case 's': - result = atoi(optarg); - if (result >= 1 && result <= 2) { - current->params.mstp_params.stopbits = (uint8_t)result; - } - break; - case 'n': - result = atoi(optarg); - if (result) { - current->route_info.net = (uint16_t)result; - } - break; - } - dev_opt = getopt_long(argc, argv, mstpString, Options, &index); - } - opt = dev_opt; - } else { - PRINT(ERROR, "Error: %s unknown\n", optarg); - return false; - } - break; - } - } - return true; + if (argv[optind + 1][0] != '-') { + current->params.mstp_params. + max_frames = + (uint8_t) atoi(argv[optind + 1]); + } + } + break; + case 'b': + result = atoi(optarg); + if (result) { + current->params.mstp_params.baudrate = + (uint32_t) result; + } + break; + case 'p': + switch (optarg[0]) { + case 'E': + current->params.mstp_params.parity = + PARITY_EVEN; + break; + case 'O': + current->params.mstp_params.parity = + PARITY_ODD; + break; + default: + current->params.mstp_params.parity = + PARITY_NONE; + break; + } + break; + case 'd': + result = atoi(optarg); + if (result >= 5 && result <= 8) { + current->params.mstp_params.databits = + (uint8_t) result; + } + break; + case 's': + result = atoi(optarg); + if (result >= 1 && result <= 2) { + current->params.mstp_params.stopbits = + (uint8_t) result; + } + break; + case 'n': + result = atoi(optarg); + if (result) { + current->route_info.net = + (uint16_t) result; + } + break; + } + dev_opt = + getopt_long(argc, argv, mstpString, Options, + &index); + } + opt = dev_opt; + } else { + PRINT(ERROR, "Error: %s unknown\n", optarg); + return false; + } + break; + } + } + return true; } void init_port_threads( - ROUTER_PORT* port_list) { - ROUTER_PORT *port = port_list; - pthread_t * thread; + ROUTER_PORT * port_list) +{ + ROUTER_PORT *port = port_list; + pthread_t *thread; - while (port != NULL) { - switch (port->type) { - case BIP: - port->func = &dl_ip_thread; - break; - case MSTP: - port->func = &dl_mstp_thread; - break; - } + while (port != NULL) { + switch (port->type) { + case BIP: + port->func = &dl_ip_thread; + break; + case MSTP: + port->func = &dl_mstp_thread; + break; + } - port->state = INIT; - thread = (pthread_t *)malloc(sizeof(pthread_t)); - pthread_create(thread, - NULL, - port->func, - port); + port->state = INIT; + thread = (pthread_t *) malloc(sizeof(pthread_t)); + pthread_create(thread, NULL, port->func, port); - pthread_detach(*thread); /* for proper thread termination */ + pthread_detach(*thread); /* for proper thread termination */ - port = port->next; - } + port = port->next; + } } -bool init_router() { - MSGBOX_ID msgboxid; - ROUTER_PORT *port; +bool init_router( + ) +{ + MSGBOX_ID msgboxid; + ROUTER_PORT *port; - msgboxid = create_msgbox(); - if (msgboxid == INVALID_MSGBOX_ID) - return false; + msgboxid = create_msgbox(); + if (msgboxid == INVALID_MSGBOX_ID) + return false; - port = head; - /* add main message box id to all ports */ - while (port != NULL) { - port->main_id = msgboxid; - port = port->next; - } + port = head; + /* add main message box id to all ports */ + while (port != NULL) { + port->main_id = msgboxid; + port = port->next; + } - init_port_threads(head); + init_port_threads(head); - /* wait for port initialization */ - port = head; - while (port != NULL) { - if (port->state == RUNNING) { - port = port->next; - continue; - } else if (port->state == INIT_FAILED) { - PRINT(ERROR, "Error: Failed to initialize %s\n", port->iface); - return false; - } else { - PRINT(INFO, "Initializing...\n"); - sleep(1); - continue; - } - } + /* wait for port initialization */ + port = head; + while (port != NULL) { + if (port->state == RUNNING) { + port = port->next; + continue; + } else if (port->state == INIT_FAILED) { + PRINT(ERROR, "Error: Failed to initialize %s\n", port->iface); + return false; + } else { + PRINT(INFO, "Initializing...\n"); + sleep(1); + continue; + } + } - return true; + return true; } -void cleanup() { - ROUTER_PORT *port; - BACMSG msg; +void cleanup( + ) +{ + ROUTER_PORT *port; + BACMSG msg; - if (head == NULL) - return; + if (head == NULL) + return; - msg.origin = head->main_id; - msg.type = SERVICE; - msg.subtype = SHUTDOWN; + msg.origin = head->main_id; + msg.type = SERVICE; + msg.subtype = SHUTDOWN; - del_msgbox(head->main_id); /* close routers message box */ + del_msgbox(head->main_id); /* close routers message box */ - /* send shutdown message to all router ports */ - port = head; - while (port != NULL) { - if (port->state == RUNNING) - send_to_msgbox(port->port_id, &msg); - port = port->next; - } + /* send shutdown message to all router ports */ + port = head; + while (port != NULL) { + if (port->state == RUNNING) + send_to_msgbox(port->port_id, &msg); + port = port->next; + } - port = head; - while (port != NULL) { - if (port->state == FINISHED) { - cleanup_dnets(port->route_info.dnets); - port = port->next; - free(head->iface); - free(head); - head = port; - } - } + port = head; + while (port != NULL) { + if (port->state == FINISHED) { + cleanup_dnets(port->route_info.dnets); + port = port->next; + free(head->iface); + free(head); + head = port; + } + } - pthread_mutex_destroy(&msg_lock); + pthread_mutex_destroy(&msg_lock); } -void print_msg(BACMSG *msg) { - if (msg->type == DATA) { - int i; - MSG_DATA *data = (MSG_DATA*)msg->data; +void print_msg( + BACMSG * msg) +{ + if (msg->type == DATA) { + int i; + MSG_DATA *data = (MSG_DATA *) msg->data; - if (data->pdu_len) { - PRINT(DEBUG, "Message PDU: "); - for (i = 0; i < data->pdu_len; i++) - PRINT(DEBUG, "%02X ",data->pdu[i]); - PRINT(DEBUG, "\n"); - } - } + if (data->pdu_len) { + PRINT(DEBUG, "Message PDU: "); + for (i = 0; i < data->pdu_len; i++) + PRINT(DEBUG, "%02X ", data->pdu[i]); + PRINT(DEBUG, "\n"); + } + } } -uint16_t process_msg(BACMSG *msg, - MSG_DATA *data, - uint8_t **buff) { +uint16_t process_msg( + BACMSG * msg, + MSG_DATA * data, + uint8_t ** buff) +{ - BACNET_ADDRESS addr; - BACNET_NPDU_DATA npdu_data; - ROUTER_PORT *srcport; - ROUTER_PORT *destport; - uint8_t npdu[MAX_NPDU]; - int16_t buff_len = 0; - int apdu_offset; - int apdu_len; - int npdu_len; + BACNET_ADDRESS addr; + BACNET_NPDU_DATA npdu_data; + ROUTER_PORT *srcport; + ROUTER_PORT *destport; + uint8_t npdu[MAX_NPDU]; + int16_t buff_len = 0; + int apdu_offset; + int apdu_len; + int npdu_len; - memmove(data, msg->data, sizeof(MSG_DATA)); + memmove(data, msg->data, sizeof(MSG_DATA)); - apdu_offset = npdu_decode(data->pdu, &data->dest, &addr, &npdu_data); - apdu_len = data->pdu_len - apdu_offset; + apdu_offset = npdu_decode(data->pdu, &data->dest, &addr, &npdu_data); + apdu_len = data->pdu_len - apdu_offset; - srcport = find_snet(msg->origin); - destport = find_dnet(data->dest.net, NULL); - assert(srcport); + srcport = find_snet(msg->origin); + destport = find_dnet(data->dest.net, NULL); + assert(srcport); - if (srcport && destport) { - data->src.net = srcport->route_info.net; + if (srcport && destport) { + data->src.net = srcport->route_info.net; - /* if received from another router save real source address (not other router source address) */ - if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK && data->src.net != addr.net) - memmove(&data->src, &addr, sizeof(BACNET_ADDRESS)); + /* if received from another router save real source address (not other router source address) */ + if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK && + data->src.net != addr.net) + memmove(&data->src, &addr, sizeof(BACNET_ADDRESS)); - /* encode both source and destination for broadcast and router-to-router communication */ - if (data->dest.net == BACNET_BROADCAST_NETWORK || destport->route_info.net != data->dest.net) { - npdu_len = npdu_encode_pdu(npdu, &data->dest, &data->src, &npdu_data); - } - else { - npdu_len = npdu_encode_pdu(npdu, NULL, &data->src, &npdu_data); - } + /* encode both source and destination for broadcast and router-to-router communication */ + if (data->dest.net == BACNET_BROADCAST_NETWORK || + destport->route_info.net != data->dest.net) { + npdu_len = + npdu_encode_pdu(npdu, &data->dest, &data->src, &npdu_data); + } else { + npdu_len = npdu_encode_pdu(npdu, NULL, &data->src, &npdu_data); + } - buff_len = npdu_len + data->pdu_len - apdu_offset; + buff_len = npdu_len + data->pdu_len - apdu_offset; - *buff = (uint8_t*)malloc(buff_len); - memmove(*buff, npdu, npdu_len); /* copy newly formed NPDU */ - memmove(*buff+npdu_len, &data->pdu[apdu_offset], apdu_len); /* copy APDU */ + *buff = (uint8_t *) malloc(buff_len); + memmove(*buff, npdu, npdu_len); /* copy newly formed NPDU */ + memmove(*buff + npdu_len, &data->pdu[apdu_offset], apdu_len); /* copy APDU */ - } else { - /* request net search */ - return -1; - } + } else { + /* request net search */ + return -1; + } - /* delete received message */ - free_data((MSG_DATA*)msg->data); + /* delete received message */ + free_data((MSG_DATA *) msg->data); - return buff_len; + return buff_len; } -int kbhit() +int kbhit( + ) { static const int STDIN = 0; static bool initialized = false; - if (! initialized) { + if (!initialized) { /* use termios to turn off line buffering */ struct termios term; tcgetattr(STDIN, &term); @@ -785,29 +852,32 @@ int kbhit() return bytesWaiting; } -bool is_network_msg(BACMSG *msg) { +bool is_network_msg( + BACMSG * msg) +{ - uint8_t control_byte; /* NPDU control byte */ - MSG_DATA *data = (MSG_DATA*)msg->data; + uint8_t control_byte; /* NPDU control byte */ + MSG_DATA *data = (MSG_DATA *) msg->data; - control_byte = data->pdu[1]; + control_byte = data->pdu[1]; - return control_byte & 0x80; /* check 7th bit */ + return control_byte & 0x80; /* check 7th bit */ } -uint16_t get_next_free_dnet() { +uint16_t get_next_free_dnet( + ) +{ - ROUTER_PORT * port = head; - uint16_t i = 1; - while(port) { - if(port->route_info.net == i) { - port = head; - i++; - continue; - } + ROUTER_PORT *port = head; + uint16_t i = 1; + while (port) { + if (port->route_info.net == i) { + port = head; + i++; + continue; + } - port = port->next; - } - return i; + port = port->next; + } + return i; } - diff --git a/bacnet-stack/demo/router/msgqueue.c b/bacnet-stack/demo/router/msgqueue.c index 2d9bc282..a0bb707f 100644 --- a/bacnet-stack/demo/router/msgqueue.c +++ b/bacnet-stack/demo/router/msgqueue.c @@ -23,73 +23,80 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv pthread_mutex_t msg_lock = PTHREAD_MUTEX_INITIALIZER; -MSGBOX_ID create_msgbox() { - MSGBOX_ID msgboxid; +MSGBOX_ID create_msgbox( + ) +{ + MSGBOX_ID msgboxid; - msgboxid = msgget(IPC_PRIVATE, 0666 | IPC_CREAT); - if (msgboxid == INVALID_MSGBOX_ID) { - return INVALID_MSGBOX_ID; - } + msgboxid = msgget(IPC_PRIVATE, 0666 | IPC_CREAT); + if (msgboxid == INVALID_MSGBOX_ID) { + return INVALID_MSGBOX_ID; + } - return msgboxid; + return msgboxid; } bool send_to_msgbox( - MSGBOX_ID dest, - BACMSG *msg) { + MSGBOX_ID dest, + BACMSG * msg) +{ - int err; + int err; - err = msgsnd(dest, msg, sizeof(BACMSG), 0); - if (err) { - return false; - } - return true; + err = msgsnd(dest, msg, sizeof(BACMSG), 0); + if (err) { + return false; + } + return true; } -BACMSG* recv_from_msgbox( - MSGBOX_ID src, - BACMSG *msg) { +BACMSG *recv_from_msgbox( + MSGBOX_ID src, + BACMSG * msg) +{ - int recv_bytes; + int recv_bytes; - recv_bytes = msgrcv(src, msg, sizeof(BACMSG), 0, IPC_NOWAIT); - if (recv_bytes > 0) { - return msg; - } else { - return NULL; - } + recv_bytes = msgrcv(src, msg, sizeof(BACMSG), 0, IPC_NOWAIT); + if (recv_bytes > 0) { + return msg; + } else { + return NULL; + } } void del_msgbox( - MSGBOX_ID msgboxid) { + MSGBOX_ID msgboxid) +{ - if (msgboxid == INVALID_MSGBOX_ID) - return; - else - msgctl(msgboxid, IPC_RMID, NULL); + if (msgboxid == INVALID_MSGBOX_ID) + return; + else + msgctl(msgboxid, IPC_RMID, NULL); } void free_data( - MSG_DATA *data) { + MSG_DATA * data) +{ - if (data->pdu) { - free(data->pdu); - data->pdu = NULL; - } - if (data) { - free(data); - data = NULL; - } + if (data->pdu) { + free(data->pdu); + data->pdu = NULL; + } + if (data) { + free(data); + data = NULL; + } } void check_data( - MSG_DATA *data) { + MSG_DATA * data) +{ - /* lock and decrement messages reference count */ - pthread_mutex_lock(&msg_lock); - if (--data->ref_count == 0) { - free_data(data); - } - pthread_mutex_unlock(&msg_lock); + /* lock and decrement messages reference count */ + pthread_mutex_lock(&msg_lock); + if (--data->ref_count == 0) { + free_data(data); + } + pthread_mutex_unlock(&msg_lock); } diff --git a/bacnet-stack/demo/router/msgqueue.h b/bacnet-stack/demo/router/msgqueue.h index 86fe3860..290f3344 100644 --- a/bacnet-stack/demo/router/msgqueue.h +++ b/bacnet-stack/demo/router/msgqueue.h @@ -32,54 +32,55 @@ extern pthread_mutex_t msg_lock; typedef int MSGBOX_ID; typedef enum { - DATA, - SERVICE + DATA, + SERVICE } MSGTYPE; typedef enum { - SHUTDOWN, - CHG_IP, - CHG_MAC + SHUTDOWN, + CHG_IP, + CHG_MAC } MSGSUBTYPE; typedef struct _message { - MSGBOX_ID origin; - MSGTYPE type; - MSGSUBTYPE subtype; - void *data; - /* add timestamp */ + MSGBOX_ID origin; + MSGTYPE type; + MSGSUBTYPE subtype; + void *data; + /* add timestamp */ } BACMSG; /* specific message type data structures */ typedef struct _msg_data { - BACNET_ADDRESS dest; - BACNET_ADDRESS src; - uint8_t *pdu; - uint16_t pdu_len; - uint8_t ref_count; + BACNET_ADDRESS dest; + BACNET_ADDRESS src; + uint8_t *pdu; + uint16_t pdu_len; + uint8_t ref_count; } MSG_DATA; -MSGBOX_ID create_msgbox(); +MSGBOX_ID create_msgbox( + ); /* returns sent byte count */ bool send_to_msgbox( - MSGBOX_ID dest, - BACMSG *msg); + MSGBOX_ID dest, + BACMSG * msg); /* returns received message */ -BACMSG* recv_from_msgbox( - MSGBOX_ID src, - BACMSG *msg); +BACMSG *recv_from_msgbox( + MSGBOX_ID src, + BACMSG * msg); void del_msgbox( - MSGBOX_ID msgboxid); + MSGBOX_ID msgboxid); /* free message data structure */ void free_data( - MSG_DATA *data); + MSG_DATA * data); /* check message reference counter and delete data if needed */ void check_data( - MSG_DATA *data); + MSG_DATA * data); #endif /* end of MSGQUEUE_H */ diff --git a/bacnet-stack/demo/router/mstpmodule.c b/bacnet-stack/demo/router/mstpmodule.c index 9995717e..5dd5566e 100644 --- a/bacnet-stack/demo/router/mstpmodule.c +++ b/bacnet-stack/demo/router/mstpmodule.c @@ -29,140 +29,139 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #define mstp_thread_debug(...) #endif -void* dl_mstp_thread(void* pArgs) { +void *dl_mstp_thread( + void *pArgs) +{ - ROUTER_PORT *port = (ROUTER_PORT*)pArgs; - struct mstp_port_struct_t mstp_port = {(MSTP_RECEIVE_STATE)0}; - volatile SHARED_MSTP_DATA shared_port_data = {0}; - uint16_t pdu_len; - uint8_t shutdown = 0; + ROUTER_PORT *port = (ROUTER_PORT *) pArgs; + struct mstp_port_struct_t mstp_port = { (MSTP_RECEIVE_STATE) 0 }; + volatile SHARED_MSTP_DATA shared_port_data = { 0 }; + uint16_t pdu_len; + uint8_t shutdown = 0; - shared_port_data.Treply_timeout = 260; - shared_port_data.MSTP_Packets = 0; - shared_port_data.Tusage_timeout = 50; - shared_port_data.RS485_Handle = -1; - shared_port_data.RS485_Baud = B38400; - shared_port_data.RS485MOD = 0; + shared_port_data.Treply_timeout = 260; + shared_port_data.MSTP_Packets = 0; + shared_port_data.Tusage_timeout = 50; + shared_port_data.RS485_Handle = -1; + shared_port_data.RS485_Baud = B38400; + shared_port_data.RS485MOD = 0; - switch(port->params.mstp_params.databits){ - case 5: - shared_port_data.RS485MOD = CS5; - break; - case 6: - shared_port_data.RS485MOD = CS6; - break; - case 7: - shared_port_data.RS485MOD = CS7; - break; - default: - shared_port_data.RS485MOD = CS8; - break; - } + switch (port->params.mstp_params.databits) { + case 5: + shared_port_data.RS485MOD = CS5; + break; + case 6: + shared_port_data.RS485MOD = CS6; + break; + case 7: + shared_port_data.RS485MOD = CS7; + break; + default: + shared_port_data.RS485MOD = CS8; + break; + } - switch(port->params.mstp_params.parity){ - case PARITY_EVEN: - shared_port_data.RS485MOD |= PARENB; - break; - case PARITY_ODD: - shared_port_data.RS485MOD |= PARENB | PARODD; - break; - default: - break; - } + switch (port->params.mstp_params.parity) { + case PARITY_EVEN: + shared_port_data.RS485MOD |= PARENB; + break; + case PARITY_ODD: + shared_port_data.RS485MOD |= PARENB | PARODD; + break; + default: + break; + } - if(port->params.mstp_params.stopbits == 2) - shared_port_data.RS485MOD |= CSTOPB; + if (port->params.mstp_params.stopbits == 2) + shared_port_data.RS485MOD |= CSTOPB; - mstp_port.UserData = (void*) &shared_port_data; - dlmstp_set_baud_rate(&mstp_port, port->params.mstp_params.baudrate); - dlmstp_set_mac_address(&mstp_port, port->route_info.mac[0]); - dlmstp_set_max_info_frames(&mstp_port, port->params.mstp_params.max_frames); - dlmstp_set_max_master(&mstp_port, port->params.mstp_params.max_master); - if(!dlmstp_init(&mstp_port, port->iface)) - printf("MSTP %s init failed. Stop.\n", port->iface); + mstp_port.UserData = (void *) &shared_port_data; + dlmstp_set_baud_rate(&mstp_port, port->params.mstp_params.baudrate); + dlmstp_set_mac_address(&mstp_port, port->route_info.mac[0]); + dlmstp_set_max_info_frames(&mstp_port, + port->params.mstp_params.max_frames); + dlmstp_set_max_master(&mstp_port, port->params.mstp_params.max_master); + if (!dlmstp_init(&mstp_port, port->iface)) + printf("MSTP %s init failed. Stop.\n", port->iface); - port->port_id = create_msgbox(); - if (port->port_id == INVALID_MSGBOX_ID) { - port->state = INIT_FAILED; - return NULL; - } + port->port_id = create_msgbox(); + if (port->port_id == INVALID_MSGBOX_ID) { + port->state = INIT_FAILED; + return NULL; + } - port->state = RUNNING; + port->state = RUNNING; - while (!shutdown) { - /* message loop */ - BACMSG msg_storage, * bacmsg; - MSG_DATA * msg_data; + while (!shutdown) { + /* message loop */ + BACMSG msg_storage, *bacmsg; + MSG_DATA *msg_data; - bacmsg = recv_from_msgbox(port->port_id, &msg_storage); + bacmsg = recv_from_msgbox(port->port_id, &msg_storage); - if(bacmsg) - { - switch(bacmsg->type) - { - case DATA: - msg_data = (MSG_DATA*) bacmsg->data; + if (bacmsg) { + switch (bacmsg->type) { + case DATA: + msg_data = (MSG_DATA *) bacmsg->data; - if(msg_data->dest.net == BACNET_BROADCAST_NETWORK) - { - dlmstp_get_broadcast_address(&(msg_data->dest)); - } - else - { - msg_data->dest.mac[0] = msg_data->dest.adr[0]; - msg_data->dest.mac_len = 1; - } + if (msg_data->dest.net == BACNET_BROADCAST_NETWORK) { + dlmstp_get_broadcast_address(&(msg_data->dest)); + } else { + msg_data->dest.mac[0] = msg_data->dest.adr[0]; + msg_data->dest.mac_len = 1; + } - dlmstp_send_pdu(&mstp_port, &(msg_data->dest), msg_data->pdu, msg_data->pdu_len); + dlmstp_send_pdu(&mstp_port, &(msg_data->dest), + msg_data->pdu, msg_data->pdu_len); - check_data(msg_data); + check_data(msg_data); - break; - case SERVICE: - switch(bacmsg->subtype) { - case SHUTDOWN: - shutdown = 1; - break; - default: - break; - } - break; - default: - continue; - break; - } - } - else - { - pdu_len = dlmstp_receive(&mstp_port, NULL, NULL, 0, 1000); + break; + case SERVICE: + switch (bacmsg->subtype) { + case SHUTDOWN: + shutdown = 1; + break; + default: + break; + } + break; + default: + continue; + break; + } + } else { + pdu_len = dlmstp_receive(&mstp_port, NULL, NULL, 0, 1000); - if(pdu_len > 0) - { - msg_data = (MSG_DATA*)malloc(sizeof(MSG_DATA)); - memmove(&(msg_data->src), (const void*)&(shared_port_data.Receive_Packet.address), sizeof(shared_port_data.Receive_Packet.address)); - msg_data->src.adr[0] = msg_data->src.mac[0]; - msg_data->src.len = 1; - msg_data->pdu = (uint8_t*)malloc(pdu_len); - memmove(msg_data->pdu, (const void*)&(shared_port_data.Receive_Packet.pdu), pdu_len); - msg_data->pdu_len = pdu_len; + if (pdu_len > 0) { + msg_data = (MSG_DATA *) malloc(sizeof(MSG_DATA)); + memmove(&(msg_data->src), + (const void *) &(shared_port_data.Receive_Packet.address), + sizeof(shared_port_data.Receive_Packet.address)); + msg_data->src.adr[0] = msg_data->src.mac[0]; + msg_data->src.len = 1; + msg_data->pdu = (uint8_t *) malloc(pdu_len); + memmove(msg_data->pdu, + (const void *) &(shared_port_data.Receive_Packet.pdu), + pdu_len); + msg_data->pdu_len = pdu_len; - msg_storage.type = DATA; - msg_storage.subtype = (MSGSUBTYPE)0; - msg_storage.origin = port->port_id; - msg_storage.data = msg_data; + msg_storage.type = DATA; + msg_storage.subtype = (MSGSUBTYPE) 0; + msg_storage.origin = port->port_id; + msg_storage.data = msg_data; - if(!send_to_msgbox(port->main_id, &msg_storage)) - { - free_data(msg_data); - } - } - } - } + if (!send_to_msgbox(port->main_id, &msg_storage)) { + free_data(msg_data); + } + } + } + } - dlmstp_cleanup(&mstp_port); - port->state = FINISHED; + dlmstp_cleanup(&mstp_port); + port->state = FINISHED; - return NULL; + return NULL; } diff --git a/bacnet-stack/demo/router/mstpmodule.h b/bacnet-stack/demo/router/mstpmodule.h index 44a3ff85..8aed485c 100644 --- a/bacnet-stack/demo/router/mstpmodule.h +++ b/bacnet-stack/demo/router/mstpmodule.h @@ -19,7 +19,7 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #include "portthread.h" -void* dl_mstp_thread( - void* pArgs); +void *dl_mstp_thread( + void *pArgs); #endif /* end of MSTPMODULE_H */ diff --git a/bacnet-stack/demo/router/network_layer.c b/bacnet-stack/demo/router/network_layer.c index 524ed178..f3d1d549 100644 --- a/bacnet-stack/demo/router/network_layer.c +++ b/bacnet-stack/demo/router/network_layer.c @@ -21,291 +21,307 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #include "bacint.h" uint16_t process_network_message( - BACMSG *msg, - MSG_DATA *data, - uint8_t **buff) { + BACMSG * msg, + MSG_DATA * data, + uint8_t ** buff) +{ - BACNET_NPDU_DATA npdu_data; - ROUTER_PORT *srcport; - ROUTER_PORT *destport; - uint16_t net; - uint8_t error_code; - int16_t buff_len = 0; - int apdu_offset; - int apdu_len; + BACNET_NPDU_DATA npdu_data; + ROUTER_PORT *srcport; + ROUTER_PORT *destport; + uint16_t net; + uint8_t error_code; + int16_t buff_len = 0; + int apdu_offset; + int apdu_len; - memmove(data, msg->data, sizeof(MSG_DATA)); + memmove(data, msg->data, sizeof(MSG_DATA)); - apdu_offset = npdu_decode(data->pdu, &data->dest, NULL, &npdu_data); - apdu_len = data->pdu_len - apdu_offset; + apdu_offset = npdu_decode(data->pdu, &data->dest, NULL, &npdu_data); + apdu_len = data->pdu_len - apdu_offset; - srcport = find_snet(msg->origin); - data->src.net = srcport->route_info.net; + srcport = find_snet(msg->origin); + data->src.net = srcport->route_info.net; - switch (npdu_data.network_message_type) { + switch (npdu_data.network_message_type) { - case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: - PRINT(INFO, "Recieved Who-Is-Router-To-Network message\n"); - if (apdu_len) { - /* if NET specified */ - decode_unsigned16(&data->pdu[apdu_offset], &net); - if (srcport->route_info.net == net) { - PRINT(INFO, "Message discarded: NET directly connected\n"); - return -2; - } + case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: + PRINT(INFO, "Recieved Who-Is-Router-To-Network message\n"); + if (apdu_len) { + /* if NET specified */ + decode_unsigned16(&data->pdu[apdu_offset], &net); + if (srcport->route_info.net == net) { + PRINT(INFO, "Message discarded: NET directly connected\n"); + return -2; + } - destport = find_dnet(net, NULL); /* see if NET can be reached */ - if (destport) { - /* if TRUE send reply */ - PRINT(INFO, "Sending I-Am-Router-To-Network message\n"); - buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, - data, buff, &net); - } else { - data->dest.net = net; /* NET to look for */ - return -1; /* else initiate NET search procedure */ - } - } else { - /* if NET is omitted (message sent with -1) */ - PRINT(INFO, "Sending I-Am-Router-To-Network message\n"); - buff_len = create_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, - data, buff, NULL); - } + destport = find_dnet(net, NULL); /* see if NET can be reached */ + if (destport) { + /* if TRUE send reply */ + PRINT(INFO, "Sending I-Am-Router-To-Network message\n"); + buff_len = + create_network_message + (NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, data, buff, + &net); + } else { + data->dest.net = net; /* NET to look for */ + return -1; /* else initiate NET search procedure */ + } + } else { + /* if NET is omitted (message sent with -1) */ + PRINT(INFO, "Sending I-Am-Router-To-Network message\n"); + buff_len = + create_network_message + (NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, data, buff, NULL); + } - break; + break; - case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: - { - PRINT(INFO, "Recieved I-Am-Router-To-Network message\n"); - int net_count = apdu_len / 2; - int i; - for (i = 0; i < net_count; i++) { - decode_unsigned16(&data->pdu[apdu_offset+2*i], &net); /* decode received NET values */ - add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ - } - break; - } - case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK: - { - /* first octet of the message contains rejection reason */ - /* next two octets contain NET (can be decoded for additional info on error) */ - error_code = data->pdu[apdu_offset]; - switch (error_code) { - case 0: - PRINT(ERROR, "Error!\n"); - break; - case 1: - PRINT(ERROR, "Error: Network unreachable\n"); - break; - case 2: - PRINT(ERROR, "Error: Network is busy\n"); - break; - case 3: - PRINT(ERROR, "Error: Unknown network message type\n"); - break; - case 4: - PRINT(ERROR, "Error: Message too long\n"); - break; - } - break; - } - case NETWORK_MESSAGE_INIT_RT_TABLE: - PRINT(INFO, "Recieved Initialize-Routing-Table message\n"); - if (data->pdu[apdu_offset] > 0) { - int net_count = data->pdu[apdu_offset]; - while (net_count--) { - int i = 1; - decode_unsigned16(&data->pdu[apdu_offset+i], &net); /* decode received NET values */ - add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ - if (data->pdu[apdu_offset+i+3] > 0) /* find next NET value */ - i = data->pdu[apdu_offset+i+3] + 4; - else - i = i + 4; - } - buff_len = create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, NULL); - } else - buff_len = create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, &buff); - break; + case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: + { + PRINT(INFO, "Recieved I-Am-Router-To-Network message\n"); + int net_count = apdu_len / 2; + int i; + for (i = 0; i < net_count; i++) { + decode_unsigned16(&data->pdu[apdu_offset + 2 * i], &net); /* decode received NET values */ + add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ + } + break; + } + case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK: + { + /* first octet of the message contains rejection reason */ + /* next two octets contain NET (can be decoded for additional info on error) */ + error_code = data->pdu[apdu_offset]; + switch (error_code) { + case 0: + PRINT(ERROR, "Error!\n"); + break; + case 1: + PRINT(ERROR, "Error: Network unreachable\n"); + break; + case 2: + PRINT(ERROR, "Error: Network is busy\n"); + break; + case 3: + PRINT(ERROR, "Error: Unknown network message type\n"); + break; + case 4: + PRINT(ERROR, "Error: Message too long\n"); + break; + } + break; + } + case NETWORK_MESSAGE_INIT_RT_TABLE: + PRINT(INFO, "Recieved Initialize-Routing-Table message\n"); + if (data->pdu[apdu_offset] > 0) { + int net_count = data->pdu[apdu_offset]; + while (net_count--) { + int i = 1; + decode_unsigned16(&data->pdu[apdu_offset + i], &net); /* decode received NET values */ + add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ + if (data->pdu[apdu_offset + i + 3] > 0) /* find next NET value */ + i = data->pdu[apdu_offset + i + 3] + 4; + else + i = i + 4; + } + buff_len = + create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, + data, buff, NULL); + } else + buff_len = + create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, + data, buff, &buff); + break; - case NETWORK_MESSAGE_INIT_RT_TABLE_ACK: - PRINT(INFO, "Recieved Initialize-Routing-Table-Ack message\n"); - if (data->pdu[apdu_offset] > 0) { - int net_count = data->pdu[apdu_offset]; - while (net_count--) { - int i = 1; - decode_unsigned16(&data->pdu[apdu_offset+i], &net); /* decode received NET values */ - add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ - if (data->pdu[apdu_offset+i+3] > 0) /* find next NET value */ - i = data->pdu[apdu_offset+i+3] + 4; - else - i = i + 4; - } - } - break; + case NETWORK_MESSAGE_INIT_RT_TABLE_ACK: + PRINT(INFO, "Recieved Initialize-Routing-Table-Ack message\n"); + if (data->pdu[apdu_offset] > 0) { + int net_count = data->pdu[apdu_offset]; + while (net_count--) { + int i = 1; + decode_unsigned16(&data->pdu[apdu_offset + i], &net); /* decode received NET values */ + add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ + if (data->pdu[apdu_offset + i + 3] > 0) /* find next NET value */ + i = data->pdu[apdu_offset + i + 3] + 4; + else + i = i + 4; + } + } + break; - case NETWORK_MESSAGE_INVALID: - case NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK: - case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK: - case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK: - case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK: - case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK: - /* hell if I know what to do with these messages */ - break; + case NETWORK_MESSAGE_INVALID: + case NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK: + case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK: + case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK: + case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK: + case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK: + /* hell if I know what to do with these messages */ + break; - default: - PRINT(ERROR, "Error: Message unsupported\n"); - break; - } + default: + PRINT(ERROR, "Error: Message unsupported\n"); + break; + } - return buff_len; + return buff_len; } uint16_t create_network_message( - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - MSG_DATA *data, - uint8_t **buff, - void *val) { + BACNET_NETWORK_MESSAGE_TYPE network_message_type, + MSG_DATA * data, + uint8_t ** buff, + void *val) +{ - int16_t buff_len; - bool data_expecting_reply = false; - BACNET_NPDU_DATA npdu_data; + int16_t buff_len; + bool data_expecting_reply = false; + BACNET_NPDU_DATA npdu_data; - if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE) - data_expecting_reply = true; - init_npdu(&npdu_data, network_message_type, data_expecting_reply); + if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE) + data_expecting_reply = true; + init_npdu(&npdu_data, network_message_type, data_expecting_reply); - *buff = (uint8_t*)malloc(128); /* resolve different length */ + *buff = (uint8_t *) malloc(128); /* resolve different length */ - /* manual destination setup for Init-RT-Table-Ack message */ - data->dest.net = BACNET_BROADCAST_NETWORK; - buff_len = npdu_encode_pdu(*buff, &data->dest, NULL, &npdu_data); + /* manual destination setup for Init-RT-Table-Ack message */ + data->dest.net = BACNET_BROADCAST_NETWORK; + buff_len = npdu_encode_pdu(*buff, &data->dest, NULL, &npdu_data); - switch (network_message_type) { + switch (network_message_type) { - case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: - if (val != NULL) { - uint8_t * valptr = (uint8_t*)val; - uint16_t val16 = (valptr[0]) + (valptr[1] << 8); - buff_len += encode_unsigned16(*buff+buff_len, val16); - } - break; + case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: + if (val != NULL) { + uint8_t *valptr = (uint8_t *) val; + uint16_t val16 = (valptr[0]) + (valptr[1] << 8); + buff_len += encode_unsigned16(*buff + buff_len, val16); + } + break; - case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: - if (val != NULL) { - uint8_t * valptr = (uint8_t*)val; - uint16_t val16 = (valptr[0]) + (valptr[1] << 8); - buff_len += encode_unsigned16(*buff+buff_len, val16); - } - else { - ROUTER_PORT *port = head; - DNET *dnet; - while (port != NULL) { - if (port->route_info.net != data->src.net) { - buff_len += encode_unsigned16(*buff+buff_len, port->route_info.net); - dnet = port->route_info.dnets; - while (dnet != NULL) { - buff_len += encode_unsigned16(*buff+buff_len, dnet->net); - dnet = dnet->next; - } - port = port->next; - } else { - dnet = port->route_info.dnets; - while (dnet != NULL) { - buff_len += encode_unsigned16(*buff+buff_len, dnet->net); - dnet = dnet->next; - } - port = port->next; - } - } - } - break; + case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: + if (val != NULL) { + uint8_t *valptr = (uint8_t *) val; + uint16_t val16 = (valptr[0]) + (valptr[1] << 8); + buff_len += encode_unsigned16(*buff + buff_len, val16); + } else { + ROUTER_PORT *port = head; + DNET *dnet; + while (port != NULL) { + if (port->route_info.net != data->src.net) { + buff_len += + encode_unsigned16(*buff + buff_len, + port->route_info.net); + dnet = port->route_info.dnets; + while (dnet != NULL) { + buff_len += + encode_unsigned16(*buff + buff_len, dnet->net); + dnet = dnet->next; + } + port = port->next; + } else { + dnet = port->route_info.dnets; + while (dnet != NULL) { + buff_len += + encode_unsigned16(*buff + buff_len, dnet->net); + dnet = dnet->next; + } + port = port->next; + } + } + } + break; - case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK: - { - uint8_t * valptr = (uint8_t*)val; - uint16_t val16 = (valptr[0]) + (valptr[1] << 8); - buff_len += encode_unsigned16(*buff + buff_len, val16); - break; - } - case NETWORK_MESSAGE_INIT_RT_TABLE: - case NETWORK_MESSAGE_INIT_RT_TABLE_ACK: - if ((uint8_t*)val) { - (*buff)[buff_len++] = (uint8_t) port_count; + case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK: + { + uint8_t *valptr = (uint8_t *) val; + uint16_t val16 = (valptr[0]) + (valptr[1] << 8); + buff_len += encode_unsigned16(*buff + buff_len, val16); + break; + } + case NETWORK_MESSAGE_INIT_RT_TABLE: + case NETWORK_MESSAGE_INIT_RT_TABLE_ACK: + if ((uint8_t *) val) { + (*buff)[buff_len++] = (uint8_t) port_count; - if (port_count > 0) { - ROUTER_PORT *port = head; - uint8_t portID = 1; + if (port_count > 0) { + ROUTER_PORT *port = head; + uint8_t portID = 1; - while (port != NULL) { - buff_len += encode_unsigned16(*buff+buff_len, port->route_info.net); - (*buff)[buff_len++] = portID++; - (*buff)[buff_len++] = 0; - port = port->next; - } - } - } else - (*buff)[buff_len++] = (uint8_t) 0; - break; + while (port != NULL) { + buff_len += + encode_unsigned16(*buff + buff_len, + port->route_info.net); + (*buff)[buff_len++] = portID++; + (*buff)[buff_len++] = 0; + port = port->next; + } + } + } else + (*buff)[buff_len++] = (uint8_t) 0; + break; - case NETWORK_MESSAGE_INVALID: - case NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK: - case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK: - case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK: - case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK: - case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK: - /* hell if I know what to do with these messages */ - break; - } + case NETWORK_MESSAGE_INVALID: + case NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK: + case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK: + case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK: + case NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK: + case NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK: + /* hell if I know what to do with these messages */ + break; + } - return buff_len; + return buff_len; } void send_network_message( - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - MSG_DATA *data, - uint8_t **buff, - void *val) { + BACNET_NETWORK_MESSAGE_TYPE network_message_type, + MSG_DATA * data, + uint8_t ** buff, + void *val) +{ - BACMSG msg; - ROUTER_PORT *port = head; - int16_t buff_len; + BACMSG msg; + ROUTER_PORT *port = head; + int16_t buff_len; - if (!data) { - data = (MSG_DATA*)malloc(sizeof(MSG_DATA)); - data->dest.net = BACNET_BROADCAST_NETWORK; - } + if (!data) { + data = (MSG_DATA *) malloc(sizeof(MSG_DATA)); + data->dest.net = BACNET_BROADCAST_NETWORK; + } - buff_len = create_network_message(network_message_type, data, buff, val); + buff_len = create_network_message(network_message_type, data, buff, val); - /* form network message */ - data->pdu = *buff; - data->pdu_len = buff_len; - msg.origin = head->main_id; - msg.type = DATA; - msg.data = data; + /* form network message */ + data->pdu = *buff; + data->pdu_len = buff_len; + msg.origin = head->main_id; + msg.type = DATA; + msg.data = data; - data->ref_count = port_count; - while (port != NULL) { - if (port->state == FINISHED) { - port = port->next; - continue; - } - send_to_msgbox(port->port_id, &msg); - port = port->next; - } + data->ref_count = port_count; + while (port != NULL) { + if (port->state == FINISHED) { + port = port->next; + continue; + } + send_to_msgbox(port->port_id, &msg); + port = port->next; + } } void init_npdu( - BACNET_NPDU_DATA *npdu_data, - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - bool data_expecting_reply) { + BACNET_NPDU_DATA * npdu_data, + BACNET_NETWORK_MESSAGE_TYPE network_message_type, + bool data_expecting_reply) +{ - if (npdu_data) { - npdu_data->data_expecting_reply = data_expecting_reply; - npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; - npdu_data->network_layer_message = true; - npdu_data->network_message_type = network_message_type; - npdu_data->vendor_id = 0; - npdu_data->priority = MESSAGE_PRIORITY_NORMAL; - npdu_data->hop_count = HOP_COUNT_DEFAULT; - } + if (npdu_data) { + npdu_data->data_expecting_reply = data_expecting_reply; + npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; + npdu_data->network_layer_message = true; + npdu_data->network_message_type = network_message_type; + npdu_data->vendor_id = 0; + npdu_data->priority = MESSAGE_PRIORITY_NORMAL; + npdu_data->hop_count = HOP_COUNT_DEFAULT; + } } diff --git a/bacnet-stack/demo/router/network_layer.h b/bacnet-stack/demo/router/network_layer.h index a8ae428c..e04284ba 100644 --- a/bacnet-stack/demo/router/network_layer.h +++ b/bacnet-stack/demo/router/network_layer.h @@ -29,25 +29,25 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #include "portthread.h" uint16_t process_network_message( - BACMSG *msg, - MSG_DATA *data, - uint8_t **buff); + BACMSG * msg, + MSG_DATA * data, + uint8_t ** buff); uint16_t create_network_message( - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - MSG_DATA *data, - uint8_t **buff, - void *val); + BACNET_NETWORK_MESSAGE_TYPE network_message_type, + MSG_DATA * data, + uint8_t ** buff, + void *val); void send_network_message( - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - MSG_DATA *data, - uint8_t **buff, - void *val); + BACNET_NETWORK_MESSAGE_TYPE network_message_type, + MSG_DATA * data, + uint8_t ** buff, + void *val); void init_npdu( - BACNET_NPDU_DATA *npdu_data, - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - bool data_expecting_reply); + BACNET_NPDU_DATA * npdu_data, + BACNET_NETWORK_MESSAGE_TYPE network_message_type, + bool data_expecting_reply); #endif /* end of NETWORK_LAYER_H */ diff --git a/bacnet-stack/demo/router/portthread.c b/bacnet-stack/demo/router/portthread.c index f6d6da8d..763401c4 100644 --- a/bacnet-stack/demo/router/portthread.c +++ b/bacnet-stack/demo/router/portthread.c @@ -19,98 +19,102 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #include #include "portthread.h" -ROUTER_PORT* find_snet( - MSGBOX_ID id) { +ROUTER_PORT *find_snet( + MSGBOX_ID id) +{ - ROUTER_PORT *port = head; + ROUTER_PORT *port = head; - while (port != NULL) { - if (port->port_id == id) - return port; - port = port->next; - } + while (port != NULL) { + if (port->port_id == id) + return port; + port = port->next; + } - return NULL; + return NULL; } -ROUTER_PORT* find_dnet( - uint16_t net, - BACNET_ADDRESS *addr) { +ROUTER_PORT *find_dnet( + uint16_t net, + BACNET_ADDRESS * addr) +{ - ROUTER_PORT *port = head; - DNET *dnet; + ROUTER_PORT *port = head; + DNET *dnet; - /* for broadcast messages no search is needed */ - if (net == BACNET_BROADCAST_NETWORK) - return port; + /* for broadcast messages no search is needed */ + if (net == BACNET_BROADCAST_NETWORK) + return port; - while(port != NULL) { + while (port != NULL) { - /* check if DNET is directly connected to the router */ - if (net == port->route_info.net) - return port; + /* check if DNET is directly connected to the router */ + if (net == port->route_info.net) + return port; - /* else search router ports DNET list */ - else if (port->route_info.dnets) { - dnet = port->route_info.dnets; - while (dnet != NULL) { - if (net == dnet->net) { - if (addr) { - memmove(&addr->len, &dnet->mac_len, 1); - memmove(&addr->adr[0], &dnet->mac[0], MAX_MAC_LEN); - } - return port; - } - dnet = dnet->next; - } - } - port = port->next; - } + /* else search router ports DNET list */ + else if (port->route_info.dnets) { + dnet = port->route_info.dnets; + while (dnet != NULL) { + if (net == dnet->net) { + if (addr) { + memmove(&addr->len, &dnet->mac_len, 1); + memmove(&addr->adr[0], &dnet->mac[0], MAX_MAC_LEN); + } + return port; + } + dnet = dnet->next; + } + } + port = port->next; + } - return NULL; + return NULL; } void add_dnet( - RT_ENTRY *route_info, - uint16_t net, - BACNET_ADDRESS addr) { + RT_ENTRY * route_info, + uint16_t net, + BACNET_ADDRESS addr) +{ - DNET *dnet = route_info->dnets; - DNET *tmp; + DNET *dnet = route_info->dnets; + DNET *tmp; - if (dnet == NULL) { - route_info->dnets = (DNET*)malloc(sizeof(DNET)); - memmove(&route_info->dnets->mac_len, &addr.len, 1); - memmove(&route_info->dnets->mac[0], &addr.adr[0], MAX_MAC_LEN); - route_info->dnets->net = net; - route_info->dnets->state = true; - route_info->dnets->next = NULL; - } else { + if (dnet == NULL) { + route_info->dnets = (DNET *) malloc(sizeof(DNET)); + memmove(&route_info->dnets->mac_len, &addr.len, 1); + memmove(&route_info->dnets->mac[0], &addr.adr[0], MAX_MAC_LEN); + route_info->dnets->net = net; + route_info->dnets->state = true; + route_info->dnets->next = NULL; + } else { - while (dnet != NULL) { - if (dnet->net == net) /* make sure NETs are not repeated */ - return; - tmp = dnet; - dnet = dnet->next; - } + while (dnet != NULL) { + if (dnet->net == net) /* make sure NETs are not repeated */ + return; + tmp = dnet; + dnet = dnet->next; + } - dnet = (DNET*)malloc(sizeof(DNET)); - memmove(&dnet->mac_len, &addr.len, 1); - memmove(&dnet->mac[0], &addr.adr[0], MAX_MAC_LEN); - dnet->net = net; - dnet->state = true; - dnet->next = NULL; - tmp->next = dnet; - } + dnet = (DNET *) malloc(sizeof(DNET)); + memmove(&dnet->mac_len, &addr.len, 1); + memmove(&dnet->mac[0], &addr.adr[0], MAX_MAC_LEN); + dnet->net = net; + dnet->state = true; + dnet->next = NULL; + tmp->next = dnet; + } } void cleanup_dnets( - DNET *dnets) { + DNET * dnets) +{ - DNET *dnet = dnets; - while(dnet != NULL) { - dnet = dnet->next; - free(dnets); - dnets = dnet; - } + DNET *dnet = dnets; + while (dnet != NULL) { + dnet = dnet->next; + free(dnets); + dnets = dnet; + } } diff --git a/bacnet-stack/demo/router/portthread.h b/bacnet-stack/demo/router/portthread.h index 1ffb5690..ec689eea 100644 --- a/bacnet-stack/demo/router/portthread.h +++ b/bacnet-stack/demo/router/portthread.h @@ -36,90 +36,91 @@ Copyright (C) 2012 Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv #endif typedef enum { - BIP = 1, - MSTP = 2 + BIP = 1, + MSTP = 2 } DL_TYPE; typedef enum { - INIT, - INIT_FAILED, - RUNNING, - FINISHED + INIT, + INIT_FAILED, + RUNNING, + FINISHED } PORT_STATE; /* router port thread function */ -typedef void* (*PORT_FUNC)( - void*); +typedef void *( + *PORT_FUNC) ( + void *); typedef enum { - PARITY_NONE, - PARITY_EVEN, - PARITY_ODD -}PARITY; + PARITY_NONE, + PARITY_EVEN, + PARITY_ODD +} PARITY; /* port specific parameters */ typedef union _port_params { - struct { - uint16_t port; - } bip_params; - struct { - uint32_t baudrate; - PARITY parity; - uint8_t databits; - uint8_t stopbits; - uint8_t max_master; - uint8_t max_frames; - } mstp_params; + struct { + uint16_t port; + } bip_params; + struct { + uint32_t baudrate; + PARITY parity; + uint8_t databits; + uint8_t stopbits; + uint8_t max_master; + uint8_t max_frames; + } mstp_params; } PORT_PARAMS; /* list node for reacheble networks */ typedef struct _dnet { - uint8_t mac[MAX_MAC_LEN]; - uint8_t mac_len; - uint16_t net; - bool state; /* enabled or disabled */ - struct _dnet *next; + uint8_t mac[MAX_MAC_LEN]; + uint8_t mac_len; + uint16_t net; + bool state; /* enabled or disabled */ + struct _dnet *next; } DNET; /* information for routing table */ typedef struct _routing_table_entry { - uint8_t mac[MAX_MAC_LEN]; - uint8_t mac_len; - uint16_t net; - DNET *dnets; + uint8_t mac[MAX_MAC_LEN]; + uint8_t mac_len; + uint16_t net; + DNET *dnets; } RT_ENTRY; typedef struct _port { - DL_TYPE type; - PORT_STATE state; - MSGBOX_ID main_id; /* same for every router port */ - MSGBOX_ID port_id; /* different for every router port */ - char *iface; - PORT_FUNC func; - RT_ENTRY route_info; - PORT_PARAMS params; - struct _port *next; /* pointer to next list node */ + DL_TYPE type; + PORT_STATE state; + MSGBOX_ID main_id; /* same for every router port */ + MSGBOX_ID port_id; /* different for every router port */ + char *iface; + PORT_FUNC func; + RT_ENTRY route_info; + PORT_PARAMS params; + struct _port *next; /* pointer to next list node */ } ROUTER_PORT; extern ROUTER_PORT *head; extern int port_count; /* get recieving router port */ -ROUTER_PORT* find_snet( - MSGBOX_ID id); +ROUTER_PORT *find_snet( + MSGBOX_ID id); /* get sending router port */ -ROUTER_PORT* find_dnet( - uint16_t net, - BACNET_ADDRESS *addr); +ROUTER_PORT *find_dnet( + uint16_t net, + BACNET_ADDRESS * addr); /* add reacheble network for specified router port */ void add_dnet( - RT_ENTRY *route_info, - uint16_t net, - BACNET_ADDRESS addr); + RT_ENTRY * route_info, + uint16_t net, + BACNET_ADDRESS addr); void cleanup_dnets( - DNET *dnets); + DNET * dnets); #endif /* end of PORTTHREAD_H */ diff --git a/bacnet-stack/demo/server/main.c b/bacnet-stack/demo/server/main.c index dd9ab6f2..092a2dc9 100644 --- a/bacnet-stack/demo/server/main.c +++ b/bacnet-stack/demo/server/main.c @@ -151,7 +151,7 @@ int main( 0 }; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 1; /* milliseconds */ + unsigned timeout = 1; /* milliseconds */ time_t last_seconds = 0; time_t current_seconds = 0; uint32_t elapsed_seconds = 0; @@ -188,7 +188,7 @@ int main( npdu_handler(&src, &Rx_Buf[0], pdu_len); } /* at least one second has passed */ - elapsed_seconds = (uint32_t)(current_seconds - last_seconds); + elapsed_seconds = (uint32_t) (current_seconds - last_seconds); if (elapsed_seconds) { last_seconds = current_seconds; dcc_timer_seconds(elapsed_seconds); diff --git a/bacnet-stack/demo/uptransfer/main.c b/bacnet-stack/demo/uptransfer/main.c index 7acd1ed8..eb720779 100644 --- a/bacnet-stack/demo/uptransfer/main.c +++ b/bacnet-stack/demo/uptransfer/main.c @@ -152,7 +152,7 @@ int main( 0 }; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 10; /* milliseconds */ + unsigned timeout = 10; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -213,7 +213,7 @@ int main( if (strcmp(argv[1], "broadcast") == 0) { Target_Broadcast = true; Target_DNET = BACNET_BROADCAST_NETWORK; - } else if (strncmp(argv[1],"dnet=",5) == 0) { + } else if (strncmp(argv[1], "dnet=", 5) == 0) { Target_Broadcast = true; Target_DNET = strtol(&argv[1][5], NULL, 0); } else { diff --git a/bacnet-stack/demo/whohas/main.c b/bacnet-stack/demo/whohas/main.c index 8c8f8d77..735c0f8e 100644 --- a/bacnet-stack/demo/whohas/main.c +++ b/bacnet-stack/demo/whohas/main.c @@ -113,8 +113,7 @@ static void print_usage( char *filename) { printf("Usage: %s [device-instance-min device-instance-min] " - " [--help]\r\n", - filename); + " [--help]\r\n", filename); } static void print_help( @@ -123,12 +122,12 @@ static void print_help( print_usage(filename); printf("Send BACnet WhoHas request to devices, \r\n" "and wait %u milliseconds (BACNET_APDU_TIMEOUT) for responses.\r\n" - "The device-instance-min or max can be 0 to %d.\r\n" - "\r\n" "Use either:\r\n" "The object-type can be 0 to %d.\r\n" + "The device-instance-min or max can be 0 to %d.\r\n" "\r\n" + "Use either:\r\n" "The object-type can be 0 to %d.\r\n" "The object-instance can be 0 to %d.\r\n" "or:\r\n" "The object-name can be any string of characters.\r\n", - BACNET_MAX_INSTANCE, (unsigned)apdu_timeout(), - BACNET_MAX_OBJECT, BACNET_MAX_INSTANCE); + BACNET_MAX_INSTANCE, (unsigned) apdu_timeout(), BACNET_MAX_OBJECT, + BACNET_MAX_INSTANCE); } int main( @@ -144,32 +143,29 @@ int main( time_t last_seconds = 0; time_t current_seconds = 0; time_t timeout_seconds = 0; - int argi = 0; + int argi = 0; bool by_name = false; if (argc < 2) { print_usage(filename_remove_path(argv[0])); return 0; } - /* print help if requested */ - for (argi = 1; argi < argc; argi++) - { - if (strcmp(argv[argi], "--help") == 0) { - print_help(filename_remove_path(argv[0])); - return 0; - } - } + /* print help if requested */ + for (argi = 1; argi < argc; argi++) { + if (strcmp(argv[argi], "--help") == 0) { + print_help(filename_remove_path(argv[0])); + return 0; + } + } /* decode the command line parameters */ if (argc < 3) { /* bacwh "name" */ - Target_Object_Instance_Min = - Target_Object_Instance_Max = -1; + Target_Object_Instance_Min = Target_Object_Instance_Max = -1; Target_Object_Name = argv[1]; by_name = true; } else if (argc < 4) { /* bacwh 8 1234 */ - Target_Object_Instance_Min = - Target_Object_Instance_Max = -1; + Target_Object_Instance_Min = Target_Object_Instance_Max = -1; Target_Object_Type = strtol(argv[1], NULL, 0); Target_Object_Instance = strtol(argv[2], NULL, 0); } else if (argc < 5) { @@ -212,14 +208,12 @@ int main( } } if (Target_Object_Instance_Min > BACNET_MAX_INSTANCE) { - fprintf(stderr, - "object-instance-min=%u - it must be less than %u\r\n", + fprintf(stderr, "object-instance-min=%u - it must be less than %u\r\n", Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1); return 1; } if (Target_Object_Instance_Max > BACNET_MAX_INSTANCE) { - fprintf(stderr, - "object-instance-max=%u - it must be less than %u\r\n", + fprintf(stderr, "object-instance-max=%u - it must be less than %u\r\n", Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1); return 1; } @@ -233,15 +227,11 @@ int main( timeout_seconds = apdu_timeout() / 1000; /* send the request */ if (by_name) { - Send_WhoHas_Name( - Target_Object_Instance_Min, - Target_Object_Instance_Max, - Target_Object_Name); + Send_WhoHas_Name(Target_Object_Instance_Min, + Target_Object_Instance_Max, Target_Object_Name); } else { - Send_WhoHas_Object( - Target_Object_Instance_Min, - Target_Object_Instance_Max, - Target_Object_Type, + Send_WhoHas_Object(Target_Object_Instance_Min, + Target_Object_Instance_Max, Target_Object_Type, Target_Object_Instance); } /* loop forever */ diff --git a/bacnet-stack/demo/whois/main.c b/bacnet-stack/demo/whois/main.c index f9634ef0..b20475c4 100644 --- a/bacnet-stack/demo/whois/main.c +++ b/bacnet-stack/demo/whois/main.c @@ -63,7 +63,7 @@ static bool Error_Detected = false; #define BAC_ADDRESS_MULT 1 struct address_entry { - struct address_entry * next; + struct address_entry *next; uint8_t Flags; uint32_t device_id; unsigned max_apdu; @@ -71,38 +71,41 @@ struct address_entry { }; static struct address_table { - struct address_entry * first; - struct address_entry * last; -} Address_Table = {0}; + struct address_entry *first; + struct address_entry *last; +} Address_Table = { +0}; -struct address_entry * alloc_address_entry(void) +struct address_entry *alloc_address_entry( + void) { - struct address_entry * rval; - rval = (struct address_entry *)calloc(1, sizeof(struct address_entry)); - if(Address_Table.first == 0) - { - Address_Table.first = Address_Table.last = rval; - } - else - { - Address_Table.last->next = rval; - Address_Table.last = rval; - } - return rval; + struct address_entry *rval; + rval = (struct address_entry *) calloc(1, sizeof(struct address_entry)); + if (Address_Table.first == 0) { + Address_Table.first = Address_Table.last = rval; + } else { + Address_Table.last->next = rval; + Address_Table.last = rval; + } + return rval; } -bool bacnet_address_matches(BACNET_ADDRESS * a1, BACNET_ADDRESS * a2) +bool bacnet_address_matches( + BACNET_ADDRESS * a1, + BACNET_ADDRESS * a2) { - int i = 0; - if(a1->net != a2->net) return false; - if(a1->len != a2->len) return false; - for(;ilen;i++) - if(a1->adr[i]!=a2->adr[i]) - return false; - return true; + int i = 0; + if (a1->net != a2->net) + return false; + if (a1->len != a2->len) + return false; + for (; i < a1->len; i++) + if (a1->adr[i] != a2->adr[i]) + return false; + return true; } void address_table_add( @@ -111,21 +114,20 @@ void address_table_add( BACNET_ADDRESS * src) { struct address_entry *pMatch; - uint8_t flags = 0; + uint8_t flags = 0; - pMatch = Address_Table.first; + pMatch = Address_Table.first; while (pMatch) { - if (pMatch->device_id == device_id) - { + if (pMatch->device_id == device_id) { if (bacnet_address_matches(&pMatch->address, src)) - return; - flags |= BAC_ADDRESS_MULT; - pMatch->Flags |= BAC_ADDRESS_MULT; + return; + flags |= BAC_ADDRESS_MULT; + pMatch->Flags |= BAC_ADDRESS_MULT; } pMatch = pMatch->next; } - pMatch = alloc_address_entry(); + pMatch = alloc_address_entry(); pMatch->Flags = flags; pMatch->device_id = device_id; @@ -219,124 +221,107 @@ static void init_service_handlers( apdu_set_reject_handler(MyRejectHandler); } -void print_macaddr(uint8_t * addr, int len) +void print_macaddr( + uint8_t * addr, + int len) { - int j = 0; + int j = 0; - while(j < len) - { - if (j != 0) { - printf(":"); - } - printf("%02X", addr[j]); - j++; - } - while(j < MAX_MAC_LEN) - { - printf(" "); - j++; - } + while (j < len) { + if (j != 0) { + printf(":"); + } + printf("%02X", addr[j]); + j++; + } + while (j < MAX_MAC_LEN) { + printf(" "); + j++; + } } static void print_address_cache( - void) + void) { - BACNET_ADDRESS address; - unsigned total_addresses = 0; - unsigned dup_addresses = 0; - struct address_entry *addr; - uint8_t local_sadr = 0; + BACNET_ADDRESS address; + unsigned total_addresses = 0; + unsigned dup_addresses = 0; + struct address_entry *addr; + uint8_t local_sadr = 0; - /* NOTE: this string format is parsed by src/address.c, - so these must be compatible. */ + /* NOTE: this string format is parsed by src/address.c, + so these must be compatible. */ - printf(";%-7s %-20s %-5s %-20s %-4s\n", - "Device", "MAC (hex)", "SNET", "SADR (hex)", "APDU"); - printf(";-------- -------------------- ----- -------------------- ----\n"); + printf(";%-7s %-20s %-5s %-20s %-4s\n", "Device", "MAC (hex)", "SNET", + "SADR (hex)", "APDU"); + printf(";-------- -------------------- ----- -------------------- ----\n"); - addr = Address_Table.first; - while (addr) - { - bacnet_address_copy(&address, &addr->address); - total_addresses++; - if(addr->Flags & BAC_ADDRESS_MULT) - { - dup_addresses++; - printf(";"); - } - else - { - printf(" "); - } - printf(" %-7u ", addr->device_id); - print_macaddr(address.mac, address.mac_len); - printf(" %-5hu ", address.net); - if (address.net) { - print_macaddr(address.adr, address.len); - } else { - print_macaddr(&local_sadr, 1); - } - printf(" %-4hu ", addr->max_apdu); - printf("\n"); + addr = Address_Table.first; + while (addr) { + bacnet_address_copy(&address, &addr->address); + total_addresses++; + if (addr->Flags & BAC_ADDRESS_MULT) { + dup_addresses++; + printf(";"); + } else { + printf(" "); + } + printf(" %-7u ", addr->device_id); + print_macaddr(address.mac, address.mac_len); + printf(" %-5hu ", address.net); + if (address.net) { + print_macaddr(address.adr, address.len); + } else { + print_macaddr(&local_sadr, 1); + } + printf(" %-4hu ", addr->max_apdu); + printf("\n"); - addr = addr->next; - } - printf(";\n; Total Devices: %u\n", total_addresses); - if (dup_addresses) { - printf("; * Duplicate Devices: %u\n", dup_addresses); - } + addr = addr->next; + } + printf(";\n; Total Devices: %u\n", total_addresses); + if (dup_addresses) { + printf("; * Duplicate Devices: %u\n", dup_addresses); + } } -static int print_usage(char* exe_name){ - printf( - "Usage:\n" - "\n" - "%s [[network]:[address]] " - "[device-instance-min [device-instance-max]] [--help]\n" , - exe_name); - return 1; +static int print_usage( + char *exe_name) +{ + printf("Usage:\n" "\n" "%s [[network]:[address]] " + "[device-instance-min [device-instance-max]] [--help]\n", exe_name); + return 1; } -static int print_help(char* exe_name){ - printf( - "Usage:\n" - "\n" - "%s [[network]:[address]] " - "[device-instance-min [device-instance-max]] [--help]\n" - "\n" - " Send BACnet WhoIs service request to a device or multiple devices, and wait\n" - " for responses. Displays any devices found and their network information.\n" - "\n" - "device-instance:\r\n" - " BACnet Device Object Instance number that you are trying to send a Who-Is\n" - " service request. The value should be in the range of 0 to 4194303. A range\n" - " of values can also be specified by using a minimum value and a maximum value.\n" - "\n" - "network:\n" - " BACnet network number for directed requests. Valid range is from 0 to 65535\n" - " where 0 is the local connection and 65535 is network broadcast.\n" - "\n" - "address:\n" - " BACnet mac address number. Valid ranges are from 0 to 255 or a IP connection \n" - " string including port number like 10.1.2.3:47808.\n" - "\n" - "Examples:\n\n" - "To send a WhoIs request to Network 123:\n" - "%s 123:\n\n" - "To send a WhoIs request to Network 123 Address 5:\n" - "%s 123:5\n\n" - "To send a WhoIs request to Device 123:\n" - "%s 123\n\n" - "To send a WhoIs request to Devices from 1000 to 9000:\n" - "%s 1000 9000\n\n" - "To send a WhoIs request to Devices from 1000 to 9000 on Network 123:\n" - "%s 123: 1000 9000\n\n" - "To send a WhoIs request to all devices:\n" - "%s\n\n", - exe_name,exe_name,exe_name,exe_name,exe_name,exe_name,exe_name); - return 1; +static int print_help( + char *exe_name) +{ + printf("Usage:\n" "\n" "%s [[network]:[address]] " + "[device-instance-min [device-instance-max]] [--help]\n" "\n" + " Send BACnet WhoIs service request to a device or multiple devices, and wait\n" + " for responses. Displays any devices found and their network information.\n" + "\n" "device-instance:\r\n" + " BACnet Device Object Instance number that you are trying to send a Who-Is\n" + " service request. The value should be in the range of 0 to 4194303. A range\n" + " of values can also be specified by using a minimum value and a maximum value.\n" + "\n" "network:\n" + " BACnet network number for directed requests. Valid range is from 0 to 65535\n" + " where 0 is the local connection and 65535 is network broadcast.\n" + "\n" "address:\n" + " BACnet mac address number. Valid ranges are from 0 to 255 or a IP connection \n" + " string including port number like 10.1.2.3:47808.\n" "\n" + "Examples:\n\n" "To send a WhoIs request to Network 123:\n" + "%s 123:\n\n" "To send a WhoIs request to Network 123 Address 5:\n" + "%s 123:5\n\n" "To send a WhoIs request to Device 123:\n" "%s 123\n\n" + "To send a WhoIs request to Devices from 1000 to 9000:\n" + "%s 1000 9000\n\n" + "To send a WhoIs request to Devices from 1000 to 9000 on Network 123:\n" + "%s 123: 1000 9000\n\n" "To send a WhoIs request to all devices:\n" + "%s\n\n", exe_name, exe_name, exe_name, exe_name, exe_name, exe_name, + exe_name); + return 1; } @@ -345,47 +330,39 @@ static int print_help(char* exe_name){ ** @return length of address parsed in bytes */ static int parse_bac_address( - BACNET_ADDRESS *dest, /* [out] BACNET Address*/ - char *src /* [in] nul terminated string to parse */ - ) + BACNET_ADDRESS * dest, /* [out] BACNET Address */ + char *src /* [in] nul terminated string to parse */ + ) { - int i = 0; - uint16_t s; - int a[4],p; - int c = sscanf(src,"%u.%u.%u.%u:%u",&a[0],&a[1],&a[2],&a[3],&p); + int i = 0; + uint16_t s; + int a[4], p; + int c = sscanf(src, "%u.%u.%u.%u:%u", &a[0], &a[1], &a[2], &a[3], &p); - dest->len = 0; + dest->len = 0; - if (c==1) - { - if( a[0] < 256 ) /* mstp */ - { - dest->adr[0] = a[0]; - dest->len = 1; - } - else if ( a[0] < 0x0FFFF ) /* lon */ - { - s = htons((uint16_t)a[0]); - memcpy(&dest->adr[0], &s, 2); - dest->len = 2; - } - else - return 0; - } - else if (c==5) /* ip address */ - { - for(i=0;i<4;i++) - { - if(a[i] == 0 || a[i] > 255) - return 0; + if (c == 1) { + if (a[0] < 256) { /* mstp */ + dest->adr[0] = a[0]; + dest->len = 1; + } else if (a[0] < 0x0FFFF) { /* lon */ + s = htons((uint16_t) a[0]); + memcpy(&dest->adr[0], &s, 2); + dest->len = 2; + } else + return 0; + } else if (c == 5) { /* ip address */ + for (i = 0; i < 4; i++) { + if (a[i] == 0 || a[i] > 255) + return 0; - dest->adr[i] = a[i]; - } - s = htons((uint16_t)p); - memcpy(&dest->adr[i], &s, 2); - dest->len = 6; - } - return dest->len; + dest->adr[i] = a[i]; + } + s = htons((uint16_t) p); + memcpy(&dest->adr[i], &s, 2); + dest->len = 6; + } + return dest->len; } @@ -404,68 +381,62 @@ int main( time_t last_seconds = 0; time_t current_seconds = 0; time_t timeout_seconds = 0; - BACNET_ADDRESS dest; - int argi; + BACNET_ADDRESS dest; + int argi; - /* print help if requested */ - for (argi = 1; argi < argc; argi++) - { - if (strcmp(argv[argi], "--help") == 0) { - print_help(filename_remove_path(argv[0])); - return 0; - } - } - - datalink_get_broadcast_address(&dest); - - /* decode the command line parameters */ - if (argc >= 2) { - char *s; - long v = strtol(argv[1], &s, 0); - if(*s++ == ':') - { - if(argv[1][0] != ':') - dest.net = (uint16_t) v; - dest.mac_len = 0; - if(isdigit(*s)) - parse_bac_address(&dest,s); - } - else - { - Target_Object_Instance_Min = Target_Object_Instance_Max = v; - } + /* print help if requested */ + for (argi = 1; argi < argc; argi++) { + if (strcmp(argv[argi], "--help") == 0) { + print_help(filename_remove_path(argv[0])); + return 0; + } } - if (argc <= 2){ - /* empty */ - } else if (argc == 3){ - if(Target_Object_Instance_Min == -1) - Target_Object_Instance_Min = - Target_Object_Instance_Max = strtol(argv[2], NULL, 0); - else - Target_Object_Instance_Max = strtol(argv[2], NULL, 0); - } else if (argc == 4){ + datalink_get_broadcast_address(&dest); + + /* decode the command line parameters */ + if (argc >= 2) { + char *s; + long v = strtol(argv[1], &s, 0); + if (*s++ == ':') { + if (argv[1][0] != ':') + dest.net = (uint16_t) v; + dest.mac_len = 0; + if (isdigit(*s)) + parse_bac_address(&dest, s); + } else { + Target_Object_Instance_Min = Target_Object_Instance_Max = v; + } + } + + if (argc <= 2) { + /* empty */ + } else if (argc == 3) { + if (Target_Object_Instance_Min == -1) + Target_Object_Instance_Min = Target_Object_Instance_Max = + strtol(argv[2], NULL, 0); + else + Target_Object_Instance_Max = strtol(argv[2], NULL, 0); + } else if (argc == 4) { Target_Object_Instance_Min = strtol(argv[2], NULL, 0); Target_Object_Instance_Max = strtol(argv[3], NULL, 0); } else { - print_usage(filename_remove_path(argv[0])); + print_usage(filename_remove_path(argv[0])); return 1; } if (Target_Object_Instance_Min > BACNET_MAX_INSTANCE) { - fprintf(stderr, - "device-instance-min=%u - it must be less than %u\r\n", + fprintf(stderr, "device-instance-min=%u - it must be less than %u\r\n", Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1); return 1; } if (Target_Object_Instance_Max > BACNET_MAX_INSTANCE) { - fprintf(stderr, - "device-instance-max=%u - it must be less than %u\r\n", + fprintf(stderr, "device-instance-max=%u - it must be less than %u\r\n", Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1); return 1; } - /* setup my info */ + /* setup my info */ Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); init_service_handlers(); address_init(); @@ -475,8 +446,9 @@ int main( last_seconds = time(NULL); timeout_seconds = apdu_timeout() / 1000; /* send the request */ - Send_WhoIs_To_Network(&dest,Target_Object_Instance_Min, Target_Object_Instance_Max); - /* loop forever */ + Send_WhoIs_To_Network(&dest, Target_Object_Instance_Min, + Target_Object_Instance_Max); + /* loop forever */ for (;;) { /* increment timer - exit if timed out */ current_seconds = time(NULL); diff --git a/bacnet-stack/demo/writefile/main.c b/bacnet-stack/demo/writefile/main.c index 5263d1a2..90bbbdae 100644 --- a/bacnet-stack/demo/writefile/main.c +++ b/bacnet-stack/demo/writefile/main.c @@ -180,7 +180,8 @@ int main( if (argc < 4) { /* FIXME: what about access method - record or stream? */ - printf("%s device-instance file-instance local-name [octet count] [pad value]\r\n", + printf + ("%s device-instance file-instance local-name [octet count] [pad value]\r\n", filename_remove_path(argv[0])); return 0; } @@ -281,8 +282,8 @@ int main( if (len < requestedOctetCount) { End_Of_File_Detected = true; if (pad_byte) { - memset(octetstring_value(&fileData)+len+1, - (int)Target_File_Requested_Octet_Pad_Byte, + memset(octetstring_value(&fileData) + len + 1, + (int) Target_File_Requested_Octet_Pad_Byte, requestedOctetCount - len); len = requestedOctetCount; } diff --git a/bacnet-stack/demo/writeprop/main.c b/bacnet-stack/demo/writeprop/main.c index f5cbb037..f807b271 100644 --- a/bacnet-stack/demo/writeprop/main.c +++ b/bacnet-stack/demo/writeprop/main.c @@ -345,7 +345,8 @@ int main( /* at least one second has passed */ if (current_seconds != last_seconds) - tsm_timer_milliseconds((uint16_t)((current_seconds - last_seconds) * 1000)); + tsm_timer_milliseconds((uint16_t) ((current_seconds - + last_seconds) * 1000)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ diff --git a/bacnet-stack/include/bacdef.h b/bacnet-stack/include/bacdef.h index c9a79a7d..444125d8 100644 --- a/bacnet-stack/include/bacdef.h +++ b/bacnet-stack/include/bacdef.h @@ -45,55 +45,55 @@ /* there are a few dependencies on the BACnet Protocol-Revision */ #if (BACNET_PROTOCOL_REVISION == 0) - #define MAX_ASHRAE_OBJECT_TYPE 18 - #define MAX_BACNET_SERVICES_SUPPORTED 35 +#define MAX_ASHRAE_OBJECT_TYPE 18 +#define MAX_BACNET_SERVICES_SUPPORTED 35 #elif (BACNET_PROTOCOL_REVISION == 1) - #define MAX_ASHRAE_OBJECT_TYPE 21 - #define MAX_BACNET_SERVICES_SUPPORTED 37 +#define MAX_ASHRAE_OBJECT_TYPE 21 +#define MAX_BACNET_SERVICES_SUPPORTED 37 #elif (BACNET_PROTOCOL_REVISION == 2) /* from 135-2001 version of the BACnet Standard */ - #define MAX_ASHRAE_OBJECT_TYPE 23 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 23 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 3) - #define MAX_ASHRAE_OBJECT_TYPE 23 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 23 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 4) /* from 135-2004 version of the BACnet Standard */ - #define MAX_ASHRAE_OBJECT_TYPE 25 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 25 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 5) - #define MAX_ASHRAE_OBJECT_TYPE 30 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 30 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 6) - #define MAX_ASHRAE_OBJECT_TYPE 31 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 31 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 7) - #define MAX_ASHRAE_OBJECT_TYPE 31 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 31 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 8) - #define MAX_ASHRAE_OBJECT_TYPE 31 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 31 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 9) /* from 135-2008 version of the BACnet Standard */ - #define MAX_ASHRAE_OBJECT_TYPE 38 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 38 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 10) - #define MAX_ASHRAE_OBJECT_TYPE 51 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 51 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 11) - #define MAX_ASHRAE_OBJECT_TYPE 51 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 51 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 12) /* from 135-2010 version of the BACnet Standard */ - #define MAX_ASHRAE_OBJECT_TYPE 51 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 51 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 13) - #define MAX_ASHRAE_OBJECT_TYPE 53 - #define MAX_BACNET_SERVICES_SUPPORTED 40 +#define MAX_ASHRAE_OBJECT_TYPE 53 +#define MAX_BACNET_SERVICES_SUPPORTED 40 #elif (BACNET_PROTOCOL_REVISION == 14) /* from 135-2012 version of the BACnet Standard */ - #define MAX_ASHRAE_OBJECT_TYPE 55 - #define MAX_BACNET_SERVICES_SUPPORTED 41 +#define MAX_ASHRAE_OBJECT_TYPE 55 +#define MAX_BACNET_SERVICES_SUPPORTED 41 #else #error MAX_ASHRAE_OBJECT_TYPE and MAX_BACNET_SERVICES_SUPPORTED not defined! #endif diff --git a/bacnet-stack/include/bacenum.h b/bacnet-stack/include/bacenum.h index 826e4898..abff5cbb 100644 --- a/bacnet-stack/include/bacenum.h +++ b/bacnet-stack/include/bacenum.h @@ -409,12 +409,12 @@ typedef enum { PROP_POWER = 384, PROP_TRANSITION = 385, PROP_EGRESS_ACTIVE = 386 - /* The special property identifiers all, optional, and required */ - /* are reserved for use in the ReadPropertyConditional and */ - /* ReadPropertyMultiple services or services not defined in this standard. */ - /* Enumerated values 0-511 are reserved for definition by ASHRAE. */ - /* Enumerated values 512-4194303 may be used by others subject to the */ - /* procedures and constraints described in Clause 23. */ + /* The special property identifiers all, optional, and required */ + /* are reserved for use in the ReadPropertyConditional and */ + /* ReadPropertyMultiple services or services not defined in this standard. */ + /* Enumerated values 0-511 are reserved for definition by ASHRAE. */ + /* Enumerated values 512-4194303 may be used by others subject to the */ + /* procedures and constraints described in Clause 23. */ } BACNET_PROPERTY_ID; /* do the MAX as define rather than enumeration for devices diff --git a/bacnet-stack/include/bvlc.h b/bacnet-stack/include/bvlc.h index b68025aa..1cbe076f 100644 --- a/bacnet-stack/include/bvlc.h +++ b/bacnet-stack/include/bvlc.h @@ -31,7 +31,7 @@ #include "bacdef.h" #include "npdu.h" -struct sockaddr_in; /* Defined elsewhere, needed here. */ +struct sockaddr_in; /* Defined elsewhere, needed here. */ #ifdef __cplusplus extern "C" { diff --git a/bacnet-stack/include/client.h b/bacnet-stack/include/client.h index baee6ff4..0a1a1cac 100644 --- a/bacnet-stack/include/client.h +++ b/bacnet-stack/include/client.h @@ -115,7 +115,7 @@ extern "C" { /* returns the invoke ID for confirmed request, or 0 if failed */ uint8_t Send_Read_Property_Request_Address( - BACNET_ADDRESS *dest, + BACNET_ADDRESS * dest, uint16_t max_apdu, BACNET_OBJECT_TYPE object_type, uint32_t object_instance, diff --git a/bacnet-stack/include/datalink.h b/bacnet-stack/include/datalink.h index 354ee938..63273a2a 100644 --- a/bacnet-stack/include/datalink.h +++ b/bacnet-stack/include/datalink.h @@ -135,7 +135,7 @@ extern "C" { * chosen at runtime from among these choices. * - Clause 10 POINT-TO-POINT (PTP) and Clause 11 EIA/CEA-709.1 ("LonTalk") LAN * are not currently supported by this project. - *//** @defgroup DLTemplates DataLink Template Functions + *//** @defgroup DLTemplates DataLink Template Functions * @ingroup DataLink * Most of the functions in this group are function templates which are assigned * to a specific DataLink network layer implementation either at compile time or diff --git a/bacnet-stack/include/datetime.h b/bacnet-stack/include/datetime.h index 4e5482d5..a89ac763 100644 --- a/bacnet-stack/include/datetime.h +++ b/bacnet-stack/include/datetime.h @@ -89,8 +89,8 @@ extern "C" { uint8_t hundredths); /* utility test for validity */ bool datetime_is_valid( - BACNET_DATE *bdate, - BACNET_TIME *btime); + BACNET_DATE * bdate, + BACNET_TIME * btime); /* utility comparison functions: if the date/times are the same, return is 0 diff --git a/bacnet-stack/include/dcc.h b/bacnet-stack/include/dcc.h index 0438572b..86c28948 100644 --- a/bacnet-stack/include/dcc.h +++ b/bacnet-stack/include/dcc.h @@ -94,9 +94,7 @@ extern "C" { * * The network management BIBBs prescribe the BACnet capabilities required to * interoperably perform network management functions. - */ - -/** @defgroup DMDCC Device Management-Device Communication Control (DM-DCC) + *//** @defgroup DMDCC Device Management-Device Communication Control (DM-DCC) * @ingroup RDMS * 16.1 DeviceCommunicationControl Service
* The DeviceCommunicationControl service is used by a client BACnet-user to @@ -109,9 +107,7 @@ extern "C" { * "indefinite," meaning communication must be re-enabled by a * DeviceCommunicationControl or, if supported, ReinitializeDevice service, * not by time. - */ - -/** @defgroup NMRC Network Management-Router Configuration (NM-RC) + *//** @defgroup NMRC Network Management-Router Configuration (NM-RC) * @ingroup RDMS * The A device may query and change the configuration of routers and * half-routers. diff --git a/bacnet-stack/include/event.h b/bacnet-stack/include/event.h index 537e18ac..259d29a2 100644 --- a/bacnet-stack/include/event.h +++ b/bacnet-stack/include/event.h @@ -202,9 +202,7 @@ extern "C" { * These BIBBs prescribe the BACnet capabilities required to interoperably * perform the alarm and event management functions enumerated in 22.2.1.2 * for the BACnet devices defined therein. - */ - -/** @defgroup EVNOTFCN Alarm and Event-Notification (AE-N) + *//** @defgroup EVNOTFCN Alarm and Event-Notification (AE-N) * @ingroup ALMEVNT * 13.6 ConfirmedCOVNotification Service
* The ConfirmedCOVNotification service is used to notify subscribers about @@ -221,9 +219,7 @@ extern "C" { * For unsubscribed notifications, the algorithm for determining when to issue * this service is a local matter and may be based on a change of value, * periodic updating, or some other criteria. - */ - -/** @defgroup ALMACK Alarm and Event-ACK (AE-ACK) + *//** @defgroup ALMACK Alarm and Event-ACK (AE-ACK) * @ingroup ALMEVNT * 13.5 AcknowledgeAlarm Service
* In some systems a device may need to know that an operator has seen the alarm diff --git a/bacnet-stack/include/fifo.h b/bacnet-stack/include/fifo.h index 0df5f7ac..447abcc1 100755 --- a/bacnet-stack/include/fifo.h +++ b/bacnet-stack/include/fifo.h @@ -31,40 +31,52 @@ typedef struct fifo_buffer_t FIFO_BUFFER; extern "C" { #endif /* __cplusplus */ - unsigned FIFO_Count(FIFO_BUFFER const *b); + unsigned FIFO_Count( + FIFO_BUFFER const *b); - bool FIFO_Full(FIFO_BUFFER const *b); + bool FIFO_Full( + FIFO_BUFFER const *b); - bool FIFO_Available(FIFO_BUFFER const *b, + bool FIFO_Available( + FIFO_BUFFER const *b, unsigned count); - bool FIFO_Empty(FIFO_BUFFER const *b); + bool FIFO_Empty( + FIFO_BUFFER const *b); - uint8_t FIFO_Peek(FIFO_BUFFER const *b); + uint8_t FIFO_Peek( + FIFO_BUFFER const *b); - uint8_t FIFO_Get(FIFO_BUFFER * b); + uint8_t FIFO_Get( + FIFO_BUFFER * b); - unsigned FIFO_Pull(FIFO_BUFFER * b, + unsigned FIFO_Pull( + FIFO_BUFFER * b, uint8_t * data_bytes, unsigned length); - bool FIFO_Put(FIFO_BUFFER * b, + bool FIFO_Put( + FIFO_BUFFER * b, uint8_t data_byte); - bool FIFO_Add(FIFO_BUFFER * b, + bool FIFO_Add( + FIFO_BUFFER * b, uint8_t * data_bytes, unsigned count); - void FIFO_Flush(FIFO_BUFFER * b); + void FIFO_Flush( + FIFO_BUFFER * b); /* note: buffer_len must be a power of two */ - void FIFO_Init(FIFO_BUFFER * b, + void FIFO_Init( + FIFO_BUFFER * b, volatile uint8_t * buffer, unsigned buffer_len); #ifdef TEST #include "ctest.h" - void testFIFOBuffer(Test * pTest); + void testFIFOBuffer( + Test * pTest); #endif #ifdef __cplusplus diff --git a/bacnet-stack/include/handlers.h b/bacnet-stack/include/handlers.h index 229c8c2c..7b5c1541 100644 --- a/bacnet-stack/include/handlers.h +++ b/bacnet-stack/include/handlers.h @@ -189,14 +189,17 @@ extern "C" { int handler_timesync_encode_recipients( uint8_t * apdu, int max_apdu); - void handler_timesync_task(void); - void handler_timesync_init(void); + void handler_timesync_task( + void); + void handler_timesync_init( + void); bool handler_timesync_recipient_write( BACNET_WRITE_PROPERTY_DATA * wp_data); - bool handler_timesync_interval_set(uint32_t minutes); + bool handler_timesync_interval_set( + uint32_t minutes); bool handler_timesync_recipient_address_set( unsigned index, - BACNET_ADDRESS *address); + BACNET_ADDRESS * address); void handler_read_property_multiple( uint8_t * service_request, @@ -313,10 +316,10 @@ extern "C" { BACNET_CONFIRMED_SERVICE_DATA * service_data); void get_alarm_summary_ack_handler( - uint8_t *service_request, + uint8_t * service_request, uint16_t service_len, - BACNET_ADDRESS *src, - BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data); + BACNET_ADDRESS * src, + BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data); #ifdef __cplusplus diff --git a/bacnet-stack/include/mstp.h b/bacnet-stack/include/mstp.h index f5520816..bec22f97 100644 --- a/bacnet-stack/include/mstp.h +++ b/bacnet-stack/include/mstp.h @@ -111,10 +111,10 @@ struct mstp_port_struct_t { so that you can be atomic on 8 bit microcontrollers */ uint32_t( *SilenceTimer) ( - void * pArg); + void *pArg); void ( *SilenceTimerReset) ( - void * pArg); + void *pArg); /* A timer used to measure and generate Reply Postponed frames. It is */ /* incremented by a timer process and is cleared by the Master Node State */ @@ -164,8 +164,8 @@ struct mstp_port_struct_t { uint8_t *OutputBuffer; uint16_t OutputBufferSize; - /*Platform-specific port data*/ - void * UserData; + /*Platform-specific port data */ + void *UserData; }; diff --git a/bacnet-stack/include/readrange.h b/bacnet-stack/include/readrange.h index b051e33e..539d4b76 100644 --- a/bacnet-stack/include/readrange.h +++ b/bacnet-stack/include/readrange.h @@ -162,9 +162,7 @@ extern "C" { * These BIBBs prescribe the BACnet capabilities required to interoperably * perform the trending functions enumerated in clause 22.2.1.4 for the * BACnet devices defined therein. -*/ - -/** @defgroup TrendReadRange Trending -Read Range Service (eg, in T-VMT) +*//** @defgroup TrendReadRange Trending -Read Range Service (eg, in T-VMT) * @ingroup Trend * 15.8 ReadRange Service
* The ReadRange service is used by a client BACnet-user to read a specific diff --git a/bacnet-stack/include/ringbuf.h b/bacnet-stack/include/ringbuf.h index 6091a28b..6125fd07 100644 --- a/bacnet-stack/include/ringbuf.h +++ b/bacnet-stack/include/ringbuf.h @@ -53,13 +53,13 @@ extern "C" { RING_BUFFER const *b); bool Ringbuf_Pop( RING_BUFFER * b, - uint8_t *data_element); + uint8_t * data_element); bool Ringbuf_Put( RING_BUFFER * b, /* ring buffer structure */ - uint8_t *data_element); /* one element to add to the ring */ + uint8_t * data_element); /* one element to add to the ring */ bool Ringbuf_Put_Front( - RING_BUFFER * b, /* ring buffer structure */ - uint8_t *data_element); + RING_BUFFER * b, /* ring buffer structure */ + uint8_t * data_element); volatile uint8_t *Ringbuf_Alloc( RING_BUFFER * b); /* Note: element_count must be a power of two */ @@ -71,10 +71,10 @@ extern "C" { #ifdef TEST #include "ctest.h" -void testRingBufSize16( - Test * pTest); -void testRingBufSize32( - Test * pTest); + void testRingBufSize16( + Test * pTest); + void testRingBufSize32( + Test * pTest); #endif #ifdef __cplusplus diff --git a/bacnet-stack/include/rp.h b/bacnet-stack/include/rp.h index 025145f6..5108d088 100644 --- a/bacnet-stack/include/rp.h +++ b/bacnet-stack/include/rp.h @@ -125,9 +125,7 @@ extern "C" { * These BIBBs prescribe the BACnet capabilities required to interoperably * perform the data sharing functions enumerated in 22.2.1.1 for the BACnet * devices defined therein. -*/ - -/** @defgroup DSRP Data Sharing -Read Property Service (DS-RP) +*//** @defgroup DSRP Data Sharing -Read Property Service (DS-RP) * @ingroup DataShare * 15.5 ReadProperty Service
* The ReadProperty service is used by a client BACnet-user to request the diff --git a/bacnet-stack/include/timesync.h b/bacnet-stack/include/timesync.h index e6684ae5..b3df1d43 100644 --- a/bacnet-stack/include/timesync.h +++ b/bacnet-stack/include/timesync.h @@ -31,11 +31,11 @@ struct BACnet_Recipient_List; typedef struct BACnet_Recipient_List { /* - BACnetRecipient ::= CHOICE { - device [0] BACnetObjectIdentifier, - address [1] BACnetAddress - } - */ + BACnetRecipient ::= CHOICE { + device [0] BACnetObjectIdentifier, + address [1] BACnetAddress + } + */ uint8_t tag; union { BACNET_OBJECT_ID device; @@ -83,11 +83,11 @@ extern "C" { int timesync_encode_timesync_recipients( uint8_t * apdu, unsigned max_apdu, - BACNET_RECIPIENT_LIST *recipient); + BACNET_RECIPIENT_LIST * recipient); int timesync_decode_timesync_recipients( uint8_t * apdu, unsigned apdu_len, - BACNET_RECIPIENT_LIST *recipient); + BACNET_RECIPIENT_LIST * recipient); #ifdef TEST #include "ctest.h" diff --git a/bacnet-stack/ports/at91sam7s/av.c b/bacnet-stack/ports/at91sam7s/av.c index af371d93..a0c647ca 100644 --- a/bacnet-stack/ports/at91sam7s/av.c +++ b/bacnet-stack/ports/at91sam7s/av.c @@ -367,8 +367,8 @@ bool Analog_Value_Write_Property( (value.type.Real >= 0.0) && (value.type.Real <= 100.0)) { level = (uint8_t) value.type.Real; object_index = - Analog_Value_Instance_To_Index(wp_data-> - object_instance); + Analog_Value_Instance_To_Index + (wp_data->object_instance); priority--; Present_Value[object_index] = level; /* Note: you could set the physical output here if we diff --git a/bacnet-stack/ports/at91sam7s/bv.c b/bacnet-stack/ports/at91sam7s/bv.c index 4e904821..ddeacaa7 100644 --- a/bacnet-stack/ports/at91sam7s/bv.c +++ b/bacnet-stack/ports/at91sam7s/bv.c @@ -278,8 +278,8 @@ bool Binary_Value_Write_Property( (value.type.Enumerated <= MAX_BINARY_PV)) { level = value.type.Enumerated; object_index = - Binary_Value_Instance_To_Index(wp_data-> - object_instance); + Binary_Value_Instance_To_Index + (wp_data->object_instance); priority--; /* NOTE: this Binary value has no priority array */ Present_Value[object_index] = level; diff --git a/bacnet-stack/ports/at91sam7s/device.c b/bacnet-stack/ports/at91sam7s/device.c index d879e026..f01eaea7 100644 --- a/bacnet-stack/ports/at91sam7s/device.c +++ b/bacnet-stack/ports/at91sam7s/device.c @@ -855,8 +855,8 @@ bool Device_Write_Property_Local( case PROP_OBJECT_IDENTIFIER: if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if ((value.type.Object_Id.type == OBJECT_DEVICE) && - (Device_Set_Object_Instance_Number(value.type.Object_Id. - instance))) { + (Device_Set_Object_Instance_Number(value.type. + Object_Id.instance))) { /* we could send an I-Am broadcast to let the world know */ status = true; } else { @@ -908,13 +908,13 @@ bool Device_Write_Property_Local( characterstring_encoding(&value.type.Character_String); if (encoding < MAX_CHARACTER_STRING_ENCODING) { /* All the object names in a device must be unique. */ - if (Device_Valid_Object_Name(&value. - type.Character_String, NULL, NULL)) { + if (Device_Valid_Object_Name(&value.type. + Character_String, NULL, NULL)) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; } else { - Device_Set_Object_Name(&value. - type.Character_String); + Device_Set_Object_Name(&value.type. + Character_String); status = true; } } else { diff --git a/bacnet-stack/ports/at91sam7s/timer.c b/bacnet-stack/ports/at91sam7s/timer.c index 6c7cee2b..8ef64672 100644 --- a/bacnet-stack/ports/at91sam7s/timer.c +++ b/bacnet-stack/ports/at91sam7s/timer.c @@ -303,7 +303,7 @@ static void Timer0IrqHandler( { volatile AT91PS_TC pTC = AT91C_BASE_TC0; /* pointer to timer channel 0 register structure */ - volatile unsigned int dummy; /* temporary */ + volatile unsigned int dummy; /* temporary */ /* read TC0 Status Register to clear interrupt */ dummy = pTC->TC_SR; diff --git a/bacnet-stack/ports/atmega168/bv.c b/bacnet-stack/ports/atmega168/bv.c index a19ca3fd..e7493b39 100644 --- a/bacnet-stack/ports/atmega168/bv.c +++ b/bacnet-stack/ports/atmega168/bv.c @@ -218,8 +218,8 @@ bool Binary_Value_Write_Property( if ((value.type.Enumerated == BINARY_ACTIVE) || (value.type.Enumerated == BINARY_INACTIVE)) { object_index = - Binary_Value_Instance_To_Index(wp_data-> - object_instance); + Binary_Value_Instance_To_Index + (wp_data->object_instance); /* NOTE: this Binary value has no priority array */ Present_Value[object_index] = (BACNET_BINARY_PV) value.type.Enumerated; diff --git a/bacnet-stack/ports/atmega168/device.c b/bacnet-stack/ports/atmega168/device.c index 0494ecfb..b303c56f 100644 --- a/bacnet-stack/ports/atmega168/device.c +++ b/bacnet-stack/ports/atmega168/device.c @@ -386,8 +386,8 @@ bool Device_Write_Property( case PROP_OBJECT_IDENTIFIER: if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if ((value.type.Object_Id.type == OBJECT_DEVICE) && - (Device_Set_Object_Instance_Number(value.type.Object_Id. - instance))) { + (Device_Set_Object_Instance_Number(value.type. + Object_Id.instance))) { /* we could send an I-Am broadcast to let the world know */ status = true; } else { diff --git a/bacnet-stack/ports/atmega8/bv.c b/bacnet-stack/ports/atmega8/bv.c index f9f98587..48510722 100644 --- a/bacnet-stack/ports/atmega8/bv.c +++ b/bacnet-stack/ports/atmega8/bv.c @@ -211,8 +211,8 @@ bool Binary_Value_Write_Property( if ((value.type.Enumerated == BINARY_ACTIVE) || (value.type.Enumerated == BINARY_INACTIVE)) { object_index = - Binary_Value_Instance_To_Index(wp_data-> - object_instance); + Binary_Value_Instance_To_Index + (wp_data->object_instance); /* NOTE: this Binary value has no priority array */ Present_Value[object_index] = (BACNET_BINARY_PV) value.type.Enumerated; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/ai.c b/bacnet-stack/ports/bdk-atxx4-mstp/ai.c index 747df57f..65605517 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/ai.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/ai.c @@ -169,13 +169,11 @@ int Analog_Input_Read_Property( case PROP_OBJECT_NAME: Analog_Input_Object_Name(rpdata->object_instance, &char_string); apdu_len = - encode_application_character_string(&apdu[0], - &char_string); + encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: apdu_len = - encode_application_enumerated(&apdu[0], - rpdata->object_type); + encode_application_enumerated(&apdu[0], rpdata->object_type); break; case PROP_PRESENT_VALUE: apdu_len = diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/av.c b/bacnet-stack/ports/bdk-atxx4-mstp/av.c index b56bed17..f7ccd659 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/av.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/av.c @@ -221,13 +221,11 @@ int Analog_Value_Read_Property( case PROP_OBJECT_NAME: Analog_Value_Object_Name(rpdata->object_instance, &char_string); apdu_len = - encode_application_character_string(&apdu[0], - &char_string); + encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: apdu_len = - encode_application_enumerated(&apdu[0], - rpdata->object_type); + encode_application_enumerated(&apdu[0], rpdata->object_type); break; case PROP_PRESENT_VALUE: real_value = Analog_Value_Present_Value(rpdata->object_instance); diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.c b/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.c index a74b9df8..d103bf1e 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bacnet.c @@ -65,7 +65,8 @@ static bool seeprom_version_test( rv = seeprom_bytes_read(NV_SEEPROM_TYPE_0, (uint8_t *) & id, 2); if (rv > 0) { - rv = seeprom_bytes_read(NV_SEEPROM_VERSION_0, (uint8_t *) & version, 2); + rv = seeprom_bytes_read(NV_SEEPROM_VERSION_0, (uint8_t *) & version, + 2); } if ((rv > 0) && (id == SEEPROM_ID) && (version == SEEPROM_VERSION)) { diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bi.c b/bacnet-stack/ports/bdk-atxx4-mstp/bi.c index 81134f2d..23eb9779 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bi.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bi.c @@ -178,10 +178,10 @@ int Binary_Input_Read_Property( BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ - BACNET_BIT_STRING bit_string = {0}; + BACNET_BIT_STRING bit_string = { 0 }; BACNET_POLARITY polarity = POLARITY_NORMAL; BACNET_BINARY_PV value = BINARY_INACTIVE; - BACNET_CHARACTER_STRING char_string = {0}; + BACNET_CHARACTER_STRING char_string = { 0 }; uint8_t *apdu = NULL; if ((rpdata->application_data == NULL) || @@ -198,13 +198,11 @@ int Binary_Input_Read_Property( case PROP_OBJECT_NAME: Binary_Input_Object_Name(rpdata->object_instance, &char_string); apdu_len = - encode_application_character_string(&apdu[0], - &char_string); + encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: apdu_len = - encode_application_enumerated(&apdu[0], - rpdata->object_type); + encode_application_enumerated(&apdu[0], rpdata->object_type); break; case PROP_PRESENT_VALUE: value = Binary_Input_Present_Value(rpdata->object_instance); diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c index ab7863ad..52d1878b 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c @@ -250,8 +250,8 @@ int Binary_Output_Read_Property( { int len = 0; int apdu_len = 0; /* return value */ - BACNET_BIT_STRING bit_string = {0}; - BACNET_CHARACTER_STRING char_string = {0}; + BACNET_BIT_STRING bit_string = { 0 }; + BACNET_CHARACTER_STRING char_string = { 0 }; BACNET_BINARY_PV present_value = BINARY_INACTIVE; unsigned object_index = 0; unsigned i = 0; @@ -272,13 +272,11 @@ int Binary_Output_Read_Property( case PROP_OBJECT_NAME: Binary_Output_Object_Name(rpdata->object_instance, &char_string); apdu_len = - encode_application_character_string(&apdu[0], - &char_string); + encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: apdu_len = - encode_application_enumerated(&apdu[0], - rpdata->object_type); + encode_application_enumerated(&apdu[0], rpdata->object_type); break; case PROP_PRESENT_VALUE: present_value = @@ -461,8 +459,8 @@ bool Binary_Output_Write_Property( priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; - Binary_Output_Present_Value_Set(wp_data-> - object_instance, level, priority); + Binary_Output_Present_Value_Set + (wp_data->object_instance, level, priority); } else if (priority == 6) { status = false; /* Command priority 6 is reserved for use by Minimum On/Off diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/defines.h b/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/defines.h index c6306353..c37b5ede 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/defines.h +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/defines.h @@ -11,11 +11,11 @@ #if (__GNUC__ <= 4) && (__GNUC_MINOR__ < 3) #if !defined(EEWE) && defined(EEPE) -# define EEWE EEPE +#define EEWE EEPE #endif #if !defined(EEMWE) && defined(EEMPE) -# define EEMWE EEMPE +#define EEMWE EEMPE #endif #endif diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/flash.h b/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/flash.h index f3433b2c..4aa13f0c 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/flash.h +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/flash.h @@ -20,55 +20,55 @@ #if defined(__ICCAVR__) /* IAR Embedded Workbench */ -# include +#include -# define _GET_LOCK_BITS() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0001, 0x09 ) -# define _GET_LOW_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0000, 0x09 ) -# define _GET_HIGH_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0003, 0x09 ) -# define _GET_EXTENDED_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0002, 0x09 ) -# define _SET_LOCK_BITS(data) __DataToR0ByteToSPMCR_SPM( data, 0x09 ) -# define _ENABLE_RWW_SECTION() __DataToR0ByteToSPMCR_SPM( 0x00, 0x11 ) +#define _GET_LOCK_BITS() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0001, 0x09 ) +#define _GET_LOW_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0000, 0x09 ) +#define _GET_HIGH_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0003, 0x09 ) +#define _GET_EXTENDED_FUSES() __AddrToZByteToSPMCR_LPM( (void __flash *) 0x0002, 0x09 ) +#define _SET_LOCK_BITS(data) __DataToR0ByteToSPMCR_SPM( data, 0x09 ) +#define _ENABLE_RWW_SECTION() __DataToR0ByteToSPMCR_SPM( 0x00, 0x11 ) -# define _WAIT_FOR_SPM() while( SPMCR_REG & (1< 0 /* AVR-GCC/avr-libc */ -# include -# include +#include +#include -# if defined(GET_LOCK_BITS) /* avr-libc >= 1.2.5 */ -# define _GET_LOCK_BITS() boot_lock_fuse_bits_get(GET_LOCK_BITS) -# define _GET_LOW_FUSES() boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS) -# define _GET_HIGH_FUSES() boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS) -# define _GET_EXTENDED_FUSES() boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS) -# endif /* defined(GET_LOCK_BITS) */ -# define _SET_LOCK_BITS(data) boot_lock_bits_set(~data) -# define _ENABLE_RWW_SECTION() boot_rww_enable() +#if defined(GET_LOCK_BITS) /* avr-libc >= 1.2.5 */ +#define _GET_LOCK_BITS() boot_lock_fuse_bits_get(GET_LOCK_BITS) +#define _GET_LOW_FUSES() boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS) +#define _GET_HIGH_FUSES() boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS) +#define _GET_EXTENDED_FUSES() boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS) +#endif /* defined(GET_LOCK_BITS) */ +#define _SET_LOCK_BITS(data) boot_lock_bits_set(~data) +#define _ENABLE_RWW_SECTION() boot_rww_enable() -# define _WAIT_FOR_SPM() boot_spm_busy_wait() +#define _WAIT_FOR_SPM() boot_spm_busy_wait() -# ifndef LARGE_MEMORY -# define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_near(addr) -# else /* LARGE_MEMORY */ -# define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_far(addr) -# endif /* LARGE_MEMORY */ -# define _FILL_TEMP_WORD(addr,data) boot_page_fill(addr, data) -# define _PAGE_ERASE(addr) boot_page_erase(addr) -# define _PAGE_WRITE(addr) boot_page_write(addr) +#ifndef LARGE_MEMORY +#define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_near(addr) +#else /* LARGE_MEMORY */ +#define _LOAD_PROGRAM_MEMORY(addr) pgm_read_byte_far(addr) +#endif /* LARGE_MEMORY */ +#define _FILL_TEMP_WORD(addr,data) boot_page_fill(addr, data) +#define _PAGE_ERASE(addr) boot_page_erase(addr) +#define _PAGE_WRITE(addr) boot_page_write(addr) #else -# error "Don't know your compiler." +#error "Don't know your compiler." #endif diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/main.c b/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/main.c index 6d525f99..ec24ff15 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/main.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bootloader/main.c @@ -46,9 +46,9 @@ * smaller devices. */ #ifdef LARGE_MEMORY -# define ADDR_T unsigned long +#define ADDR_T unsigned long #else /* !LARGE_MEMORY */ -# define ADDR_T unsigned int +#define ADDR_T unsigned int #endif /* LARGE_MEMORY */ #ifndef REMOVE_BLOCK_SUPPORT diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/device.c b/bacnet-stack/ports/bdk-atxx4-mstp/device.c index db2745b9..dd72a421 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/device.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/device.c @@ -561,8 +561,8 @@ int Device_Read_Property_Local( { int apdu_len = 0; /* return value */ int len = 0; /* apdu len intermediate value */ - BACNET_BIT_STRING bit_string = {0}; - BACNET_CHARACTER_STRING char_string = {0}; + BACNET_BIT_STRING bit_string = { 0 }; + BACNET_CHARACTER_STRING char_string = { 0 }; unsigned i = 0; int object_type = 0; uint32_t instance = 0; @@ -575,7 +575,7 @@ int Device_Read_Property_Local( return 0; } apdu = rpdata->application_data; - switch ((int)rpdata->object_property) { + switch ((int) rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: apdu_len = encode_application_object_id(&apdu[0], rpdata->object_type, @@ -584,13 +584,11 @@ int Device_Read_Property_Local( case PROP_OBJECT_NAME: Device_Object_Name(rpdata->object_instance, &char_string); apdu_len = - encode_application_character_string(&apdu[0], - &char_string); + encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: apdu_len = - encode_application_enumerated(&apdu[0], - rpdata->object_type); + encode_application_enumerated(&apdu[0], rpdata->object_type); break; case PROP_DESCRIPTION: bacnet_name(NV_EEPROM_DEVICE_DESCRIPTION, &char_string, @@ -801,12 +799,12 @@ bool Device_Write_Property_Local( wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; return false; } - switch ((int)wp_data->object_property) { + switch ((int) wp_data->object_property) { case PROP_OBJECT_IDENTIFIER: if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if ((value.type.Object_Id.type == OBJECT_DEVICE) && - (Device_Set_Object_Instance_Number(value.type.Object_Id. - instance))) { + (Device_Set_Object_Instance_Number(value.type. + Object_Id.instance))) { eeprom_bytes_write(NV_EEPROM_DEVICE_0, (uint8_t *) & value.type.Object_Id.instance, 4); /* we could send an I-Am broadcast to let the world know */ @@ -855,10 +853,8 @@ bool Device_Write_Property_Local( if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { status = bacnet_name_write_unique(NV_EEPROM_DEVICE_NAME, - wp_data->object_type, - wp_data->object_instance, - &value.type.Character_String, - &wp_data->error_class, + wp_data->object_type, wp_data->object_instance, + &value.type.Character_String, &wp_data->error_class, &wp_data->error_code); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c b/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c index c00454fe..2387e304 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/dlmstp.c @@ -1129,8 +1129,8 @@ static bool MSTP_Master_Node_FSM( if (pkt != NULL) { matched = dlmstp_compare_data_expecting_reply(&InputBuffer[0], - DataLength, SourceAddress, &pkt->buffer[0], pkt->length, - pkt->destination_mac); + DataLength, SourceAddress, &pkt->buffer[0], + pkt->length, pkt->destination_mac); } else { matched = false; } @@ -1146,10 +1146,12 @@ static bool MSTP_Master_Node_FSM( if (pkt->data_expecting_reply) { frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY; } else { - frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY; + frame_type = + FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY; } - MSTP_Send_Frame(frame_type, pkt->destination_mac, This_Station, - (uint8_t *) & pkt->buffer[0], pkt->length); + MSTP_Send_Frame(frame_type, pkt->destination_mac, + This_Station, (uint8_t *) & pkt->buffer[0], + pkt->length); Master_State = MSTP_MASTER_STATE_IDLE; /* clear our flag we were holding for comparison */ MSTP_Flag.ReceivedValidFrame = false; @@ -1354,4 +1356,3 @@ void dlmstp_get_broadcast_address( return; } - diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h b/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h index caaa690f..f3d59140 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h +++ b/bacnet-stack/ports/bdk-atxx4-mstp/iar2gcc.h @@ -330,12 +330,12 @@ unsigned char __uint8_eeprom_load( #define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2)) #endif #if (defined(__GNUC__) && ((__GNUC__ == 4) && (__GNUC_MINOR__ < 5))) - #if defined(__AVR_ATmega644P__) +#if defined(__AVR_ATmega644P__) /* bug in WinAVR - fixed in later versions */ - #define power_usart1_enable() (PRR &= (uint8_t)~(1 << PRUSART1)) - #elif defined(__AVR_ATmega1284P__) - #define power_usart1_enable() (PRR0 &= (uint8_t)~(1 << PRUSART1)) - #endif +#define power_usart1_enable() (PRR &= (uint8_t)~(1 << PRUSART1)) +#elif defined(__AVR_ATmega1284P__) +#define power_usart1_enable() (PRR0 &= (uint8_t)~(1 << PRUSART1)) +#endif #endif #if defined(__CROSSWORKS_AVR) diff --git a/bacnet-stack/ports/bsd/bip-init.c b/bacnet-stack/ports/bsd/bip-init.c index f3dac00a..5241d9ee 100644 --- a/bacnet-stack/ports/bsd/bip-init.c +++ b/bacnet-stack/ports/bsd/bip-init.c @@ -43,14 +43,13 @@ bool BIP_Debug = true; -void * -get_addr_ptr (struct sockaddr * sockaddr_ptr) +void *get_addr_ptr( + struct sockaddr *sockaddr_ptr) { - void * addr_ptr; + void *addr_ptr; if (sockaddr_ptr->sa_family == AF_INET) { - addr_ptr = &((struct sockaddr_in *) sockaddr_ptr)->sin_addr; - } - else if (sockaddr_ptr->sa_family == AF_INET6) { + addr_ptr = &((struct sockaddr_in *) sockaddr_ptr)->sin_addr; + } else if (sockaddr_ptr->sa_family == AF_INET6) { addr_ptr = &((struct sockaddr_in6 *) sockaddr_ptr)->sin6_addr; } return addr_ptr; @@ -81,41 +80,41 @@ long bip_getaddrbyname( * @param request [in] addr broadaddr netmask */ static int get_local_address( - char *ifname,struct in_addr *addr,char *request) + char *ifname, + struct in_addr *addr, + char *request) { - char rv; /* return value */ + char rv; /* return value */ - struct ifaddrs * ifaddrs_ptr; + struct ifaddrs *ifaddrs_ptr; int status; - status = getifaddrs (& ifaddrs_ptr); + status = getifaddrs(&ifaddrs_ptr); if (status == -1) { - fprintf (stderr, "Error in 'getifaddrs': %d (%s)\n", - errno, strerror (errno)); + fprintf(stderr, "Error in 'getifaddrs': %d (%s)\n", errno, + strerror(errno)); } while (ifaddrs_ptr) { - if ((ifaddrs_ptr->ifa_addr->sa_family == AF_INET) && - (strcmp(ifaddrs_ptr->ifa_name, ifname) == 0)) { - void * addr_ptr; - if (! ifaddrs_ptr->ifa_addr) { - return rv; - } - if (strcmp(request, "addr") == 0) { - addr_ptr = get_addr_ptr (ifaddrs_ptr->ifa_addr); - } - else if (strcmp(request, "broadaddr") == 0) { - addr_ptr = get_addr_ptr (ifaddrs_ptr->ifa_broadaddr); - } - else if (strcmp(request, "netmask") == 0) { - addr_ptr = get_addr_ptr (ifaddrs_ptr->ifa_netmask); - } - if (addr_ptr) { - memcpy(addr, addr_ptr, sizeof(struct in_addr)); - } + if ((ifaddrs_ptr->ifa_addr->sa_family == AF_INET) && + (strcmp(ifaddrs_ptr->ifa_name, ifname) == 0)) { + void *addr_ptr; + if (!ifaddrs_ptr->ifa_addr) { + return rv; } - ifaddrs_ptr = ifaddrs_ptr->ifa_next; + if (strcmp(request, "addr") == 0) { + addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_addr); + } else if (strcmp(request, "broadaddr") == 0) { + addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_broadaddr); + } else if (strcmp(request, "netmask") == 0) { + addr_ptr = get_addr_ptr(ifaddrs_ptr->ifa_netmask); + } + if (addr_ptr) { + memcpy(addr, addr_ptr, sizeof(struct in_addr)); + } + } + ifaddrs_ptr = ifaddrs_ptr->ifa_next; } - freeifaddrs (ifaddrs_ptr); + freeifaddrs(ifaddrs_ptr); return rv; } @@ -185,7 +184,7 @@ bool bip_init( if (ifname) { bip_set_interface(ifname); - printf("interface %s", ifname); + printf("interface %s", ifname); } else { bip_set_interface("en0"); } @@ -258,9 +257,9 @@ int bip_get_local_netmask( char *ifname = getenv("BACNET_IFACE"); /* will probably be null */ if (ifname == NULL) ifname = "en0"; - printf("ifname %s",ifname); + printf("ifname %s", ifname); char *request = "netmask"; rv = get_local_address(ifname, netmask, request); - + return rv; } diff --git a/bacnet-stack/ports/bsd/net.h b/bacnet-stack/ports/bsd/net.h index 3c73d7f3..03b0b7d3 100644 --- a/bacnet-stack/ports/bsd/net.h +++ b/bacnet-stack/ports/bsd/net.h @@ -46,28 +46,28 @@ #include /* for Unix domain sockets */ #ifdef HAVE_SYS_SELECT_H -# include /* for convenience */ +#include /* for convenience */ #endif #ifdef HAVE_POLL_H -# include /* for convenience */ +#include /* for convenience */ #endif #ifdef HAVE_STRINGS_H -# include /* for convenience */ +#include /* for convenience */ #endif /* Three headers are normally needed for socket/file ioctl's: * , , and . */ #ifdef HAVE_SYS_IOCTL_H -# include +#include #endif #ifdef HAVE_SYS_FILIO_H -# include +#include #endif #ifdef HAVE_SYS_SOCKIO_H -# include +#include #endif #include diff --git a/bacnet-stack/ports/linux/dlmstp.c b/bacnet-stack/ports/linux/dlmstp.c index beb9ec24..073ef6ed 100644 --- a/bacnet-stack/ports/linux/dlmstp.c +++ b/bacnet-stack/ports/linux/dlmstp.c @@ -100,7 +100,7 @@ static uint8_t Tusage_timeout = 60; static struct timeval start; static uint32_t Timer_Silence( - void * pArg) + void *pArg) { struct timeval now, tmp_diff; int32_t res; @@ -113,7 +113,7 @@ static uint32_t Timer_Silence( } static void Timer_Silence_Reset( - void * pArg) + void *pArg) { gettimeofday(&start, NULL); } diff --git a/bacnet-stack/ports/linux/dlmstp_linux.c b/bacnet-stack/ports/linux/dlmstp_linux.c index f62eb758..b36bb790 100644 --- a/bacnet-stack/ports/linux/dlmstp_linux.c +++ b/bacnet-stack/ports/linux/dlmstp_linux.c @@ -49,46 +49,44 @@ #define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;} uint32_t Timer_Silence( - void * poPort) + void *poPort) { - struct timeval now, tmp_diff; - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return -1; - } - poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return -1; - } + struct timeval now, tmp_diff; + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return -1; + } + poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + return -1; + } - int32_t res; + int32_t res; - gettimeofday(&now, NULL); - timersub(&poSharedData->start, &now, &tmp_diff); - res = ((tmp_diff.tv_sec) * 1000 + (tmp_diff.tv_usec) / 1000); + gettimeofday(&now, NULL); + timersub(&poSharedData->start, &now, &tmp_diff); + res = ((tmp_diff.tv_sec) * 1000 + (tmp_diff.tv_usec) / 1000); - return (res >= 0 ? res : -res); + return (res >= 0 ? res : -res); } void Timer_Silence_Reset( - void * poPort) + void *poPort) { - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return; - } - poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return; - } + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return; + } + poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + return; + } - gettimeofday(&poSharedData->start, NULL); + gettimeofday(&poSharedData->start, NULL); } void get_abstime( @@ -106,22 +104,22 @@ void get_abstime( } void dlmstp_cleanup( - void * poPort) + void *poPort) { - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return; - } - poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return; - } + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return; + } + poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + return; + } /* restore the old port settings */ - tcsetattr(poSharedData->RS485_Handle, TCSANOW, &poSharedData->RS485_oldtio); + tcsetattr(poSharedData->RS485_Handle, TCSANOW, + &poSharedData->RS485_oldtio); close(poSharedData->RS485_Handle); pthread_cond_destroy(&poSharedData->Received_Frame_Flag); @@ -134,7 +132,7 @@ void dlmstp_cleanup( /* returns number of bytes sent on success, zero on failure */ int dlmstp_send_pdu( - void * poPort, + void *poPort, BACNET_ADDRESS * dest, /* destination address */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len) @@ -142,34 +140,34 @@ int dlmstp_send_pdu( int bytes_sent = 0; struct mstp_pdu_packet *pkt; unsigned i = 0; - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return 0; - } - poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return 0; - } + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return 0; + } + poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + return 0; + } - pkt = (struct mstp_pdu_packet *) Ringbuf_Alloc(&poSharedData->PDU_Queue); - if (pkt) { - pkt->data_expecting_reply = BACNET_DATA_EXPECTING_REPLY(pdu[BACNET_PDU_CONTROL_BYTE_OFFSET]); - for (i = 0; i < pdu_len; i++) { - pkt->buffer[i] = pdu[i]; - } - pkt->length = pdu_len; - pkt->destination_mac = dest->mac[0]; - bytes_sent = pdu_len; - } + pkt = (struct mstp_pdu_packet *) Ringbuf_Alloc(&poSharedData->PDU_Queue); + if (pkt) { + pkt->data_expecting_reply = + BACNET_DATA_EXPECTING_REPLY(pdu[BACNET_PDU_CONTROL_BYTE_OFFSET]); + for (i = 0; i < pdu_len; i++) { + pkt->buffer[i] = pdu[i]; + } + pkt->length = pdu_len; + pkt->destination_mac = dest->mac[0]; + bytes_sent = pdu_len; + } - return bytes_sent; + return bytes_sent; } uint16_t dlmstp_receive( - void * poPort, + void *poPort, BACNET_ADDRESS * src, /* source address */ uint8_t * pdu, /* PDU data */ uint16_t max_pdu, /* amount of space available in the PDU */ @@ -178,60 +176,58 @@ uint16_t dlmstp_receive( uint16_t pdu_len = 0; struct timespec abstime; int rv = 0; - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return 0; - } - poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return 0; - } + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return 0; + } + poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + return 0; + } (void) max_pdu; /* see if there is a packet available, and a place to put the reply (if necessary) and process it */ get_abstime(&abstime, timeout); - rv = pthread_cond_timedwait(&poSharedData->Receive_Packet_Flag, &poSharedData->Receive_Packet_Mutex, - &abstime); - if (rv == 0) { - if (poSharedData->Receive_Packet.ready) { - if (poSharedData->Receive_Packet.pdu_len) { - poSharedData->MSTP_Packets++; - if (src) { - memmove(src, &poSharedData->Receive_Packet.address, - sizeof(poSharedData->Receive_Packet.address)); - } - if (pdu) { - memmove(pdu, &poSharedData->Receive_Packet.pdu, - sizeof(poSharedData->Receive_Packet.pdu)); - } - pdu_len = poSharedData->Receive_Packet.pdu_len; + rv = pthread_cond_timedwait(&poSharedData->Receive_Packet_Flag, + &poSharedData->Receive_Packet_Mutex, &abstime); + if (rv == 0) { + if (poSharedData->Receive_Packet.ready) { + if (poSharedData->Receive_Packet.pdu_len) { + poSharedData->MSTP_Packets++; + if (src) { + memmove(src, &poSharedData->Receive_Packet.address, + sizeof(poSharedData->Receive_Packet.address)); } - poSharedData->Receive_Packet.ready = false; + if (pdu) { + memmove(pdu, &poSharedData->Receive_Packet.pdu, + sizeof(poSharedData->Receive_Packet.pdu)); + } + pdu_len = poSharedData->Receive_Packet.pdu_len; } + poSharedData->Receive_Packet.ready = false; } + } - return pdu_len; + return pdu_len; } void *dlmstp_receive_fsm_task( void *pArg) { bool received_frame; - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t*)pArg; - if(!mstp_port) - { - return NULL; + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = (struct mstp_port_struct_t *) pArg; + if (!mstp_port) { + return NULL; } - poSharedData = (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t*)pArg)->UserData; - if(!poSharedData) - { - return NULL; - } + poSharedData = + (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t *) pArg)->UserData; + if (!poSharedData) { + return NULL; + } for (;;) { /* only do receive state machine while we don't have a frame */ @@ -239,9 +235,10 @@ void *dlmstp_receive_fsm_task( (mstp_port->ReceivedInvalidFrame == false)) { do { RS485_Check_UART_Data(mstp_port); - MSTP_Receive_Frame_FSM((volatile struct mstp_port_struct_t*)pArg); + MSTP_Receive_Frame_FSM((volatile struct mstp_port_struct_t *) + pArg); received_frame = mstp_port->ReceivedValidFrame || - mstp_port->ReceivedInvalidFrame; + mstp_port->ReceivedInvalidFrame; if (received_frame) { pthread_cond_signal(&poSharedData->Received_Frame_Flag); break; @@ -256,61 +253,60 @@ void *dlmstp_receive_fsm_task( void *dlmstp_master_fsm_task( void *pArg) { - uint32_t silence = 0; - bool run_master = false; - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t*)pArg; - if(!mstp_port) - { - return NULL; + uint32_t silence = 0; + bool run_master = false; + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = (struct mstp_port_struct_t *) pArg; + if (!mstp_port) { + return NULL; } - poSharedData = (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t*)pArg)->UserData; - if(!poSharedData) - { - return NULL; - } + poSharedData = + (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t *) pArg)->UserData; + if (!poSharedData) { + return NULL; + } - for (;;) { - if (mstp_port->ReceivedValidFrame == false && - mstp_port->ReceivedInvalidFrame == false) { - RS485_Check_UART_Data(mstp_port); - MSTP_Receive_Frame_FSM(mstp_port); - } - if (mstp_port->ReceivedValidFrame || mstp_port->ReceivedInvalidFrame) { - run_master = true; - } else { - silence = mstp_port->SilenceTimer(NULL); - switch (mstp_port->master_state) { - case MSTP_MASTER_STATE_IDLE: - if (silence >= Tno_token) - run_master = true; - break; - case MSTP_MASTER_STATE_WAIT_FOR_REPLY: - if (silence >= poSharedData->Treply_timeout) - run_master = true; - break; - case MSTP_MASTER_STATE_POLL_FOR_MASTER: - if (silence >= poSharedData->Tusage_timeout) - run_master = true; - break; - default: - run_master = true; - break; - } - } - if (run_master) { - if (mstp_port->This_Station <= DEFAULT_MAX_MASTER) { - while (MSTP_Master_Node_FSM(mstp_port)) { - /* do nothing while immediate transitioning */ - } - } else if (mstp_port->This_Station < 255) { - MSTP_Slave_Node_FSM(mstp_port); - } - } - } + for (;;) { + if (mstp_port->ReceivedValidFrame == false && + mstp_port->ReceivedInvalidFrame == false) { + RS485_Check_UART_Data(mstp_port); + MSTP_Receive_Frame_FSM(mstp_port); + } + if (mstp_port->ReceivedValidFrame || mstp_port->ReceivedInvalidFrame) { + run_master = true; + } else { + silence = mstp_port->SilenceTimer(NULL); + switch (mstp_port->master_state) { + case MSTP_MASTER_STATE_IDLE: + if (silence >= Tno_token) + run_master = true; + break; + case MSTP_MASTER_STATE_WAIT_FOR_REPLY: + if (silence >= poSharedData->Treply_timeout) + run_master = true; + break; + case MSTP_MASTER_STATE_POLL_FOR_MASTER: + if (silence >= poSharedData->Tusage_timeout) + run_master = true; + break; + default: + run_master = true; + break; + } + } + if (run_master) { + if (mstp_port->This_Station <= DEFAULT_MAX_MASTER) { + while (MSTP_Master_Node_FSM(mstp_port)) { + /* do nothing while immediate transitioning */ + } + } else if (mstp_port->This_Station < 255) { + MSTP_Slave_Node_FSM(mstp_port); + } + } + } - return NULL; + return NULL; } void dlmstp_fill_bacnet_address( @@ -343,12 +339,11 @@ uint16_t MSTP_Put_Receive( volatile struct mstp_port_struct_t *mstp_port) { uint16_t pdu_len = 0; - SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA*)mstp_port->UserData; + SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return 0; - } + if (!poSharedData) { + return 0; + } if (!poSharedData->Receive_Packet.ready) { /* bounds check - maybe this should send an abort? */ @@ -373,42 +368,41 @@ uint16_t MSTP_Get_Send( volatile struct mstp_port_struct_t * mstp_port, unsigned timeout) { /* milliseconds to wait for a packet */ - uint16_t pdu_len = 0; - uint8_t frame_type = 0; - struct mstp_pdu_packet *pkt; - SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA*)mstp_port->UserData; + uint16_t pdu_len = 0; + uint8_t frame_type = 0; + struct mstp_pdu_packet *pkt; + SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return 0; - } + if (!poSharedData) { + return 0; + } - (void) timeout; - if (Ringbuf_Empty(&poSharedData->PDU_Queue)) { - return 0; - } - pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&poSharedData->PDU_Queue); - if (pkt->data_expecting_reply) { - frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY; - } else { - frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY; - } - /* convert the PDU into the MSTP Frame */ - pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */ - mstp_port->OutputBufferSize, frame_type, pkt->destination_mac, - mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length); + (void) timeout; + if (Ringbuf_Empty(&poSharedData->PDU_Queue)) { + return 0; + } + pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&poSharedData->PDU_Queue); + if (pkt->data_expecting_reply) { + frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY; + } else { + frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY; + } + /* convert the PDU into the MSTP Frame */ + pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */ + mstp_port->OutputBufferSize, frame_type, pkt->destination_mac, + mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length); (void) Ringbuf_Pop(&poSharedData->PDU_Queue, NULL); - return pdu_len; + return pdu_len; } bool dlmstp_compare_data_expecting_reply( - uint8_t * request_pdu, - uint16_t request_pdu_len, - uint8_t src_address, - uint8_t * reply_pdu, - uint16_t reply_pdu_len, - uint8_t dest_address) + uint8_t * request_pdu, + uint16_t request_pdu_len, + uint8_t src_address, + uint8_t * reply_pdu, + uint16_t reply_pdu_len, + uint8_t dest_address) { uint16_t offset; /* One way to check the message is to compare NPDU @@ -565,12 +559,11 @@ uint16_t MSTP_Get_Reply( bool matched = false; uint8_t frame_type = 0; struct mstp_pdu_packet *pkt; - SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA*)mstp_port->UserData; + SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return 0; - } + if (!poSharedData) { + return 0; + } if (Ringbuf_Empty(&poSharedData->PDU_Queue)) { return 0; @@ -599,15 +592,15 @@ uint16_t MSTP_Get_Reply( } void dlmstp_set_mac_address( - void * poPort, + void *poPort, uint8_t mac_address) { /* SHARED_MSTP_DATA * poSharedData; */ - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return; - } + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return; + } /* poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; if(!poSharedData) @@ -617,7 +610,7 @@ void dlmstp_set_mac_address( */ /* Master Nodes can only have address 0-127 */ if (mac_address <= 127) { - mstp_port->This_Station = mac_address; + mstp_port->This_Station = mac_address; /* FIXME: implement your data storage */ /* I2C_Write_Byte( EEPROM_DEVICE_ADDRESS, @@ -631,14 +624,14 @@ void dlmstp_set_mac_address( } uint8_t dlmstp_mac_address( - void * poPort) + void *poPort) { /* SHARED_MSTP_DATA * poSharedData; */ - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return 0; - } + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return 0; + } /* poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; if(!poSharedData) { @@ -657,15 +650,15 @@ uint8_t dlmstp_mac_address( /* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */ /* node, its value shall be 1. */ void dlmstp_set_max_info_frames( - void * poPort, + void *poPort, uint8_t max_info_frames) { /* SHARED_MSTP_DATA * poSharedData; */ - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return; - } + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return; + } /* poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; if(!poSharedData) @@ -674,7 +667,7 @@ void dlmstp_set_max_info_frames( } */ if (max_info_frames >= 1) { - mstp_port->Nmax_info_frames = max_info_frames; + mstp_port->Nmax_info_frames = max_info_frames; /* FIXME: implement your data storage */ /* I2C_Write_Byte( EEPROM_DEVICE_ADDRESS, @@ -686,14 +679,14 @@ void dlmstp_set_max_info_frames( } uint8_t dlmstp_max_info_frames( - void * poPort) + void *poPort) { /* SHARED_MSTP_DATA * poSharedData; */ - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return 0; - } + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return 0; + } /* poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; if(!poSharedData) @@ -710,15 +703,15 @@ uint8_t dlmstp_max_info_frames( /* less than or equal to 127. If Max_Master is not writable in a node, */ /* its value shall be 127. */ void dlmstp_set_max_master( - void * poPort, + void *poPort, uint8_t max_master) { /* SHARED_MSTP_DATA * poSharedData; */ - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return; - } + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return; + } /* poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; if(!poSharedData) @@ -728,7 +721,7 @@ void dlmstp_set_max_master( */ if (max_master <= 127) { if (mstp_port->This_Station <= max_master) { - mstp_port->Nmax_master = max_master; + mstp_port->Nmax_master = max_master; /* FIXME: implement your data storage */ /* I2C_Write_Byte( EEPROM_DEVICE_ADDRESS, @@ -741,14 +734,14 @@ void dlmstp_set_max_master( } uint8_t dlmstp_max_master( - void * poPort) + void *poPort) { /* SHARED_MSTP_DATA * poSharedData; */ - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return 0; - } + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return 0; + } /* poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; if(!poSharedData) @@ -761,36 +754,35 @@ uint8_t dlmstp_max_master( /* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */ void dlmstp_set_baud_rate( - void * poPort, + void *poPort, uint32_t baud) { - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return; - } - poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return; - } + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return; + } + poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + return; + } switch (baud) { case 9600: - poSharedData->RS485_Baud = B9600; + poSharedData->RS485_Baud = B9600; break; case 19200: - poSharedData->RS485_Baud = B19200; + poSharedData->RS485_Baud = B19200; break; case 38400: - poSharedData->RS485_Baud = B38400; + poSharedData->RS485_Baud = B38400; break; case 57600: - poSharedData->RS485_Baud = B57600; + poSharedData->RS485_Baud = B57600; break; case 115200: - poSharedData->RS485_Baud = B115200; + poSharedData->RS485_Baud = B115200; break; default: break; @@ -798,19 +790,18 @@ void dlmstp_set_baud_rate( } uint32_t dlmstp_baud_rate( - void * poPort) + void *poPort) { - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return false; - } - poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return false; - } + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return false; + } + poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + return false; + } switch (poSharedData->RS485_Baud) { case B19200: @@ -828,21 +819,20 @@ uint32_t dlmstp_baud_rate( } void dlmstp_get_my_address( - void * poPort, + void *poPort, BACNET_ADDRESS * my_address) { int i = 0; /* counter */ - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t *) poPort; - if(!mstp_port) - { - return; - } - poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return; - } + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return; + } + poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + return; + } my_address->mac_len = 1; my_address->mac[0] = mstp_port->This_Station; my_address->net = 0; /* local only, no routing */ @@ -873,28 +863,30 @@ void dlmstp_get_broadcast_address( } bool dlmstp_init( - void * poPort, + void *poPort, char *ifname) { unsigned long hThread = 0; int rv = 0; - SHARED_MSTP_DATA * poSharedData; - struct mstp_port_struct_t * mstp_port = (struct mstp_port_struct_t*)poPort; - if(!mstp_port) - { - return false; - } + SHARED_MSTP_DATA *poSharedData; + struct mstp_port_struct_t *mstp_port = + (struct mstp_port_struct_t *) poPort; + if (!mstp_port) { + return false; + } - poSharedData = (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t*)mstp_port)->UserData; - if(!poSharedData) - { - return false; - } + poSharedData = + (SHARED_MSTP_DATA *) ((struct mstp_port_struct_t *) mstp_port)-> + UserData; + if (!poSharedData) { + return false; + } - poSharedData->RS485_Port_Name = ifname; + poSharedData->RS485_Port_Name = ifname; /* initialize PDU queue */ - Ringbuf_Init(&poSharedData->PDU_Queue, (uint8_t *) & poSharedData->PDU_Buffer, - sizeof(struct mstp_pdu_packet), MSTP_PDU_PACKET_COUNT); + Ringbuf_Init(&poSharedData->PDU_Queue, + (uint8_t *) & poSharedData->PDU_Buffer, sizeof(struct mstp_pdu_packet), + MSTP_PDU_PACKET_COUNT); /* initialize packet queue */ poSharedData->Receive_Packet.ready = false; poSharedData->Receive_Packet.pdu_len = 0; @@ -918,7 +910,9 @@ bool dlmstp_init( Open device for reading and writing. Blocking mode - more CPU effecient */ - poSharedData->RS485_Handle = open(poSharedData->RS485_Port_Name, O_RDWR | O_NOCTTY | O_NONBLOCK/*| O_NDELAY */ ); + poSharedData->RS485_Handle = + open(poSharedData->RS485_Port_Name, + O_RDWR | O_NOCTTY | O_NONBLOCK /*| O_NDELAY */ ); if (poSharedData->RS485_Handle < 0) { perror(poSharedData->RS485_Port_Name); exit(-1); @@ -941,7 +935,8 @@ bool dlmstp_init( CLOCAL : local connection, no modem contol CREAD : enable receiving characters */ - newtio.c_cflag = poSharedData->RS485_Baud | poSharedData->RS485MOD | CLOCAL | CREAD; + newtio.c_cflag = + poSharedData->RS485_Baud | poSharedData->RS485MOD | CLOCAL | CREAD; /* Raw input */ newtio.c_iflag = 0; /* Raw output */ @@ -954,7 +949,8 @@ bool dlmstp_init( usleep(200000); tcflush(poSharedData->RS485_Handle, TCIOFLUSH); /* ringbuffer */ - FIFO_Init(&poSharedData->Rx_FIFO, poSharedData->Rx_Buffer, sizeof(poSharedData->Rx_Buffer)); + FIFO_Init(&poSharedData->Rx_FIFO, poSharedData->Rx_Buffer, + sizeof(poSharedData->Rx_Buffer)); printf("=success!\n"); mstp_port->InputBuffer = &poSharedData->RxBuffer[0]; mstp_port->InputBufferSize = sizeof(poSharedData->RxBuffer); @@ -967,7 +963,8 @@ bool dlmstp_init( #if PRINT_ENABLED fprintf(stderr, "MS/TP MAC: %02X\n", mstp_port->This_Station); fprintf(stderr, "MS/TP Max_Master: %02X\n", mstp_port->Nmax_master); - fprintf(stderr, "MS/TP Max_Info_Frames: %u\n", mstp_port->Nmax_info_frames); + fprintf(stderr, "MS/TP Max_Info_Frames: %u\n", + mstp_port->Nmax_info_frames); #endif rv = pthread_create(&hThread, NULL, dlmstp_master_fsm_task, mstp_port); diff --git a/bacnet-stack/ports/linux/dlmstp_linux.h b/bacnet-stack/ports/linux/dlmstp_linux.h index dcc3a93f..43487ded 100644 --- a/bacnet-stack/ports/linux/dlmstp_linux.h +++ b/bacnet-stack/ports/linux/dlmstp_linux.h @@ -62,91 +62,90 @@ struct mstp_pdu_packet { uint8_t buffer[MAX_MPDU]; }; -typedef struct shared_mstp_data -{ - /* Number of MS/TP Packets Rx/Tx */ - uint16_t MSTP_Packets; +typedef struct shared_mstp_data { + /* Number of MS/TP Packets Rx/Tx */ + uint16_t MSTP_Packets; - /* packet queues */ - DLMSTP_PACKET Receive_Packet; - DLMSTP_PACKET Transmit_Packet; - /* - RT_COND Receive_Packet_Flag; - RT_MUTEX Receive_Packet_Mutex; - */ - pthread_cond_t Receive_Packet_Flag; - pthread_mutex_t Receive_Packet_Mutex; - /* mechanism to wait for a frame in state machine */ - /* - RT_COND Received_Frame_Flag; - RT_MUTEX Received_Frame_Mutex; - */ - pthread_cond_t Received_Frame_Flag; - pthread_mutex_t Received_Frame_Mutex; - pthread_cond_t Master_Done_Flag; - pthread_mutex_t Master_Done_Mutex; - /* buffers needed by mstp port struct */ - uint8_t TxBuffer[MAX_MPDU]; - uint8_t RxBuffer[MAX_MPDU]; - /* The minimum time without a DataAvailable or ReceiveError event */ - /* that a node must wait for a station to begin replying to a */ - /* confirmed request: 255 milliseconds. (Implementations may use */ - /* larger values for this timeout, not to exceed 300 milliseconds.) */ - uint16_t Treply_timeout; - /* The minimum time without a DataAvailable or ReceiveError event that a */ - /* node must wait for a remote node to begin using a token or replying to */ - /* a Poll For Master frame: 20 milliseconds. (Implementations may use */ - /* larger values for this timeout, not to exceed 100 milliseconds.) */ - uint8_t Tusage_timeout; - /* Timer that indicates line silence - and functions */ - uint16_t SilenceTime; + /* packet queues */ + DLMSTP_PACKET Receive_Packet; + DLMSTP_PACKET Transmit_Packet; + /* + RT_COND Receive_Packet_Flag; + RT_MUTEX Receive_Packet_Mutex; + */ + pthread_cond_t Receive_Packet_Flag; + pthread_mutex_t Receive_Packet_Mutex; + /* mechanism to wait for a frame in state machine */ + /* + RT_COND Received_Frame_Flag; + RT_MUTEX Received_Frame_Mutex; + */ + pthread_cond_t Received_Frame_Flag; + pthread_mutex_t Received_Frame_Mutex; + pthread_cond_t Master_Done_Flag; + pthread_mutex_t Master_Done_Mutex; + /* buffers needed by mstp port struct */ + uint8_t TxBuffer[MAX_MPDU]; + uint8_t RxBuffer[MAX_MPDU]; + /* The minimum time without a DataAvailable or ReceiveError event */ + /* that a node must wait for a station to begin replying to a */ + /* confirmed request: 255 milliseconds. (Implementations may use */ + /* larger values for this timeout, not to exceed 300 milliseconds.) */ + uint16_t Treply_timeout; + /* The minimum time without a DataAvailable or ReceiveError event that a */ + /* node must wait for a remote node to begin using a token or replying to */ + /* a Poll For Master frame: 20 milliseconds. (Implementations may use */ + /* larger values for this timeout, not to exceed 100 milliseconds.) */ + uint8_t Tusage_timeout; + /* Timer that indicates line silence - and functions */ + uint16_t SilenceTime; - /* handle returned from open() */ - int RS485_Handle; - /* baudrate settings are defined in , which is - included by */ - unsigned int RS485_Baud; - /* serial port name, /dev/ttyS0, - /dev/ttyUSB0 for USB->RS485 from B&B Electronics USOPTL4 */ - char *RS485_Port_Name; - /* serial I/O settings */ - struct termios RS485_oldtio; - /* some terminal I/O have RS-485 specific functionality */ - tcflag_t RS485MOD; - /* Ring buffer for incoming bytes, in order to speed up the receiving. */ - FIFO_BUFFER Rx_FIFO; - /* buffer size needs to be a power of 2 */ - uint8_t Rx_Buffer[4096]; - struct timeval start; + /* handle returned from open() */ + int RS485_Handle; + /* baudrate settings are defined in , which is + included by */ + unsigned int RS485_Baud; + /* serial port name, /dev/ttyS0, + /dev/ttyUSB0 for USB->RS485 from B&B Electronics USOPTL4 */ + char *RS485_Port_Name; + /* serial I/O settings */ + struct termios RS485_oldtio; + /* some terminal I/O have RS-485 specific functionality */ + tcflag_t RS485MOD; + /* Ring buffer for incoming bytes, in order to speed up the receiving. */ + FIFO_BUFFER Rx_FIFO; + /* buffer size needs to be a power of 2 */ + uint8_t Rx_Buffer[4096]; + struct timeval start; - RING_BUFFER PDU_Queue; + RING_BUFFER PDU_Queue; - struct mstp_pdu_packet PDU_Buffer[MSTP_PDU_PACKET_COUNT]; + struct mstp_pdu_packet PDU_Buffer[MSTP_PDU_PACKET_COUNT]; -}SHARED_MSTP_DATA; +} SHARED_MSTP_DATA; #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ bool dlmstp_init( - void * poShared, + void *poShared, char *ifname); void dlmstp_reset( - void * poShared); + void *poShared); void dlmstp_cleanup( - void * poShared); + void *poShared); /* returns number of bytes sent on success, negative on failure */ int dlmstp_send_pdu( - void * poShared, + void *poShared, BACNET_ADDRESS * dest, /* destination address */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len); /* number of bytes of data */ /* returns the number of octets in the PDU, or zero on failure */ uint16_t dlmstp_receive( - void * poShared, + void *poShared, BACNET_ADDRESS * src, /* source address */ uint8_t * pdu, /* PDU data */ uint16_t max_pdu, /* amount of space available in the PDU */ @@ -160,10 +159,10 @@ extern "C" { /* bandwidth to particular nodes. If Max_Info_Frames is not writable in a */ /* node, its value shall be 1. */ void dlmstp_set_max_info_frames( - void * poShared, + void *poShared, uint8_t max_info_frames); uint8_t dlmstp_max_info_frames( - void * poShared); + void *poShared); /* This parameter represents the value of the Max_Master property of the */ /* node's Device object. The value of Max_Master specifies the highest */ @@ -171,30 +170,30 @@ extern "C" { /* less than or equal to 127. If Max_Master is not writable in a node, */ /* its value shall be 127. */ void dlmstp_set_max_master( - void * poShared, + void *poShared, uint8_t max_master); uint8_t dlmstp_max_master( - void * poShared); + void *poShared); /* MAC address 0-127 */ void dlmstp_set_mac_address( - void * poShared, + void *poShared, uint8_t my_address); uint8_t dlmstp_mac_address( - void * poShared); + void *poShared); void dlmstp_get_my_address( - void * poShared, + void *poShared, BACNET_ADDRESS * my_address); void dlmstp_get_broadcast_address( BACNET_ADDRESS * dest); /* destination address */ /* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */ void dlmstp_set_baud_rate( - void * poShared, + void *poShared, uint32_t baud); uint32_t dlmstp_baud_rate( - void * poShared); + void *poShared); void dlmstp_fill_bacnet_address( BACNET_ADDRESS * src, @@ -206,5 +205,4 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - -#endif /*DLMSTP_LINUX_H*/ +#endif /*DLMSTP_LINUX_H */ diff --git a/bacnet-stack/ports/linux/net.h b/bacnet-stack/ports/linux/net.h index f5edeb6a..3f1f3ba7 100644 --- a/bacnet-stack/ports/linux/net.h +++ b/bacnet-stack/ports/linux/net.h @@ -46,28 +46,28 @@ #include /* for Unix domain sockets */ #ifdef HAVE_SYS_SELECT_H -# include /* for convenience */ +#include /* for convenience */ #endif #ifdef HAVE_POLL_H -# include /* for convenience */ +#include /* for convenience */ #endif #ifdef HAVE_STRINGS_H -# include /* for convenience */ +#include /* for convenience */ #endif /* Three headers are normally needed for socket/file ioctl's: * , , and . */ #ifdef HAVE_SYS_IOCTL_H -# include +#include #endif #ifdef HAVE_SYS_FILIO_H -# include +#include #endif #ifdef HAVE_SYS_SOCKIO_H -# include +#include #endif #include diff --git a/bacnet-stack/ports/linux/rs485.c b/bacnet-stack/ports/linux/rs485.c index 0abe3385..f74434b6 100644 --- a/bacnet-stack/ports/linux/rs485.c +++ b/bacnet-stack/ports/linux/rs485.c @@ -54,8 +54,8 @@ #include #include #include -#include /* for struct serial_struct */ -#include /* for calculation of custom divisor */ +#include /* for struct serial_struct */ +#include /* for calculation of custom divisor */ #include /* Local includes */ @@ -187,8 +187,8 @@ uint32_t RS485_Get_Baud_Rate( break; case B38400: if (!RS485_SpecBaud) { - /* Linux asks for custom divisor - only when baud is set on 38400 */ + /* Linux asks for custom divisor + only when baud is set on 38400 */ baud = 38400; } else { baud = 76800; @@ -217,14 +217,13 @@ uint32_t RS485_Get_Baud_Rate( * NOTES: none *****************************************************************************/ uint32_t RS485_Get_Port_Baud_Rate( - volatile struct mstp_port_struct_t *mstp_port) + volatile struct mstp_port_struct_t * mstp_port) { uint32_t baud = 0; - SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - return 0; - } + SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + return 0; + } switch (poSharedData->RS485_Baud) { case B0: baud = 0; @@ -387,66 +386,63 @@ void RS485_Send_Frame( volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ uint16_t nbytes) -{ /* number of bytes of data (up to 501) */ +{ /* number of bytes of data (up to 501) */ uint32_t turnaround_time = Tturnaround * 1000; uint32_t baud; ssize_t written = 0; int greska; - SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - baud = RS485_Get_Baud_Rate(); - /* sleeping for turnaround time is necessary to give other devices - time to change from sending to receiving state. */ - usleep(turnaround_time / baud); - /* - On success, the number of bytes written are returned (zero indicates - nothing was written). On error, -1 is returned, and errno is set - appropriately. If count is zero and the file descriptor refers to a - regular file, 0 will be returned without causing any other effect. For - a special file, the results are not portable. - */ - written = write(RS485_Handle, buffer, nbytes); - greska = errno; - if (written <= 0) { - printf("write error: %s\n", strerror(greska)); - } else { - /* wait until all output has been transmitted. */ - tcdrain(RS485_Handle); - } - /* tcdrain(RS485_Handle); */ - /* per MSTP spec, sort of */ - if (mstp_port) { - mstp_port->SilenceTimerReset((void*)mstp_port); - } - } - else - { - baud = RS485_Get_Port_Baud_Rate(mstp_port); - /* sleeping for turnaround time is necessary to give other devices - time to change from sending to receiving state. */ - usleep(turnaround_time / baud); - /* - On success, the number of bytes written are returned (zero indicates - nothing was written). On error, -1 is returned, and errno is set - appropriately. If count is zero and the file descriptor refers to a - regular file, 0 will be returned without causing any other effect. For - a special file, the results are not portable. - */ - written = write(poSharedData->RS485_Handle, buffer, nbytes); - greska = errno; - if (written <= 0) { - printf("write error: %s\n", strerror(greska)); - } else { - /* wait until all output has been transmitted. */ - tcdrain(poSharedData->RS485_Handle); - } - /* tcdrain(RS485_Handle); */ - /* per MSTP spec, sort of */ - if (mstp_port) { - mstp_port->SilenceTimerReset((void*)mstp_port); - } - } + SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + baud = RS485_Get_Baud_Rate(); + /* sleeping for turnaround time is necessary to give other devices + time to change from sending to receiving state. */ + usleep(turnaround_time / baud); + /* + On success, the number of bytes written are returned (zero indicates + nothing was written). On error, -1 is returned, and errno is set + appropriately. If count is zero and the file descriptor refers to a + regular file, 0 will be returned without causing any other effect. For + a special file, the results are not portable. + */ + written = write(RS485_Handle, buffer, nbytes); + greska = errno; + if (written <= 0) { + printf("write error: %s\n", strerror(greska)); + } else { + /* wait until all output has been transmitted. */ + tcdrain(RS485_Handle); + } + /* tcdrain(RS485_Handle); */ + /* per MSTP spec, sort of */ + if (mstp_port) { + mstp_port->SilenceTimerReset((void *) mstp_port); + } + } else { + baud = RS485_Get_Port_Baud_Rate(mstp_port); + /* sleeping for turnaround time is necessary to give other devices + time to change from sending to receiving state. */ + usleep(turnaround_time / baud); + /* + On success, the number of bytes written are returned (zero indicates + nothing was written). On error, -1 is returned, and errno is set + appropriately. If count is zero and the file descriptor refers to a + regular file, 0 will be returned without causing any other effect. For + a special file, the results are not portable. + */ + written = write(poSharedData->RS485_Handle, buffer, nbytes); + greska = errno; + if (written <= 0) { + printf("write error: %s\n", strerror(greska)); + } else { + /* wait until all output has been transmitted. */ + tcdrain(poSharedData->RS485_Handle); + } + /* tcdrain(RS485_Handle); */ + /* per MSTP spec, sort of */ + if (mstp_port) { + mstp_port->SilenceTimerReset((void *) mstp_port); + } + } return; } @@ -465,75 +461,73 @@ void RS485_Check_UART_Data( uint8_t buf[2048]; int n; - SHARED_MSTP_DATA * poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; - if(!poSharedData) - { - if (mstp_port->ReceiveError == true) { - /* do nothing but wait for state machine to clear the error */ - /* burning time, so wait a longer time */ - waiter.tv_sec = 0; - waiter.tv_usec = 5000; - } else if (mstp_port->DataAvailable == false) { - /* wait for state machine to read from the DataRegister */ - if (FIFO_Count(&Rx_FIFO) > 0) { - /* data is available */ - mstp_port->DataRegister = FIFO_Get(&Rx_FIFO); - mstp_port->DataAvailable = true; - /* FIFO is giving data - don't wait very long */ - waiter.tv_sec = 0; - waiter.tv_usec = 10; - } else { - /* FIFO is empty - wait a longer time */ - waiter.tv_sec = 0; - waiter.tv_usec = 5000; - } - } - /* grab bytes and stuff them into the FIFO every time */ - FD_ZERO(&input); - FD_SET(RS485_Handle, &input); - n = select(RS485_Handle + 1, &input, NULL, NULL, &waiter); - if (n < 0) { - return; - } - if (FD_ISSET(RS485_Handle, &input)) { - n = read(RS485_Handle, buf, sizeof(buf)); - FIFO_Add(&Rx_FIFO, &buf[0], n); - } - } - else - { - if (mstp_port->ReceiveError == true) { - /* do nothing but wait for state machine to clear the error */ - /* burning time, so wait a longer time */ - waiter.tv_sec = 0; - waiter.tv_usec = 5000; - } else if (mstp_port->DataAvailable == false) { - /* wait for state machine to read from the DataRegister */ - if (FIFO_Count(&poSharedData->Rx_FIFO) > 0) { - /* data is available */ - mstp_port->DataRegister = FIFO_Get(&poSharedData->Rx_FIFO); - mstp_port->DataAvailable = true; - /* FIFO is giving data - don't wait very long */ - waiter.tv_sec = 0; - waiter.tv_usec = 10; - } else { - /* FIFO is empty - wait a longer time */ - waiter.tv_sec = 0; - waiter.tv_usec = 5000; - } - } - /* grab bytes and stuff them into the FIFO every time */ - FD_ZERO(&input); - FD_SET(poSharedData->RS485_Handle, &input); - n = select(poSharedData->RS485_Handle + 1, &input, NULL, NULL, &waiter); - if (n < 0) { - return; - } - if (FD_ISSET(poSharedData->RS485_Handle, &input)) { - n = read(poSharedData->RS485_Handle, buf, sizeof(buf)); - FIFO_Add(&poSharedData->Rx_FIFO, &buf[0], n); - } - } + SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData; + if (!poSharedData) { + if (mstp_port->ReceiveError == true) { + /* do nothing but wait for state machine to clear the error */ + /* burning time, so wait a longer time */ + waiter.tv_sec = 0; + waiter.tv_usec = 5000; + } else if (mstp_port->DataAvailable == false) { + /* wait for state machine to read from the DataRegister */ + if (FIFO_Count(&Rx_FIFO) > 0) { + /* data is available */ + mstp_port->DataRegister = FIFO_Get(&Rx_FIFO); + mstp_port->DataAvailable = true; + /* FIFO is giving data - don't wait very long */ + waiter.tv_sec = 0; + waiter.tv_usec = 10; + } else { + /* FIFO is empty - wait a longer time */ + waiter.tv_sec = 0; + waiter.tv_usec = 5000; + } + } + /* grab bytes and stuff them into the FIFO every time */ + FD_ZERO(&input); + FD_SET(RS485_Handle, &input); + n = select(RS485_Handle + 1, &input, NULL, NULL, &waiter); + if (n < 0) { + return; + } + if (FD_ISSET(RS485_Handle, &input)) { + n = read(RS485_Handle, buf, sizeof(buf)); + FIFO_Add(&Rx_FIFO, &buf[0], n); + } + } else { + if (mstp_port->ReceiveError == true) { + /* do nothing but wait for state machine to clear the error */ + /* burning time, so wait a longer time */ + waiter.tv_sec = 0; + waiter.tv_usec = 5000; + } else if (mstp_port->DataAvailable == false) { + /* wait for state machine to read from the DataRegister */ + if (FIFO_Count(&poSharedData->Rx_FIFO) > 0) { + /* data is available */ + mstp_port->DataRegister = FIFO_Get(&poSharedData->Rx_FIFO); + mstp_port->DataAvailable = true; + /* FIFO is giving data - don't wait very long */ + waiter.tv_sec = 0; + waiter.tv_usec = 10; + } else { + /* FIFO is empty - wait a longer time */ + waiter.tv_sec = 0; + waiter.tv_usec = 5000; + } + } + /* grab bytes and stuff them into the FIFO every time */ + FD_ZERO(&input); + FD_SET(poSharedData->RS485_Handle, &input); + n = select(poSharedData->RS485_Handle + 1, &input, NULL, NULL, + &waiter); + if (n < 0) { + return; + } + if (FD_ISSET(poSharedData->RS485_Handle, &input)) { + n = read(poSharedData->RS485_Handle, buf, sizeof(buf)); + FIFO_Add(&poSharedData->Rx_FIFO, &buf[0], n); + } + } } void RS485_Cleanup( @@ -541,7 +535,7 @@ void RS485_Cleanup( { /* restore the old port settings */ tcsetattr(RS485_Handle, TCSANOW, &RS485_oldtio); - ioctl (RS485_Handle, TIOCSSERIAL, &RS485_oldserial); + ioctl(RS485_Handle, TIOCSSERIAL, &RS485_oldserial); close(RS485_Handle); } @@ -573,9 +567,9 @@ void RS485_Initialize( /* save current serial port settings */ tcgetattr(RS485_Handle, &RS485_oldtio); /* we read the old serial setup */ - ioctl (RS485_Handle, TIOCGSERIAL, &RS485_oldserial); + ioctl(RS485_Handle, TIOCGSERIAL, &RS485_oldserial); /* we need a copy of existing settings */ - memcpy (&newserial, &RS485_oldserial, sizeof (struct serial_struct)); + memcpy(&newserial, &RS485_oldserial, sizeof(struct serial_struct)); /* clear struct for new port settings */ bzero(&newtio, sizeof(newtio)); /* @@ -599,19 +593,21 @@ void RS485_Initialize( /* 76800, custom divisor must be set */ newserial.flags |= ASYNC_SPD_CUST; newserial.custom_divisor = - round (((float)newserial.baud_base)/76800); + round(((float) newserial.baud_base) / 76800); /* we must check that we calculated some sane value; - small baud bases yield bad custom divisor values */ - baud_error = fabs (1 -((float)newserial.baud_base)/ - ((float)newserial.custom_divisor)/76800); + small baud bases yield bad custom divisor values */ + baud_error = + fabs(1 - + ((float) newserial.baud_base) / + ((float) newserial.custom_divisor) / 76800); if ((newserial.custom_divisor == 0) || (baud_error > 0.02)) { /* bad divisor */ - fprintf (stderr, "bad custom divisor %d, base baud %d\n", + fprintf(stderr, "bad custom divisor %d, base baud %d\n", newserial.custom_divisor, newserial.baud_base); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } /* if all goes well, set new divisor */ - ioctl (RS485_Handle, TIOCSSERIAL, &newserial); + ioctl(RS485_Handle, TIOCSSERIAL, &newserial); } /* destructor */ diff --git a/bacnet-stack/ports/lwip/bip.c b/bacnet-stack/ports/lwip/bip.c index 0b406b92..91ba274c 100644 --- a/bacnet-stack/ports/lwip/bip.c +++ b/bacnet-stack/ports/lwip/bip.c @@ -94,7 +94,7 @@ uint16_t bip_get_port( static void bip_mac_to_addr( struct ip_addr *address, - uint8_t *mac) + uint8_t * mac) { if (mac && address) { address->addr = ((u32_t) ((((uint32_t) mac[0]) << 24) & 0xff000000)); @@ -105,14 +105,14 @@ static void bip_mac_to_addr( } static void bip_addr_to_mac( - uint8_t *mac, + uint8_t * mac, struct ip_addr *address) { if (mac && address) { - mac[0] = (uint8_t)(address->addr >> 24); - mac[1] = (uint8_t)(address->addr >> 16); - mac[2] = (uint8_t)(address->addr >> 8); - mac[3] = (uint8_t)(address->addr); + mac[0] = (uint8_t) (address->addr >> 24); + mac[1] = (uint8_t) (address->addr >> 16); + mac[2] = (uint8_t) (address->addr >> 8); + mac[3] = (uint8_t) (address->addr); } } @@ -161,7 +161,7 @@ int bip_send_pdu( if (pkt == NULL) { return 0; } - mtu = (uint8_t *)pkt->payload; + mtu = (uint8_t *) pkt->payload; mtu[0] = BVLL_TYPE_BACNET_IP; if (dest->net == BACNET_BROADCAST_NETWORK) { /* broadcast */ @@ -209,7 +209,7 @@ void bip_server_callback( }; /* address where message came from */ struct ip_addr sin_addr; uint16_t sin_port = 0; - uint8_t *pdu = (uint8_t *)pkt->payload; + uint8_t *pdu = (uint8_t *) pkt->payload; /* the signature of a BACnet/IP packet */ if (pdu[0] != BVLL_TYPE_BACNET_IP) { @@ -219,8 +219,7 @@ void bip_server_callback( if ((function == BVLC_ORIGINAL_UNICAST_NPDU) || (function == BVLC_ORIGINAL_BROADCAST_NPDU)) { /* ignore messages from me */ - if ((addr->addr == BIP_Address.s_addr) && - (port == BIP_Port)) { + if ((addr->addr == BIP_Address.s_addr) && (port == BIP_Port)) { pdu_len = 0; } else { /* data in src->mac[] is in network format */ @@ -236,8 +235,7 @@ void bip_server_callback( } else if (function == BVLC_FORWARDED_NPDU) { bip_mac_to_addr(&sin_addr, &pdu[4]); memcpy(&sin_port, &pdu[8], 2); - if ((sin_addr.addr == BIP_Address.s_addr) && - (sin_port == BIP_Port)) { + if ((sin_addr.addr == BIP_Address.s_addr) && (sin_port == BIP_Port)) { /* ignore forwarded messages from me */ pdu_len = 0; } else { @@ -326,12 +324,13 @@ void bip_get_broadcast_address( bool bip_init( char *ifname) { - (void)ifname; + (void) ifname; /* Create a new UDP control block */ Server_upcb = udp_new(); if (Server_upcb == NULL) { /* increase MEMP_NUM_UDP_PCB in lwipopts.h */ - while(1) {}; + while (1) { + }; } /* Bind the upcb to the UDP_PORT port */ /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */ diff --git a/bacnet-stack/ports/lwip/net.h b/bacnet-stack/ports/lwip/net.h index 338023c6..b4e6d0ae 100644 --- a/bacnet-stack/ports/lwip/net.h +++ b/bacnet-stack/ports/lwip/net.h @@ -39,17 +39,17 @@ /* members are in network byte order */ struct sockaddr_in { - u8_t sin_len; - u8_t sin_family; - u16_t sin_port; - struct in_addr sin_addr; - char sin_zero[8]; + u8_t sin_len; + u8_t sin_family; + u16_t sin_port; + struct in_addr sin_addr; + char sin_zero[8]; }; struct sockaddr { - u8_t sa_len; - u8_t sa_family; - char sa_data[14]; + u8_t sa_len; + u8_t sa_family; + char sa_data[14]; }; #endif diff --git a/bacnet-stack/ports/pic18f6720/ai.c b/bacnet-stack/ports/pic18f6720/ai.c index 31b43465..35f5cea1 100644 --- a/bacnet-stack/ports/pic18f6720/ai.c +++ b/bacnet-stack/ports/pic18f6720/ai.c @@ -73,7 +73,7 @@ char *Analog_Input_Name( static char text_string[16] = ""; /* okay for single thread */ if (object_instance < MAX_ANALOG_INPUTS) { - sprintf(text_string, "AI-%lu", (unsigned long)object_instance); + sprintf(text_string, "AI-%lu", (unsigned long) object_instance); return text_string; } @@ -172,4 +172,3 @@ int Analog_Input_Read_Property( return apdu_len; } - diff --git a/bacnet-stack/ports/pic18f6720/av.c b/bacnet-stack/ports/pic18f6720/av.c index c5f5968a..c44057bb 100644 --- a/bacnet-stack/ports/pic18f6720/av.c +++ b/bacnet-stack/ports/pic18f6720/av.c @@ -333,8 +333,8 @@ bool Analog_Value_Write_Property( (value.type.Real >= 0.0) && (value.type.Real <= 100.0)) { level = (uint8_t) value.type.Real; object_index = - Analog_Value_Instance_To_Index(wp_data-> - object_instance); + Analog_Value_Instance_To_Index + (wp_data->object_instance); priority--; Present_Value[object_index] = level; /* Note: you could set the physical output here if we diff --git a/bacnet-stack/ports/pic18f6720/bv.c b/bacnet-stack/ports/pic18f6720/bv.c index 32b1aa2d..9d8efec7 100644 --- a/bacnet-stack/ports/pic18f6720/bv.c +++ b/bacnet-stack/ports/pic18f6720/bv.c @@ -158,7 +158,8 @@ int Binary_Value_Read_Property( encode_application_enumerated(&apdu[0], OBJECT_BINARY_VALUE); break; case PROP_PRESENT_VALUE: - present_value = Binary_Value_Present_Value(rpdata->object_instance); + present_value = + Binary_Value_Present_Value(rpdata->object_instance); apdu_len = encode_application_enumerated(&apdu[0], present_value); break; case PROP_STATUS_FLAGS: @@ -245,8 +246,8 @@ bool Binary_Value_Write_Property( (value.type.Enumerated <= MAX_BINARY_PV)) { level = value.type.Enumerated; object_index = - Binary_Value_Instance_To_Index(wp_data-> - object_instance); + Binary_Value_Instance_To_Index + (wp_data->object_instance); priority--; /* NOTE: this Binary value has no priority array */ Present_Value[object_index] = level; diff --git a/bacnet-stack/ports/pic18f6720/device.c b/bacnet-stack/ports/pic18f6720/device.c index be80237e..f0046862 100644 --- a/bacnet-stack/ports/pic18f6720/device.c +++ b/bacnet-stack/ports/pic18f6720/device.c @@ -85,7 +85,7 @@ BACNET_REINITIALIZED_STATE Device_Reinitialized_State( void Device_Init( object_functions_t * object_table) { - (void)object_table; + (void) object_table; Reinitialize_State = BACNET_REINIT_IDLE; dcc_set_status_duration(COMMUNICATION_ENABLE, 0); /* FIXME: Get the data from the eeprom */ @@ -420,10 +420,8 @@ int Device_Read_Property_Local( } } } else { - if (Device_Object_List_Identifier( - rpdata->array_index, - &object_type, - &instance)) + if (Device_Object_List_Identifier(rpdata->array_index, + &object_type, &instance)) apdu_len = encode_application_object_id(&apdu[0], object_type, instance); @@ -586,8 +584,8 @@ bool Device_Write_Property_Local( case PROP_OBJECT_IDENTIFIER: if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if ((value.type.Object_Id.type == OBJECT_DEVICE) && - (Device_Set_Object_Instance_Number(value.type.Object_Id. - instance))) { + (Device_Set_Object_Instance_Number(value.type. + Object_Id.instance))) { /* we could send an I-Am broadcast to let the world know */ status = true; } else { @@ -646,11 +644,13 @@ bool Device_Write_Property_Local( the device. */ } else { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; + wp_data->error_code = + ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED; + wp_data->error_code = + ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED; } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; diff --git a/bacnet-stack/ports/pic18f6720/mstp.c b/bacnet-stack/ports/pic18f6720/mstp.c index b685e201..de38f555 100644 --- a/bacnet-stack/ports/pic18f6720/mstp.c +++ b/bacnet-stack/ports/pic18f6720/mstp.c @@ -916,8 +916,7 @@ bool MSTP_Master_Node_FSM( should be sent is unknown - so PollForMaster */ mstp_port->Poll_Station = next_this_station; MSTP_Create_And_Send_Frame(mstp_port, - FRAME_TYPE_POLL_FOR_MASTER, - mstp_port->Poll_Station, + FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); mstp_port->RetryCount = 0; mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; @@ -1150,10 +1149,10 @@ bool MSTP_Master_Node_FSM( see if the message is that same APDU type along with the matching src/dest and invoke ID */ matched = - mstp_compare_data_expecting_reply(&mstp_port-> - InputBuffer[0], mstp_port->DataLength, - mstp_port->SourceAddress, &mstp_port->TxBuffer[0], - mstp_port->TxLength, mstp_port->TxDestination); + mstp_compare_data_expecting_reply(&mstp_port->InputBuffer + [0], mstp_port->DataLength, mstp_port->SourceAddress, + &mstp_port->TxBuffer[0], mstp_port->TxLength, + mstp_port->TxDestination); } if (matched && mstp_port->TxReady) { /* Reply */ diff --git a/bacnet-stack/ports/rtos32/bip-init.c b/bacnet-stack/ports/rtos32/bip-init.c index 3357b518..c8bd98d4 100644 --- a/bacnet-stack/ports/rtos32/bip-init.c +++ b/bacnet-stack/ports/rtos32/bip-init.c @@ -261,7 +261,8 @@ bool bip_init( bip_set_port(htons((0xBAC0)); /* assumes that the driver has already been initialized */ sock_fd = socket(AF_INET, SOCK_DGRAM, IPROTO_UDP); - bip_set_socket(sock_fd); if (sock_fd < 0) + bip_set_socket(sock_fd); + if (sock_fd < 0) return false; /* bind the socket to the local port number and IP address */ sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_ANY); diff --git a/bacnet-stack/ports/rx62n/bo.c b/bacnet-stack/ports/rx62n/bo.c index 682ed46d..b6157c82 100644 --- a/bacnet-stack/ports/rx62n/bo.c +++ b/bacnet-stack/ports/rx62n/bo.c @@ -436,8 +436,8 @@ bool Binary_Output_Write_Property( priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; - Binary_Output_Present_Value_Set(wp_data-> - object_instance, level, priority); + Binary_Output_Present_Value_Set + (wp_data->object_instance, level, priority); } else if (priority == 6) { status = false; /* Command priority 6 is reserved for use by Minimum On/Off diff --git a/bacnet-stack/ports/rx62n/device.c b/bacnet-stack/ports/rx62n/device.c index 23bc7e26..c5016537 100644 --- a/bacnet-stack/ports/rx62n/device.c +++ b/bacnet-stack/ports/rx62n/device.c @@ -838,8 +838,8 @@ bool Device_Write_Property_Local( &wp_data->error_class, &wp_data->error_code); if (status) { if ((value.type.Object_Id.type == OBJECT_DEVICE) && - (Device_Set_Object_Instance_Number(value.type.Object_Id. - instance))) { + (Device_Set_Object_Instance_Number(value.type. + Object_Id.instance))) { /* we could send an I-Am broadcast to let the world know */ status = true; } else { @@ -873,8 +873,8 @@ bool Device_Write_Property_Local( WPValidateString(&value, MAX_DEV_NAME_LEN, false, &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Object_Name(characterstring_value(&value.type. - Character_String), + Device_Set_Object_Name(characterstring_value(&value. + type.Character_String), characterstring_length(&value.type.Character_String)); } break; @@ -883,8 +883,8 @@ bool Device_Write_Property_Local( WPValidateString(&value, MAX_DEV_LOC_LEN, true, &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Location(characterstring_value(&value.type. - Character_String), + Device_Set_Location(characterstring_value(&value. + type.Character_String), characterstring_length(&value.type.Character_String)); } break; @@ -894,8 +894,8 @@ bool Device_Write_Property_Local( WPValidateString(&value, MAX_DEV_DESC_LEN, true, &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Description(characterstring_value(&value.type. - Character_String), + Device_Set_Description(characterstring_value(&value. + type.Character_String), characterstring_length(&value.type.Character_String)); } break; diff --git a/bacnet-stack/ports/stm32f10x/bo.c b/bacnet-stack/ports/stm32f10x/bo.c index 5b6a3b7a..d60b867e 100644 --- a/bacnet-stack/ports/stm32f10x/bo.c +++ b/bacnet-stack/ports/stm32f10x/bo.c @@ -437,8 +437,8 @@ bool Binary_Output_Write_Property( priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; - Binary_Output_Present_Value_Set(wp_data-> - object_instance, level, priority); + Binary_Output_Present_Value_Set + (wp_data->object_instance, level, priority); } else if (priority == 6) { status = false; /* Command priority 6 is reserved for use by Minimum On/Off diff --git a/bacnet-stack/ports/stm32f10x/device.c b/bacnet-stack/ports/stm32f10x/device.c index f5d9fd6d..7dc18577 100644 --- a/bacnet-stack/ports/stm32f10x/device.c +++ b/bacnet-stack/ports/stm32f10x/device.c @@ -841,8 +841,8 @@ bool Device_Write_Property_Local( case PROP_OBJECT_IDENTIFIER: if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { if ((value.type.Object_Id.type == OBJECT_DEVICE) && - (Device_Set_Object_Instance_Number(value.type.Object_Id. - instance))) { + (Device_Set_Object_Instance_Number(value.type. + Object_Id.instance))) { /* we could send an I-Am broadcast to let the world know */ status = true; } else { @@ -894,13 +894,13 @@ bool Device_Write_Property_Local( characterstring_encoding(&value.type.Character_String); if (encoding < MAX_CHARACTER_STRING_ENCODING) { /* All the object names in a device must be unique. */ - if (Device_Valid_Object_Name(&value. - type.Character_String, NULL, NULL)) { + if (Device_Valid_Object_Name(&value.type. + Character_String, NULL, NULL)) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; } else { - Device_Set_Object_Name(&value. - type.Character_String); + Device_Set_Object_Name(&value.type. + Character_String); status = true; } } else { diff --git a/bacnet-stack/ports/stm32f10x/rs485.c b/bacnet-stack/ports/stm32f10x/rs485.c index 96171240..b1047752 100644 --- a/bacnet-stack/ports/stm32f10x/rs485.c +++ b/bacnet-stack/ports/stm32f10x/rs485.c @@ -112,7 +112,7 @@ bool rs485_receive_error( return false; } - /*********************************************************************//** + /*********************************************************************//** * @brief USARTx interrupt handler sub-routine * @param[in] None * @return None diff --git a/bacnet-stack/ports/win32/dlmstp.c b/bacnet-stack/ports/win32/dlmstp.c index 8bedf58e..d3c19802 100644 --- a/bacnet-stack/ports/win32/dlmstp.c +++ b/bacnet-stack/ports/win32/dlmstp.c @@ -73,13 +73,13 @@ static uint8_t Tusage_timeout = 50; /* Timer that indicates line silence - and functions */ static uint32_t Timer_Silence( - void * pArg) + void *pArg) { return timer_milliseconds(TIMER_SILENCE); } static void Timer_Silence_Reset( - void * pArg) + void *pArg) { timer_reset(TIMER_SILENCE); } @@ -259,7 +259,7 @@ uint16_t MSTP_Put_Receive( Receive_Packet.pdu_len = mstp_port->DataLength; Receive_Packet.ready = true; rc = ReleaseSemaphore(Receive_Packet_Flag, 1, NULL); - (void)rc; + (void) rc; } return pdu_len; diff --git a/bacnet-stack/src/address.c b/bacnet-stack/src/address.c index d04eecbd..dfca1222 100644 --- a/bacnet-stack/src/address.c +++ b/bacnet-stack/src/address.c @@ -149,7 +149,8 @@ static struct Address_Cache_Entry *address_remove_oldest( pMatch = Address_Cache; while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { - if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | + if ((pMatch-> + Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | BAC_ADDR_STATIC)) == BAC_ADDR_IN_USE) { if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */ ulTime = pMatch->TimeToLive; @@ -168,7 +169,8 @@ static struct Address_Cache_Entry *address_remove_oldest( /* Second pass - try in use and un bound as last resort */ pMatch = Address_Cache; while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { - if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | + if ((pMatch-> + Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | BAC_ADDR_STATIC)) == ((uint8_t) (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ))) { if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */ diff --git a/bacnet-stack/src/bacaddr.c b/bacnet-stack/src/bacaddr.c index 3310cb2e..8cc6a8ae 100644 --- a/bacnet-stack/src/bacaddr.c +++ b/bacnet-stack/src/bacaddr.c @@ -66,7 +66,7 @@ bool bacnet_address_same( uint8_t i = 0; /* loop counter */ uint8_t max_len = 0; /* used for dynamic max */ - if (dest == src) /* same ? */ + if (dest == src) /* same ? */ return true; if (dest->net != src->net) @@ -82,8 +82,7 @@ bool bacnet_address_same( if (dest->adr[i] != src->adr[i]) return false; } - if (dest->net == 0) - { + if (dest->net == 0) { if (dest->mac_len != src->mac_len) return false; max_len = dest->mac_len; diff --git a/bacnet-stack/src/bacapp.c b/bacnet-stack/src/bacapp.c index 481fa65c..9792e943 100644 --- a/bacnet-stack/src/bacapp.c +++ b/bacnet-stack/src/bacapp.c @@ -1103,8 +1103,8 @@ int bacapp_snprintf_value( if (value->type.Enumerated < MAX_ASHRAE_OBJECT_TYPE) { ret_val = snprintf(str, str_len, "%s", - bactext_object_type_name(value-> - type.Enumerated)); + bactext_object_type_name(value->type. + Enumerated)); } else if (value->type.Enumerated < 128) { ret_val = snprintf(str, str_len, "reserved %lu", @@ -1124,8 +1124,8 @@ int bacapp_snprintf_value( if (value->type.Enumerated < 256) { ret_val = snprintf(str, str_len, "%s", - bactext_engineering_unit_name(value->type. - Enumerated)); + bactext_engineering_unit_name(value-> + type.Enumerated)); } else { ret_val = snprintf(str, str_len, "proprietary %lu", @@ -1135,16 +1135,16 @@ int bacapp_snprintf_value( case PROP_POLARITY: ret_val = snprintf(str, str_len, "%s", - bactext_binary_polarity_name(value->type. - Enumerated)); + bactext_binary_polarity_name(value-> + type.Enumerated)); break; case PROP_PRESENT_VALUE: case PROP_RELINQUISH_DEFAULT: if (object_type < PROPRIETARY_BACNET_OBJECT_TYPE) { ret_val = snprintf(str, str_len, "%s", - bactext_binary_present_value_name(value-> - type.Enumerated)); + bactext_binary_present_value_name(value->type. + Enumerated)); } else { ret_val = snprintf(str, str_len, "%lu", @@ -1159,8 +1159,8 @@ int bacapp_snprintf_value( case PROP_SYSTEM_STATUS: ret_val = snprintf(str, str_len, "%s", - bactext_device_status_name(value->type. - Enumerated)); + bactext_device_status_name(value-> + type.Enumerated)); break; case PROP_SEGMENTATION_SUPPORTED: ret_val = @@ -1261,8 +1261,8 @@ int bacapp_snprintf_value( break; if (value->type.Object_Id.type < MAX_ASHRAE_OBJECT_TYPE) { if (!append_str(&p_str, &rem_str_len, - bactext_object_type_name(value->type.Object_Id. - type) + bactext_object_type_name(value->type. + Object_Id.type) ) ) break; @@ -1645,8 +1645,8 @@ void testBACnetApplicationData_Safe( break; case BACNET_APPLICATION_TAG_CHARACTER_STRING: - characterstring_init_ansi(&input_value[i]. - type.Character_String, "Hello There!"); + characterstring_init_ansi(&input_value[i].type. + Character_String, "Hello There!"); break; case BACNET_APPLICATION_TAG_BIT_STRING: diff --git a/bacnet-stack/src/bacdcode.c b/bacnet-stack/src/bacdcode.c index 365f5b8b..dcfb3cc4 100644 --- a/bacnet-stack/src/bacdcode.c +++ b/bacnet-stack/src/bacdcode.c @@ -994,7 +994,7 @@ uint32_t encode_bacnet_character_string_safe( char *pString, uint32_t length) { - uint32_t apdu_len = 1 /*encoding*/; + uint32_t apdu_len = 1 /*encoding */ ; uint32_t i; apdu_len += length; @@ -1014,9 +1014,7 @@ int encode_bacnet_character_string( uint8_t * apdu, BACNET_CHARACTER_STRING * char_string) { - return (int)encode_bacnet_character_string_safe( - apdu, - MAX_APDU, + return (int) encode_bacnet_character_string_safe(apdu, MAX_APDU, characterstring_encoding(char_string), characterstring_value(char_string), characterstring_length(char_string)); diff --git a/bacnet-stack/src/bacstr.c b/bacnet-stack/src/bacstr.c index 87e4c544..28a9a62f 100644 --- a/bacnet-stack/src/bacstr.c +++ b/bacnet-stack/src/bacstr.c @@ -743,7 +743,7 @@ size_t octetstring_copy_value( if (src && dest) { if (length <= src->length) { for (i = 0; i < src->length; i++) { - dest[i]= src->value[i]; + dest[i] = src->value[i]; } bytes_copied = src->length; } diff --git a/bacnet-stack/src/bactext.c b/bacnet-stack/src/bactext.c index 0e4febf2..0fa0cdb1 100644 --- a/bacnet-stack/src/bactext.c +++ b/bacnet-stack/src/bactext.c @@ -915,7 +915,7 @@ INDTEXT_DATA bacnet_property_names[] = { {PROP_LAST_KEY_SERVER, "last-key-server"} , {PROP_NETWORK_ACCESS_SECURITY_POLICIES, - "network-access-security-policies"} + "network-access-security-policies"} , {PROP_PACKET_REORDER_TIME, "packet-reorder-time"} , @@ -1013,7 +1013,8 @@ INDTEXT_DATA bacnet_property_names[] = { , {PROP_LIGHTING_COMMAND, "lighting-command"} , - {PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY, "lighting-command-default-priority"} + {PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY, + "lighting-command-default-priority"} , {PROP_MAX_ACTUAL_VALUE, "max-actual-value"} , diff --git a/bacnet-stack/src/bip.c b/bacnet-stack/src/bip.c index 1c6b6ca8..78e7112a 100644 --- a/bacnet-stack/src/bip.c +++ b/bacnet-stack/src/bip.c @@ -166,9 +166,8 @@ int bip_send_pdu( mtu[0] = BVLL_TYPE_BACNET_IP; bip_dest.sin_family = AF_INET; - if ((dest->net == BACNET_BROADCAST_NETWORK) || - ((dest->net > 0) && (dest->len == 0)) || - (dest->mac_len == 0)) { + if ((dest->net == BACNET_BROADCAST_NETWORK) || ((dest->net > 0) && + (dest->len == 0)) || (dest->mac_len == 0)) { /* broadcast */ address.s_addr = BIP_Broadcast_Address.s_addr; port = BIP_Port; diff --git a/bacnet-stack/src/bvlc.c b/bacnet-stack/src/bvlc.c index 5a8228f4..2e2a649d 100644 --- a/bacnet-stack/src/bvlc.c +++ b/bacnet-stack/src/bvlc.c @@ -700,8 +700,8 @@ static void bvlc_bdt_forward_npdu( mask in the BDT entry and logically ORing it with the BBMD address of the same entry. */ bip_dest.sin_addr.s_addr = - ((~BBMD_Table[i].broadcast_mask.s_addr) | BBMD_Table[i]. - dest_address.s_addr); + ((~BBMD_Table[i].broadcast_mask. + s_addr) | BBMD_Table[i].dest_address.s_addr); bip_dest.sin_port = BBMD_Table[i].dest_port; /* don't send to my broadcast address and same port */ if ((bip_dest.sin_addr.s_addr == bip_get_broadcast_addr()) @@ -1179,9 +1179,8 @@ int bvlc_send_pdu( /* mac_len = 0 is a broadcast address */ /* net = 0 indicates local, net = 65535 indicates global */ /* net > 0 and net < 65535 are network specific broadcast if len = 0 */ - if ((dest->net == BACNET_BROADCAST_NETWORK) || - ((dest->net > 0) && (dest->len == 0)) || - (dest->mac_len == 0)) { + if ((dest->net == BACNET_BROADCAST_NETWORK) || ((dest->net > 0) && + (dest->len == 0)) || (dest->mac_len == 0)) { /* if we are a foreign device */ if (Remote_BBMD.sin_port) { mtu[1] = BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK; diff --git a/bacnet-stack/src/datetime.c b/bacnet-stack/src/datetime.c index 47d6b8bd..63131d00 100644 --- a/bacnet-stack/src/datetime.c +++ b/bacnet-stack/src/datetime.c @@ -87,7 +87,7 @@ static bool date_is_valid( uint8_t month, uint8_t day) { - bool status = false; /* true if value date */ + bool status = false; /* true if value date */ uint8_t monthdays; /* days in a month */ @@ -193,16 +193,17 @@ static bool time_is_valid( * @return true if the date and time are valid */ bool datetime_is_valid( - BACNET_DATE *bdate, - BACNET_TIME *btime) + BACNET_DATE * bdate, + BACNET_TIME * btime) { - bool status = false; /* return value */ + bool status = false; /* return value */ /* get the number of days in the month, and check for valid month too */ if (bdate) { status = date_is_valid(bdate->year, bdate->month, bdate->day); if (status && btime) { - status = time_is_valid(btime->hour, btime->min, btime->sec, + status = + time_is_valid(btime->hour, btime->min, btime->sec, btime->hundredths); } else { status = false; diff --git a/bacnet-stack/src/event.c b/bacnet-stack/src/event.c index 2d519864..8c3fa642 100644 --- a/bacnet-stack/src/event.c +++ b/bacnet-stack/src/event.c @@ -192,14 +192,14 @@ int event_notify_encode_service_request( len = encode_context_bitstring(&apdu[apdu_len], 0, - &data->notificationParams.changeOfBitstring. - referencedBitString); + &data->notificationParams. + changeOfBitstring.referencedBitString); apdu_len += len; len = encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams.changeOfBitstring. - statusFlags); + &data->notificationParams. + changeOfBitstring.statusFlags); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 0); @@ -223,8 +223,8 @@ int event_notify_encode_service_request( len = encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams.changeOfState. - statusFlags); + &data->notificationParams. + changeOfState.statusFlags); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 1); @@ -242,8 +242,8 @@ int event_notify_encode_service_request( case CHANGE_OF_VALUE_REAL: len = encode_context_real(&apdu[apdu_len], 1, - data->notificationParams.changeOfValue. - newValue.changeValue); + data->notificationParams. + changeOfValue.newValue.changeValue); apdu_len += len; break; @@ -251,8 +251,8 @@ int event_notify_encode_service_request( len = encode_context_bitstring(&apdu[apdu_len], 0, - &data->notificationParams.changeOfValue. - newValue.changedBits); + &data->notificationParams. + changeOfValue.newValue.changedBits); apdu_len += len; break; @@ -265,8 +265,8 @@ int event_notify_encode_service_request( len = encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams.changeOfValue. - statusFlags); + &data->notificationParams. + changeOfValue.statusFlags); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 2); @@ -280,20 +280,20 @@ int event_notify_encode_service_request( len = encode_context_real(&apdu[apdu_len], 0, - data->notificationParams.floatingLimit. - referenceValue); + data->notificationParams. + floatingLimit.referenceValue); apdu_len += len; len = encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams.floatingLimit. - statusFlags); + &data->notificationParams. + floatingLimit.statusFlags); apdu_len += len; len = encode_context_real(&apdu[apdu_len], 2, - data->notificationParams.floatingLimit. - setPointValue); + data->notificationParams. + floatingLimit.setPointValue); apdu_len += len; len = @@ -312,8 +312,8 @@ int event_notify_encode_service_request( len = encode_context_real(&apdu[apdu_len], 0, - data->notificationParams.outOfRange. - exceedingValue); + data->notificationParams. + outOfRange.exceedingValue); apdu_len += len; len = @@ -341,26 +341,26 @@ int event_notify_encode_service_request( len = encode_context_enumerated(&apdu[apdu_len], 0, - data->notificationParams.changeOfLifeSafety. - newState); + data->notificationParams. + changeOfLifeSafety.newState); apdu_len += len; len = encode_context_enumerated(&apdu[apdu_len], 1, - data->notificationParams.changeOfLifeSafety. - newMode); + data->notificationParams. + changeOfLifeSafety.newMode); apdu_len += len; len = encode_context_bitstring(&apdu[apdu_len], 2, - &data->notificationParams.changeOfLifeSafety. - statusFlags); + &data->notificationParams. + changeOfLifeSafety.statusFlags); apdu_len += len; len = encode_context_enumerated(&apdu[apdu_len], 3, - data->notificationParams.changeOfLifeSafety. - operationExpected); + data->notificationParams. + changeOfLifeSafety.operationExpected); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 8); @@ -374,20 +374,20 @@ int event_notify_encode_service_request( len = bacapp_encode_context_device_obj_property_ref(&apdu [apdu_len], 0, - &data->notificationParams.bufferReady. - bufferProperty); + &data->notificationParams. + bufferReady.bufferProperty); apdu_len += len; len = encode_context_unsigned(&apdu[apdu_len], 1, - data->notificationParams.bufferReady. - previousNotification); + data->notificationParams. + bufferReady.previousNotification); apdu_len += len; len = encode_context_unsigned(&apdu[apdu_len], 2, - data->notificationParams.bufferReady. - currentNotification); + data->notificationParams. + bufferReady.currentNotification); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 10); @@ -399,20 +399,20 @@ int event_notify_encode_service_request( len = encode_context_unsigned(&apdu[apdu_len], 0, - data->notificationParams.unsignedRange. - exceedingValue); + data->notificationParams. + unsignedRange.exceedingValue); apdu_len += len; len = encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams.unsignedRange. - statusFlags); + &data->notificationParams. + unsignedRange.statusFlags); apdu_len += len; len = encode_context_unsigned(&apdu[apdu_len], 2, - data->notificationParams.unsignedRange. - exceededLimit); + data->notificationParams. + unsignedRange.exceededLimit); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 11); @@ -595,16 +595,18 @@ int event_notify_decode_service_request( case EVENT_CHANGE_OF_BITSTRING: if (-1 == (section_length = decode_context_bitstring(&apdu[len], 0, - &data->notificationParams. - changeOfBitstring.referencedBitString))) { + &data-> + notificationParams.changeOfBitstring. + referencedBitString))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_bitstring(&apdu[len], 1, - &data->notificationParams. - changeOfBitstring.statusFlags))) { + &data-> + notificationParams.changeOfBitstring. + statusFlags))) { return -1; } len += section_length; @@ -615,16 +617,16 @@ int event_notify_decode_service_request( if (-1 == (section_length = bacapp_decode_context_property_state(&apdu [len], 0, - &data->notificationParams.changeOfState. - newState))) { + &data->notificationParams. + changeOfState.newState))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_bitstring(&apdu[len], 1, - &data->notificationParams.changeOfState. - statusFlags))) { + &data->notificationParams. + changeOfState.statusFlags))) { return -1; } len += section_length; @@ -642,8 +644,9 @@ int event_notify_decode_service_request( if (-1 == (section_length = decode_context_bitstring(&apdu[len], 0, - &data->notificationParams. - changeOfValue.newValue.changedBits))) { + &data-> + notificationParams.changeOfValue. + newValue.changedBits))) { return -1; } @@ -654,8 +657,9 @@ int event_notify_decode_service_request( CHANGE_OF_VALUE_REAL)) { if (-1 == (section_length = decode_context_real(&apdu[len], 1, - &data->notificationParams. - changeOfValue.newValue.changeValue))) { + &data-> + notificationParams.changeOfValue. + newValue.changeValue))) { return -1; } @@ -673,8 +677,8 @@ int event_notify_decode_service_request( if (-1 == (section_length = decode_context_bitstring(&apdu[len], 1, - &data->notificationParams.changeOfValue. - statusFlags))) { + &data->notificationParams. + changeOfValue.statusFlags))) { return -1; } len += section_length; @@ -683,31 +687,31 @@ int event_notify_decode_service_request( case EVENT_FLOATING_LIMIT: if (-1 == (section_length = decode_context_real(&apdu[len], 0, - &data->notificationParams.floatingLimit. - referenceValue))) { + &data->notificationParams. + floatingLimit.referenceValue))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_bitstring(&apdu[len], 1, - &data->notificationParams.floatingLimit. - statusFlags))) { + &data->notificationParams. + floatingLimit.statusFlags))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_real(&apdu[len], 2, - &data->notificationParams.floatingLimit. - setPointValue))) { + &data->notificationParams. + floatingLimit.setPointValue))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_real(&apdu[len], 3, - &data->notificationParams.floatingLimit. - errorLimit))) { + &data->notificationParams. + floatingLimit.errorLimit))) { return -1; } len += section_length; @@ -716,31 +720,31 @@ int event_notify_decode_service_request( case EVENT_OUT_OF_RANGE: if (-1 == (section_length = decode_context_real(&apdu[len], 0, - &data->notificationParams.outOfRange. - exceedingValue))) { + &data->notificationParams. + outOfRange.exceedingValue))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_bitstring(&apdu[len], 1, - &data->notificationParams.outOfRange. - statusFlags))) { + &data->notificationParams. + outOfRange.statusFlags))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_real(&apdu[len], 2, - &data->notificationParams.outOfRange. - deadband))) { + &data->notificationParams. + outOfRange.deadband))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_real(&apdu[len], 3, - &data->notificationParams.outOfRange. - exceededLimit))) { + &data->notificationParams. + outOfRange.exceededLimit))) { return -1; } len += section_length; @@ -768,8 +772,9 @@ int event_notify_decode_service_request( if (-1 == (section_length = decode_context_bitstring(&apdu[len], 2, - &data->notificationParams. - changeOfLifeSafety.statusFlags))) { + &data-> + notificationParams.changeOfLifeSafety. + statusFlags))) { return -1; } len += section_length; @@ -779,8 +784,8 @@ int event_notify_decode_service_request( &value))) { return -1; } - data->notificationParams.changeOfLifeSafety. - operationExpected = + data->notificationParams. + changeOfLifeSafety.operationExpected = (BACNET_LIFE_SAFETY_OPERATION) value; len += section_length; break; @@ -789,24 +794,24 @@ int event_notify_decode_service_request( if (-1 == (section_length = bacapp_decode_context_device_obj_property_ref (&apdu[len], 0, - &data->notificationParams.bufferReady. - bufferProperty))) { + &data->notificationParams. + bufferReady.bufferProperty))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_unsigned(&apdu[len], 1, - &data->notificationParams.bufferReady. - previousNotification))) { + &data->notificationParams. + bufferReady.previousNotification))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_unsigned(&apdu[len], 2, - &data->notificationParams.bufferReady. - currentNotification))) { + &data->notificationParams. + bufferReady.currentNotification))) { return -1; } len += section_length; @@ -815,24 +820,24 @@ int event_notify_decode_service_request( case EVENT_UNSIGNED_RANGE: if (-1 == (section_length = decode_context_unsigned(&apdu[len], 0, - &data->notificationParams.unsignedRange. - exceedingValue))) { + &data->notificationParams. + unsignedRange.exceedingValue))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_bitstring(&apdu[len], 1, - &data->notificationParams.unsignedRange. - statusFlags))) { + &data->notificationParams. + unsignedRange.statusFlags))) { return -1; } len += section_length; if (-1 == (section_length = decode_context_unsigned(&apdu[len], 2, - &data->notificationParams.unsignedRange. - exceededLimit))) { + &data->notificationParams. + unsignedRange.exceededLimit))) { return -1; } len += section_length; @@ -1078,16 +1083,16 @@ void testEventEventState( data.eventType = EVENT_CHANGE_OF_BITSTRING; - bitstring_init(&data.notificationParams.changeOfBitstring. - referencedBitString); - bitstring_set_bit(&data.notificationParams.changeOfBitstring. - referencedBitString, 0, true); - bitstring_set_bit(&data.notificationParams.changeOfBitstring. - referencedBitString, 1, false); - bitstring_set_bit(&data.notificationParams.changeOfBitstring. - referencedBitString, 2, true); - bitstring_set_bit(&data.notificationParams.changeOfBitstring. - referencedBitString, 2, false); + bitstring_init(&data.notificationParams. + changeOfBitstring.referencedBitString); + bitstring_set_bit(&data.notificationParams. + changeOfBitstring.referencedBitString, 0, true); + bitstring_set_bit(&data.notificationParams. + changeOfBitstring.referencedBitString, 1, false); + bitstring_set_bit(&data.notificationParams. + changeOfBitstring.referencedBitString, 2, true); + bitstring_set_bit(&data.notificationParams. + changeOfBitstring.referencedBitString, 2, false); bitstring_init(&data.notificationParams.changeOfBitstring.statusFlags); @@ -1111,8 +1116,8 @@ void testEventEventState( testBaseEventState(pTest); ct_test(pTest, - bitstring_same(&data.notificationParams. - changeOfBitstring.referencedBitString, + bitstring_same(&data.notificationParams.changeOfBitstring. + referencedBitString, &data2.notificationParams.changeOfBitstring.referencedBitString)); ct_test(pTest, @@ -1175,16 +1180,16 @@ void testEventEventState( data.notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_BITS; - bitstring_init(&data.notificationParams.changeOfValue.newValue. - changedBits); - bitstring_set_bit(&data.notificationParams.changeOfValue.newValue. - changedBits, 0, true); - bitstring_set_bit(&data.notificationParams.changeOfValue.newValue. - changedBits, 1, false); - bitstring_set_bit(&data.notificationParams.changeOfValue.newValue. - changedBits, 2, false); - bitstring_set_bit(&data.notificationParams.changeOfValue.newValue. - changedBits, 3, false); + bitstring_init(&data.notificationParams.changeOfValue. + newValue.changedBits); + bitstring_set_bit(&data.notificationParams.changeOfValue. + newValue.changedBits, 0, true); + bitstring_set_bit(&data.notificationParams.changeOfValue. + newValue.changedBits, 1, false); + bitstring_set_bit(&data.notificationParams.changeOfValue. + newValue.changedBits, 2, false); + bitstring_set_bit(&data.notificationParams.changeOfValue. + newValue.changedBits, 3, false); memset(buffer, 0, MAX_APDU); inLen = event_notify_encode_service_request(&buffer[0], &data); @@ -1205,8 +1210,8 @@ void testEventEventState( data2.notificationParams.changeOfValue.tag); ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfValue. - newValue.changedBits, + bitstring_same(&data.notificationParams.changeOfValue.newValue. + changedBits, &data2.notificationParams.changeOfValue.newValue.changedBits)); /**********************************************************************************/ @@ -1429,12 +1434,12 @@ void testEventEventState( data.notificationParams.bufferReady.currentNotification = 2345; data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.type = OBJECT_DEVICE; - data.notificationParams.bufferReady.bufferProperty.deviceIndentifier. - instance = 500; + data.notificationParams.bufferReady.bufferProperty. + deviceIndentifier.instance = 500; data.notificationParams.bufferReady.bufferProperty.objectIdentifier.type = OBJECT_ANALOG_INPUT; - data.notificationParams.bufferReady.bufferProperty.objectIdentifier. - instance = 100; + data.notificationParams.bufferReady.bufferProperty. + objectIdentifier.instance = 100; data.notificationParams.bufferReady.bufferProperty.propertyIdentifier = PROP_PRESENT_VALUE; data.notificationParams.bufferReady.bufferProperty.arrayIndex = 0; @@ -1459,34 +1464,34 @@ void testEventEventState( ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.deviceIndentifier. - type == - data2.notificationParams.bufferReady.bufferProperty.deviceIndentifier. - type); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.deviceIndentifier. - instance == - data2.notificationParams.bufferReady.bufferProperty.deviceIndentifier. - instance); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.objectIdentifier. - instance == - data2.notificationParams.bufferReady.bufferProperty.objectIdentifier. - instance); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.objectIdentifier. - type == - data2.notificationParams.bufferReady.bufferProperty.objectIdentifier. - type); + data.notificationParams.bufferReady.bufferProperty. + deviceIndentifier.type == + data2.notificationParams.bufferReady.bufferProperty. + deviceIndentifier.type); ct_test(pTest, data.notificationParams.bufferReady.bufferProperty. - propertyIdentifier == + deviceIndentifier.instance == data2.notificationParams.bufferReady.bufferProperty. - propertyIdentifier); + deviceIndentifier.instance); + + ct_test(pTest, + data.notificationParams.bufferReady.bufferProperty. + objectIdentifier.instance == + data2.notificationParams.bufferReady.bufferProperty. + objectIdentifier.instance); + + ct_test(pTest, + data.notificationParams.bufferReady.bufferProperty. + objectIdentifier.type == + data2.notificationParams.bufferReady.bufferProperty. + objectIdentifier.type); + + ct_test(pTest, + data.notificationParams.bufferReady. + bufferProperty.propertyIdentifier == + data2.notificationParams.bufferReady. + bufferProperty.propertyIdentifier); ct_test(pTest, data.notificationParams.bufferReady.bufferProperty.arrayIndex == diff --git a/bacnet-stack/src/fifo.c b/bacnet-stack/src/fifo.c index 6c9d2707..2ac10eff 100755 --- a/bacnet-stack/src/fifo.c +++ b/bacnet-stack/src/fifo.c @@ -101,7 +101,8 @@ * * @return Number of bytes in the FIFO */ -unsigned FIFO_Count(FIFO_BUFFER const *b) +unsigned FIFO_Count( + FIFO_BUFFER const *b) { unsigned head, tail; /* used to avoid volatile decision */ @@ -121,7 +122,8 @@ unsigned FIFO_Count(FIFO_BUFFER const *b) * * @return true if the FIFO is full, false if it is not. */ -bool FIFO_Full(FIFO_BUFFER const *b) +bool FIFO_Full( + FIFO_BUFFER const *b) { return (b ? (FIFO_Count(b) == b->buffer_len) : true); } @@ -134,7 +136,8 @@ bool FIFO_Full(FIFO_BUFFER const *b) * * @return true if the number of bytes sought is available */ -bool FIFO_Available(FIFO_BUFFER const *b, +bool FIFO_Available( + FIFO_BUFFER const *b, unsigned count) { return (b ? (count <= (b->buffer_len - FIFO_Count(b))) : false); @@ -146,7 +149,8 @@ bool FIFO_Available(FIFO_BUFFER const *b, * @param b - pointer to FIFO_BUFFER structure * @return true if the FIFO is empty, false if it is not. */ -bool FIFO_Empty(FIFO_BUFFER const *b) +bool FIFO_Empty( + FIFO_BUFFER const *b) { return (b ? (FIFO_Count(b) == 0) : true); } @@ -161,7 +165,8 @@ bool FIFO_Empty(FIFO_BUFFER const *b) * * @return byte of data, or zero if nothing in the list */ -uint8_t FIFO_Peek(FIFO_BUFFER const *b) +uint8_t FIFO_Peek( + FIFO_BUFFER const *b) { unsigned index; @@ -183,7 +188,8 @@ uint8_t FIFO_Peek(FIFO_BUFFER const *b) * * @return the data */ -uint8_t FIFO_Get(FIFO_BUFFER * b) +uint8_t FIFO_Get( + FIFO_BUFFER * b) { uint8_t data_byte = 0; unsigned index; @@ -207,7 +213,8 @@ uint8_t FIFO_Get(FIFO_BUFFER * b) * * @return the number of bytes actually pulled from the FIFO */ -unsigned FIFO_Pull(FIFO_BUFFER * b, +unsigned FIFO_Pull( + FIFO_BUFFER * b, uint8_t * buffer, unsigned length) { @@ -246,7 +253,8 @@ unsigned FIFO_Pull(FIFO_BUFFER * b, * * @return true on successful add, false if not added */ -bool FIFO_Put(FIFO_BUFFER * b, +bool FIFO_Put( + FIFO_BUFFER * b, uint8_t data_byte) { bool status = false; /* return value */ @@ -274,7 +282,8 @@ bool FIFO_Put(FIFO_BUFFER * b, * * @return true if space available and added, false if not added */ -bool FIFO_Add(FIFO_BUFFER * b, +bool FIFO_Add( + FIFO_BUFFER * b, uint8_t * buffer, unsigned count) { @@ -303,7 +312,8 @@ bool FIFO_Add(FIFO_BUFFER * b, * * @return none */ -void FIFO_Flush(FIFO_BUFFER * b) +void FIFO_Flush( + FIFO_BUFFER * b) { unsigned head; /* used to avoid volatile decision */ @@ -322,7 +332,8 @@ void FIFO_Flush(FIFO_BUFFER * b) * * @return none */ -void FIFO_Init(FIFO_BUFFER * b, +void FIFO_Init( + FIFO_BUFFER * b, volatile uint8_t * buffer, unsigned buffer_len) { @@ -347,7 +358,8 @@ void FIFO_Init(FIFO_BUFFER * b, * * @param pTest - test tracking pointer */ -void testFIFOBuffer(Test * pTest) +void testFIFOBuffer( + Test * pTest) { /* FIFO data structure */ FIFO_BUFFER test_buffer = { 0 }; @@ -466,7 +478,8 @@ void testFIFOBuffer(Test * pTest) * * @return returns 0 on success, and non-zero on fail. */ -int main(void) +int main( + void) { Test *pTest; bool rc; diff --git a/bacnet-stack/src/get_alarm_sum.c b/bacnet-stack/src/get_alarm_sum.c index 439d4fbf..da14f873 100644 --- a/bacnet-stack/src/get_alarm_sum.c +++ b/bacnet-stack/src/get_alarm_sum.c @@ -126,8 +126,7 @@ int get_alarm_summary_ack_decode_apdu_data( /* tag 0 - Object Identifier */ apdu_len += bacapp_decode_application_data(&apdu[apdu_len], - max_apdu - apdu_len, - &value); + max_apdu - apdu_len, &value); if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { get_alarm_data->objectIdentifier = value.type.Object_Id; } else { @@ -136,18 +135,17 @@ int get_alarm_summary_ack_decode_apdu_data( /* tag 1 - Alarm State */ apdu_len += bacapp_decode_application_data(&apdu[apdu_len], - max_apdu - apdu_len, - &value); - if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED){ - get_alarm_data->alarmState = (BACNET_EVENT_STATE)value.type.Enumerated; + max_apdu - apdu_len, &value); + if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) { + get_alarm_data->alarmState = + (BACNET_EVENT_STATE) value.type.Enumerated; } else { return BACNET_STATUS_ERROR; } /* tag 2 - Acknowledged Transitions */ apdu_len += bacapp_decode_application_data(&apdu[apdu_len], - max_apdu - apdu_len, - &value); + max_apdu - apdu_len, &value); if (value.tag == BACNET_APPLICATION_TAG_BIT_STRING) { get_alarm_data->acknowledgedTransitions = value.type.Bit_String; } else { diff --git a/bacnet-stack/src/mstp.c b/bacnet-stack/src/mstp.c index 7eab6417..c9d145f5 100644 --- a/bacnet-stack/src/mstp.c +++ b/bacnet-stack/src/mstp.c @@ -256,14 +256,14 @@ void MSTP_Receive_Frame_FSM( mstptext_receive_state(mstp_port->receive_state), mstp_port->DataRegister, mstp_port->HeaderCRC, mstp_port->Index, mstp_port->EventCount, mstp_port->DataLength, - mstp_port->SilenceTimer((void*)mstp_port)); + mstp_port->SilenceTimer((void *) mstp_port)); switch (mstp_port->receive_state) { /* In the IDLE state, the node waits for the beginning of a frame. */ case MSTP_RECEIVE_STATE_IDLE: /* EatAnError */ if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; - mstp_port->SilenceTimerReset((void*)mstp_port); + mstp_port->SilenceTimerReset((void *) mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); /* wait for the start of a frame. */ } else if (mstp_port->DataAvailable == true) { @@ -279,14 +279,14 @@ void MSTP_Receive_Frame_FSM( /* wait for the start of a frame. */ } mstp_port->DataAvailable = false; - mstp_port->SilenceTimerReset((void*)mstp_port); + mstp_port->SilenceTimerReset((void *) mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); } break; /* In the PREAMBLE state, the node waits for the second octet of the preamble. */ case MSTP_RECEIVE_STATE_PREAMBLE: /* Timeout */ - if (mstp_port->SilenceTimer((void*)mstp_port) > Tframe_abort) { + if (mstp_port->SilenceTimer((void *) mstp_port) > Tframe_abort) { /* a correct preamble has not been received */ /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; @@ -294,7 +294,7 @@ void MSTP_Receive_Frame_FSM( /* Error */ else if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; - mstp_port->SilenceTimerReset((void*)mstp_port); + mstp_port->SilenceTimerReset((void *) mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; @@ -317,25 +317,26 @@ void MSTP_Receive_Frame_FSM( mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } mstp_port->DataAvailable = false; - mstp_port->SilenceTimerReset((void*)mstp_port); + mstp_port->SilenceTimerReset((void *) mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); } break; /* In the HEADER state, the node waits for the fixed message header. */ case MSTP_RECEIVE_STATE_HEADER: /* Timeout */ - if (mstp_port->SilenceTimer((void*)mstp_port) > Tframe_abort) { + if (mstp_port->SilenceTimer((void *) mstp_port) > Tframe_abort) { /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; printf_receive_error("MSTP: Rx Header: SilenceTimer %u > %d\n", - (unsigned) mstp_port->SilenceTimer((void*)mstp_port), Tframe_abort); + (unsigned) mstp_port->SilenceTimer((void *) mstp_port), + Tframe_abort); } /* Error */ else if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; - mstp_port->SilenceTimerReset((void*)mstp_port); + mstp_port->SilenceTimerReset((void *) mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; @@ -460,7 +461,7 @@ void MSTP_Receive_Frame_FSM( /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } - mstp_port->SilenceTimerReset((void*)mstp_port); + mstp_port->SilenceTimerReset((void *) mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); mstp_port->DataAvailable = false; } @@ -469,19 +470,20 @@ void MSTP_Receive_Frame_FSM( case MSTP_RECEIVE_STATE_DATA: case MSTP_RECEIVE_STATE_SKIP_DATA: /* Timeout */ - if (mstp_port->SilenceTimer((void*)mstp_port) > Tframe_abort) { + if (mstp_port->SilenceTimer((void *) mstp_port) > Tframe_abort) { /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; printf_receive_error ("MSTP: Rx Data: SilenceTimer %ums > %dms\n", - (unsigned) mstp_port->SilenceTimer((void*)mstp_port), Tframe_abort); + (unsigned) mstp_port->SilenceTimer((void *) mstp_port), + Tframe_abort); /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } /* Error */ else if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; - mstp_port->SilenceTimerReset((void*)mstp_port); + mstp_port->SilenceTimerReset((void *) mstp_port); /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; printf_receive_error("MSTP: Rx Data: ReceiveError\n"); @@ -538,7 +540,7 @@ void MSTP_Receive_Frame_FSM( mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } mstp_port->DataAvailable = false; - mstp_port->SilenceTimerReset((void*)mstp_port); + mstp_port->SilenceTimerReset((void *) mstp_port); } break; default: @@ -590,7 +592,7 @@ bool MSTP_Master_Node_FSM( case MSTP_MASTER_STATE_IDLE: /* In the IDLE state, the node waits for a frame. */ /* LostToken */ - if (mstp_port->SilenceTimer((void*)mstp_port) >= Tno_token) { + if (mstp_port->SilenceTimer((void *) mstp_port) >= Tno_token) { /* assume that the token has been lost */ mstp_port->EventCount = 0; /* Addendum 135-2004d-8 */ mstp_port->master_state = MSTP_MASTER_STATE_NO_TOKEN; @@ -609,7 +611,7 @@ bool MSTP_Master_Node_FSM( "Src=%02X Dest=%02X DataLen=%u " "FC=%u ST=%u Type=%s\n", mstp_port->SourceAddress, mstp_port->DestinationAddress, mstp_port->DataLength, mstp_port->FrameCount, - mstp_port->SilenceTimer((void*)mstp_port), + mstp_port->SilenceTimer((void *) mstp_port), mstptext_frame_type((unsigned) mstp_port->FrameType)); /* destined for me! */ if ((mstp_port->DestinationAddress == mstp_port->This_Station) @@ -720,7 +722,7 @@ bool MSTP_Master_Node_FSM( case MSTP_MASTER_STATE_WAIT_FOR_REPLY: /* In the WAIT_FOR_REPLY state, the node waits for */ /* a reply from another node. */ - if (mstp_port->SilenceTimer((void*)mstp_port) >= Treply_timeout) { + if (mstp_port->SilenceTimer((void *) mstp_port) >= Treply_timeout) { /* ReplyTimeout */ /* assume that the request has failed */ mstp_port->FrameCount = mstp_port->Nmax_info_frames; @@ -867,7 +869,7 @@ bool MSTP_Master_Node_FSM( case MSTP_MASTER_STATE_PASS_TOKEN: /* The PASS_TOKEN state listens for a successor to begin using */ /* the token that this node has just attempted to pass. */ - if (mstp_port->SilenceTimer((void*)mstp_port) <= Tusage_timeout) { + if (mstp_port->SilenceTimer((void *) mstp_port) <= Tusage_timeout) { if (mstp_port->EventCount > Nmin_octets) { /* SawTokenUser */ /* Assume that a frame has been sent by the new token user. */ @@ -912,7 +914,7 @@ bool MSTP_Master_Node_FSM( /* for that period of time. The timeout is continued to determine */ /* whether or not this node may create a token. */ my_timeout = Tno_token + (Tslot * mstp_port->This_Station); - if (mstp_port->SilenceTimer((void*)mstp_port) < my_timeout) { + if (mstp_port->SilenceTimer((void *) mstp_port) < my_timeout) { if (mstp_port->EventCount > Nmin_octets) { /* SawFrame */ /* Some other node exists at a lower address. */ @@ -925,8 +927,9 @@ bool MSTP_Master_Node_FSM( Tno_token + (Tslot * (mstp_port->This_Station + 1)); mm_timeout = Tno_token + (Tslot * (mstp_port->Nmax_master + 1)); - if ((mstp_port->SilenceTimer((void*)mstp_port) < ns_timeout) || - (mstp_port->SilenceTimer((void*)mstp_port) > mm_timeout)) { + if ((mstp_port->SilenceTimer((void *) mstp_port) < ns_timeout) + || (mstp_port->SilenceTimer((void *) mstp_port) > + mm_timeout)) { /* GenerateToken */ /* Assume that this node is the lowest numerical address */ /* on the network and is empowered to create a token. */ @@ -990,7 +993,8 @@ bool MSTP_Master_Node_FSM( transition_now = true; } mstp_port->ReceivedValidFrame = false; - } else if ((mstp_port->SilenceTimer((void*)mstp_port) > Tusage_timeout) || + } else if ((mstp_port->SilenceTimer((void *) mstp_port) > + Tusage_timeout) || (mstp_port->ReceivedInvalidFrame == true)) { if (mstp_port->SoleMaster == true) { /* SoleMaster */ @@ -1059,7 +1063,8 @@ bool MSTP_Master_Node_FSM( mstp_port->master_state = MSTP_MASTER_STATE_IDLE; /* clear our flag we were holding for comparison */ mstp_port->ReceivedValidFrame = false; - } else if (mstp_port->SilenceTimer((void*)mstp_port) > Treply_delay) { + } else if (mstp_port->SilenceTimer((void *) mstp_port) > + Treply_delay) { /* DeferredReply */ /* If no reply will be available from the higher layers */ /* within Treply_delay after the reception of the */ @@ -1088,7 +1093,7 @@ bool MSTP_Master_Node_FSM( mstp_port->This_Station, next_this_station, mstp_port->Next_Station, next_next_station, mstp_port->Poll_Station, next_poll_station, mstp_port->EventCount, - mstp_port->TokenCount, mstp_port->SilenceTimer((void*)mstp_port), + mstp_port->TokenCount, mstp_port->SilenceTimer((void *) mstp_port), mstptext_master_state(mstp_port->master_state)); } @@ -1126,7 +1131,8 @@ void MSTP_Slave_Node_FSM( (uint16_t) length); /* clear our flag we were holding for comparison */ mstp_port->ReceivedValidFrame = false; - } else if (mstp_port->SilenceTimer((void*)mstp_port) > Treply_delay) { + } else if (mstp_port->SilenceTimer((void *) mstp_port) > + Treply_delay) { /* If no reply will be available from the higher layers within Treply_delay after the reception of the final octet of the requesting frame (the mechanism used to determine @@ -1198,7 +1204,7 @@ void MSTP_Init( mstp_port->ReceivedValidFrame = false; mstp_port->ReceivedValidFrameNotForUs = false; mstp_port->RetryCount = 0; - mstp_port->SilenceTimerReset((void*)mstp_port); + mstp_port->SilenceTimerReset((void *) mstp_port); mstp_port->SoleMaster = false; mstp_port->SourceAddress = 0; mstp_port->TokenCount = 0; @@ -1263,7 +1269,7 @@ void RS485_Check_UART_Data( mstp_port->DataRegister = *data; mstp_port->DataAvailable = true; } - (void)Ringbuf_Pop(&Test_Buffer, NULL); + (void) Ringbuf_Pop(&Test_Buffer, NULL); } } diff --git a/bacnet-stack/src/ringbuf.c b/bacnet-stack/src/ringbuf.c index 42b3d88c..b7292b43 100644 --- a/bacnet-stack/src/ringbuf.c +++ b/bacnet-stack/src/ringbuf.c @@ -112,10 +112,10 @@ volatile uint8_t *Ringbuf_Peek( *****************************************************************************/ bool Ringbuf_Pop( RING_BUFFER * b, - uint8_t *data_element) + uint8_t * data_element) { - bool status = false; /* return value */ - volatile uint8_t *ring_data = NULL; /* used to help point ring data */ + bool status = false; /* return value */ + volatile uint8_t *ring_data = NULL; /* used to help point ring data */ unsigned i; /* loop counter */ if (!Ringbuf_Empty(b)) { @@ -141,7 +141,7 @@ bool Ringbuf_Pop( *****************************************************************************/ bool Ringbuf_Put( RING_BUFFER * b, /* ring buffer structure */ - uint8_t *data_element) + uint8_t * data_element) { /* one element to add to the ring */ bool status = false; /* return value */ volatile uint8_t *ring_data = NULL; /* used to help point ring data */ @@ -173,11 +173,11 @@ bool Ringbuf_Put( *****************************************************************************/ bool Ringbuf_Put_Front( RING_BUFFER * b, /* ring buffer structure */ - uint8_t *data_element) + uint8_t * data_element) { /* one element to add to the front of the ring */ bool status = false; /* return value */ - volatile uint8_t *ring_data = NULL; /* used to help point ring data */ - unsigned i = 0; /* loop counter */ + volatile uint8_t *ring_data = NULL; /* used to help point ring data */ + unsigned i = 0; /* loop counter */ if (b && data_element) { /* limit the amount of elements that we accept */ @@ -285,7 +285,7 @@ static void testRingAroundBuffer( ct_test(pTest, test_data[data_index] == dummy); } } - (void)Ringbuf_Pop(test_buffer, NULL); + (void) Ringbuf_Pop(test_buffer, NULL); } } ct_test(pTest, Ringbuf_Empty(test_buffer)); @@ -320,7 +320,7 @@ static void testRingBuf( ct_test(pTest, test_data[data_index] == data_element[data_index]); } ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - (void)Ringbuf_Pop(&test_buffer, NULL); + (void) Ringbuf_Pop(&test_buffer, NULL); ct_test(pTest, Ringbuf_Empty(&test_buffer)); /* fill to max */ @@ -351,7 +351,7 @@ static void testRingBuf( ct_test(pTest, test_data[data_index] == index); } } - (void)Ringbuf_Pop(&test_buffer, NULL); + (void) Ringbuf_Pop(&test_buffer, NULL); } ct_test(pTest, Ringbuf_Empty(&test_buffer)); diff --git a/bacnet-stack/src/rp.c b/bacnet-stack/src/rp.c index 347b5f6e..aba1966a 100644 --- a/bacnet-stack/src/rp.c +++ b/bacnet-stack/src/rp.c @@ -59,8 +59,8 @@ int rp_encode_apdu( /* check bounds so that we could create malformed messages for testing */ len = - encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type, - rpdata->object_instance); + encode_context_object_id(&apdu[apdu_len], 0, + rpdata->object_type, rpdata->object_instance); apdu_len += len; } if (rpdata->object_property <= 4194303) { diff --git a/bacnet-stack/src/timesync.c b/bacnet-stack/src/timesync.c index c07c0b7a..2449fccb 100644 --- a/bacnet-stack/src/timesync.c +++ b/bacnet-stack/src/timesync.c @@ -140,7 +140,7 @@ int timesync_decode_service_request( int timesync_encode_timesync_recipients( uint8_t * apdu, unsigned max_apdu, - BACNET_RECIPIENT_LIST *recipient) + BACNET_RECIPIENT_LIST * recipient) { int len = 0; int apdu_len = 0; @@ -150,9 +150,10 @@ int timesync_encode_timesync_recipients( pRecipient = recipient; while (pRecipient != NULL) { if (pRecipient->tag == 0) { - if (max_apdu >= (1+4)) { + if (max_apdu >= (1 + 4)) { /* CHOICE - device [0] BACnetObjectIdentifier */ - len = encode_context_object_id(&apdu[apdu_len], 0, + len = + encode_context_object_id(&apdu[apdu_len], 0, pRecipient->type.device.type, pRecipient->type.device.instance); apdu_len += len; @@ -181,14 +182,15 @@ int timesync_encode_timesync_recipients( octetstring_init(&octet_string, NULL, 0); } else if (pRecipient->type.address.net) { octetstring_init(&octet_string, - &pRecipient->type.address.adr[0], - pRecipient->type.address.len); + &pRecipient->type.address.adr[0], + pRecipient->type.address.len); } else { octetstring_init(&octet_string, - &pRecipient->type.address.mac[0], - pRecipient->type.address.mac_len); + &pRecipient->type.address.mac[0], + pRecipient->type.address.mac_len); } - len = encode_application_octet_string(&apdu[apdu_len], + len = + encode_application_octet_string(&apdu[apdu_len], &octet_string); apdu_len += len; /* CHOICE - address [1] BACnetAddress - closing */ @@ -231,7 +233,7 @@ int timesync_encode_timesync_recipients( int timesync_decode_timesync_recipients( uint8_t * apdu, unsigned max_apdu, - BACNET_RECIPIENT_LIST *recipient) + BACNET_RECIPIENT_LIST * recipient) { int len = 0; int apdu_len = 0; @@ -247,7 +249,8 @@ int timesync_decode_timesync_recipients( /* device [0] BACnetObjectIdentifier */ if (decode_is_context_tag(&apdu[apdu_len], 0)) { pRecipient->tag = 0; - len = decode_context_object_id(&apdu[apdu_len], 0, + len = + decode_context_object_id(&apdu[apdu_len], 0, &pRecipient->type.device.type, &pRecipient->type.device.instance); if (len < 0) { @@ -265,7 +268,9 @@ int timesync_decode_timesync_recipients( if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { return BACNET_STATUS_ABORT; } - len = decode_unsigned(&apdu[apdu_len], len_value_type, &unsigned_value); + len = + decode_unsigned(&apdu[apdu_len], len_value_type, + &unsigned_value); pRecipient->type.address.net = unsigned_value; apdu_len += len; /* mac-address OCTET STRING */ @@ -276,23 +281,18 @@ int timesync_decode_timesync_recipients( if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) { return BACNET_STATUS_ABORT; } - len = decode_octet_string(&apdu[0], len_value_type, - &octet_string); + len = decode_octet_string(&apdu[0], len_value_type, &octet_string); apdu_len += len; if (octetstring_length(&octet_string) == 0) { /* -- A string of length 0 indicates a broadcast */ } else if (pRecipient->type.address.net) { pRecipient->type.address.len = - octetstring_copy_value( - &pRecipient->type.address.adr[0], - sizeof(pRecipient->type.address.adr), - &octet_string); + octetstring_copy_value(&pRecipient->type.address.adr[0], + sizeof(pRecipient->type.address.adr), &octet_string); } else { pRecipient->type.address.mac_len = - octetstring_copy_value( - &pRecipient->type.address.mac[0], - sizeof(pRecipient->type.address.mac), - &octet_string); + octetstring_copy_value(&pRecipient->type.address.mac[0], + sizeof(pRecipient->type.address.mac), &octet_string); } } else { return BACNET_STATUS_ABORT; @@ -311,8 +311,8 @@ int timesync_decode_timesync_recipients( void testTimeSyncRecipientData( Test * pTest, - BACNET_RECIPIENT_LIST *recipient1, - BACNET_RECIPIENT_LIST *recipient2) + BACNET_RECIPIENT_LIST * recipient1, + BACNET_RECIPIENT_LIST * recipient2) { unsigned i = 0; @@ -320,15 +320,13 @@ void testTimeSyncRecipientData( ct_test(pTest, recipient1->tag == recipient2->tag); if (recipient1->tag == 0) { ct_test(pTest, - recipient1->type.device.type == - recipient2->type.device.type); + recipient1->type.device.type == recipient2->type.device.type); ct_test(pTest, recipient1->type.device.instance == recipient2->type.device.instance); } else if (recipient1->tag == 1) { ct_test(pTest, - recipient1->type.address.net == - recipient2->type.address.net); + recipient1->type.address.net == recipient2->type.address.net); if (recipient1->type.address.net == BACNET_BROADCAST_NETWORK) { ct_test(pTest, recipient1->type.address.mac_len == @@ -400,12 +398,14 @@ void testTimeSyncRecipient( recipient[2].type.address.mac[5] = 0xC1; recipient[2].type.address.mac_len = 6; /* perform positive test */ - len = timesync_encode_timesync_recipients(&apdu[0], - sizeof(apdu), &recipient[0]); + len = + timesync_encode_timesync_recipients(&apdu[0], sizeof(apdu), + &recipient[0]); ct_test(pTest, len != BACNET_STATUS_ABORT); ct_test(pTest, len > 0); - len = timesync_decode_timesync_recipients(&apdu[0], - sizeof(apdu), &test_recipient[0]); + len = + timesync_decode_timesync_recipients(&apdu[0], sizeof(apdu), + &test_recipient[0]); ct_test(pTest, len != BACNET_STATUS_ABORT); ct_test(pTest, len > 0); testTimeSyncRecipientData(pTest, &recipient[0], &test_recipient[0]);