From 3e1cb1847ff58004c7e4980a05844fd92b0f11b6 Mon Sep 17 00:00:00 2001 From: skarg Date: Wed, 17 Aug 2011 02:27:11 +0000 Subject: [PATCH] Indented project. --- bacnet-stack/demo/dcc/main.c | 2 +- bacnet-stack/demo/epics/main.c | 12 +- bacnet-stack/demo/gateway/main.c | 2 +- bacnet-stack/demo/handler/h_alarm_ack.c | 36 +- bacnet-stack/demo/handler/h_cov.c | 30 +- bacnet-stack/demo/handler/h_getevent.c | 20 +- bacnet-stack/demo/handler/h_rp.c | 2 +- bacnet-stack/demo/handler/h_rpm.c | 15 +- bacnet-stack/demo/handler/h_rpm_a.c | 12 +- bacnet-stack/demo/handler/h_ucov.c | 4 +- bacnet-stack/demo/handler/h_whohas.c | 7 +- bacnet-stack/demo/handler/h_wp.c | 4 +- bacnet-stack/demo/handler/h_wpm.c | 101 +- bacnet-stack/demo/handler/s_ihave.c | 2 +- bacnet-stack/demo/handler/s_wp.c | 5 +- bacnet-stack/demo/mstpcap/main.c | 61 +- bacnet-stack/demo/object/ai.c | 495 ++--- bacnet-stack/demo/object/ai.h | 33 +- bacnet-stack/demo/object/ao.c | 18 +- bacnet-stack/demo/object/ao.h | 2 +- bacnet-stack/demo/object/av.c | 493 ++--- bacnet-stack/demo/object/av.h | 32 +- bacnet-stack/demo/object/bacfile.c | 18 +- bacnet-stack/demo/object/bacfile.h | 2 +- bacnet-stack/demo/object/bi.c | 18 +- bacnet-stack/demo/object/bi.h | 2 +- bacnet-stack/demo/object/bo.c | 18 +- bacnet-stack/demo/object/bo.h | 2 +- bacnet-stack/demo/object/bv.c | 18 +- bacnet-stack/demo/object/bv.h | 2 +- bacnet-stack/demo/object/device.c | 170 +- bacnet-stack/demo/object/device.h | 26 +- bacnet-stack/demo/object/gw_device.c | 19 +- bacnet-stack/demo/object/lc.c | 2 +- bacnet-stack/demo/object/lc.h | 2 +- bacnet-stack/demo/object/lo.c | 24 +- bacnet-stack/demo/object/lsp.c | 21 +- bacnet-stack/demo/object/lsp.h | 2 +- bacnet-stack/demo/object/ms-input.c | 29 +- bacnet-stack/demo/object/ms-input.h | 2 +- bacnet-stack/demo/object/mso.c | 33 +- bacnet-stack/demo/object/mso.h | 2 +- bacnet-stack/demo/object/nc.c | 1818 +++++++++-------- bacnet-stack/demo/object/nc.h | 99 +- bacnet-stack/demo/object/trendlog.c | 16 +- bacnet-stack/demo/object/trendlog.h | 2 +- bacnet-stack/demo/ptransfer/main.c | 2 +- bacnet-stack/demo/readfile/main.c | 2 +- bacnet-stack/demo/readprop/main.c | 2 +- bacnet-stack/demo/readpropm/main.c | 2 +- bacnet-stack/demo/readrange/main.c | 2 +- bacnet-stack/demo/reinit/main.c | 2 +- bacnet-stack/demo/server/main.c | 4 +- bacnet-stack/demo/timesync/main.c | 2 +- bacnet-stack/demo/ucov/main.c | 2 +- bacnet-stack/demo/whohas/main.c | 2 +- bacnet-stack/demo/whois/main.c | 2 +- bacnet-stack/demo/writefile/main.c | 2 +- bacnet-stack/demo/writeprop/main.c | 2 +- bacnet-stack/include/bacenum.h | 2 +- bacnet-stack/include/client.h | 2 +- bacnet-stack/include/datalink.h | 2 +- bacnet-stack/include/dcc.h | 4 +- bacnet-stack/include/event.h | 4 +- bacnet-stack/include/readrange.h | 2 +- bacnet-stack/include/rp.h | 2 +- bacnet-stack/include/whohas.h | 2 +- bacnet-stack/include/wpm.h | 25 +- bacnet-stack/ports/at91sam7s/ai.c | 2 +- bacnet-stack/ports/at91sam7s/av.c | 6 +- bacnet-stack/ports/at91sam7s/bi.c | 2 +- bacnet-stack/ports/at91sam7s/bv.c | 6 +- bacnet-stack/ports/at91sam7s/device.c | 81 +- bacnet-stack/ports/at91sam7s/dlmstp.c | 6 +- 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/adc-block.c | 23 +- bacnet-stack/ports/bdk-atxx4-mstp/ai.c | 2 +- bacnet-stack/ports/bdk-atxx4-mstp/av.c | 2 +- bacnet-stack/ports/bdk-atxx4-mstp/bi.c | 2 +- bacnet-stack/ports/bdk-atxx4-mstp/bname.c | 115 +- bacnet-stack/ports/bdk-atxx4-mstp/bname.h | 18 +- bacnet-stack/ports/bdk-atxx4-mstp/bo.c | 6 +- bacnet-stack/ports/bdk-atxx4-mstp/device.c | 61 +- bacnet-stack/ports/linux/dlmstp.c | 83 +- bacnet-stack/ports/linux/rs485.c | 32 +- bacnet-stack/ports/pic18f6720/av.c | 4 +- bacnet-stack/ports/pic18f6720/bv.c | 4 +- bacnet-stack/ports/pic18f6720/device.c | 4 +- bacnet-stack/ports/rtos32/bip-init.c | 3 +- bacnet-stack/ports/rx62n/bo.c | 4 +- bacnet-stack/ports/rx62n/device.c | 18 +- bacnet-stack/ports/rx62n/ethernet.c | 4 +- bacnet-stack/ports/rx62n/led.c | 50 +- bacnet-stack/ports/rx62n/main.c | 3 +- bacnet-stack/ports/rx62n/timer-hdw.c | 18 +- bacnet-stack/ports/stm32f10x/automac.c | 96 +- bacnet-stack/ports/stm32f10x/automac.h | 49 +- bacnet-stack/ports/stm32f10x/bo.c | 6 +- bacnet-stack/ports/stm32f10x/device.c | 29 +- bacnet-stack/ports/stm32f10x/dlmstp.c | 102 +- bacnet-stack/ports/stm32f10x/led.c | 18 +- bacnet-stack/ports/stm32f10x/led.h | 30 +- bacnet-stack/ports/stm32f10x/main.c | 96 +- bacnet-stack/ports/stm32f10x/rs485.c | 41 +- bacnet-stack/ports/stm32f10x/rs485.h | 12 +- bacnet-stack/ports/stm32f10x/stm32f10x_conf.h | 10 +- bacnet-stack/ports/stm32f10x/stm32f10x_it.c | 52 +- bacnet-stack/ports/stm32f10x/stm32f10x_it.h | 24 +- .../ports/stm32f10x/system_stm32f10x.c | 1316 ++++++------ bacnet-stack/ports/stm32f10x/timer_sys.c | 12 +- bacnet-stack/ports/win32/main.c | 4 +- bacnet-stack/ports/win32/timer.c | 21 +- bacnet-stack/src/address.c | 6 +- bacnet-stack/src/bacapp.c | 24 +- bacnet-stack/src/bacdcode.c | 3 +- bacnet-stack/src/bacpropstates.c | 3 +- bacnet-stack/src/bacstr.c | 83 +- bacnet-stack/src/bactext.c | 2 +- bacnet-stack/src/bvlc.c | 4 +- bacnet-stack/src/event.c | 335 +-- bacnet-stack/src/ptransfer.c | 3 +- bacnet-stack/src/ringbuf.c | 18 +- bacnet-stack/src/wpm.c | 123 +- 125 files changed, 3548 insertions(+), 3353 deletions(-) diff --git a/bacnet-stack/demo/dcc/main.c b/bacnet-stack/demo/dcc/main.c index d57ec35b..d2266801 100644 --- a/bacnet-stack/demo/dcc/main.c +++ b/bacnet-stack/demo/dcc/main.c @@ -55,7 +55,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/epics/main.c b/bacnet-stack/demo/epics/main.c index f35296bf..f8e81062 100644 --- a/bacnet-stack/demo/epics/main.c +++ b/bacnet-stack/demo/epics/main.c @@ -66,7 +66,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ @@ -840,7 +840,7 @@ int CheckCommandLineArgs( if (++i < argc) { #if defined(BACDL_BIP) My_BIP_Port = (uint16_t) strtol(argv[i], NULL, 0); - /* Used strtol so sport can be either 0xBAC0 or 47808 */ + /* Used strtol so sport can be either 0xBAC0 or 47808 */ #endif } break; @@ -1172,11 +1172,11 @@ int main( (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(invoke_id)) { invoke_id = 0; } else { diff --git a/bacnet-stack/demo/gateway/main.c b/bacnet-stack/demo/gateway/main.c index 56abfaf1..6244b465 100644 --- a/bacnet-stack/demo/gateway/main.c +++ b/bacnet-stack/demo/gateway/main.c @@ -101,7 +101,7 @@ static object_functions_t Object_Table[] = { {FILE_OBJ_FUNCTIONS}, #endif {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /** Buffer used for receiving */ diff --git a/bacnet-stack/demo/handler/h_alarm_ack.c b/bacnet-stack/demo/handler/h_alarm_ack.c index cf09825b..55487d25 100644 --- a/bacnet-stack/demo/handler/h_alarm_ack.c +++ b/bacnet-stack/demo/handler/h_alarm_ack.c @@ -119,7 +119,6 @@ void handler_alarm_ack( #endif goto AA_ABORT; } - #if PRINT_ENABLED fprintf(stderr, "Alarm Ack Operation: Received acknowledge for object id (%d, %lu) from %s for process id %lu \n", @@ -131,49 +130,54 @@ void handler_alarm_ack( if (Alarm_Ack[data.eventObjectIdentifier.type]) { - ack_result = Alarm_Ack[data.eventObjectIdentifier.type](&data, &error_code); + ack_result = + Alarm_Ack[data.eventObjectIdentifier.type] (&data, &error_code); - switch (ack_result) - { + switch (ack_result) { case 1: - len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM); + len = + encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM); #if PRINT_ENABLED fprintf(stderr, "Alarm Acknowledge: " "Sending Simple Ack!\n"); #endif break; case -1: - len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, - ERROR_CLASS_OBJECT, error_code); + len = + bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, + error_code); #if PRINT_ENABLED fprintf(stderr, "Alarm Acknowledge: error %s!\n", - bactext_error_code_name(error_code)); + bactext_error_code_name(error_code)); #endif break; default: - len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + len = + abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); #if PRINT_ENABLED fprintf(stderr, "Alarm Acknowledge: abort other!\n"); #endif break; } - } - else { - len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + } else { + len = + bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, ERROR_CODE_NO_ALARM_CONFIGURED); #if PRINT_ENABLED fprintf(stderr, "Alarm Acknowledge: error %s!\n", - bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED)); + bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED)); #endif } -AA_ABORT: + AA_ABORT: pdu_len += len; bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], diff --git a/bacnet-stack/demo/handler/h_cov.c b/bacnet-stack/demo/handler/h_cov.c index 1b022adc..56f054ab 100644 --- a/bacnet-stack/demo/handler/h_cov.c +++ b/bacnet-stack/demo/handler/h_cov.c @@ -419,32 +419,31 @@ void handler_cov_task( COV_Subscriptions[index].monitoredObjectIdentifier.type; object_instance = COV_Subscriptions[index].monitoredObjectIdentifier.instance; - status = Device_Encode_Value_List( - object_type, - object_instance, + status = + Device_Encode_Value_List(object_type, object_instance, &value_list[0]); if (status) { COV_Subscriptions[index].send_requested = true; } if (COV_Subscriptions[index].send_requested) { - cov_send_request( - &COV_Subscriptions[index], - &value_list[0]); + cov_send_request(&COV_Subscriptions[index], &value_list[0]); COV_Subscriptions[index].send_requested = false; } - if (status && ((index+1) < MAX_COV_SUBCRIPTIONS)) { + if (status && ((index + 1) < MAX_COV_SUBCRIPTIONS)) { /* if more than one subscription for this object instance */ - for (index2 = index+1; index2 < MAX_COV_SUBCRIPTIONS; index2++) { + for (index2 = index + 1; index2 < MAX_COV_SUBCRIPTIONS; + index2++) { object_type2 = - COV_Subscriptions[index2].monitoredObjectIdentifier.type; + COV_Subscriptions[index2].monitoredObjectIdentifier. + type; object_instance2 = - COV_Subscriptions[index2].monitoredObjectIdentifier.instance; + COV_Subscriptions[index2].monitoredObjectIdentifier. + instance; if ((COV_Subscriptions[index].lifetime) && (COV_Subscriptions[index].valid) && (object_type == object_type2) && (object_instance == object_instance2)) { - cov_send_request( - &COV_Subscriptions[index2], + cov_send_request(&COV_Subscriptions[index2], &value_list[0]); COV_Subscriptions[index2].send_requested = false; } @@ -470,11 +469,8 @@ static bool cov_subscribe( if (status) { status = Device_Value_List_Supported(object_type); if (status) { - status = cov_list_subscribe( - src, - cov_data, - error_class, - error_code); + status = + cov_list_subscribe(src, cov_data, error_class, error_code); } else { *error_class = ERROR_CLASS_OBJECT; *error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; diff --git a/bacnet-stack/demo/handler/h_getevent.c b/bacnet-stack/demo/handler/h_getevent.c index eaf4fb37..37840a03 100644 --- a/bacnet-stack/demo/handler/h_getevent.c +++ b/bacnet-stack/demo/handler/h_getevent.c @@ -59,7 +59,7 @@ void handler_get_event_information( BACNET_CONFIRMED_SERVICE_DATA * service_data) { int len = 0; - int pdu_len = 0; + int pdu_len = 0; int apdu_len = 0; BACNET_NPDU_DATA npdu_data; bool error = false; @@ -116,8 +116,8 @@ void handler_get_event_information( error = true; goto GET_EVENT_ERROR; } - pdu_len += len; - apdu_len = len; + pdu_len += len; + apdu_len = len; for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) { if (Get_Event_Info[i]) { for (j = 0; j < 0xffff; j++) { @@ -125,8 +125,10 @@ void handler_get_event_information( if (valid_event > 0) { /* encode GetEvent_data only when type of object_id has max value */ if (object_id.type != MAX_BACNET_OBJECT_TYPE) { - if ((object_id.type == getevent_data.objectIdentifier.type) && - (object_id.instance == getevent_data.objectIdentifier.instance)) { + if ((object_id.type == + getevent_data.objectIdentifier.type) && + (object_id.instance == + getevent_data.objectIdentifier.instance)) { /* found 'Last Received Object Identifier' so should set type of object_id to max value */ object_id.type = MAX_BACNET_OBJECT_TYPE; @@ -147,16 +149,14 @@ void handler_get_event_information( if (apdu_len >= service_data->max_resp - 2) { /* Device must be able to fit minimum one event information. Length of one event informations needs more than 50 octets. */ - if (service_data->max_resp < 128){ + if (service_data->max_resp < 128) { len = BACNET_STATUS_ABORT; error = true; goto GET_EVENT_ERROR; - } - else + } else more_events = true; break; - } - else + } else pdu_len += len; } else if (valid_event < 0) { break; diff --git a/bacnet-stack/demo/handler/h_rp.c b/bacnet-stack/demo/handler/h_rp.c index 870b2b00..07c57df8 100644 --- a/bacnet-stack/demo/handler/h_rp.c +++ b/bacnet-stack/demo/handler/h_rp.c @@ -128,7 +128,7 @@ void handler_read_property( /* too big for the sender - send an abort * Setting of error code needed here as read property processing may * have overriden the default set at start */ - rpdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; + rpdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; len = BACNET_STATUS_ABORT; #if PRINT_ENABLED fprintf(stderr, "RP: Message too large.\n"); diff --git a/bacnet-stack/demo/handler/h_rpm.c b/bacnet-stack/demo/handler/h_rpm.c index 6954ff7e..fdc0df20 100644 --- a/bacnet-stack/demo/handler/h_rpm.c +++ b/bacnet-stack/demo/handler/h_rpm.c @@ -319,9 +319,8 @@ void handler_read_property_multiple( if (property_count == 0) { /* handle the error code - but use the special property */ len = - RPM_Encode_Property( - &Handler_Transmit_Buffer[npdu_len], - (uint16_t) apdu_len, MAX_APDU, + RPM_Encode_Property(&Handler_Transmit_Buffer + [npdu_len], (uint16_t) apdu_len, MAX_APDU, &rpmdata); if (len > 0) { apdu_len += len; @@ -335,10 +334,9 @@ void handler_read_property_multiple( RPM_Object_Property(&property_list, special_object_property, index); len = - RPM_Encode_Property( - &Handler_Transmit_Buffer[npdu_len], - (uint16_t) apdu_len, - MAX_APDU, &rpmdata); + RPM_Encode_Property(&Handler_Transmit_Buffer + [npdu_len], (uint16_t) apdu_len, MAX_APDU, + &rpmdata); if (len > 0) { apdu_len += len; } else { @@ -352,8 +350,7 @@ void handler_read_property_multiple( /* handle an individual property */ len = RPM_Encode_Property(&Handler_Transmit_Buffer[npdu_len], - (uint16_t) apdu_len, - MAX_APDU, &rpmdata); + (uint16_t) apdu_len, MAX_APDU, &rpmdata); if (len > 0) { apdu_len += len; } else { diff --git a/bacnet-stack/demo/handler/h_rpm_a.c b/bacnet-stack/demo/handler/h_rpm_a.c index cfa53799..b150d86e 100644 --- a/bacnet-stack/demo/handler/h_rpm_a.c +++ b/bacnet-stack/demo/handler/h_rpm_a.c @@ -220,8 +220,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); @@ -268,10 +268,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 83d4727d..30ea436e 100644 --- a/bacnet-stack/demo/handler/h_whohas.c +++ b/bacnet-stack/demo/handler/h_whohas.c @@ -64,10 +64,9 @@ static void match_name_or_object( } } else { /* valid object_name copy in my device? */ - found = Device_Object_Name_Copy( - data->object.identifier.type, - data->object.identifier.instance, - &object_name); + found = + Device_Object_Name_Copy(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_wp.c b/bacnet-stack/demo/handler/h_wp.c index 95f9be7f..ca2f12fd 100644 --- a/bacnet-stack/demo/handler/h_wp.c +++ b/bacnet-stack/demo/handler/h_wp.c @@ -181,8 +181,8 @@ bool WPValidateString( (!characterstring_printable(&pValue->type.Character_String))) { /* assumption: non-empty also means must be "printable" */ *pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE; - } else if (characterstring_length(&pValue->type. - Character_String) >= iMaxLen) { + } else if (characterstring_length(&pValue-> + type.Character_String) >= iMaxLen) { *pErrorClass = ERROR_CLASS_RESOURCES; *pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; } else diff --git a/bacnet-stack/demo/handler/h_wpm.c b/bacnet-stack/demo/handler/h_wpm.c index 7538e462..f5c7d270 100644 --- a/bacnet-stack/demo/handler/h_wpm.c +++ b/bacnet-stack/demo/handler/h_wpm.c @@ -70,10 +70,10 @@ void handler_write_property_multiple( BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data) { - int len = 0; - int apdu_len = 0; - int npdu_len = 0; - int pdu_len = 0; + int len = 0; + int apdu_len = 0; + int npdu_len = 0; + int pdu_len = 0; int decode_len = 0; bool error = false; BACNET_WRITE_PROPERTY_DATA wp_data; @@ -84,9 +84,10 @@ void handler_write_property_multiple( if (service_data->segmented_message) { - len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, - ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); + len = + abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], + service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, + true); #if PRINT_ENABLED fprintf(stderr, "WPM: Segmented message. Sending Abort!\n"); #endif @@ -95,27 +96,25 @@ void handler_write_property_multiple( /* decode service request */ decode_len = 0; - do - { + do { /* decode Object Identifier */ - len = wpm_decode_object_id(&service_request[decode_len], - service_len - decode_len, &wp_data); - if (len > 0) - { + len = + wpm_decode_object_id(&service_request[decode_len], + service_len - decode_len, &wp_data); + if (len > 0) { uint8_t tag_number = 0; decode_len += len; /* Opening tag 1 - List of Properties */ - if (decode_is_opening_tag_number(&service_request[decode_len++], 1)) - { - do - { + if (decode_is_opening_tag_number(&service_request[decode_len++], + 1)) { + do { /* decode a 'Property Identifier'; (3) an optional 'Property Array Index' */ /* (4) a 'Property Value'; and (5) an optional 'Priority'. */ - len = wpm_decode_object_property(&service_request[decode_len], - service_len - decode_len, &wp_data); - if (len > 0) - { + len = + wpm_decode_object_property(&service_request + [decode_len], service_len - decode_len, &wp_data); + if (len > 0) { decode_len += len; #if PRINT_ENABLED fprintf(stderr, @@ -123,81 +122,79 @@ void handler_write_property_multiple( (unsigned long) wp_data.object_type, (unsigned long) wp_data.object_instance, (unsigned long) wp_data.object_property, - (unsigned long) wp_data.priority, (long) wp_data.array_index); + (unsigned long) wp_data.priority, + (long) wp_data.array_index); #endif - if (Device_Write_Property(&wp_data) == false) - { + if (Device_Write_Property(&wp_data) == false) { error = true; - break; /* do while (decoding List of Properties) */ + break; /* do while (decoding List of Properties) */ } - } - else - { + } else { #if PRINT_ENABLED fprintf(stderr, "WPM: Bad Encoding!\n"); #endif wp_data.error_class = ERROR_CLASS_PROPERTY; - wp_data.error_code = ERROR_CODE_OTHER; + wp_data.error_code = ERROR_CODE_OTHER; error = true; break; /* do while (decoding List of Properties) */ } /* Closing tag 1 - List of Properties */ - if (decode_is_closing_tag_number(&service_request[decode_len], 1)) - { + if (decode_is_closing_tag_number(&service_request + [decode_len], 1)) { tag_number = 1; decode_len++; - } - else + } else tag_number = 0; /* it was not tag 1, decode next Property Identifier ... */ } - while(tag_number != 1); /* end decoding List of Properties for "that" object */ + while (tag_number != 1); /* end decoding List of Properties for "that" object */ if (error) - break; /*do while (decode service request) */ + break; /*do while (decode service request) */ } - } - else - { + } else { #if PRINT_ENABLED fprintf(stderr, "WPM: Bad Encoding!\n"); #endif wp_data.error_class = ERROR_CLASS_OBJECT; - wp_data.error_code = ERROR_CODE_OTHER; + wp_data.error_code = ERROR_CODE_OTHER; error = true; - break; /*do while (decode service request) */ + break; /*do while (decode service request) */ } } - while(decode_len < service_len); + while (decode_len < service_len); /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + npdu_len = + npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); apdu_len = 0; if (error == false) { - apdu_len = wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id); + apdu_len = + wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], + service_data->invoke_id); #if PRINT_ENABLED fprintf(stderr, "WPM: Sending Simple Ack!\n"); #endif - } - else { - apdu_len = wpm_error_ack_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, &wp_data); + } else { + 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 } -WPM_ABORT: + WPM_ABORT: pdu_len = npdu_len + apdu_len; - bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = + datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); } diff --git a/bacnet-stack/demo/handler/s_ihave.c b/bacnet-stack/demo/handler/s_ihave.c index 4361d5e7..d0dd256d 100644 --- a/bacnet-stack/demo/handler/s_ihave.c +++ b/bacnet-stack/demo/handler/s_ihave.c @@ -57,7 +57,7 @@ void Send_I_Have( uint32_t device_id, BACNET_OBJECT_TYPE object_type, uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { int len = 0; int pdu_len = 0; diff --git a/bacnet-stack/demo/handler/s_wp.c b/bacnet-stack/demo/handler/s_wp.c index 1b66e13b..d6e46192 100644 --- a/bacnet-stack/demo/handler/s_wp.c +++ b/bacnet-stack/demo/handler/s_wp.c @@ -155,8 +155,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 d32314db..f1188943 100644 --- a/bacnet-stack/demo/mstpcap/main.c +++ b/bacnet-stack/demo/mstpcap/main.c @@ -172,7 +172,8 @@ static void packet_statistics( break; case FRAME_TYPE_POLL_FOR_MASTER: if (MSTP_Statistics[src].last_pfm_tokens) { - npoll = MSTP_Statistics[src].token_received_count - + npoll = + MSTP_Statistics[src].token_received_count - MSTP_Statistics[src].last_pfm_tokens; if (npoll > MSTP_Statistics[src].npoll) { MSTP_Statistics[src].npoll = npoll; @@ -252,10 +253,8 @@ static void packet_statistics_print( fprintf(stdout, "\r\n"); fprintf(stdout, "==== MS/TP Frame Counts ====\r\n"); - fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s", - "MAC", - "Tokens","PFM","RPFM","DER", - "Postpd","DNER","TestReq","TestRsp"); + fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s", "MAC", "Tokens", + "PFM", "RPFM", "DER", "Postpd", "DNER", "TestReq", "TestRsp"); fprintf(stdout, "\r\n"); for (i = 0; i < 256; i++) { /* check for masters or slaves */ @@ -280,9 +279,9 @@ static void packet_statistics_print( node_count = 0; fprintf(stdout, "\r\n"); fprintf(stdout, "==== MS/TP Usage and Timing Maximums ====\r\n"); - fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-7s", - "MAC","MaxMstr","Retries","Npoll","Self", - "Treply","Tusage","Trpfm","Tder","Tpostpd"); + fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-7s", "MAC", + "MaxMstr", "Retries", "Npoll", "Self", "Treply", "Tusage", "Trpfm", + "Tder", "Tpostpd"); fprintf(stdout, "\r\n"); for (i = 0; i < 256; i++) { /* check for masters or slaves */ @@ -552,8 +551,8 @@ static void write_received_packet( (void) data_write((char *) &mstp_port->DataCRCActualLSB, 1, 1); } } else { - fprintf(stderr, "mstpcap[packet]: failed to open %s: %s\n", Capture_Filename, - strerror(errno)); + fprintf(stderr, "mstpcap[packet]: failed to open %s: %s\n", + Capture_Filename, strerror(errno)); } } @@ -561,61 +560,61 @@ static void write_received_packet( static bool test_global_header( const char *filename) { - uint32_t magic_number = 0; /* magic number */ + uint32_t magic_number = 0; /* magic number */ uint16_t version_major = 0; /* major version number */ uint16_t version_minor = 0; /* minor version number */ int32_t thiszone = 0; /* GMT to local correction */ uint32_t sigfigs = 0; /* accuracy of timestamps */ - uint32_t snaplen = 0; /* max length of captured packets, in octets */ - uint32_t network = 0; /* data link type - BACNET_MS_TP */ + uint32_t snaplen = 0; /* max length of captured packets, in octets */ + uint32_t network = 0; /* data link type - BACNET_MS_TP */ size_t count = 0; /* create a new file. */ pFile = fopen(filename, "rb"); if (pFile) { - count = fread(&magic_number, sizeof(magic_number), 1, pFile); + count = fread(&magic_number, sizeof(magic_number), 1, pFile); if ((count != 1) || (magic_number != 0xa1b2c3d4)) { fprintf(stderr, "mstpcap: invalid magic number\n"); fclose(pFile); pFile = NULL; return false; } - count = fread(&version_major, sizeof(version_major), 1, pFile); + count = fread(&version_major, sizeof(version_major), 1, pFile); if ((count != 1) || (version_major != 2)) { fprintf(stderr, "mstpcap: invalid major version\n"); fclose(pFile); pFile = NULL; return false; } - count = fread(&version_minor, sizeof(version_minor), 1, pFile); + count = fread(&version_minor, sizeof(version_minor), 1, pFile); if ((count != 1) || (version_minor != 4)) { fprintf(stderr, "mstpcap: invalid minor version\n"); fclose(pFile); pFile = NULL; return false; } - count = fread(&thiszone, sizeof(thiszone), 1, pFile); + count = fread(&thiszone, sizeof(thiszone), 1, pFile); if ((count != 1) || (thiszone != 0)) { fprintf(stderr, "mstpcap: invalid time zone\n"); fclose(pFile); pFile = NULL; return false; } - count = fread(&sigfigs, sizeof(sigfigs), 1, pFile); + count = fread(&sigfigs, sizeof(sigfigs), 1, pFile); if ((count != 1) || (sigfigs != 0)) { fprintf(stderr, "mstpcap: invalid time stamp accuracy\n"); fclose(pFile); pFile = NULL; return false; } - count = fread(&snaplen, sizeof(snaplen), 1, pFile); + count = fread(&snaplen, sizeof(snaplen), 1, pFile); if ((count != 1) || (snaplen != 65535)) { fprintf(stderr, "mstpcap: invalid length of captured packets\n"); fclose(pFile); pFile = NULL; return false; } - count = fread(&network, sizeof(network), 1, pFile); + count = fread(&network, sizeof(network), 1, pFile); if ((count != 1) || (network != 165)) { fprintf(stderr, "mstpcap: invalid data link type (DLT)\n"); fclose(pFile); @@ -634,11 +633,11 @@ static bool test_global_header( static bool read_received_packet( volatile struct mstp_port_struct_t *mstp_port) { - uint32_t ts_sec = 0; /* timestamp seconds */ - uint32_t ts_usec = 0; /* timestamp microseconds */ - uint32_t incl_len = 0; /* number of octets of packet saved in file */ - uint32_t orig_len = 0; /* actual length of packet */ - uint8_t header[8] = {0}; /* MS/TP header */ + uint32_t ts_sec = 0; /* timestamp seconds */ + uint32_t ts_usec = 0; /* timestamp microseconds */ + uint32_t incl_len = 0; /* number of octets of packet saved in file */ + uint32_t orig_len = 0; /* actual length of packet */ + uint8_t header[8] = { 0 }; /* MS/TP header */ struct timeval tv; size_t count = 0; @@ -678,12 +677,12 @@ static bool read_received_packet( mstp_port->FrameType = header[2]; mstp_port->DestinationAddress = header[3]; mstp_port->SourceAddress = header[4]; - mstp_port->DataLength = MAKE_WORD(header[6],header[5]); + mstp_port->DataLength = MAKE_WORD(header[6], header[5]); mstp_port->HeaderCRCActual = header[7]; if (orig_len > 8) { mstp_port->DataLength = orig_len - 8 - 2; - count = fread(mstp_port->InputBuffer, - mstp_port->DataLength, 1, pFile); + count = + fread(mstp_port->InputBuffer, mstp_port->DataLength, 1, pFile); if (count != 1) { fclose(pFile); pFile = NULL; @@ -811,9 +810,9 @@ int main( if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) { printf("mstpcap %s\r\n", BACNET_VERSION_TEXT); printf("Copyright (C) 2011 by Steve Karg\r\n" - "This is free software; see the source for copying conditions.\r\n" - "There is NO warranty; not even for MERCHANTABILITY or\r\n" - "FITNESS FOR A PARTICULAR PURPOSE.\r\n"); + "This is free software; see the source for copying conditions.\r\n" + "There is NO warranty; not even for MERCHANTABILITY or\r\n" + "FITNESS FOR A PARTICULAR PURPOSE.\r\n"); return 0; } if ((argc > 1) && (strcmp(argv[1], "--scan") == 0)) { diff --git a/bacnet-stack/demo/object/ai.c b/bacnet-stack/demo/object/ai.c index e67be315..3d157800 100644 --- a/bacnet-stack/demo/object/ai.c +++ b/bacnet-stack/demo/object/ai.c @@ -108,7 +108,7 @@ void Analog_Input_Init( unsigned i, j; for (i = 0; i < MAX_ANALOG_INPUTS; i++) { - AI_Descr[i].Present_Value = 0.0f; + AI_Descr[i].Present_Value = 0.0f; AI_Descr[i].Out_Of_Service = false; AI_Descr[i].Units = UNITS_PERCENT; AI_Descr[i].Reliability = RELIABILITY_NO_FAULT_DETECTED; @@ -127,8 +127,7 @@ void Analog_Input_Init( handler_get_event_information_set(OBJECT_ANALOG_INPUT, Analog_Input_Event_Information); /* Set handler for AcknowledgeAlarm function */ - handler_alarm_ack_set(OBJECT_ANALOG_INPUT, - Analog_Input_Alarm_Ack); + handler_alarm_ack_set(OBJECT_ANALOG_INPUT, Analog_Input_Alarm_Ack); #endif } } @@ -207,7 +206,7 @@ void Analog_Input_Present_Value_Set( bool Analog_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ unsigned int index; @@ -277,50 +276,61 @@ int Analog_Input_Read_Property( bitstring_init(&bit_string); #if defined(INTRINSIC_REPORTING) bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, - CurrentAI->Event_State ? true : false); + CurrentAI->Event_State ? true : false); #else bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); #endif bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, CurrentAI->Out_Of_Service); + bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, + CurrentAI->Out_Of_Service); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_STATE: #if defined(INTRINSIC_REPORTING) - apdu_len = encode_application_enumerated(&apdu[0], - CurrentAI->Event_State); + apdu_len = + encode_application_enumerated(&apdu[0], + CurrentAI->Event_State); #else - apdu_len = encode_application_enumerated(&apdu[0], - EVENT_STATE_NORMAL); + apdu_len = + encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); #endif break; case PROP_RELIABILITY: - apdu_len = encode_application_enumerated(&apdu[0], CurrentAI->Reliability); + apdu_len = + encode_application_enumerated(&apdu[0], + CurrentAI->Reliability); break; case PROP_OUT_OF_SERVICE: - apdu_len = encode_application_boolean(&apdu[0], CurrentAI->Out_Of_Service); + apdu_len = + encode_application_boolean(&apdu[0], + CurrentAI->Out_Of_Service); break; case PROP_UNITS: - apdu_len = encode_application_enumerated(&apdu[0], CurrentAI->Units); + apdu_len = + encode_application_enumerated(&apdu[0], CurrentAI->Units); break; #if defined(INTRINSIC_REPORTING) case PROP_TIME_DELAY: - apdu_len = encode_application_unsigned(&apdu[0], CurrentAI->Time_Delay); + apdu_len = + encode_application_unsigned(&apdu[0], CurrentAI->Time_Delay); break; case PROP_NOTIFICATION_CLASS: - apdu_len = encode_application_unsigned(&apdu[0], CurrentAI->Notification_Class); + apdu_len = + encode_application_unsigned(&apdu[0], + CurrentAI->Notification_Class); break; case PROP_HIGH_LIMIT: - apdu_len = encode_application_real(&apdu[0], CurrentAI->High_Limit); + apdu_len = + encode_application_real(&apdu[0], CurrentAI->High_Limit); break; case PROP_LOW_LIMIT: @@ -334,21 +344,26 @@ 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); + apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; 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; @@ -356,62 +371,69 @@ 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); + CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, - CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); + CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_NOTIFY_TYPE: - apdu_len = encode_application_enumerated(&apdu[0], - CurrentAI->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); + apdu_len = + encode_application_enumerated(&apdu[0], + CurrentAI->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); break; case PROP_EVENT_TIME_STAMPS: /* Array element zero is the number of elements in the array */ if (rpdata->array_index == 0) - apdu_len = encode_application_unsigned(&apdu[0], - MAX_BACNET_EVENT_TRANSITION); + apdu_len = + encode_application_unsigned(&apdu[0], + MAX_BACNET_EVENT_TRANSITION); /* if no index was specified, then try to encode the entire list */ /* into one packet. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {; - len = encode_opening_tag(&apdu[apdu_len], - TIME_STAMP_DATETIME); - len += encode_application_date(&apdu[apdu_len + len], - &CurrentAI->Event_Time_Stamps[i].date); - len += encode_application_time(&apdu[apdu_len + len], - &CurrentAI->Event_Time_Stamps[i].time); - len += encode_closing_tag(&apdu[apdu_len + len], - TIME_STAMP_DATETIME); + len = + encode_opening_tag(&apdu[apdu_len], + TIME_STAMP_DATETIME); + len += + encode_application_date(&apdu[apdu_len + len], + &CurrentAI->Event_Time_Stamps[i].date); + len += + encode_application_time(&apdu[apdu_len + len], + &CurrentAI->Event_Time_Stamps[i].time); + len += + encode_closing_tag(&apdu[apdu_len + len], + TIME_STAMP_DATETIME); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) apdu_len += len; else { rpdata->error_class = ERROR_CLASS_SERVICES; - rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; + rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; apdu_len = BACNET_STATUS_ERROR; break; } } - } - else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { - apdu_len = encode_opening_tag(&apdu[apdu_len], - TIME_STAMP_DATETIME); - apdu_len += encode_application_date(&apdu[apdu_len], - &CurrentAI->Event_Time_Stamps[rpdata->array_index].date); - apdu_len += encode_application_time(&apdu[apdu_len], - &CurrentAI->Event_Time_Stamps[rpdata->array_index].time); - apdu_len += encode_closing_tag(&apdu[apdu_len], - TIME_STAMP_DATETIME); - } - else { + } else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { + apdu_len = + encode_opening_tag(&apdu[apdu_len], TIME_STAMP_DATETIME); + apdu_len += + encode_application_date(&apdu[apdu_len], + &CurrentAI->Event_Time_Stamps[rpdata->array_index].date); + apdu_len += + encode_application_time(&apdu[apdu_len], + &CurrentAI->Event_Time_Stamps[rpdata->array_index].time); + apdu_len += + encode_closing_tag(&apdu[apdu_len], TIME_STAMP_DATETIME); + } else { rpdata->error_class = ERROR_CLASS_PROPERTY; - rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; + rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; apdu_len = BACNET_STATUS_ERROR; } break; @@ -436,11 +458,10 @@ int Analog_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->object_property != PROP_EVENT_TIME_STAMPS) && - (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->object_property != PROP_EVENT_TIME_STAMPS) + && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; - rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; + rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; } @@ -449,7 +470,7 @@ int Analog_Input_Read_Property( /* returns true if successful */ bool Analog_Input_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) + BACNET_WRITE_PROPERTY_DATA * wp_data) { bool status = false; /* return value */ unsigned int object_index = 0; @@ -465,7 +486,7 @@ bool Analog_Input_Write_Property( if (len < 0) { /* error while decoding - a value larger than we can handle */ 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; return false; } @@ -484,11 +505,10 @@ bool Analog_Input_Write_Property( if (status) { if (CurrentAI->Out_Of_Service == true) { Analog_Input_Present_Value_Set(wp_data->object_instance, - value.type.Real); - } - else { + value.type.Real); + } else { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; status = false; } } @@ -570,13 +590,12 @@ bool Analog_Input_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { - if(value.type.Bit_String.bits_used == 2) { + if (value.type.Bit_String.bits_used == 2) { CurrentAI->Limit_Enable = value.type.Bit_String.value[0]; - } - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; - status = false; + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + status = false; } } break; @@ -587,13 +606,12 @@ bool Analog_Input_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { - if(value.type.Bit_String.bits_used == 3) { + if (value.type.Bit_String.bits_used == 3) { CurrentAI->Event_Enable = value.type.Bit_String.value[0]; - } - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; - status = false; + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + status = false; } } break; @@ -604,13 +622,12 @@ bool Analog_Input_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { - if(value.type.Bit_String.bits_used > NOTIFY_EVENT) { + if (value.type.Bit_String.bits_used > NOTIFY_EVENT) { CurrentAI->Event_Enable = value.type.Enumerated; - } - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; - status = false; + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + status = false; } } break; @@ -618,7 +635,7 @@ bool Analog_Input_Write_Property( default: wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; } @@ -626,7 +643,8 @@ bool Analog_Input_Write_Property( } -void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) +void Analog_Input_Intrinsic_Reporting( + uint32_t object_instance) { #if defined(INTRINSIC_REPORTING) BACNET_EVENT_NOTIFICATION_DATA event_data; @@ -637,7 +655,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) uint8_t ToState; float ExceededLimit = 0.0f; float PresentVal = 0.0f; - bool SendNotify = false; + bool SendNotify = false; object_index = Analog_Input_Instance_To_Index(object_instance); @@ -648,7 +666,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) /* check limits */ if (!CurrentAI->Limit_Enable) - return; /* limits are not configured */ + return; /* limits are not configured */ if (CurrentAI->Ack_notify_data.bSendAckNotify) { @@ -659,8 +677,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) #if PRINT_ENABLED fprintf(stderr, "Send Acknotification for (%s,%d).\n", - bactext_object_type_name(OBJECT_ANALOG_INPUT), - object_instance); + bactext_object_type_name(OBJECT_ANALOG_INPUT), object_instance); #endif /* PRINT_ENABLED */ characterstring_init_ansi(&msgText, "AckNotification"); @@ -670,25 +687,23 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) /* Send EventNotification. */ SendNotify = true; - } - else - { + } else { /* actual Present_Value */ PresentVal = Analog_Input_Present_Value(object_instance); - FromState = CurrentAI->Event_State; - switch (CurrentAI->Event_State) - { + FromState = CurrentAI->Event_State; + switch (CurrentAI->Event_State) { case EVENT_STATE_NORMAL: /* A TO-OFFNORMAL event is generated under these conditions: - (a) the Present_Value must exceed the High_Limit for a minimum - period of time, specified in the Time_Delay property, and - (b) the HighLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ + (a) the Present_Value must exceed the High_Limit for a minimum + period of time, specified in the Time_Delay property, and + (b) the HighLimitEnable flag must be set in the Limit_Enable property, and + (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ if ((PresentVal > CurrentAI->High_Limit) && - ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && - ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) - { - if(!CurrentAI->Remaining_Time_Delay) + ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == + EVENT_HIGH_LIMIT_ENABLE) && + ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == + EVENT_ENABLE_TO_OFFNORMAL)) { + if (!CurrentAI->Remaining_Time_Delay) CurrentAI->Event_State = EVENT_STATE_HIGH_LIMIT; else CurrentAI->Remaining_Time_Delay--; @@ -696,15 +711,16 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) } /* A TO-OFFNORMAL event is generated under these conditions: - (a) the Present_Value must exceed the Low_Limit plus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the LowLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ + (a) the Present_Value must exceed the Low_Limit plus the Deadband + for a minimum period of time, specified in the Time_Delay property, and + (b) the LowLimitEnable flag must be set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable property. */ if ((PresentVal < CurrentAI->Low_Limit) && - ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && - ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) - { - if(!CurrentAI->Remaining_Time_Delay) + ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == + EVENT_LOW_LIMIT_ENABLE) && + ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == + EVENT_ENABLE_TO_OFFNORMAL)) { + if (!CurrentAI->Remaining_Time_Delay) CurrentAI->Event_State = EVENT_STATE_LOW_LIMIT; else CurrentAI->Remaining_Time_Delay--; @@ -717,15 +733,16 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) case EVENT_STATE_HIGH_LIMIT: /* Once exceeded, the Present_Value must fall below the High_Limit minus the Deadband before a TO-NORMAL event is generated under these conditions: - (a) the Present_Value must fall below the High_Limit minus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the HighLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal < CurrentAI->High_Limit - CurrentAI->Deadband) && - ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && - ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) - { - if(!CurrentAI->Remaining_Time_Delay) + (a) the Present_Value must fall below the High_Limit minus the Deadband + for a minimum period of time, specified in the Time_Delay property, and + (b) the HighLimitEnable flag must be set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable property. */ + if ((PresentVal < CurrentAI->High_Limit - CurrentAI->Deadband) + && ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == + EVENT_HIGH_LIMIT_ENABLE) && + ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == + EVENT_ENABLE_TO_NORMAL)) { + if (!CurrentAI->Remaining_Time_Delay) CurrentAI->Event_State = EVENT_STATE_NORMAL; else CurrentAI->Remaining_Time_Delay--; @@ -739,15 +756,16 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) /* Once the Present_Value has fallen below the Low_Limit, the Present_Value must exceed the Low_Limit plus the Deadband before a TO-NORMAL event is generated under these conditions: - (a) the Present_Value must exceed the Low_Limit plus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the LowLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal > CurrentAI->Low_Limit + CurrentAI->Deadband) && - ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && - ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) - { - if(!CurrentAI->Remaining_Time_Delay) + (a) the Present_Value must exceed the Low_Limit plus the Deadband + for a minimum period of time, specified in the Time_Delay property, and + (b) the LowLimitEnable flag must be set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable property. */ + if ((PresentVal > CurrentAI->Low_Limit + CurrentAI->Deadband) + && ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == + EVENT_LOW_LIMIT_ENABLE) && + ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == + EVENT_ENABLE_TO_NORMAL)) { + if (!CurrentAI->Remaining_Time_Delay) CurrentAI->Event_State = EVENT_STATE_NORMAL; else CurrentAI->Remaining_Time_Delay--; @@ -758,41 +776,36 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) break; default: - return; /* shouldn't happen */ - } /* switch (FromState) */ + return; /* shouldn't happen */ + } /* switch (FromState) */ ToState = CurrentAI->Event_State; - if (FromState != ToState) - { + if (FromState != ToState) { /* Event_State has changed. Need to fill only the basic parameters of this type of event. Other parameters will be filled in common function. */ - switch (ToState) - { + switch (ToState) { case EVENT_STATE_HIGH_LIMIT: ExceededLimit = CurrentAI->High_Limit; - characterstring_init_ansi(&msgText, - "Goes to high limit"); + characterstring_init_ansi(&msgText, "Goes to high limit"); break; case EVENT_STATE_LOW_LIMIT: ExceededLimit = CurrentAI->Low_Limit; - characterstring_init_ansi(&msgText, - "Goes to low limit"); + characterstring_init_ansi(&msgText, "Goes to low limit"); break; case EVENT_STATE_NORMAL: - if(FromState == EVENT_STATE_HIGH_LIMIT) { + if (FromState == EVENT_STATE_HIGH_LIMIT) { ExceededLimit = CurrentAI->High_Limit; characterstring_init_ansi(&msgText, - "Back to normal state from high limit"); - } - else { + "Back to normal state from high limit"); + } else { ExceededLimit = CurrentAI->Low_Limit; characterstring_init_ansi(&msgText, - "Back to normal state from low limit"); + "Back to normal state from low limit"); } break; @@ -803,9 +816,9 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) #if PRINT_ENABLED fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n", - bactext_object_type_name(OBJECT_ANALOG_INPUT), - object_instance, bactext_event_state_name(FromState), - bactext_event_state_name(ToState)); + bactext_object_type_name(OBJECT_ANALOG_INPUT), object_instance, + bactext_event_state_name(FromState), + bactext_event_state_name(ToState)); #endif /* PRINT_ENABLED */ /* Notify Type */ @@ -817,8 +830,7 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) } - if (SendNotify) - { + if (SendNotify) { /* Event Object Identifier */ event_data.eventObjectIdentifier.type = OBJECT_ANALOG_INPUT; event_data.eventObjectIdentifier.instance = object_instance; @@ -829,22 +841,21 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { /* fill Event_Time_Stamps */ - switch (ToState) - { + switch (ToState) { case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: CurrentAI->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] = - event_data.timeStamp.value.dateTime; + event_data.timeStamp.value.dateTime; break; case EVENT_STATE_FAULT: CurrentAI->Event_Time_Stamps[TRANSITION_TO_FAULT] = - event_data.timeStamp.value.dateTime; + event_data.timeStamp.value.dateTime; break; case EVENT_STATE_NORMAL: CurrentAI->Event_Time_Stamps[TRANSITION_TO_NORMAL] = - event_data.timeStamp.value.dateTime; + event_data.timeStamp.value.dateTime; break; } } @@ -871,50 +882,57 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) /* Event Values */ if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { /* Value that exceeded a limit. */ - event_data.notificationParams.outOfRange.exceedingValue = PresentVal; + 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, 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, CurrentAI->Out_Of_Service); + 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, + CurrentAI->Out_Of_Service); /* Deadband used for limit checking. */ - event_data.notificationParams.outOfRange.deadband = CurrentAI->Deadband; + event_data.notificationParams.outOfRange.deadband = + CurrentAI->Deadband; /* Limit that was exceeded. */ - event_data.notificationParams.outOfRange.exceededLimit = ExceededLimit; + event_data.notificationParams.outOfRange.exceededLimit = + ExceededLimit; } /* add data from notification class */ Notification_Class_common_reporting_function(&event_data); /* Ack required */ - if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && - (event_data.ackRequired == true)) - { - switch (event_data.toState) - { + if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && + (event_data.ackRequired == true)) { + switch (event_data.toState) { 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; } } @@ -924,12 +942,13 @@ void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) #if defined(INTRINSIC_REPORTING) -int Analog_Input_Event_Information(unsigned index, - BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) +int Analog_Input_Event_Information( + unsigned index, + BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) { bool IsNotAckedTransitions; bool IsActiveEvent; - int i; + int i; /* check index */ @@ -939,63 +958,75 @@ int Analog_Input_Event_Information(unsigned index, /* 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); - } - else - return -1; /* end of list */ + 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); + } else + return -1; /* end of list */ if ((IsActiveEvent) || (IsNotAckedTransitions)) { /* Object Identifier */ getevent_data->objectIdentifier.type = OBJECT_ANALOG_INPUT; - getevent_data->objectIdentifier.instance = Analog_Input_Index_To_Instance(index); + getevent_data->objectIdentifier.instance = + Analog_Input_Index_To_Instance(index); /* Event State */ getevent_data->eventState = AI_Descr[index].Event_State; /* Acknowledged Transitions */ bitstring_init(&getevent_data->acknowledgedTransitions); - bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, - 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); - bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, - AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); + bitstring_set_bit(&getevent_data->acknowledgedTransitions, + TRANSITION_TO_OFFNORMAL, + 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); + bitstring_set_bit(&getevent_data->acknowledgedTransitions, + TRANSITION_TO_NORMAL, + AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); /* Event Time Stamps */ for (i = 0; i < 3; i++) { getevent_data->eventTimeStamps[i].tag = TIME_STAMP_DATETIME; getevent_data->eventTimeStamps[i].value.dateTime = - AI_Descr[index].Event_Time_Stamps[i]; + AI_Descr[index].Event_Time_Stamps[i]; } /* Notify Type */ getevent_data->notifyType = AI_Descr[index].Notify_Type; /* 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); + getevent_data->eventPriorities); - return 1; /* active event */ - } - else - return 0; /* no active event at this index */ + return 1; /* active event */ + } else + return 0; /* no active event at this index */ } -int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, - BACNET_ERROR_CODE * error_code) +int Analog_Input_Alarm_Ack( + BACNET_ALARM_ACK_DATA * alarmack_data, + BACNET_ERROR_CODE * error_code) { ANALOG_INPUT_DESCR *CurrentAI; unsigned int object_index; - object_index = Analog_Input_Instance_To_Index( - alarmack_data->eventObjectIdentifier.instance); + object_index = + Analog_Input_Instance_To_Index(alarmack_data->eventObjectIdentifier. + instance); if (object_index < MAX_ANALOG_INPUTS) CurrentAI = &AI_Descr[object_index]; @@ -1004,71 +1035,73 @@ int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, return -1; } - switch (alarmack_data->eventStateAcked) - { + switch (alarmack_data->eventStateAcked) { case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - if(CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { - if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ + 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, - &alarmack_data->eventTimeStamp.value.dateTime) > 0) - { + 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; - } - else { + CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked = true; + } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; } break; case EVENT_STATE_FAULT: - if(CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false) { - if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ + if (CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].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_NORMAL].Time_Stamp, - &alarmack_data->eventTimeStamp.value.dateTime) > 0) - { + 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; } /* FIXME: Send ack notification */ - CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = true; - } - else { + CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = + true; + } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; } break; case EVENT_STATE_NORMAL: - if(CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) { - if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ + if (CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].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_FAULT].Time_Stamp, - &alarmack_data->eventTimeStamp.value.dateTime) > 0) - { + 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; } /* FIXME: Send ack notification */ - CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = true; - } - else { + CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = + true; + } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; } diff --git a/bacnet-stack/demo/object/ai.h b/bacnet-stack/demo/object/ai.h index 621d51ab..24adfb3d 100644 --- a/bacnet-stack/demo/object/ai.h +++ b/bacnet-stack/demo/object/ai.h @@ -42,20 +42,20 @@ extern "C" { #endif /* __cplusplus */ typedef struct analog_input_descr { - uint8_t Event_State : 3; - float Present_Value; + uint8_t Event_State:3; + float Present_Value; BACNET_RELIABILITY Reliability; - bool Out_Of_Service; - uint8_t Units; + bool Out_Of_Service; + uint8_t Units; #if defined(INTRINSIC_REPORTING) uint32_t Time_Delay; uint32_t Notification_Class; - float High_Limit; - float Low_Limit; - float Deadband; - uint8_t Limit_Enable : 2; - uint8_t Event_Enable : 3; - uint8_t Notify_Type : 1; + float High_Limit; + float Low_Limit; + float Deadband; + uint8_t Limit_Enable:2; + uint8_t Event_Enable:3; + uint8_t Notify_Type:1; ACKED_INFO Acked_Transitions[MAX_BACNET_EVENT_TRANSITION]; BACNET_DATE_TIME Event_Time_Stamps[MAX_BACNET_EVENT_TRANSITION]; /* time to generate event notification */ @@ -83,7 +83,7 @@ extern "C" { bool Analog_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); bool Analog_Input_Name_Set( uint32_t object_instance, char *new_name); @@ -112,14 +112,17 @@ extern "C" { float value); /* note: header of Intrinsic_Reporting function is required - even when INTRINSIC_REPORTING is not defined */ - void Analog_Input_Intrinsic_Reporting(uint32_t object_instance); + even when INTRINSIC_REPORTING is not defined */ + void Analog_Input_Intrinsic_Reporting( + uint32_t object_instance); #if defined(INTRINSIC_REPORTING) - int Analog_Input_Event_Information(unsigned index, + int Analog_Input_Event_Information( + unsigned index, BACNET_GET_EVENT_INFORMATION_DATA * getevent_data); - int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, + int Analog_Input_Alarm_Ack( + BACNET_ALARM_ACK_DATA * alarmack_data, BACNET_ERROR_CODE * error_code); #endif diff --git a/bacnet-stack/demo/object/ao.c b/bacnet-stack/demo/object/ao.c index 4b2b7e93..5fc3abed 100644 --- a/bacnet-stack/demo/object/ao.c +++ b/bacnet-stack/demo/object/ao.c @@ -255,7 +255,7 @@ bool Analog_Output_Present_Value_Relinquish( /* note: the object name must be unique within this device */ bool Analog_Output_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ bool status = false; @@ -447,11 +447,11 @@ bool Analog_Output_Write_Property( if (status) { level = AO_LEVEL_NULL; 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; @@ -491,10 +491,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } diff --git a/bacnet-stack/demo/object/ao.h b/bacnet-stack/demo/object/ao.h index 326eab06..b2c2bf9b 100644 --- a/bacnet-stack/demo/object/ao.h +++ b/bacnet-stack/demo/object/ao.h @@ -65,7 +65,7 @@ extern "C" { bool Analog_Output_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); bool Analog_Output_Name_Set( uint32_t object_instance, char *new_name); diff --git a/bacnet-stack/demo/object/av.c b/bacnet-stack/demo/object/av.c index bb49d6ef..9575bda1 100644 --- a/bacnet-stack/demo/object/av.c +++ b/bacnet-stack/demo/object/av.c @@ -133,8 +133,7 @@ void Analog_Value_Init( handler_get_event_information_set(OBJECT_ANALOG_VALUE, Analog_Value_Event_Information); /* Set handler for AcknowledgeAlarm function */ - handler_alarm_ack_set(OBJECT_ANALOG_VALUE, - Analog_Value_Alarm_Ack); + handler_alarm_ack_set(OBJECT_ANALOG_VALUE, Analog_Value_Alarm_Ack); #endif } } @@ -196,8 +195,7 @@ bool Analog_Value_Present_Value_Set( CurrentAV = &AV_Descr[index]; if (priority && (priority <= BACNET_MAX_PRIORITY) && (priority != 6 /* reserved */ ) && - (value >= 0.0) && (value <= 100.0)) - { + (value >= 0.0) && (value <= 100.0)) { CurrentAV->Priority_Array[priority - 1] = (uint8_t) value; /* Note: you could set the physical output here to the next highest priority, or to the relinquish default if no @@ -240,7 +238,7 @@ float Analog_Value_Present_Value( /* note: the object name must be unique within this device */ bool Analog_Value_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ bool status = false; @@ -310,24 +308,26 @@ int Analog_Value_Read_Property( bitstring_init(&bit_string); #if defined(INTRINSIC_REPORTING) bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, - CurrentAV->Event_State ? true : false); + CurrentAV->Event_State ? true : false); #else bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); #endif bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, CurrentAV->Out_Of_Service); + bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, + CurrentAV->Out_Of_Service); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_STATE: #if defined(INTRINSIC_REPORTING) - apdu_len = encode_application_enumerated(&apdu[0], - CurrentAV->Event_State); + apdu_len = + encode_application_enumerated(&apdu[0], + CurrentAV->Event_State); #else - apdu_len = encode_application_enumerated(&apdu[0], - EVENT_STATE_NORMAL); + apdu_len = + encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); #endif break; @@ -337,7 +337,8 @@ int Analog_Value_Read_Property( break; case PROP_UNITS: - apdu_len = encode_application_enumerated(&apdu[0], CurrentAV->Units); + apdu_len = + encode_application_enumerated(&apdu[0], CurrentAV->Units); break; case PROP_PRIORITY_ARRAY: @@ -363,7 +364,7 @@ int Analog_Value_Read_Property( apdu_len += len; else { rpdata->error_class = ERROR_CLASS_SERVICES; - rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; + rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; apdu_len = BACNET_STATUS_ERROR; break; } @@ -371,11 +372,11 @@ int Analog_Value_Read_Property( } else { if (rpdata->array_index <= BACNET_MAX_PRIORITY) { if (CurrentAV->Priority_Array[rpdata->array_index - 1] - == ANALOG_LEVEL_NULL) + == ANALOG_LEVEL_NULL) apdu_len = encode_application_null(&apdu[0]); else { - real_value = CurrentAV->Priority_Array - [rpdata->array_index - 1]; + real_value = + CurrentAV->Priority_Array[rpdata->array_index - 1]; apdu_len = encode_application_real(&apdu[0], real_value); } @@ -394,15 +395,19 @@ int Analog_Value_Read_Property( #if defined(INTRINSIC_REPORTING) case PROP_TIME_DELAY: - apdu_len = encode_application_unsigned(&apdu[0], CurrentAV->Time_Delay); + apdu_len = + encode_application_unsigned(&apdu[0], CurrentAV->Time_Delay); break; case PROP_NOTIFICATION_CLASS: - apdu_len = encode_application_unsigned(&apdu[0], CurrentAV->Notification_Class); + apdu_len = + encode_application_unsigned(&apdu[0], + CurrentAV->Notification_Class); break; case PROP_HIGH_LIMIT: - apdu_len = encode_application_real(&apdu[0], CurrentAV->High_Limit); + apdu_len = + encode_application_real(&apdu[0], CurrentAV->High_Limit); break; case PROP_LOW_LIMIT: @@ -416,21 +421,26 @@ 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); + apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; 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; @@ -438,62 +448,69 @@ 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); + CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, - CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); + CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_NOTIFY_TYPE: - apdu_len = encode_application_enumerated(&apdu[0], - CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); + apdu_len = + encode_application_enumerated(&apdu[0], + CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); break; case PROP_EVENT_TIME_STAMPS: /* Array element zero is the number of elements in the array */ if (rpdata->array_index == 0) - apdu_len = encode_application_unsigned(&apdu[0], - MAX_BACNET_EVENT_TRANSITION); + apdu_len = + encode_application_unsigned(&apdu[0], + MAX_BACNET_EVENT_TRANSITION); /* if no index was specified, then try to encode the entire list */ /* into one packet. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) {; - len = encode_opening_tag(&apdu[apdu_len], - TIME_STAMP_DATETIME); - len += encode_application_date(&apdu[apdu_len + len], - &CurrentAV->Event_Time_Stamps[i].date); - len += encode_application_time(&apdu[apdu_len + len], - &CurrentAV->Event_Time_Stamps[i].time); - len += encode_closing_tag(&apdu[apdu_len + len], - TIME_STAMP_DATETIME); + len = + encode_opening_tag(&apdu[apdu_len], + TIME_STAMP_DATETIME); + len += + encode_application_date(&apdu[apdu_len + len], + &CurrentAV->Event_Time_Stamps[i].date); + len += + encode_application_time(&apdu[apdu_len + len], + &CurrentAV->Event_Time_Stamps[i].time); + len += + encode_closing_tag(&apdu[apdu_len + len], + TIME_STAMP_DATETIME); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) apdu_len += len; else { rpdata->error_class = ERROR_CLASS_SERVICES; - rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; + rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; apdu_len = BACNET_STATUS_ERROR; break; } } - } - else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { - apdu_len = encode_opening_tag(&apdu[apdu_len], - TIME_STAMP_DATETIME); - apdu_len += encode_application_date(&apdu[apdu_len], - &CurrentAV->Event_Time_Stamps[rpdata->array_index].date); - apdu_len += encode_application_time(&apdu[apdu_len], - &CurrentAV->Event_Time_Stamps[rpdata->array_index].time); - apdu_len += encode_closing_tag(&apdu[apdu_len], - TIME_STAMP_DATETIME); - } - else { + } else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { + apdu_len = + encode_opening_tag(&apdu[apdu_len], TIME_STAMP_DATETIME); + apdu_len += + encode_application_date(&apdu[apdu_len], + &CurrentAV->Event_Time_Stamps[rpdata->array_index].date); + apdu_len += + encode_application_time(&apdu[apdu_len], + &CurrentAV->Event_Time_Stamps[rpdata->array_index].time); + apdu_len += + encode_closing_tag(&apdu[apdu_len], TIME_STAMP_DATETIME); + } else { rpdata->error_class = ERROR_CLASS_PROPERTY; - rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; + rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; apdu_len = BACNET_STATUS_ERROR; } break; @@ -501,17 +518,16 @@ int Analog_Value_Read_Property( default: rpdata->error_class = ERROR_CLASS_PROPERTY; - rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; + rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; apdu_len = BACNET_STATUS_ERROR; break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->object_property != PROP_PRIORITY_ARRAY) && + if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) && (rpdata->object_property != PROP_EVENT_TIME_STAMPS) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; - rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; + rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; } @@ -677,13 +693,12 @@ bool Analog_Value_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { - if(value.type.Bit_String.bits_used == 2) { + if (value.type.Bit_String.bits_used == 2) { CurrentAV->Limit_Enable = value.type.Bit_String.value[0]; - } - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; - status = false; + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + status = false; } } break; @@ -694,13 +709,12 @@ bool Analog_Value_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { - if(value.type.Bit_String.bits_used == 3) { + if (value.type.Bit_String.bits_used == 3) { CurrentAV->Event_Enable = value.type.Bit_String.value[0]; - } - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; - status = false; + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + status = false; } } break; @@ -711,13 +725,12 @@ bool Analog_Value_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { - if(value.type.Bit_String.bits_used > NOTIFY_EVENT) { + if (value.type.Bit_String.bits_used > NOTIFY_EVENT) { CurrentAV->Event_Enable = value.type.Enumerated; - } - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; - status = false; + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + status = false; } } break; @@ -725,7 +738,7 @@ bool Analog_Value_Write_Property( default: wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; } @@ -733,7 +746,8 @@ bool Analog_Value_Write_Property( } -void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) +void Analog_Value_Intrinsic_Reporting( + uint32_t object_instance) { #if defined(INTRINSIC_REPORTING) BACNET_EVENT_NOTIFICATION_DATA event_data; @@ -744,7 +758,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) uint8_t ToState; float ExceededLimit = 0.0f; float PresentVal = 0.0f; - bool SendNotify = false; + bool SendNotify = false; object_index = Analog_Value_Instance_To_Index(object_instance); @@ -755,7 +769,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) /* check limits */ if (!CurrentAV->Limit_Enable) - return; /* limits are not configured */ + return; /* limits are not configured */ if (CurrentAV->Ack_notify_data.bSendAckNotify) { @@ -766,8 +780,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) #if PRINT_ENABLED fprintf(stderr, "Send Acknotification for (%s,%d).\n", - bactext_object_type_name(OBJECT_ANALOG_VALUE), - object_instance); + bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance); #endif /* PRINT_ENABLED */ characterstring_init_ansi(&msgText, "AckNotification"); @@ -777,25 +790,23 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) /* Send EventNotification. */ SendNotify = true; - } - else - { + } else { /* actual Present_Value */ PresentVal = Analog_Value_Present_Value(object_instance); - FromState = CurrentAV->Event_State; - switch (CurrentAV->Event_State) - { + FromState = CurrentAV->Event_State; + switch (CurrentAV->Event_State) { case EVENT_STATE_NORMAL: /* A TO-OFFNORMAL event is generated under these conditions: - (a) the Present_Value must exceed the High_Limit for a minimum - period of time, specified in the Time_Delay property, and - (b) the HighLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ + (a) the Present_Value must exceed the High_Limit for a minimum + period of time, specified in the Time_Delay property, and + (b) the HighLimitEnable flag must be set in the Limit_Enable property, and + (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ if ((PresentVal > CurrentAV->High_Limit) && - ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && - ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) - { - if(!CurrentAV->Remaining_Time_Delay) + ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == + EVENT_HIGH_LIMIT_ENABLE) && + ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == + EVENT_ENABLE_TO_OFFNORMAL)) { + if (!CurrentAV->Remaining_Time_Delay) CurrentAV->Event_State = EVENT_STATE_HIGH_LIMIT; else CurrentAV->Remaining_Time_Delay--; @@ -803,15 +814,16 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) } /* A TO-OFFNORMAL event is generated under these conditions: - (a) the Present_Value must exceed the Low_Limit plus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the LowLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ + (a) the Present_Value must exceed the Low_Limit plus the Deadband + for a minimum period of time, specified in the Time_Delay property, and + (b) the LowLimitEnable flag must be set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable property. */ if ((PresentVal < CurrentAV->Low_Limit) && - ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && - ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == EVENT_ENABLE_TO_OFFNORMAL)) - { - if(!CurrentAV->Remaining_Time_Delay) + ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == + EVENT_LOW_LIMIT_ENABLE) && + ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == + EVENT_ENABLE_TO_OFFNORMAL)) { + if (!CurrentAV->Remaining_Time_Delay) CurrentAV->Event_State = EVENT_STATE_LOW_LIMIT; else CurrentAV->Remaining_Time_Delay--; @@ -824,15 +836,16 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) case EVENT_STATE_HIGH_LIMIT: /* Once exceeded, the Present_Value must fall below the High_Limit minus the Deadband before a TO-NORMAL event is generated under these conditions: - (a) the Present_Value must fall below the High_Limit minus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the HighLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal < CurrentAV->High_Limit - CurrentAV->Deadband) && - ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == EVENT_HIGH_LIMIT_ENABLE) && - ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) - { - if(!CurrentAV->Remaining_Time_Delay) + (a) the Present_Value must fall below the High_Limit minus the Deadband + for a minimum period of time, specified in the Time_Delay property, and + (b) the HighLimitEnable flag must be set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable property. */ + if ((PresentVal < CurrentAV->High_Limit - CurrentAV->Deadband) + && ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == + EVENT_HIGH_LIMIT_ENABLE) && + ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == + EVENT_ENABLE_TO_NORMAL)) { + if (!CurrentAV->Remaining_Time_Delay) CurrentAV->Event_State = EVENT_STATE_NORMAL; else CurrentAV->Remaining_Time_Delay--; @@ -846,15 +859,16 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) /* Once the Present_Value has fallen below the Low_Limit, the Present_Value must exceed the Low_Limit plus the Deadband before a TO-NORMAL event is generated under these conditions: - (a) the Present_Value must exceed the Low_Limit plus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the LowLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband) && - ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == EVENT_LOW_LIMIT_ENABLE) && - ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == EVENT_ENABLE_TO_NORMAL)) - { - if(!CurrentAV->Remaining_Time_Delay) + (a) the Present_Value must exceed the Low_Limit plus the Deadband + for a minimum period of time, specified in the Time_Delay property, and + (b) the LowLimitEnable flag must be set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable property. */ + if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband) + && ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == + EVENT_LOW_LIMIT_ENABLE) && + ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == + EVENT_ENABLE_TO_NORMAL)) { + if (!CurrentAV->Remaining_Time_Delay) CurrentAV->Event_State = EVENT_STATE_NORMAL; else CurrentAV->Remaining_Time_Delay--; @@ -865,41 +879,36 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) break; default: - return; /* shouldn't happen */ - } /* switch (FromState) */ + return; /* shouldn't happen */ + } /* switch (FromState) */ ToState = CurrentAV->Event_State; - if (FromState != ToState) - { + if (FromState != ToState) { /* Event_State has changed. Need to fill only the basic parameters of this type of event. Other parameters will be filled in common function. */ - switch (ToState) - { + switch (ToState) { case EVENT_STATE_HIGH_LIMIT: ExceededLimit = CurrentAV->High_Limit; - characterstring_init_ansi(&msgText, - "Goes to high limit"); + characterstring_init_ansi(&msgText, "Goes to high limit"); break; case EVENT_STATE_LOW_LIMIT: ExceededLimit = CurrentAV->Low_Limit; - characterstring_init_ansi(&msgText, - "Goes to low limit"); + characterstring_init_ansi(&msgText, "Goes to low limit"); break; case EVENT_STATE_NORMAL: - if(FromState == EVENT_STATE_HIGH_LIMIT) { + if (FromState == EVENT_STATE_HIGH_LIMIT) { ExceededLimit = CurrentAV->High_Limit; characterstring_init_ansi(&msgText, - "Back to normal state from high limit"); - } - else { + "Back to normal state from high limit"); + } else { ExceededLimit = CurrentAV->Low_Limit; characterstring_init_ansi(&msgText, - "Back to normal state from low limit"); + "Back to normal state from low limit"); } break; @@ -910,9 +919,9 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) #if PRINT_ENABLED fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n", - bactext_object_type_name(OBJECT_ANALOG_VALUE), - object_instance, bactext_event_state_name(FromState), - bactext_event_state_name(ToState)); + bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance, + bactext_event_state_name(FromState), + bactext_event_state_name(ToState)); #endif /* PRINT_ENABLED */ /* Notify Type */ @@ -924,8 +933,7 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) } - if (SendNotify) - { + if (SendNotify) { /* Event Object Identifier */ event_data.eventObjectIdentifier.type = OBJECT_ANALOG_VALUE; event_data.eventObjectIdentifier.instance = object_instance; @@ -936,22 +944,21 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { /* fill Event_Time_Stamps */ - switch (ToState) - { + switch (ToState) { case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: CurrentAV->Event_Time_Stamps[TRANSITION_TO_OFFNORMAL] = - event_data.timeStamp.value.dateTime; + event_data.timeStamp.value.dateTime; break; case EVENT_STATE_FAULT: CurrentAV->Event_Time_Stamps[TRANSITION_TO_FAULT] = - event_data.timeStamp.value.dateTime; + event_data.timeStamp.value.dateTime; break; case EVENT_STATE_NORMAL: CurrentAV->Event_Time_Stamps[TRANSITION_TO_NORMAL] = - event_data.timeStamp.value.dateTime; + event_data.timeStamp.value.dateTime; break; } } @@ -978,50 +985,57 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) /* Event Values */ if (event_data.notifyType != NOTIFY_ACK_NOTIFICATION) { /* Value that exceeded a limit. */ - event_data.notificationParams.outOfRange.exceedingValue = PresentVal; + 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, 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, CurrentAV->Out_Of_Service); + 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, + CurrentAV->Out_Of_Service); /* Deadband used for limit checking. */ - event_data.notificationParams.outOfRange.deadband = CurrentAV->Deadband; + event_data.notificationParams.outOfRange.deadband = + CurrentAV->Deadband; /* Limit that was exceeded. */ - event_data.notificationParams.outOfRange.exceededLimit = ExceededLimit; + event_data.notificationParams.outOfRange.exceededLimit = + ExceededLimit; } /* add data from notification class */ Notification_Class_common_reporting_function(&event_data); /* Ack required */ - if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && - (event_data.ackRequired == true)) - { - switch (event_data.toState) - { + if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && + (event_data.ackRequired == true)) { + switch (event_data.toState) { 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; } } @@ -1031,12 +1045,13 @@ void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) #if defined(INTRINSIC_REPORTING) -int Analog_Value_Event_Information(unsigned index, - BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) +int Analog_Value_Event_Information( + unsigned index, + BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) { bool IsNotAckedTransitions; bool IsActiveEvent; - int i; + int i; /* check index */ @@ -1046,62 +1061,74 @@ int Analog_Value_Event_Information(unsigned index, /* 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); - } - else - return -1; /* end of list */ + 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); + } else + return -1; /* end of list */ if ((IsActiveEvent) || (IsNotAckedTransitions)) { /* Object Identifier */ getevent_data->objectIdentifier.type = OBJECT_ANALOG_VALUE; - getevent_data->objectIdentifier.instance = Analog_Value_Index_To_Instance(index); + getevent_data->objectIdentifier.instance = + Analog_Value_Index_To_Instance(index); /* Event State */ getevent_data->eventState = AV_Descr[index].Event_State; /* Acknowledged Transitions */ bitstring_init(&getevent_data->acknowledgedTransitions); - bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_OFFNORMAL, - 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); - bitstring_set_bit(&getevent_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, - AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); + bitstring_set_bit(&getevent_data->acknowledgedTransitions, + TRANSITION_TO_OFFNORMAL, + 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); + bitstring_set_bit(&getevent_data->acknowledgedTransitions, + TRANSITION_TO_NORMAL, + AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); /* Event Time Stamps */ for (i = 0; i < 3; i++) { getevent_data->eventTimeStamps[i].tag = TIME_STAMP_DATETIME; getevent_data->eventTimeStamps[i].value.dateTime = - AV_Descr[index].Event_Time_Stamps[i]; + AV_Descr[index].Event_Time_Stamps[i]; } /* Notify Type */ getevent_data->notifyType = AV_Descr[index].Notify_Type; /* 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); + getevent_data->eventPriorities); - return 1; /* active event */ - } - else - return 0; /* no active event at this index */ + return 1; /* active event */ + } else + return 0; /* no active event at this index */ } -int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, - BACNET_ERROR_CODE * error_code) +int Analog_Value_Alarm_Ack( + BACNET_ALARM_ACK_DATA * alarmack_data, + BACNET_ERROR_CODE * error_code) { ANALOG_VALUE_DESCR *CurrentAV; unsigned int object_index; - object_index = Analog_Value_Instance_To_Index( - alarmack_data->eventObjectIdentifier.instance); + object_index = + Analog_Value_Instance_To_Index(alarmack_data->eventObjectIdentifier. + instance); if (object_index < MAX_ANALOG_VALUES) CurrentAV = &AV_Descr[object_index]; @@ -1110,71 +1137,73 @@ int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, return -1; } - switch (alarmack_data->eventStateAcked) - { + switch (alarmack_data->eventStateAcked) { case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - if(CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked == false) { - if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ + 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, - &alarmack_data->eventTimeStamp.value.dateTime) > 0) - { + 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; - } - else { + CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. + bIsAcked = true; + } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; } break; case EVENT_STATE_FAULT: - if(CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == false) { - if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ + if (CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].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_NORMAL].Time_Stamp, - &alarmack_data->eventTimeStamp.value.dateTime) > 0) - { + 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; } /* Clean transitions flag. */ - CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = true; - } - else { + CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = + true; + } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; } break; case EVENT_STATE_NORMAL: - if(CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == false) { - if(alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME){ + if (CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].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_FAULT].Time_Stamp, - &alarmack_data->eventTimeStamp.value.dateTime) > 0) - { + 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; } /* Clean transitions flag. */ - CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = true; - } - else { + CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked = + true; + } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; } @@ -1205,10 +1234,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } diff --git a/bacnet-stack/demo/object/av.h b/bacnet-stack/demo/object/av.h index 649c4572..7e45cfde 100644 --- a/bacnet-stack/demo/object/av.h +++ b/bacnet-stack/demo/object/av.h @@ -43,23 +43,23 @@ extern "C" { #endif /* __cplusplus */ typedef struct analog_value_descr { - uint8_t Event_State : 3; - bool Out_Of_Service; - uint8_t Units; + uint8_t Event_State:3; + bool Out_Of_Service; + uint8_t Units; /* Here is our Priority Array. They are supposed to be Real, but */ /* we don't have that kind of memory, so we will use a single byte */ /* and load a Real for returning the value when asked. */ - uint8_t Priority_Array[BACNET_MAX_PRIORITY]; - float Relinquish_Default; + uint8_t Priority_Array[BACNET_MAX_PRIORITY]; + float Relinquish_Default; #if defined(INTRINSIC_REPORTING) uint32_t Time_Delay; uint32_t Notification_Class; - float High_Limit; - float Low_Limit; - float Deadband; - uint8_t Limit_Enable : 2; - uint8_t Event_Enable : 3; - uint8_t Notify_Type : 1; + float High_Limit; + float Low_Limit; + float Deadband; + uint8_t Limit_Enable:2; + uint8_t Event_Enable:3; + uint8_t Notify_Type:1; ACKED_INFO Acked_Transitions[MAX_BACNET_EVENT_TRANSITION]; BACNET_DATE_TIME Event_Time_Stamps[MAX_BACNET_EVENT_TRANSITION]; /* time to generate event notification */ @@ -85,7 +85,7 @@ extern "C" { bool Analog_Value_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); int Analog_Value_Read_Property( BACNET_READ_PROPERTY_DATA * rpdata); @@ -101,15 +101,17 @@ extern "C" { uint32_t object_instance); /* note: header of Intrinsic_Reporting function is required - even when INTRINSIC_REPORTING is not defined */ + even when INTRINSIC_REPORTING is not defined */ void Analog_Value_Intrinsic_Reporting( uint32_t object_instance); #if defined(INTRINSIC_REPORTING) - int Analog_Value_Event_Information(unsigned index, + int Analog_Value_Event_Information( + unsigned index, BACNET_GET_EVENT_INFORMATION_DATA * getevent_data); - int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA * alarmack_data, + int Analog_Value_Alarm_Ack( + BACNET_ALARM_ACK_DATA * alarmack_data, BACNET_ERROR_CODE * error_code); #endif diff --git a/bacnet-stack/demo/object/bacfile.c b/bacnet-stack/demo/object/bacfile.c index 48509b59..84695568 100644 --- a/bacnet-stack/demo/object/bacfile.c +++ b/bacnet-stack/demo/object/bacfile.c @@ -94,7 +94,7 @@ void BACfile_Property_Lists( return; } -static char * bacfile_name( +static char *bacfile_name( uint32_t instance) { uint32_t index = 0; @@ -114,7 +114,7 @@ static char * bacfile_name( bool bacfile_object_name( uint32_t instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { bool status = false; char *filename = NULL; @@ -491,15 +491,13 @@ bool bacfile_read_ack_stream_data( found = true; pFile = fopen(pFilename, "rb"); if (pFile) { - (void) fseek(pFile, data->type.stream.fileStartPosition, - SEEK_SET); + (void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET); if (fwrite(octetstring_value(&data->fileData), - octetstring_length(&data->fileData), 1, - pFile) != 1) { - #if PRINT_ENABLED - fprintf(stderr, "Failed to write to %s (%lu)!\n", - pFilename, (unsigned long) instance); - #endif + octetstring_length(&data->fileData), 1, pFile) != 1) { +#if PRINT_ENABLED + fprintf(stderr, "Failed to write to %s (%lu)!\n", pFilename, + (unsigned long) instance); +#endif } fclose(pFile); } diff --git a/bacnet-stack/demo/object/bacfile.h b/bacnet-stack/demo/object/bacfile.h index 3997f7b0..5285512e 100644 --- a/bacnet-stack/demo/object/bacfile.h +++ b/bacnet-stack/demo/object/bacfile.h @@ -54,7 +54,7 @@ extern "C" { const int **pProprietary); bool bacfile_object_name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); bool bacfile_valid_instance( uint32_t object_instance); uint32_t bacfile_count( diff --git a/bacnet-stack/demo/object/bi.c b/bacnet-stack/demo/object/bi.c index 477858b7..827e8bea 100644 --- a/bacnet-stack/demo/object/bi.c +++ b/bacnet-stack/demo/object/bi.c @@ -233,10 +233,10 @@ bool Binary_Input_Encode_Value_List( value_list->value.context_specific = false; value_list->value.tag = BACNET_APPLICATION_TAG_BIT_STRING; bitstring_init(&value_list->value.type.Bit_String); - bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_IN_ALARM, - false); - bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_FAULT, - false); + bitstring_set_bit(&value_list->value.type.Bit_String, + STATUS_FLAG_IN_ALARM, false); + bitstring_set_bit(&value_list->value.type.Bit_String, + STATUS_FLAG_FAULT, false); bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_OVERRIDDEN, false); if (Binary_Input_Out_Of_Service(object_instance)) { @@ -292,7 +292,7 @@ static void Binary_Input_Out_Of_Service_Set( bool Binary_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ bool status = false; @@ -494,10 +494,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } diff --git a/bacnet-stack/demo/object/bi.h b/bacnet-stack/demo/object/bi.h index 9e231569..8a9862ab 100644 --- a/bacnet-stack/demo/object/bi.h +++ b/bacnet-stack/demo/object/bi.h @@ -54,7 +54,7 @@ extern "C" { bool Binary_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); bool Binary_Input_Name_Set( uint32_t object_instance, char *new_name); diff --git a/bacnet-stack/demo/object/bo.c b/bacnet-stack/demo/object/bo.c index 81fd7b0e..f68ed73c 100644 --- a/bacnet-stack/demo/object/bo.c +++ b/bacnet-stack/demo/object/bo.c @@ -179,7 +179,7 @@ BACNET_BINARY_PV Binary_Output_Present_Value( /* note: the object name must be unique within this device */ bool Binary_Output_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ bool status = false; @@ -376,8 +376,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 @@ -403,8 +403,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--; @@ -455,10 +455,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } diff --git a/bacnet-stack/demo/object/bo.h b/bacnet-stack/demo/object/bo.h index 6aece0ef..90224350 100644 --- a/bacnet-stack/demo/object/bo.h +++ b/bacnet-stack/demo/object/bo.h @@ -57,7 +57,7 @@ extern "C" { bool Binary_Output_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); bool Binary_Output_Name_Set( uint32_t object_instance, char *new_name); diff --git a/bacnet-stack/demo/object/bv.c b/bacnet-stack/demo/object/bv.c index 30b6e727..e77fc6f0 100644 --- a/bacnet-stack/demo/object/bv.c +++ b/bacnet-stack/demo/object/bv.c @@ -176,7 +176,7 @@ static BACNET_BINARY_PV Binary_Value_Present_Value( /* note: the object name must be unique within this device */ bool Binary_Value_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ bool status = false; @@ -359,8 +359,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 @@ -386,8 +386,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--; @@ -437,10 +437,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } diff --git a/bacnet-stack/demo/object/bv.h b/bacnet-stack/demo/object/bv.h index ab8c10ee..dcb33904 100644 --- a/bacnet-stack/demo/object/bv.h +++ b/bacnet-stack/demo/object/bv.h @@ -51,7 +51,7 @@ extern "C" { bool Binary_Value_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); void Binary_Value_Init( void); diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index 86130dee..ade0b7f3 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -38,7 +38,7 @@ #include "apdu.h" #include "wp.h" /* WriteProperty handling */ #include "rp.h" /* ReadProperty handling */ -#include "dcc.h" /* DeviceCommunicationControl handling */ +#include "dcc.h" /* DeviceCommunicationControl handling */ #include "version.h" #include "device.h" /* me */ #include "handlers.h" @@ -86,72 +86,81 @@ extern bool Routed_Device_Write_Property_Local( static object_functions_t Object_Table[] = { { - OBJECT_DEVICE, NULL, Device_Count, /* don't init - recursive! */ + OBJECT_DEVICE, NULL, Device_Count, /* don't init - recursive! */ Device_Index_To_Instance, Device_Valid_Object_Instance_Number, Device_Object_Name, Device_Read_Property_Local, Device_Write_Property_Local, Device_Property_Lists, - NULL, NULL, NULL, NULL}, { - OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count, + NULL, NULL, NULL, NULL}, { + OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count, Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance, Analog_Input_Object_Name, Analog_Input_Read_Property, Analog_Input_Write_Property, Analog_Input_Property_Lists, - NULL, NULL, NULL, Analog_Input_Intrinsic_Reporting}, { - OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count, + NULL, NULL, NULL, Analog_Input_Intrinsic_Reporting}, { + OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count, Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance, Analog_Value_Object_Name, Analog_Value_Read_Property, Analog_Value_Write_Property, Analog_Value_Property_Lists, - NULL, NULL, NULL, Analog_Value_Intrinsic_Reporting}, { - OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count, + NULL, NULL, NULL, Analog_Value_Intrinsic_Reporting}, { + OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count, Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance, Binary_Input_Object_Name, Binary_Input_Read_Property, NULL, Binary_Input_Property_Lists, - NULL, NULL, NULL, NULL}, { - OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count, + NULL, NULL, NULL, NULL}, { + OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count, Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance, Binary_Value_Object_Name, Binary_Value_Read_Property, Binary_Value_Write_Property, Binary_Value_Property_Lists, - NULL, NULL, NULL, NULL}, { + NULL, NULL, NULL, NULL}, { #if defined(INTRINSIC_REPORTING) - OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, Notification_Class_Count, - Notification_Class_Index_To_Instance, Notification_Class_Valid_Instance, + OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, + Notification_Class_Count, + Notification_Class_Index_To_Instance, + Notification_Class_Valid_Instance, Notification_Class_Object_Name, Notification_Class_Read_Property, - Notification_Class_Write_Property, Notification_Class_Property_Lists, - NULL, NULL, NULL, NULL}, { + Notification_Class_Write_Property, + Notification_Class_Property_Lists, + NULL, NULL, NULL, NULL}, { #endif - OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Init, Life_Safety_Point_Count, - Life_Safety_Point_Index_To_Instance, Life_Safety_Point_Valid_Instance, + OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Init, + Life_Safety_Point_Count, + Life_Safety_Point_Index_To_Instance, + Life_Safety_Point_Valid_Instance, Life_Safety_Point_Object_Name, Life_Safety_Point_Read_Property, Life_Safety_Point_Write_Property, Life_Safety_Point_Property_Lists, - NULL, NULL, NULL, NULL}, { - OBJECT_LOAD_CONTROL, Load_Control_Init, Load_Control_Count, + NULL, NULL, NULL, NULL}, { + OBJECT_LOAD_CONTROL, Load_Control_Init, Load_Control_Count, Load_Control_Index_To_Instance, Load_Control_Valid_Instance, Load_Control_Object_Name, Load_Control_Read_Property, Load_Control_Write_Property, Load_Control_Property_Lists, - NULL, NULL, NULL}, { - OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init, Multistate_Output_Count, - Multistate_Output_Index_To_Instance, Multistate_Output_Valid_Instance, + NULL, NULL, NULL}, { + OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init, + Multistate_Output_Count, + Multistate_Output_Index_To_Instance, + Multistate_Output_Valid_Instance, Multistate_Output_Object_Name, Multistate_Output_Read_Property, Multistate_Output_Write_Property, Multistate_Output_Property_Lists, - NULL, NULL, NULL, NULL}, { - OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, Multistate_Input_Count, - Multistate_Input_Index_To_Instance, Multistate_Input_Valid_Instance, + NULL, NULL, NULL, NULL}, { + OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, + Multistate_Input_Count, + Multistate_Input_Index_To_Instance, + Multistate_Input_Valid_Instance, Multistate_Input_Object_Name, Multistate_Input_Read_Property, Multistate_Input_Write_Property, Multistate_Input_Property_Lists, - NULL, NULL, NULL, NULL}, { - OBJECT_TRENDLOG, Trend_Log_Init, Trend_Log_Count, + NULL, NULL, NULL, NULL}, { + OBJECT_TRENDLOG, Trend_Log_Init, Trend_Log_Count, Trend_Log_Index_To_Instance, Trend_Log_Valid_Instance, Trend_Log_Object_Name, Trend_Log_Read_Property, Trend_Log_Write_Property, Trend_Log_Property_Lists, - TrendLogGetRRInfo, NULL, NULL, NULL}, { + TrendLogGetRRInfo, NULL, NULL, NULL}, { #if defined(BACFILE) - OBJECT_FILE, bacfile_init, bacfile_count, + OBJECT_FILE, bacfile_init, bacfile_count, bacfile_index_to_instance, bacfile_valid_instance, bacfile_object_name, bacfile_read_property, bacfile_write_property, BACfile_Property_Lists, - NULL, NULL, NULL, NULL}, { + NULL, NULL, NULL, NULL}, { #endif - MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL} + MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL} }; @@ -474,7 +483,7 @@ bool Device_Valid_Object_Instance_Number( bool Device_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { bool status = false; @@ -486,7 +495,7 @@ bool Device_Object_Name( } bool Device_Set_Object_Name( - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { bool status = false; /*return value */ @@ -816,7 +825,7 @@ bool Device_Object_List_Identifier( * @return True on success or else False if not found. */ bool Device_Valid_Object_Name( - BACNET_CHARACTER_STRING *object_name1, + BACNET_CHARACTER_STRING * object_name1, int *object_type, uint32_t * object_instance) { @@ -835,7 +844,7 @@ bool Device_Valid_Object_Name( pObject = Device_Objects_Find_Functions(type); if ((pObject != NULL) && (pObject->Object_Name != NULL) && (pObject->Object_Name(instance, &object_name2) && - characterstring_same(object_name1, &object_name2))) { + characterstring_same(object_name1, &object_name2))) { found = true; if (object_type) { *object_type = type; @@ -860,7 +869,7 @@ bool Device_Valid_Object_Id( int object_type, uint32_t object_instance) { - bool status = false; /* return value */ + bool status = false; /* return value */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -880,7 +889,7 @@ bool Device_Valid_Object_Id( bool Device_Object_Name_Copy( int object_type, uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { struct object_functions *pObject = NULL; bool found = false; @@ -960,7 +969,8 @@ int tm_isdst Daylight Savings flag. } } -void Device_getCurrentDateTime(BACNET_DATE_TIME * DateTime) +void Device_getCurrentDateTime( + BACNET_DATE_TIME * DateTime) { Update_Current_Time(); @@ -1265,8 +1275,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; @@ -1299,8 +1309,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: @@ -1325,15 +1335,14 @@ bool Device_Write_Property_Local( case PROP_OBJECT_NAME: status = WPValidateString(&value, - characterstring_capacity(&My_Object_Name), - false, - &wp_data->error_class, &wp_data->error_code); + characterstring_capacity(&My_Object_Name), false, + &wp_data->error_class, &wp_data->error_code); if (status) { /* All the object names in a device must be unique. Disallow setting the Device Object Name to any objects in the device. */ if (Device_Valid_Object_Name(&value.type.Character_String, - NULL, NULL)) { + NULL, NULL)) { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; @@ -1347,8 +1356,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; @@ -1358,8 +1367,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; @@ -1368,8 +1377,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; @@ -1381,8 +1390,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; @@ -1464,9 +1473,9 @@ bool Device_Write_Property( * @return True if the object instance supports this feature and value changed. */ bool Device_Encode_Value_List( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_PROPERTY_VALUE * value_list) + BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_PROPERTY_VALUE * value_list) { bool status = false; /* Ever the pessamist! */ struct object_functions *pObject = NULL; @@ -1476,9 +1485,8 @@ bool Device_Encode_Value_List( if (pObject->Object_Valid_Instance && pObject->Object_Valid_Instance(object_instance)) { if (pObject->Object_Value_List) { - status = pObject->Object_Value_List( - object_instance, - value_list); + status = + pObject->Object_Value_List(object_instance, value_list); } } } @@ -1488,29 +1496,27 @@ bool Device_Encode_Value_List( #if defined(INTRINSIC_REPORTING) -void Device_local_reporting(void) +void Device_local_reporting( + void) { - struct object_functions *pObject; + struct object_functions *pObject; uint32_t objects_count; uint32_t object_instance; - int object_type; + int object_type; uint32_t idx; objects_count = Device_Object_List_Count(); /* loop for all objects */ - for (idx = 1; idx < objects_count; idx++) - { - Device_Object_List_Identifier(idx, &object_type, - &object_instance); + for (idx = 1; idx < objects_count; idx++) { + Device_Object_List_Identifier(idx, &object_type, &object_instance); pObject = Device_Objects_Find_Functions(object_type); if (pObject != NULL) { if (pObject->Object_Valid_Instance && pObject->Object_Valid_Instance(object_instance)) { if (pObject->Object_Intrinsic_Reporting) { - pObject->Object_Intrinsic_Reporting( - object_instance); + pObject->Object_Intrinsic_Reporting(object_instance); } } } @@ -1555,7 +1561,7 @@ void Device_Init( characterstring_init_ansi(&My_Object_Name, "SimpleServer"); /* we don't use the object table passed in since there is extra stuff we don't need in there. */ - (void)object_table; + (void) object_table; pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { if (pObject->Object_Init) { @@ -1653,10 +1659,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } @@ -1668,11 +1674,11 @@ bool WPValidateString( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - iMaxLen=iMaxLen; - bEmptyAllowed=bEmptyAllowed; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + iMaxLen = iMaxLen; + bEmptyAllowed = bEmptyAllowed; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } @@ -1681,8 +1687,8 @@ int handler_cov_encode_subscriptions( uint8_t * apdu, int max_apdu) { - apdu=apdu; - max_apdu=max_apdu; + apdu = apdu; + max_apdu = max_apdu; return 0; } diff --git a/bacnet-stack/demo/object/device.h b/bacnet-stack/demo/object/device.h index aed558ca..e8583aa9 100644 --- a/bacnet-stack/demo/object/device.h +++ b/bacnet-stack/demo/object/device.h @@ -73,9 +73,9 @@ typedef uint32_t( */ typedef bool( *object_name_function) - ( + ( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); /** Look in the table of objects of this type, and see if this is a valid * instance number. @@ -116,9 +116,9 @@ typedef bool( * @ingroup ObjHelpers * @param [in] Object instance. */ -typedef void( +typedef void ( *object_intrinsic_reporting_function) ( - uint32_t object_instance); + uint32_t object_instance); /** Defines the group of object helper functions for any supported Object. @@ -213,7 +213,8 @@ extern "C" { rr_info_function Device_Objects_RR_Info( BACNET_OBJECT_TYPE object_type); - void Device_getCurrentDateTime(BACNET_DATE_TIME * DateTime); + void Device_getCurrentDateTime( + BACNET_DATE_TIME * DateTime); void Device_Property_Lists( const int **pRequired, @@ -250,14 +251,14 @@ extern "C" { bool Device_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); bool Device_Set_Object_Name( - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); /* copy a child object name */ bool Device_Object_Name_Copy( int object_type, uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); BACNET_DEVICE_STATUS Device_System_Status( void); @@ -316,7 +317,7 @@ extern "C" { void); bool Device_Valid_Object_Name( - BACNET_CHARACTER_STRING *object_name, + BACNET_CHARACTER_STRING * object_name, int *object_type, uint32_t * object_instance); bool Device_Valid_Object_Id( @@ -338,7 +339,8 @@ extern "C" { BACNET_WRITE_PROPERTY_DATA * wp_data); #if defined(INTRINSIC_REPORTING) - void Device_local_reporting(void); + void Device_local_reporting( + void); #endif /* Prototypes for Routing functionality in the Device Object. @@ -411,11 +413,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 418918d6..13f82670 100644 --- a/bacnet-stack/demo/object/gw_device.c +++ b/bacnet-stack/demo/object/gw_device.c @@ -127,14 +127,10 @@ uint16_t Add_Routed_Device( pDev->bacObj.mObject_Type = OBJECT_DEVICE; pDev->bacObj.Object_Instance_Number = Object_Instance; if (sObject_Name != NULL) - Routed_Device_Set_Object_Name( - CHARACTER_UTF8, - sObject_Name, + Routed_Device_Set_Object_Name(CHARACTER_UTF8, sObject_Name, strlen(sObject_Name)); else - Routed_Device_Set_Object_Name( - CHARACTER_UTF8, - "No Name", + Routed_Device_Set_Object_Name(CHARACTER_UTF8, "No Name", strlen("No Name")); if (sDescription != NULL) Routed_Device_Set_Description(sDescription, strlen(sDescription)); @@ -488,8 +484,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; @@ -503,8 +499,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)); } @@ -559,8 +555,7 @@ bool Routed_Device_Set_Object_Name( bool status = false; /*return value */ DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; - if ((encoding == CHARACTER_UTF8) && - (length < MAX_DEV_NAME_LEN)) { + if ((encoding == CHARACTER_UTF8) && (length < MAX_DEV_NAME_LEN)) { /* Make the change and update the database revision */ memmove(pDev->bacObj.Object_Name, value, length); pDev->bacObj.Object_Name[length] = 0; diff --git a/bacnet-stack/demo/object/lc.c b/bacnet-stack/demo/object/lc.c index 1ed8617e..52c297b3 100644 --- a/bacnet-stack/demo/object/lc.c +++ b/bacnet-stack/demo/object/lc.c @@ -274,7 +274,7 @@ static BACNET_SHED_STATE Load_Control_Present_Value( /* note: the object name must be unique within this device */ bool Load_Control_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ bool status = false; diff --git a/bacnet-stack/demo/object/lc.h b/bacnet-stack/demo/object/lc.h index ae88da10..09704288 100644 --- a/bacnet-stack/demo/object/lc.h +++ b/bacnet-stack/demo/object/lc.h @@ -54,7 +54,7 @@ extern "C" { bool Load_Control_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); void Load_Control_Init( void); diff --git a/bacnet-stack/demo/object/lo.c b/bacnet-stack/demo/object/lo.c index 88180dd1..697962a3 100644 --- a/bacnet-stack/demo/object/lo.c +++ b/bacnet-stack/demo/object/lo.c @@ -469,8 +469,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] @@ -554,11 +554,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 @@ -585,8 +585,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; } @@ -612,10 +612,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } diff --git a/bacnet-stack/demo/object/lsp.c b/bacnet-stack/demo/object/lsp.c index 33d76a69..0dbe8846 100644 --- a/bacnet-stack/demo/object/lsp.c +++ b/bacnet-stack/demo/object/lsp.c @@ -175,7 +175,7 @@ static BACNET_LIFE_SAFETY_STATE Life_Safety_Point_Present_Value( /* note: the object name must be unique within this device */ bool Life_Safety_Point_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ bool status = false; @@ -218,7 +218,8 @@ int Life_Safety_Point_Read_Property( break; case PROP_OBJECT_NAME: case PROP_DESCRIPTION: - Life_Safety_Point_Object_Name(rpdata->object_instance, &char_string); + Life_Safety_Point_Object_Name(rpdata->object_instance, + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; @@ -324,8 +325,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 { @@ -341,8 +342,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; } @@ -368,10 +369,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } diff --git a/bacnet-stack/demo/object/lsp.h b/bacnet-stack/demo/object/lsp.h index ecf1c306..402622c9 100644 --- a/bacnet-stack/demo/object/lsp.h +++ b/bacnet-stack/demo/object/lsp.h @@ -50,7 +50,7 @@ extern "C" { uint32_t object_instance); bool Life_Safety_Point_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); void Life_Safety_Point_Init( void); diff --git a/bacnet-stack/demo/object/ms-input.c b/bacnet-stack/demo/object/ms-input.c index 38278961..12f70239 100644 --- a/bacnet-stack/demo/object/ms-input.c +++ b/bacnet-stack/demo/object/ms-input.c @@ -227,7 +227,7 @@ bool Multistate_Input_Description_Set( bool Multistate_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -348,7 +348,8 @@ int Multistate_Input_Read_Property( /* note: Name and Description don't have to be the same. You could make Description writable and different */ case PROP_OBJECT_NAME: - Multistate_Input_Object_Name(rpdata->object_instance, &char_string); + Multistate_Input_Object_Name(rpdata->object_instance, + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; @@ -403,8 +404,8 @@ int Multistate_Input_Read_Property( /* if no index was specified, then try to encode the entire list */ /* into one packet. */ object_index = - Multistate_Input_Instance_To_Index(rpdata-> - object_instance); + Multistate_Input_Instance_To_Index + (rpdata->object_instance); for (i = 1; i <= MULTISTATE_NUMBER_OF_STATES; i++) { characterstring_init_ansi(&char_string, Multistate_Input_State_Text(rpdata->object_instance, @@ -425,8 +426,8 @@ int Multistate_Input_Read_Property( } } else { object_index = - Multistate_Input_Instance_To_Index(rpdata-> - object_instance); + Multistate_Input_Instance_To_Index + (rpdata->object_instance); if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) { characterstring_init_ansi(&char_string, Multistate_Input_State_Text(rpdata->object_instance, @@ -486,8 +487,8 @@ bool Multistate_Input_Write_Property( if (status) { if (Out_Of_Service[object_index]) { 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; @@ -505,8 +506,8 @@ bool Multistate_Input_Write_Property( &wp_data->error_class, &wp_data->error_code); if (status) { object_index = - Multistate_Input_Instance_To_Index(wp_data-> - object_instance); + Multistate_Input_Instance_To_Index + (wp_data->object_instance); Out_Of_Service[object_index] = value.type.Boolean; } break; @@ -531,10 +532,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } diff --git a/bacnet-stack/demo/object/ms-input.h b/bacnet-stack/demo/object/ms-input.h index 34545e2a..4a8fbe2c 100644 --- a/bacnet-stack/demo/object/ms-input.h +++ b/bacnet-stack/demo/object/ms-input.h @@ -62,7 +62,7 @@ extern "C" { bool Multistate_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); bool Multistate_Input_Name_Set( uint32_t object_instance, char *new_name); diff --git a/bacnet-stack/demo/object/mso.c b/bacnet-stack/demo/object/mso.c index efd8fecf..0ff12186 100644 --- a/bacnet-stack/demo/object/mso.c +++ b/bacnet-stack/demo/object/mso.c @@ -182,7 +182,7 @@ static uint32_t Multistate_Output_Present_Value( /* note: the object name must be unique within this device */ bool Multistate_Output_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ bool status = false; @@ -224,7 +224,8 @@ int Multistate_Output_Read_Property( You could make Description writable and different */ case PROP_OBJECT_NAME: case PROP_DESCRIPTION: - Multistate_Output_Object_Name(rpdata->object_instance, &char_string); + Multistate_Output_Object_Name(rpdata->object_instance, + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; @@ -267,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] == @@ -293,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) @@ -376,8 +377,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; @@ -404,8 +405,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--; @@ -431,8 +432,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; } @@ -458,10 +459,10 @@ bool WPValidateArgType( BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - pValue=pValue; - ucExpectedTag=ucExpectedTag; - pErrorClass=pErrorClass; - pErrorCode=pErrorCode; + pValue = pValue; + ucExpectedTag = ucExpectedTag; + pErrorClass = pErrorClass; + pErrorCode = pErrorCode; return false; } diff --git a/bacnet-stack/demo/object/mso.h b/bacnet-stack/demo/object/mso.h index de29a4fe..829b2e37 100644 --- a/bacnet-stack/demo/object/mso.h +++ b/bacnet-stack/demo/object/mso.h @@ -51,7 +51,7 @@ extern "C" { bool Multistate_Output_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); void Multistate_Output_Init( void); diff --git a/bacnet-stack/demo/object/nc.c b/bacnet-stack/demo/object/nc.c index 64343bc6..e8b02bbd 100644 --- a/bacnet-stack/demo/object/nc.c +++ b/bacnet-stack/demo/object/nc.c @@ -1,889 +1,929 @@ -/************************************************************************** -* -* Copyright (C) 2011 Krzysztof Malorny -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ -#include -#include -#include -#include - -#include "address.h" -#include "bacdef.h" -#include "bacdcode.h" -#include "bacenum.h" -#include "bacapp.h" -#include "client.h" -#include "config.h" -#include "device.h" -#include "event.h" -#include "handlers.h" -#include "txbuf.h" -#include "wp.h" -#include "nc.h" - - -#ifndef MAX_NOTIFICATION_CLASSES -#define MAX_NOTIFICATION_CLASSES 2 -#endif - - -#if defined(INTRINSIC_REPORTING) -static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES]; - -/* These three arrays are used by the ReadPropertyMultiple handler */ -static const int Notification_Properties_Required[] = -{ - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_NOTIFICATION_CLASS, - PROP_PRIORITY, - PROP_ACK_REQUIRED, - PROP_RECIPIENT_LIST, - -1 -}; - -static const int Notification_Properties_Optional[] = -{ - PROP_DESCRIPTION, - -1 -}; - -static const int Notification_Properties_Proprietary[] = -{ - -1 -}; - -void Notification_Class_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) -{ - if (pRequired) - *pRequired = Notification_Properties_Required; - if (pOptional) - *pOptional = Notification_Properties_Optional; - if (pProprietary) - *pProprietary = Notification_Properties_Proprietary; - return; -} - -void Notification_Class_Init(void) -{ - uint8_t NotifyIdx = 0; - - for (NotifyIdx = 0; NotifyIdx < MAX_NOTIFICATION_CLASSES; NotifyIdx++) - { - /* init with zeros */ - memset(&NC_Info[NotifyIdx], 0x00, sizeof(NOTIFICATION_CLASS_INFO)); - /* set the basic parameters */ - NC_Info[NotifyIdx].Ack_Required = 0; - NC_Info[NotifyIdx].Priority[0] = 255; /* The lowest priority for Normal message. */ - NC_Info[NotifyIdx].Priority[1] = 255; /* The lowest priority for Normal message. */ - NC_Info[NotifyIdx].Priority[2] = 255; /* The lowest priority for Normal message. */ - } - - return; -} - - -/* we simply have 0-n object instances. Yours might be */ -/* more complex, and then you need validate that the */ -/* given instance exists */ -bool Notification_Class_Valid_Instance( - uint32_t object_instance) -{ - unsigned int index; - - index = Notification_Class_Instance_To_Index(object_instance); - if (index < MAX_NOTIFICATION_CLASSES) - return true; - - return false; -} - -/* we simply have 0-n object instances. Yours might be */ -/* more complex, and then count how many you have */ -unsigned Notification_Class_Count(void) -{ - return MAX_NOTIFICATION_CLASSES; -} - -/* we simply have 0-n object instances. Yours might be */ -/* more complex, and then you need to return the instance */ -/* that correlates to the correct index */ -uint32_t Notification_Class_Index_To_Instance(unsigned index) -{ - return index; -} - -/* we simply have 0-n object instances. Yours might be */ -/* more complex, and then you need to return the index */ -/* that correlates to the correct instance number */ -unsigned Notification_Class_Instance_To_Index( - uint32_t object_instance) -{ - unsigned index = MAX_NOTIFICATION_CLASSES; - - if (object_instance < MAX_NOTIFICATION_CLASSES) - index = object_instance; - - return index; -} - -bool Notification_Class_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) -{ - static char text_string[32] = ""; /* okay for single thread */ - unsigned int index; - bool status = false; - - index = Notification_Class_Instance_To_Index(object_instance); - if (index < MAX_NOTIFICATION_CLASSES) { - sprintf(text_string, "NOTIFICATION CLASS %lu", (unsigned long) index); - status = characterstring_init_ansi(object_name, text_string); - } - - return status; -} - - - -int Notification_Class_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) -{ - NOTIFICATION_CLASS_INFO *CurrentNotify; - BACNET_CHARACTER_STRING char_string; - BACNET_OCTET_STRING octet_string; - BACNET_BIT_STRING bit_string; - uint8_t *apdu = NULL; - uint8_t u8Val; - int idx; - int apdu_len = 0; /* return value */ - - - if ((rpdata == NULL) || (rpdata->application_data == NULL) || - (rpdata->application_data_len == 0)) { - return 0; - } - - apdu = rpdata->application_data; - CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(rpdata->object_instance)]; - - switch (rpdata->object_property) - { - case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_NOTIFICATION_CLASS, - rpdata->object_instance); - break; - - case PROP_OBJECT_NAME: - case PROP_DESCRIPTION: - Notification_Class_Object_Name(rpdata->object_instance, &char_string); - apdu_len = - encode_application_character_string(&apdu[0], &char_string); - break; - - case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], OBJECT_NOTIFICATION_CLASS); - break; - - case PROP_NOTIFICATION_CLASS: - apdu_len += encode_application_unsigned(&apdu[0], rpdata->object_instance); - break; - - case PROP_PRIORITY: - if (rpdata->array_index == 0) - apdu_len += encode_application_unsigned(&apdu[0], 3); - else - { - if (rpdata->array_index == BACNET_ARRAY_ALL) - { - /* TO-OFFNORMAL */ - apdu_len += encode_application_unsigned(&apdu[apdu_len], - CurrentNotify->Priority[0]); - /* TO-FAULT */ - apdu_len += encode_application_unsigned(&apdu[apdu_len], - CurrentNotify->Priority[1]); - /* TO-NORMAL */ - apdu_len += encode_application_unsigned(&apdu[apdu_len], - CurrentNotify->Priority[2]); - } - else if (rpdata->array_index <= 3) - { - apdu_len += encode_application_unsigned(&apdu[apdu_len], - CurrentNotify->Priority[rpdata->array_index - 1]); - } - else - { - rpdata->error_class = ERROR_CLASS_PROPERTY; - rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; - apdu_len = -1; - } - } - break; - - case PROP_ACK_REQUIRED: - u8Val = CurrentNotify->Ack_Required; - - bitstring_init(&bit_string); - bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false ); - bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, - (u8Val & TRANSITION_TO_FAULT_MASKED ) ? true : false ); - bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, - (u8Val & TRANSITION_TO_NORMAL_MASKED ) ? true : false ); - /* encode bitstring */ - apdu_len += encode_application_bitstring(&apdu[apdu_len], &bit_string); - break; - - case PROP_RECIPIENT_LIST: - /* encode all entry of Recipient_List */ - for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) - { - BACNET_DESTINATION *RecipientEntry; - int i = 0; - - /* get pointer of current element for Recipient_List - easier for use */ - RecipientEntry = &CurrentNotify->Recipient_List[idx]; - if (RecipientEntry->Recipient.RecipientType != RECIPIENT_TYPE_NOTINITIALIZED) - { - /* Valid Days - BACnetDaysOfWeek - [bitstring] monday-sunday */ - u8Val = 0x01; - bitstring_init(&bit_string); - - for (i = 0; i < MAX_BACNET_DAYS_OF_WEEK; i++) - { - if (RecipientEntry->ValidDays & u8Val) - bitstring_set_bit(&bit_string, i, true); - else - bitstring_set_bit(&bit_string, i, false); - u8Val <<= 1; /* next day */ - } - apdu_len += encode_application_bitstring(&apdu[apdu_len],&bit_string); - - /* From Time */ - apdu_len += encode_application_time(&apdu[apdu_len], - &RecipientEntry->FromTime); - - /* To Time */ - apdu_len += encode_application_time(&apdu[apdu_len], - &RecipientEntry->ToTime); - - /* - BACnetRecipient ::= CHOICE { - device [0] BACnetObjectIdentifier, - address [1] BACnetAddress - } */ - - /* CHOICE - device [0] BACnetObjectIdentifier */ - if (RecipientEntry->Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) - { - apdu_len += encode_context_object_id(&apdu[apdu_len], 0, OBJECT_DEVICE, - RecipientEntry->Recipient._.DeviceIdentifier); - } - /* CHOICE - address [1] BACnetAddress */ - else if (RecipientEntry->Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) - { - /* opening tag 1 */ - apdu_len += encode_opening_tag(&apdu[apdu_len], 1); - /* network-number Unsigned16, */ - apdu_len += encode_application_unsigned(&apdu[apdu_len], - RecipientEntry->Recipient._.Address.net); - - /* mac-address OCTET STRING */ - if (RecipientEntry->Recipient._.Address.net) - { - octetstring_init(&octet_string, - RecipientEntry->Recipient._.Address.adr, - RecipientEntry->Recipient._.Address.len); - } - else - { - octetstring_init(&octet_string, - RecipientEntry->Recipient._.Address.mac, - RecipientEntry->Recipient._.Address.mac_len); - } - apdu_len += encode_application_octet_string(&apdu[apdu_len], &octet_string); - - /* closing tag 1 */ - apdu_len += encode_closing_tag(&apdu[apdu_len], 1); - - } - else {;} /* shouldn't happen */ - - /* Process Identifier - Unsigned32 */ - apdu_len += encode_application_unsigned(&apdu[apdu_len], - RecipientEntry->ProcessIdentifier); - - /* Issue Confirmed Notifications - boolean */ - apdu_len += encode_application_boolean(&apdu[apdu_len], - RecipientEntry->ConfirmedNotify); - - /* Transitions - BACnet Event Transition Bits [bitstring] */ - u8Val = RecipientEntry->Transitions; - - bitstring_init(&bit_string); - bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false ); - bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, - (u8Val & TRANSITION_TO_FAULT_MASKED ) ? true : false ); - bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, - (u8Val & TRANSITION_TO_NORMAL_MASKED ) ? true : false ); - - apdu_len += encode_application_bitstring(&apdu[apdu_len], &bit_string); - } - } - break; - - default: - rpdata->error_class = ERROR_CLASS_PROPERTY; - rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; - apdu_len = -1; - break; - } - - /* only array properties can have array options */ - if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY) && - (rpdata->array_index != BACNET_ARRAY_ALL)) - { - rpdata->error_class = ERROR_CLASS_PROPERTY; - rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; - apdu_len = BACNET_STATUS_ERROR; - } - - return apdu_len; -} - - -bool Notification_Class_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) -{ - NOTIFICATION_CLASS_INFO *CurrentNotify; - NOTIFICATION_CLASS_INFO TmpNotify; - BACNET_APPLICATION_DATA_VALUE value; - bool status = false; - int iOffset = 0; - uint8_t idx = 0; - int len = 0; - - - - CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(wp_data->object_instance)]; - - /* decode the some of the request - */ - len = bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); - - switch (wp_data->object_property) - { - case PROP_PRIORITY: - status = - WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); - - if (status) { - if (wp_data->array_index == 0) { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; - } - else if (wp_data->array_index == BACNET_ARRAY_ALL) { - /* FIXME: wite all array */ - } - else if (wp_data->array_index <= 3) { - CurrentNotify->Priority[wp_data->array_index - 1] = - value.type.Unsigned_Int; - } - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; - } - } - break; - - case PROP_ACK_REQUIRED: - status = - WPValidateArgType(&value, BACNET_APPLICATION_TAG_BIT_STRING, - &wp_data->error_class, &wp_data->error_code); - - if (status) { - if (value.type.Bit_String.bits_used == 3) { - CurrentNotify->Ack_Required = - value.type.Bit_String.value[0]; - } - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; - } - } - break; - - case PROP_RECIPIENT_LIST: - - memset(&TmpNotify, 0x00, sizeof(NOTIFICATION_CLASS_INFO)); - - /* decode all packed */ - 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); - - if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { - /* Bad decode, wrong tag or following required parameter missing */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - - if (value.type.Bit_String.bits_used == MAX_BACNET_DAYS_OF_WEEK) - /* store value */ - TmpNotify.Recipient_List[idx].ValidDays = value.type.Bit_String.value[0]; - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_OTHER; - return false; - } - - iOffset += len; - /* Decode From Time */ - len = 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 */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - /* store value */ - TmpNotify.Recipient_List[idx].FromTime = value.type.Time; - - iOffset += len; - /* Decode To Time */ - len = 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 */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - /* store value */ - TmpNotify.Recipient_List[idx].ToTime = value.type.Time; - - iOffset += len; - /* context tag [0] - Device */ - if (decode_is_context_tag(&wp_data->application_data[iOffset], 0)) - { - TmpNotify.Recipient_List[idx].Recipient.RecipientType = RECIPIENT_TYPE_DEVICE; - /* Decode Network Number */ - len = bacapp_decode_context_data( - &wp_data->application_data[iOffset], - wp_data->application_data_len, &value, - PROP_RECIPIENT_LIST); - - if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_OBJECT_ID)) { - /* Bad decode, wrong tag or following required parameter missing */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - /* store value */ - 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)) - { - iOffset++; - TmpNotify.Recipient_List[idx].Recipient.RecipientType = RECIPIENT_TYPE_ADDRESS; - /* Decode Network Number */ - len = 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)) { - /* Bad decode, wrong tag or following required parameter missing */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - /* store value */ - TmpNotify.Recipient_List[idx].Recipient._.Address.net = value.type.Unsigned_Int; - - iOffset += len; - /* Decode Address */ - len = bacapp_decode_application_data( - &wp_data->application_data[iOffset], - wp_data->application_data_len, &value); - - if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_OCTET_STRING)) { - /* Bad decode, wrong tag or following required parameter missing */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - 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, - 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, - value.type.Octet_String.length); - TmpNotify.Recipient_List[idx].Recipient._.Address.len = - value.type.Octet_String.length; - } - - iOffset += len; - /* closing tag [1] - Recipient */ - if (decode_is_closing_tag_number(&wp_data->application_data[iOffset], 1)) - iOffset++; - else { - /* Bad decode, wrong tag or following required parameter missing */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - } - else { - /* Bad decode, wrong tag or following required parameter missing */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - - /* Process Identifier */ - len = 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)) { - /* Bad decode, wrong tag or following required parameter missing */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - /* store value */ - TmpNotify.Recipient_List[idx].ProcessIdentifier = value.type.Unsigned_Int; - - iOffset += len; - /* Issue Confirmed Notifications */ - len = bacapp_decode_application_data( - &wp_data->application_data[iOffset], - wp_data->application_data_len, &value); - - if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) { - /* Bad decode, wrong tag or following required parameter missing */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - /* store value */ - TmpNotify.Recipient_List[idx].ConfirmedNotify = value.type.Boolean; - - iOffset += len; - /* Transitions */ - len = 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)) { - /* Bad decode, wrong tag or following required parameter missing */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; - return false; - } - - if (value.type.Bit_String.bits_used == MAX_BACNET_EVENT_TRANSITION) - /* store value */ - TmpNotify.Recipient_List[idx].Transitions = value.type.Bit_String.value[0]; - else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_OTHER; - return false; - } - iOffset += len; - - /* Increasing element of list */ - if (++idx >= NC_MAX_RECIPIENTS) { - wp_data->error_class = ERROR_CLASS_RESOURCES; - wp_data->error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; - return false; - } - } - - /* Decoded all recipient list */ - /* copy elements from temporary object */ - for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) - { - BACNET_ADDRESS src = {0}; - unsigned max_apdu = 0; - int32_t DeviceID; - - CurrentNotify->Recipient_List[idx] = TmpNotify.Recipient_List[idx]; - - if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { - /* copy Device_ID */ - DeviceID = CurrentNotify->Recipient_List[idx].Recipient._.DeviceIdentifier; - address_bind_request(DeviceID, &max_apdu, &src); - - } - 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); */ - } - } - - status = true; - - break; - - default: - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY; - break; - } - - return status; -} - - -void Notification_Class_Get_Priorities( - uint32_t Object_Instance, uint32_t *pPriorityArray) -{ - NOTIFICATION_CLASS_INFO *CurrentNotify; - uint32_t object_index; - int i; - - object_index = Notification_Class_Instance_To_Index(Object_Instance); - - if (object_index < MAX_NOTIFICATION_CLASSES) - CurrentNotify = &NC_Info[object_index]; - else { - for (i = 0; i < 3; i++) - pPriorityArray[i] = 255; - return; /* unknown object */ - } - - for (i = 0; i < 3; i++) - pPriorityArray[i] = CurrentNotify->Priority[i]; -} - - -static bool IsRecipientActive(BACNET_DESTINATION * pBacDest, uint8_t EventToState) -{ - BACNET_DATE_TIME DateTime; - - /* valid Transitions */ - switch (EventToState) - { - case EVENT_STATE_OFFNORMAL: - case EVENT_STATE_HIGH_LIMIT: - case EVENT_STATE_LOW_LIMIT: - if (!(pBacDest->Transitions & TRANSITION_TO_OFFNORMAL_MASKED)) - return false; - break; - - case EVENT_STATE_FAULT: - if (!(pBacDest->Transitions & TRANSITION_TO_FAULT_MASKED)) - return false; - break; - - case EVENT_STATE_NORMAL: - if (!(pBacDest->Transitions & TRANSITION_TO_NORMAL_MASKED)) - return false; - break; - - default: - return false; /* shouldn't happen */ - } - - /* get actual date and time */ - Device_getCurrentDateTime(&DateTime); - - /* valid Days */ - if (!((0x01 << (DateTime.date.wday - 1)) & pBacDest->ValidDays)) - return false; - - /* valid FromTime */ - if (datetime_compare_time(&DateTime.time, &pBacDest->FromTime) < 0) - return false; - - /* valid ToTime */ - if (datetime_compare_time(&pBacDest->ToTime, &DateTime.time) < 0) - return false; - - return true; -} - - -void Notification_Class_common_reporting_function( - BACNET_EVENT_NOTIFICATION_DATA * event_data) -{ - /* Fill the parameters common for all types of events. */ - - NOTIFICATION_CLASS_INFO *CurrentNotify; - BACNET_DESTINATION *pBacDest; - uint32_t notify_index; - uint8_t index; - - - notify_index = Notification_Class_Instance_To_Index( - event_data->notificationClass); - - if (notify_index < MAX_NOTIFICATION_CLASSES) - CurrentNotify = &NC_Info[notify_index]; - else - return; - - - /* Initiating Device Identifier */ - event_data->initiatingObjectIdentifier.type = OBJECT_DEVICE; - event_data->initiatingObjectIdentifier.instance = - Device_Object_Instance_Number(); - - /* Priority and AckRequired*/ - switch (event_data->toState) - { - case EVENT_STATE_NORMAL: - event_data->priority = - CurrentNotify->Priority[EVENT_STATE_NORMAL]; - event_data->ackRequired = (CurrentNotify->Ack_Required & - TRANSITION_TO_NORMAL_MASKED) ? true : false; - break; - - case EVENT_STATE_FAULT: - event_data->priority = - CurrentNotify->Priority[EVENT_STATE_FAULT]; - event_data->ackRequired = (CurrentNotify->Ack_Required & - TRANSITION_TO_FAULT_MASKED) ? true : false; - break; - - case EVENT_STATE_OFFNORMAL: - case EVENT_STATE_HIGH_LIMIT: - case EVENT_STATE_LOW_LIMIT: - event_data->priority = - CurrentNotify->Priority[EVENT_STATE_OFFNORMAL]; - event_data->ackRequired = (CurrentNotify->Ack_Required & - TRANSITION_TO_OFFNORMAL_MASKED) ? true : false; - break; - - default: /* shouldn't happen */ - break; - } - - /* send notifications for active recipients */ - /* pointer to first recipient */ - pBacDest = &CurrentNotify->Recipient_List[0]; - for (index = 0; index < NC_MAX_RECIPIENTS; index++, pBacDest++) - { - /* check if recipient is defined */ - if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_NOTINITIALIZED) - break; /* recipient doesn't defined - end of list */ - - if (IsRecipientActive(pBacDest, event_data->toState) == true) - { - BACNET_ADDRESS dest; - uint32_t device_id; - unsigned max_apdu; - - /* Process Identifier */ - event_data->processIdentifier = pBacDest->ProcessIdentifier; - - /* send notification */ - if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { - /* send notification to the specified device */ - device_id = pBacDest->Recipient._.DeviceIdentifier; - - if (pBacDest->ConfirmedNotify == true) - Send_CEvent_Notify(device_id, event_data); - else if (address_get_by_device(device_id, &max_apdu, &dest)) - Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, &dest); - } - else if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { - /* send notification to the address indicated */ - if (pBacDest->ConfirmedNotify == true) { - if (address_get_device_id(&dest, &device_id)) - Send_CEvent_Notify(device_id, event_data); - } - else { - dest = pBacDest->Recipient._.Address; - Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, &dest); - } - } - } - } -} - -/* This function tries to find the addresses of the defined devices. */ -/* It should be called periodically (example once per minute). */ -void Notification_Class_find_recipient(void) -{ - NOTIFICATION_CLASS_INFO *CurrentNotify; - BACNET_DESTINATION *pBacDest; - BACNET_ADDRESS src = {0}; - unsigned max_apdu = 0; - uint32_t notify_index; - uint32_t DeviceID; - uint8_t idx; - - - for (notify_index = 0; notify_index < MAX_NOTIFICATION_CLASSES; notify_index++) - { - /* pointer to current notification */ - CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(notify_index)]; - /* pointer to first recipient */ - pBacDest = &CurrentNotify->Recipient_List[0]; - for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++, pBacDest++) - { - if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { - /* Device ID */ - DeviceID = 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) { - - } - } - } -} -#endif /* defined(INTRINSIC_REPORTING) */ +/************************************************************************** +* +* Copyright (C) 2011 Krzysztof Malorny +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*********************************************************************/ +#include +#include +#include +#include + +#include "address.h" +#include "bacdef.h" +#include "bacdcode.h" +#include "bacenum.h" +#include "bacapp.h" +#include "client.h" +#include "config.h" +#include "device.h" +#include "event.h" +#include "handlers.h" +#include "txbuf.h" +#include "wp.h" +#include "nc.h" + + +#ifndef MAX_NOTIFICATION_CLASSES +#define MAX_NOTIFICATION_CLASSES 2 +#endif + + +#if defined(INTRINSIC_REPORTING) +static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES]; + +/* These three arrays are used by the ReadPropertyMultiple handler */ +static const int Notification_Properties_Required[] = { + PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_NOTIFICATION_CLASS, + PROP_PRIORITY, + PROP_ACK_REQUIRED, + PROP_RECIPIENT_LIST, + -1 +}; + +static const int Notification_Properties_Optional[] = { + PROP_DESCRIPTION, + -1 +}; + +static const int Notification_Properties_Proprietary[] = { + -1 +}; + +void Notification_Class_Property_Lists( + const int **pRequired, + const int **pOptional, + const int **pProprietary) +{ + if (pRequired) + *pRequired = Notification_Properties_Required; + if (pOptional) + *pOptional = Notification_Properties_Optional; + if (pProprietary) + *pProprietary = Notification_Properties_Proprietary; + return; +} + +void Notification_Class_Init( + void) +{ + uint8_t NotifyIdx = 0; + + for (NotifyIdx = 0; NotifyIdx < MAX_NOTIFICATION_CLASSES; NotifyIdx++) { + /* init with zeros */ + memset(&NC_Info[NotifyIdx], 0x00, sizeof(NOTIFICATION_CLASS_INFO)); + /* set the basic parameters */ + NC_Info[NotifyIdx].Ack_Required = 0; + NC_Info[NotifyIdx].Priority[0] = 255; /* The lowest priority for Normal message. */ + NC_Info[NotifyIdx].Priority[1] = 255; /* The lowest priority for Normal message. */ + NC_Info[NotifyIdx].Priority[2] = 255; /* The lowest priority for Normal message. */ + } + + return; +} + + +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then you need validate that the */ +/* given instance exists */ +bool Notification_Class_Valid_Instance( + uint32_t object_instance) +{ + unsigned int index; + + index = Notification_Class_Instance_To_Index(object_instance); + if (index < MAX_NOTIFICATION_CLASSES) + return true; + + return false; +} + +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then count how many you have */ +unsigned Notification_Class_Count( + void) +{ + return MAX_NOTIFICATION_CLASSES; +} + +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then you need to return the instance */ +/* that correlates to the correct index */ +uint32_t Notification_Class_Index_To_Instance( + unsigned index) +{ + return index; +} + +/* we simply have 0-n object instances. Yours might be */ +/* more complex, and then you need to return the index */ +/* that correlates to the correct instance number */ +unsigned Notification_Class_Instance_To_Index( + uint32_t object_instance) +{ + unsigned index = MAX_NOTIFICATION_CLASSES; + + if (object_instance < MAX_NOTIFICATION_CLASSES) + index = object_instance; + + return index; +} + +bool Notification_Class_Object_Name( + uint32_t object_instance, + BACNET_CHARACTER_STRING * object_name) +{ + static char text_string[32] = ""; /* okay for single thread */ + unsigned int index; + bool status = false; + + index = Notification_Class_Instance_To_Index(object_instance); + if (index < MAX_NOTIFICATION_CLASSES) { + sprintf(text_string, "NOTIFICATION CLASS %lu", (unsigned long) index); + status = characterstring_init_ansi(object_name, text_string); + } + + return status; +} + + + +int Notification_Class_Read_Property( + BACNET_READ_PROPERTY_DATA * rpdata) +{ + NOTIFICATION_CLASS_INFO *CurrentNotify; + BACNET_CHARACTER_STRING char_string; + BACNET_OCTET_STRING octet_string; + BACNET_BIT_STRING bit_string; + uint8_t *apdu = NULL; + uint8_t u8Val; + int idx; + int apdu_len = 0; /* return value */ + + + if ((rpdata == NULL) || (rpdata->application_data == NULL) || + (rpdata->application_data_len == 0)) { + return 0; + } + + apdu = rpdata->application_data; + CurrentNotify = + &NC_Info[Notification_Class_Instance_To_Index(rpdata-> + object_instance)]; + + switch (rpdata->object_property) { + case PROP_OBJECT_IDENTIFIER: + apdu_len = + encode_application_object_id(&apdu[0], + OBJECT_NOTIFICATION_CLASS, rpdata->object_instance); + break; + + case PROP_OBJECT_NAME: + case PROP_DESCRIPTION: + Notification_Class_Object_Name(rpdata->object_instance, + &char_string); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + + case PROP_OBJECT_TYPE: + apdu_len = + encode_application_enumerated(&apdu[0], + OBJECT_NOTIFICATION_CLASS); + break; + + case PROP_NOTIFICATION_CLASS: + apdu_len += + encode_application_unsigned(&apdu[0], rpdata->object_instance); + break; + + case PROP_PRIORITY: + if (rpdata->array_index == 0) + apdu_len += encode_application_unsigned(&apdu[0], 3); + else { + if (rpdata->array_index == BACNET_ARRAY_ALL) { + /* TO-OFFNORMAL */ + apdu_len += + encode_application_unsigned(&apdu[apdu_len], + CurrentNotify->Priority[0]); + /* TO-FAULT */ + apdu_len += + encode_application_unsigned(&apdu[apdu_len], + CurrentNotify->Priority[1]); + /* TO-NORMAL */ + apdu_len += + encode_application_unsigned(&apdu[apdu_len], + CurrentNotify->Priority[2]); + } else if (rpdata->array_index <= 3) { + apdu_len += + encode_application_unsigned(&apdu[apdu_len], + CurrentNotify->Priority[rpdata->array_index - 1]); + } else { + rpdata->error_class = ERROR_CLASS_PROPERTY; + rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; + apdu_len = -1; + } + } + break; + + case PROP_ACK_REQUIRED: + u8Val = CurrentNotify->Ack_Required; + + bitstring_init(&bit_string); + bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, + (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false); + bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, + (u8Val & TRANSITION_TO_FAULT_MASKED) ? true : false); + bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, + (u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false); + /* encode bitstring */ + apdu_len += + encode_application_bitstring(&apdu[apdu_len], &bit_string); + break; + + case PROP_RECIPIENT_LIST: + /* encode all entry of Recipient_List */ + for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) { + BACNET_DESTINATION *RecipientEntry; + int i = 0; + + /* get pointer of current element for Recipient_List - easier for use */ + RecipientEntry = &CurrentNotify->Recipient_List[idx]; + if (RecipientEntry->Recipient.RecipientType != + RECIPIENT_TYPE_NOTINITIALIZED) { + /* Valid Days - BACnetDaysOfWeek - [bitstring] monday-sunday */ + u8Val = 0x01; + bitstring_init(&bit_string); + + for (i = 0; i < MAX_BACNET_DAYS_OF_WEEK; i++) { + if (RecipientEntry->ValidDays & u8Val) + bitstring_set_bit(&bit_string, i, true); + else + bitstring_set_bit(&bit_string, i, false); + u8Val <<= 1; /* next day */ + } + apdu_len += + encode_application_bitstring(&apdu[apdu_len], + &bit_string); + + /* From Time */ + apdu_len += + encode_application_time(&apdu[apdu_len], + &RecipientEntry->FromTime); + + /* To Time */ + apdu_len += + encode_application_time(&apdu[apdu_len], + &RecipientEntry->ToTime); + + /* + BACnetRecipient ::= CHOICE { + device [0] BACnetObjectIdentifier, + address [1] BACnetAddress + } */ + + /* CHOICE - device [0] BACnetObjectIdentifier */ + if (RecipientEntry->Recipient.RecipientType == + RECIPIENT_TYPE_DEVICE) { + apdu_len += + encode_context_object_id(&apdu[apdu_len], 0, + OBJECT_DEVICE, + RecipientEntry->Recipient._.DeviceIdentifier); + } + /* CHOICE - address [1] BACnetAddress */ + else if (RecipientEntry->Recipient.RecipientType == + RECIPIENT_TYPE_ADDRESS) { + /* opening tag 1 */ + apdu_len += encode_opening_tag(&apdu[apdu_len], 1); + /* network-number Unsigned16, */ + apdu_len += + encode_application_unsigned(&apdu[apdu_len], + RecipientEntry->Recipient._.Address.net); + + /* mac-address OCTET STRING */ + if (RecipientEntry->Recipient._.Address.net) { + octetstring_init(&octet_string, + RecipientEntry->Recipient._.Address.adr, + RecipientEntry->Recipient._.Address.len); + } else { + octetstring_init(&octet_string, + RecipientEntry->Recipient._.Address.mac, + RecipientEntry->Recipient._.Address.mac_len); + } + apdu_len += + encode_application_octet_string(&apdu[apdu_len], + &octet_string); + + /* closing tag 1 */ + apdu_len += encode_closing_tag(&apdu[apdu_len], 1); + + } else {; + } /* shouldn't happen */ + + /* Process Identifier - Unsigned32 */ + apdu_len += + encode_application_unsigned(&apdu[apdu_len], + RecipientEntry->ProcessIdentifier); + + /* Issue Confirmed Notifications - boolean */ + apdu_len += + encode_application_boolean(&apdu[apdu_len], + RecipientEntry->ConfirmedNotify); + + /* Transitions - BACnet Event Transition Bits [bitstring] */ + u8Val = RecipientEntry->Transitions; + + bitstring_init(&bit_string); + bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, + (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : + false); + bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, + (u8Val & TRANSITION_TO_FAULT_MASKED) ? true : false); + bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, + (u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false); + + apdu_len += + encode_application_bitstring(&apdu[apdu_len], + &bit_string); + } + } + break; + + default: + rpdata->error_class = ERROR_CLASS_PROPERTY; + rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; + apdu_len = -1; + break; + } + + /* only array properties can have array options */ + if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { + rpdata->error_class = ERROR_CLASS_PROPERTY; + rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; + apdu_len = BACNET_STATUS_ERROR; + } + + return apdu_len; +} + + +bool Notification_Class_Write_Property( + BACNET_WRITE_PROPERTY_DATA * wp_data) +{ + NOTIFICATION_CLASS_INFO *CurrentNotify; + NOTIFICATION_CLASS_INFO TmpNotify; + BACNET_APPLICATION_DATA_VALUE value; + bool status = false; + int iOffset = 0; + uint8_t idx = 0; + int len = 0; + + + + CurrentNotify = + &NC_Info[Notification_Class_Instance_To_Index(wp_data-> + object_instance)]; + + /* decode the some of the request + */ + len = + bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); + + switch (wp_data->object_property) { + case PROP_PRIORITY: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); + + if (status) { + if (wp_data->array_index == 0) { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; + } else if (wp_data->array_index == BACNET_ARRAY_ALL) { + /* FIXME: wite all array */ + } else if (wp_data->array_index <= 3) { + CurrentNotify->Priority[wp_data->array_index - 1] = + value.type.Unsigned_Int; + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; + } + } + break; + + case PROP_ACK_REQUIRED: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BIT_STRING, + &wp_data->error_class, &wp_data->error_code); + + if (status) { + if (value.type.Bit_String.bits_used == 3) { + CurrentNotify->Ack_Required = + value.type.Bit_String.value[0]; + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + } + } + break; + + case PROP_RECIPIENT_LIST: + + memset(&TmpNotify, 0x00, sizeof(NOTIFICATION_CLASS_INFO)); + + /* decode all packed */ + 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); + + if ((len == 0) || + (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { + /* Bad decode, wrong tag or following required parameter missing */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + + if (value.type.Bit_String.bits_used == MAX_BACNET_DAYS_OF_WEEK) + /* store value */ + TmpNotify.Recipient_List[idx].ValidDays = + value.type.Bit_String.value[0]; + else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_OTHER; + return false; + } + + iOffset += len; + /* Decode From Time */ + len = + 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 */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + /* store value */ + TmpNotify.Recipient_List[idx].FromTime = value.type.Time; + + iOffset += len; + /* Decode To Time */ + len = + 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 */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + /* store value */ + TmpNotify.Recipient_List[idx].ToTime = value.type.Time; + + iOffset += len; + /* context tag [0] - Device */ + if (decode_is_context_tag(&wp_data->application_data[iOffset], + 0)) { + TmpNotify.Recipient_List[idx].Recipient.RecipientType = + RECIPIENT_TYPE_DEVICE; + /* Decode Network Number */ + len = + bacapp_decode_context_data(&wp_data-> + application_data[iOffset], + wp_data->application_data_len, &value, + PROP_RECIPIENT_LIST); + + if ((len == 0) || + (value.tag != BACNET_APPLICATION_TAG_OBJECT_ID)) { + /* Bad decode, wrong tag or following required parameter missing */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + /* store value */ + 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)) { + iOffset++; + TmpNotify.Recipient_List[idx].Recipient.RecipientType = + RECIPIENT_TYPE_ADDRESS; + /* Decode Network Number */ + len = + 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)) { + /* Bad decode, wrong tag or following required parameter missing */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + /* store value */ + TmpNotify.Recipient_List[idx].Recipient._.Address.net = + value.type.Unsigned_Int; + + iOffset += len; + /* Decode Address */ + len = + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], + wp_data->application_data_len, &value); + + if ((len == 0) || + (value.tag != BACNET_APPLICATION_TAG_OCTET_STRING)) { + /* Bad decode, wrong tag or following required parameter missing */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + 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, + 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, + value.type.Octet_String.length); + TmpNotify.Recipient_List[idx].Recipient._.Address.len = + value.type.Octet_String.length; + } + + iOffset += len; + /* closing tag [1] - Recipient */ + if (decode_is_closing_tag_number(&wp_data-> + application_data[iOffset], 1)) + iOffset++; + else { + /* Bad decode, wrong tag or following required parameter missing */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + } else { + /* Bad decode, wrong tag or following required parameter missing */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + + /* Process Identifier */ + len = + 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)) { + /* Bad decode, wrong tag or following required parameter missing */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + /* store value */ + TmpNotify.Recipient_List[idx].ProcessIdentifier = + value.type.Unsigned_Int; + + iOffset += len; + /* Issue Confirmed Notifications */ + len = + bacapp_decode_application_data(&wp_data-> + application_data[iOffset], wp_data->application_data_len, + &value); + + if ((len == 0) || + (value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) { + /* Bad decode, wrong tag or following required parameter missing */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + /* store value */ + TmpNotify.Recipient_List[idx].ConfirmedNotify = + value.type.Boolean; + + iOffset += len; + /* Transitions */ + len = + 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)) { + /* Bad decode, wrong tag or following required parameter missing */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; + return false; + } + + if (value.type.Bit_String.bits_used == + MAX_BACNET_EVENT_TRANSITION) + /* store value */ + TmpNotify.Recipient_List[idx].Transitions = + value.type.Bit_String.value[0]; + else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_OTHER; + return false; + } + iOffset += len; + + /* Increasing element of list */ + if (++idx >= NC_MAX_RECIPIENTS) { + wp_data->error_class = ERROR_CLASS_RESOURCES; + wp_data->error_code = + ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; + return false; + } + } + + /* Decoded all recipient list */ + /* copy elements from temporary object */ + for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) { + BACNET_ADDRESS src = { 0 }; + unsigned max_apdu = 0; + int32_t DeviceID; + + CurrentNotify->Recipient_List[idx] = + TmpNotify.Recipient_List[idx]; + + if (CurrentNotify->Recipient_List[idx].Recipient. + RecipientType == RECIPIENT_TYPE_DEVICE) { + /* copy Device_ID */ + DeviceID = + CurrentNotify->Recipient_List[idx].Recipient._. + DeviceIdentifier; + address_bind_request(DeviceID, &max_apdu, &src); + + } 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); */ + } + } + + status = true; + + break; + + default: + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_UNKNOWN_PROPERTY; + break; + } + + return status; +} + + +void Notification_Class_Get_Priorities( + uint32_t Object_Instance, + uint32_t * pPriorityArray) +{ + NOTIFICATION_CLASS_INFO *CurrentNotify; + uint32_t object_index; + int i; + + object_index = Notification_Class_Instance_To_Index(Object_Instance); + + if (object_index < MAX_NOTIFICATION_CLASSES) + CurrentNotify = &NC_Info[object_index]; + else { + for (i = 0; i < 3; i++) + pPriorityArray[i] = 255; + return; /* unknown object */ + } + + for (i = 0; i < 3; i++) + pPriorityArray[i] = CurrentNotify->Priority[i]; +} + + +static bool IsRecipientActive( + BACNET_DESTINATION * pBacDest, + uint8_t EventToState) +{ + BACNET_DATE_TIME DateTime; + + /* valid Transitions */ + switch (EventToState) { + case EVENT_STATE_OFFNORMAL: + case EVENT_STATE_HIGH_LIMIT: + case EVENT_STATE_LOW_LIMIT: + if (!(pBacDest->Transitions & TRANSITION_TO_OFFNORMAL_MASKED)) + return false; + break; + + case EVENT_STATE_FAULT: + if (!(pBacDest->Transitions & TRANSITION_TO_FAULT_MASKED)) + return false; + break; + + case EVENT_STATE_NORMAL: + if (!(pBacDest->Transitions & TRANSITION_TO_NORMAL_MASKED)) + return false; + break; + + default: + return false; /* shouldn't happen */ + } + + /* get actual date and time */ + Device_getCurrentDateTime(&DateTime); + + /* valid Days */ + if (!((0x01 << (DateTime.date.wday - 1)) & pBacDest->ValidDays)) + return false; + + /* valid FromTime */ + if (datetime_compare_time(&DateTime.time, &pBacDest->FromTime) < 0) + return false; + + /* valid ToTime */ + if (datetime_compare_time(&pBacDest->ToTime, &DateTime.time) < 0) + return false; + + return true; +} + + +void Notification_Class_common_reporting_function( + BACNET_EVENT_NOTIFICATION_DATA * event_data) +{ + /* Fill the parameters common for all types of events. */ + + NOTIFICATION_CLASS_INFO *CurrentNotify; + BACNET_DESTINATION *pBacDest; + uint32_t notify_index; + uint8_t index; + + + notify_index = + Notification_Class_Instance_To_Index(event_data->notificationClass); + + if (notify_index < MAX_NOTIFICATION_CLASSES) + CurrentNotify = &NC_Info[notify_index]; + else + return; + + + /* Initiating Device Identifier */ + event_data->initiatingObjectIdentifier.type = OBJECT_DEVICE; + event_data->initiatingObjectIdentifier.instance = + Device_Object_Instance_Number(); + + /* Priority and AckRequired */ + switch (event_data->toState) { + case EVENT_STATE_NORMAL: + event_data->priority = CurrentNotify->Priority[EVENT_STATE_NORMAL]; + event_data->ackRequired = + (CurrentNotify-> + Ack_Required & TRANSITION_TO_NORMAL_MASKED) ? true : false; + break; + + case EVENT_STATE_FAULT: + event_data->priority = CurrentNotify->Priority[EVENT_STATE_FAULT]; + event_data->ackRequired = + (CurrentNotify-> + Ack_Required & TRANSITION_TO_FAULT_MASKED) ? true : false; + break; + + case EVENT_STATE_OFFNORMAL: + case EVENT_STATE_HIGH_LIMIT: + case EVENT_STATE_LOW_LIMIT: + event_data->priority = + CurrentNotify->Priority[EVENT_STATE_OFFNORMAL]; + event_data->ackRequired = + (CurrentNotify-> + Ack_Required & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false; + break; + + default: /* shouldn't happen */ + break; + } + + /* send notifications for active recipients */ + /* pointer to first recipient */ + pBacDest = &CurrentNotify->Recipient_List[0]; + for (index = 0; index < NC_MAX_RECIPIENTS; index++, pBacDest++) { + /* check if recipient is defined */ + if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_NOTINITIALIZED) + break; /* recipient doesn't defined - end of list */ + + if (IsRecipientActive(pBacDest, event_data->toState) == true) { + BACNET_ADDRESS dest; + uint32_t device_id; + unsigned max_apdu; + + /* Process Identifier */ + event_data->processIdentifier = pBacDest->ProcessIdentifier; + + /* send notification */ + if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { + /* send notification to the specified device */ + device_id = pBacDest->Recipient._.DeviceIdentifier; + + if (pBacDest->ConfirmedNotify == true) + Send_CEvent_Notify(device_id, event_data); + else if (address_get_by_device(device_id, &max_apdu, &dest)) + Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, + &dest); + } else if (pBacDest->Recipient.RecipientType == + RECIPIENT_TYPE_ADDRESS) { + /* send notification to the address indicated */ + if (pBacDest->ConfirmedNotify == true) { + if (address_get_device_id(&dest, &device_id)) + Send_CEvent_Notify(device_id, event_data); + } else { + dest = pBacDest->Recipient._.Address; + Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, + &dest); + } + } + } + } +} + +/* This function tries to find the addresses of the defined devices. */ +/* It should be called periodically (example once per minute). */ +void Notification_Class_find_recipient( + void) +{ + NOTIFICATION_CLASS_INFO *CurrentNotify; + BACNET_DESTINATION *pBacDest; + BACNET_ADDRESS src = { 0 }; + unsigned max_apdu = 0; + uint32_t notify_index; + uint32_t DeviceID; + uint8_t idx; + + + for (notify_index = 0; notify_index < MAX_NOTIFICATION_CLASSES; + notify_index++) { + /* pointer to current notification */ + CurrentNotify = + &NC_Info[Notification_Class_Instance_To_Index(notify_index)]; + /* pointer to first recipient */ + pBacDest = &CurrentNotify->Recipient_List[0]; + for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++, pBacDest++) { + if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == + RECIPIENT_TYPE_DEVICE) { + /* Device ID */ + DeviceID = + 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) { + + } + } + } +} +#endif /* defined(INTRINSIC_REPORTING) */ diff --git a/bacnet-stack/demo/object/nc.h b/bacnet-stack/demo/object/nc.h index 235edee7..14552f3f 100644 --- a/bacnet-stack/demo/object/nc.h +++ b/bacnet-stack/demo/object/nc.h @@ -38,11 +38,11 @@ extern "C" { /* max "length" of recipient_list */ #define NC_MAX_RECIPIENTS 10 /* Recipient types */ -typedef enum { - RECIPIENT_TYPE_NOTINITIALIZED = 0, - RECIPIENT_TYPE_DEVICE = 1, - RECIPIENT_TYPE_ADDRESS = 2 -} NC_RECIPIENT_TYPE; + typedef enum { + RECIPIENT_TYPE_NOTINITIALIZED = 0, + RECIPIENT_TYPE_DEVICE = 1, + RECIPIENT_TYPE_ADDRESS = 2 + } NC_RECIPIENT_TYPE; #if defined(INTRINSIC_REPORTING) @@ -53,47 +53,47 @@ BACnetRecipient ::= CHOICE { address [1] BACnetAddress } */ -typedef struct BACnet_Recipient { - uint8_t RecipientType; /* Type of Recipient */ - union { - uint32_t DeviceIdentifier; - BACNET_ADDRESS Address; - } _; -} BACNET_RECIPIENT; + typedef struct BACnet_Recipient { + uint8_t RecipientType; /* Type of Recipient */ + union { + uint32_t DeviceIdentifier; + BACNET_ADDRESS Address; + } _; + } BACNET_RECIPIENT; /* BACnetDestination structure */ -typedef struct BACnet_Destination { - uint8_t ValidDays; - BACNET_TIME FromTime; - BACNET_TIME ToTime; - BACNET_RECIPIENT Recipient; - uint32_t ProcessIdentifier; - uint8_t Transitions; - bool ConfirmedNotify; -} BACNET_DESTINATION; + typedef struct BACnet_Destination { + uint8_t ValidDays; + BACNET_TIME FromTime; + BACNET_TIME ToTime; + BACNET_RECIPIENT Recipient; + uint32_t ProcessIdentifier; + uint8_t Transitions; + bool ConfirmedNotify; + } BACNET_DESTINATION; /* Structure containing configuration for a Notification Class */ -typedef struct Notification_Class_info { - uint8_t Priority[3]; /* BACnetARRAY[3] of Unsigned */ - uint8_t Ack_Required; /* BACnetEventTransitionBits */ - BACNET_DESTINATION Recipient_List[NC_MAX_RECIPIENTS]; /* List of BACnetDestination */ -} NOTIFICATION_CLASS_INFO; + typedef struct Notification_Class_info { + uint8_t Priority[3]; /* BACnetARRAY[3] of Unsigned */ + uint8_t Ack_Required; /* BACnetEventTransitionBits */ + BACNET_DESTINATION Recipient_List[NC_MAX_RECIPIENTS]; /* List of BACnetDestination */ + } NOTIFICATION_CLASS_INFO; /* Indicates whether the transaction has been confirmed */ -typedef struct Acked_info { - bool bIsAcked; /* true when transitions is acked */ - BACNET_DATE_TIME Time_Stamp;/* time stamp of when a alarm was generated */ -} ACKED_INFO; + typedef struct Acked_info { + bool bIsAcked; /* true when transitions is acked */ + BACNET_DATE_TIME Time_Stamp; /* time stamp of when a alarm was generated */ + } ACKED_INFO; /* Information needed to send AckNotification */ -typedef struct Ack_Notification { - bool bSendAckNotify; /* true if need to send AckNotification */ - uint8_t EventState; -} ACK_NOTIFICATION; + typedef struct Ack_Notification { + bool bSendAckNotify; /* true if need to send AckNotification */ + uint8_t EventState; + } ACK_NOTIFICATION; @@ -102,43 +102,46 @@ typedef struct Ack_Notification { const int **pOptional, const int **pProprietary); - void Notification_Class_Init(void); + void Notification_Class_Init( + void); bool Notification_Class_Valid_Instance( - uint32_t object_instance); - unsigned Notification_Class_Count(void); - uint32_t Notification_Class_Index_To_Instance(unsigned index); + uint32_t object_instance); + unsigned Notification_Class_Count( + void); + uint32_t Notification_Class_Index_To_Instance( + unsigned index); unsigned Notification_Class_Instance_To_Index( - uint32_t object_instance); + uint32_t object_instance); bool Notification_Class_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + uint32_t object_instance, + BACNET_CHARACTER_STRING * object_name); int Notification_Class_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Notification_Class_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data); + BACNET_WRITE_PROPERTY_DATA * wp_data); void Notification_Class_Get_Priorities( - uint32_t Object_Instance, uint32_t *pPriorityArray); + uint32_t Object_Instance, + uint32_t * pPriorityArray); void Notification_Class_common_reporting_function( - BACNET_EVENT_NOTIFICATION_DATA * event_data); + BACNET_EVENT_NOTIFICATION_DATA * event_data); - void Notification_Class_find_recipient(void); + void Notification_Class_find_recipient( + void); #endif /* defined(INTRINSIC_REPORTING) */ #ifdef __cplusplus } #endif /* __cplusplus */ - #define NOTIFICATION_CLASS_OBJ_FUNCTIONS \ OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, Notification_Class_Count, \ Notification_Class_Index_To_Instance, Notification_Class_Valid_Instance, \ Notification_Class_Object_Name, Notification_Class_Read_Property, \ Notification_Class_Write_Property, Notification_Class_Property_Lists, \ NULL, NULL, NULL - #endif /* NC_H */ diff --git a/bacnet-stack/demo/object/trendlog.c b/bacnet-stack/demo/object/trendlog.c index 4f0f97b2..05e01f6f 100644 --- a/bacnet-stack/demo/object/trendlog.c +++ b/bacnet-stack/demo/object/trendlog.c @@ -259,7 +259,7 @@ void Trend_Log_Init( */ bool Trend_Log_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ bool status = false; @@ -736,9 +736,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 */ @@ -755,8 +755,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)) { @@ -1098,8 +1098,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/object/trendlog.h b/bacnet-stack/demo/object/trendlog.h index 0b3247f8..336686bc 100644 --- a/bacnet-stack/demo/object/trendlog.h +++ b/bacnet-stack/demo/object/trendlog.h @@ -141,7 +141,7 @@ extern "C" { bool Trend_Log_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); int Trend_Log_Read_Property( BACNET_READ_PROPERTY_DATA * rpdata); diff --git a/bacnet-stack/demo/ptransfer/main.c b/bacnet-stack/demo/ptransfer/main.c index aecb4c97..add47fe3 100644 --- a/bacnet-stack/demo/ptransfer/main.c +++ b/bacnet-stack/demo/ptransfer/main.c @@ -70,7 +70,7 @@ uint8_t Send_Private_Transfer_Request( static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/readfile/main.c b/bacnet-stack/demo/readfile/main.c index b837445a..8b655c2f 100644 --- a/bacnet-stack/demo/readfile/main.c +++ b/bacnet-stack/demo/readfile/main.c @@ -54,7 +54,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/readprop/main.c b/bacnet-stack/demo/readprop/main.c index 90accbd3..e7b1a5c9 100644 --- a/bacnet-stack/demo/readprop/main.c +++ b/bacnet-stack/demo/readprop/main.c @@ -57,7 +57,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/readpropm/main.c b/bacnet-stack/demo/readpropm/main.c index 23be2a7a..9649ab72 100644 --- a/bacnet-stack/demo/readpropm/main.c +++ b/bacnet-stack/demo/readpropm/main.c @@ -58,7 +58,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/readrange/main.c b/bacnet-stack/demo/readrange/main.c index b7eb0681..d7e68bd4 100644 --- a/bacnet-stack/demo/readrange/main.c +++ b/bacnet-stack/demo/readrange/main.c @@ -84,7 +84,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/reinit/main.c b/bacnet-stack/demo/reinit/main.c index f97f0128..cb9361b7 100644 --- a/bacnet-stack/demo/reinit/main.c +++ b/bacnet-stack/demo/reinit/main.c @@ -55,7 +55,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/server/main.c b/bacnet-stack/demo/server/main.c index 0b3871d4..a5dee4fd 100644 --- a/bacnet-stack/demo/server/main.c +++ b/bacnet-stack/demo/server/main.c @@ -123,7 +123,7 @@ static void Init_Service_Handlers( handler_alarm_ack); apdu_set_confirmed_handler(SERVICE_CONFIRMED_GET_EVENT_INFORMATION, handler_get_event_information); -#endif /* defined(INTRINSIC_REPORTING) */ +#endif /* defined(INTRINSIC_REPORTING) */ } /** Handler registered with atexit() inside main function to, well, cleanup. @@ -156,7 +156,7 @@ int main( 0 }; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ time_t last_seconds = 0; time_t current_seconds = 0; uint32_t elapsed_seconds = 0; diff --git a/bacnet-stack/demo/timesync/main.c b/bacnet-stack/demo/timesync/main.c index df5ec9ee..5b178b2d 100644 --- a/bacnet-stack/demo/timesync/main.c +++ b/bacnet-stack/demo/timesync/main.c @@ -50,7 +50,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/ucov/main.c b/bacnet-stack/demo/ucov/main.c index 947c5658..052d9727 100644 --- a/bacnet-stack/demo/ucov/main.c +++ b/bacnet-stack/demo/ucov/main.c @@ -54,7 +54,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; static void Init_Service_Handlers( diff --git a/bacnet-stack/demo/whohas/main.c b/bacnet-stack/demo/whohas/main.c index 2c4f686b..859133e2 100644 --- a/bacnet-stack/demo/whohas/main.c +++ b/bacnet-stack/demo/whohas/main.c @@ -54,7 +54,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/whois/main.c b/bacnet-stack/demo/whois/main.c index a744b043..72f26714 100644 --- a/bacnet-stack/demo/whois/main.c +++ b/bacnet-stack/demo/whois/main.c @@ -54,7 +54,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/writefile/main.c b/bacnet-stack/demo/writefile/main.c index f234ed63..30836d79 100644 --- a/bacnet-stack/demo/writefile/main.c +++ b/bacnet-stack/demo/writefile/main.c @@ -54,7 +54,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/demo/writeprop/main.c b/bacnet-stack/demo/writeprop/main.c index c6a5915c..baf33c50 100644 --- a/bacnet-stack/demo/writeprop/main.c +++ b/bacnet-stack/demo/writeprop/main.c @@ -60,7 +60,7 @@ static object_functions_t Object_Table[] = { {DEVICE_OBJ_FUNCTIONS}, {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL} + NULL, NULL, NULL, NULL, NULL, NULL} }; /* buffer used for receive */ diff --git a/bacnet-stack/include/bacenum.h b/bacnet-stack/include/bacenum.h index a2dc66af..6f96be12 100644 --- a/bacnet-stack/include/bacenum.h +++ b/bacnet-stack/include/bacenum.h @@ -964,7 +964,7 @@ typedef enum { } BACNET_VT_CLASS; typedef enum { - CHARACTER_ANSI_X34 = 0, /* deprecated */ + CHARACTER_ANSI_X34 = 0, /* deprecated */ CHARACTER_UTF8 = 0, CHARACTER_MS_DBCS = 1, CHARACTER_JISC_6226 = 2, diff --git a/bacnet-stack/include/client.h b/bacnet-stack/include/client.h index 89d84fd6..0a55c533 100644 --- a/bacnet-stack/include/client.h +++ b/bacnet-stack/include/client.h @@ -97,7 +97,7 @@ extern "C" { uint32_t device_id, BACNET_OBJECT_TYPE object_type, uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name); + BACNET_CHARACTER_STRING * object_name); int Send_UCOV_Notify( uint8_t * buffer, diff --git a/bacnet-stack/include/datalink.h b/bacnet-stack/include/datalink.h index f8311f38..d931ea4c 100644 --- a/bacnet-stack/include/datalink.h +++ b/bacnet-stack/include/datalink.h @@ -143,7 +143,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/dcc.h b/bacnet-stack/include/dcc.h index fbc5fd0c..5c2e5471 100644 --- a/bacnet-stack/include/dcc.h +++ b/bacnet-stack/include/dcc.h @@ -104,7 +104,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 @@ -117,7 +117,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 6c819803..fa93d75f 100644 --- a/bacnet-stack/include/event.h +++ b/bacnet-stack/include/event.h @@ -213,7 +213,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 @@ -230,7 +230,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/readrange.h b/bacnet-stack/include/readrange.h index 795ddd5c..feb123ff 100644 --- a/bacnet-stack/include/readrange.h +++ b/bacnet-stack/include/readrange.h @@ -172,7 +172,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/rp.h b/bacnet-stack/include/rp.h index 52333aff..dc8cf5f4 100644 --- a/bacnet-stack/include/rp.h +++ b/bacnet-stack/include/rp.h @@ -135,7 +135,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/whohas.h b/bacnet-stack/include/whohas.h index f6ddeda5..a68f0cfd 100644 --- a/bacnet-stack/include/whohas.h +++ b/bacnet-stack/include/whohas.h @@ -41,7 +41,7 @@ typedef struct BACnet_Who_Has_Data { int32_t low_limit; /* deviceInstanceRange */ int32_t high_limit; - bool is_object_name; /* true if a string */ + bool is_object_name; /* true if a string */ union { BACNET_OBJECT_ID identifier; BACNET_CHARACTER_STRING name; diff --git a/bacnet-stack/include/wpm.h b/bacnet-stack/include/wpm.h index 7d75ee00..7a607530 100644 --- a/bacnet-stack/include/wpm.h +++ b/bacnet-stack/include/wpm.h @@ -38,19 +38,26 @@ extern "C" { /* decode the service request only */ - int wpm_decode_object_id(uint8_t * apdu, uint16_t apdu_len, - BACNET_WRITE_PROPERTY_DATA * data); - - int wpm_decode_object_property(uint8_t * apdu, - uint16_t apdu_len, - BACNET_WRITE_PROPERTY_DATA * wpm_data); + int wpm_decode_object_id( + uint8_t * apdu, + uint16_t apdu_len, + BACNET_WRITE_PROPERTY_DATA * data); + + int wpm_decode_object_property( + uint8_t * apdu, + uint16_t apdu_len, + BACNET_WRITE_PROPERTY_DATA * wpm_data); /* encode service */ - int wpm_ack_encode_apdu_init(uint8_t *apdu, uint8_t invoke_id); + int wpm_ack_encode_apdu_init( + uint8_t * apdu, + uint8_t invoke_id); - int wpm_error_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, - BACNET_WRITE_PROPERTY_DATA * wp_data); + int wpm_error_ack_encode_apdu( + uint8_t * apdu, + uint8_t invoke_id, + BACNET_WRITE_PROPERTY_DATA * wp_data); #ifdef __cplusplus diff --git a/bacnet-stack/ports/at91sam7s/ai.c b/bacnet-stack/ports/at91sam7s/ai.c index c0721e14..9eff02a5 100644 --- a/bacnet-stack/ports/at91sam7s/ai.c +++ b/bacnet-stack/ports/at91sam7s/ai.c @@ -109,7 +109,7 @@ uint32_t Analog_Input_Index_To_Instance( bool Analog_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[16] = "AI-0"; /* okay for single thread */ bool status = false; diff --git a/bacnet-stack/ports/at91sam7s/av.c b/bacnet-stack/ports/at91sam7s/av.c index 26770208..1a876179 100644 --- a/bacnet-stack/ports/at91sam7s/av.c +++ b/bacnet-stack/ports/at91sam7s/av.c @@ -167,7 +167,7 @@ float Analog_Value_Present_Value( bool Analog_Value_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[16] = "AV-0"; /* okay for single thread */ bool status = false; @@ -360,8 +360,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/bi.c b/bacnet-stack/ports/at91sam7s/bi.c index fbb2a232..4e79c527 100644 --- a/bacnet-stack/ports/at91sam7s/bi.c +++ b/bacnet-stack/ports/at91sam7s/bi.c @@ -146,7 +146,7 @@ BACNET_BINARY_PV Binary_Input_Present_Value( bool Binary_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[16] = "BI-0"; /* okay for single thread */ bool status = false; diff --git a/bacnet-stack/ports/at91sam7s/bv.c b/bacnet-stack/ports/at91sam7s/bv.c index 10b7312a..d0a91595 100644 --- a/bacnet-stack/ports/at91sam7s/bv.c +++ b/bacnet-stack/ports/at91sam7s/bv.c @@ -141,7 +141,7 @@ static BACNET_BINARY_PV Binary_Value_Present_Value( /* note: the object name must be unique within this device */ bool Binary_Value_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[16] = "BV-0"; /* okay for single thread */ bool status = false; @@ -271,8 +271,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 4c213f69..2fc33618 100644 --- a/bacnet-stack/ports/at91sam7s/device.c +++ b/bacnet-stack/ports/at91sam7s/device.c @@ -179,8 +179,7 @@ static int Read_Property_Common( break; case PROP_OBJECT_NAME: if (pObject->Object_Name) { - (void)pObject->Object_Name( - rpdata->object_instance, + (void) pObject->Object_Name(rpdata->object_instance, &char_string); } else { characterstring_init_ansi(&char_string, ""); @@ -213,13 +212,13 @@ int Device_Read_Property( /* initialize the default return values */ pObject = Device_Objects_Find_Functions(rpdata->object_type); if (pObject) { - if (pObject->Object_Valid_Instance && - pObject->Object_Valid_Instance(rpdata->object_instance)) { + if (pObject->Object_Valid_Instance && + pObject->Object_Valid_Instance(rpdata->object_instance)) { apdu_len = Read_Property_Common(pObject, rpdata); - } else { - rpdata->error_class = ERROR_CLASS_OBJECT; - rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; - } + } else { + rpdata->error_class = ERROR_CLASS_OBJECT; + rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; + } } else { rpdata->error_class = ERROR_CLASS_OBJECT; rpdata->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; @@ -237,18 +236,18 @@ bool Device_Write_Property( /* initialize the default return values */ pObject = Device_Objects_Find_Functions(wp_data->object_type); if (pObject) { - if (pObject->Object_Valid_Instance && - pObject->Object_Valid_Instance(wp_data->object_instance)) { - if (pObject->Object_Write_Property) { - status = pObject->Object_Write_Property(wp_data); - } else { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; - } + if (pObject->Object_Valid_Instance && + pObject->Object_Valid_Instance(wp_data->object_instance)) { + if (pObject->Object_Write_Property) { + status = pObject->Object_Write_Property(wp_data); } else { - wp_data->error_class = ERROR_CLASS_OBJECT; - wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; } + } else { + wp_data->error_class = ERROR_CLASS_OBJECT; + wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; + } } else { wp_data->error_class = ERROR_CLASS_OBJECT; wp_data->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; @@ -340,7 +339,7 @@ uint32_t Device_Index_To_Instance( bool Device_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { bool status = false; @@ -352,7 +351,7 @@ bool Device_Object_Name( } bool Device_Set_Object_Name( - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { bool status = false; /*return value */ @@ -394,13 +393,13 @@ BACNET_REINITIALIZED_STATE Device_Reinitialized_State( } void Device_Init( - object_functions_t * object_table) + object_functions_t * object_table) { struct my_object_functions *pObject = NULL; /* we don't use the object table passed in since there is extra stuff we don't need in there. */ - (void)object_table; + (void) object_table; /* our local object table */ pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { @@ -440,7 +439,7 @@ bool Device_Valid_Object_Instance_Number( /* BACnet allows for a wildcard instance number */ return ((Object_Instance_Number == object_id) || (object_id == BACNET_MAX_INSTANCE)); - } +} BACNET_DEVICE_STATUS Device_System_Status( void) @@ -461,25 +460,25 @@ int Device_Set_System_Status( } return result; - } +} uint16_t Device_Vendor_Identifier( void) { return BACNET_VENDOR_ID; - } +} BACNET_SEGMENTATION Device_Segmentation_Supported( void) { return SEGMENTATION_NONE; - } +} uint32_t Device_Database_Revision( void) { return Database_Revision; - } +} void Device_Inc_Database_Revision( void) @@ -542,7 +541,7 @@ bool Device_Object_List_Identifier( } bool Device_Valid_Object_Name( - BACNET_CHARACTER_STRING *object_name1, + BACNET_CHARACTER_STRING * object_name1, int *object_type, uint32_t * object_instance) { @@ -561,7 +560,7 @@ bool Device_Valid_Object_Name( pObject = Device_Objects_Find_Functions(type); if ((pObject != NULL) && (pObject->Object_Name != NULL) && (pObject->Object_Name(instance, &object_name2) && - characterstring_same(object_name1, &object_name2))) { + characterstring_same(object_name1, &object_name2))) { found = true; if (object_type) { *object_type = type; @@ -581,7 +580,7 @@ bool Device_Valid_Object_Id( int object_type, uint32_t object_instance) { - bool status = false; /* return value */ + bool status = false; /* return value */ struct my_object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -595,7 +594,7 @@ bool Device_Valid_Object_Id( bool Device_Object_Name_Copy( int object_type, uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { struct my_object_functions *pObject = NULL; bool found = false; @@ -851,8 +850,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 { @@ -895,22 +894,20 @@ bool Device_Write_Property_Local( break; case PROP_OBJECT_NAME: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - length = characterstring_length( - &value.type.Character_String); + length = characterstring_length(&value.type.Character_String); if (length < characterstring_capacity(&My_Object_Name)) { - encoding = characterstring_encoding( - &value.type.Character_String); + encoding = + 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)) { status = false; 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); } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; diff --git a/bacnet-stack/ports/at91sam7s/dlmstp.c b/bacnet-stack/ports/at91sam7s/dlmstp.c index 80f0173b..e613bbe1 100644 --- a/bacnet-stack/ports/at91sam7s/dlmstp.c +++ b/bacnet-stack/ports/at91sam7s/dlmstp.c @@ -1177,9 +1177,9 @@ static void MSTP_Slave_Node_FSM( } else if (MSTP_Flag.ReceivePacketPending) { if (Ringbuf_Empty(&PDU_Queue)) { /* 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 - this is a local matter), then no reply is possible. */ + within Treply_delay after the reception of the final octet + of the requesting frame (the mechanism used to determine + this is a local matter), then no reply is possible. */ MSTP_Flag.ReceivePacketPending = false; } else { pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue); diff --git a/bacnet-stack/ports/atmega168/bv.c b/bacnet-stack/ports/atmega168/bv.c index 86d74cb3..67b8abf7 100644 --- a/bacnet-stack/ports/atmega168/bv.c +++ b/bacnet-stack/ports/atmega168/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/atmega168/device.c b/bacnet-stack/ports/atmega168/device.c index b97f71ae..d7eede8b 100644 --- a/bacnet-stack/ports/atmega168/device.c +++ b/bacnet-stack/ports/atmega168/device.c @@ -380,8 +380,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 86d74cb3..67b8abf7 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/adc-block.c b/bacnet-stack/ports/bdk-atxx4-mstp/adc-block.c index ae2bde77..a41899ad 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/adc-block.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/adc-block.c @@ -72,18 +72,18 @@ void adc_enable( * Notes: none **************************************************/ uint8_t adc_result_8bit( - uint8_t channel) /* 0..7 = ADC0..ADC7, respectively */ -{ - uint8_t value = 0; /* return value */ + uint8_t channel) +{ /* 0..7 = ADC0..ADC7, respectively */ + uint8_t value = 0; /* return value */ - while ( ADCSRA & (1 << ADSC) ) ; + while (ADCSRA & (1 << ADSC)); ADMUX = channel | (1 << ADLAR) | (0 << REFS1) | (1 << REFS0); /* Delay needed for the stabilization of the ADC input voltage */ _delay_us(10); /* Start the analog to digital conversion */ ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADIF) | ADPS_8BIT; /* Wait for the analog to digital conversion to complete */ - while ( (ADCSRA & (1 << ADIF)) == 0 ) ; + while ((ADCSRA & (1 << ADIF)) == 0); value = ADCH; return value; @@ -95,18 +95,18 @@ uint8_t adc_result_8bit( * Notes: none **************************************************/ uint16_t adc_result_10bit( - uint8_t channel) /* 0..7 = ADC0..ADC7, respectively */ -{ + uint8_t channel) +{ /* 0..7 = ADC0..ADC7, respectively */ uint16_t value = 0; /* return value */ - while ( ADCSRA & (1 << ADSC) ) ; + while (ADCSRA & (1 << ADSC)); ADMUX = channel | (0 << ADLAR) | (0 << REFS1) | (1 << REFS0); /* Delay needed for the stabilization of the ADC input voltage */ _delay_us(10); /* Start the analog to digital conversion */ ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADIF) | ADPS_10BIT; /* Wait for the analog to digital conversion to complete */ - while ( (ADCSRA & (1 << ADIF)) == 0 ) ; + while ((ADCSRA & (1 << ADIF)) == 0); value = ADCL; value |= (ADCH << 8); @@ -118,11 +118,12 @@ uint16_t adc_result_10bit( * Returns: none * Notes: none **************************************************/ -void adc_init(void) +void adc_init( + void) { /* configure ADC for Free Running Mode - ADTS = 000 */ /* AIN1 is applied to the negative input of the Analog Comparator - ACME */ - BITMASK_CLEAR(ADCSRB, _BV(ACME)|_BV(ADTS2)|_BV(ADTS1)|_BV(ADTS0)); + BITMASK_CLEAR(ADCSRB, _BV(ACME) | _BV(ADTS2) | _BV(ADTS1) | _BV(ADTS0)); /* Digital input not needed on ADC0, so disable it to save power */ BIT_SET(DIDR0, ADC0D); /* Clear the Power Reduction bit to enable ADC */ diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/ai.c b/bacnet-stack/ports/bdk-atxx4-mstp/ai.c index d17b34ec..c166173c 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/ai.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/ai.c @@ -111,7 +111,7 @@ uint32_t Analog_Input_Index_To_Instance( bool Analog_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32]; /* okay for single thread */ bool status = false; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/av.c b/bacnet-stack/ports/bdk-atxx4-mstp/av.c index 25897cc7..e29c96d8 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/av.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/av.c @@ -177,7 +177,7 @@ bool Analog_Value_Present_Value_Set( /* note: the object name must be unique within this device */ bool Analog_Value_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32] = ""; /* okay for single thread */ unsigned index = 0; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bi.c b/bacnet-stack/ports/bdk-atxx4-mstp/bi.c index 7fa4a972..3f40fd29 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bi.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bi.c @@ -159,7 +159,7 @@ bool Binary_Input_Present_Value_Set( bool Binary_Input_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32]; /* okay for single thread */ bool status = false; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bname.c b/bacnet-stack/ports/bdk-atxx4-mstp/bname.c index 09d913ee..539c73bc 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bname.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bname.c @@ -39,26 +39,36 @@ by Jeff Bezanson placed in the public domain Fall 2005 */ static const char trailingBytesForUTF8[256] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, + 4, 4, 4, 5, 5, 5, 5 }; /* based on the valid_utf8 routine from the PCRE library by Philip Hazel length is in bytes, since without knowing whether the string is valid it's hard to know how many characters there are! */ -static int utf8_isvalid(const char *str, int length) +static int utf8_isvalid( + const char *str, + int length) { - const unsigned char *p, *pend = (unsigned char*)str + length; + const unsigned char *p, *pend = (unsigned char *) str + length; unsigned char c; int ab; - for (p = (unsigned char*)str; p < pend; p++) { + for (p = (unsigned char *) str; p < pend; p++) { c = *p; /* null in middle of string */ if (c == 0) { @@ -84,37 +94,42 @@ static int utf8_isvalid(const char *str, int length) } /* Check for overlong sequences for each different length */ switch (ab) { - /* Check for xx00 000x */ - case 1: - if ((c & 0x3e) == 0) return 0; - continue; /* We know there aren't any more bytes to check */ + /* Check for xx00 000x */ + case 1: + if ((c & 0x3e) == 0) + return 0; + continue; /* We know there aren't any more bytes to check */ - /* Check for 1110 0000, xx0x xxxx */ - case 2: - if (c == 0xe0 && (*p & 0x20) == 0) return 0; - break; + /* Check for 1110 0000, xx0x xxxx */ + case 2: + if (c == 0xe0 && (*p & 0x20) == 0) + return 0; + break; - /* Check for 1111 0000, xx00 xxxx */ - case 3: - if (c == 0xf0 && (*p & 0x30) == 0) return 0; - break; + /* Check for 1111 0000, xx00 xxxx */ + case 3: + if (c == 0xf0 && (*p & 0x30) == 0) + return 0; + break; - /* Check for 1111 1000, xx00 0xxx */ - case 4: - if (c == 0xf8 && (*p & 0x38) == 0) return 0; - break; + /* Check for 1111 1000, xx00 0xxx */ + case 4: + if (c == 0xf8 && (*p & 0x38) == 0) + return 0; + break; - /* Check for leading 0xfe or 0xff, - and then for 1111 1100, xx00 00xx */ - case 5: - if (c == 0xfe || c == 0xff || - (c == 0xfc && (*p & 0x3c) == 0)) return 0; - break; + /* Check for leading 0xfe or 0xff, + and then for 1111 1100, xx00 00xx */ + case 5: + if (c == 0xfe || c == 0xff || (c == 0xfc && (*p & 0x3c) == 0)) + return 0; + break; } /* Check for valid bytes after the 2nd, if any; all must start 10 */ while (--ab > 0) { - if ((*(++p) & 0xc0) != 0x80) return 0; + if ((*(++p) & 0xc0) != 0x80) + return 0; } } @@ -144,7 +159,7 @@ static bool bacnet_name_isvalid( bool bacnet_name_set( uint16_t offset, - BACNET_CHARACTER_STRING *char_string) + BACNET_CHARACTER_STRING * char_string) { uint8_t encoding = 0; uint8_t length = 0; @@ -154,15 +169,9 @@ bool bacnet_name_set( encoding = characterstring_encoding(char_string); str = characterstring_value(char_string); if (bacnet_name_isvalid(encoding, length, str)) { - seeprom_bytes_write( - NV_EEPROM_NAME_LENGTH(offset), - &length, 1); - seeprom_bytes_write( - NV_EEPROM_NAME_ENCODING(offset), - &encoding, 1); - seeprom_bytes_write( - NV_EEPROM_NAME_STRING(offset), - (uint8_t *)str, + seeprom_bytes_write(NV_EEPROM_NAME_LENGTH(offset), &length, 1); + seeprom_bytes_write(NV_EEPROM_NAME_ENCODING(offset), &encoding, 1); + seeprom_bytes_write(NV_EEPROM_NAME_STRING(offset), (uint8_t *) str, length); return true; } @@ -172,9 +181,9 @@ bool bacnet_name_set( bool bacnet_name_write( uint16_t offset, - 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) { bool status = false; size_t length = 0; @@ -215,9 +224,9 @@ bool bacnet_name_write( /* no required minumum length or duplicate checking */ bool bacnet_name_write_other( uint16_t offset, - 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) { bool status = false; size_t length = 0; @@ -247,16 +256,16 @@ bool bacnet_name_write_other( void bacnet_name_init( uint16_t offset, - BACNET_CHARACTER_STRING *char_string, + BACNET_CHARACTER_STRING * char_string, char *default_string) { characterstring_init_ansi(char_string, default_string); - (void)bacnet_name_set(offset, char_string); + (void) bacnet_name_set(offset, char_string); } void bacnet_name( uint16_t offset, - BACNET_CHARACTER_STRING *char_string, + BACNET_CHARACTER_STRING * char_string, char *default_string) { uint8_t encoding = 0; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bname.h b/bacnet-stack/ports/bdk-atxx4-mstp/bname.h index fc89fed6..2c352f69 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bname.h +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bname.h @@ -33,26 +33,26 @@ extern "C" { bool bacnet_name_set( uint16_t eeprom_offset, - BACNET_CHARACTER_STRING *char_string); + BACNET_CHARACTER_STRING * char_string); void bacnet_name_init( uint16_t eeprom_offset, - BACNET_CHARACTER_STRING *char_string, + BACNET_CHARACTER_STRING * char_string, char *default_string); void bacnet_name( uint16_t eeprom_offset, - BACNET_CHARACTER_STRING *char_string, + BACNET_CHARACTER_STRING * char_string, char *default_string); bool bacnet_name_write( uint16_t offset, - 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); /* no required minumum length or duplicate checking */ bool bacnet_name_write_other( uint16_t offset, - 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); #ifdef __cplusplus } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c index 2ec608c2..1741890d 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c @@ -231,7 +231,7 @@ bool Binary_Output_Out_Of_Service( /* note: the object name must be unique within this device */ bool Binary_Output_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[32]; /* okay for single thread */ bool status = false; @@ -439,8 +439,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/device.c b/bacnet-stack/ports/bdk-atxx4-mstp/device.c index 39cc63f5..50c54a2b 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/device.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/device.c @@ -195,12 +195,12 @@ static int Read_Property_Common( } else { characterstring_init_ansi(&char_string, ""); if (pObject->Object_Name) { - (void)pObject->Object_Name( - rpdata->object_instance, + (void) pObject->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: @@ -361,7 +361,8 @@ uint32_t Device_Index_To_Instance( return Object_Instance_Number; } -static char *Device_Name_Default(void) +static char *Device_Name_Default( + void) { static char text_string[32]; /* okay for single thread */ @@ -372,15 +373,12 @@ static char *Device_Name_Default(void) bool Device_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { bool status = false; if (object_instance == Object_Instance_Number) { - bacnet_name( - NV_EEPROM_DEVICE_NAME, - object_name, - Device_Name_Default()); + bacnet_name(NV_EEPROM_DEVICE_NAME, object_name, Device_Name_Default()); status = true; } @@ -416,13 +414,13 @@ BACNET_REINITIALIZED_STATE Device_Reinitialized_State( } void Device_Init( - object_functions_t * object_table) + object_functions_t * object_table) { struct my_object_functions *pObject = NULL; /* we don't use the object table passed in since there is extra stuff we don't need in there. */ - (void)object_table; + (void) object_table; /* our local object table */ pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { @@ -574,7 +572,7 @@ bool Device_Object_List_Identifier( } bool Device_Valid_Object_Name( - BACNET_CHARACTER_STRING *object_name1, + BACNET_CHARACTER_STRING * object_name1, int *object_type, uint32_t * object_instance) { @@ -593,7 +591,7 @@ bool Device_Valid_Object_Name( pObject = Device_Objects_Find_Functions(type); if ((pObject != NULL) && (pObject->Object_Name != NULL) && (pObject->Object_Name(instance, &object_name2) && - characterstring_same(object_name1, &object_name2))) { + characterstring_same(object_name1, &object_name2))) { found = true; if (object_type) { *object_type = type; @@ -613,7 +611,7 @@ bool Device_Valid_Object_Id( int object_type, uint32_t object_instance) { - bool status = false; /* return value */ + bool status = false; /* return value */ struct my_object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -627,7 +625,7 @@ bool Device_Valid_Object_Id( bool Device_Object_Name_Copy( int object_type, uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { struct my_object_functions *pObject = NULL; bool found = false; @@ -673,17 +671,13 @@ int Device_Read_Property_Local( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_DESCRIPTION: - bacnet_name( - NV_EEPROM_DEVICE_DESCRIPTION, - &char_string, + bacnet_name(NV_EEPROM_DEVICE_DESCRIPTION, &char_string, "BACnet Development Kit"); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_LOCATION: - bacnet_name( - NV_EEPROM_DEVICE_LOCATION, - &char_string, + bacnet_name(NV_EEPROM_DEVICE_LOCATION, &char_string, "default location"); apdu_len = encode_application_character_string(&apdu[0], &char_string); @@ -881,8 +875,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 { @@ -925,10 +919,9 @@ bool Device_Write_Property_Local( break; case PROP_OBJECT_NAME: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - status = bacnet_name_write( - NV_EEPROM_DEVICE_NAME, - &value.type.Character_String, - &wp_data->error_class, + status = + bacnet_name_write(NV_EEPROM_DEVICE_NAME, + &value.type.Character_String, &wp_data->error_class, &wp_data->error_code); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -937,10 +930,9 @@ bool Device_Write_Property_Local( break; case PROP_DESCRIPTION: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - status = bacnet_name_write_other( - NV_EEPROM_DEVICE_DESCRIPTION, - &value.type.Character_String, - &wp_data->error_class, + status = + bacnet_name_write_other(NV_EEPROM_DEVICE_DESCRIPTION, + &value.type.Character_String, &wp_data->error_class, &wp_data->error_code); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -949,10 +941,9 @@ bool Device_Write_Property_Local( break; case PROP_LOCATION: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - status = bacnet_name_write_other( - NV_EEPROM_DEVICE_LOCATION, - &value.type.Character_String, - &wp_data->error_class, + status = + bacnet_name_write_other(NV_EEPROM_DEVICE_LOCATION, + &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/linux/dlmstp.c b/bacnet-stack/ports/linux/dlmstp.c index 61d4b482..9f235930 100644 --- a/bacnet-stack/ports/linux/dlmstp.c +++ b/bacnet-stack/ports/linux/dlmstp.c @@ -91,7 +91,8 @@ static uint8_t Tusage_timeout = 60; static struct timeval start; -static uint32_t Timer_Silence(void) +static uint32_t Timer_Silence( + void) { struct timeval now, tmp_diff; int32_t res; @@ -105,14 +106,16 @@ static uint32_t Timer_Silence(void) return (res >= 0 ? res : -res); } -static void Timer_Silence_Reset(void) +static void Timer_Silence_Reset( + void) { pthread_mutex_lock(&Timer_Mutex); gettimeofday(&start, NULL); pthread_mutex_unlock(&Timer_Mutex); } -static void get_abstime(struct timespec *abstime, +static void get_abstime( + struct timespec *abstime, unsigned long milliseconds) { struct timeval now, offset, result; @@ -125,7 +128,8 @@ static void get_abstime(struct timespec *abstime, abstime->tv_nsec = result.tv_usec * 1000; } -void dlmstp_cleanup(void) +void dlmstp_cleanup( + void) { pthread_cond_destroy(&Received_Frame_Flag); pthread_cond_destroy(&Receive_Packet_Flag); @@ -137,12 +141,10 @@ void dlmstp_cleanup(void) } /* returns number of bytes sent on success, zero on failure */ -int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */ - +int dlmstp_send_pdu( + BACNET_ADDRESS * dest, /* destination address */ BACNET_NPDU_DATA * npdu_data, /* network information */ - uint8_t * pdu, /* any data to be sent - may be null */ - unsigned pdu_len) { /* number of bytes of data */ int bytes_sent = 0; @@ -168,12 +170,10 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */ return bytes_sent; } -uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */ - +uint16_t dlmstp_receive( + BACNET_ADDRESS * src, /* source address */ uint8_t * pdu, /* PDU data */ - uint16_t max_pdu, /* amount of space available in the PDU */ - unsigned timeout) { /* milliseconds to wait for a packet */ uint16_t pdu_len = 0; @@ -207,7 +207,8 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */ return pdu_len; } -static void *dlmstp_master_fsm_task(void *pArg) +static void *dlmstp_master_fsm_task( + void *pArg) { uint32_t silence = 0; bool run_master = false; @@ -252,7 +253,8 @@ static void *dlmstp_master_fsm_task(void *pArg) return NULL; } -void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, +void dlmstp_fill_bacnet_address( + BACNET_ADDRESS * src, uint8_t mstp_address) { int i = 0; @@ -277,7 +279,8 @@ void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, } /* for the MS/TP state machine to use for putting received data */ -uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port) +uint16_t MSTP_Put_Receive( + volatile struct mstp_port_struct_t *mstp_port) { uint16_t pdu_len = 0; @@ -300,7 +303,8 @@ uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port) /* for the MS/TP state machine to use for getting data to send */ /* Return: amount of PDU data */ -uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t * mstp_port, +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; @@ -329,7 +333,8 @@ uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t * mstp_port, return pdu_len; } -static bool dlmstp_compare_data_expecting_reply(uint8_t * request_pdu, +static bool dlmstp_compare_data_expecting_reply( + uint8_t * request_pdu, uint16_t request_pdu_len, uint8_t src_address, uint8_t * reply_pdu, @@ -445,7 +450,8 @@ static bool dlmstp_compare_data_expecting_reply(uint8_t * request_pdu, } /* Get the reply to a DATA_EXPECTING_REPLY frame, or nothing */ -uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t * mstp_port, +uint16_t MSTP_Get_Reply( + volatile struct mstp_port_struct_t * mstp_port, unsigned timeout) { /* milliseconds to wait for a packet */ uint16_t pdu_len = 0; /* return value */ @@ -484,7 +490,8 @@ uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t * mstp_port, return pdu_len; } -void dlmstp_set_mac_address(uint8_t mac_address) +void dlmstp_set_mac_address( + uint8_t mac_address) { /* Master Nodes can only have address 0-127 */ if (mac_address <= 127) { @@ -501,7 +508,8 @@ void dlmstp_set_mac_address(uint8_t mac_address) return; } -uint8_t dlmstp_mac_address(void) +uint8_t dlmstp_mac_address( + void) { return MSTP_Port.This_Station; } @@ -513,7 +521,8 @@ uint8_t dlmstp_mac_address(void) /* nodes. This may be used to allocate more or less of the available link */ /* 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(uint8_t max_info_frames) +void dlmstp_set_max_info_frames( + uint8_t max_info_frames) { if (max_info_frames >= 1) { MSTP_Port.Nmax_info_frames = max_info_frames; @@ -527,7 +536,8 @@ void dlmstp_set_max_info_frames(uint8_t max_info_frames) return; } -uint8_t dlmstp_max_info_frames(void) +uint8_t dlmstp_max_info_frames( + void) { return MSTP_Port.Nmax_info_frames; } @@ -537,7 +547,8 @@ uint8_t dlmstp_max_info_frames(void) /* allowable address for master nodes. The value of Max_Master shall be */ /* 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(uint8_t max_master) +void dlmstp_set_max_master( + uint8_t max_master) { if (max_master <= 127) { if (MSTP_Port.This_Station <= max_master) { @@ -553,23 +564,27 @@ void dlmstp_set_max_master(uint8_t max_master) return; } -uint8_t dlmstp_max_master(void) +uint8_t dlmstp_max_master( + void) { return MSTP_Port.Nmax_master; } /* RS485 Baud Rate 9600, 19200, 38400, 57600, 115200 */ -void dlmstp_set_baud_rate(uint32_t baud) +void dlmstp_set_baud_rate( + uint32_t baud) { RS485_Set_Baud_Rate(baud); } -uint32_t dlmstp_baud_rate(void) +uint32_t dlmstp_baud_rate( + void) { return RS485_Get_Baud_Rate(); } -void dlmstp_get_my_address(BACNET_ADDRESS * my_address) +void dlmstp_get_my_address( + BACNET_ADDRESS * my_address) { int i = 0; /* counter */ @@ -584,7 +599,8 @@ void dlmstp_get_my_address(BACNET_ADDRESS * my_address) return; } -void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) +void dlmstp_get_broadcast_address( + BACNET_ADDRESS * dest) { /* destination address */ int i = 0; /* counter */ @@ -601,7 +617,8 @@ void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) return; } -bool dlmstp_init(char *ifname) +bool dlmstp_init( + char *ifname) { unsigned long hThread = 0; int rv = 0; @@ -665,10 +682,9 @@ bool dlmstp_init(char *ifname) #ifdef TEST_DLMSTP #include -void apdu_handler(BACNET_ADDRESS * src, /* source address */ - +void apdu_handler( + BACNET_ADDRESS * src, /* source address */ uint8_t * apdu, /* APDU data */ - uint16_t pdu_len) { /* for confirmed messages */ (void) src; @@ -678,7 +694,8 @@ void apdu_handler(BACNET_ADDRESS * src, /* source address */ static char *Network_Interface = NULL; -int main(int argc, +int main( + int argc, char *argv[]) { uint16_t pdu_len = 0; diff --git a/bacnet-stack/ports/linux/rs485.c b/bacnet-stack/ports/linux/rs485.c index 96639486..bcdc626e 100644 --- a/bacnet-stack/ports/linux/rs485.c +++ b/bacnet-stack/ports/linux/rs485.c @@ -95,7 +95,8 @@ static pthread_mutex_t Reader_Mutex, IOMutex; #define _POSIX_SOURCE 1 /* POSIX compliant source */ -static void *rs485_read_task(void *arg) +static void *rs485_read_task( + void *arg) { uint8_t buf[1 << 11]; int count, n; @@ -134,7 +135,8 @@ static void *rs485_read_task(void *arg) * ALGORITHM: none * NOTES: none *********************************************************************/ -void RS485_Set_Interface(char *ifname) +void RS485_Set_Interface( + char *ifname) { /* note: expects a constant char, or char from the heap */ if (ifname) { @@ -148,7 +150,8 @@ void RS485_Set_Interface(char *ifname) * ALGORITHM: none * NOTES: none *********************************************************************/ -const char *RS485_Interface(void) +const char *RS485_Interface( + void) { return RS485_Port_Name; } @@ -159,7 +162,8 @@ const char *RS485_Interface(void) * ALGORITHM: none * NOTES: none *****************************************************************************/ -uint32_t RS485_Get_Baud_Rate(void) +uint32_t RS485_Get_Baud_Rate( + void) { switch (RS485_Baud) { case B19200: @@ -182,7 +186,8 @@ uint32_t RS485_Get_Baud_Rate(void) * ALGORITHM: none * NOTES: none *****************************************************************************/ -bool RS485_Set_Baud_Rate(uint32_t baud) +bool RS485_Set_Baud_Rate( + uint32_t baud) { bool valid = true; @@ -215,10 +220,9 @@ bool RS485_Set_Baud_Rate(uint32_t baud) } /* Transmits a Frame on the wire */ -void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ - +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) */ ssize_t written = 0; @@ -246,7 +250,8 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port } /* called by timer, interrupt(?) or other thread */ -void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) +void RS485_Check_UART_Data( + volatile struct mstp_port_struct_t *mstp_port) { if (mstp_port->ReceiveError == true) { /* wait for state machine to clear this */ @@ -266,7 +271,8 @@ void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) } } -void RS485_Cleanup(void) +void RS485_Cleanup( + void) { /* restore the old port settings */ tcsetattr(RS485_Handle, TCSANOW, &RS485_oldtio); @@ -276,7 +282,8 @@ void RS485_Cleanup(void) } -void RS485_Initialize(void) +void RS485_Initialize( + void) { struct termios newtio; unsigned long hThread = 0; @@ -333,7 +340,8 @@ void RS485_Initialize(void) #ifdef TEST_RS485 #include -int main(int argc, +int main( + int argc, char *argv[]) { uint8_t buf[8]; diff --git a/bacnet-stack/ports/pic18f6720/av.c b/bacnet-stack/ports/pic18f6720/av.c index 1626523a..b9f3b96d 100644 --- a/bacnet-stack/ports/pic18f6720/av.c +++ b/bacnet-stack/ports/pic18f6720/av.c @@ -325,8 +325,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 c559301f..d79c192c 100644 --- a/bacnet-stack/ports/pic18f6720/bv.c +++ b/bacnet-stack/ports/pic18f6720/bv.c @@ -237,8 +237,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 16bda6f7..a37e2bf5 100644 --- a/bacnet-stack/ports/pic18f6720/device.c +++ b/bacnet-stack/ports/pic18f6720/device.c @@ -510,8 +510,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/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 a8af0727..6f438d01 100644 --- a/bacnet-stack/ports/rx62n/bo.c +++ b/bacnet-stack/ports/rx62n/bo.c @@ -429,8 +429,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 d2eb3d0c..123a9464 100644 --- a/bacnet-stack/ports/rx62n/device.c +++ b/bacnet-stack/ports/rx62n/device.c @@ -35,7 +35,7 @@ #include "apdu.h" #include "wp.h" /* WriteProperty handling */ #include "rp.h" /* ReadProperty handling */ -#include "dcc.h" /* DeviceCommunicationControl handling */ +#include "dcc.h" /* DeviceCommunicationControl handling */ #include "version.h" #include "device.h" /* me */ #include "handlers.h" @@ -833,8 +833,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 { @@ -868,8 +868,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; @@ -878,8 +878,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; @@ -889,8 +889,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/rx62n/ethernet.c b/bacnet-stack/ports/rx62n/ethernet.c index d54ba2a1..082cd6c9 100644 --- a/bacnet-stack/ports/rx62n/ethernet.c +++ b/bacnet-stack/ports/rx62n/ethernet.c @@ -44,7 +44,7 @@ static uint8_t Ethernet_Broadcast[MAX_MAC_LEN] = /* The OUI 00-00-5E has been allocated to IANA. */ /* my local device data - MAC address */ static uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = - {0x00, 0x00, 0x5E, 0x00, 0x00, 0x01}; + { 0x00, 0x00, 0x5E, 0x00, 0x00, 0x01 }; /* status of the link */ static int32_t Ethernet_Status = R_ETHER_ERROR; @@ -167,7 +167,7 @@ uint16_t ethernet_receive( if (!ethernet_valid()) return 0; - received_bytes = R_Ether_Read(0, (void *)buf); + received_bytes = R_Ether_Read(0, (void *) buf); if (received_bytes == 0) return 0; diff --git a/bacnet-stack/ports/rx62n/led.c b/bacnet-stack/ports/rx62n/led.c index ce68789e..9b7e9539 100644 --- a/bacnet-stack/ports/rx62n/led.c +++ b/bacnet-stack/ports/rx62n/led.c @@ -42,40 +42,40 @@ void led_on( { switch (index) { case 4: - R_IO_PORT_Write( LED4, LED_ON ); + R_IO_PORT_Write(LED4, LED_ON); break; case 5: - R_IO_PORT_Write( LED5, LED_ON ); + R_IO_PORT_Write(LED5, LED_ON); break; case 6: - R_IO_PORT_Write( LED6, LED_ON ); + R_IO_PORT_Write(LED6, LED_ON); break; case 7: - R_IO_PORT_Write( LED7, LED_ON ); + R_IO_PORT_Write(LED7, LED_ON); break; case 8: - R_IO_PORT_Write( LED8, LED_ON ); + R_IO_PORT_Write(LED8, LED_ON); break; case 9: - R_IO_PORT_Write( LED9, LED_ON ); + R_IO_PORT_Write(LED9, LED_ON); break; case 10: - R_IO_PORT_Write( LED10, LED_ON ); + R_IO_PORT_Write(LED10, LED_ON); break; case 11: - R_IO_PORT_Write( LED11, LED_ON ); + R_IO_PORT_Write(LED11, LED_ON); break; case 12: - R_IO_PORT_Write( LED12, LED_ON ); + R_IO_PORT_Write(LED12, LED_ON); break; case 13: - R_IO_PORT_Write( LED13, LED_ON ); + R_IO_PORT_Write(LED13, LED_ON); break; case 14: - R_IO_PORT_Write( LED14, LED_ON ); + R_IO_PORT_Write(LED14, LED_ON); break; case 15: - R_IO_PORT_Write( LED15, LED_ON ); + R_IO_PORT_Write(LED15, LED_ON); break; default: break; @@ -96,40 +96,40 @@ void led_off( { switch (index) { case 4: - R_IO_PORT_Write( LED4, LED_OFF ); + R_IO_PORT_Write(LED4, LED_OFF); break; case 5: - R_IO_PORT_Write( LED5, LED_OFF ); + R_IO_PORT_Write(LED5, LED_OFF); break; case 6: - R_IO_PORT_Write( LED6, LED_OFF ); + R_IO_PORT_Write(LED6, LED_OFF); break; case 7: - R_IO_PORT_Write( LED7, LED_OFF ); + R_IO_PORT_Write(LED7, LED_OFF); break; case 8: - R_IO_PORT_Write( LED8, LED_OFF ); + R_IO_PORT_Write(LED8, LED_OFF); break; case 9: - R_IO_PORT_Write( LED9, LED_OFF ); + R_IO_PORT_Write(LED9, LED_OFF); break; case 10: - R_IO_PORT_Write( LED10, LED_OFF ); + R_IO_PORT_Write(LED10, LED_OFF); break; case 11: - R_IO_PORT_Write( LED11, LED_OFF ); + R_IO_PORT_Write(LED11, LED_OFF); break; case 12: - R_IO_PORT_Write( LED12, LED_OFF ); + R_IO_PORT_Write(LED12, LED_OFF); break; case 13: - R_IO_PORT_Write( LED13, LED_OFF ); + R_IO_PORT_Write(LED13, LED_OFF); break; case 14: - R_IO_PORT_Write( LED14, LED_OFF ); + R_IO_PORT_Write(LED14, LED_OFF); break; case 15: - R_IO_PORT_Write( LED15, LED_OFF ); + R_IO_PORT_Write(LED15, LED_OFF); break; default: break; @@ -228,7 +228,7 @@ void led_init( void) { unsigned i = 0; - + for (i = 0; i < MAX_LEDS; i++) { led_on_interval(i, 500); } diff --git a/bacnet-stack/ports/rx62n/main.c b/bacnet-stack/ports/rx62n/main.c index a71b7a17..46288df5 100644 --- a/bacnet-stack/ports/rx62n/main.c +++ b/bacnet-stack/ports/rx62n/main.c @@ -30,7 +30,8 @@ #include "led.h" /** Main function of BACnet demo for RX62N evaluation board */ -int main(void) +int main( + void) { InitialiseLCD(); ClearLCD(); diff --git a/bacnet-stack/ports/rx62n/timer-hdw.c b/bacnet-stack/ports/rx62n/timer-hdw.c index 6c99ec86..37513125 100644 --- a/bacnet-stack/ports/rx62n/timer-hdw.c +++ b/bacnet-stack/ports/rx62n/timer-hdw.c @@ -30,7 +30,8 @@ static volatile uint32_t Millisecond_Counter; static volatile uint8_t Millisecond_Counter_Byte; /* forward prototype for interrupt service routine */ -void int_cmt0_isr(void); +void int_cmt0_isr( + void); /************************************************************************* * Description: Timer Interrupt Handler @@ -49,7 +50,8 @@ static void timer_interrupt_handler( * Returns: nothing * Notes: none *************************************************************************/ -void int_cmt0_isr(void) +void int_cmt0_isr( + void) { timer_interrupt_handler(); } @@ -92,15 +94,9 @@ void timer_init( bool err = true; /* CMT is configured for a 1ms interval, and executes the callback - function CB_CompareMatch on every compare match */ - err &= R_CMT_Create( - 3, - PDL_CMT_PERIOD, - 1E-3, - int_cmt0_isr, - 3 - ); + function CB_CompareMatch on every compare match */ + err &= R_CMT_Create(3, PDL_CMT_PERIOD, 1E-3, int_cmt0_isr, 3); /* Halt in while loop when RPDL errors detected */ - while(!err); + while (!err); } diff --git a/bacnet-stack/ports/stm32f10x/automac.c b/bacnet-stack/ports/stm32f10x/automac.c index 9a389623..28c6d209 100644 --- a/bacnet-stack/ports/stm32f10x/automac.c +++ b/bacnet-stack/ports/stm32f10x/automac.c @@ -65,7 +65,8 @@ static bool Auto_Mode_Enabled; * RETURN: true if automode enabled * NOTES: none *****************************************************************************/ -bool automac_enabled(void) +bool automac_enabled( + void) { return Auto_Mode_Enabled; } @@ -75,7 +76,8 @@ bool automac_enabled(void) * RETURN: nothing * NOTES: none *****************************************************************************/ -void automac_enabled_set(bool status) +void automac_enabled_set( + bool status) { Auto_Mode_Enabled = status; } @@ -85,7 +87,8 @@ void automac_enabled_set(bool status) * RETURN: true if full * NOTES: none *****************************************************************************/ -bool automac_pfm_cycle_complete(void) +bool automac_pfm_cycle_complete( + void) { return PFM_Cycle_Complete; } @@ -95,13 +98,13 @@ bool automac_pfm_cycle_complete(void) * RETURN: true if used * NOTES: none *****************************************************************************/ -static bool automac_address_used(uint8_t mac) +static bool automac_address_used( + uint8_t mac) { bool status = false; if (mac < MAC_SLOTS_MAX) { - if ((Auto_MAC_Data[mac].emitter) || - (Auto_MAC_Data[mac].reserved) || + if ((Auto_MAC_Data[mac].emitter) || (Auto_MAC_Data[mac].reserved) || (Auto_MAC_Data[mac].token)) { status = true; } @@ -115,13 +118,13 @@ static bool automac_address_used(uint8_t mac) * RETURN: true if valid * NOTES: none *****************************************************************************/ -bool automac_free_address_valid(uint8_t mac) +bool automac_free_address_valid( + uint8_t mac) { bool status = false; if (mac < MAC_SLOTS_MAX) { - if ((Auto_MAC_Data[mac].pfm) && - (!automac_address_used(mac))) { + if ((Auto_MAC_Data[mac].pfm) && (!automac_address_used(mac))) { status = true; } } @@ -134,11 +137,12 @@ bool automac_free_address_valid(uint8_t mac) * RETURN: Next_Station, or 255 if there are no next stations * NOTES: none *****************************************************************************/ -uint8_t automac_next_station(uint8_t mac) +uint8_t automac_next_station( + uint8_t mac) { - uint8_t i = 0; /* loop counter */ + uint8_t i = 0; /* loop counter */ uint8_t next_station = 255; /* return value */ - uint8_t test_station = 0; /* station number to test for token */ + uint8_t test_station = 0; /* station number to test for token */ test_station = (mac + 1) % 128; for (i = 0; i < MAC_SLOTS_MAX; i++) { @@ -157,7 +161,8 @@ uint8_t automac_next_station(uint8_t mac) * RETURN: Number of free MAC addresses * NOTES: none *****************************************************************************/ -uint8_t automac_free_address_count(void) +uint8_t automac_free_address_count( + void) { uint8_t i = 0; uint8_t slots = 0; @@ -176,7 +181,8 @@ uint8_t automac_free_address_count(void) * RETURN: Number of free MAC addresses * NOTES: none *****************************************************************************/ -uint8_t automac_free_address_mac(uint8_t count) +uint8_t automac_free_address_mac( + uint8_t count) { uint8_t i = 0; uint8_t slots = 0; @@ -200,7 +206,8 @@ uint8_t automac_free_address_mac(uint8_t count) * RETURN: free MAC addresses * NOTES: none *****************************************************************************/ -uint8_t automac_free_address_random(void) +uint8_t automac_free_address_random( + void) { uint8_t count = 0; uint8_t random_count = 0; @@ -208,7 +215,7 @@ uint8_t automac_free_address_random(void) count = automac_free_address_count(); if (count) { - random_count = rand()%count; + random_count = rand() % count; mac = automac_free_address_mac(random_count); } @@ -220,7 +227,8 @@ uint8_t automac_free_address_random(void) * RETURN: MAC addresses * NOTES: none *****************************************************************************/ -uint8_t automac_address(void) +uint8_t automac_address( + void) { return My_MAC_Address; } @@ -230,7 +238,8 @@ uint8_t automac_address(void) * RETURN: MAC addresses * NOTES: none *****************************************************************************/ -void automac_address_set(uint8_t mac) +void automac_address_set( + uint8_t mac) { My_MAC_Address = mac; } @@ -240,7 +249,8 @@ void automac_address_set(uint8_t mac) * RETURN: MAC addresses * NOTES: none *****************************************************************************/ -uint16_t automac_time_slot(void) +uint16_t automac_time_slot( + void) { return My_Time_Slot; } @@ -250,12 +260,14 @@ uint16_t automac_time_slot(void) * RETURN: MAC addresses * NOTES: none *****************************************************************************/ -void automac_address_init(void) +void automac_address_init( + void) { - My_MAC_Address = MAC_SLOTS_OFFSET + rand()%(MAC_SLOTS_MAX-MAC_SLOTS_OFFSET); + My_MAC_Address = + MAC_SLOTS_OFFSET + rand() % (MAC_SLOTS_MAX - MAC_SLOTS_OFFSET); /* at least as long as a dropped token - worst case */ My_Time_Slot = Tno_token + (MAC_SLOTS_MAX * Tslot); - My_Time_Slot += (uint16_t)My_MAC_Address * Tslot; + My_Time_Slot += (uint16_t) My_MAC_Address *Tslot; } /**************************************************************************** @@ -263,7 +275,8 @@ void automac_address_init(void) * RETURN: nothing * NOTES: none *****************************************************************************/ -void automac_pfm_set(uint8_t mac) +void automac_pfm_set( + uint8_t mac) { if (mac < MAC_SLOTS_MAX) { if (Auto_MAC_Data[mac].pfm) { @@ -281,7 +294,8 @@ void automac_pfm_set(uint8_t mac) * RETURN: nothing * NOTES: none *****************************************************************************/ -void automac_token_set(uint8_t mac) +void automac_token_set( + uint8_t mac) { if (mac < MAC_SLOTS_MAX) { Auto_MAC_Data[mac].token = true; @@ -293,7 +307,8 @@ void automac_token_set(uint8_t mac) * RETURN: nothing * NOTES: none *****************************************************************************/ -void automac_emitter_set(uint8_t mac) +void automac_emitter_set( + uint8_t mac) { if (mac < MAC_SLOTS_MAX) { Auto_MAC_Data[mac].emitter = true; @@ -305,7 +320,8 @@ void automac_emitter_set(uint8_t mac) * RETURN: nothing * NOTES: none *****************************************************************************/ -void automac_init(void) +void automac_init( + void) { uint8_t i = 0; @@ -359,34 +375,31 @@ void test_Auto_MAC( srand(42); mac = automac_free_address_random(); ct_test(pTest, mac == 255); - automac_pfm_set(MAC_SLOTS_OFFSET+1); + automac_pfm_set(MAC_SLOTS_OFFSET + 1); mac = automac_free_address_mac(0); - ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1)); + ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1)); mac = automac_free_address_random(); - ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1)); + ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1)); /* test 2 free addresses */ - automac_pfm_set(MAC_SLOTS_OFFSET+2); + automac_pfm_set(MAC_SLOTS_OFFSET + 2); mac = automac_free_address_mac(0); - ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1)); + ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1)); mac = automac_free_address_mac(1); - ct_test(pTest, mac == (MAC_SLOTS_OFFSET+2)); + ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2)); mac = automac_free_address_random(); - ct_test(pTest, - (mac == (MAC_SLOTS_OFFSET+1)) || - (mac == (MAC_SLOTS_OFFSET+2))); + ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) || + (mac == (MAC_SLOTS_OFFSET + 2))); /* test 3 free addresses */ automac_pfm_set(126); mac = automac_free_address_mac(0); - ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1)); + ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1)); mac = automac_free_address_mac(1); - ct_test(pTest, mac == (MAC_SLOTS_OFFSET+2)); + ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2)); mac = automac_free_address_mac(2); ct_test(pTest, mac == 126); mac = automac_free_address_random(); - ct_test(pTest, - (mac == (MAC_SLOTS_OFFSET+1))|| - (mac == (MAC_SLOTS_OFFSET+2))|| - (mac == 126)); + ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) || + (mac == (MAC_SLOTS_OFFSET + 2)) || (mac == 126)); /* test the stored address */ mac = automac_address(); ct_test(pTest, mac < MAC_SLOTS_MAX); @@ -423,4 +436,3 @@ int main( } #endif #endif - diff --git a/bacnet-stack/ports/stm32f10x/automac.h b/bacnet-stack/ports/stm32f10x/automac.h index 73b5f76d..fcfd7d4b 100644 --- a/bacnet-stack/ports/stm32f10x/automac.h +++ b/bacnet-stack/ports/stm32f10x/automac.h @@ -34,26 +34,41 @@ extern "C" { #endif /* __cplusplus */ - void automac_init(void); + void automac_init( + void); - bool automac_free_address_valid(uint8_t mac); - uint8_t automac_free_address_count(void); - uint8_t automac_free_address_mac(uint8_t count); - uint8_t automac_free_address_random(void); - void automac_pfm_set(uint8_t mac); - void automac_token_set(uint8_t mac); - void automac_emitter_set(uint8_t mac); - uint8_t automac_next_station(uint8_t mac); - uint8_t automac_address(void); - void automac_address_set(uint8_t mac); - void automac_address_init(void); - uint16_t automac_time_slot(void); - bool automac_pfm_cycle_complete(void); - bool automac_enabled(void); - void automac_enabled_set(bool status); + bool automac_free_address_valid( + uint8_t mac); + uint8_t automac_free_address_count( + void); + uint8_t automac_free_address_mac( + uint8_t count); + uint8_t automac_free_address_random( + void); + void automac_pfm_set( + uint8_t mac); + void automac_token_set( + uint8_t mac); + void automac_emitter_set( + uint8_t mac); + uint8_t automac_next_station( + uint8_t mac); + uint8_t automac_address( + void); + void automac_address_set( + uint8_t mac); + void automac_address_init( + void); + uint16_t automac_time_slot( + void); + bool automac_pfm_cycle_complete( + void); + bool automac_enabled( + void); + void automac_enabled_set( + bool status); #ifdef __cplusplus } #endif /* __cplusplus */ - #endif diff --git a/bacnet-stack/ports/stm32f10x/bo.c b/bacnet-stack/ports/stm32f10x/bo.c index 38535212..d34f1c3b 100644 --- a/bacnet-stack/ports/stm32f10x/bo.c +++ b/bacnet-stack/ports/stm32f10x/bo.c @@ -222,7 +222,7 @@ bool Binary_Output_Out_Of_Service( /* note: the object name must be unique within this device */ bool Binary_Output_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { static char text_string[16] = "BO-0"; /* okay for single thread */ bool status = false; @@ -430,8 +430,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 b9c4dcf6..4c7a2aa5 100644 --- a/bacnet-stack/ports/stm32f10x/device.c +++ b/bacnet-stack/ports/stm32f10x/device.c @@ -175,8 +175,7 @@ static int Read_Property_Common( } else { characterstring_init_ansi(&char_string, ""); if (pObject->Object_Name) { - (void)pObject->Object_Name( - rpdata->object_instance, + (void) pObject->Object_Name(rpdata->object_instance, &char_string); } } @@ -343,7 +342,7 @@ uint32_t Device_Index_To_Instance( bool Device_Object_Name( uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { bool status = false; @@ -387,7 +386,7 @@ void Device_Init( { struct my_object_functions *pObject = NULL; - (void)object_table; + (void) object_table; pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { if (pObject->Object_Init) { @@ -525,7 +524,7 @@ bool Device_Object_List_Identifier( } bool Device_Valid_Object_Name( - BACNET_CHARACTER_STRING *object_name1, + BACNET_CHARACTER_STRING * object_name1, int *object_type, uint32_t * object_instance) { @@ -541,10 +540,10 @@ bool Device_Valid_Object_Name( for (i = 0; i < max_objects; i++) { check_id = Device_Object_List_Identifier(i, &type, &instance); if (check_id) { - pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type); + pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) type); if ((pObject != NULL) && (pObject->Object_Name != NULL) && (pObject->Object_Name(instance, &object_name2) && - characterstring_same(object_name1, &object_name2))) { + characterstring_same(object_name1, &object_name2))) { found = true; if (object_type) { *object_type = type; @@ -564,10 +563,10 @@ bool Device_Valid_Object_Id( int object_type, uint32_t object_instance) { - bool status = false; /* return value */ + bool status = false; /* return value */ struct my_object_functions *pObject = NULL; - pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)object_type); + pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) object_type); if ((pObject != NULL) && (pObject->Object_Valid_Instance != NULL)) { status = pObject->Object_Valid_Instance(object_instance); } @@ -578,7 +577,7 @@ bool Device_Valid_Object_Id( bool Device_Object_Name_Copy( int object_type, uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) + BACNET_CHARACTER_STRING * object_name) { struct my_object_functions *pObject = NULL; bool found = false; @@ -591,7 +590,7 @@ bool Device_Object_Name_Copy( for (i = 0; i < max_objects; i++) { check_id = Device_Object_List_Identifier(i, &type, &instance); if (check_id) { - pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type); + pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) type); if ((pObject != NULL) && (pObject->Object_Name != NULL)) { found = pObject->Object_Name(instance, object_name); break; @@ -816,8 +815,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 { @@ -869,8 +868,8 @@ bool Device_Write_Property_Local( uint8_t encoding = characterstring_encoding(&value.type.Character_String); if (encoding < MAX_CHARACTER_STRING_ENCODING) { - characterstring_copy(&My_Object_Name, &value.type. - Character_String); + characterstring_copy(&My_Object_Name, + &value.type.Character_String); status = true; } else { wp_data->error_class = ERROR_CLASS_PROPERTY; diff --git a/bacnet-stack/ports/stm32f10x/dlmstp.c b/bacnet-stack/ports/stm32f10x/dlmstp.c index c62fb1be..f3aecc39 100644 --- a/bacnet-stack/ports/stm32f10x/dlmstp.c +++ b/bacnet-stack/ports/stm32f10x/dlmstp.c @@ -206,22 +206,17 @@ static RING_BUFFER PDU_Queue; /* node, its value shall be 1. */ static uint8_t Nmax_info_frames = MSTP_PDU_PACKET_COUNT; -void dlmstp_automac_hander(void); +void dlmstp_automac_hander( + void); bool dlmstp_init( char *ifname) { ifname = ifname; - Ringbuf_Init( - &Transmit_Queue, - (uint8_t *)&Transmit_Buffer, - sizeof(struct mstp_tx_packet), - MSTP_TRANSMIT_PACKET_COUNT); - Ringbuf_Init( - &PDU_Queue, - (uint8_t *)&PDU_Buffer, - sizeof(struct mstp_pdu_packet), - MSTP_PDU_PACKET_COUNT); + Ringbuf_Init(&Transmit_Queue, (uint8_t *) & Transmit_Buffer, + sizeof(struct mstp_tx_packet), MSTP_TRANSMIT_PACKET_COUNT); + Ringbuf_Init(&PDU_Queue, (uint8_t *) & PDU_Buffer, + sizeof(struct mstp_pdu_packet), MSTP_PDU_PACKET_COUNT); rs485_init(); automac_init(); @@ -366,25 +361,26 @@ static bool dlmstp_compare_data_expecting_reply( return true; } -typedef enum -{ +typedef enum { MSTP_TX_STATE_IDLE, MSTP_TX_STATE_SILENCE_WAIT, MSTP_TX_STATE_SEND_WAIT, MSTP_TX_STATE_STOP } MSTP_TX_STATE; -static bool MSTP_Transmit_FSM(void) +static bool MSTP_Transmit_FSM( + void) { static MSTP_TX_STATE state = MSTP_TX_STATE_IDLE; static struct mstp_tx_packet *pkt; - MSTP_TX_START: + MSTP_TX_START: switch (state) { case MSTP_TX_STATE_IDLE: if (!Ringbuf_Empty(&Transmit_Queue)) { /* get the packet - but don't remove it from queue */ - pkt = (struct mstp_tx_packet *)Ringbuf_Get_Front( - &Transmit_Queue); + pkt = + (struct mstp_tx_packet *) + Ringbuf_Get_Front(&Transmit_Queue); state = MSTP_TX_STATE_SILENCE_WAIT; } break; @@ -415,7 +411,7 @@ static bool MSTP_Transmit_FSM(void) if (rs485_byte_sent() && rs485_frame_sent()) { rs485_rts_enable(false); /* remove the packet from the queue */ - (void)Ringbuf_Pop_Front(&Transmit_Queue); + (void) Ringbuf_Pop_Front(&Transmit_Queue); state = MSTP_TX_STATE_IDLE; } break; @@ -452,8 +448,7 @@ static void MSTP_Send_Frame( static struct mstp_tx_packet *pkt; uint16_t i = 0; /* used to calculate CRC for data */ - pkt = (struct mstp_tx_packet *)Ringbuf_Alloc( - &Transmit_Queue); + pkt = (struct mstp_tx_packet *) Ringbuf_Alloc(&Transmit_Queue); if (pkt) { /* create the MS/TP header */ pkt->buffer[0] = 0x55; @@ -474,11 +469,11 @@ static void MSTP_Send_Frame( /* calculate CRC for any data */ for (i = 0; i < data_len; i++) { crc16 = CRC_Calc_Data(data[i], crc16); - pkt->buffer[8+i] = data[i]; + pkt->buffer[8 + i] = data[i]; } crc16 = ~crc16; - pkt->buffer[8+data_len] = (crc16 & 0x00FF); - pkt->buffer[8+data_len+1] = ((crc16 & 0xFF00) >> 8); + pkt->buffer[8 + data_len] = (crc16 & 0x00FF); + pkt->buffer[8 + data_len + 1] = ((crc16 & 0xFF00) >> 8); pkt->length += data_len; pkt->length += 2; } @@ -630,13 +625,15 @@ static void MSTP_Receive_Frame_FSM( } else { /* receive the data portion of the frame. */ if ((DestinationAddress == This_Station) || - (DestinationAddress == MSTP_BROADCAST_ADDRESS)) { + (DestinationAddress == + MSTP_BROADCAST_ADDRESS)) { if (DataLength <= InputBufferSize) { /* Data */ Receive_State = MSTP_RECEIVE_STATE_DATA; } else { /* FrameTooLong */ - Receive_State = MSTP_RECEIVE_STATE_SKIP_DATA; + Receive_State = + MSTP_RECEIVE_STATE_SKIP_DATA; } } else { /* NotForUs */ @@ -877,8 +874,7 @@ static bool MSTP_Master_Node_FSM( transition_now = true; } else { uint8_t frame_type; - pkt = (struct mstp_pdu_packet *)Ringbuf_Pop_Front( - &PDU_Queue); + pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue); if (pkt->data_expecting_reply) { frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY; } else { @@ -985,10 +981,9 @@ static bool MSTP_Master_Node_FSM( (Next_Station == This_Station)) { /* NextStationUnknown - added in Addendum 135-2008v-1 */ /* then the next station to which the token - should be sent is unknown - so PollForMaster */ + should be sent is unknown - so PollForMaster */ Poll_Station = next_this_station; - MSTP_Send_Frame( - FRAME_TYPE_POLL_FOR_MASTER, Poll_Station, + MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station, This_Station, NULL, 0); RetryCount = 0; Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER; @@ -1214,12 +1209,11 @@ static bool MSTP_Master_Node_FSM( /* Note: we could wait for up to Treply_delay */ matched = false; if (!Ringbuf_Empty(&PDU_Queue)) { - pkt = (struct mstp_pdu_packet *)Ringbuf_Get_Front( - &PDU_Queue); + pkt = (struct mstp_pdu_packet *) Ringbuf_Get_Front(&PDU_Queue); 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); } if (matched) { /* Reply */ @@ -1230,8 +1224,7 @@ static bool MSTP_Master_Node_FSM( /* then call MSTP_Send_Frame to transmit the reply frame */ /* and enter the IDLE state to wait for the next frame. */ uint8_t frame_type; - pkt = (struct mstp_pdu_packet *)Ringbuf_Pop_Front( - &PDU_Queue); + pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue); if (pkt->data_expecting_reply) { frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY; } else { @@ -1276,7 +1269,7 @@ int dlmstp_send_pdu( struct mstp_pdu_packet *pkt; uint16_t i = 0; - pkt = (struct mstp_pdu_packet *)Ringbuf_Alloc(&PDU_Queue); + pkt = (struct mstp_pdu_packet *) Ringbuf_Alloc(&PDU_Queue); if (pkt) { pkt->data_expecting_reply = npdu_data->data_expecting_reply; for (i = 0; i < pdu_len; i++) { @@ -1300,7 +1293,8 @@ typedef enum { } AUTOMAC_STATE; /* buffer used to send and validate a response - size is min APDU size */ static uint8_t AutoMAC_Test_Buffer[50]; -void dlmstp_automac_hander(void) +void dlmstp_automac_hander( + void) { static AUTOMAC_STATE state = AUTOMAC_STATE_IDLE; uint8_t mac = 0; @@ -1341,7 +1335,7 @@ void dlmstp_automac_hander(void) } } else if (rs485_silence_elapsed(automac_time_slot())) { /* long silence indicates we are alone or - with other silent devices */ + with other silent devices */ SourceAddress = automac_address(); state = AUTOMAC_STATE_TESTING; } @@ -1360,7 +1354,8 @@ void dlmstp_automac_hander(void) automac_init(); state = AUTOMAC_STATE_IDLE; } else if (mac == DestinationAddress) { - MSTP_Send_Frame(FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER, + MSTP_Send_Frame + (FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER, SourceAddress, mac, NULL, 0); state = AUTOMAC_STATE_TOKEN; } @@ -1433,9 +1428,8 @@ void dlmstp_automac_hander(void) encode_unsigned16(&AutoMAC_Test_Buffer[0], vendor_id); serial_number = Device_Object_Instance_Number(); encode_unsigned32(&AutoMAC_Test_Buffer[2], serial_number); - MSTP_Send_Frame(FRAME_TYPE_TEST_REQUEST, - SourceAddress, mac, &AutoMAC_Test_Buffer[0], - 6); + MSTP_Send_Frame(FRAME_TYPE_TEST_REQUEST, SourceAddress, mac, + &AutoMAC_Test_Buffer[0], 6); state = AUTOMAC_STATE_CONFIRM; break; case AUTOMAC_STATE_CONFIRM: @@ -1448,8 +1442,7 @@ void dlmstp_automac_hander(void) MSTP_Flag.ReceivedValidFrame = false; MSTP_Flag.ReceivedValidFrameNotForUs = false; mac = automac_address(); - if ((mac == DestinationAddress) && - (DataLength >= 6)) { + if ((mac == DestinationAddress) && (DataLength >= 6)) { decode_unsigned16(&InputBuffer[0], &vendor_id); decode_unsigned32(&InputBuffer[2], &serial_number); if ((vendor_id == Device_Vendor_Identifier()) && @@ -1511,18 +1504,14 @@ uint16_t dlmstp_receive( /* only do receive state machine while we don't have a frame */ if ((MSTP_Flag.ReceivedValidFrame == false) && (MSTP_Flag.ReceivedValidFrameNotForUs == false) && - (MSTP_Flag.ReceivedInvalidFrame == false) && - (transmitting == false)) { + (MSTP_Flag.ReceivedInvalidFrame == false) && (transmitting == false)) { MSTP_Receive_Frame_FSM(); } /* only do master state machine while rx is idle */ - if ((Receive_State == MSTP_RECEIVE_STATE_IDLE) && - (transmitting == false)) { - if ((This_Station != 255) && - (MSTP_Flag.ReceivedValidFrameNotForUs)) { + if ((Receive_State == MSTP_RECEIVE_STATE_IDLE) && (transmitting == false)) { + if ((This_Station != 255) && (MSTP_Flag.ReceivedValidFrameNotForUs)) { MSTP_Flag.ReceivedValidFrameNotForUs = false; - if ((SourceAddress == This_Station) && - automac_enabled()) { + if ((SourceAddress == This_Station) && automac_enabled()) { /* duplicate MAC on the wire */ automac_init(); This_Station = 255; @@ -1602,8 +1591,7 @@ void dlmstp_set_max_master( uint8_t max_master) { if (max_master <= 127) { - if ((This_Station == 255) || - (This_Station <= max_master)) { + if ((This_Station == 255) || (This_Station <= max_master)) { Nmax_master = max_master; } } @@ -1651,7 +1639,8 @@ void dlmstp_get_broadcast_address( return; } -bool dlmstp_sole_master(void) +bool dlmstp_sole_master( + void) { if (MSTP_Flag.SoleMaster) { return true; @@ -1659,4 +1648,3 @@ bool dlmstp_sole_master(void) return false; } - diff --git a/bacnet-stack/ports/stm32f10x/led.c b/bacnet-stack/ports/stm32f10x/led.c index 090f1aa1..a692c12f 100644 --- a/bacnet-stack/ports/stm32f10x/led.c +++ b/bacnet-stack/ports/stm32f10x/led.c @@ -89,7 +89,8 @@ void led_rx_off( * Returns: true if on, false if off. * Notes: none *************************************************************************/ -bool led_rx_state(void) +bool led_rx_state( + void) { return Rx_State; } @@ -99,7 +100,8 @@ bool led_rx_state(void) * Returns: true if on, false if off. * Notes: none *************************************************************************/ -bool led_tx_state(void) +bool led_tx_state( + void) { return Tx_State; } @@ -109,7 +111,8 @@ bool led_tx_state(void) * Returns: none * Notes: none *************************************************************************/ -void led_tx_toggle(void) +void led_tx_toggle( + void) { if (led_tx_state()) { led_tx_off(); @@ -123,7 +126,8 @@ void led_tx_toggle(void) * Returns: none * Notes: none *************************************************************************/ -void led_rx_toggle(void) +void led_rx_toggle( + void) { if (led_rx_state()) { led_rx_off(); @@ -247,7 +251,8 @@ void led_ld3_off( * Returns: true if on, false if off. * Notes: none *************************************************************************/ -bool led_ld3_state(void) +bool led_ld3_state( + void) { return LD3_State; } @@ -257,7 +262,8 @@ bool led_ld3_state(void) * Returns: none * Notes: none *************************************************************************/ -void led_ld3_toggle(void) +void led_ld3_toggle( + void) { if (led_ld3_state()) { led_ld3_off(); diff --git a/bacnet-stack/ports/stm32f10x/led.h b/bacnet-stack/ports/stm32f10x/led.h index 113c5eb0..b7269ae2 100644 --- a/bacnet-stack/ports/stm32f10x/led.h +++ b/bacnet-stack/ports/stm32f10x/led.h @@ -39,30 +39,40 @@ extern "C" { void); void led_ld4_off( void); - bool led_ld3_state(void); - void led_ld3_toggle(void); + bool led_ld3_state( + void); + void led_ld3_toggle( + void); - void led_tx_on(void); - void led_rx_on(void); + void led_tx_on( + void); + void led_rx_on( + void); void led_tx_on_interval( uint16_t interval_ms); void led_rx_on_interval( uint16_t interval_ms); - void led_tx_off(void); - void led_rx_off(void); + void led_tx_off( + void); + void led_rx_off( + void); void led_tx_off_delay( uint32_t delay_ms); void led_rx_off_delay( uint32_t delay_ms); - void led_tx_toggle(void); - void led_rx_toggle(void); + void led_tx_toggle( + void); + void led_rx_toggle( + void); - bool led_tx_state(void); - bool led_rx_state(void); + bool led_tx_state( + void); + bool led_rx_state( + void); void led_task( void); diff --git a/bacnet-stack/ports/stm32f10x/main.c b/bacnet-stack/ports/stm32f10x/main.c index 70b3a6ba..cb5b97eb 100644 --- a/bacnet-stack/ports/stm32f10x/main.c +++ b/bacnet-stack/ports/stm32f10x/main.c @@ -44,15 +44,16 @@ char *BACnet_Version = "1.0"; * @param line: assert_param error line source number * @retval None */ -void assert_failed(uint8_t* file, uint32_t line) +void assert_failed( + uint8_t * file, + uint32_t line) { - /* User can add his own implementation to report the file name and line number, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* Infinite loop */ - while (1) - { - } + /* Infinite loop */ + while (1) { + } } #endif @@ -60,7 +61,8 @@ void assert_failed(uint8_t* file, uint32_t line) #define LSE_FAIL_FLAG 0x80 #define LSE_PASS_FLAG 0x100 -void lse_init(void) +void lse_init( + void) { uint32_t LSE_Delay = 0; struct etimer Delay_Timer; @@ -70,42 +72,37 @@ void lse_init(void) /* Enable LSE (Low Speed External Oscillation) */ RCC_LSEConfig(RCC_LSE_ON); - /* Check the LSE Status */ - while(1) - { - if(LSE_Delay < LSE_FAIL_FLAG) - { - timer_elapsed_start(&Delay_Timer); - while (!timer_elapsed_milliseconds(&Delay_Timer,500)) { - /* do nothing */ - } - /* check whether LSE is ready, with 4 seconds timeout */ - LSE_Delay += 0x10; - if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET) - { - /* Set flag: LSE PASS */ - LSE_Delay |= LSE_PASS_FLAG; - led_ld4_off(); - /* Disable LSE */ - RCC_LSEConfig(RCC_LSE_OFF); - break; - } - } + /* Check the LSE Status */ + while (1) { + if (LSE_Delay < LSE_FAIL_FLAG) { + timer_elapsed_start(&Delay_Timer); + while (!timer_elapsed_milliseconds(&Delay_Timer, 500)) { + /* do nothing */ + } + /* check whether LSE is ready, with 4 seconds timeout */ + LSE_Delay += 0x10; + if (RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET) { + /* Set flag: LSE PASS */ + LSE_Delay |= LSE_PASS_FLAG; + led_ld4_off(); + /* Disable LSE */ + RCC_LSEConfig(RCC_LSE_OFF); + break; + } + } - /* LSE_FAIL_FLAG = 0x80 */ - else if(LSE_Delay >= LSE_FAIL_FLAG) - { - if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) - { - /* Set flag: LSE FAIL */ - LSE_Delay |= LSE_FAIL_FLAG; - led_ld4_on(); - } - /* Disable LSE */ - RCC_LSEConfig(RCC_LSE_OFF); - break; + /* LSE_FAIL_FLAG = 0x80 */ + else if (LSE_Delay >= LSE_FAIL_FLAG) { + if (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { + /* Set flag: LSE FAIL */ + LSE_Delay |= LSE_FAIL_FLAG; + led_ld4_on(); + } + /* Disable LSE */ + RCC_LSEConfig(RCC_LSE_OFF); + break; + } } - } } int main( @@ -114,17 +111,16 @@ int main( struct itimer Blink_Timer; /*At this stage the microcontroller clock setting is already configured, - this is done through SystemInit() function which is called from startup - file (startup_stm32f10x_xx.s) before to branch to application main. - To reconfigure the default setting of SystemInit() function, refer to - system_stm32f10x.c file */ + this is done through SystemInit() function which is called from startup + file (startup_stm32f10x_xx.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_stm32f10x.c file */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); led_init(); - RCC_APB2PeriphClockCmd( - RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | - RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | - RCC_APB2Periph_GPIOE, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | + RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, + ENABLE); timer_init(); lse_init(); led_init(); diff --git a/bacnet-stack/ports/stm32f10x/rs485.c b/bacnet-stack/ports/stm32f10x/rs485.c index 0d95327d..acc10cda 100644 --- a/bacnet-stack/ports/stm32f10x/rs485.c +++ b/bacnet-stack/ports/stm32f10x/rs485.c @@ -58,7 +58,8 @@ static uint32_t Baud_Rate = 38400; * Returns: nothing * Notes: none **************************************************************************/ -void rs485_silence_reset(void) +void rs485_silence_reset( + void) { timer_elapsed_start(&Silence_Timer); } @@ -68,7 +69,8 @@ void rs485_silence_reset(void) * Returns: true if the amount of time has elapsed * Notes: none **************************************************************************/ -bool rs485_silence_elapsed(uint32_t interval) +bool rs485_silence_elapsed( + uint32_t interval) { return timer_elapsed_milliseconds(&Silence_Timer, interval); } @@ -95,9 +97,7 @@ static uint16_t rs485_turnaround_time( bool rs485_turnaround_elapsed( void) { - return timer_elapsed_milliseconds( - &Silence_Timer, - rs485_turnaround_time()); + return timer_elapsed_milliseconds(&Silence_Timer, rs485_turnaround_time()); } @@ -112,20 +112,21 @@ bool rs485_receive_error( return false; } -/*********************************************************************//** + /*********************************************************************//** * @brief USARTx interrupt handler sub-routine * @param[in] None * @return None **********************************************************************/ -void USART2_IRQHandler(void) +void USART2_IRQHandler( + void) { uint8_t data_byte; - if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) { + if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) { /* Read one byte from the receive data register */ data_byte = USART_ReceiveData(USART2); - (void)FIFO_Put(&Receive_Buffer, data_byte); + (void) FIFO_Put(&Receive_Buffer, data_byte); } } @@ -137,7 +138,7 @@ void USART2_IRQHandler(void) bool rs485_byte_available( uint8_t * data_register) { - bool data_available = false; /* return value */ + bool data_available = false; /* return value */ if (!FIFO_Empty(&Receive_Buffer)) { *data_register = FIFO_Get(&Receive_Buffer); @@ -154,7 +155,8 @@ bool rs485_byte_available( * RETURN: nothing * NOTES: none **************************************************************************/ -void rs485_byte_send(uint8_t tx_byte) +void rs485_byte_send( + uint8_t tx_byte) { led_tx_on_interval(10); USART_SendData(USART2, tx_byte); @@ -167,7 +169,8 @@ void rs485_byte_send(uint8_t tx_byte) * Returns: true if the USART register is empty * Notes: none **************************************************************************/ -bool rs485_byte_sent(void) +bool rs485_byte_sent( + void) { return USART_GetFlagStatus(USART2, USART_FLAG_TXE); } @@ -177,7 +180,8 @@ bool rs485_byte_sent(void) * Returns: true if the USART FIFO is empty * Notes: none **************************************************************************/ -bool rs485_frame_sent(void) +bool rs485_frame_sent( + void) { return USART_GetFlagStatus(USART2, USART_FLAG_TC); } @@ -188,9 +192,9 @@ bool rs485_frame_sent(void) * NOTES: none **************************************************************************/ void rs485_bytes_send( - uint8_t * buffer, /* data to send */ - uint16_t nbytes) /* number of bytes of data */ -{ + uint8_t * buffer, /* data to send */ + uint16_t nbytes) +{ /* number of bytes of data */ uint8_t tx_byte; while (nbytes) { @@ -295,7 +299,8 @@ void rs485_rts_enable( * Returns: nothing * Notes: none **************************************************************************/ -void rs485_init(void) +void rs485_init( + void) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; @@ -335,6 +340,6 @@ void rs485_init(void) USART_Cmd(USART2, ENABLE); FIFO_Init(&Receive_Buffer, &Receive_Buffer_Data[0], - (unsigned)sizeof(Receive_Buffer_Data)); + (unsigned) sizeof(Receive_Buffer_Data)); timer_elapsed_start(&Silence_Timer); } diff --git a/bacnet-stack/ports/stm32f10x/rs485.h b/bacnet-stack/ports/stm32f10x/rs485.h index 0103a94c..b055de2a 100644 --- a/bacnet-stack/ports/stm32f10x/rs485.h +++ b/bacnet-stack/ports/stm32f10x/rs485.h @@ -52,13 +52,17 @@ extern "C" { /* a granular approach */ void rs485_byte_send( uint8_t data_register); - bool rs485_byte_sent(void); - bool rs485_frame_sent(void); + bool rs485_byte_sent( + void); + bool rs485_frame_sent( + void); bool rs485_turnaround_elapsed( void); - void rs485_silence_reset(void); - bool rs485_silence_elapsed(uint32_t interval); + void rs485_silence_reset( + void); + bool rs485_silence_elapsed( + uint32_t interval); #ifdef __cplusplus } diff --git a/bacnet-stack/ports/stm32f10x/stm32f10x_conf.h b/bacnet-stack/ports/stm32f10x/stm32f10x_conf.h index 1ec60d00..a89cac7c 100644 --- a/bacnet-stack/ports/stm32f10x/stm32f10x_conf.h +++ b/bacnet-stack/ports/stm32f10x/stm32f10x_conf.h @@ -46,7 +46,7 @@ #include "stm32f10x_tim.h" #include "stm32f10x_usart.h" #include "stm32f10x_wwdg.h" -#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ +#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ @@ -62,11 +62,13 @@ * If expr is true, it returns no value. * @retval None */ - #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ - void assert_failed(uint8_t* file, uint32_t line); +void assert_failed( + uint8_t * file, + uint32_t line); #else - #define assert_param(expr) ((void)0) +#define assert_param(expr) ((void)0) #endif /* USE_FULL_ASSERT */ #endif /* __STM32F10x_CONF_H */ diff --git a/bacnet-stack/ports/stm32f10x/stm32f10x_it.c b/bacnet-stack/ports/stm32f10x/stm32f10x_it.c index 1787ae80..632ab73c 100644 --- a/bacnet-stack/ports/stm32f10x/stm32f10x_it.c +++ b/bacnet-stack/ports/stm32f10x/stm32f10x_it.c @@ -47,7 +47,8 @@ * @param None * @retval None */ -void NMI_Handler(void) +void NMI_Handler( + void) { } @@ -56,12 +57,12 @@ void NMI_Handler(void) * @param None * @retval None */ -void HardFault_Handler(void) +void HardFault_Handler( + void) { - /* Go to infinite loop when Hard Fault exception occurs */ - while (1) - { - } + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) { + } } /** @@ -69,12 +70,12 @@ void HardFault_Handler(void) * @param None * @retval None */ -void MemManage_Handler(void) +void MemManage_Handler( + void) { - /* Go to infinite loop when Memory Manage exception occurs */ - while (1) - { - } + /* Go to infinite loop when Memory Manage exception occurs */ + while (1) { + } } /** @@ -82,12 +83,12 @@ void MemManage_Handler(void) * @param None * @retval None */ -void BusFault_Handler(void) +void BusFault_Handler( + void) { - /* Go to infinite loop when Bus Fault exception occurs */ - while (1) - { - } + /* Go to infinite loop when Bus Fault exception occurs */ + while (1) { + } } /** @@ -95,12 +96,12 @@ void BusFault_Handler(void) * @param None * @retval None */ -void UsageFault_Handler(void) +void UsageFault_Handler( + void) { - /* Go to infinite loop when Usage Fault exception occurs */ - while (1) - { - } + /* Go to infinite loop when Usage Fault exception occurs */ + while (1) { + } } /** @@ -108,7 +109,8 @@ void UsageFault_Handler(void) * @param None * @retval None */ -void SVC_Handler(void) +void SVC_Handler( + void) { } @@ -117,7 +119,8 @@ void SVC_Handler(void) * @param None * @retval None */ -void DebugMon_Handler(void) +void DebugMon_Handler( + void) { } @@ -126,7 +129,8 @@ void DebugMon_Handler(void) * @param None * @retval None */ -void PendSV_Handler(void) +void PendSV_Handler( + void) { } diff --git a/bacnet-stack/ports/stm32f10x/stm32f10x_it.h b/bacnet-stack/ports/stm32f10x/stm32f10x_it.h index 0187ac00..490a7acf 100644 --- a/bacnet-stack/ports/stm32f10x/stm32f10x_it.h +++ b/bacnet-stack/ports/stm32f10x/stm32f10x_it.h @@ -30,14 +30,22 @@ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ -void NMI_Handler(void); -void HardFault_Handler(void); -void MemManage_Handler(void); -void BusFault_Handler(void); -void UsageFault_Handler(void); -void SVC_Handler(void); -void DebugMon_Handler(void); -void PendSV_Handler(void); +void NMI_Handler( + void); +void HardFault_Handler( + void); +void MemManage_Handler( + void); +void BusFault_Handler( + void); +void UsageFault_Handler( + void); +void SVC_Handler( + void); +void DebugMon_Handler( + void); +void PendSV_Handler( + void); #endif /* __STM32F10x_IT_H */ diff --git a/bacnet-stack/ports/stm32f10x/system_stm32f10x.c b/bacnet-stack/ports/stm32f10x/system_stm32f10x.c index fd7728c9..7b2caa43 100644 --- a/bacnet-stack/ports/stm32f10x/system_stm32f10x.c +++ b/bacnet-stack/ports/stm32f10x/system_stm32f10x.c @@ -24,8 +24,8 @@ /** @addtogroup stm32f10x_system * @{ - */ - + */ + /** @addtogroup STM32F10x_System_Private_Includes * @{ */ @@ -70,13 +70,13 @@ the System clock. If you are using different crystal you have to adapt those functions accordingly. */ - + #if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) /* #define SYSCLK_FREQ_HSE HSE_VALUE */ - #define SYSCLK_FREQ_24MHz 24000000 +#define SYSCLK_FREQ_24MHz 24000000 #else /* #define SYSCLK_FREQ_HSE HSE_VALUE */ -/* #define SYSCLK_FREQ_24MHz 24000000 */ +/* #define SYSCLK_FREQ_24MHz 24000000 */ /* #define SYSCLK_FREQ_36MHz 36000000 */ /* #define SYSCLK_FREQ_48MHz 48000000 */ /* #define SYSCLK_FREQ_56MHz 56000000 */ @@ -85,16 +85,16 @@ /*!< Uncomment the following line if you need to use external SRAM mounted on STM3210E-EVAL board (STM32 High density and XL-density devices) or on - STM32100E-EVAL board (STM32 High-density value line devices) as data memory */ + STM32100E-EVAL board (STM32 High-density value line devices) as data memory */ #if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL) /* #define DATA_IN_ExtSRAM */ #endif /*!< Uncomment the following line if you need to relocate your vector Table in - Internal SRAM. */ + Internal SRAM. */ /* #define VECT_TAB_SRAM */ -#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field. - This value must be a multiple of 0x100. */ +#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field. + This value must be a multiple of 0x100. */ /** @@ -117,22 +117,23 @@ * Clock Definitions *******************************************************************************/ #ifdef SYSCLK_FREQ_HSE - uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /*!< System Clock Frequency (Core Clock) */ +uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_24MHz - uint32_t SystemCoreClock = SYSCLK_FREQ_24MHz; /*!< System Clock Frequency (Core Clock) */ +uint32_t SystemCoreClock = SYSCLK_FREQ_24MHz; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_36MHz - uint32_t SystemCoreClock = SYSCLK_FREQ_36MHz; /*!< System Clock Frequency (Core Clock) */ +uint32_t SystemCoreClock = SYSCLK_FREQ_36MHz; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_48MHz - uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz; /*!< System Clock Frequency (Core Clock) */ +uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_56MHz - uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz; /*!< System Clock Frequency (Core Clock) */ +uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_72MHz - uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz; /*!< System Clock Frequency (Core Clock) */ +uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz; /*!< System Clock Frequency (Core Clock) */ #else /*!< HSI Selected as System Clock source */ - uint32_t SystemCoreClock = HSI_VALUE; /*!< System Clock Frequency (Core Clock) */ +uint32_t SystemCoreClock = HSI_VALUE; /*!< System Clock Frequency (Core Clock) */ #endif -__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; +__I uint8_t AHBPrescTable[16] = + { 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9 }; /** * @} */ @@ -141,24 +142,32 @@ __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9} * @{ */ -static void SetSysClock(void); +static void SetSysClock( + void); #ifdef SYSCLK_FREQ_HSE - static void SetSysClockToHSE(void); +static void SetSysClockToHSE( + void); #elif defined SYSCLK_FREQ_24MHz - static void SetSysClockTo24(void); +static void SetSysClockTo24( + void); #elif defined SYSCLK_FREQ_36MHz - static void SetSysClockTo36(void); +static void SetSysClockTo36( + void); #elif defined SYSCLK_FREQ_48MHz - static void SetSysClockTo48(void); +static void SetSysClockTo48( + void); #elif defined SYSCLK_FREQ_56MHz - static void SetSysClockTo56(void); +static void SetSysClockTo56( + void); #elif defined SYSCLK_FREQ_72MHz - static void SetSysClockTo72(void); +static void SetSysClockTo72( + void); #endif #ifdef DATA_IN_ExtSRAM - static void SystemInit_ExtMemCtl(void); +static void SystemInit_ExtMemCtl( + void); #endif /* DATA_IN_ExtSRAM */ /** @@ -177,63 +186,64 @@ static void SetSysClock(void); * @param None * @retval None */ -void SystemInit (void) +void SystemInit( + void) { - /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ - /* Set HSION bit */ - RCC->CR |= (uint32_t)0x00000001; + /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ + /* Set HSION bit */ + RCC->CR |= (uint32_t) 0x00000001; - /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ + /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #ifndef STM32F10X_CL - RCC->CFGR &= (uint32_t)0xF8FF0000; + RCC->CFGR &= (uint32_t) 0xF8FF0000; #else - RCC->CFGR &= (uint32_t)0xF0FF0000; -#endif /* STM32F10X_CL */ - - /* Reset HSEON, CSSON and PLLON bits */ - RCC->CR &= (uint32_t)0xFEF6FFFF; + RCC->CFGR &= (uint32_t) 0xF0FF0000; +#endif /* STM32F10X_CL */ - /* Reset HSEBYP bit */ - RCC->CR &= (uint32_t)0xFFFBFFFF; + /* Reset HSEON, CSSON and PLLON bits */ + RCC->CR &= (uint32_t) 0xFEF6FFFF; - /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ - RCC->CFGR &= (uint32_t)0xFF80FFFF; + /* Reset HSEBYP bit */ + RCC->CR &= (uint32_t) 0xFFFBFFFF; + + /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ + RCC->CFGR &= (uint32_t) 0xFF80FFFF; #ifdef STM32F10X_CL - /* Reset PLL2ON and PLL3ON bits */ - RCC->CR &= (uint32_t)0xEBFFFFFF; + /* Reset PLL2ON and PLL3ON bits */ + RCC->CR &= (uint32_t) 0xEBFFFFFF; - /* Disable all interrupts and clear pending bits */ - RCC->CIR = 0x00FF0000; + /* Disable all interrupts and clear pending bits */ + RCC->CIR = 0x00FF0000; - /* Reset CFGR2 register */ - RCC->CFGR2 = 0x00000000; + /* Reset CFGR2 register */ + RCC->CFGR2 = 0x00000000; #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) - /* Disable all interrupts and clear pending bits */ - RCC->CIR = 0x009F0000; + /* Disable all interrupts and clear pending bits */ + RCC->CIR = 0x009F0000; - /* Reset CFGR2 register */ - RCC->CFGR2 = 0x00000000; + /* Reset CFGR2 register */ + RCC->CFGR2 = 0x00000000; #else - /* Disable all interrupts and clear pending bits */ - RCC->CIR = 0x009F0000; + /* Disable all interrupts and clear pending bits */ + RCC->CIR = 0x009F0000; #endif /* STM32F10X_CL */ - -#if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL) - #ifdef DATA_IN_ExtSRAM - SystemInit_ExtMemCtl(); - #endif /* DATA_IN_ExtSRAM */ -#endif - /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */ - /* Configure the Flash Latency cycles and enable prefetch buffer */ - SetSysClock(); +#if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL) +#ifdef DATA_IN_ExtSRAM + SystemInit_ExtMemCtl(); +#endif /* DATA_IN_ExtSRAM */ +#endif + + /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */ + /* Configure the Flash Latency cycles and enable prefetch buffer */ + SetSysClock(); #ifdef VECT_TAB_SRAM - SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ + SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else - SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ -#endif + SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ +#endif } /** @@ -242,112 +252,101 @@ void SystemInit (void) * @param None * @retval None */ -void SystemCoreClockUpdate (void) +void SystemCoreClockUpdate( + void) { - uint32_t tmp = 0, pllmull = 0, pllsource = 0; + uint32_t tmp = 0, pllmull = 0, pllsource = 0; #ifdef STM32F10X_CL - uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0; + uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = + 0, pll2mull = 0; #endif /* STM32F10X_CL */ #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) - uint32_t prediv1factor = 0; + uint32_t prediv1factor = 0; #endif /* STM32F10X_LD_VL or STM32F10X_MD_VL or STM32F10X_HD_VL */ - - /* Get SYSCLK source -------------------------------------------------------*/ - tmp = RCC->CFGR & RCC_CFGR_SWS; - - switch (tmp) - { - case 0x00: /* HSI used as system clock */ - SystemCoreClock = HSI_VALUE; - break; - case 0x04: /* HSE used as system clock */ - SystemCoreClock = HSE_VALUE; - break; - case 0x08: /* PLL used as system clock */ - /* Get PLL clock source and multiplication factor ----------------------*/ - pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; - pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; - -#ifndef STM32F10X_CL - pllmull = ( pllmull >> 18) + 2; - - if (pllsource == 0x00) - { - /* HSI oscillator clock divided by 2 selected as PLL clock entry */ - SystemCoreClock = (HSI_VALUE >> 1) * pllmull; - } - else - { - #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) - prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; - /* HSE oscillator clock selected as PREDIV1 clock entry */ - SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; - #else - /* HSE selected as PLL clock entry */ - if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) - {/* HSE oscillator clock divided by 2 */ - SystemCoreClock = (HSE_VALUE >> 1) * pllmull; - } - else - { - SystemCoreClock = HSE_VALUE * pllmull; - } - #endif - } + /* Get SYSCLK source ------------------------------------------------------- */ + tmp = RCC->CFGR & RCC_CFGR_SWS; + + switch (tmp) { + case 0x00: /* HSI used as system clock */ + SystemCoreClock = HSI_VALUE; + break; + case 0x04: /* HSE used as system clock */ + SystemCoreClock = HSE_VALUE; + break; + case 0x08: /* PLL used as system clock */ + + /* Get PLL clock source and multiplication factor ---------------------- */ + pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; + pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; + +#ifndef STM32F10X_CL + pllmull = (pllmull >> 18) + 2; + + if (pllsource == 0x00) { + /* HSI oscillator clock divided by 2 selected as PLL clock entry */ + SystemCoreClock = (HSI_VALUE >> 1) * pllmull; + } else { +#if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) + prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; + /* HSE oscillator clock selected as PREDIV1 clock entry */ + SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else - pllmull = pllmull >> 18; - - if (pllmull != 0x0D) - { - pllmull += 2; - } - else - { /* PLL multiplication factor = PLL input clock * 6.5 */ - pllmull = 13 / 2; - } - - if (pllsource == 0x00) - { - /* HSI oscillator clock divided by 2 selected as PLL clock entry */ - SystemCoreClock = (HSI_VALUE >> 1) * pllmull; - } - else - {/* PREDIV1 selected as PLL clock entry */ - - /* Get PREDIV1 clock source and division factor */ - prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; - prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; - - if (prediv1source == 0) - { - /* HSE oscillator clock selected as PREDIV1 clock entry */ - SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; - } - else - {/* PLL2 clock selected as PREDIV1 clock entry */ - - /* Get PREDIV2 division factor and PLL2 multiplication factor */ - prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1; - pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2; - SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; - } - } -#endif /* STM32F10X_CL */ - break; + /* HSE selected as PLL clock entry */ + if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t) RESET) { /* HSE oscillator clock divided by 2 */ + SystemCoreClock = (HSE_VALUE >> 1) * pllmull; + } else { + SystemCoreClock = HSE_VALUE * pllmull; + } +#endif + } +#else + pllmull = pllmull >> 18; - default: - SystemCoreClock = HSI_VALUE; - break; - } - - /* Compute HCLK clock frequency ----------------*/ - /* Get HCLK prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; - /* HCLK clock frequency */ - SystemCoreClock >>= tmp; + if (pllmull != 0x0D) { + pllmull += 2; + } else { /* PLL multiplication factor = PLL input clock * 6.5 */ + pllmull = 13 / 2; + } + + if (pllsource == 0x00) { + /* HSI oscillator clock divided by 2 selected as PLL clock entry */ + SystemCoreClock = (HSI_VALUE >> 1) * pllmull; + } else { /* PREDIV1 selected as PLL clock entry */ + + /* Get PREDIV1 clock source and division factor */ + prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; + prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; + + if (prediv1source == 0) { + /* HSE oscillator clock selected as PREDIV1 clock entry */ + SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; + } else { /* PLL2 clock selected as PREDIV1 clock entry */ + + /* Get PREDIV2 division factor and PLL2 multiplication factor */ + prediv2factor = + ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1; + pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8) + 2; + SystemCoreClock = + (((HSE_VALUE / prediv2factor) * pll2mull) / + prediv1factor) * pllmull; + } + } +#endif /* STM32F10X_CL */ + break; + + default: + SystemCoreClock = HSI_VALUE; + break; + } + + /* Compute HCLK clock frequency ---------------- */ + /* Get HCLK prescaler */ + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; + /* HCLK clock frequency */ + SystemCoreClock >>= tmp; } /** @@ -355,24 +354,25 @@ void SystemCoreClockUpdate (void) * @param None * @retval None */ -static void SetSysClock(void) +static void SetSysClock( + void) { #ifdef SYSCLK_FREQ_HSE - SetSysClockToHSE(); + SetSysClockToHSE(); #elif defined SYSCLK_FREQ_24MHz - SetSysClockTo24(); + SetSysClockTo24(); #elif defined SYSCLK_FREQ_36MHz - SetSysClockTo36(); + SetSysClockTo36(); #elif defined SYSCLK_FREQ_48MHz - SetSysClockTo48(); + SetSysClockTo48(); #elif defined SYSCLK_FREQ_56MHz - SetSysClockTo56(); + SetSysClockTo56(); #elif defined SYSCLK_FREQ_72MHz - SetSysClockTo72(); + SetSysClockTo72(); #endif - - /* If none of the define above is enabled, the HSI is used as System clock - source (default after reset) */ + + /* If none of the define above is enabled, the HSI is used as System clock + source (default after reset) */ } /** @@ -380,7 +380,7 @@ static void SetSysClock(void) * before jump to __main * @param None * @retval None - */ + */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. @@ -390,41 +390,42 @@ static void SetSysClock(void) * data memory (including heap and stack). * @param None * @retval None - */ -void SystemInit_ExtMemCtl(void) + */ +void SystemInit_ExtMemCtl( + void) { /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ - /* Enable FSMC clock */ - RCC->AHBENR = 0x00000114; - - /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ - RCC->APB2ENR = 0x000001E0; - + /* Enable FSMC clock */ + RCC->AHBENR = 0x00000114; + + /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ + RCC->APB2ENR = 0x000001E0; + /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ -/*---------------- NOE and NWE configuration --------------------------------*/ +/*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ - - GPIOD->CRL = 0x44BB44BB; - GPIOD->CRH = 0xBBBBBBBB; - GPIOE->CRL = 0xB44444BB; - GPIOE->CRH = 0xBBBBBBBB; + GPIOD->CRL = 0x44BB44BB; + GPIOD->CRH = 0xBBBBBBBB; - GPIOF->CRL = 0x44BBBBBB; - GPIOF->CRH = 0xBBBB4444; + GPIOE->CRL = 0xB44444BB; + GPIOE->CRH = 0xBBBBBBBB; - GPIOG->CRL = 0x44BBBBBB; - GPIOG->CRH = 0x44444B44; - -/*---------------- FSMC Configuration ---------------------------------------*/ + GPIOF->CRL = 0x44BBBBBB; + GPIOF->CRH = 0xBBBB4444; + + GPIOG->CRL = 0x44BBBBBB; + GPIOG->CRH = 0x44444B44; + +/*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ - - FSMC_Bank1->BTCR[4] = 0x00001011; - FSMC_Bank1->BTCR[5] = 0x00000200; + + FSMC_Bank1->BTCR[4] = 0x00001011; + FSMC_Bank1->BTCR[5] = 0x00000200; } #endif /* DATA_IN_ExtSRAM */ @@ -436,76 +437,66 @@ void SystemInit_ExtMemCtl(void) * @param None * @retval None */ -static void SetSysClockToHSE(void) +static void SetSysClockToHSE( + void) { - __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - - /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/ - /* Enable HSE */ - RCC->CR |= ((uint32_t)RCC_CR_HSEON); - - /* Wait till HSE is ready and if Time out is reached exit */ - do - { - HSEStatus = RCC->CR & RCC_CR_HSERDY; - StartUpCounter++; - } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - if ((RCC->CR & RCC_CR_HSERDY) != RESET) - { - HSEStatus = (uint32_t)0x01; - } - else - { - HSEStatus = (uint32_t)0x00; - } + /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration --------------------------- */ + /* Enable HSE */ + RCC->CR |= ((uint32_t) RCC_CR_HSEON); - if (HSEStatus == (uint32_t)0x01) - { + /* Wait till HSE is ready and if Time out is reached exit */ + do { + HSEStatus = RCC->CR & RCC_CR_HSERDY; + StartUpCounter++; + } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CR & RCC_CR_HSERDY) != RESET) { + HSEStatus = (uint32_t) 0x01; + } else { + HSEStatus = (uint32_t) 0x00; + } + + if (HSEStatus == (uint32_t) 0x01) { #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL - /* Enable Prefetch Buffer */ - FLASH->ACR |= FLASH_ACR_PRFTBE; + /* Enable Prefetch Buffer */ + FLASH->ACR |= FLASH_ACR_PRFTBE; - /* Flash 0 wait state */ - FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY); + /* Flash 0 wait state */ + FLASH->ACR &= (uint32_t) ((uint32_t) ~ FLASH_ACR_LATENCY); #ifndef STM32F10X_CL - FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0; + FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_0; #else - if (HSE_VALUE <= 24000000) - { - FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0; - } - else - { - FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1; - } + if (HSE_VALUE <= 24000000) { + FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_0; + } else { + FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_1; + } #endif /* STM32F10X_CL */ #endif - - /* HCLK = SYSCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; - - /* PCLK2 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1; - - /* PCLK1 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1; - - /* Select HSE as system clock source */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); - RCC->CFGR |= (uint32_t)RCC_CFGR_SW_HSE; - /* Wait till HSE is used as system clock source */ - while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x04) - { + /* HCLK = SYSCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_HPRE_DIV1; + + /* PCLK2 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE2_DIV1; + + /* PCLK1 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE1_DIV1; + + /* Select HSE as system clock source */ + RCC->CFGR &= (uint32_t) ((uint32_t) ~ (RCC_CFGR_SW)); + RCC->CFGR |= (uint32_t) RCC_CFGR_SW_HSE; + + /* Wait till HSE is used as system clock source */ + while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x04) { + } + } else { /* If HSE fails to start-up, the application will have wrong clock + configuration. User can add here some code to deal with this error */ } - } - else - { /* If HSE fails to start-up, the application will have wrong clock - configuration. User can add here some code to deal with this error */ - } } #elif defined SYSCLK_FREQ_24MHz /** @@ -515,101 +506,105 @@ static void SetSysClockToHSE(void) * @param None * @retval None */ -static void SetSysClockTo24(void) +static void SetSysClockTo24( + void) { - __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - - /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/ - /* Enable HSE */ - RCC->CR |= ((uint32_t)RCC_CR_HSEON); - - /* Wait till HSE is ready and if Time out is reached exit */ - do - { - HSEStatus = RCC->CR & RCC_CR_HSERDY; - StartUpCounter++; - } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - if ((RCC->CR & RCC_CR_HSERDY) != RESET) - { - HSEStatus = (uint32_t)0x01; - } - else - { - HSEStatus = (uint32_t)0x00; - } + /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration --------------------------- */ + /* Enable HSE */ + RCC->CR |= ((uint32_t) RCC_CR_HSEON); - if (HSEStatus == (uint32_t)0x01) - { -#if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL - /* Enable Prefetch Buffer */ - FLASH->ACR |= FLASH_ACR_PRFTBE; + /* Wait till HSE is ready and if Time out is reached exit */ + do { + HSEStatus = RCC->CR & RCC_CR_HSERDY; + StartUpCounter++; + } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); - /* Flash 0 wait state */ - FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY); - FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0; + if ((RCC->CR & RCC_CR_HSERDY) != RESET) { + HSEStatus = (uint32_t) 0x01; + } else { + HSEStatus = (uint32_t) 0x00; + } + + if (HSEStatus == (uint32_t) 0x01) { +#if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL + /* Enable Prefetch Buffer */ + FLASH->ACR |= FLASH_ACR_PRFTBE; + + /* Flash 0 wait state */ + FLASH->ACR &= (uint32_t) ((uint32_t) ~ FLASH_ACR_LATENCY); + FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_0; #endif - - /* HCLK = SYSCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; - - /* PCLK2 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1; - - /* PCLK1 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1; - -#ifdef STM32F10X_CL - /* Configure PLLs ------------------------------------------------------*/ - /* PLL configuration: PLLCLK = PREDIV1 * 6 = 24 MHz */ - RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | - RCC_CFGR_PLLMULL6); - /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ - /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */ - RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | - RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); - RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | - RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10); - - /* Enable PLL2 */ - RCC->CR |= RCC_CR_PLL2ON; - /* Wait till PLL2 is ready */ - while((RCC->CR & RCC_CR_PLL2RDY) == 0) - { - } + /* HCLK = SYSCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_HPRE_DIV1; + + /* PCLK2 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE2_DIV1; + + /* PCLK1 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE1_DIV1; + +#ifdef STM32F10X_CL + /* Configure PLLs ------------------------------------------------------ */ + /* PLL configuration: PLLCLK = PREDIV1 * 6 = 24 MHz */ + RCC->CFGR &= + (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | + RCC_CFGR_PLLMULL); + RCC->CFGR |= + (uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | + RCC_CFGR_PLLMULL6); + + /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ + /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */ + RCC->CFGR2 &= + (uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | + RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); + RCC->CFGR2 |= + (uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | + RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10); + + /* Enable PLL2 */ + RCC->CR |= RCC_CR_PLL2ON; + /* Wait till PLL2 is ready */ + while ((RCC->CR & RCC_CR_PLL2RDY) == 0) { + } #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) - /* PLL configuration: = (HSE / 2) * 6 = 24 MHz */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1_Div2 | RCC_CFGR_PLLMULL6); -#else - /* PLL configuration: = (HSE / 2) * 6 = 24 MHz */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL6); + /* PLL configuration: = (HSE / 2) * 6 = 24 MHz */ + RCC->CFGR &= + (uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | + RCC_CFGR_PLLMULL)); + RCC->CFGR |= + (uint32_t) (RCC_CFGR_PLLSRC_PREDIV1 | + RCC_CFGR_PLLXTPRE_PREDIV1_Div2 | RCC_CFGR_PLLMULL6); +#else + /* PLL configuration: = (HSE / 2) * 6 = 24 MHz */ + RCC->CFGR &= + (uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | + RCC_CFGR_PLLMULL)); + RCC->CFGR |= + (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | + RCC_CFGR_PLLMULL6); #endif /* STM32F10X_CL */ - /* Enable PLL */ - RCC->CR |= RCC_CR_PLLON; + /* Enable PLL */ + RCC->CR |= RCC_CR_PLLON; - /* Wait till PLL is ready */ - while((RCC->CR & RCC_CR_PLLRDY) == 0) - { + /* Wait till PLL is ready */ + while ((RCC->CR & RCC_CR_PLLRDY) == 0) { + } + + /* Select PLL as system clock source */ + RCC->CFGR &= (uint32_t) ((uint32_t) ~ (RCC_CFGR_SW)); + RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; + + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) { + } + } else { /* If HSE fails to start-up, the application will have wrong clock + configuration. User can add here some code to deal with this error */ } - - /* Select PLL as system clock source */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); - RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL; - - /* Wait till PLL is used as system clock source */ - while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) - { - } - } - else - { /* If HSE fails to start-up, the application will have wrong clock - configuration. User can add here some code to deal with this error */ - } } #elif defined SYSCLK_FREQ_36MHz /** @@ -619,98 +614,98 @@ static void SetSysClockTo24(void) * @param None * @retval None */ -static void SetSysClockTo36(void) +static void SetSysClockTo36( + void) { - __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - - /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/ - /* Enable HSE */ - RCC->CR |= ((uint32_t)RCC_CR_HSEON); - - /* Wait till HSE is ready and if Time out is reached exit */ - do - { - HSEStatus = RCC->CR & RCC_CR_HSERDY; - StartUpCounter++; - } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - if ((RCC->CR & RCC_CR_HSERDY) != RESET) - { - HSEStatus = (uint32_t)0x01; - } - else - { - HSEStatus = (uint32_t)0x00; - } + /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration --------------------------- */ + /* Enable HSE */ + RCC->CR |= ((uint32_t) RCC_CR_HSEON); - if (HSEStatus == (uint32_t)0x01) - { - /* Enable Prefetch Buffer */ - FLASH->ACR |= FLASH_ACR_PRFTBE; + /* Wait till HSE is ready and if Time out is reached exit */ + do { + HSEStatus = RCC->CR & RCC_CR_HSERDY; + StartUpCounter++; + } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); - /* Flash 1 wait state */ - FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY); - FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1; - - /* HCLK = SYSCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; - - /* PCLK2 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1; - - /* PCLK1 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1; - -#ifdef STM32F10X_CL - /* Configure PLLs ------------------------------------------------------*/ - - /* PLL configuration: PLLCLK = PREDIV1 * 9 = 36 MHz */ - RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | - RCC_CFGR_PLLMULL9); - - /*!< PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ - /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */ - - RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | - RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); - RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | - RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10); - - /* Enable PLL2 */ - RCC->CR |= RCC_CR_PLL2ON; - /* Wait till PLL2 is ready */ - while((RCC->CR & RCC_CR_PLL2RDY) == 0) - { + if ((RCC->CR & RCC_CR_HSERDY) != RESET) { + HSEStatus = (uint32_t) 0x01; + } else { + HSEStatus = (uint32_t) 0x00; } - -#else - /* PLL configuration: PLLCLK = (HSE / 2) * 9 = 36 MHz */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL9); + + if (HSEStatus == (uint32_t) 0x01) { + /* Enable Prefetch Buffer */ + FLASH->ACR |= FLASH_ACR_PRFTBE; + + /* Flash 1 wait state */ + FLASH->ACR &= (uint32_t) ((uint32_t) ~ FLASH_ACR_LATENCY); + FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_1; + + /* HCLK = SYSCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_HPRE_DIV1; + + /* PCLK2 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE2_DIV1; + + /* PCLK1 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE1_DIV1; + +#ifdef STM32F10X_CL + /* Configure PLLs ------------------------------------------------------ */ + + /* PLL configuration: PLLCLK = PREDIV1 * 9 = 36 MHz */ + RCC->CFGR &= + (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | + RCC_CFGR_PLLMULL); + RCC->CFGR |= + (uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | + RCC_CFGR_PLLMULL9); + + /*!< PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ + /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */ + + RCC->CFGR2 &= + (uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | + RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); + RCC->CFGR2 |= + (uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | + RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10); + + /* Enable PLL2 */ + RCC->CR |= RCC_CR_PLL2ON; + /* Wait till PLL2 is ready */ + while ((RCC->CR & RCC_CR_PLL2RDY) == 0) { + } + +#else + /* PLL configuration: PLLCLK = (HSE / 2) * 9 = 36 MHz */ + RCC->CFGR &= + (uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | + RCC_CFGR_PLLMULL)); + RCC->CFGR |= + (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | + RCC_CFGR_PLLMULL9); #endif /* STM32F10X_CL */ - /* Enable PLL */ - RCC->CR |= RCC_CR_PLLON; + /* Enable PLL */ + RCC->CR |= RCC_CR_PLLON; - /* Wait till PLL is ready */ - while((RCC->CR & RCC_CR_PLLRDY) == 0) - { + /* Wait till PLL is ready */ + while ((RCC->CR & RCC_CR_PLLRDY) == 0) { + } + + /* Select PLL as system clock source */ + RCC->CFGR &= (uint32_t) ((uint32_t) ~ (RCC_CFGR_SW)); + RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; + + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) { + } + } else { /* If HSE fails to start-up, the application will have wrong clock + configuration. User can add here some code to deal with this error */ } - - /* Select PLL as system clock source */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); - RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL; - - /* Wait till PLL is used as system clock source */ - while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) - { - } - } - else - { /* If HSE fails to start-up, the application will have wrong clock - configuration. User can add here some code to deal with this error */ - } } #elif defined SYSCLK_FREQ_48MHz /** @@ -720,97 +715,95 @@ static void SetSysClockTo36(void) * @param None * @retval None */ -static void SetSysClockTo48(void) +static void SetSysClockTo48( + void) { - __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - - /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/ - /* Enable HSE */ - RCC->CR |= ((uint32_t)RCC_CR_HSEON); - - /* Wait till HSE is ready and if Time out is reached exit */ - do - { - HSEStatus = RCC->CR & RCC_CR_HSERDY; - StartUpCounter++; - } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - if ((RCC->CR & RCC_CR_HSERDY) != RESET) - { - HSEStatus = (uint32_t)0x01; - } - else - { - HSEStatus = (uint32_t)0x00; - } + /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration --------------------------- */ + /* Enable HSE */ + RCC->CR |= ((uint32_t) RCC_CR_HSEON); - if (HSEStatus == (uint32_t)0x01) - { - /* Enable Prefetch Buffer */ - FLASH->ACR |= FLASH_ACR_PRFTBE; + /* Wait till HSE is ready and if Time out is reached exit */ + do { + HSEStatus = RCC->CR & RCC_CR_HSERDY; + StartUpCounter++; + } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); - /* Flash 1 wait state */ - FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY); - FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1; - - /* HCLK = SYSCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; - - /* PCLK2 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1; - - /* PCLK1 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2; - -#ifdef STM32F10X_CL - /* Configure PLLs ------------------------------------------------------*/ - /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ - /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */ - - RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | - RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); - RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | - RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5); - - /* Enable PLL2 */ - RCC->CR |= RCC_CR_PLL2ON; - /* Wait till PLL2 is ready */ - while((RCC->CR & RCC_CR_PLL2RDY) == 0) - { + if ((RCC->CR & RCC_CR_HSERDY) != RESET) { + HSEStatus = (uint32_t) 0x01; + } else { + HSEStatus = (uint32_t) 0x00; } - - - /* PLL configuration: PLLCLK = PREDIV1 * 6 = 48 MHz */ - RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | - RCC_CFGR_PLLMULL6); -#else - /* PLL configuration: PLLCLK = HSE * 6 = 48 MHz */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6); + + if (HSEStatus == (uint32_t) 0x01) { + /* Enable Prefetch Buffer */ + FLASH->ACR |= FLASH_ACR_PRFTBE; + + /* Flash 1 wait state */ + FLASH->ACR &= (uint32_t) ((uint32_t) ~ FLASH_ACR_LATENCY); + FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_1; + + /* HCLK = SYSCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_HPRE_DIV1; + + /* PCLK2 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE2_DIV1; + + /* PCLK1 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE1_DIV2; + +#ifdef STM32F10X_CL + /* Configure PLLs ------------------------------------------------------ */ + /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ + /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */ + + RCC->CFGR2 &= + (uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | + RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); + RCC->CFGR2 |= + (uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | + RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5); + + /* Enable PLL2 */ + RCC->CR |= RCC_CR_PLL2ON; + /* Wait till PLL2 is ready */ + while ((RCC->CR & RCC_CR_PLL2RDY) == 0) { + } + + + /* PLL configuration: PLLCLK = PREDIV1 * 6 = 48 MHz */ + RCC->CFGR &= + (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | + RCC_CFGR_PLLMULL); + RCC->CFGR |= + (uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | + RCC_CFGR_PLLMULL6); +#else + /* PLL configuration: PLLCLK = HSE * 6 = 48 MHz */ + RCC->CFGR &= + (uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | + RCC_CFGR_PLLMULL)); + RCC->CFGR |= (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6); #endif /* STM32F10X_CL */ - /* Enable PLL */ - RCC->CR |= RCC_CR_PLLON; + /* Enable PLL */ + RCC->CR |= RCC_CR_PLLON; - /* Wait till PLL is ready */ - while((RCC->CR & RCC_CR_PLLRDY) == 0) - { + /* Wait till PLL is ready */ + while ((RCC->CR & RCC_CR_PLLRDY) == 0) { + } + + /* Select PLL as system clock source */ + RCC->CFGR &= (uint32_t) ((uint32_t) ~ (RCC_CFGR_SW)); + RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; + + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) { + } + } else { /* If HSE fails to start-up, the application will have wrong clock + configuration. User can add here some code to deal with this error */ } - - /* Select PLL as system clock source */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); - RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL; - - /* Wait till PLL is used as system clock source */ - while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) - { - } - } - else - { /* If HSE fails to start-up, the application will have wrong clock - configuration. User can add here some code to deal with this error */ - } } #elif defined SYSCLK_FREQ_56MHz @@ -821,98 +814,96 @@ static void SetSysClockTo48(void) * @param None * @retval None */ -static void SetSysClockTo56(void) +static void SetSysClockTo56( + void) { - __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - - /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/ - /* Enable HSE */ - RCC->CR |= ((uint32_t)RCC_CR_HSEON); - - /* Wait till HSE is ready and if Time out is reached exit */ - do - { - HSEStatus = RCC->CR & RCC_CR_HSERDY; - StartUpCounter++; - } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - if ((RCC->CR & RCC_CR_HSERDY) != RESET) - { - HSEStatus = (uint32_t)0x01; - } - else - { - HSEStatus = (uint32_t)0x00; - } + /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration --------------------------- */ + /* Enable HSE */ + RCC->CR |= ((uint32_t) RCC_CR_HSEON); - if (HSEStatus == (uint32_t)0x01) - { - /* Enable Prefetch Buffer */ - FLASH->ACR |= FLASH_ACR_PRFTBE; + /* Wait till HSE is ready and if Time out is reached exit */ + do { + HSEStatus = RCC->CR & RCC_CR_HSERDY; + StartUpCounter++; + } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); - /* Flash 2 wait state */ - FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY); - FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2; - - /* HCLK = SYSCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; - - /* PCLK2 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1; - - /* PCLK1 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2; + if ((RCC->CR & RCC_CR_HSERDY) != RESET) { + HSEStatus = (uint32_t) 0x01; + } else { + HSEStatus = (uint32_t) 0x00; + } + + if (HSEStatus == (uint32_t) 0x01) { + /* Enable Prefetch Buffer */ + FLASH->ACR |= FLASH_ACR_PRFTBE; + + /* Flash 2 wait state */ + FLASH->ACR &= (uint32_t) ((uint32_t) ~ FLASH_ACR_LATENCY); + FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_2; + + /* HCLK = SYSCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_HPRE_DIV1; + + /* PCLK2 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE2_DIV1; + + /* PCLK1 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE1_DIV2; #ifdef STM32F10X_CL - /* Configure PLLs ------------------------------------------------------*/ - /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ - /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */ - - RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | - RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); - RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | - RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5); - - /* Enable PLL2 */ - RCC->CR |= RCC_CR_PLL2ON; - /* Wait till PLL2 is ready */ - while((RCC->CR & RCC_CR_PLL2RDY) == 0) - { - } - - - /* PLL configuration: PLLCLK = PREDIV1 * 7 = 56 MHz */ - RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | - RCC_CFGR_PLLMULL7); -#else - /* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL7); + /* Configure PLLs ------------------------------------------------------ */ + /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ + /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */ + + RCC->CFGR2 &= + (uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | + RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); + RCC->CFGR2 |= + (uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | + RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5); + + /* Enable PLL2 */ + RCC->CR |= RCC_CR_PLL2ON; + /* Wait till PLL2 is ready */ + while ((RCC->CR & RCC_CR_PLL2RDY) == 0) { + } + + + /* PLL configuration: PLLCLK = PREDIV1 * 7 = 56 MHz */ + RCC->CFGR &= + (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | + RCC_CFGR_PLLMULL); + RCC->CFGR |= + (uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | + RCC_CFGR_PLLMULL7); +#else + /* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */ + RCC->CFGR &= + (uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | + RCC_CFGR_PLLMULL)); + RCC->CFGR |= (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL7); #endif /* STM32F10X_CL */ - /* Enable PLL */ - RCC->CR |= RCC_CR_PLLON; + /* Enable PLL */ + RCC->CR |= RCC_CR_PLLON; - /* Wait till PLL is ready */ - while((RCC->CR & RCC_CR_PLLRDY) == 0) - { + /* Wait till PLL is ready */ + while ((RCC->CR & RCC_CR_PLLRDY) == 0) { + } + + /* Select PLL as system clock source */ + RCC->CFGR &= (uint32_t) ((uint32_t) ~ (RCC_CFGR_SW)); + RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; + + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) { + } + } else { /* If HSE fails to start-up, the application will have wrong clock + configuration. User can add here some code to deal with this error */ } - - /* Select PLL as system clock source */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); - RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL; - - /* Wait till PLL is used as system clock source */ - while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) - { - } - } - else - { /* If HSE fails to start-up, the application will have wrong clock - configuration. User can add here some code to deal with this error */ - } } #elif defined SYSCLK_FREQ_72MHz @@ -923,99 +914,96 @@ static void SetSysClockTo56(void) * @param None * @retval None */ -static void SetSysClockTo72(void) +static void SetSysClockTo72( + void) { - __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - - /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/ - /* Enable HSE */ - RCC->CR |= ((uint32_t)RCC_CR_HSEON); - - /* Wait till HSE is ready and if Time out is reached exit */ - do - { - HSEStatus = RCC->CR & RCC_CR_HSERDY; - StartUpCounter++; - } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; - if ((RCC->CR & RCC_CR_HSERDY) != RESET) - { - HSEStatus = (uint32_t)0x01; - } - else - { - HSEStatus = (uint32_t)0x00; - } + /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration --------------------------- */ + /* Enable HSE */ + RCC->CR |= ((uint32_t) RCC_CR_HSEON); - if (HSEStatus == (uint32_t)0x01) - { - /* Enable Prefetch Buffer */ - FLASH->ACR |= FLASH_ACR_PRFTBE; + /* Wait till HSE is ready and if Time out is reached exit */ + do { + HSEStatus = RCC->CR & RCC_CR_HSERDY; + StartUpCounter++; + } while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); - /* Flash 2 wait state */ - FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY); - FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2; + if ((RCC->CR & RCC_CR_HSERDY) != RESET) { + HSEStatus = (uint32_t) 0x01; + } else { + HSEStatus = (uint32_t) 0x00; + } - - /* HCLK = SYSCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; - - /* PCLK2 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1; - - /* PCLK1 = HCLK */ - RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2; + if (HSEStatus == (uint32_t) 0x01) { + /* Enable Prefetch Buffer */ + FLASH->ACR |= FLASH_ACR_PRFTBE; + + /* Flash 2 wait state */ + FLASH->ACR &= (uint32_t) ((uint32_t) ~ FLASH_ACR_LATENCY); + FLASH->ACR |= (uint32_t) FLASH_ACR_LATENCY_2; + + + /* HCLK = SYSCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_HPRE_DIV1; + + /* PCLK2 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE2_DIV1; + + /* PCLK1 = HCLK */ + RCC->CFGR |= (uint32_t) RCC_CFGR_PPRE1_DIV2; #ifdef STM32F10X_CL - /* Configure PLLs ------------------------------------------------------*/ - /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ - /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */ - - RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | - RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); - RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | - RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5); - - /* Enable PLL2 */ - RCC->CR |= RCC_CR_PLL2ON; - /* Wait till PLL2 is ready */ - while((RCC->CR & RCC_CR_PLL2RDY) == 0) - { - } - - - /* PLL configuration: PLLCLK = PREDIV1 * 9 = 72 MHz */ - RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | - RCC_CFGR_PLLMULL9); -#else - /* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | - RCC_CFGR_PLLMULL)); - RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9); + /* Configure PLLs ------------------------------------------------------ */ + /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */ + /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */ + + RCC->CFGR2 &= + (uint32_t) ~ (RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL | + RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC); + RCC->CFGR2 |= + (uint32_t) (RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 | + RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5); + + /* Enable PLL2 */ + RCC->CR |= RCC_CR_PLL2ON; + /* Wait till PLL2 is ready */ + while ((RCC->CR & RCC_CR_PLL2RDY) == 0) { + } + + + /* PLL configuration: PLLCLK = PREDIV1 * 9 = 72 MHz */ + RCC->CFGR &= + (uint32_t) ~ (RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | + RCC_CFGR_PLLMULL); + RCC->CFGR |= + (uint32_t) (RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | + RCC_CFGR_PLLMULL9); +#else + /* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */ + RCC->CFGR &= + (uint32_t) ((uint32_t) ~ (RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | + RCC_CFGR_PLLMULL)); + RCC->CFGR |= (uint32_t) (RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9); #endif /* STM32F10X_CL */ - /* Enable PLL */ - RCC->CR |= RCC_CR_PLLON; + /* Enable PLL */ + RCC->CR |= RCC_CR_PLLON; - /* Wait till PLL is ready */ - while((RCC->CR & RCC_CR_PLLRDY) == 0) - { - } - - /* Select PLL as system clock source */ - RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); - RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL; + /* Wait till PLL is ready */ + while ((RCC->CR & RCC_CR_PLLRDY) == 0) { + } - /* Wait till PLL is used as system clock source */ - while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) - { + /* Select PLL as system clock source */ + RCC->CFGR &= (uint32_t) ((uint32_t) ~ (RCC_CFGR_SW)); + RCC->CFGR |= (uint32_t) RCC_CFGR_SW_PLL; + + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR & (uint32_t) RCC_CFGR_SWS) != (uint32_t) 0x08) { + } + } else { /* If HSE fails to start-up, the application will have wrong clock + configuration. User can add here some code to deal with this error */ } - } - else - { /* If HSE fails to start-up, the application will have wrong clock - configuration. User can add here some code to deal with this error */ - } } #endif @@ -1026,8 +1014,8 @@ static void SetSysClockTo72(void) /** * @} */ - + /** * @} - */ + */ /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ diff --git a/bacnet-stack/ports/stm32f10x/timer_sys.c b/bacnet-stack/ports/stm32f10x/timer_sys.c index 26c8b4d3..46a30aa8 100644 --- a/bacnet-stack/ports/stm32f10x/timer_sys.c +++ b/bacnet-stack/ports/stm32f10x/timer_sys.c @@ -61,7 +61,8 @@ static void timer_debug_off( * Returns: none * Notes: none *************************************************************************/ -void timer_debug_toggle(void) +void timer_debug_toggle( + void) { static bool state = false; @@ -79,7 +80,8 @@ void timer_debug_toggle(void) * Returns: nothing * Notes: reserved name for ISR handlers *************************************************************************/ -void SysTick_Handler(void) +void SysTick_Handler( + void) { /* increment the tick count */ Millisecond_Counter++; @@ -91,7 +93,8 @@ void SysTick_Handler(void) * Returns: none * Notes: none *************************************************************************/ -uint32_t timer_milliseconds(void) +uint32_t timer_milliseconds( + void) { return Millisecond_Counter; } @@ -101,7 +104,8 @@ uint32_t timer_milliseconds(void) * Returns: none * Notes: peripheral frequency defined in hardware.h *************************************************************************/ -void timer_init(void) +void timer_init( + void) { GPIO_InitTypeDef GPIO_InitStructure; diff --git a/bacnet-stack/ports/win32/main.c b/bacnet-stack/ports/win32/main.c index b139c46c..61505952 100644 --- a/bacnet-stack/ports/win32/main.c +++ b/bacnet-stack/ports/win32/main.c @@ -76,7 +76,7 @@ static object_functions_t Object_Table[] = { #if defined(BACFILE) {FILE_OBJ_FUNCTIONS}, #endif - {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, }; /* buffer used for receive */ @@ -189,7 +189,7 @@ static void LocalIAmHandler( static void Init_Service_Handlers( void) { - Device_Initialize_Object_Functions(&Object_Table[0]); + Device_Initialize_Object_Functions(&Object_Table[0]); Device_Init(); /* we need to handle who-is to support dynamic device binding */ diff --git a/bacnet-stack/ports/win32/timer.c b/bacnet-stack/ports/win32/timer.c index ab88cc59..564e82fd 100644 --- a/bacnet-stack/ports/win32/timer.c +++ b/bacnet-stack/ports/win32/timer.c @@ -38,9 +38,9 @@ /* Offset between Windows epoch 1/1/1601 and Unix epoch 1/1/1970 in 100 nanosec units */ #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 #else - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL #endif /* counter for the various timers */ @@ -81,16 +81,16 @@ int gettimeofday( usec_timer <<= 32; usec_timer |= ft.dwLowDateTime; /*converting file time to unix epoch 1970 */ - usec_timer /= 10; /*convert into microseconds*/ + usec_timer /= 10; /*convert into microseconds */ usec_timer -= DELTA_EPOCH_IN_MICROSECS; - tp->tv_sec = (long)(usec_timer / 1000000UL); - tp->tv_usec = (long)(usec_timer % 1000000UL); + tp->tv_sec = (long) (usec_timer / 1000000UL); + tp->tv_usec = (long) (usec_timer % 1000000UL); time_start = timeGetTime(); } else { elapsed_milliseconds = timeGetTime() - time_start; usec_elapsed = usec_timer + (elapsed_milliseconds * 1000UL); - tp->tv_sec = (long)(usec_elapsed / 1000000UL); - tp->tv_usec = (long)(usec_elapsed % 1000000UL); + tp->tv_sec = (long) (usec_elapsed / 1000000UL); + tp->tv_usec = (long) (usec_elapsed % 1000000UL); } if (tzp) { if (!tzflag) { @@ -207,8 +207,9 @@ void timer_init( /* configure for 1ms resolution - if possible */ Timer_Period = min(max(tc.wPeriodMin, 1L), tc.wPeriodMax); if (Timer_Period != 1L) { - fprintf(stderr, "Failed to set timer to 1ms. " - "Time period set to %ums\n", (unsigned)Timer_Period); + fprintf(stderr, + "Failed to set timer to 1ms. " "Time period set to %ums\n", + (unsigned) Timer_Period); } timeBeginPeriod(Timer_Period); atexit(timer_cleanup); @@ -234,7 +235,7 @@ int main( { long now = 0, last = 0, delta = 0; struct timeval tv; - struct timeval old_tv = {0}; + struct timeval old_tv = { 0 }; timer_init(); printf("Testing granularity of timeGetTime()...\n"); diff --git a/bacnet-stack/src/address.c b/bacnet-stack/src/address.c index 1cffa485..745d652a 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/bacapp.c b/bacnet-stack/src/bacapp.c index c569996e..4a1c5b3e 100644 --- a/bacnet-stack/src/bacapp.c +++ b/bacnet-stack/src/bacapp.c @@ -1008,8 +1008,8 @@ bool bacapp_print_value( case PROP_OBJECT_TYPE: if (value->type.Enumerated < MAX_ASHRAE_OBJECT_TYPE) { fprintf(stream, "%s", - bactext_object_type_name(value-> - type.Enumerated)); + bactext_object_type_name(value->type. + Enumerated)); } else if (value->type.Enumerated < 128) { fprintf(stream, "reserved %lu", (unsigned long) value->type.Enumerated); @@ -1025,8 +1025,8 @@ bool bacapp_print_value( case PROP_UNITS: if (value->type.Enumerated < 256) { fprintf(stream, "%s", - bactext_engineering_unit_name(value->type. - Enumerated)); + bactext_engineering_unit_name(value-> + type.Enumerated)); } else { fprintf(stream, "proprietary %lu", (unsigned long) value->type.Enumerated); @@ -1034,14 +1034,14 @@ bool bacapp_print_value( break; case PROP_POLARITY: fprintf(stream, "%s", - bactext_binary_polarity_name(value->type. - Enumerated)); + bactext_binary_polarity_name(value-> + type.Enumerated)); break; case PROP_PRESENT_VALUE: if (object_type < PROPRIETARY_BACNET_OBJECT_TYPE) { fprintf(stream, "%s", - bactext_binary_present_value_name(value-> - type.Enumerated)); + bactext_binary_present_value_name(value->type. + Enumerated)); } else { fprintf(stream, "%lu", (unsigned long) value->type.Enumerated); @@ -1053,8 +1053,8 @@ bool bacapp_print_value( break; case PROP_SYSTEM_STATUS: fprintf(stream, "%s", - bactext_device_status_name(value->type. - Enumerated)); + bactext_device_status_name(value-> + type.Enumerated)); break; case PROP_SEGMENTATION_SUPPORTED: fprintf(stream, "%s", @@ -1425,8 +1425,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 01a039fa..aec57507 100644 --- a/bacnet-stack/src/bacdcode.c +++ b/bacnet-stack/src/bacdcode.c @@ -2277,8 +2277,7 @@ void testBACDCodeObject( uint32_t decoded_instance = 0; encode_bacnet_object_id(&encoded_array[0], type, instance); - decode_object_id(&encoded_array[0], &decoded_type, - &decoded_instance); + decode_object_id(&encoded_array[0], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == type); ct_test(pTest, decoded_instance == instance); encode_bacnet_object_id(&object_array[0], type, instance); diff --git a/bacnet-stack/src/bacpropstates.c b/bacnet-stack/src/bacpropstates.c index fc137b0f..e75481ec 100644 --- a/bacnet-stack/src/bacpropstates.c +++ b/bacnet-stack/src/bacpropstates.c @@ -51,8 +51,7 @@ int bacapp_decode_property_state( uint8_t tagnum; section_length = - decode_tag_number_and_value(&apdu[len], &tagnum, - &len_value_type); + decode_tag_number_and_value(&apdu[len], &tagnum, &len_value_type); if (-1 == section_length) { return -1; diff --git a/bacnet-stack/src/bacstr.c b/bacnet-stack/src/bacstr.c index 83b0b0fc..33832b04 100644 --- a/bacnet-stack/src/bacstr.c +++ b/bacnet-stack/src/bacstr.c @@ -496,26 +496,36 @@ bool characterstring_printable( by Jeff Bezanson placed in the public domain Fall 2005 */ static const char trailingBytesForUTF8[256] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, + 4, 4, 4, 5, 5, 5, 5 }; /* based on the valid_utf8 routine from the PCRE library by Philip Hazel length is in bytes, since without knowing whether the string is valid it's hard to know how many characters there are! */ -static int utf8_isvalid(const char *str, int length) +static int utf8_isvalid( + const char *str, + int length) { - const unsigned char *p, *pend = (unsigned char*)str + length; + const unsigned char *p, *pend = (unsigned char *) str + length; unsigned char c; int ab; - for (p = (unsigned char*)str; p < pend; p++) { + for (p = (unsigned char *) str; p < pend; p++) { c = *p; /* null in middle of string */ if (c == 0) { @@ -541,37 +551,42 @@ static int utf8_isvalid(const char *str, int length) } /* Check for overlong sequences for each different length */ switch (ab) { - /* Check for xx00 000x */ - case 1: - if ((c & 0x3e) == 0) return 0; - continue; /* We know there aren't any more bytes to check */ + /* Check for xx00 000x */ + case 1: + if ((c & 0x3e) == 0) + return 0; + continue; /* We know there aren't any more bytes to check */ - /* Check for 1110 0000, xx0x xxxx */ - case 2: - if (c == 0xe0 && (*p & 0x20) == 0) return 0; - break; + /* Check for 1110 0000, xx0x xxxx */ + case 2: + if (c == 0xe0 && (*p & 0x20) == 0) + return 0; + break; - /* Check for 1111 0000, xx00 xxxx */ - case 3: - if (c == 0xf0 && (*p & 0x30) == 0) return 0; - break; + /* Check for 1111 0000, xx00 xxxx */ + case 3: + if (c == 0xf0 && (*p & 0x30) == 0) + return 0; + break; - /* Check for 1111 1000, xx00 0xxx */ - case 4: - if (c == 0xf8 && (*p & 0x38) == 0) return 0; - break; + /* Check for 1111 1000, xx00 0xxx */ + case 4: + if (c == 0xf8 && (*p & 0x38) == 0) + return 0; + break; - /* Check for leading 0xfe or 0xff, - and then for 1111 1100, xx00 00xx */ - case 5: - if (c == 0xfe || c == 0xff || - (c == 0xfc && (*p & 0x3c) == 0)) return 0; - break; + /* Check for leading 0xfe or 0xff, + and then for 1111 1100, xx00 00xx */ + case 5: + if (c == 0xfe || c == 0xff || (c == 0xfc && (*p & 0x3c) == 0)) + return 0; + break; } /* Check for valid bytes after the 2nd, if any; all must start 10 */ while (--ab > 0) { - if ((*(++p) & 0xc0) != 0x80) return 0; + if ((*(++p) & 0xc0) != 0x80) + return 0; } } diff --git a/bacnet-stack/src/bactext.c b/bacnet-stack/src/bactext.c index 0a9db1a4..51b56239 100644 --- a/bacnet-stack/src/bactext.c +++ b/bacnet-stack/src/bactext.c @@ -2002,7 +2002,7 @@ INDTEXT_DATA network_layer_msg_names[] = { {NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, "I-Am-Router-To-Network"} , {NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK, - "I-Could-Be-Router-To-Network"} + "I-Could-Be-Router-To-Network"} , {NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, "Reject-Message-to-Network"} , diff --git a/bacnet-stack/src/bvlc.c b/bacnet-stack/src/bvlc.c index 1d2352d1..cc639277 100644 --- a/bacnet-stack/src/bvlc.c +++ b/bacnet-stack/src/bvlc.c @@ -656,8 +656,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()) diff --git a/bacnet-stack/src/event.c b/bacnet-stack/src/event.c index 8f6ea4c3..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; @@ -1020,9 +1025,9 @@ void testEventEventState( data.notificationParams.changeOfState.newState.state.units == data2.notificationParams.changeOfState.newState.state.units); - ct_test(pTest, bitstring_same( - &data.notificationParams.changeOfState.statusFlags, - &data2.notificationParams.changeOfState.statusFlags)); + ct_test(pTest, + bitstring_same(&data.notificationParams.changeOfState.statusFlags, + &data2.notificationParams.changeOfState.statusFlags)); /**********************************************************************************/ /**********************************************************************************/ @@ -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); @@ -1110,13 +1115,14 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, bitstring_same( - &data.notificationParams.changeOfBitstring.referencedBitString, - &data2.notificationParams.changeOfBitstring.referencedBitString)); + ct_test(pTest, + bitstring_same(&data.notificationParams.changeOfBitstring. + referencedBitString, + &data2.notificationParams.changeOfBitstring.referencedBitString)); - ct_test(pTest, bitstring_same( - &data.notificationParams.changeOfBitstring.statusFlags, - &data2.notificationParams.changeOfBitstring.statusFlags)); + ct_test(pTest, + bitstring_same(&data.notificationParams.changeOfBitstring.statusFlags, + &data2.notificationParams.changeOfBitstring.statusFlags)); /**********************************************************************************/ /**********************************************************************************/ @@ -1154,9 +1160,9 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, bitstring_same( - &data.notificationParams.changeOfValue.statusFlags, - &data2.notificationParams.changeOfValue.statusFlags)); + ct_test(pTest, + bitstring_same(&data.notificationParams.changeOfValue.statusFlags, + &data2.notificationParams.changeOfValue.statusFlags)); ct_test(pTest, data.notificationParams.changeOfValue.tag == @@ -1174,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); @@ -1195,17 +1201,18 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, bitstring_same( - &data.notificationParams.changeOfValue.statusFlags, - &data2.notificationParams.changeOfValue.statusFlags)); + ct_test(pTest, + bitstring_same(&data.notificationParams.changeOfValue.statusFlags, + &data2.notificationParams.changeOfValue.statusFlags)); ct_test(pTest, data.notificationParams.changeOfValue.tag == data2.notificationParams.changeOfValue.tag); - ct_test(pTest, bitstring_same( - &data.notificationParams.changeOfValue.newValue.changedBits, - &data2.notificationParams.changeOfValue.newValue.changedBits)); + ct_test(pTest, + bitstring_same(&data.notificationParams.changeOfValue.newValue. + changedBits, + &data2.notificationParams.changeOfValue.newValue.changedBits)); /**********************************************************************************/ /**********************************************************************************/ @@ -1254,9 +1261,9 @@ void testEventEventState( ct_test(pTest, data.notificationParams.floatingLimit.errorLimit == data2.notificationParams.floatingLimit.errorLimit); - ct_test(pTest, bitstring_same( - &data.notificationParams.floatingLimit.statusFlags, - &data2.notificationParams.floatingLimit.statusFlags)); + ct_test(pTest, + bitstring_same(&data.notificationParams.floatingLimit.statusFlags, + &data2.notificationParams.floatingLimit.statusFlags)); /**********************************************************************************/ @@ -1306,9 +1313,9 @@ void testEventEventState( ct_test(pTest, data.notificationParams.outOfRange.exceedingValue == data2.notificationParams.outOfRange.exceedingValue); - ct_test(pTest, bitstring_same( - &data.notificationParams.outOfRange.statusFlags, - &data2.notificationParams.outOfRange.statusFlags)); + ct_test(pTest, + bitstring_same(&data.notificationParams.outOfRange.statusFlags, + &data2.notificationParams.outOfRange.statusFlags)); /**********************************************************************************/ /**********************************************************************************/ @@ -1361,9 +1368,9 @@ void testEventEventState( data.notificationParams.changeOfLifeSafety.operationExpected == data2.notificationParams.changeOfLifeSafety.operationExpected); - ct_test(pTest, bitstring_same( - &data.notificationParams.changeOfLifeSafety.statusFlags, - &data2.notificationParams.changeOfLifeSafety.statusFlags)); + ct_test(pTest, + bitstring_same(&data.notificationParams.changeOfLifeSafety.statusFlags, + &data2.notificationParams.changeOfLifeSafety.statusFlags)); /**********************************************************************************/ /**********************************************************************************/ @@ -1408,9 +1415,9 @@ void testEventEventState( data.notificationParams.unsignedRange.exceededLimit == data2.notificationParams.unsignedRange.exceededLimit); - ct_test(pTest, bitstring_same( - &data.notificationParams.unsignedRange.statusFlags, - &data2.notificationParams.unsignedRange.statusFlags)); + ct_test(pTest, + bitstring_same(&data.notificationParams.unsignedRange.statusFlags, + &data2.notificationParams.unsignedRange.statusFlags)); /**********************************************************************************/ /**********************************************************************************/ @@ -1427,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; @@ -1457,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/ptransfer.c b/bacnet-stack/src/ptransfer.c index 87789148..99e36861 100644 --- a/bacnet-stack/src/ptransfer.c +++ b/bacnet-stack/src/ptransfer.c @@ -642,8 +642,7 @@ void test_Unconfirmed_Private_Transfer_Request( len = uptransfer_encode_apdu(&apdu[0], &private_data); ct_test(pTest, len != 0); apdu_len = len; - len = - uptransfer_decode_apdu(&apdu[0], apdu_len, &test_data); + len = uptransfer_decode_apdu(&apdu[0], apdu_len, &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); diff --git a/bacnet-stack/src/ringbuf.c b/bacnet-stack/src/ringbuf.c index 8a98350c..146459d3 100644 --- a/bacnet-stack/src/ringbuf.c +++ b/bacnet-stack/src/ringbuf.c @@ -198,7 +198,7 @@ void Ringbuf_Init( /* test the ring buffer */ void testRingAroundBuffer( Test * pTest, - RING_BUFFER *test_buffer, + RING_BUFFER * test_buffer, uint8_t * data_element, unsigned element_size, unsigned element_count) @@ -319,22 +319,14 @@ void testRingBuf( } ct_test(pTest, Ringbuf_Empty(&test_buffer)); - testRingAroundBuffer( - pTest, - &test_buffer, - data_element, - element_size, + testRingAroundBuffer(pTest, &test_buffer, data_element, element_size, element_count); /* adjust the internal index of Ringbuf to test unsigned wrapping */ - test_buffer.head = UINT_MAX-1; - test_buffer.tail = UINT_MAX-1; + test_buffer.head = UINT_MAX - 1; + test_buffer.tail = UINT_MAX - 1; - testRingAroundBuffer( - pTest, - &test_buffer, - data_element, - element_size, + testRingAroundBuffer(pTest, &test_buffer, data_element, element_size, element_count); return; diff --git a/bacnet-stack/src/wpm.c b/bacnet-stack/src/wpm.c index 2f1d2f84..c6eda70a 100644 --- a/bacnet-stack/src/wpm.c +++ b/bacnet-stack/src/wpm.c @@ -33,38 +33,39 @@ /** @file wpm.c Encode/Decode BACnet Write Property Multiple APDUs */ /* decode service */ -int wpm_decode_object_id(uint8_t * apdu, uint16_t apdu_len, - BACNET_WRITE_PROPERTY_DATA * data) +int wpm_decode_object_id( + uint8_t * apdu, + uint16_t apdu_len, + BACNET_WRITE_PROPERTY_DATA * data) { - uint8_t tag_number = 0; - uint32_t len_value = 0; + uint8_t tag_number = 0; + uint32_t len_value = 0; uint32_t object_instance = 0; uint16_t object_type = 0; uint16_t len = 0; - if((apdu )&& (apdu_len)) - { + if ((apdu) && (apdu_len)) { /* Context tag 0 - Object ID */ - len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); - if(tag_number == 0) - { - len += decode_object_id(&apdu[len], &object_type, &object_instance); + len += + decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + if (tag_number == 0) { + len += + decode_object_id(&apdu[len], &object_type, &object_instance); data->object_type = object_type; data->object_instance = object_instance; - } - else + } else return -1; - } - else + } else return -1; return len; } -int wpm_decode_object_property(uint8_t * apdu, - uint16_t apdu_len, - BACNET_WRITE_PROPERTY_DATA * wp_data) +int wpm_decode_object_property( + uint8_t * apdu, + uint16_t apdu_len, + BACNET_WRITE_PROPERTY_DATA * wp_data) { uint8_t tag_number = 0; uint32_t len_value = 0; @@ -72,68 +73,70 @@ int wpm_decode_object_property(uint8_t * apdu, int len = 0, i = 0; - if((apdu) && (apdu_len) && (wp_data)) - { + if ((apdu) && (apdu_len) && (wp_data)) { wp_data->array_index = BACNET_ARRAY_ALL; - wp_data->priority = BACNET_MAX_PRIORITY; + wp_data->priority = BACNET_MAX_PRIORITY; wp_data->application_data_len = 0; /* tag 0 - Property Identifier */ - len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); - if(tag_number == 0) - { + len += + decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + if (tag_number == 0) { len += decode_enumerated(&apdu[len], len_value, &ulVal); wp_data->object_property = ulVal; - } - else + } else return -1; /* tag 1 - Property Array Index - optional */ - len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); - if(tag_number == 1) - { - len += decode_unsigned(&apdu[len],len_value, &ulVal); + len += + decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + if (tag_number == 1) { + len += decode_unsigned(&apdu[len], len_value, &ulVal); wp_data->array_index = ulVal; - len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += + decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); } /* tag 2 - Property Value */ - if((tag_number == 2) && (decode_is_opening_tag(&apdu[len-1]))) - { + if ((tag_number == 2) && (decode_is_opening_tag(&apdu[len - 1]))) { len--; - wp_data->application_data_len = bacapp_data_len(&apdu[len], - apdu_len - len, wp_data->object_property); + wp_data->application_data_len = + bacapp_data_len(&apdu[len], apdu_len - len, + wp_data->object_property); len++; /* copy application data */ - for(i = 0; i < wp_data->application_data_len; i++) - wp_data->application_data[i] = apdu[len+i]; + for (i = 0; i < wp_data->application_data_len; i++) + wp_data->application_data[i] = apdu[len + i]; len += wp_data->application_data_len; - len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += + decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); /* closing tag 2 */ - if((tag_number != 2) &&(decode_is_closing_tag(&apdu[len-1]))) + if ((tag_number != 2) && (decode_is_closing_tag(&apdu[len - 1]))) return -1; - } - else + } else return -1; /* tag 3 - Priority - optional */ - len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); - if(tag_number == 3) { + len += + decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + if (tag_number == 3) { len += decode_unsigned(&apdu[len], len_value, &ulVal); wp_data->priority = ulVal; - } - else + } else len--; - } - else + } else return -1; return len; } -int wpm_ack_encode_apdu_init(uint8_t * apdu, uint8_t invoke_id) +int wpm_ack_encode_apdu_init( + uint8_t * apdu, + uint8_t invoke_id) { int len = 0; @@ -146,13 +149,14 @@ int wpm_ack_encode_apdu_init(uint8_t * apdu, uint8_t invoke_id) return len; } -int wpm_error_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, - BACNET_WRITE_PROPERTY_DATA * wp_data) +int wpm_error_ack_encode_apdu( + uint8_t * apdu, + uint8_t invoke_id, + BACNET_WRITE_PROPERTY_DATA * wp_data) { int len = 0; - if (apdu) - { + if (apdu) { apdu[len++] = PDU_TYPE_ERROR; apdu[len++] = invoke_id; apdu[len++] = SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE; @@ -160,18 +164,19 @@ int wpm_error_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, len += encode_opening_tag(&apdu[len], 0); len += encode_application_enumerated(&apdu[len], wp_data->error_class); len += encode_application_enumerated(&apdu[len], wp_data->error_code); - len += encode_closing_tag(&apdu[len], 0); + len += encode_closing_tag(&apdu[len], 0); len += encode_opening_tag(&apdu[len], 1); - len += encode_context_object_id(&apdu[len], 0, - wp_data->object_type, wp_data->object_instance); - len += encode_context_enumerated(&apdu[len], 1, - wp_data->object_property); + len += + encode_context_object_id(&apdu[len], 0, wp_data->object_type, + wp_data->object_instance); + len += + encode_context_enumerated(&apdu[len], 1, wp_data->object_property); - if(wp_data->array_index != BACNET_ARRAY_ALL) - len += encode_context_unsigned(&apdu[len], 2, wp_data->array_index); + if (wp_data->array_index != BACNET_ARRAY_ALL) + len += + encode_context_unsigned(&apdu[len], 2, wp_data->array_index); len += encode_closing_tag(&apdu[len], 1); } return len; } -