From 710cfccfefcc997122585881117d47b005df7b97 Mon Sep 17 00:00:00 2001 From: skarg Date: Tue, 4 May 2010 21:06:26 +0000 Subject: [PATCH] Indented using indent script. --- bacnet-stack/demo/epics/bacepics.h | 20 +- bacnet-stack/demo/epics/main.c | 1147 ++++++++--------- bacnet-stack/demo/handler/dlenv.c | 9 +- bacnet-stack/demo/handler/h_alarm_ack.c | 5 +- bacnet-stack/demo/handler/h_arf_a.c | 2 +- bacnet-stack/demo/handler/h_cov.c | 11 +- bacnet-stack/demo/handler/h_iam.c | 6 +- bacnet-stack/demo/handler/h_ihave.c | 4 +- bacnet-stack/demo/handler/h_lso.c | 3 +- bacnet-stack/demo/handler/h_npdu.c | 6 +- bacnet-stack/demo/handler/h_pt.c | 85 +- bacnet-stack/demo/handler/h_pt_a.c | 10 +- bacnet-stack/demo/handler/h_rd.c | 9 +- bacnet-stack/demo/handler/h_rp.c | 26 +- bacnet-stack/demo/handler/h_rp_a.c | 45 +- bacnet-stack/demo/handler/h_rpm.c | 8 +- bacnet-stack/demo/handler/h_rpm_a.c | 18 +- bacnet-stack/demo/handler/h_rr.c | 38 +- bacnet-stack/demo/handler/h_ucov.c | 3 +- bacnet-stack/demo/handler/h_wp.c | 34 +- bacnet-stack/demo/handler/objects.c | 4 +- bacnet-stack/demo/handler/s_cov.c | 8 +- bacnet-stack/demo/handler/s_iam.c | 13 +- bacnet-stack/demo/handler/s_wp.c | 5 +- bacnet-stack/demo/mstpcap/main.c | 20 +- bacnet-stack/demo/object/ai.c | 15 +- bacnet-stack/demo/object/ao.c | 51 +- bacnet-stack/demo/object/av.c | 49 +- bacnet-stack/demo/object/bacfile.c | 22 +- bacnet-stack/demo/object/bi.c | 32 +- bacnet-stack/demo/object/bo.c | 50 +- bacnet-stack/demo/object/bv.c | 59 +- bacnet-stack/demo/object/device.c | 563 ++++----- bacnet-stack/demo/object/lc.c | 59 +- bacnet-stack/demo/object/lo.c | 62 +- bacnet-stack/demo/object/lsp.c | 38 +- bacnet-stack/demo/object/ms-input.c | 54 +- bacnet-stack/demo/object/mso.c | 56 +- bacnet-stack/demo/object/trendlog.c | 1235 ++++++++++--------- bacnet-stack/demo/readfile/main.c | 2 +- bacnet-stack/demo/readrange/main.c | 279 +++-- bacnet-stack/demo/server/main.c | 4 +- bacnet-stack/demo/ucov/main.c | 3 +- bacnet-stack/include/address.h | 4 +- bacnet-stack/include/ai.h | 4 +- bacnet-stack/include/ao.h | 2 +- bacnet-stack/include/apdu.h | 4 +- bacnet-stack/include/av.h | 2 +- bacnet-stack/include/bacdevobjpropref.h | 2 +- bacnet-stack/include/bacenum.h | 8 +- bacnet-stack/include/bacfile.h | 2 +- bacnet-stack/include/bi.h | 2 +- bacnet-stack/include/bip.h | 2 - bacnet-stack/include/bo.h | 2 +- bacnet-stack/include/bv.h | 2 +- bacnet-stack/include/cov.h | 2 - bacnet-stack/include/datalink.h | 8 +- bacnet-stack/include/dcc.h | 6 +- bacnet-stack/include/device.h | 33 +- bacnet-stack/include/event.h | 10 +- bacnet-stack/include/fifo.h | 4 +- bacnet-stack/include/handlers.h | 11 +- bacnet-stack/include/lc.h | 2 +- bacnet-stack/include/lo.h | 2 +- bacnet-stack/include/lsp.h | 2 +- bacnet-stack/include/ms-input.h | 2 +- bacnet-stack/include/mso.h | 2 +- bacnet-stack/include/rd.h | 6 +- bacnet-stack/include/readrange.h | 27 +- bacnet-stack/include/ringbuf.h | 16 +- bacnet-stack/include/rp.h | 10 +- bacnet-stack/include/rpm.h | 4 +- bacnet-stack/include/trendlog.h | 138 +-- bacnet-stack/include/tsm.h | 3 +- bacnet-stack/include/whohas.h | 1 - bacnet-stack/include/whois.h | 2 - bacnet-stack/include/wp.h | 2 - bacnet-stack/ports/at91sam7s/ai.c | 8 +- bacnet-stack/ports/at91sam7s/av.c | 19 +- bacnet-stack/ports/at91sam7s/bi.c | 9 +- bacnet-stack/ports/at91sam7s/bv.c | 16 +- bacnet-stack/ports/at91sam7s/device.c | 134 +- bacnet-stack/ports/at91sam7s/main.c | 3 +- bacnet-stack/ports/atmega168/ai.c | 3 +- bacnet-stack/ports/atmega168/av.c | 3 +- bacnet-stack/ports/atmega168/bv.c | 7 +- bacnet-stack/ports/atmega168/device.c | 7 +- bacnet-stack/ports/atmega168/device.h | 12 +- bacnet-stack/ports/atmega8/ai.c | 3 +- bacnet-stack/ports/atmega8/av.c | 3 +- bacnet-stack/ports/atmega8/bv.c | 7 +- bacnet-stack/ports/atmega8/device.c | 3 +- bacnet-stack/ports/bdk-atxx4-mstp/ai.c | 10 +- bacnet-stack/ports/bdk-atxx4-mstp/av.c | 31 +- bacnet-stack/ports/bdk-atxx4-mstp/bi.c | 7 +- bacnet-stack/ports/bdk-atxx4-mstp/bo.c | 72 +- bacnet-stack/ports/bdk-atxx4-mstp/device.c | 178 ++- bacnet-stack/ports/bdk-atxx4-mstp/led.c | 10 +- bacnet-stack/ports/bdk-atxx4-mstp/main.c | 6 +- bacnet-stack/ports/bdk-atxx4-mstp/rs485.c | 6 +- bacnet-stack/ports/bdk-atxx4-mstp/rs485.h | 6 +- bacnet-stack/ports/bdk-atxx4-mstp/seeprom.c | 10 +- bacnet-stack/ports/bdk-atxx4-mstp/timer.c | 58 +- bacnet-stack/ports/bdk-atxx4-mstp/timer.h | 5 +- bacnet-stack/ports/bdk-atxx4-mstp/timer2.c | 10 +- bacnet-stack/ports/linux/bip-init.c | 10 +- bacnet-stack/ports/linux/net.h | 3 +- bacnet-stack/ports/linux/timer.h | 2 +- bacnet-stack/ports/pic18f6720/ai.c | 3 +- bacnet-stack/ports/pic18f6720/av.c | 4 +- bacnet-stack/ports/pic18f6720/bi.c | 3 +- bacnet-stack/ports/pic18f6720/bv.c | 7 +- bacnet-stack/ports/pic18f6720/device.c | 10 +- bacnet-stack/ports/win32/bip-init.c | 8 +- bacnet-stack/ports/win32/dlmstp.c | 3 +- bacnet-stack/src/address.c | 179 +-- bacnet-stack/src/alarm_ack.c | 6 +- bacnet-stack/src/apdu.c | 4 +- bacnet-stack/src/bacapp.c | 84 +- bacnet-stack/src/bacdcode.c | 15 +- bacnet-stack/src/bacdevobjpropref.c | 13 +- bacnet-stack/src/bacreal.c | 4 +- bacnet-stack/src/bacstr.c | 2 +- bacnet-stack/src/bactext.c | 2 +- bacnet-stack/src/bvlc.c | 4 +- bacnet-stack/src/datetime.c | 5 +- bacnet-stack/src/event.c | 289 +++-- bacnet-stack/src/getevent.c | 25 +- bacnet-stack/src/mstp.c | 25 +- bacnet-stack/src/ptransfer.c | 6 +- bacnet-stack/src/rd.c | 2 +- bacnet-stack/src/readrange.c | 12 +- bacnet-stack/src/ringbuf.c | 48 +- bacnet-stack/src/tsm.c | 11 +- 134 files changed, 2901 insertions(+), 3035 deletions(-) diff --git a/bacnet-stack/demo/epics/bacepics.h b/bacnet-stack/demo/epics/bacepics.h index dea4ba37..5e7d22f2 100755 --- a/bacnet-stack/demo/epics/bacepics.h +++ b/bacnet-stack/demo/epics/bacepics.h @@ -74,16 +74,16 @@ * @ingroup BACEPICS */ typedef enum { - /** Initial state to establish a binding with the target device. */ - INITIAL_BINDING, - /** Getting ALL properties and values at once with RPM. */ - GET_ALL_REQUEST, GET_ALL_RESPONSE, - /** Getting ALL properties with array index = 0, just to get the list. */ - GET_LIST_OF_ALL_REQUEST, GET_LIST_OF_ALL_RESPONSE, - /** Processing the properties individually with ReadProperty. */ - GET_PROPERTY_REQUEST, GET_PROPERTY_RESPONSE, - /** Done with this Object; move onto the next. */ - NEXT_OBJECT + /** Initial state to establish a binding with the target device. */ + INITIAL_BINDING, + /** Getting ALL properties and values at once with RPM. */ + GET_ALL_REQUEST, GET_ALL_RESPONSE, + /** Getting ALL properties with array index = 0, just to get the list. */ + GET_LIST_OF_ALL_REQUEST, GET_LIST_OF_ALL_RESPONSE, + /** Processing the properties individually with ReadProperty. */ + GET_PROPERTY_REQUEST, GET_PROPERTY_RESPONSE, + /** Done with this Object; move onto the next. */ + NEXT_OBJECT } EPICS_STATES; diff --git a/bacnet-stack/demo/epics/main.c b/bacnet-stack/demo/epics/main.c index 891fe431..4a48bb1e 100644 --- a/bacnet-stack/demo/epics/main.c +++ b/bacnet-stack/demo/epics/main.c @@ -98,7 +98,7 @@ static OS_Keylist Object_List; /* When we need to process an Object's properties one at a time, * then we build and use this list */ -#define MAX_PROPS 100 /* Supersized so it always is big enough. */ +#define MAX_PROPS 100 /* Supersized so it always is big enough. */ static uint32_t Property_List_Length = 0; static uint32_t Property_List_Index = 0; static int32_t Property_List[MAX_PROPS + 2]; @@ -116,7 +116,7 @@ static bool Using_Walked_List = false; * array, then set this true in case it aborts and we need Using_Walked_List */ static bool IsLongArray = false; -static bool ShowValues = false; /* Show value instead of '?' */ +static bool ShowValues = false; /* Show value instead of '?' */ #if !defined(PRINT_ERRORS) #define PRINT_ERRORS 1 @@ -132,7 +132,8 @@ static void MyErrorHandler( (void) src; (void) invoke_id; #if PRINT_ERRORS - printf("-- BACnet Error: %s: %s\r\n", bactext_error_class_name(error_class), + printf("-- BACnet Error: %s: %s\r\n", + bactext_error_class_name(error_class), bactext_error_code_name(error_code)); #else (void) error_class; @@ -153,8 +154,9 @@ void MyAbortHandler( (void) server; #if PRINT_ERRORS /* It is normal for this to fail, so don't print. */ - if ( ( myState != GET_ALL_RESPONSE ) && !IsLongArray ) - printf("-- BACnet Abort: %s ", bactext_abort_reason_name(abort_reason)); + if ((myState != GET_ALL_RESPONSE) && !IsLongArray) + printf("-- BACnet Abort: %s ", + bactext_abort_reason_name(abort_reason)); #else (void) abort_reason; #endif @@ -191,19 +193,17 @@ void MyReadPropertyAckHandler( if (rp_data) { len = rp_ack_fully_decode_service_request(service_request, service_len, - rp_data); + rp_data); } if (len > 0) { memmove(&Read_Property_Multiple_Data.service_data, service_data, - sizeof(BACNET_CONFIRMED_SERVICE_ACK_DATA)); + sizeof(BACNET_CONFIRMED_SERVICE_ACK_DATA)); Read_Property_Multiple_Data.rpm_data = rp_data; Read_Property_Multiple_Data.new_data = true; - } - else - { - if ( len < 0 ) /* Eg, failed due to no segmentation */ - Error_Detected = true; - free( rp_data ); + } else { + if (len < 0) /* Eg, failed due to no segmentation */ + Error_Detected = true; + free(rp_data); } } @@ -221,22 +221,20 @@ void MyReadPropertyMultipleAckHandler( if (rpm_data) { len = rpm_ack_decode_service_request(service_request, service_len, - rpm_data); + rpm_data); } if (len > 0) { memmove(&Read_Property_Multiple_Data.service_data, service_data, - sizeof(BACNET_CONFIRMED_SERVICE_ACK_DATA)); + sizeof(BACNET_CONFIRMED_SERVICE_ACK_DATA)); Read_Property_Multiple_Data.rpm_data = rpm_data; Read_Property_Multiple_Data.new_data = true; /* Will process and free the RPM data later */ + } else { + if (len < 0) /* Eg, failed due to no segmentation */ + Error_Detected = true; + free(rpm_data); } - else - { - if ( len < 0 ) /* Eg, failed due to no segmentation */ - Error_Detected = true; - free( rpm_data ); - } - } +} static void Init_Service_Handlers( void) @@ -253,12 +251,12 @@ static void Init_Service_Handlers( (handler_unrecognized_service); /* we must implement read property - it's required! */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, - handler_read_property); + handler_read_property); /* handle the data coming back from confirmed requests */ apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY, - MyReadPropertyAckHandler); + MyReadPropertyAckHandler); apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, - MyReadPropertyMultipleAckHandler); + MyReadPropertyMultipleAckHandler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); @@ -278,8 +276,8 @@ static void Init_Service_Handlers( * @param property [in] Which property we are printing. * @return True if success. Or otherwise. */ - - bool PrettyPrintPropertyValue( + +bool PrettyPrintPropertyValue( FILE * stream, BACNET_APPLICATION_DATA_VALUE * value, BACNET_PROPERTY_ID property) @@ -287,67 +285,58 @@ static void Init_Service_Handlers( bool status = true; /*return value */ size_t len = 0, i = 0, j = 0; - if ( (value != NULL) && (value->tag == BACNET_APPLICATION_TAG_BIT_STRING) && - ( (property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) || - (property == PROP_PROTOCOL_SERVICES_SUPPORTED) ) ) - { + if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_BIT_STRING) && + ((property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) || + (property == PROP_PROTOCOL_SERVICES_SUPPORTED))) { len = bitstring_bits_used(&value->type.Bit_String); fprintf(stream, "( \r\n "); for (i = 0; i < len; i++) { - fprintf(stream, "%s", - bitstring_bit(&value->type.Bit_String, + fprintf(stream, "%s", bitstring_bit(&value->type.Bit_String, (uint8_t) i) ? "T" : "F"); if (i < len - 1) fprintf(stream, ","); else fprintf(stream, " "); /* Tried with 8 per line, but with the comments, got way too long. */ - if ( (i == (len-1) ) || ( (i % 4) == 3 ) ) /* line break every 4 */ - { - fprintf(stream, " -- "); /* EPICS comments begin with "--" */ + if ((i == (len - 1)) || ((i % 4) == 3)) { /* line break every 4 */ + fprintf(stream, " -- "); /* EPICS comments begin with "--" */ /* Now rerun the same 4 bits, but print labels for true ones */ - for ( j = i - (i%4); j <= i; j++) - { - if ( bitstring_bit(&value->type.Bit_String, (uint8_t) j) ) - { - if (property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) - fprintf( stream, " %s,", bactext_object_type_name(j) ); + for (j = i - (i % 4); j <= i; j++) { + if (bitstring_bit(&value->type.Bit_String, (uint8_t) j)) { + if (property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) + fprintf(stream, " %s,", + bactext_object_type_name(j)); /* PROP_PROTOCOL_SERVICES_SUPPORTED */ - else - { + else { bool bIsConfirmed; size_t newIndex; - if ( apdu_service_supported_to_index( j, - &newIndex, &bIsConfirmed ) ) - { - if ( bIsConfirmed ) - fprintf( stream, " %s,", - bactext_confirmed_service_name(newIndex) ); - - else - fprintf( stream, " %s,", - bactext_unconfirmed_service_name( - (newIndex) ) ); - + if (apdu_service_supported_to_index(j, &newIndex, + &bIsConfirmed)) { + if (bIsConfirmed) + fprintf(stream, " %s,", + bactext_confirmed_service_name + (newIndex)); + + else + fprintf(stream, " %s,", + bactext_unconfirmed_service_name( + (newIndex))); + } } - } - else /* not supported */ - fprintf( stream, "," ); + } else /* not supported */ + fprintf(stream, ","); } fprintf(stream, "\r\n "); - } - } + } + } fprintf(stream, ") \r\n"); - } - else if ( value != NULL ) - { - assert( false ); /* How did I get here? Fix your code. */ - /* Meanwhile, a fallback plan */ - status = bacapp_print_value(stdout, value, property); - } - else - fprintf(stream, "? \r\n"); + } else if (value != NULL) { + assert(false); /* How did I get here? Fix your code. */ + /* Meanwhile, a fallback plan */ + status = bacapp_print_value(stdout, value, property); + } else + fprintf(stream, "? \r\n"); return status; } @@ -362,200 +351,182 @@ static void Init_Service_Handlers( * Value, and Error information. */ void PrintReadPropertyData( - BACNET_PROPERTY_REFERENCE *rpm_property) + BACNET_PROPERTY_REFERENCE * rpm_property) { BACNET_APPLICATION_DATA_VALUE *value, *old_value; bool print_brace = false; KEY object_list_element; - bool isSequence = false; /* Ie, will need bracketing braces {} */ + bool isSequence = false; /* Ie, will need bracketing braces {} */ - if (rpm_property == NULL ) - { - fprintf( stdout, " -- Null Property data \r\n" ); - return; + if (rpm_property == NULL) { + fprintf(stdout, " -- Null Property data \r\n"); + return; } value = rpm_property->value; - if ( value == NULL ) - { - /* Then we print the error information */ + if (value == NULL) { + /* Then we print the error information */ fprintf(stdout, "? -- BACnet Error: %s: %s\r\n", bactext_error_class_name((int) rpm_property->error.error_class), bactext_error_code_name((int) rpm_property->error.error_code)); - return; + return; + } +#if 0 + if (data->array_index == BACNET_ARRAY_ALL) + fprintf(stderr, "%s #%u %s\n", + bactext_object_type_name(data->object_type), data->object_instance, + bactext_property_name(data->object_property)); + else + fprintf(stderr, "%s #%u %s[%d]\n", + bactext_object_type_name(data->object_type), data->object_instance, + bactext_property_name(data->object_property), data->array_index); +#endif + if ((value != NULL) && (value->next != NULL)) { + /* Then this is an array of values; open brace */ + fprintf(stdout, "{ "); + print_brace = true; /* remember to close it */ } -#if 0 - if (data->array_index == BACNET_ARRAY_ALL) - fprintf(stderr, "%s #%u %s\n", - bactext_object_type_name(data->object_type), - data->object_instance, - bactext_property_name(data->object_property)); - else - fprintf(stderr, "%s #%u %s[%d]\n", - bactext_object_type_name(data->object_type), - data->object_instance, - bactext_property_name(data->object_property), - data->array_index); -#endif - if( ( value != NULL ) && ( value->next != NULL ) ) - { - /* Then this is an array of values; open brace */ - fprintf(stdout, "{ "); - print_brace = true; /* remember to close it */ - } + if (!Using_Walked_List) + Walked_List_Index = Walked_List_Length = 0; /* In case we need this. */ + /* value(s) loop until there is no "next" ... */ + while (value != NULL) { + switch (rpm_property->propertyIdentifier) { + /* These are all arrays, so they open and close with braces */ + case PROP_OBJECT_LIST: + case PROP_STATE_TEXT: + case PROP_STRUCTURED_OBJECT_LIST: + case PROP_SUBORDINATE_ANNOTATIONS: + case PROP_SUBORDINATE_LIST: + if (Using_Walked_List) { + if ((rpm_property->propertyArrayIndex == 0) && + (value->tag == BACNET_APPLICATION_TAG_UNSIGNED_INT)) { + /* Grab the value of the Object List length - don't print it! */ + Walked_List_Length = value->type.Unsigned_Int; + if (rpm_property->propertyIdentifier == + PROP_OBJECT_LIST) + Object_List_Length = value->type.Unsigned_Int; + break; + } else + assert(Walked_List_Index == + rpm_property->propertyArrayIndex); + } else { + Walked_List_Index++; + /* If we got the whole Object List array in one RP call, keep + * the Index and List_Length in sync as we cycle through. */ + if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) + Object_List_Length = ++Object_List_Index; + } + if (Walked_List_Index == 1) { + /* Open this Array of Objects for the first entry (unless + * opening brace has already printed, since this is an array + * of values[] ) */ + if (value->next == NULL) + fprintf(stdout, "{ \r\n "); + else + fprintf(stdout, "\r\n "); + } - if ( !Using_Walked_List ) - Walked_List_Index = Walked_List_Length = 0; /* In case we need this. */ - /* value(s) loop until there is no "next" ... */ - while ( value != NULL ) - { - switch( rpm_property->propertyIdentifier ) - { - /* These are all arrays, so they open and close with braces */ - case PROP_OBJECT_LIST: - case PROP_STATE_TEXT: - case PROP_STRUCTURED_OBJECT_LIST: - case PROP_SUBORDINATE_ANNOTATIONS: - case PROP_SUBORDINATE_LIST: - if ( Using_Walked_List ) - { - if ( (rpm_property->propertyArrayIndex == 0) && - (value->tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) ) - { - /* Grab the value of the Object List length - don't print it! */ - Walked_List_Length = value->type.Unsigned_Int; - if ( rpm_property->propertyIdentifier == PROP_OBJECT_LIST) - Object_List_Length = value->type.Unsigned_Int; - break; - } - else - assert( Walked_List_Index == rpm_property->propertyArrayIndex); - } - else - { - Walked_List_Index++; - /* If we got the whole Object List array in one RP call, keep - * the Index and List_Length in sync as we cycle through. */ - if ( rpm_property->propertyIdentifier == PROP_OBJECT_LIST) - Object_List_Length = ++Object_List_Index; - } - if ( Walked_List_Index == 1 ) - { - /* Open this Array of Objects for the first entry (unless - * opening brace has already printed, since this is an array - * of values[] ) */ - if( value->next == NULL ) - fprintf(stdout, "{ \r\n "); - else - fprintf(stdout, "\r\n "); - } + if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) { + if (value->tag != BACNET_APPLICATION_TAG_OBJECT_ID) { + assert(false); /* Something not right here */ + break; + } + /* Store the object list so we can interrogate + each object. */ + object_list_element = + KEY_ENCODE(value->type.Object_Id.type, + value->type.Object_Id.instance); + /* We don't have anything to put in the data pointer + * yet, so just leave it null. The key is Key here. */ + Keylist_Data_Add(Object_List, object_list_element, NULL); + } else if (rpm_property->propertyIdentifier == PROP_STATE_TEXT) { + /* Make sure it fits within 31 chars for original VTS3 limitation. + * If longer, take first 15 dash, and last 15 chars. */ + if (value->type.Character_String.length > 31) { + int iLast15idx = + value->type.Character_String.length - 15; + value->type.Character_String.value[15] = '-'; + memcpy(&value->type.Character_String.value[16], + &value->type.Character_String.value[iLast15idx], + 15); + value->type.Character_String.value[31] = 0; + value->type.Character_String.length = 31; + } + } else if (rpm_property->propertyIdentifier == + PROP_SUBORDINATE_LIST) { + if (value->tag != BACNET_APPLICATION_TAG_OBJECT_ID) { + assert(false); /* Something not right here */ + break; + } + /* TODO: handle Sequence of { Device ObjID, Object ID }, */ + isSequence = true; + } - if ( rpm_property->propertyIdentifier == PROP_OBJECT_LIST) - { - if ( value->tag != BACNET_APPLICATION_TAG_OBJECT_ID ) { - assert( false ); /* Something not right here */ - break; - } - /* Store the object list so we can interrogate - each object. */ - object_list_element = - KEY_ENCODE(value->type.Object_Id.type, - value->type.Object_Id.instance); - /* We don't have anything to put in the data pointer - * yet, so just leave it null. The key is Key here. */ - Keylist_Data_Add( Object_List, object_list_element, NULL ); - } - else if ( rpm_property->propertyIdentifier == PROP_STATE_TEXT ) - { - /* Make sure it fits within 31 chars for original VTS3 limitation. - * If longer, take first 15 dash, and last 15 chars. */ - if ( value->type.Character_String.length > 31 ) - { - int iLast15idx = value->type.Character_String.length - 15; - value->type.Character_String.value[15] = '-'; - memcpy( &value->type.Character_String.value[16], - &value->type.Character_String.value[iLast15idx], 15 ); - value->type.Character_String.value[31] = 0; - value->type.Character_String.length = 31; - } - } - else if ( rpm_property->propertyIdentifier == PROP_SUBORDINATE_LIST) - { - if ( value->tag != BACNET_APPLICATION_TAG_OBJECT_ID ) { - assert( false ); /* Something not right here */ - break; - } - /* TODO: handle Sequence of { Device ObjID, Object ID }, */ - isSequence = true; - } + /* If the object is a Sequence, it needs its own bracketing braces */ + if (isSequence) + fprintf(stdout, "{"); + bacapp_print_value(stdout, value, + rpm_property->propertyIdentifier); + if (isSequence) + fprintf(stdout, "}"); - /* If the object is a Sequence, it needs its own bracketing braces */ - if ( isSequence ) - fprintf(stdout, "{"); - bacapp_print_value(stdout, value, rpm_property->propertyIdentifier ); - if ( isSequence ) - fprintf(stdout, "}"); + if ((Walked_List_Index < Walked_List_Length) || + (value->next != NULL)) { + /* There are more. */ + fprintf(stdout, ", "); + if (!(Walked_List_Index % 4)) + fprintf(stdout, "\r\n "); + } else { + fprintf(stdout, " } \r\n"); + } + break; - if ( ( Walked_List_Index < Walked_List_Length ) || - ( value->next != NULL ) ) - { - /* There are more. */ - fprintf(stdout, ", "); - if (!(Walked_List_Index % 4)) - fprintf(stdout, "\r\n "); - } else { - fprintf(stdout, " } \r\n"); - } - break; + case PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED: + case PROP_PROTOCOL_SERVICES_SUPPORTED: + PrettyPrintPropertyValue(stdout, value, + rpm_property->propertyIdentifier); + break; - case PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED: - case PROP_PROTOCOL_SERVICES_SUPPORTED: - PrettyPrintPropertyValue(stdout, value, rpm_property->propertyIdentifier); - break; + default: + /* Some properties are presented just as '?' in an EPICS; + * screen these out here, unless ShowValues is true. */ + switch (rpm_property->propertyIdentifier) { + case PROP_DEVICE_ADDRESS_BINDING: + case PROP_DAYLIGHT_SAVINGS_STATUS: + case PROP_LOCAL_DATE: + case PROP_LOCAL_TIME: + case PROP_PRESENT_VALUE: + case PROP_PRIORITY_ARRAY: + case PROP_RELIABILITY: + case PROP_UTC_OFFSET: + case PROP_DATABASE_REVISION: + if (!ShowValues) { + fprintf(stdout, "?"); + break; + } + /* Else, fall through and print value: */ + default: + bacapp_print_value(stdout, value, + rpm_property->propertyIdentifier); + break; + } + if (value->next != NULL) { + /* there's more! */ + fprintf(stdout, ","); + } else { + if (print_brace) { + /* Closing brace for this multi-valued array */ + fprintf(stdout, " }"); + } + fprintf(stdout, "\r\n"); + } + break; + } - default: - /* Some properties are presented just as '?' in an EPICS; - * screen these out here, unless ShowValues is true. */ - switch( rpm_property->propertyIdentifier ) - { - case PROP_DEVICE_ADDRESS_BINDING: - case PROP_DAYLIGHT_SAVINGS_STATUS: - case PROP_LOCAL_DATE: - case PROP_LOCAL_TIME: - case PROP_PRESENT_VALUE: - case PROP_PRIORITY_ARRAY: - case PROP_RELIABILITY: - case PROP_UTC_OFFSET: - case PROP_DATABASE_REVISION: - if ( !ShowValues ) - { - fprintf(stdout, "?"); - break; - } - /* Else, fall through and print value: */ - default: - bacapp_print_value(stdout, value, rpm_property->propertyIdentifier); - break; - } - if ( value->next != NULL ) { - /* there's more! */ - fprintf(stdout, ","); - } - else - { - if (print_brace) { - /* Closing brace for this multi-valued array */ - fprintf(stdout, " }"); - } - fprintf(stdout, "\r\n"); - } - break; - } - - old_value = value; - value = value->next; /* next or NULL */ - free( old_value ); - } /* End while loop */ + old_value = value; + value = value->next; /* next or NULL */ + free(old_value); + } /* End while loop */ } @@ -571,66 +542,57 @@ void PrintReadPropertyData( */ static uint8_t Read_Properties( uint32_t device_instance, - BACNET_OBJECT_ID *pMyObject ) + BACNET_OBJECT_ID * pMyObject) { uint8_t invoke_id = 0; struct special_property_list_t PropertyListStruct; - if ( Property_List_Length == 0 ) - { - /* If we failed to get the Properties with RPM, just settle for what we - * know is the fixed list of Required (only) properties. - * In practice, this should only happen for simple devices that don't - * implement RPM or have really limited MAX_APDU size. - */ - Device_Objects_Property_List( pMyObject->type, &PropertyListStruct); - pPropList = PropertyListStruct.Required.pList; - if ( pPropList != NULL ) - { - Property_List_Length = PropertyListStruct.Required.count; - } - else - { - fprintf( stdout, " -- No Properties available for %s \r\n", - bactext_object_type_name( pMyObject->type ) ); - } - } - else - pPropList = Property_List; + if (Property_List_Length == 0) { + /* If we failed to get the Properties with RPM, just settle for what we + * know is the fixed list of Required (only) properties. + * In practice, this should only happen for simple devices that don't + * implement RPM or have really limited MAX_APDU size. + */ + Device_Objects_Property_List(pMyObject->type, &PropertyListStruct); + pPropList = PropertyListStruct.Required.pList; + if (pPropList != NULL) { + Property_List_Length = PropertyListStruct.Required.count; + } else { + fprintf(stdout, " -- No Properties available for %s \r\n", + bactext_object_type_name(pMyObject->type)); + } + } else + pPropList = Property_List; - if ( (pPropList != NULL ) && ( pPropList[Property_List_Index] != -1) ) - { - int prop = pPropList[Property_List_Index]; - int32_t array_index; - IsLongArray = false; - if ( Using_Walked_List ) - { + if ((pPropList != NULL) && (pPropList[Property_List_Index] != -1)) { + int prop = pPropList[Property_List_Index]; + int32_t array_index; + IsLongArray = false; + if (Using_Walked_List) { if (Walked_List_Length == 0) { /* printf(" %s: ", bactext_property_name( prop ) ); */ array_index = 0; } else { - array_index = Walked_List_Index; + array_index = Walked_List_Index; } } else { - printf(" %s: ", bactext_property_name( prop ) ); + printf(" %s: ", bactext_property_name(prop)); array_index = BACNET_ARRAY_ALL; - switch( prop ) - { - /* These are all potentially long arrays, so they may abort */ - case PROP_OBJECT_LIST: - case PROP_STATE_TEXT: - case PROP_STRUCTURED_OBJECT_LIST: - case PROP_SUBORDINATE_ANNOTATIONS: - case PROP_SUBORDINATE_LIST: - IsLongArray = true; - break; - } + switch (prop) { + /* These are all potentially long arrays, so they may abort */ + case PROP_OBJECT_LIST: + case PROP_STATE_TEXT: + case PROP_STRUCTURED_OBJECT_LIST: + case PROP_SUBORDINATE_ANNOTATIONS: + case PROP_SUBORDINATE_LIST: + IsLongArray = true; + break; + } } invoke_id = - Send_Read_Property_Request(device_instance, - pMyObject->type, pMyObject->instance, - prop, array_index ); + Send_Read_Property_Request(device_instance, pMyObject->type, + pMyObject->instance, prop, array_index); } @@ -647,8 +609,8 @@ static uint8_t Read_Properties( * singly process the list of Properties. */ EPICS_STATES ProcessRPMData( - BACNET_READ_ACCESS_DATA * rpm_data, - EPICS_STATES myState ) + BACNET_READ_ACCESS_DATA * rpm_data, + EPICS_STATES myState) { BACNET_READ_ACCESS_DATA *old_rpm_data; BACNET_PROPERTY_REFERENCE *rpm_property; @@ -656,47 +618,42 @@ EPICS_STATES ProcessRPMData( BACNET_APPLICATION_DATA_VALUE *value; BACNET_APPLICATION_DATA_VALUE *old_value; bool bSuccess = true; - EPICS_STATES nextState = myState; /* assume no change */ + EPICS_STATES nextState = myState; /* assume no change */ /* Some flags to keep the output "pretty" - * wait and put these object lists at the end */ bool bHasObjectList = false; bool bHasStructuredViewList = false; - while (rpm_data) - { + while (rpm_data) { rpm_property = rpm_data->listOfProperties; while (rpm_property) { /* For the GET_LIST_OF_ALL_RESPONSE case, * just keep what property this was */ - if ( myState == GET_LIST_OF_ALL_RESPONSE ) - { - switch ( rpm_property->propertyIdentifier ) - { - case PROP_OBJECT_LIST: - bHasObjectList = true; /* Will append below */ - break; - case PROP_STRUCTURED_OBJECT_LIST: - bHasStructuredViewList = true; - break; - default: - Property_List[ Property_List_Index++ ] = - rpm_property->propertyIdentifier; - Property_List_Length++; - break; - } - /* Free up the value(s) */ + if (myState == GET_LIST_OF_ALL_RESPONSE) { + switch (rpm_property->propertyIdentifier) { + case PROP_OBJECT_LIST: + bHasObjectList = true; /* Will append below */ + break; + case PROP_STRUCTURED_OBJECT_LIST: + bHasStructuredViewList = true; + break; + default: + Property_List[Property_List_Index++] = + rpm_property->propertyIdentifier; + Property_List_Length++; + break; + } + /* Free up the value(s) */ value = rpm_property->value; while (value) { old_value = value; value = value->next; free(old_value); } - } - else - { - printf(" %s: ", bactext_property_name( - rpm_property->propertyIdentifier) ); - PrintReadPropertyData( rpm_property ); + } else { + printf(" %s: ", + bactext_property_name(rpm_property->propertyIdentifier)); + PrintReadPropertyData(rpm_property); } old_rpm_property = rpm_property; rpm_property = rpm_property->next; @@ -708,82 +665,80 @@ EPICS_STATES ProcessRPMData( } /* Now determine the next state */ - if ( bSuccess && ( myState == GET_ALL_RESPONSE) ) - nextState = NEXT_OBJECT; - else if ( bSuccess ) /* and GET_LIST_OF_ALL_RESPONSE */ - { - /* Now append the properties we waited on. */ - if ( bHasStructuredViewList ) { - Property_List[ Property_List_Index++ ] = PROP_STRUCTURED_OBJECT_LIST; - Property_List_Length++; - } - if ( bHasObjectList ) { - Property_List[ Property_List_Index++ ] = PROP_OBJECT_LIST; - Property_List_Length++; - } - /* Now insert the -1 list terminator, but don't count it. */ - Property_List[ Property_List_Index ] = -1; - assert ( Property_List_Length < MAX_PROPS ); - Property_List_Index = 0; /* Will start at top of the list */ - nextState = GET_PROPERTY_REQUEST; + if (bSuccess && (myState == GET_ALL_RESPONSE)) + nextState = NEXT_OBJECT; + else if (bSuccess) { /* and GET_LIST_OF_ALL_RESPONSE */ + /* Now append the properties we waited on. */ + if (bHasStructuredViewList) { + Property_List[Property_List_Index++] = PROP_STRUCTURED_OBJECT_LIST; + Property_List_Length++; + } + if (bHasObjectList) { + Property_List[Property_List_Index++] = PROP_OBJECT_LIST; + Property_List_Length++; + } + /* Now insert the -1 list terminator, but don't count it. */ + Property_List[Property_List_Index] = -1; + assert(Property_List_Length < MAX_PROPS); + Property_List_Index = 0; /* Will start at top of the list */ + nextState = GET_PROPERTY_REQUEST; } return nextState; } -void PrintUsage() +void PrintUsage( + ) { - printf("bacepics -- Generates Object and Property List for EPICS \r\n" ); - printf("Usage: \r\n" ); - printf(" bacepics [-v] device-instance \r\n" ); - printf(" Use the -v option to show values instead of '?' \r\n\r\n" ); + printf("bacepics -- Generates Object and Property List for EPICS \r\n"); + printf("Usage: \r\n"); + printf(" bacepics [-v] device-instance \r\n"); + printf(" Use the -v option to show values instead of '?' \r\n\r\n"); printf("Insert the output in your EPICS file as the last section: \r\n"); printf("\"List of Objects in test device:\" \r\n"); printf("before the final statement: \r\n"); - printf("\"End of BACnet Protocol Implementation Conformance Statement\" \r\n"); + printf + ("\"End of BACnet Protocol Implementation Conformance Statement\" \r\n"); exit(0); } int CheckCommandLineArgs( - int argc, - char *argv[] ) + int argc, + char *argv[]) { - int i; - bool bFoundTarget = false; + int i; + bool bFoundTarget = false; /* FIXME: handle multi homed systems - use an argument passed to the datalink_init() */ /* print help if not enough arguments */ if (argc < 2) { - fprintf(stderr, "Must provide a device-instance \r\n\r\n" ); - PrintUsage(); /* Will exit */ + fprintf(stderr, "Must provide a device-instance \r\n\r\n"); + PrintUsage(); /* Will exit */ } - for ( i = 1; i < argc; i++ ) - { - char *anArg = argv[i]; - if ( anArg[0] == '-' ) - { - if ( anArg[1] == 'v' ) - ShowValues = true; - else - PrintUsage(); - } - else - { - /* decode the Target Device Instance parameter */ - Target_Device_Object_Instance = strtol( anArg, NULL, 0); - if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) { - fprintf(stderr, "device-instance=%u - it must be less than %u\r\n", - Target_Device_Object_Instance, BACNET_MAX_INSTANCE + 1); - PrintUsage(); - } - bFoundTarget = true; - } + for (i = 1; i < argc; i++) { + char *anArg = argv[i]; + if (anArg[0] == '-') { + if (anArg[1] == 'v') + ShowValues = true; + else + PrintUsage(); + } else { + /* decode the Target Device Instance parameter */ + Target_Device_Object_Instance = strtol(anArg, NULL, 0); + if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) { + fprintf(stderr, + "device-instance=%u - it must be less than %u\r\n", + Target_Device_Object_Instance, BACNET_MAX_INSTANCE + 1); + PrintUsage(); + } + bFoundTarget = true; + } } - if ( !bFoundTarget ) { - fprintf(stderr, "Must provide a device-instance \r\n\r\n" ); - PrintUsage(); /* Will exit */ + if (!bFoundTarget) { + fprintf(stderr, "Must provide a device-instance \r\n\r\n"); + PrintUsage(); /* Will exit */ } - return 0; /* All OK if we reach here */ + return 0; /* All OK if we reach here */ } /** Main function of the bacepics program. @@ -821,7 +776,7 @@ int main( BACNET_PROPERTY_REFERENCE *rpm_property; KEY nextKey; - CheckCommandLineArgs( argc, argv ); /* Won't return if there is an issue. */ + CheckCommandLineArgs(argc, argv); /* Won't return if there is an issue. */ /* setup my info */ Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); @@ -843,7 +798,7 @@ int main( printf("List of Objects in test device:\r\n"); /* Print Opening brace, then kick off the Device Object */ printf("{ \r\n"); - printf(" { \r\n"); /* And opening brace for the first object */ + printf(" { \r\n"); /* And opening brace for the first object */ myObject.type = OBJECT_DEVICE; myObject.instance = Target_Device_Object_Instance; myState = INITIAL_BINDING; @@ -857,159 +812,156 @@ int main( } /* OK to proceed; see what we are up to now */ - switch ( myState ) - { - case INITIAL_BINDING: - /* returns 0 bytes on timeout */ - pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); + switch (myState) { + case INITIAL_BINDING: + /* returns 0 bytes on timeout */ + pdu_len = + datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); - /* process; normally is some initial error */ - if (pdu_len) { - npdu_handler(&src, &Rx_Buf[0], pdu_len); - } - /* will wait until the device is bound, or timeout and quit */ - found = address_bind_request(Target_Device_Object_Instance, - &max_apdu, &Target_Address); - if ( !found ) - { - /* increment timer - exit if timed out */ - elapsed_seconds += (current_seconds - last_seconds); - if (elapsed_seconds > timeout_seconds) { - printf("\rError: APDU Timeout!\r\n"); - break; + /* process; normally is some initial error */ + if (pdu_len) { + npdu_handler(&src, &Rx_Buf[0], pdu_len); } - /* else, loop back and try again */ - continue; - } - else - myState = GET_ALL_REQUEST; - break; - - case GET_ALL_REQUEST: - case GET_LIST_OF_ALL_REQUEST: /* differs in ArrayIndex only */ - Error_Detected = false; - Property_List_Index = Property_List_Length = 0; - /* Update times; aids single-step debugging */ - last_seconds = current_seconds; - rpm_object = calloc(1, sizeof(BACNET_READ_ACCESS_DATA)); - assert( rpm_object ); - rpm_object->object_type = myObject.type; - rpm_object->object_instance = myObject.instance; - rpm_property = calloc(1, sizeof(BACNET_PROPERTY_REFERENCE)); - rpm_object->listOfProperties = rpm_property; - assert( rpm_property ); - rpm_property->propertyIdentifier = PROP_ALL; - if ( myState == GET_LIST_OF_ALL_REQUEST ) - rpm_property->propertyArrayIndex = 0; /* Get count of arrays */ - else - rpm_property->propertyArrayIndex = -1; /* optional: None */ - invoke_id = - Send_Read_Property_Multiple_Request( buffer, MAX_PDU, - Target_Device_Object_Instance, rpm_object ); - if ( invoke_id > 0 ) - { - if ( myState == GET_LIST_OF_ALL_REQUEST ) - myState = GET_LIST_OF_ALL_RESPONSE; - else - myState = GET_ALL_RESPONSE; - } - break; - - case GET_ALL_RESPONSE: - case GET_LIST_OF_ALL_RESPONSE: - /* returns 0 bytes on timeout */ - pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); - - /* process */ - if (pdu_len) { - npdu_handler(&src, &Rx_Buf[0], pdu_len); - } - - if ((Read_Property_Multiple_Data.new_data) && - (invoke_id == Read_Property_Multiple_Data.service_data.invoke_id)) { - Read_Property_Multiple_Data.new_data = false; - myState = ProcessRPMData( Read_Property_Multiple_Data.rpm_data, - myState ); - if (tsm_invoke_id_free(invoke_id)) { - invoke_id = 0; - } - else { - assert( false ); /* How can this be? */ - invoke_id = 0; - } - } else if (tsm_invoke_id_free(invoke_id)) { - invoke_id = 0; - if (Error_Detected) /* The normal case for Device Object */ - { - /* Try again, just to get a list of properties. */ - if ( myState == GET_ALL_RESPONSE ) - myState = GET_LIST_OF_ALL_REQUEST; - /* Else it may be that RPM is not implemented. */ - else - myState = GET_PROPERTY_REQUEST; - } - else - myState = GET_ALL_REQUEST; /* Let's try again */ - } else if (tsm_invoke_id_failed(invoke_id)) { - fprintf(stderr, "\rError: TSM Timeout!\r\n"); - tsm_free_invoke_id(invoke_id); - invoke_id = 0; - myState = GET_ALL_REQUEST; /* Let's try again */ - } else if (Error_Detected) { - /* Don't think we'll ever actually reach this point. */ - invoke_id = 0; - myState = NEXT_OBJECT; /* Give up and move on to the next.*/ - } - break; - - /* Process the next single property in our list, - * if we couldn't GET_ALL at once above. */ - case GET_PROPERTY_REQUEST: - Error_Detected = false; - /* Update times; aids single-step debugging */ - last_seconds = current_seconds; - invoke_id = Read_Properties(Target_Device_Object_Instance, &myObject ); - if (invoke_id == 0) { - /* Reached the end of the list. */ - myState = NEXT_OBJECT; /* Move on to the next.*/ - } - else - myState = GET_PROPERTY_RESPONSE; - break; - - case GET_PROPERTY_RESPONSE: - /* returns 0 bytes on timeout */ - pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); - - /* process */ - if (pdu_len) { - npdu_handler(&src, &Rx_Buf[0], pdu_len); - } - - if ( (Read_Property_Multiple_Data.new_data) && - (invoke_id == Read_Property_Multiple_Data.service_data.invoke_id)) - { - Read_Property_Multiple_Data.new_data = false; - PrintReadPropertyData( Read_Property_Multiple_Data.rpm_data->listOfProperties ); - if (tsm_invoke_id_free(invoke_id)) { - invoke_id = 0; - } - else { - assert( false ); /* How can this be? */ - invoke_id = 0; - } - /* Advance the property (or Array List) index */ - if ( Using_Walked_List ) - { - Walked_List_Index++; - if (Walked_List_Index > Walked_List_Length) { - /* go on to next property */ - Property_List_Index++; - Using_Walked_List = false; + /* will wait until the device is bound, or timeout and quit */ + found = + address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); + if (!found) { + /* increment timer - exit if timed out */ + elapsed_seconds += (current_seconds - last_seconds); + if (elapsed_seconds > timeout_seconds) { + printf("\rError: APDU Timeout!\r\n"); + break; } - } - else - Property_List_Index++; + /* else, loop back and try again */ + continue; + } else + myState = GET_ALL_REQUEST; + break; + + case GET_ALL_REQUEST: + case GET_LIST_OF_ALL_REQUEST: /* differs in ArrayIndex only */ + Error_Detected = false; + Property_List_Index = Property_List_Length = 0; + /* Update times; aids single-step debugging */ + last_seconds = current_seconds; + rpm_object = calloc(1, sizeof(BACNET_READ_ACCESS_DATA)); + assert(rpm_object); + rpm_object->object_type = myObject.type; + rpm_object->object_instance = myObject.instance; + rpm_property = calloc(1, sizeof(BACNET_PROPERTY_REFERENCE)); + rpm_object->listOfProperties = rpm_property; + assert(rpm_property); + rpm_property->propertyIdentifier = PROP_ALL; + if (myState == GET_LIST_OF_ALL_REQUEST) + rpm_property->propertyArrayIndex = 0; /* Get count of arrays */ + else + rpm_property->propertyArrayIndex = -1; /* optional: None */ + invoke_id = + Send_Read_Property_Multiple_Request(buffer, MAX_PDU, + Target_Device_Object_Instance, rpm_object); + if (invoke_id > 0) { + if (myState == GET_LIST_OF_ALL_REQUEST) + myState = GET_LIST_OF_ALL_RESPONSE; + else + myState = GET_ALL_RESPONSE; + } + break; + + case GET_ALL_RESPONSE: + case GET_LIST_OF_ALL_RESPONSE: + /* returns 0 bytes on timeout */ + pdu_len = + datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); + + /* process */ + if (pdu_len) { + npdu_handler(&src, &Rx_Buf[0], pdu_len); + } + + if ((Read_Property_Multiple_Data.new_data) && + (invoke_id == + Read_Property_Multiple_Data.service_data.invoke_id)) { + Read_Property_Multiple_Data.new_data = false; + myState = + ProcessRPMData(Read_Property_Multiple_Data.rpm_data, + myState); + if (tsm_invoke_id_free(invoke_id)) { + invoke_id = 0; + } else { + assert(false); /* How can this be? */ + invoke_id = 0; + } + } else if (tsm_invoke_id_free(invoke_id)) { + invoke_id = 0; + if (Error_Detected) { /* The normal case for Device Object */ + /* Try again, just to get a list of properties. */ + if (myState == GET_ALL_RESPONSE) + myState = GET_LIST_OF_ALL_REQUEST; + /* Else it may be that RPM is not implemented. */ + else + myState = GET_PROPERTY_REQUEST; + } else + myState = GET_ALL_REQUEST; /* Let's try again */ + } else if (tsm_invoke_id_failed(invoke_id)) { + fprintf(stderr, "\rError: TSM Timeout!\r\n"); + tsm_free_invoke_id(invoke_id); + invoke_id = 0; + myState = GET_ALL_REQUEST; /* Let's try again */ + } else if (Error_Detected) { + /* Don't think we'll ever actually reach this point. */ + invoke_id = 0; + myState = NEXT_OBJECT; /* Give up and move on to the next. */ + } + break; + + /* Process the next single property in our list, + * if we couldn't GET_ALL at once above. */ + case GET_PROPERTY_REQUEST: + Error_Detected = false; + /* Update times; aids single-step debugging */ + last_seconds = current_seconds; + invoke_id = + Read_Properties(Target_Device_Object_Instance, &myObject); + if (invoke_id == 0) { + /* Reached the end of the list. */ + myState = NEXT_OBJECT; /* Move on to the next. */ + } else + myState = GET_PROPERTY_RESPONSE; + break; + + case GET_PROPERTY_RESPONSE: + /* returns 0 bytes on timeout */ + pdu_len = + datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); + + /* process */ + if (pdu_len) { + npdu_handler(&src, &Rx_Buf[0], pdu_len); + } + + if ((Read_Property_Multiple_Data.new_data) && + (invoke_id == + Read_Property_Multiple_Data.service_data.invoke_id)) { + Read_Property_Multiple_Data.new_data = false; + PrintReadPropertyData(Read_Property_Multiple_Data. + rpm_data->listOfProperties); + if (tsm_invoke_id_free(invoke_id)) { + invoke_id = 0; + } else { + assert(false); /* How can this be? */ + invoke_id = 0; + } + /* Advance the property (or Array List) index */ + if (Using_Walked_List) { + Walked_List_Index++; + if (Walked_List_Index > Walked_List_Length) { + /* go on to next property */ + Property_List_Index++; + Using_Walked_List = false; + } + } else + Property_List_Index++; /* if ( pPropList[Property_List_Index] == PROP_OBJECT_LIST ) */ /* { */ /* if ( !Using_Walked_List ) /* Just switched */ */ @@ -1018,82 +970,76 @@ int main( /* Walked_List_Index = Walked_List_Length = 0; */ /* } */ /* } */ - myState = GET_PROPERTY_REQUEST; /* Go fetch next Property */ - } - else if (tsm_invoke_id_free(invoke_id)) { - invoke_id = 0; - if (Error_Detected) - { - if ( IsLongArray ) { - /* Change to using a Walked List and retry this property */ - Using_Walked_List = true; - Walked_List_Index = Walked_List_Length = 0; - } - else { - /* OK, skip this one and try the next property. */ - fprintf( stdout, " -- Failed to get %s \r\n", - bactext_property_name(pPropList[Property_List_Index]) ); - Property_List_Index++; - } - } - myState = GET_PROPERTY_REQUEST; - } else if (tsm_invoke_id_failed(invoke_id)) { - fprintf(stderr, "\rError: TSM Timeout!\r\n"); - tsm_free_invoke_id(invoke_id); - invoke_id = 0; - myState = GET_PROPERTY_REQUEST; /* Let's try again, same Property */ - } else if (Error_Detected) { - /* Don't think we'll ever actually reach this point. */ - invoke_id = 0; - myState = NEXT_OBJECT; /* Give up and move on to the next.*/ - } - break; + myState = GET_PROPERTY_REQUEST; /* Go fetch next Property */ + } else if (tsm_invoke_id_free(invoke_id)) { + invoke_id = 0; + if (Error_Detected) { + if (IsLongArray) { + /* Change to using a Walked List and retry this property */ + Using_Walked_List = true; + Walked_List_Index = Walked_List_Length = 0; + } else { + /* OK, skip this one and try the next property. */ + fprintf(stdout, " -- Failed to get %s \r\n", + bactext_property_name(pPropList + [Property_List_Index])); + Property_List_Index++; + } + } + myState = GET_PROPERTY_REQUEST; + } else if (tsm_invoke_id_failed(invoke_id)) { + fprintf(stderr, "\rError: TSM Timeout!\r\n"); + tsm_free_invoke_id(invoke_id); + invoke_id = 0; + myState = GET_PROPERTY_REQUEST; /* Let's try again, same Property */ + } else if (Error_Detected) { + /* Don't think we'll ever actually reach this point. */ + invoke_id = 0; + myState = NEXT_OBJECT; /* Give up and move on to the next. */ + } + break; - case NEXT_OBJECT: - if ( myObject.type == OBJECT_DEVICE ) - { - printf(" -- Found %d Objects \r\n", Keylist_Count( Object_List ) ); - Object_List_Index = -1; /* start over (will be incr to 0) */ - } - /* Advance to the next object, as long as it's not the Device object */ - do - { - Object_List_Index++; - nextKey = Keylist_Key( Object_List, Object_List_Index ); - /* If done with all Objects, signal end of this while loop */ - if ( ( nextKey == 0 ) || ( Object_List_Index >= Object_List_Length ) ) - { - /* Closing brace for the last Object */ - printf(" } \r\n"); - myObject.type = MAX_BACNET_OBJECT_TYPE; - } - else - { - /* Closing brace for the previous Object */ - printf(" }, \r\n"); - myObject.type = KEY_DECODE_TYPE( nextKey ); - myObject.instance = KEY_DECODE_ID( nextKey ); - /* Opening brace for the new Object */ - printf(" { \r\n"); - /* Test code: - if ( myObject.type == OBJECT_STRUCTURED_VIEW ) - printf( " -- Structured View %d \n", myObject.instance ); - */ - } - myState = GET_ALL_REQUEST; + case NEXT_OBJECT: + if (myObject.type == OBJECT_DEVICE) { + printf(" -- Found %d Objects \r\n", + Keylist_Count(Object_List)); + Object_List_Index = -1; /* start over (will be incr to 0) */ + } + /* Advance to the next object, as long as it's not the Device object */ + do { + Object_List_Index++; + nextKey = Keylist_Key(Object_List, Object_List_Index); + /* If done with all Objects, signal end of this while loop */ + if ((nextKey == 0) || + (Object_List_Index >= Object_List_Length)) { + /* Closing brace for the last Object */ + printf(" } \r\n"); + myObject.type = MAX_BACNET_OBJECT_TYPE; + } else { + /* Closing brace for the previous Object */ + printf(" }, \r\n"); + myObject.type = KEY_DECODE_TYPE(nextKey); + myObject.instance = KEY_DECODE_ID(nextKey); + /* Opening brace for the new Object */ + printf(" { \r\n"); + /* Test code: + if ( myObject.type == OBJECT_STRUCTURED_VIEW ) + printf( " -- Structured View %d \n", myObject.instance ); + */ + } + myState = GET_ALL_REQUEST; - } while ( myObject.type == OBJECT_DEVICE ); - /* Else, don't re-do the Device Object; move to the next object. */ - break; + } while (myObject.type == OBJECT_DEVICE); + /* Else, don't re-do the Device Object; move to the next object. */ + break; - default: - assert( false ); /* program error; fix this */ - break; - } + default: + assert(false); /* program error; fix this */ + break; + } - /* Check for timeouts */ - if ( !found || ( invoke_id > 0 ) ) - { + /* Check for timeouts */ + if (!found || (invoke_id > 0)) { /* increment timer - exit if timed out */ elapsed_seconds += (current_seconds - last_seconds); if (elapsed_seconds > timeout_seconds) { @@ -1102,7 +1048,7 @@ int main( } } - } while ( myObject.type < MAX_BACNET_OBJECT_TYPE ); + } while (myObject.type < MAX_BACNET_OBJECT_TYPE); /* Closing brace for all Objects */ printf("} \r\n"); @@ -1110,5 +1056,4 @@ int main( return 0; } -/*@}*/ /* End group BACEPICS */ - + /*@}*//* End group BACEPICS */ diff --git a/bacnet-stack/demo/handler/dlenv.c b/bacnet-stack/demo/handler/dlenv.c index 9967cabc..c4cfe6ce 100644 --- a/bacnet-stack/demo/handler/dlenv.c +++ b/bacnet-stack/demo/handler/dlenv.c @@ -132,11 +132,10 @@ void dlenv_init( if (!datalink_init(getenv("BACNET_IFACE"))) { exit(1); } - pEnv = getenv("BACNET_INVOKE_ID"); - if (pEnv) { - tsm_invokeID_set((uint8_t)strtol(pEnv, NULL, 0)); - } - + pEnv = getenv("BACNET_INVOKE_ID"); + if (pEnv) { + tsm_invokeID_set((uint8_t) strtol(pEnv, NULL, 0)); + } #if defined(BACDL_BIP) && BBMD_ENABLED pEnv = getenv("BACNET_BBMD_PORT"); if (pEnv) { diff --git a/bacnet-stack/demo/handler/h_alarm_ack.c b/bacnet-stack/demo/handler/h_alarm_ack.c index 94a04a5a..17846296 100644 --- a/bacnet-stack/demo/handler/h_alarm_ack.c +++ b/bacnet-stack/demo/handler/h_alarm_ack.c @@ -109,8 +109,9 @@ void handler_alarm_ack( #if PRINT_ENABLED fprintf(stderr, "Alarm Ack Operation: Received acknowledge for object id %lu from %s for process id %lu for object %lu\n", - (unsigned long)data.eventObjectIdentifier.instance, data.ackSource.value, - (unsigned long)data.ackProcessIdentifier, (unsigned long)data.eventObjectIdentifier.instance); + (unsigned long) data.eventObjectIdentifier.instance, + data.ackSource.value, (unsigned long) data.ackProcessIdentifier, + (unsigned long) data.eventObjectIdentifier.instance); #endif len = diff --git a/bacnet-stack/demo/handler/h_arf_a.c b/bacnet-stack/demo/handler/h_arf_a.c index 554f3bdd..026c684f 100644 --- a/bacnet-stack/demo/handler/h_arf_a.c +++ b/bacnet-stack/demo/handler/h_arf_a.c @@ -82,7 +82,7 @@ void handler_atomic_read_file_ack( pFile) != 1) { #if PRINT_ENABLED fprintf(stderr, "Failed to write to %s (%lu)!\n", - pFilename, (unsigned long)instance); + pFilename, (unsigned long) instance); #endif } fclose(pFile); diff --git a/bacnet-stack/demo/handler/h_cov.c b/bacnet-stack/demo/handler/h_cov.c index 5d8f05c4..826ef145 100644 --- a/bacnet-stack/demo/handler/h_cov.c +++ b/bacnet-stack/demo/handler/h_cov.c @@ -344,9 +344,8 @@ static bool cov_send_request( value_list[1].next = NULL; switch (cov_subscription->monitoredObjectIdentifier.type) { case OBJECT_BINARY_INPUT: - Binary_Input_Encode_Value_List - (cov_subscription->monitoredObjectIdentifier.instance, - &value_list[0]); + Binary_Input_Encode_Value_List(cov_subscription-> + monitoredObjectIdentifier.instance, &value_list[0]); break; default: goto COV_FAILED; @@ -422,7 +421,7 @@ void handler_cov_task( COV_Subscriptions[index].lifetime -= elapsed_seconds; #if 0 fprintf(stderr, "COVtask: subscription[%d].lifetime=%lu\n", - index, (unsigned long)COV_Subscriptions[index].lifetime); + index, (unsigned long) COV_Subscriptions[index].lifetime); #endif } else { COV_Subscriptions[index].lifetime = 0; @@ -463,8 +462,8 @@ static bool cov_subscribe( switch (cov_data->monitoredObjectIdentifier.type) { case OBJECT_BINARY_INPUT: - if (Binary_Input_Valid_Instance - (cov_data->monitoredObjectIdentifier.instance)) { + if (Binary_Input_Valid_Instance(cov_data-> + monitoredObjectIdentifier.instance)) { status = cov_list_subscribe(src, cov_data, error_class, error_code); } else { diff --git a/bacnet-stack/demo/handler/h_iam.c b/bacnet-stack/demo/handler/h_iam.c index 52f886a0..f60b7927 100644 --- a/bacnet-stack/demo/handler/h_iam.c +++ b/bacnet-stack/demo/handler/h_iam.c @@ -61,9 +61,9 @@ void handler_i_am_add( #endif if (len != -1) { #if PRINT_ENABLED - fprintf(stderr, " from %lu, MAC = %d.%d.%d.%d.%d.%d\n", (unsigned long)device_id, - src->mac[0], src->mac[1], src->mac[2], src->mac[3], src->mac[4], - src->mac[5]); + fprintf(stderr, " from %lu, MAC = %d.%d.%d.%d.%d.%d\n", + (unsigned long) device_id, src->mac[0], src->mac[1], src->mac[2], + src->mac[3], src->mac[4], src->mac[5]); #endif address_add(device_id, max_apdu, src); } else { diff --git a/bacnet-stack/demo/handler/h_ihave.c b/bacnet-stack/demo/handler/h_ihave.c index 27b099d7..ebd1ee61 100644 --- a/bacnet-stack/demo/handler/h_ihave.c +++ b/bacnet-stack/demo/handler/h_ihave.c @@ -55,9 +55,9 @@ void handler_i_have( #if PRINT_ENABLED fprintf(stderr, "I-Have: %s %lu from %s %lu!\r\n", bactext_object_type_name(data.object_id.type), - (unsigned long)data.object_id.instance, + (unsigned long) data.object_id.instance, bactext_object_type_name(data.device_id.type), - (unsigned long)data.device_id.instance); + (unsigned long) data.device_id.instance); #endif } else { #if PRINT_ENABLED diff --git a/bacnet-stack/demo/handler/h_lso.c b/bacnet-stack/demo/handler/h_lso.c index 1b404eec..276c5f86 100644 --- a/bacnet-stack/demo/handler/h_lso.c +++ b/bacnet-stack/demo/handler/h_lso.c @@ -92,7 +92,8 @@ void handler_lso( #if PRINT_ENABLED fprintf(stderr, "Life Safety Operation: Received operation %d from process id %lu for object %lu\n", - data.operation, (unsigned long)data.processId, (unsigned long)data.targetObject.instance); + data.operation, (unsigned long) data.processId, + (unsigned long) data.targetObject.instance); #endif len = diff --git a/bacnet-stack/demo/handler/h_npdu.c b/bacnet-stack/demo/handler/h_npdu.c index 8f82f120..9c6be5b0 100644 --- a/bacnet-stack/demo/handler/h_npdu.c +++ b/bacnet-stack/demo/handler/h_npdu.c @@ -64,14 +64,14 @@ void npdu_handler( (uint16_t) (pdu_len - apdu_offset)); } else { #if PRINT_ENABLED - printf("NPDU: DNET=%u. Discarded!\n", (unsigned)dest.net); + printf("NPDU: DNET=%u. Discarded!\n", (unsigned) dest.net); #endif } } } else { #if PRINT_ENABLED - printf("NPDU: BACnet Protocol Version=%u. Discarded!\n", - (unsigned)pdu[0]); + printf("NPDU: BACnet Protocol Version=%u. Discarded!\n", + (unsigned) pdu[0]); #endif } diff --git a/bacnet-stack/demo/handler/h_pt.c b/bacnet-stack/demo/handler/h_pt.c index b42076aa..667f9ef7 100644 --- a/bacnet-stack/demo/handler/h_pt.c +++ b/bacnet-stack/demo/handler/h_pt.c @@ -72,10 +72,10 @@ void ProcessPT( decode_tag_number_and_value(&data->serviceParameters[iLen], &tag_number, &len_value_type); iLen += tag_len; - if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { + if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { /* Bail out early if wrong type */ /* and signal unexpected error */ - data->serviceParametersLen = 0; + data->serviceParametersLen = 0; return; } @@ -86,44 +86,45 @@ void ProcessPT( if (cBlockNumber < MY_MAX_BLOCK) { if (data->serviceNumber == MY_SVC_READ) { /* Read Response is an unsigned int with - 0 for success or a non 0 error code - For a successful read the 0 success - code is followed by the block number - and then the block contents which - consist of 2 unsigned ints (in 0 to 255 - range as they are really chars) a single - precision real and a string which - will be up to 32 chars + a nul */ + 0 for success or a non 0 error code + For a successful read the 0 success + code is followed by the block number + and then the block contents which + consist of 2 unsigned ints (in 0 to 255 + range as they are really chars) a single + precision real and a string which + will be up to 32 chars + a nul */ iLen = 0; /* Signal success */ - iLen += encode_application_unsigned(&IOBufferPT[iLen], MY_ERR_OK); + iLen += encode_application_unsigned(&IOBufferPT[iLen], MY_ERR_OK); /* Followed by the block number */ - iLen += encode_application_unsigned(&IOBufferPT[iLen], - cBlockNumber); + iLen += + encode_application_unsigned(&IOBufferPT[iLen], cBlockNumber); /* And Then the block contents */ - iLen += encode_application_unsigned(&IOBufferPT[iLen], - MyData[(int8_t)cBlockNumber].cMyByte1); iLen += encode_application_unsigned(&IOBufferPT[iLen], - MyData[(int8_t)cBlockNumber].cMyByte2); + MyData[(int8_t) cBlockNumber].cMyByte1); + iLen += + encode_application_unsigned(&IOBufferPT[iLen], + MyData[(int8_t) cBlockNumber].cMyByte2); iLen += encode_application_real(&IOBufferPT[iLen], - MyData[(int8_t)cBlockNumber].fMyReal); - characterstring_init_ansi(&bsTemp, - (char *)MyData[(int8_t)cBlockNumber].sMyString); + MyData[(int8_t) cBlockNumber].fMyReal); + characterstring_init_ansi(&bsTemp, + (char *) MyData[(int8_t) cBlockNumber].sMyString); iLen += encode_application_character_string(&IOBufferPT[iLen], &bsTemp); - } else { + } else { /* Write operation */ /* Write block consists of the block number - followed by the block contents as - described above for the read operation. - The returned result is an unsigned - response which is 0 for success and - a non 0 error code otherwise. */ + followed by the block contents as + described above for the read operation. + The returned result is an unsigned + response which is 0 for success and + a non 0 error code otherwise. */ tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], @@ -136,7 +137,7 @@ void ProcessPT( iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, &ulTemp); - MyData[(int8_t)cBlockNumber].cMyByte1 = (char) ulTemp; + MyData[(int8_t) cBlockNumber].cMyByte1 = (char) ulTemp; tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], @@ -149,7 +150,7 @@ void ProcessPT( iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, &ulTemp); - MyData[(int8_t)cBlockNumber].cMyByte2 = (char) ulTemp; + MyData[(int8_t) cBlockNumber].cMyByte2 = (char) ulTemp; tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], @@ -161,7 +162,7 @@ void ProcessPT( } iLen += decode_real(&data->serviceParameters[iLen], - &MyData[(int8_t)cBlockNumber].fMyReal); + &MyData[(int8_t) cBlockNumber].fMyReal); tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], @@ -174,16 +175,16 @@ void ProcessPT( decode_character_string(&data->serviceParameters[iLen], len_value_type, &bsTemp); /* Only copy as much as we can accept */ - strncpy((char *)MyData[(int8_t)cBlockNumber].sMyString, - characterstring_value(&bsTemp), MY_MAX_STR); + strncpy((char *) MyData[(int8_t) cBlockNumber].sMyString, + characterstring_value(&bsTemp), MY_MAX_STR); /* Make sure it is nul terminated */ - MyData[(int8_t)cBlockNumber].sMyString[MY_MAX_STR] = '\0'; + MyData[(int8_t) cBlockNumber].sMyString[MY_MAX_STR] = '\0'; /* Signal success */ - iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_OK); + iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_OK); } } else { /* Signal bad index */ - iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_BAD_INDEX); + iLen = encode_application_unsigned(&IOBufferPT[0], MY_ERR_BAD_INDEX); } data->serviceParametersLen = iLen; data->serviceParameters = IOBufferPT; @@ -260,17 +261,17 @@ void handler_conf_private_trans( } /* Simple example with service number of 0 for - read block and 1 for write block - We also only support our own vendor ID. - In theory we could support others - for compatability purposes but these - interfaces are rarely documented... */ - if ((data.vendorID == BACNET_VENDOR_ID) && - (data.serviceNumber <= MY_SVC_WRITE)) { + read block and 1 for write block + We also only support our own vendor ID. + In theory we could support others + for compatability purposes but these + interfaces are rarely documented... */ + if ((data.vendorID == BACNET_VENDOR_ID) && + (data.serviceNumber <= MY_SVC_WRITE)) { /* We only try to understand our own IDs and service numbers */ /* Will either return a result block or an app level status block */ - ProcessPT(&data); - if (data.serviceParametersLen == 0) { + ProcessPT(&data); + if (data.serviceParametersLen == 0) { /* No respopnse means fatal error */ error = true; error_class = ERROR_CLASS_SERVICES; diff --git a/bacnet-stack/demo/handler/h_pt_a.c b/bacnet-stack/demo/handler/h_pt_a.c index 70483105..f2af8998 100644 --- a/bacnet-stack/demo/handler/h_pt_a.c +++ b/bacnet-stack/demo/handler/h_pt_a.c @@ -104,7 +104,8 @@ void DecodeBlock( return; iLen += decode_character_string(&pData[iLen], len_value_type, &bsName); - strncpy((char *)Response.sMyString, characterstring_value(&bsName), MY_MAX_STR); + strncpy((char *) Response.sMyString, characterstring_value(&bsName), + MY_MAX_STR); Response.sMyString[MY_MAX_STR] = '\0'; /* Make sure it is nul terminated */ printf("Private Transfer Read Block Response\n"); @@ -168,13 +169,14 @@ void ProcessPTA( cBlockNumber = (char) ulTemp; DecodeBlock(cBlockNumber, &data->serviceParameters[iLen]); } else { /* Read error */ - printf("Private Transfer read operation returned error code: %lu\n", - (unsigned long)uiErrorCode); + printf + ("Private Transfer read operation returned error code: %lu\n", + (unsigned long) uiErrorCode); return; } } else { /* Write I/O block - should just be an OK type message */ printf("Private Transfer write operation returned error code: %lu\n", - (unsigned long)uiErrorCode); + (unsigned long) uiErrorCode); } } diff --git a/bacnet-stack/demo/handler/h_rd.c b/bacnet-stack/demo/handler/h_rd.c index 9709e5c9..304e8f6b 100644 --- a/bacnet-stack/demo/handler/h_rd.c +++ b/bacnet-stack/demo/handler/h_rd.c @@ -96,13 +96,13 @@ void handler_reinitialize_device( goto RD_ABORT; } /* decode the service request only */ - len = rd_decode_service_request(service_request, service_len, - &rd_data.state, + len = + rd_decode_service_request(service_request, service_len, &rd_data.state, &rd_data.password); #if PRINT_ENABLED if (len > 0) { fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n", - (unsigned) rd_data.state, + (unsigned) rd_data.state, characterstring_value(&rd_data.password)); } else { fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n"); @@ -143,8 +143,7 @@ void handler_reinitialize_device( service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE, rd_data.error_class, rd_data.error_code); #if PRINT_ENABLED - fprintf(stderr, - "ReinitializeDevice: Sending Error.\n"); + fprintf(stderr, "ReinitializeDevice: Sending Error.\n"); #endif } } diff --git a/bacnet-stack/demo/handler/h_rp.c b/bacnet-stack/demo/handler/h_rp.c index 4048806b..97ead2e8 100644 --- a/bacnet-stack/demo/handler/h_rp.c +++ b/bacnet-stack/demo/handler/h_rp.c @@ -113,26 +113,26 @@ void handler_read_property( } /* assume that there is an error */ error = true; - apdu_len = rp_ack_encode_apdu_init( - &Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, - &rpdata); + apdu_len = + rp_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], + service_data->invoke_id, &rpdata); /* configure our storage */ - rpdata.application_data = &Handler_Transmit_Buffer[npdu_len+apdu_len]; - rpdata.application_data_len = + rpdata.application_data = &Handler_Transmit_Buffer[npdu_len + apdu_len]; + rpdata.application_data_len = sizeof(Handler_Transmit_Buffer) - (npdu_len + apdu_len); - len = Device_Read_Property(&rpdata); + len = Device_Read_Property(&rpdata); if (len >= 0) { apdu_len += len; - len = rp_ack_encode_apdu_object_property_end( - &Handler_Transmit_Buffer[npdu_len+apdu_len]); + len = + rp_ack_encode_apdu_object_property_end(&Handler_Transmit_Buffer + [npdu_len + apdu_len]); apdu_len += len; if (apdu_len > service_data->max_resp) { /* too big for the sender - send an abort */ apdu_len = abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "RP: Message too large. Sending Abort!\n"); #endif @@ -163,11 +163,11 @@ void handler_read_property( fprintf(stderr, "RP: Sending Error!\n"); #endif } - } + } RP_ABORT: pdu_len = npdu_len + apdu_len; bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) diff --git a/bacnet-stack/demo/handler/h_rp_a.c b/bacnet-stack/demo/handler/h_rp_a.c index e034ee28..c60e962c 100644 --- a/bacnet-stack/demo/handler/h_rp_a.c +++ b/bacnet-stack/demo/handler/h_rp_a.c @@ -62,12 +62,12 @@ static void PrintReadPropertyData( if (data->array_index == BACNET_ARRAY_ALL) fprintf(stderr, "%s #%lu %s\n", bactext_object_type_name(data->object_type), - (unsigned long)data->object_instance, + (unsigned long) data->object_instance, bactext_property_name(data->object_property)); else fprintf(stderr, "%s #%lu %s[%d]\n", bactext_object_type_name(data->object_type), - (unsigned long)data->object_instance, + (unsigned long) data->object_instance, bactext_property_name(data->object_property), data->array_index); #endif @@ -160,23 +160,22 @@ int rp_ack_fully_decode_service_request( { int decoded_len = 0; /* return value */ BACNET_READ_PROPERTY_DATA rp1data; - BACNET_PROPERTY_REFERENCE *rp1_property; /* single property */ + BACNET_PROPERTY_REFERENCE *rp1_property; /* single property */ BACNET_APPLICATION_DATA_VALUE *value, *old_value; - uint8_t * vdata; + uint8_t *vdata; int vlen, len; decoded_len = rp_ack_decode_service_request(apdu, apdu_len, &rp1data); - if ( decoded_len > 0 ) - { - /* Then we have to transfer to the BACNET_READ_ACCESS_DATA structure - * and decode the value(s) portion - */ - read_access_data->object_type = rp1data.object_type; - read_access_data->object_instance = rp1data.object_instance; + if (decoded_len > 0) { + /* Then we have to transfer to the BACNET_READ_ACCESS_DATA structure + * and decode the value(s) portion + */ + read_access_data->object_type = rp1data.object_type; + read_access_data->object_instance = rp1data.object_instance; rp1_property = calloc(1, sizeof(BACNET_PROPERTY_REFERENCE)); read_access_data->listOfProperties = rp1_property; - if ( rp1_property == NULL ) - return -1; /* can't proceed if calloc failed. */ + if (rp1_property == NULL) + return -1; /* can't proceed if calloc failed. */ rp1_property->propertyIdentifier = rp1data.object_property; rp1_property->propertyArrayIndex = rp1data.array_index; /* Is there no Error case possible here, as there is when decoding RPM? */ @@ -184,7 +183,7 @@ int rp_ack_fully_decode_service_request( /* rp_ack_decode_service_request() processing already removed the * Opening and Closing '3' Tags. * note: if this is an array, there will be - more than one element to decode */ + more than one element to decode */ vdata = rp1data.application_data; vlen = rp1data.application_data_len; value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE)); @@ -196,9 +195,7 @@ int rp_ack_fully_decode_service_request( bacapp_decode_context_data(vdata, vlen, value, rp1_property->propertyIdentifier); } else { - len = - bacapp_decode_application_data(vdata, vlen, - value); + len = bacapp_decode_application_data(vdata, vlen, value); } decoded_len += len; vlen -= len; @@ -212,17 +209,15 @@ int rp_ack_fully_decode_service_request( } else { /* nothing decoded and no closing tag, so malformed */ if (len == 0) { - free( value ); - free( rp1_property ); + free(value); + free(rp1_property); read_access_data->listOfProperties = NULL; return -1; } - if ( vlen > 0 ) /* If more values */ - { - old_value = value; - value = - calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE)); - old_value->next = value; + if (vlen > 0) { /* If more values */ + old_value = value; + value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE)); + old_value->next = value; } } } diff --git a/bacnet-stack/demo/handler/h_rpm.c b/bacnet-stack/demo/handler/h_rpm.c index dc9d8128..aae31378 100644 --- a/bacnet-stack/demo/handler/h_rpm.c +++ b/bacnet-stack/demo/handler/h_rpm.c @@ -76,7 +76,7 @@ static BACNET_PROPERTY_ID RPM_Object_Property( } } - return (BACNET_PROPERTY_ID)property; + return (BACNET_PROPERTY_ID) property; } static unsigned RPM_Object_Property_Count( @@ -133,9 +133,9 @@ static int RPM_Encode_Property( rpdata.application_data_len = sizeof(Temp_Buf); len = Device_Read_Property(&rpdata); if (len < 0) { - if ( len == -2 ) { - return 0; /* Ie, Abort */ - } + if (len == -2) { + return 0; /* Ie, Abort */ + } /* error was returned - encode that for the response */ len = rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0], diff --git a/bacnet-stack/demo/handler/h_rpm_a.c b/bacnet-stack/demo/handler/h_rpm_a.c index d0892c19..4e357709 100644 --- a/bacnet-stack/demo/handler/h_rpm_a.c +++ b/bacnet-stack/demo/handler/h_rpm_a.c @@ -71,7 +71,7 @@ int rpm_ack_decode_service_request( BACNET_APPLICATION_DATA_VALUE *value; BACNET_APPLICATION_DATA_VALUE *old_value; - assert( read_access_data != NULL ); + assert(read_access_data != NULL); rpm_object = read_access_data; old_rpm_object = rpm_object; while (rpm_object && apdu_len) { @@ -211,7 +211,7 @@ static void PrintReadPropertyMultipleData( #if PRINT_ENABLED fprintf(stdout, "%s #%lu\r\n", bactext_object_type_name(rpm_data->object_type), - (unsigned long)rpm_data->object_instance); + (unsigned long) rpm_data->object_instance); fprintf(stdout, "{\r\n"); #endif listOfProperties = rpm_data->listOfProperties; @@ -219,11 +219,11 @@ static void PrintReadPropertyMultipleData( #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); + (unsigned) listOfProperties->propertyIdentifier); } #endif if (listOfProperties->propertyArrayIndex != BACNET_ARRAY_ALL) { @@ -261,10 +261,10 @@ static void PrintReadPropertyMultipleData( #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_rr.c b/bacnet-stack/demo/handler/h_rr.c index 901cdbf9..30260ceb 100644 --- a/bacnet-stack/demo/handler/h_rr.c +++ b/bacnet-stack/demo/handler/h_rr.c @@ -49,38 +49,38 @@ int Encode_RR_payload( BACNET_READ_RANGE_DATA * pRequest) { int apdu_len = -1; - rr_info_function info_fn_ptr = NULL; + rr_info_function info_fn_ptr = NULL; RR_PROP_INFO PropInfo; /* initialize the default return values */ pRequest->error_class = ERROR_CLASS_SERVICES; - pRequest->error_code = ERROR_CODE_OTHER; - + pRequest->error_code = ERROR_CODE_OTHER; + /* handle each object type */ info_fn_ptr = Device_Objects_RR_Info(pRequest->object_type); - + if ((info_fn_ptr != NULL) && (info_fn_ptr(pRequest, &PropInfo) != false)) { /* We try and do some of the more generic error checking here to cut down on duplication of effort */ - - if((pRequest->RequestType == RR_BY_POSITION) && (pRequest->Range.RefIndex == 0)) {/* First index is 1 so can't accept 0 */ - pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */ - } else if(((PropInfo.RequestTypes & RR_ARRAY_OF_LISTS) == 0) && (pRequest->array_index != 0) && (pRequest->array_index != BACNET_ARRAY_ALL)) { + + if ((pRequest->RequestType == RR_BY_POSITION) && (pRequest->Range.RefIndex == 0)) { /* First index is 1 so can't accept 0 */ + pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */ + } else if (((PropInfo.RequestTypes & RR_ARRAY_OF_LISTS) == 0) && + (pRequest->array_index != 0) && + (pRequest->array_index != BACNET_ARRAY_ALL)) { /* Array access attempted on a non array property */ - pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; - } - else if((pRequest->RequestType != RR_READ_ALL) && ((PropInfo.RequestTypes & pRequest->RequestType) == 0)) { + pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; + } else if ((pRequest->RequestType != RR_READ_ALL) && + ((PropInfo.RequestTypes & pRequest->RequestType) == 0)) { /* By Time or By Sequence not supported - By Position is always required */ - pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */ - } - else if((pRequest->Count == 0) && (pRequest->RequestType != RR_READ_ALL)) { /* Count cannot be zero */ - pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */ - } - else if(PropInfo.Handler != NULL) { + pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */ + } else if ((pRequest->Count == 0) && (pRequest->RequestType != RR_READ_ALL)) { /* Count cannot be zero */ + pRequest->error_code = ERROR_CODE_OTHER; /* I couldn't see anything more appropriate so... */ + } else if (PropInfo.Handler != NULL) { apdu_len = PropInfo.Handler(apdu, pRequest); } } else { /* Either we don't support RR for this property yet or it is not a list or array of lists */ - pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST; + pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST; } return apdu_len; @@ -119,7 +119,7 @@ void handler_read_range( #endif goto RR_ABORT; } - memset(&data, 0, sizeof(data)); /* start with blank canvas */ + memset(&data, 0, sizeof(data)); /* start with blank canvas */ len = rr_decode_service_request(service_request, service_len, &data); #if PRINT_ENABLED if (len <= 0) diff --git a/bacnet-stack/demo/handler/h_ucov.c b/bacnet-stack/demo/handler/h_ucov.c index 7a267216..ae1d53be 100644 --- a/bacnet-stack/demo/handler/h_ucov.c +++ b/bacnet-stack/demo/handler/h_ucov.c @@ -103,7 +103,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_wp.c b/bacnet-stack/demo/handler/h_wp.c index 3b7ddc09..060549dd 100644 --- a/bacnet-stack/demo/handler/h_wp.c +++ b/bacnet-stack/demo/handler/h_wp.c @@ -97,8 +97,10 @@ void handler_write_property( if (len > 0) fprintf(stderr, "WP: type=%lu instance=%lu property=%lu priority=%lu index=%ld\n", - (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.object_type, + (unsigned long) wp_data.object_instance, + (unsigned long) wp_data.object_property, + (unsigned long) wp_data.priority, (long) wp_data.array_index); else fprintf(stderr, "WP: Unable to decode Request!\n"); #endif @@ -149,13 +151,13 @@ void handler_write_property( */ bool WPValidateString( - BACNET_APPLICATION_DATA_VALUE *pValue, + BACNET_APPLICATION_DATA_VALUE * pValue, int iMaxLen, bool bEmptyAllowed, BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - bool bResult; + bool bResult; /* Save on a bit of code duplication by pre selecting the most * common outcomes from the tests (not necessarily the most likely @@ -164,21 +166,25 @@ bool WPValidateString( bResult = false; *pErrorClass = ERROR_CLASS_PROPERTY; - if(pValue->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - if(characterstring_encoding(&pValue->type.Character_String) == CHARACTER_ANSI_X34) { - if((bEmptyAllowed == false) && (characterstring_length(&pValue->type.Character_String) == 0)) { + if (pValue->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { + if (characterstring_encoding(&pValue->type.Character_String) == + CHARACTER_ANSI_X34) { + if ((bEmptyAllowed == false) && + (characterstring_length(&pValue->type.Character_String) == + 0)) { *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 - bResult = true; /* It's all good! */ + bResult = true; /* It's all good! */ } else *pErrorCode = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED; } else *pErrorCode = ERROR_CODE_INVALID_DATA_TYPE; - return(bResult); + return (bResult); } /** Perform simple validation of type of Write Property argument based @@ -187,23 +193,23 @@ bool WPValidateString( */ bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE *pValue, + BACNET_APPLICATION_DATA_VALUE * pValue, uint8_t ucExpectedTag, BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode) { - bool bResult; + bool bResult; /* * start out assuming success and only set up error * response if validation fails. */ bResult = true; - if(pValue->tag != ucExpectedTag) { + if (pValue->tag != ucExpectedTag) { bResult = false; *pErrorClass = ERROR_CLASS_PROPERTY; *pErrorCode = ERROR_CODE_INVALID_DATA_TYPE; } - return(bResult); + return (bResult); } diff --git a/bacnet-stack/demo/handler/objects.c b/bacnet-stack/demo/handler/objects.c index f1849b4c..83247247 100644 --- a/bacnet-stack/demo/handler/objects.c +++ b/bacnet-stack/demo/handler/objects.c @@ -94,7 +94,7 @@ OBJECT_DEVICE_T *objects_device_new( } else { fprintf(stderr, "Objects: Unable to allocate device %lu buffer\n", - (unsigned long)device_instance); + (unsigned long) device_instance); } } } @@ -112,7 +112,7 @@ OBJECT_DEVICE_T *objects_device_delete( pDevice = Keylist_Data_Delete_By_Index(Device_List, index); if (pDevice) { fprintf(stderr, "Objects: removing device %lu", - (unsigned long)pDevice->Object_Identifier.instance); + (unsigned long) pDevice->Object_Identifier.instance); if (pDevice->Object_List) { do { pObject = diff --git a/bacnet-stack/demo/handler/s_cov.c b/bacnet-stack/demo/handler/s_cov.c index 941d3d27..4dee2c78 100644 --- a/bacnet-stack/demo/handler/s_cov.c +++ b/bacnet-stack/demo/handler/s_cov.c @@ -124,10 +124,9 @@ uint8_t Send_COV_Subscribe( npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = cov_subscribe_encode_adpu( - &Handler_Transmit_Buffer[pdu_len], - invoke_id, - cov_data); + len = + cov_subscribe_encode_adpu(&Handler_Transmit_Buffer[pdu_len], + invoke_id, cov_data); pdu_len += len; /* will it fit in the sender? note: if there is a bottleneck router in between @@ -158,4 +157,3 @@ uint8_t Send_COV_Subscribe( return invoke_id; } - diff --git a/bacnet-stack/demo/handler/s_iam.c b/bacnet-stack/demo/handler/s_iam.c index 814230a1..844b19b2 100644 --- a/bacnet-stack/demo/handler/s_iam.c +++ b/bacnet-stack/demo/handler/s_iam.c @@ -56,7 +56,7 @@ int iam_encode_pdu( int len = 0; int pdu_len = 0; - datalink_get_broadcast_address(dest); + datalink_get_broadcast_address(dest); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL); pdu_len = npdu_encode_pdu(&buffer[0], dest, NULL, npdu_data); @@ -75,7 +75,7 @@ int iam_encode_pdu( * @param buffer [in] The buffer to use for building and sending the message. */ void Send_I_Am( - uint8_t * buffer ) + uint8_t * buffer) { int pdu_len = 0; BACNET_ADDRESS dest; @@ -126,15 +126,13 @@ int iam_unicast_encode_pdu( BACNET_ADDRESS my_address; /* The destination will be the same as the src, so copy it over. */ - memcpy( dest, src, sizeof( BACNET_ADDRESS ) ); + memcpy(dest, src, sizeof(BACNET_ADDRESS)); dest->net = 0; datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL); - npdu_len = - npdu_encode_pdu(&buffer[0], dest, &my_address, - npdu_data); + npdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data); /* encode the APDU portion of the packet */ apdu_len = iam_encode_apdu(&buffer[npdu_len], Device_Object_Instance_Number(), @@ -157,7 +155,7 @@ int iam_unicast_encode_pdu( */ void Send_I_Am_Unicast( uint8_t * buffer, - BACNET_ADDRESS * src ) + BACNET_ADDRESS * src) { int pdu_len = 0; BACNET_ADDRESS dest; @@ -186,4 +184,3 @@ void Send_I_Am_Unicast( fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno)); #endif } - diff --git a/bacnet-stack/demo/handler/s_wp.c b/bacnet-stack/demo/handler/s_wp.c index 8a961f57..b6b290ed 100644 --- a/bacnet-stack/demo/handler/s_wp.c +++ b/bacnet-stack/demo/handler/s_wp.c @@ -155,9 +155,8 @@ 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 bb042e9a..15b0e757 100644 --- a/bacnet-stack/demo/mstpcap/main.c +++ b/bacnet-stack/demo/mstpcap/main.c @@ -144,8 +144,7 @@ static void packet_statistics( if (dst > MSTP_Statistics[src].max_master) { MSTP_Statistics[src].max_master = dst; } - if ((old_frame == FRAME_TYPE_POLL_FOR_MASTER) && - (old_src == src)) { + if ((old_frame == FRAME_TYPE_POLL_FOR_MASTER) && (old_src == src)) { /* Tusage_timeout */ delta = timeval_diff_ms(&old_tv, tv); if (delta > MSTP_Statistics[src].tusage_timeout) { @@ -212,9 +211,8 @@ static void packet_statistics_save( fprintf(stdout, "\r\n"); for (i = 0; i < 256; i++) { /* check for masters or slaves */ - if ((MSTP_Statistics[i].token_count) || - (MSTP_Statistics[i].der_reply) || - (MSTP_Statistics[i].pfm_count)) { + if ((MSTP_Statistics[i].token_count) || (MSTP_Statistics[i].der_reply) + || (MSTP_Statistics[i].pfm_count)) { fprintf(stdout, "%u\t%u", i, (unsigned) MSTP_Statistics[i].max_master); fprintf(stdout, "\t%lu\t%lu\t%lu\t%lu", @@ -379,6 +377,7 @@ size_t data_write( } return fwrite(ptr, size, nitems, pFile); } + size_t data_write_header( const void *ptr, size_t size, @@ -413,7 +412,7 @@ static void filename_create( static void write_global_header( const char *filename) { - static bool pipe_enable = true; /* don't write more than one header */ + static bool pipe_enable = true; /* don't write more than one header */ uint32_t magic_number = 0xa1b2c3d4; /* magic number */ uint16_t version_major = 2; /* major version number */ uint16_t version_minor = 4; /* minor version number */ @@ -425,9 +424,12 @@ static void write_global_header( /* create a new file. */ pFile = fopen(filename, "wb"); if (pFile) { - (void) data_write_header(&magic_number, sizeof(magic_number), 1, pipe_enable); - (void) data_write_header(&version_major, sizeof(version_major), 1, pipe_enable); - (void) data_write_header(&version_minor, sizeof(version_minor), 1, pipe_enable); + (void) data_write_header(&magic_number, sizeof(magic_number), 1, + pipe_enable); + (void) data_write_header(&version_major, sizeof(version_major), 1, + pipe_enable); + (void) data_write_header(&version_minor, sizeof(version_minor), 1, + pipe_enable); (void) data_write_header(&thiszone, sizeof(thiszone), 1, pipe_enable); (void) data_write_header(&sigfigs, sizeof(sigfigs), 1, pipe_enable); (void) data_write_header(&snaplen, sizeof(snaplen), 1, pipe_enable); diff --git a/bacnet-stack/demo/object/ai.c b/bacnet-stack/demo/object/ai.c index 86be063f..5026a624 100644 --- a/bacnet-stack/demo/object/ai.c +++ b/bacnet-stack/demo/object/ai.c @@ -160,7 +160,7 @@ char *Analog_Input_Name( index = Analog_Input_Instance_To_Index(object_instance); if (index < MAX_ANALOG_INPUTS) { - sprintf(text_string, "ANALOG INPUT %lu", (unsigned long)index); + sprintf(text_string, "ANALOG INPUT %lu", (unsigned long) index); return text_string; } @@ -170,15 +170,14 @@ char *Analog_Input_Name( /* return apdu length, or -1 on error */ /* assumption - object has already exists */ int Analog_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -242,8 +241,7 @@ int Analog_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; @@ -276,7 +274,7 @@ void testAnalogInput( Analog_Input_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_ANALOG_INPUT; + rpdata.object_type = OBJECT_ANALOG_INPUT; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -284,8 +282,7 @@ void testAnalogInput( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/ao.c b/bacnet-stack/demo/object/ao.c index 17af1dad..9dbb99ab 100644 --- a/bacnet-stack/demo/object/ao.c +++ b/bacnet-stack/demo/object/ao.c @@ -259,7 +259,8 @@ char *Analog_Output_Name( static char text_string[32] = ""; /* okay for single thread */ if (object_instance < MAX_ANALOG_OUTPUTS) { - sprintf(text_string, "ANALOG OUTPUT %lu", (unsigned long)object_instance); + sprintf(text_string, "ANALOG OUTPUT %lu", + (unsigned long) object_instance); return text_string; } @@ -268,7 +269,7 @@ char *Analog_Output_Name( /* return apdu len, or -1 on error */ int Analog_Output_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -280,8 +281,7 @@ int Analog_Output_Read_Property( bool state = false; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -320,7 +320,8 @@ int Analog_Output_Read_Property( encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: - object_index = Analog_Output_Instance_To_Index(rpdata->object_instance); + object_index = + Analog_Output_Instance_To_Index(rpdata->object_instance); state = Analog_Output_Out_Of_Service[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; @@ -361,12 +362,13 @@ int Analog_Output_Read_Property( object_index = Analog_Output_Instance_To_Index(rpdata->object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { - if (Analog_Output_Level[object_index][rpdata->array_index - 1] == - AO_LEVEL_NULL) + if (Analog_Output_Level[object_index][rpdata->array_index - + 1] == AO_LEVEL_NULL) apdu_len = encode_application_null(&apdu[0]); else { real_value = - Analog_Output_Level[object_index][rpdata->array_index - 1]; + Analog_Output_Level[object_index][rpdata-> + array_index - 1]; apdu_len = encode_application_real(&apdu[0], real_value); } @@ -388,8 +390,7 @@ int Analog_Output_Read_Property( 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->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -435,29 +436,28 @@ bool Analog_Output_Write_Property( wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } else { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_NULL, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, + &wp_data->error_class, &wp_data->error_code); 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; } - } - } + } + } break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { object_index = Analog_Output_Instance_To_Index(wp_data->object_instance); @@ -494,7 +494,7 @@ void testAnalogOutput( Analog_Output_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_ANALOG_OUTPUT; + rpdata.object_type = OBJECT_ANALOG_OUTPUT; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -502,8 +502,7 @@ void testAnalogOutput( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/av.c b/bacnet-stack/demo/object/av.c index 0bc4812d..f96465b8 100644 --- a/bacnet-stack/demo/object/av.c +++ b/bacnet-stack/demo/object/av.c @@ -207,7 +207,8 @@ char *Analog_Value_Name( static char text_string[32] = ""; /* okay for single thread */ if (object_instance < MAX_ANALOG_VALUES) { - sprintf(text_string, "ANALOG VALUE %lu", (unsigned long)object_instance); + sprintf(text_string, "ANALOG VALUE %lu", + (unsigned long) object_instance); return text_string; } @@ -216,7 +217,7 @@ char *Analog_Value_Name( /* return apdu len, or -1 on error */ int Analog_Value_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -228,8 +229,7 @@ int Analog_Value_Read_Property( bool state = false; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -268,7 +268,8 @@ int Analog_Value_Read_Property( encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: - object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Analog_Value_Instance_To_Index(rpdata->object_instance); state = Analog_Value_Out_Of_Service[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; @@ -283,7 +284,8 @@ int Analog_Value_Read_Property( /* if no index was specified, then try to encode the entire list */ /* into one packet. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { - object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Analog_Value_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 (Analog_Value_Level[object_index][i] == @@ -306,14 +308,16 @@ int Analog_Value_Read_Property( } } } else { - object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Analog_Value_Instance_To_Index(rpdata->object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { - if (Analog_Value_Level[object_index][rpdata->array_index - 1] == - ANALOG_LEVEL_NULL) + if (Analog_Value_Level[object_index][rpdata->array_index - + 1] == ANALOG_LEVEL_NULL) apdu_len = encode_application_null(&apdu[0]); else { real_value = - Analog_Value_Level[object_index][rpdata->array_index - 1]; + Analog_Value_Level[object_index][rpdata-> + array_index - 1]; apdu_len = encode_application_real(&apdu[0], real_value); } @@ -335,8 +339,7 @@ int Analog_Value_Read_Property( 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->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -383,14 +386,14 @@ bool Analog_Value_Write_Property( wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } else { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_NULL, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, + &wp_data->error_class, &wp_data->error_code); if (status) { level = ANALOG_LEVEL_NULL; object_index = - Analog_Value_Instance_To_Index(wp_data->object_instance); + Analog_Value_Instance_To_Index(wp_data-> + object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; @@ -410,10 +413,9 @@ bool Analog_Value_Write_Property( } break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); @@ -449,7 +451,7 @@ void testAnalog_Value( Analog_Value_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_ANALOG_VALUE; + rpdata.object_type = OBJECT_ANALOG_VALUE; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -457,8 +459,7 @@ void testAnalog_Value( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/bacfile.c b/bacnet-stack/demo/object/bacfile.c index 23cfab84..715de069 100644 --- a/bacnet-stack/demo/object/bacfile.c +++ b/bacnet-stack/demo/object/bacfile.c @@ -185,7 +185,7 @@ static unsigned bacfile_file_size( /* return the number of bytes used, or -1 on error */ int bacfile_read_property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ char text_string[32] = { "" }; @@ -194,8 +194,7 @@ int bacfile_read_property( BACNET_TIME btime; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -207,7 +206,8 @@ int bacfile_read_property( rpdata->object_instance); break; case PROP_OBJECT_NAME: - sprintf(text_string, "FILE %lu", (unsigned long)rpdata->object_instance); + sprintf(text_string, "FILE %lu", + (unsigned long) rpdata->object_instance); characterstring_init_ansi(&char_string, text_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); @@ -302,10 +302,9 @@ bool bacfile_write_property( property shall be logical TRUE only if no changes have been made to the file data by internal processes or through File Access Services since the last time the object was archived. */ - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Boolean) { /* FIXME: do something to wp_data->object_instance */ @@ -318,10 +317,9 @@ bool bacfile_write_property( /* If the file size can be changed by writing to the file, and File_Access_Method is STREAM_ACCESS, then this property shall be writable. */ - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { /* FIXME: do something with value.type.Unsigned to wp_data->object_instance */ diff --git a/bacnet-stack/demo/object/bi.c b/bacnet-stack/demo/object/bi.c index 407c0ce2..ee7b89f5 100644 --- a/bacnet-stack/demo/object/bi.c +++ b/bacnet-stack/demo/object/bi.c @@ -39,7 +39,7 @@ #include "bi.h" #include "handlers.h" -#ifndef MAX_BINARY_INPUTS +#ifndef MAX_BINARY_INPUTS #define MAX_BINARY_INPUTS 5 #endif @@ -287,7 +287,8 @@ char *Binary_Input_Name( static char text_string[32] = ""; /* okay for single thread */ if (object_instance < MAX_BINARY_INPUTS) { - sprintf(text_string, "BINARY INPUT %lu", (unsigned long)object_instance); + sprintf(text_string, "BINARY INPUT %lu", + (unsigned long) object_instance); return text_string; } @@ -297,7 +298,7 @@ char *Binary_Input_Name( /* return apdu length, or -1 on error */ /* assumption - object already exists, and has been bounds checked */ int Binary_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; @@ -305,8 +306,7 @@ int Binary_Input_Read_Property( BACNET_POLARITY polarity = POLARITY_NORMAL; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -370,8 +370,7 @@ int Binary_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; @@ -396,10 +395,9 @@ bool Binary_Input_Write_Property( /* FIXME: len == 0: unable to decode? */ switch (wp_data->object_property) { case PROP_PRESENT_VALUE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Enumerated <= MAX_BINARY_PV) { Binary_Input_Present_Value_Set(wp_data->object_instance, @@ -412,10 +410,9 @@ bool Binary_Input_Write_Property( } break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { Binary_Input_Out_Of_Service_Set(wp_data->object_instance, value.type.Boolean); @@ -449,7 +446,7 @@ void testBinaryInput( Binary_Input_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_BINARY_INPUT; + rpdata.object_type = OBJECT_BINARY_INPUT; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -457,8 +454,7 @@ void testBinaryInput( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/bo.c b/bacnet-stack/demo/object/bo.c index cc3e6d25..1692dc1f 100644 --- a/bacnet-stack/demo/object/bo.c +++ b/bacnet-stack/demo/object/bo.c @@ -183,7 +183,8 @@ char *Binary_Output_Name( static char text_string[32] = ""; /* okay for single thread */ if (object_instance < MAX_BINARY_OUTPUTS) { - sprintf(text_string, "BINARY OUTPUT %lu", (unsigned long)object_instance); + sprintf(text_string, "BINARY OUTPUT %lu", + (unsigned long) object_instance); return text_string; } @@ -192,7 +193,7 @@ char *Binary_Output_Name( /* return apdu len, or -1 on error */ int Binary_Output_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -205,8 +206,7 @@ int Binary_Output_Read_Property( bool state = false; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -231,7 +231,8 @@ int Binary_Output_Read_Property( encode_application_enumerated(&apdu[0], OBJECT_BINARY_OUTPUT); break; case PROP_PRESENT_VALUE: - present_value = Binary_Output_Present_Value(rpdata->object_instance); + present_value = + Binary_Output_Present_Value(rpdata->object_instance); apdu_len = encode_application_enumerated(&apdu[0], present_value); break; case PROP_STATUS_FLAGS: @@ -249,7 +250,8 @@ int Binary_Output_Read_Property( encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: - object_index = Binary_Output_Instance_To_Index(rpdata->object_instance); + object_index = + Binary_Output_Instance_To_Index(rpdata->object_instance); state = Binary_Output_Out_Of_Service[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; @@ -290,12 +292,13 @@ int Binary_Output_Read_Property( object_index = Binary_Output_Instance_To_Index(rpdata->object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { - if (Binary_Output_Level[object_index][rpdata->array_index - 1] == - BINARY_NULL) + if (Binary_Output_Level[object_index][rpdata->array_index - + 1] == BINARY_NULL) apdu_len = encode_application_null(&apdu[apdu_len]); else { present_value = - Binary_Output_Level[object_index][rpdata->array_index - 1]; + Binary_Output_Level[object_index][rpdata-> + array_index - 1]; apdu_len = encode_application_enumerated(&apdu[apdu_len], present_value); @@ -329,8 +332,7 @@ int Binary_Output_Read_Property( 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->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -369,8 +371,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 @@ -390,14 +392,14 @@ bool Binary_Output_Write_Property( wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } else { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_NULL, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, + &wp_data->error_class, &wp_data->error_code); 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--; @@ -417,10 +419,9 @@ bool Binary_Output_Write_Property( } break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { object_index = Binary_Output_Instance_To_Index(wp_data->object_instance); @@ -457,7 +458,7 @@ void testBinaryOutput( Binary_Output_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_BINARY_OUTPUT; + rpdata.object_type = OBJECT_BINARY_OUTPUT; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -465,8 +466,7 @@ void testBinaryOutput( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/bv.c b/bacnet-stack/demo/object/bv.c index 0a5978ec..f54207a8 100644 --- a/bacnet-stack/demo/object/bv.c +++ b/bacnet-stack/demo/object/bv.c @@ -180,7 +180,8 @@ char *Binary_Value_Name( static char text_string[32] = ""; /* okay for single thread */ if (object_instance < MAX_BINARY_VALUES) { - sprintf(text_string, "BINARY VALUE %lu", (unsigned long)object_instance); + sprintf(text_string, "BINARY VALUE %lu", + (unsigned long) object_instance); return text_string; } @@ -189,7 +190,7 @@ char *Binary_Value_Name( /* return apdu len, or -1 on error */ int Binary_Value_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -201,8 +202,7 @@ int Binary_Value_Read_Property( bool state = false; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -227,7 +227,8 @@ int Binary_Value_Read_Property( encode_application_enumerated(&apdu[0], OBJECT_BINARY_VALUE); break; case PROP_PRESENT_VALUE: - present_value = Binary_Value_Present_Value(rpdata->object_instance); + present_value = + Binary_Value_Present_Value(rpdata->object_instance); apdu_len = encode_application_enumerated(&apdu[0], present_value); break; case PROP_STATUS_FLAGS: @@ -245,7 +246,8 @@ int Binary_Value_Read_Property( encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: - object_index = Binary_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Binary_Value_Instance_To_Index(rpdata->object_instance); state = Binary_Value_Out_Of_Service[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; @@ -257,7 +259,8 @@ int Binary_Value_Read_Property( /* if no index was specified, then try to encode the entire list */ /* into one packet. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { - object_index = Binary_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Binary_Value_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 (Binary_Value_Level[object_index][i] == BINARY_NULL) @@ -279,14 +282,16 @@ int Binary_Value_Read_Property( } } } else { - object_index = Binary_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Binary_Value_Instance_To_Index(rpdata->object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { - if (Binary_Value_Level[object_index][rpdata->array_index] == - BINARY_NULL) + if (Binary_Value_Level[object_index][rpdata-> + array_index] == BINARY_NULL) apdu_len = encode_application_null(&apdu[apdu_len]); else { present_value = - Binary_Value_Level[object_index][rpdata->array_index]; + Binary_Value_Level[object_index][rpdata-> + array_index]; apdu_len = encode_application_enumerated(&apdu[apdu_len], present_value); @@ -310,8 +315,7 @@ int Binary_Value_Read_Property( 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->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -350,8 +354,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 @@ -371,14 +375,14 @@ bool Binary_Value_Write_Property( wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } else { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_NULL, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, + &wp_data->error_class, &wp_data->error_code); 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--; @@ -398,12 +402,12 @@ bool Binary_Value_Write_Property( } break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { - object_index = Binary_Value_Instance_To_Index(wp_data->object_instance); + object_index = + Binary_Value_Instance_To_Index(wp_data->object_instance); Binary_Value_Out_Of_Service[object_index] = value.type.Boolean; } break; @@ -436,7 +440,7 @@ void testBinary_Value( Binary_Value_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_BINARY_VALUE; + rpdata.object_type = OBJECT_BINARY_VALUE; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -444,8 +448,7 @@ void testBinary_Value( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index 41bc45a0..66978416 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -29,7 +29,7 @@ #include #include #include /* for memmove */ -#include /* for timezone, localtime */ +#include /* for timezone, localtime */ #include "bacdef.h" #include "bacdcode.h" #include "bacenum.h" @@ -70,7 +70,7 @@ long int timezone; /* forward prototypes */ static int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); static bool Device_Write_Property_Local( BACNET_WRITE_PROPERTY_DATA * wp_data); @@ -82,7 +82,7 @@ static bool Device_Write_Property_Local( * for each Object type. * In both appearance and operation, this group of functions acts like * they are member functions of a C++ Object base class. - */ + */ static struct object_functions { BACNET_OBJECT_TYPE Object_Type; object_init_function Object_Init; @@ -95,154 +95,76 @@ static struct object_functions { rpm_property_lists_function Object_RPM_List; rr_info_function Object_RR_Info; object_iterate_function Object_Iterator; -} Object_Table[] = -{ - {OBJECT_DEVICE, - NULL, - Device_Count, - Device_Index_To_Instance, - Device_Valid_Object_Instance_Number, - Device_Name, - Device_Read_Property_Local, - Device_Write_Property_Local, - Device_Property_Lists, - DeviceGetRRInfo, - NULL}, - {OBJECT_ANALOG_INPUT, - Analog_Input_Init, - Analog_Input_Count, - Analog_Input_Index_To_Instance, - Analog_Input_Valid_Instance, - Analog_Input_Name, - Analog_Input_Read_Property, - NULL, - Analog_Input_Property_Lists, - NULL, - NULL}, - {OBJECT_ANALOG_OUTPUT, - Analog_Output_Init, - Analog_Output_Count, - Analog_Output_Index_To_Instance, - Analog_Output_Valid_Instance, - Analog_Output_Name, - Analog_Output_Read_Property, - Analog_Output_Write_Property, - Analog_Output_Property_Lists, - NULL, - NULL}, - {OBJECT_ANALOG_VALUE, - Analog_Value_Init, - Analog_Value_Count, - Analog_Value_Index_To_Instance, - Analog_Value_Valid_Instance, - Analog_Value_Name, - Analog_Value_Read_Property, - Analog_Value_Write_Property, - Analog_Value_Property_Lists, - NULL, - NULL}, - {OBJECT_BINARY_INPUT, - Binary_Input_Init, - Binary_Input_Count, - Binary_Input_Index_To_Instance, - Binary_Input_Valid_Instance, - Binary_Input_Name, - Binary_Input_Read_Property, - NULL, - Binary_Input_Property_Lists, - NULL, - NULL}, - {OBJECT_BINARY_OUTPUT, - Binary_Output_Init, - Binary_Output_Count, - Binary_Output_Index_To_Instance, - Binary_Output_Valid_Instance, - Binary_Output_Name, - Binary_Output_Read_Property, - Binary_Output_Write_Property, - Binary_Output_Property_Lists, - NULL, - NULL}, - {OBJECT_BINARY_VALUE, - Binary_Value_Init, - Binary_Value_Count, - Binary_Value_Index_To_Instance, - Binary_Value_Valid_Instance, - Binary_Value_Name, - Binary_Value_Read_Property, - Binary_Value_Write_Property, - Binary_Value_Property_Lists, - NULL, - NULL}, - {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_Name, - Life_Safety_Point_Read_Property, - Life_Safety_Point_Write_Property, - Life_Safety_Point_Property_Lists, - NULL, - NULL}, - {OBJECT_LOAD_CONTROL, - Load_Control_Init, - Load_Control_Count, - Load_Control_Index_To_Instance, - Load_Control_Valid_Instance, - Load_Control_Name, - Load_Control_Read_Property, - Load_Control_Write_Property, - Load_Control_Property_Lists, - NULL, - NULL}, - {OBJECT_MULTI_STATE_OUTPUT, - Multistate_Output_Init, - Multistate_Output_Count, - Multistate_Output_Index_To_Instance, - Multistate_Output_Valid_Instance, - Multistate_Output_Name, - Multistate_Output_Read_Property, - Multistate_Output_Write_Property, - Multistate_Output_Property_Lists, - NULL, - NULL}, - {OBJECT_MULTI_STATE_INPUT, - Multistate_Input_Init, - Multistate_Input_Count, - Multistate_Input_Index_To_Instance, - Multistate_Input_Valid_Instance, - Multistate_Input_Name, - Multistate_Input_Read_Property, - Multistate_Input_Write_Property, - Multistate_Input_Property_Lists, - NULL, - NULL}, - {OBJECT_TRENDLOG, - Trend_Log_Init, - Trend_Log_Count, - Trend_Log_Index_To_Instance, - Trend_Log_Valid_Instance, - Trend_Log_Name, - Trend_Log_Read_Property, - Trend_Log_Write_Property, - Trend_Log_Property_Lists, - TrendLogGetRRInfo, - NULL}, +} Object_Table[] = { + { + OBJECT_DEVICE, NULL, Device_Count, Device_Index_To_Instance, + Device_Valid_Object_Instance_Number, Device_Name, + Device_Read_Property_Local, Device_Write_Property_Local, + Device_Property_Lists, DeviceGetRRInfo, NULL}, { + OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count, + Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance, + Analog_Input_Name, Analog_Input_Read_Property, NULL, + Analog_Input_Property_Lists, NULL, NULL}, { + OBJECT_ANALOG_OUTPUT, Analog_Output_Init, Analog_Output_Count, + Analog_Output_Index_To_Instance, Analog_Output_Valid_Instance, + Analog_Output_Name, Analog_Output_Read_Property, + Analog_Output_Write_Property, Analog_Output_Property_Lists, + NULL, NULL}, { + OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count, + Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance, + Analog_Value_Name, Analog_Value_Read_Property, + Analog_Value_Write_Property, Analog_Value_Property_Lists, NULL, + NULL}, { + OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count, + Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance, + Binary_Input_Name, Binary_Input_Read_Property, NULL, + Binary_Input_Property_Lists, NULL, NULL}, { + OBJECT_BINARY_OUTPUT, Binary_Output_Init, Binary_Output_Count, + Binary_Output_Index_To_Instance, Binary_Output_Valid_Instance, + Binary_Output_Name, Binary_Output_Read_Property, + Binary_Output_Write_Property, Binary_Output_Property_Lists, + NULL, NULL}, { + OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count, + Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance, + Binary_Value_Name, Binary_Value_Read_Property, + Binary_Value_Write_Property, Binary_Value_Property_Lists, NULL, + NULL}, { + 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_Name, + Life_Safety_Point_Read_Property, + Life_Safety_Point_Write_Property, + Life_Safety_Point_Property_Lists, NULL, NULL}, { + OBJECT_LOAD_CONTROL, Load_Control_Init, Load_Control_Count, + Load_Control_Index_To_Instance, Load_Control_Valid_Instance, + Load_Control_Name, Load_Control_Read_Property, + Load_Control_Write_Property, Load_Control_Property_Lists, NULL, + NULL}, { + OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init, + Multistate_Output_Count, Multistate_Output_Index_To_Instance, + Multistate_Output_Valid_Instance, Multistate_Output_Name, + Multistate_Output_Read_Property, + Multistate_Output_Write_Property, + Multistate_Output_Property_Lists, NULL, NULL}, { + OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, + Multistate_Input_Count, Multistate_Input_Index_To_Instance, + Multistate_Input_Valid_Instance, Multistate_Input_Name, + Multistate_Input_Read_Property, + Multistate_Input_Write_Property, + Multistate_Input_Property_Lists, NULL, NULL}, { + OBJECT_TRENDLOG, Trend_Log_Init, Trend_Log_Count, + Trend_Log_Index_To_Instance, Trend_Log_Valid_Instance, + Trend_Log_Name, Trend_Log_Read_Property, + Trend_Log_Write_Property, Trend_Log_Property_Lists, + TrendLogGetRRInfo, NULL}, #if defined(BACFILE) - {OBJECT_FILE, - bacfile_init, - bacfile_count, - bacfile_index_to_instance, - bacfile_valid_instance, - bacfile_name, - bacfile_read_property, - bacfile_write_property, - BACfile_Property_Lists, - NULL}, + { + OBJECT_FILE, bacfile_init, bacfile_count, bacfile_index_to_instance, + bacfile_valid_instance, bacfile_name, bacfile_read_property, + bacfile_write_property, BACfile_Property_Lists, NULL}, #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} }; /** Glue function to let the Device object, when called by a handler, @@ -252,7 +174,7 @@ static struct object_functions { * @return Pointer to the group of object helper functions that implement this * type of Object. */ -static struct object_functions * Device_Objects_Find_Functions( +static struct object_functions *Device_Objects_Find_Functions( BACNET_OBJECT_TYPE Object_Type) { struct object_functions *pObject = NULL; @@ -261,13 +183,13 @@ static struct object_functions * Device_Objects_Find_Functions( while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { /* handle each object type */ if (pObject->Object_Type == Object_Type) { - return(pObject); + return (pObject); } pObject++; } - return(NULL); + return (NULL); } /** Try to find a rr_info_function helper function for the requested object type. @@ -281,12 +203,11 @@ static struct object_functions * Device_Objects_Find_Functions( */ rr_info_function Device_Objects_RR_Info( BACNET_OBJECT_TYPE object_type) - { struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); - return(pObject != NULL ? pObject->Object_RR_Info : NULL); + return (pObject != NULL ? pObject->Object_RR_Info : NULL); } static unsigned property_list_count( @@ -332,21 +253,22 @@ void Device_Objects_Property_List( pObject = Device_Objects_Find_Functions(object_type); if ((pObject != NULL) && (pObject->Object_RPM_List != NULL)) { - pObject->Object_RPM_List( - &pPropertyList->Required.pList, - &pPropertyList->Optional.pList, - &pPropertyList->Proprietary.pList); + pObject->Object_RPM_List(&pPropertyList->Required.pList, + &pPropertyList->Optional.pList, &pPropertyList->Proprietary.pList); } /* Fetch the counts if available otherwise zero them */ - pPropertyList->Required.count = pPropertyList->Required.pList == NULL - ? 0 : property_list_count(pPropertyList->Required.pList); + pPropertyList->Required.count = + pPropertyList->Required.pList == + NULL ? 0 : property_list_count(pPropertyList->Required.pList); - pPropertyList->Optional.count = pPropertyList->Optional.pList == NULL - ? 0 : property_list_count(pPropertyList->Optional.pList); - - pPropertyList->Proprietary.count = pPropertyList->Proprietary.pList == NULL - ? 0 : property_list_count(pPropertyList->Proprietary.pList); + pPropertyList->Optional.count = + pPropertyList->Optional.pList == + NULL ? 0 : property_list_count(pPropertyList->Optional.pList); + + pPropertyList->Proprietary.count = + pPropertyList->Proprietary.pList == + NULL ? 0 : property_list_count(pPropertyList->Proprietary.pList); return; } @@ -364,8 +286,8 @@ void Device_Objects_Property_List( * On failure, the error class and code will be set. * @return True if succeeds (password is correct), else False. */ -bool Device_Reinitialize( - BACNET_REINITIALIZE_DEVICE_DATA *rd_data) +bool Device_Reinitialize( + BACNET_REINITIALIZE_DEVICE_DATA * rd_data) { bool status = false; @@ -398,7 +320,7 @@ bool Device_Reinitialize( rd_data->error_class = ERROR_CLASS_SECURITY; rd_data->error_code = ERROR_CODE_PASSWORD_FAILURE; } - + return status; } @@ -493,8 +415,8 @@ static char Description[MAX_DEV_DESC_LEN + 1] = "server"; /* static uint8_t Max_Segments_Accepted = 0; */ /* VT_Classes_Supported */ /* Active_VT_Sessions */ -static BACNET_TIME Local_Time; /* rely on OS, if there is one */ -static BACNET_DATE Local_Date; /* rely on OS, if there is one */ +static BACNET_TIME Local_Time; /* rely on OS, if there is one */ +static BACNET_DATE Local_Date; /* rely on OS, if there is one */ /* NOTE: BACnet UTC Offset is inverse of common practice. If your UTC offset is -5hours of GMT, then BACnet UTC offset is +5hours. @@ -517,7 +439,8 @@ static uint32_t Database_Revision = 0; /* Slave_Address_Binding */ /* Profile_Name */ -unsigned Device_Count(void) +unsigned Device_Count( + void) { return 1; } @@ -551,8 +474,7 @@ bool Device_Set_Object_Instance_Number( /* Make the change and update the database revision */ Object_Instance_Number = object_id; Device_Inc_Database_Revision(); - } - else + } else status = false; return status; @@ -572,7 +494,7 @@ char *Device_Name( if (object_instance == Object_Instance_Number) { return My_Object_Name; } - + return NULL; } @@ -612,12 +534,12 @@ int Device_Set_System_Status( BACNET_DEVICE_STATUS status, bool local) { - int result = 0; /*return value - 0 = ok, -1 = bad value, -2 = not allowed */ + int result = 0; /*return value - 0 = ok, -1 = bad value, -2 = not allowed */ /* We limit the options available depending on whether the source is * internal or external. */ - if(local) { - switch(status) { + if (local) { + switch (status) { case STATUS_OPERATIONAL: case STATUS_OPERATIONAL_READ_ONLY: case STATUS_DOWNLOAD_REQUIRED: @@ -626,7 +548,7 @@ int Device_Set_System_Status( System_Status = status; break; - /* Don't support backup at present so don't allow setting */ + /* Don't support backup at present so don't allow setting */ case STATUS_BACKUP_IN_PROGRESS: result = -2; break; @@ -636,30 +558,30 @@ int Device_Set_System_Status( break; } } else { - switch(status) { - /* Allow these for the moment as a way to easily alter - * overall device operation. The lack of password protection - * or other authentication makes allowing writes to this - * property a risky facility to provide. - */ + switch (status) { + /* Allow these for the moment as a way to easily alter + * overall device operation. The lack of password protection + * or other authentication makes allowing writes to this + * property a risky facility to provide. + */ case STATUS_OPERATIONAL: case STATUS_OPERATIONAL_READ_ONLY: case STATUS_NON_OPERATIONAL: System_Status = status; break; - /* Don't allow outsider set this - it should probably - * be set if the device config is incomplete or - * corrupted or perhaps after some sort of operator - * wipe operation. - */ + /* Don't allow outsider set this - it should probably + * be set if the device config is incomplete or + * corrupted or perhaps after some sort of operator + * wipe operation. + */ case STATUS_DOWNLOAD_REQUIRED: - /* Don't allow outsider set this - it should be set - * internally at the start of a multi packet download - * perhaps indirectly via PT or WF to a config file. - */ + /* Don't allow outsider set this - it should be set + * internally at the start of a multi packet download + * perhaps indirectly via PT or WF to a config file. + */ case STATUS_DOWNLOAD_IN_PROGRESS: - /* Don't support backup at present so don't allow setting */ + /* Don't support backup at present so don't allow setting */ case STATUS_BACKUP_IN_PROGRESS: result = -2; break; @@ -670,7 +592,7 @@ int Device_Set_System_Status( } } - return(result); + return (result); } const char *Device_Vendor_Name( @@ -880,28 +802,29 @@ bool Device_Object_List_Identifier( while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { if (pObject->Object_Count) { object_index -= count; - count = pObject->Object_Count(); - if (object_index < count) { - /* Use the iterator function if available otherwise + count = pObject->Object_Count(); + if (object_index < count) { + /* Use the iterator function if available otherwise * look for the index to instance to get the ID */ - if(pObject->Object_Iterator) { + if (pObject->Object_Iterator) { /* First find the first object */ temp_index = pObject->Object_Iterator(~0); /* Then step through the objects to find the nth */ - while(object_index != 0) { - temp_index = pObject->Object_Iterator(temp_index); + while (object_index != 0) { + temp_index = pObject->Object_Iterator(temp_index); object_index--; } /* set the object_index up before falling through to next bit */ object_index = temp_index; } - if(pObject->Object_Index_To_Instance) { - *object_type = pObject->Object_Type; - *instance = pObject->Object_Index_To_Instance(object_index); + if (pObject->Object_Index_To_Instance) { + *object_type = pObject->Object_Type; + *instance = + pObject->Object_Index_To_Instance(object_index); status = true; - break; - } - } + break; + } + } } pObject++; } @@ -965,18 +888,19 @@ char *Device_Valid_Object_Id( pObject = Device_Objects_Find_Functions(object_type); if ((pObject != NULL) && (pObject->Object_Name != NULL)) name = pObject->Object_Name(object_instance); - + return name; } -static void Update_Current_Time(void) +static void Update_Current_Time( + void) { struct tm *tblock = NULL; - #if defined(_MSC_VER) +#if defined(_MSC_VER) time_t tTemp; - #else +#else struct timeval tv; - #endif +#endif /* struct tm @@ -990,46 +914,36 @@ int tm_wday Day of week [0,6] (Sunday =0). int tm_yday Day of year [0,365]. int tm_isdst Daylight Savings flag. */ - #if defined(_MSC_VER) +#if defined(_MSC_VER) time(&tTemp); tblock = localtime(&tTemp); - #else - if (gettimeofday(&tv, NULL) == 0) { +#else + if (gettimeofday(&tv, NULL) == 0) { tblock = localtime(&tv.tv_sec); } - #endif - +#endif + if (tblock) { - datetime_set_date( - &Local_Date, - (uint16_t) tblock->tm_year+1900, - (uint8_t) tblock->tm_mon+1, - (uint8_t) tblock->tm_mday); - #if !defined(_MSC_VER) - datetime_set_time( - &Local_Time, - (uint8_t) tblock->tm_hour, - (uint8_t) tblock->tm_min, - (uint8_t) tblock->tm_sec, - (uint8_t)(tv.tv_usec / 10000)); - #else - datetime_set_time( - &Local_Time, - (uint8_t) tblock->tm_hour, - (uint8_t) tblock->tm_min, - (uint8_t) tblock->tm_sec, - 0); - #endif + datetime_set_date(&Local_Date, (uint16_t) tblock->tm_year + 1900, + (uint8_t) tblock->tm_mon + 1, (uint8_t) tblock->tm_mday); +#if !defined(_MSC_VER) + datetime_set_time(&Local_Time, (uint8_t) tblock->tm_hour, + (uint8_t) tblock->tm_min, (uint8_t) tblock->tm_sec, + (uint8_t) (tv.tv_usec / 10000)); +#else + datetime_set_time(&Local_Time, (uint8_t) tblock->tm_hour, + (uint8_t) tblock->tm_min, (uint8_t) tblock->tm_sec, 0); +#endif if (tblock->tm_isdst) { Daylight_Savings_Status = true; } else { Daylight_Savings_Status = false; } /* note: timezone is declared in stdlib. */ - UTC_Offset = timezone/60; + UTC_Offset = timezone / 60; } else { datetime_date_wildcard_set(&Local_Date); - datetime_time_wildcard_set(&Local_Time); + datetime_time_wildcard_set(&Local_Time); Daylight_Savings_Status = false; } } @@ -1037,7 +951,7 @@ int tm_isdst Daylight Savings flag. /* return the length of the apdu encoded or -1 for error or -2 for abort message */ static int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ int len = 0; /* apdu len intermediate value */ @@ -1051,8 +965,7 @@ static int Device_Read_Property_Local( struct object_functions *pObject = NULL; bool found = false; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -1162,8 +1075,7 @@ static int Device_Read_Property_Local( pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { - if ((pObject->Object_Count) && - (pObject->Object_Count() > 0)) { + if ((pObject->Object_Count) && (pObject->Object_Count() > 0)) { bitstring_set_bit(&bit_string, pObject->Object_Type, true); } pObject++; @@ -1181,9 +1093,8 @@ static int Device_Read_Property_Local( /* your maximum APDU size. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 1; i <= count; i++) { - found = Device_Object_List_Identifier( - i, - &object_type, + found = + Device_Object_List_Identifier(i, &object_type, &instance); if (found) { len = @@ -1206,10 +1117,9 @@ static int Device_Read_Property_Local( } } } else { - found = Device_Object_List_Identifier( - rpdata->array_index, - &object_type, - &instance); + found = + Device_Object_List_Identifier(rpdata->array_index, + &object_type, &instance); if (found) { apdu_len = encode_application_object_id(&apdu[0], object_type, @@ -1265,8 +1175,7 @@ static int Device_Read_Property_Local( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->object_property != PROP_OBJECT_LIST) && + if ((apdu_len >= 0) && (rpdata->object_property != PROP_OBJECT_LIST) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -1285,7 +1194,7 @@ static int Device_Read_Property_Local( * @return The length of the APDU on success, else -1 */ int Device_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = -1; struct object_functions *pObject = NULL; @@ -1295,7 +1204,7 @@ int Device_Read_Property( rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; pObject = Device_Objects_Find_Functions(rpdata->object_type); if (pObject != NULL) { - if (pObject->Object_Valid_Instance && + if (pObject->Object_Valid_Instance && pObject->Object_Valid_Instance(rpdata->object_instance)) { if (pObject->Object_Read_Property) { apdu_len = pObject->Object_Read_Property(rpdata); @@ -1329,13 +1238,13 @@ static bool Device_Write_Property_Local( /* FIXME: len == 0: unable to decode? */ switch (wp_data->object_property) { case PROP_OBJECT_IDENTIFIER: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_OBJECT_ID, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_OBJECT_ID, + &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; @@ -1345,43 +1254,39 @@ static bool Device_Write_Property_Local( } break; case PROP_NUMBER_OF_APDU_RETRIES: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { /* FIXME: bounds check? */ apdu_retries_set((uint8_t) value.type.Unsigned_Int); } break; case PROP_APDU_TIMEOUT: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { /* FIXME: bounds check? */ apdu_timeout_set((uint16_t) value.type.Unsigned_Int); } break; case PROP_VENDOR_IDENTIFIER: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &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: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); if (status) { - temp = Device_Set_System_Status((BACNET_DEVICE_STATUS) + temp = Device_Set_System_Status((BACNET_DEVICE_STATUS) value.type.Enumerated, false); if (temp != 0) { status = false; @@ -1389,62 +1294,63 @@ static bool Device_Write_Property_Local( if (temp == -1) { wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } else { - wp_data->error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; + wp_data->error_code = + ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; } } } break; case PROP_OBJECT_NAME: - status = 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), characterstring_length(&value.type.Character_String)); + status = + 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), + characterstring_length(&value.type.Character_String)); } break; case PROP_LOCATION: - status = WPValidateString(&value, - MAX_DEV_LOC_LEN, - true, + status = + 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), characterstring_length(&value.type.Character_String)); + if (status) { + Device_Set_Location(characterstring_value(&value.type. + Character_String), + characterstring_length(&value.type.Character_String)); } break; case PROP_DESCRIPTION: - status = 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), characterstring_length(&value.type.Character_String)); + status = + 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), + characterstring_length(&value.type.Character_String)); } break; case PROP_MODEL_NAME: - status = 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), characterstring_length(&value.type.Character_String)); + status = + 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), + characterstring_length(&value.type.Character_String)); } break; #if defined(BACDL_MSTP) case PROP_MAX_INFO_FRAMES: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &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; @@ -1453,10 +1359,9 @@ static bool Device_Write_Property_Local( } break; case PROP_MAX_MASTER: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { if ((value.type.Unsigned_Int > 0) && (value.type.Unsigned_Int <= 127)) { @@ -1490,7 +1395,7 @@ static bool Device_Write_Property_Local( bool Device_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data) { - bool status = false; /* Ever the pessamist! */ + bool status = false; /* Ever the pessamist! */ struct object_functions *pObject = NULL; /* initialize the default return values */ @@ -1498,7 +1403,7 @@ bool Device_Write_Property( wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; pObject = Device_Objects_Find_Functions(wp_data->object_type); if (pObject != NULL) { - if (pObject->Object_Valid_Instance && + 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); @@ -1515,7 +1420,7 @@ bool Device_Write_Property( wp_data->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; } - return(status); + return (status); } @@ -1537,12 +1442,12 @@ void Device_Init( } bool DeviceGetRRInfo( - BACNET_READ_RANGE_DATA *pRequest, /* Info on the request */ - RR_PROP_INFO *pInfo) /* Where to put the response */ -{ - bool status = false; /* return value */ - - switch(pRequest->object_property) { + BACNET_READ_RANGE_DATA * pRequest, /* Info on the request */ + RR_PROP_INFO * pInfo) +{ /* Where to put the response */ + bool status = false; /* return value */ + + switch (pRequest->object_property) { case PROP_VT_CLASSES_SUPPORTED: case PROP_ACTIVE_VT_SESSIONS: case PROP_LIST_OF_SESSION_KEYS: @@ -1553,7 +1458,7 @@ bool DeviceGetRRInfo( case PROP_UTC_TIME_SYNCHRONIZATION_RECIPIENTS: pInfo->RequestTypes = RR_BY_POSITION; pRequest->error_class = ERROR_CLASS_PROPERTY; - pRequest->error_code = ERROR_CODE_UNKNOWN_PROPERTY; + pRequest->error_code = ERROR_CODE_UNKNOWN_PROPERTY; break; case PROP_DEVICE_ADDRESS_BINDING: @@ -1561,15 +1466,15 @@ bool DeviceGetRRInfo( pInfo->Handler = rr_address_list_encode; status = true; break; - + case PROP_ACTIVE_COV_SUBSCRIPTIONS: pInfo->RequestTypes = RR_BY_POSITION; pRequest->error_class = ERROR_CLASS_PROPERTY; - pRequest->error_code = ERROR_CODE_UNKNOWN_PROPERTY; + pRequest->error_code = ERROR_CODE_UNKNOWN_PROPERTY; break; default: pRequest->error_class = ERROR_CLASS_SERVICES; - pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST; + pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST; break; } diff --git a/bacnet-stack/demo/object/lc.c b/bacnet-stack/demo/object/lc.c index c699b9f2..bbbfecf5 100644 --- a/bacnet-stack/demo/object/lc.c +++ b/bacnet-stack/demo/object/lc.c @@ -199,7 +199,7 @@ void Load_Control_Init( Shed_Duration[i] = 0; Duty_Window[i] = 0; Load_Control_Enable[i] = true; - Full_Duty_Baseline[i] = 1.500; /* kilowatts */ + Full_Duty_Baseline[i] = 1.500; /* kilowatts */ Expected_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL; Expected_Shed_Level[i].value.level = 0; Actual_Shed_Level[i].type = BACNET_SHED_TYPE_LEVEL; @@ -680,7 +680,7 @@ void Load_Control_State_Machine_Handler( /* return apdu len, or -1 on error */ int Load_Control_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -692,8 +692,7 @@ int Load_Control_Read_Property( bool state = false; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -933,7 +932,7 @@ bool Load_Control_Write_Property( unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; - BACNET_DATE TempDate; /* build here in case of error in time half of datetime */ + BACNET_DATE TempDate; /* build here in case of error in time half of datetime */ /* decode the some of the request */ len = @@ -980,23 +979,22 @@ bool Load_Control_Write_Property( break; case PROP_START_TIME: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_DATE, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_DATE, + &wp_data->error_class, &wp_data->error_code); if (!status) { /* don't continue if we don't have a valid date */ break; } /* Hold the date until we are sure the time is also there */ TempDate = value.type.Date; - len = bacapp_decode_application_data(wp_data->application_data + len, + len = + bacapp_decode_application_data(wp_data->application_data + len, wp_data->application_data_len - len, &value); if (len) { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_TIME, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_TIME, + &wp_data->error_class, &wp_data->error_code); if (status) { /* Write time and date and set written flag */ Start_Time[object_index].date = TempDate; @@ -1011,10 +1009,9 @@ bool Load_Control_Write_Property( break; case PROP_SHED_DURATION: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { Shed_Duration[object_index] = value.type.Unsigned_Int; Load_Control_Request_Written[object_index] = true; @@ -1022,10 +1019,9 @@ bool Load_Control_Write_Property( break; case PROP_DUTY_WINDOW: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { Duty_Window[object_index] = value.type.Unsigned_Int; Load_Control_Request_Written[object_index] = true; @@ -1033,10 +1029,9 @@ bool Load_Control_Write_Property( break; case PROP_SHED_LEVELS: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { /* re-write the size of the array? */ if (wp_data->array_index == 0) { @@ -1059,10 +1054,9 @@ bool Load_Control_Write_Property( break; case PROP_ENABLE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { Load_Control_Enable[object_index] = value.type.Boolean; } @@ -1477,7 +1471,7 @@ void testLoadControl( Load_Control_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_LOAD_CONTROL; + rpdata.object_type = OBJECT_LOAD_CONTROL; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -1485,8 +1479,7 @@ void testLoadControl( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/lo.c b/bacnet-stack/demo/object/lo.c index a771df74..a7d1fbff 100644 --- a/bacnet-stack/demo/object/lo.c +++ b/bacnet-stack/demo/object/lo.c @@ -28,7 +28,7 @@ /* WARNING! This object is still BACnet DRAFT status! If you need to implement in a real product, you will need to modify the new OBJECT type and properties to - be in the proprietrary range to be BACnet compliant */ + be in the proprietrary range to be BACnet compliant */ #include #include @@ -152,7 +152,7 @@ int Lighting_Output_Decode_Lighting_Command( apdu_len += len; len = decode_enumerated(&apdu[apdu_len], len_value_type, - (uint32_t *)&data->operation); + (uint32_t *) & data->operation); apdu_len += len; /* Tag 1: level - OPTIONAL */ if (decode_is_context_tag(&apdu[apdu_len], 1)) { @@ -162,7 +162,7 @@ int Lighting_Output_Decode_Lighting_Command( apdu_len += len; len = decode_real(&apdu[apdu_len], &real_value); apdu_len += len; - data->level = (uint8_t)real_value; + data->level = (uint8_t) real_value; /* FIXME: are we going to flag errors in decoding values here? */ } /* FIXME: finish me! */ @@ -359,7 +359,7 @@ char *Lighting_Output_Name( /* return apdu len, or -1 on error */ int Lighting_Output_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -371,8 +371,7 @@ int Lighting_Output_Read_Property( bool state = false; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -398,11 +397,13 @@ int Lighting_Output_Read_Property( OBJECT_LIGHTING_OUTPUT); break; case PROP_PRESENT_VALUE: - real_value = Lighting_Output_Present_Value(rpdata->object_instance); + real_value = + Lighting_Output_Present_Value(rpdata->object_instance); apdu_len = encode_application_real(&apdu[0], real_value); break; case PROP_PROGRESS_VALUE: - real_value = Lighting_Output_Progress_Value(rpdata->object_instance); + real_value = + Lighting_Output_Progress_Value(rpdata->object_instance); apdu_len = encode_application_real(&apdu[0], real_value); break; case PROP_LIGHTING_COMMAND: @@ -423,7 +424,8 @@ int Lighting_Output_Read_Property( encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: - object_index = Lighting_Output_Instance_To_Index(rpdata->object_instance); + object_index = + Lighting_Output_Instance_To_Index(rpdata->object_instance); state = Lighting_Output_Out_Of_Service[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; @@ -465,13 +467,13 @@ 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][rpdata->array_index - - 1]; + Lighting_Output_Level[object_index][rpdata-> + array_index - 1]; apdu_len = encode_application_real(&apdu[0], real_value); } @@ -494,8 +496,7 @@ int Lighting_Output_Read_Property( 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->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -541,18 +542,17 @@ bool Lighting_Output_Write_Property( wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } else { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_NULL, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, + &wp_data->error_class, &wp_data->error_code); 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 @@ -574,14 +574,13 @@ bool Lighting_Output_Write_Property( &Lighting_Command[wp_data->object_instance]); break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &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; } @@ -615,7 +614,7 @@ void testLightingOutput( Lighting_Output_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_LIGHTING_OUTPUT; + rpdata.object_type = OBJECT_LIGHTING_OUTPUT; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -623,8 +622,7 @@ void testLightingOutput( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/lsp.c b/bacnet-stack/demo/object/lsp.c index d731442f..ecb6120c 100644 --- a/bacnet-stack/demo/object/lsp.c +++ b/bacnet-stack/demo/object/lsp.c @@ -188,7 +188,7 @@ char *Life_Safety_Point_Name( /* return apdu len, or -1 on error */ int Life_Safety_Point_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -203,8 +203,7 @@ int Life_Safety_Point_Read_Property( BACNET_RELIABILITY reliability = RELIABILITY_NO_FAULT_DETECTED; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -228,7 +227,8 @@ int Life_Safety_Point_Read_Property( OBJECT_LIFE_SAFETY_POINT); break; case PROP_PRESENT_VALUE: - present_value = Life_Safety_Point_Present_Value(rpdata->object_instance); + present_value = + Life_Safety_Point_Present_Value(rpdata->object_instance); apdu_len = encode_application_enumerated(&apdu[0], present_value); break; case PROP_STATUS_FLAGS: @@ -286,8 +286,7 @@ int Life_Safety_Point_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; @@ -313,15 +312,14 @@ bool Life_Safety_Point_Write_Property( /* FIXME: len == 0: unable to decode? */ switch (wp_data->object_property) { case PROP_MODE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); 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 { @@ -332,14 +330,13 @@ bool Life_Safety_Point_Write_Property( } break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &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; } @@ -373,7 +370,7 @@ void testLifeSafetyPoint( Life_Safety_Point_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_LIFE_SAFETY_POINT; + rpdata.object_type = OBJECT_LIFE_SAFETY_POINT; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -381,8 +378,7 @@ void testLifeSafetyPoint( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/ms-input.c b/bacnet-stack/demo/object/ms-input.c index b405e361..ae88c639 100644 --- a/bacnet-stack/demo/object/ms-input.c +++ b/bacnet-stack/demo/object/ms-input.c @@ -318,7 +318,7 @@ bool Multistate_Input_State_Text_Set( /* return apdu len, or -1 on error */ int Multistate_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -330,8 +330,7 @@ int Multistate_Input_Read_Property( bool state = false; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -362,7 +361,8 @@ int Multistate_Input_Read_Property( OBJECT_MULTI_STATE_INPUT); break; case PROP_PRESENT_VALUE: - present_value = Multistate_Input_Present_Value(rpdata->object_instance); + present_value = + Multistate_Input_Present_Value(rpdata->object_instance); apdu_len = encode_application_unsigned(&apdu[0], present_value); break; case PROP_STATUS_FLAGS: @@ -380,7 +380,8 @@ int Multistate_Input_Read_Property( encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: - object_index = Multistate_Input_Instance_To_Index(rpdata->object_instance); + object_index = + Multistate_Input_Instance_To_Index(rpdata->object_instance); state = Out_Of_Service[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; @@ -399,10 +400,12 @@ 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 = 0; i < MULTISTATE_NUMBER_OF_STATES; i++) { characterstring_init_ansi(&char_string, - Multistate_Input_State_Text(rpdata->object_instance, i)); + Multistate_Input_State_Text(rpdata->object_instance, + i)); /* FIXME: this might go beyond MAX_APDU length! */ len = encode_application_character_string(&apdu[apdu_len], @@ -419,11 +422,12 @@ 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, - rpdata->array_index-1)); + rpdata->array_index - 1)); apdu_len = encode_application_character_string(&apdu[0], &char_string); @@ -441,8 +445,7 @@ int Multistate_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->object_property != PROP_STATE_TEXT) && + if ((apdu_len >= 0) && (rpdata->object_property != PROP_STATE_TEXT) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -469,15 +472,14 @@ bool Multistate_Input_Write_Property( /* FIXME: len == 0: unable to decode? */ switch (wp_data->object_property) { case PROP_PRESENT_VALUE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { if (Out_Of_Service[object_index]) { - status = Multistate_Input_Present_Value_Set( - wp_data->object_instance, - value.type.Unsigned_Int); + status = + 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; @@ -490,14 +492,13 @@ bool Multistate_Input_Write_Property( } break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &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; @@ -530,7 +531,7 @@ void testMultistateInput( Multistate_Input_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_MULTI_STATE_INPUT; + rpdata.object_type = OBJECT_MULTI_STATE_INPUT; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -538,8 +539,7 @@ void testMultistateInput( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/mso.c b/bacnet-stack/demo/object/mso.c index c229cb5d..a6b7e6b8 100644 --- a/bacnet-stack/demo/object/mso.c +++ b/bacnet-stack/demo/object/mso.c @@ -195,7 +195,7 @@ char *Multistate_Output_Name( /* return apdu len, or -1 on error */ int Multistate_Output_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -207,8 +207,7 @@ int Multistate_Output_Read_Property( bool state = false; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -234,7 +233,8 @@ int Multistate_Output_Read_Property( OBJECT_MULTI_STATE_OUTPUT); break; case PROP_PRESENT_VALUE: - present_value = Multistate_Output_Present_Value(rpdata->object_instance); + present_value = + Multistate_Output_Present_Value(rpdata->object_instance); apdu_len = encode_application_unsigned(&apdu[0], present_value); break; case PROP_STATUS_FLAGS: @@ -266,7 +266,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] == @@ -291,15 +292,16 @@ 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) + if (Multistate_Output_Level[object_index][rpdata-> + array_index - 1] == MULTISTATE_NULL) apdu_len = encode_application_null(&apdu[0]); else { present_value = - Multistate_Output_Level[object_index][rpdata->array_index - - 1]; + Multistate_Output_Level[object_index][rpdata-> + array_index - 1]; apdu_len = encode_application_unsigned(&apdu[0], present_value); @@ -329,8 +331,7 @@ int Multistate_Output_Read_Property( 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->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -369,8 +370,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; @@ -391,15 +392,14 @@ bool Multistate_Output_Write_Property( wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } else { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_NULL, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, + &wp_data->error_class, &wp_data->error_code); 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--; @@ -420,14 +420,13 @@ bool Multistate_Output_Write_Property( } break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &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; } @@ -461,7 +460,7 @@ void testMultistateOutput( Multistate_Output_Init(); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); - rpdata.object_type = OBJECT_MULTI_STATE_OUTPUT; + rpdata.object_type = OBJECT_MULTI_STATE_OUTPUT; rpdata.object_instance = 1; rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; @@ -469,8 +468,7 @@ void testMultistateOutput( ct_test(pTest, len != 0); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID); - len = - decode_object_id(&apdu[len], &decoded_type, &decoded_instance); + len = decode_object_id(&apdu[len], &decoded_type, &decoded_instance); ct_test(pTest, decoded_type == rpdata.object_type); ct_test(pTest, decoded_instance == rpdata.object_instance); diff --git a/bacnet-stack/demo/object/trendlog.c b/bacnet-stack/demo/object/trendlog.c index 939590c9..53081e2e 100644 --- a/bacnet-stack/demo/object/trendlog.c +++ b/bacnet-stack/demo/object/trendlog.c @@ -79,7 +79,7 @@ static const int Trend_Log_Properties_Optional[] = { /* Required if COV logging supported PROP_COV_RESUBSCRIPTION_INTERVAL, PROP_CLIENT_COV_INCREMENT, */ - + /* Required if intrinsic reporting supported PROP_NOTIFICATION_THRESHOLD, PROP_RECORDS_SINCE_NOTIFICATION, @@ -89,7 +89,7 @@ static const int Trend_Log_Properties_Optional[] = { PROP_ACKED_TRANSITIONS, PROP_NOTIFY_TYPE, PROP_EVENT_TIME_STAMPS, */ - + PROP_ALIGN_INTERVALS, PROP_INTERVAL_OFFSET, PROP_TRIGGER, @@ -172,12 +172,12 @@ void Trend_Log_Init( int iEntry; struct tm TempTime; time_t tClock; - + if (!initialized) { initialized = true; /* initialize all the values */ - + for (iLog = 0; iLog < MAX_TREND_LOGS; iLog++) { /* * Do we need to do anything here? @@ -190,55 +190,61 @@ void Trend_Log_Init( * entries into any active logs if the power down or reset * may have caused us to miss readings. */ - + /* We will just fill the logs with some entries for testing * purposes. */ TempTime.tm_year = 109; - TempTime.tm_mon = iLog + 1; /* Different month for each log */ + TempTime.tm_mon = iLog + 1; /* Different month for each log */ TempTime.tm_mday = 1; TempTime.tm_hour = 0; - TempTime.tm_min = 0; - TempTime.tm_sec = 0; + TempTime.tm_min = 0; + TempTime.tm_sec = 0; tClock = mktime(&TempTime); - - for(iEntry = 0; iEntry < TL_MAX_ENTRIES; iEntry++) { + + for (iEntry = 0; iEntry < TL_MAX_ENTRIES; iEntry++) { Logs[iLog][iEntry].tTimeStamp = tClock; - Logs[iLog][iEntry].ucRecType = TL_TYPE_REAL; - Logs[iLog][iEntry].Datum.fReal = (float)(iEntry + (iLog * TL_MAX_ENTRIES)); + Logs[iLog][iEntry].ucRecType = TL_TYPE_REAL; + Logs[iLog][iEntry].Datum.fReal = + (float) (iEntry + (iLog * TL_MAX_ENTRIES)); /* Put status flags with every second log */ - if((iLog & 1) == 0) - Logs[iLog][iEntry].ucStatus = 128; + if ((iLog & 1) == 0) + Logs[iLog][iEntry].ucStatus = 128; else - Logs[iLog][iEntry].ucStatus = 0; - tClock += 900; /* advance 15 minutes */ + Logs[iLog][iEntry].ucStatus = 0; + tClock += 900; /* advance 15 minutes */ } - - LogInfo[iLog].tLastDataTime = tClock - 900; - LogInfo[iLog].bAlignIntervals = true; - LogInfo[iLog].bEnable = true; - LogInfo[iLog].bStopWhenFull = false; - LogInfo[iLog].bTrigger = false; - LogInfo[iLog].LoggingType = LOGGING_TYPE_POLLED; - LogInfo[iLog].Source.arrayIndex = 0; - LogInfo[iLog].ucTimeFlags = 0; - LogInfo[iLog].ulIntervalOffset = 0; - LogInfo[iLog].iIndex = 0; - LogInfo[iLog].ulLogInterval = 900; - LogInfo[iLog].ulRecordCount = 1000; - LogInfo[iLog].ulTotalRecordCount = 10000; - - LogInfo[iLog].Source.deviceIndentifier.instance = Device_Object_Instance_Number(); - LogInfo[iLog].Source.deviceIndentifier.type = OBJECT_DEVICE; - LogInfo[iLog].Source.objectIdentifier.instance = iLog; - LogInfo[iLog].Source.objectIdentifier.type = OBJECT_ANALOG_INPUT; - LogInfo[iLog].Source.arrayIndex = BACNET_ARRAY_ALL; - LogInfo[iLog].Source.propertyIdentifier = PROP_PRESENT_VALUE; - - datetime_set_values(&LogInfo[iLog].StartTime, 2009, 1, 1, 0, 0, 0, 0); - LogInfo[iLog].tStartTime = TL_BAC_Time_To_Local(&LogInfo[iLog].StartTime); - datetime_set_values(&LogInfo[iLog].StopTime, 2009, 12, 22, 23, 59, 59, 99); - LogInfo[iLog].tStopTime = TL_BAC_Time_To_Local(&LogInfo[iLog].StopTime); + + LogInfo[iLog].tLastDataTime = tClock - 900; + LogInfo[iLog].bAlignIntervals = true; + LogInfo[iLog].bEnable = true; + LogInfo[iLog].bStopWhenFull = false; + LogInfo[iLog].bTrigger = false; + LogInfo[iLog].LoggingType = LOGGING_TYPE_POLLED; + LogInfo[iLog].Source.arrayIndex = 0; + LogInfo[iLog].ucTimeFlags = 0; + LogInfo[iLog].ulIntervalOffset = 0; + LogInfo[iLog].iIndex = 0; + LogInfo[iLog].ulLogInterval = 900; + LogInfo[iLog].ulRecordCount = 1000; + LogInfo[iLog].ulTotalRecordCount = 10000; + + LogInfo[iLog].Source.deviceIndentifier.instance = + Device_Object_Instance_Number(); + LogInfo[iLog].Source.deviceIndentifier.type = OBJECT_DEVICE; + LogInfo[iLog].Source.objectIdentifier.instance = iLog; + LogInfo[iLog].Source.objectIdentifier.type = OBJECT_ANALOG_INPUT; + LogInfo[iLog].Source.arrayIndex = BACNET_ARRAY_ALL; + LogInfo[iLog].Source.propertyIdentifier = PROP_PRESENT_VALUE; + + datetime_set_values(&LogInfo[iLog].StartTime, 2009, 1, 1, 0, 0, 0, + 0); + LogInfo[iLog].tStartTime = + TL_BAC_Time_To_Local(&LogInfo[iLog].StartTime); + datetime_set_values(&LogInfo[iLog].StopTime, 2009, 12, 22, 23, 59, + 59, 99); + LogInfo[iLog].tStopTime = + TL_BAC_Time_To_Local(&LogInfo[iLog].StopTime); } } @@ -268,7 +274,7 @@ char *Trend_Log_Name( /* return the length of the apdu encoded or -1 for error or -2 for abort message */ int Trend_Log_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ int len = 0; /* apdu len intermediate value */ @@ -277,37 +283,41 @@ int Trend_Log_Read_Property( TL_LOG_INFO *CurrentLog; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } apdu = rpdata->application_data; - CurrentLog = &LogInfo[Trend_Log_Instance_To_Index(rpdata->object_instance)]; /* Pin down which log to look at */ + CurrentLog = &LogInfo[Trend_Log_Instance_To_Index(rpdata->object_instance)]; /* Pin down which log to look at */ switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = + apdu_len = encode_application_object_id(&apdu[0], OBJECT_TRENDLOG, rpdata->object_instance); break; - + case PROP_DESCRIPTION: case PROP_OBJECT_NAME: - characterstring_init_ansi(&char_string, Trend_Log_Name(rpdata->object_instance)); + characterstring_init_ansi(&char_string, + Trend_Log_Name(rpdata->object_instance)); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; - + case PROP_OBJECT_TYPE: - apdu_len = encode_application_enumerated(&apdu[0], OBJECT_TRENDLOG); + apdu_len = + encode_application_enumerated(&apdu[0], OBJECT_TRENDLOG); break; case PROP_ENABLE: - apdu_len = encode_application_boolean(&apdu[0], CurrentLog->bEnable); + apdu_len = + encode_application_boolean(&apdu[0], CurrentLog->bEnable); break; - + case PROP_STOP_WHEN_FULL: - apdu_len = encode_application_boolean(&apdu[0], CurrentLog->bStopWhenFull); + apdu_len = + encode_application_boolean(&apdu[0], + CurrentLog->bStopWhenFull); break; case PROP_BUFFER_SIZE: @@ -322,20 +332,27 @@ int Trend_Log_Read_Property( break; case PROP_RECORD_COUNT: - apdu_len += encode_application_unsigned(&apdu[0], CurrentLog->ulRecordCount); + apdu_len += + encode_application_unsigned(&apdu[0], + CurrentLog->ulRecordCount); break; case PROP_TOTAL_RECORD_COUNT: - apdu_len += encode_application_unsigned(&apdu[0], CurrentLog->ulTotalRecordCount); + apdu_len += + encode_application_unsigned(&apdu[0], + CurrentLog->ulTotalRecordCount); break; case PROP_EVENT_STATE: /* note: see the details in the standard on how to use this */ - apdu_len = encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); + apdu_len = + encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_LOGGING_TYPE: - apdu_len = encode_application_enumerated(&apdu[0], CurrentLog->LoggingType); + apdu_len = + encode_application_enumerated(&apdu[0], + CurrentLog->LoggingType); break; case PROP_STATUS_FLAGS: @@ -344,24 +361,26 @@ int Trend_Log_Read_Property( bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); 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,false); + bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_START_TIME: - len = encode_application_date(&apdu[0], - &CurrentLog->StartTime.date); + len = + encode_application_date(&apdu[0], &CurrentLog->StartTime.date); apdu_len = len; - len = encode_application_time(&apdu[apdu_len], + len = + encode_application_time(&apdu[apdu_len], &CurrentLog->StartTime.time); apdu_len += len; break; case PROP_STOP_TIME: - len = encode_application_date(&apdu[0], - &CurrentLog->StopTime.date); + len = + encode_application_date(&apdu[0], &CurrentLog->StopTime.date); apdu_len = len; - len = encode_application_time(&apdu[apdu_len], + len = + encode_application_time(&apdu[apdu_len], &CurrentLog->StopTime.time); apdu_len += len; break; @@ -377,27 +396,36 @@ int Trend_Log_Read_Property( * deviceIdentifier [3] BACnetObjectIdentifier OPTIONAL * } */ - apdu_len += bacapp_encode_device_obj_property_ref(&apdu[0], &CurrentLog->Source); + apdu_len += + bacapp_encode_device_obj_property_ref(&apdu[0], + &CurrentLog->Source); break; case PROP_LOG_INTERVAL: /* We only log to 1 sec accuracy so must multiply by 100 before passing it on */ - apdu_len += encode_application_unsigned(&apdu[0], CurrentLog->ulLogInterval * 100); + apdu_len += + encode_application_unsigned(&apdu[0], + CurrentLog->ulLogInterval * 100); break; case PROP_ALIGN_INTERVALS: - apdu_len = encode_application_boolean(&apdu[0], CurrentLog->bAlignIntervals); + apdu_len = + encode_application_boolean(&apdu[0], + CurrentLog->bAlignIntervals); break; - + case PROP_INTERVAL_OFFSET: /* We only log to 1 sec accuracy so must multiply by 100 before passing it on */ - apdu_len += encode_application_unsigned(&apdu[0], CurrentLog->ulIntervalOffset * 100); + apdu_len += + encode_application_unsigned(&apdu[0], + CurrentLog->ulIntervalOffset * 100); break; - + case PROP_TRIGGER: - apdu_len = encode_application_boolean(&apdu[0], CurrentLog->bTrigger); + apdu_len = + encode_application_boolean(&apdu[0], CurrentLog->bTrigger); break; - + default: rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; @@ -405,9 +433,8 @@ int Trend_Log_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; apdu_len = -1; @@ -425,14 +452,14 @@ bool Trend_Log_Write_Property( int iOffset = 0; BACNET_APPLICATION_DATA_VALUE value; TL_LOG_INFO *CurrentLog; - BACNET_DATE TempDate; /* build here in case of error in time half of datetime */ + BACNET_DATE TempDate; /* build here in case of error in time half of datetime */ BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE TempSource; bool bEffectiveEnable; int log_index; - + /* Pin down which log to look at */ - log_index = Trend_Log_Instance_To_Index(wp_data->object_instance); - CurrentLog = &LogInfo[log_index]; + log_index = Trend_Log_Instance_To_Index(wp_data->object_instance); + CurrentLog = &LogInfo[log_index]; /* decode the some of the request */ len = @@ -443,40 +470,39 @@ bool Trend_Log_Write_Property( switch (wp_data->object_property) { case PROP_ENABLE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { /* Section 12.25.5 can't enable a full log with stop when full set */ - if((CurrentLog->bEnable == false) && - (CurrentLog->bStopWhenFull == true) && - (CurrentLog->ulRecordCount == TL_MAX_ENTRIES) && - (value.type.Boolean == true)) { + if ((CurrentLog->bEnable == false) && + (CurrentLog->bStopWhenFull == true) && + (CurrentLog->ulRecordCount == TL_MAX_ENTRIES) && + (value.type.Boolean == true)) { status = false; wp_data->error_class = ERROR_CLASS_OBJECT; wp_data->error_code = ERROR_CODE_LOG_BUFFER_FULL; break; } - + /* Only trigger this validation on a potential change of state */ - if(CurrentLog->bEnable != value.type.Boolean) { + if (CurrentLog->bEnable != value.type.Boolean) { bEffectiveEnable = TL_Is_Enabled(log_index); CurrentLog->bEnable = value.type.Boolean; /* To do: what actions do we need to take on writing ? */ - if(value.type.Boolean == false) { - if(bEffectiveEnable == true) { + if (value.type.Boolean == false) { + if (bEffectiveEnable == true) { /* Only insert record if we really were - enabled i.e. times and enable flags */ - TL_Insert_Status_Rec(log_index, + enabled i.e. times and enable flags */ + TL_Insert_Status_Rec(log_index, LOG_STATUS_LOG_DISABLED, true); } } else { - if(TL_Is_Enabled(log_index)) { + if (TL_Is_Enabled(log_index)) { /* Have really gone from disabled to enabled as * enable flag and times were correct */ - TL_Insert_Status_Rec(log_index, + TL_Insert_Status_Rec(log_index, LOG_STATUS_LOG_DISABLED, false); } } @@ -485,26 +511,26 @@ bool Trend_Log_Write_Property( break; case PROP_STOP_WHEN_FULL: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { /* Only trigger this on a change of state */ - if(CurrentLog->bStopWhenFull != value.type.Boolean) { + if (CurrentLog->bStopWhenFull != value.type.Boolean) { CurrentLog->bStopWhenFull = value.type.Boolean; - - if((value.type.Boolean == true) && - (CurrentLog->ulRecordCount == TL_MAX_ENTRIES) && - (CurrentLog->bEnable == true)) { - + + if ((value.type.Boolean == true) && + (CurrentLog->ulRecordCount == TL_MAX_ENTRIES) && + (CurrentLog->bEnable == true)) { + /* When full log is switched from normal to stop when full * disable the log and record the fact - see 135-2008 12.25.12 */ CurrentLog->bEnable = false; - TL_Insert_Status_Rec(log_index, LOG_STATUS_LOG_DISABLED, true); + TL_Insert_Status_Rec(log_index, + LOG_STATUS_LOG_DISABLED, true); } - } + } } break; @@ -518,16 +544,16 @@ bool Trend_Log_Write_Property( break; case PROP_RECORD_COUNT: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { - if(value.type.Unsigned_Int == 0) { + if (value.type.Unsigned_Int == 0) { /* Time to clear down the log */ CurrentLog->ulRecordCount = 0; CurrentLog->iIndex = 0; - TL_Insert_Status_Rec(log_index, LOG_STATUS_BUFFER_PURGED, true); + TL_Insert_Status_Rec(log_index, LOG_STATUS_BUFFER_PURGED, + true); } } break; @@ -536,20 +562,19 @@ bool Trend_Log_Write_Property( /* logic * triggered and polled options. */ - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); if (status) { - if(value.type.Enumerated != LOGGING_TYPE_COV) { + if (value.type.Enumerated != LOGGING_TYPE_COV) { CurrentLog->LoggingType = value.type.Enumerated; - if(value.type.Enumerated == LOGGING_TYPE_POLLED) { + if (value.type.Enumerated == LOGGING_TYPE_POLLED) { /* As per 12.25.27 pick a suitable default if interval is 0 */ - if(CurrentLog->ulLogInterval == 0) { + if (CurrentLog->ulLogInterval == 0) { CurrentLog->ulLogInterval = 900; } } - if(value.type.Enumerated == LOGGING_TYPE_TRIGGERED) { + if (value.type.Enumerated == LOGGING_TYPE_TRIGGERED) { /* As per 12.25.27 0 the interval if triggered logging selected */ CurrentLog->ulLogInterval = 0; } @@ -557,88 +582,90 @@ bool Trend_Log_Write_Property( /* We don't currently support COV */ status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; - } + wp_data->error_code = + ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; + } } break; case PROP_START_TIME: /* Copy the date part to safe place */ - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_DATE, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_DATE, + &wp_data->error_class, &wp_data->error_code); if (!status) { break; } TempDate = value.type.Date; /* Then decode the time part */ - len = bacapp_decode_application_data(wp_data->application_data + len, + len = + bacapp_decode_application_data(wp_data->application_data + len, wp_data->application_data_len - len, &value); - + if (len) { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_TIME, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_TIME, + &wp_data->error_class, &wp_data->error_code); if (!status) { break; } /* First record the current enable state of the log */ bEffectiveEnable = TL_Is_Enabled(log_index); - CurrentLog->StartTime.date = TempDate; /* Safe to copy the date now */ + CurrentLog->StartTime.date = TempDate; /* Safe to copy the date now */ CurrentLog->StartTime.time = value.type.Time; - + if (datetime_wildcard_present(&CurrentLog->StartTime)) { /* Mark start time as wild carded */ CurrentLog->ucTimeFlags |= TL_T_START_WILD; - CurrentLog->tStartTime = 0; + CurrentLog->tStartTime = 0; } else { /* Clear wild card flag and set time in local format */ CurrentLog->ucTimeFlags &= ~TL_T_START_WILD; - CurrentLog->tStartTime = TL_BAC_Time_To_Local(&CurrentLog->StartTime); + CurrentLog->tStartTime = + TL_BAC_Time_To_Local(&CurrentLog->StartTime); } - - if(bEffectiveEnable != TL_Is_Enabled(log_index)) { + + if (bEffectiveEnable != TL_Is_Enabled(log_index)) { /* Enable status has changed because of time update */ - if(bEffectiveEnable == true) { + if (bEffectiveEnable == true) { /* Say we went from enabled to disabled */ - TL_Insert_Status_Rec(log_index, LOG_STATUS_LOG_DISABLED, true); + TL_Insert_Status_Rec(log_index, + LOG_STATUS_LOG_DISABLED, true); } else { /* Say we went from disabled to enabled */ - TL_Insert_Status_Rec(log_index, LOG_STATUS_LOG_DISABLED, false); + TL_Insert_Status_Rec(log_index, + LOG_STATUS_LOG_DISABLED, false); } - } + } } break; case PROP_STOP_TIME: /* Copy the date part to safe place */ - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_DATE, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_DATE, + &wp_data->error_class, &wp_data->error_code); if (!status) { break; } TempDate = value.type.Date; /* Then decode the time part */ - len = bacapp_decode_application_data(wp_data->application_data + len, + len = + bacapp_decode_application_data(wp_data->application_data + len, wp_data->application_data_len - len, &value); - + if (len) { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_TIME, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_TIME, + &wp_data->error_class, &wp_data->error_code); if (!status) { break; } /* First record the current enable state of the log */ bEffectiveEnable = TL_Is_Enabled(log_index); - CurrentLog->StopTime.date = TempDate; /* Safe to copy the date now */ + CurrentLog->StopTime.date = TempDate; /* Safe to copy the date now */ CurrentLog->StopTime.time = value.type.Time; - + if (datetime_wildcard_present(&CurrentLog->StopTime)) { /* Mark stop time as wild carded */ CurrentLog->ucTimeFlags |= TL_T_STOP_WILD; @@ -646,122 +673,145 @@ bool Trend_Log_Write_Property( } else { /* Clear wild card flag and set time in local format */ CurrentLog->ucTimeFlags &= ~TL_T_STOP_WILD; - CurrentLog->tStopTime = TL_BAC_Time_To_Local(&CurrentLog->StopTime); + CurrentLog->tStopTime = + TL_BAC_Time_To_Local(&CurrentLog->StopTime); } - - if(bEffectiveEnable != TL_Is_Enabled(log_index)) { + + if (bEffectiveEnable != TL_Is_Enabled(log_index)) { /* Enable status has changed because of time update */ - if(bEffectiveEnable == true) { + if (bEffectiveEnable == true) { /* Say we went from enabled to disabled */ - TL_Insert_Status_Rec(log_index, LOG_STATUS_LOG_DISABLED, true); + TL_Insert_Status_Rec(log_index, + LOG_STATUS_LOG_DISABLED, true); } else { /* Say we went from disabled to enabled */ - TL_Insert_Status_Rec(log_index, LOG_STATUS_LOG_DISABLED, false); + TL_Insert_Status_Rec(log_index, + LOG_STATUS_LOG_DISABLED, false); } - } + } } break; case PROP_LOG_DEVICE_OBJECT_PROPERTY: memset(&TempSource, 0, sizeof(TempSource)); /* Start with clean sheet */ TempSource.arrayIndex = BACNET_ARRAY_ALL; /* Need this so if no array index set we read properties in full */ - + /* First up is the object ID */ - len = bacapp_decode_context_data(wp_data->application_data, wp_data->application_data_len, &value, PROP_LOG_DEVICE_OBJECT_PROPERTY); - if((len == 0) || (value.context_tag != 0) || ((wp_data->application_data_len - len) == 0)) { - /* Bad decode, wrong tag or following required parameter missing */ + len = + bacapp_decode_context_data(wp_data->application_data, + wp_data->application_data_len, &value, + PROP_LOG_DEVICE_OBJECT_PROPERTY); + if ((len == 0) || (value.context_tag != 0) || + ((wp_data->application_data_len - len) == 0)) { + /* Bad decode, wrong tag or following required parameter missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_OTHER; break; } - + TempSource.objectIdentifier = value.type.Object_Id; wp_data->application_data_len -= len; iOffset = len; /* Second up is the property id */ - len = 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 != 1)) { - /* Bad decode or wrong tag */ + len = + 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 != 1)) { + /* Bad decode or wrong tag */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_OTHER; break; } - - TempSource.propertyIdentifier = value.type.Enumerated; + + TempSource.propertyIdentifier = value.type.Enumerated; wp_data->application_data_len -= len; - + /* If there is still more to come */ - if(wp_data->application_data_len != 0) { + 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); - if((len == 0) || ((value.context_tag != 2) && (value.context_tag != 3))) { - /* Bad decode or wrong tag */ + len = + 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 */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_OTHER; break; } - if(value.context_tag == 2) { + if (value.context_tag == 2) { /* Got an index so deal with it */ TempSource.arrayIndex = value.type.Unsigned_Int; wp_data->application_data_len -= len; /* Still some remaining so fetch potential device ID */ - if(wp_data->application_data_len != 0) { + 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); - if((len == 0) || (value.context_tag != 3)) { - /* Bad decode or wrong tag */ + len = + 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)) { + /* Bad decode or wrong tag */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_OTHER; break; } } } - - if(value.context_tag == 3) { + + if (value.context_tag == 3) { /* Got a device ID so deal with it */ TempSource.deviceIndentifier = value.type.Object_Id; - if((TempSource.deviceIndentifier.instance != Device_Object_Instance_Number()) || - (TempSource.deviceIndentifier.type != OBJECT_DEVICE)) { - /* Not our ID so can't handle it at the moment */ - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; + if ((TempSource.deviceIndentifier.instance != + Device_Object_Instance_Number()) || + (TempSource.deviceIndentifier.type != OBJECT_DEVICE)) { + /* Not our ID so can't handle it at the moment */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = + ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; break; } - } + } } /* Make sure device ID is set to ours in case not supplied */ - TempSource.deviceIndentifier.type = OBJECT_DEVICE; - TempSource.deviceIndentifier.instance = Device_Object_Instance_Number(); + TempSource.deviceIndentifier.type = OBJECT_DEVICE; + TempSource.deviceIndentifier.instance = + Device_Object_Instance_Number(); /* Quick comparison if structures are packed ... */ - if(memcmp(&TempSource, &CurrentLog->Source, sizeof(BACNET_OBJECT_ID)) != 0) { + if (memcmp(&TempSource, &CurrentLog->Source, + sizeof(BACNET_OBJECT_ID)) != 0) { /* Clear buffer if property being logged is changed */ CurrentLog->ulRecordCount = 0; CurrentLog->iIndex = 0; - TL_Insert_Status_Rec(log_index, LOG_STATUS_BUFFER_PURGED, true); + TL_Insert_Status_Rec(log_index, LOG_STATUS_BUFFER_PURGED, + true); } - CurrentLog->Source = TempSource; + CurrentLog->Source = TempSource; status = true; break; case PROP_LOG_INTERVAL: - if(CurrentLog->LoggingType == LOGGING_TYPE_TRIGGERED) { + if (CurrentLog->LoggingType == LOGGING_TYPE_TRIGGERED) { /* Read only if triggered log so flag error and bail out */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; break; } - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { - if((CurrentLog->LoggingType == LOGGING_TYPE_POLLED) && + if ((CurrentLog->LoggingType == LOGGING_TYPE_POLLED) && (value.type.Unsigned_Int == 0)) { /* We don't support COV at the moment so don't allow switching * to it by clearing interval whilst in polling mode */ wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; + wp_data->error_code = + ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; status = false; } else { /* We only log to 1 sec accuracy so must divide by 100 before passing it on */ @@ -771,40 +821,38 @@ bool Trend_Log_Write_Property( break; case PROP_ALIGN_INTERVALS: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentLog->bAlignIntervals = value.type.Boolean; } break; - + case PROP_INTERVAL_OFFSET: /* We only log to 1 sec accuracy so must divide by 100 before passing it on */ - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentLog->ulIntervalOffset = value.type.Unsigned_Int / 100; } break; - + case PROP_TRIGGER: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { /* We will not allow triggered operation if polling with aligning * to the clock as that will produce non aligned readings which * goes against the reason for selscting this mode */ - if((CurrentLog->LoggingType == LOGGING_TYPE_POLLED) && - (CurrentLog->bAlignIntervals == true)) { + if ((CurrentLog->LoggingType == LOGGING_TYPE_POLLED) && + (CurrentLog->bAlignIntervals == true)) { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_NOT_CONFIGURED_FOR_TRIGGERED_LOGGING; + wp_data->error_code = + ERROR_CODE_NOT_CONFIGURED_FOR_TRIGGERED_LOGGING; status = false; } else { CurrentLog->bTrigger = value.type.Boolean; @@ -822,25 +870,25 @@ bool Trend_Log_Write_Property( } bool TrendLogGetRRInfo( - BACNET_READ_RANGE_DATA *pRequest, /* Info on the request */ - RR_PROP_INFO *pInfo) /* Where to put the information */ -{ + BACNET_READ_RANGE_DATA * pRequest, /* Info on the request */ + RR_PROP_INFO * pInfo) +{ /* Where to put the information */ int log_index; log_index = Trend_Log_Instance_To_Index(pRequest->object_instance); - if(log_index >= MAX_TREND_LOGS) { + if (log_index >= MAX_TREND_LOGS) { pRequest->error_class = ERROR_CLASS_OBJECT; - pRequest->error_code = ERROR_CODE_UNKNOWN_OBJECT; - } else if(pRequest->object_property == PROP_LOG_BUFFER) { + pRequest->error_code = ERROR_CODE_UNKNOWN_OBJECT; + } else if (pRequest->object_property == PROP_LOG_BUFFER) { pInfo->RequestTypes = RR_BY_POSITION | RR_BY_TIME | RR_BY_SEQUENCE; pInfo->Handler = rr_trend_log_encode; - return(true); + return (true); } else { pRequest->error_class = ERROR_CLASS_SERVICES; - pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST; + pRequest->error_code = ERROR_CODE_PROPERTY_IS_NOT_A_LIST; } - return(false); + return (false); } /***************************************************************************** @@ -850,27 +898,29 @@ bool TrendLogGetRRInfo( * pushed out of the log to make room. * *****************************************************************************/ -void TL_Insert_Status_Rec(int iLog, BACNET_LOG_STATUS eStatus, bool bState) - +void TL_Insert_Status_Rec( + int iLog, + BACNET_LOG_STATUS eStatus, + bool bState) { TL_LOG_INFO *CurrentLog; - TL_DATA_REC TempRec; - + TL_DATA_REC TempRec; + CurrentLog = &LogInfo[iLog]; - + TempRec.tTimeStamp = time(NULL); - TempRec.ucRecType = TL_TYPE_STATUS; - TempRec.ucStatus = 0; + TempRec.ucRecType = TL_TYPE_STATUS; + TempRec.ucStatus = 0; TempRec.Datum.ucLogStatus = 0; /* Note we set the bits in correct order so that we can place them directly * into the bitstring structure later on when we have to encode them */ - switch(eStatus) { + switch (eStatus) { case LOG_STATUS_LOG_DISABLED: - if(bState) + if (bState) TempRec.Datum.ucLogStatus = 1 << LOG_STATUS_LOG_DISABLED; break; case LOG_STATUS_BUFFER_PURGED: - if(bState) + if (bState) TempRec.Datum.ucLogStatus = 1 << LOG_STATUS_BUFFER_PURGED; break; case LOG_STATUS_LOG_INTERRUPTED: @@ -879,14 +929,14 @@ void TL_Insert_Status_Rec(int iLog, BACNET_LOG_STATUS eStatus, bool bState) default: break; } - + Logs[iLog][CurrentLog->iIndex++] = TempRec; - if(CurrentLog->iIndex >= TL_MAX_ENTRIES) + if (CurrentLog->iIndex >= TL_MAX_ENTRIES) CurrentLog->iIndex = 0; - + CurrentLog->ulTotalRecordCount++; - if(CurrentLog->ulRecordCount < TL_MAX_ENTRIES) + if (CurrentLog->ulRecordCount < TL_MAX_ENTRIES) CurrentLog->ulRecordCount++; } @@ -895,103 +945,118 @@ void TL_Insert_Status_Rec(int iLog, BACNET_LOG_STATUS eStatus, bool bState) * if the log is really enabled now. See 135-2008 sections 12.25.5 - 12.25.7 * *****************************************************************************/ -bool TL_Is_Enabled(int iLog) +bool TL_Is_Enabled( + int iLog) { TL_LOG_INFO *CurrentLog; time_t tNow; bool bStatus; - + bStatus = true; CurrentLog = &LogInfo[iLog]; #if 0 - printf("\nFlags - %u, Start - %u, Stop - %u\n", (unsigned int)CurrentLog->ucTimeFlags,(unsigned int)CurrentLog->tStartTime, (unsigned int)CurrentLog->tStopTime); + printf("\nFlags - %u, Start - %u, Stop - %u\n", + (unsigned int) CurrentLog->ucTimeFlags, + (unsigned int) CurrentLog->tStartTime, + (unsigned int) CurrentLog->tStopTime); #endif - if(CurrentLog->bEnable == false) { + if (CurrentLog->bEnable == false) { /* Not enabled so time is irrelevant */ bStatus = false; - } else if((CurrentLog->ucTimeFlags == 0) && (CurrentLog->tStopTime < CurrentLog->tStartTime)) { + } else if ((CurrentLog->ucTimeFlags == 0) && + (CurrentLog->tStopTime < CurrentLog->tStartTime)) { /* Start time was after stop time as per 12.25.6 and 12.25.7 */ bStatus = false; - } else if(CurrentLog->ucTimeFlags != (TL_T_START_WILD | TL_T_STOP_WILD)) { + } else if (CurrentLog->ucTimeFlags != (TL_T_START_WILD | TL_T_STOP_WILD)) { /* enabled and either 1 wild card or none */ tNow = time(NULL); #if 0 - printf("\nFlags - %u, Current - %u, Start - %u, Stop - %u\n", (unsigned int)CurrentLog->ucTimeFlags,(unsigned int)Now, (unsigned int)CurrentLog->tStartTime, (unsigned int)CurrentLog->tStopTime); + printf("\nFlags - %u, Current - %u, Start - %u, Stop - %u\n", + (unsigned int) CurrentLog->ucTimeFlags, (unsigned int) Now, + (unsigned int) CurrentLog->tStartTime, + (unsigned int) CurrentLog->tStopTime); #endif - if((CurrentLog->ucTimeFlags & TL_T_START_WILD) != 0) { + if ((CurrentLog->ucTimeFlags & TL_T_START_WILD) != 0) { /* wild card start time */ - if(tNow > CurrentLog->tStopTime) + if (tNow > CurrentLog->tStopTime) bStatus = false; - } else if((CurrentLog->ucTimeFlags & TL_T_STOP_WILD) != 0) { + } else if ((CurrentLog->ucTimeFlags & TL_T_STOP_WILD) != 0) { /* wild card stop time */ - if(tNow < CurrentLog->tStartTime) + if (tNow < CurrentLog->tStartTime) bStatus = false; } else { #if 0 - printf("\nCurrent - %u, Start - %u, Stop - %u\n", (unsigned int)Now, (unsigned int)CurrentLog->tStartTime, (unsigned int)CurrentLog->tStopTime); + printf("\nCurrent - %u, Start - %u, Stop - %u\n", + (unsigned int) Now, (unsigned int) CurrentLog->tStartTime, + (unsigned int) CurrentLog->tStopTime); #endif /* No wildcards so use both times */ - if((tNow < CurrentLog->tStartTime) || (tNow > CurrentLog->tStopTime)) - bStatus = false; + if ((tNow < CurrentLog->tStartTime) || + (tNow > CurrentLog->tStopTime)) + bStatus = false; } } - - return(bStatus); + + return (bStatus); } /***************************************************************************** * Convert a BACnet time into a local time in seconds since the local epoch * *****************************************************************************/ -time_t TL_BAC_Time_To_Local(BACNET_DATE_TIME *SourceTime) +time_t TL_BAC_Time_To_Local( + BACNET_DATE_TIME * SourceTime) { struct tm LocalTime; int iTemp; - LocalTime.tm_year = SourceTime->date.year - 1900; /* We store BACnet year in full format */ + LocalTime.tm_year = SourceTime->date.year - 1900; /* We store BACnet year in full format */ /* Some clients send a date of all 0s to indicate start of epoch * even though this is not a valid date. Pick this up here and * correct the day and month for the local time functions. */ - iTemp = SourceTime->date.year + SourceTime->date.month +SourceTime->date.day; - if(iTemp == 1900) { - LocalTime.tm_mon = 0; - LocalTime.tm_mday = 1; - } else { - LocalTime.tm_mon = SourceTime->date.month - 1; + iTemp = + SourceTime->date.year + SourceTime->date.month + SourceTime->date.day; + if (iTemp == 1900) { + LocalTime.tm_mon = 0; + LocalTime.tm_mday = 1; + } else { + LocalTime.tm_mon = SourceTime->date.month - 1; LocalTime.tm_mday = SourceTime->date.day; - } + } LocalTime.tm_hour = SourceTime->time.hour; - LocalTime.tm_min = SourceTime->time.min; - LocalTime.tm_sec = SourceTime->time.sec; - - return(mktime(&LocalTime)); + LocalTime.tm_min = SourceTime->time.min; + LocalTime.tm_sec = SourceTime->time.sec; + + return (mktime(&LocalTime)); } /***************************************************************************** * Convert a local time in seconds since the local epoch into a BACnet time * *****************************************************************************/ -void TL_Local_Time_To_BAC(BACNET_DATE_TIME *DestTime, time_t SourceTime) +void TL_Local_Time_To_BAC( + BACNET_DATE_TIME * DestTime, + time_t SourceTime) { struct tm *TempTime; - + TempTime = localtime(&SourceTime); - - DestTime->date.year = TempTime->tm_year + 1900; + + DestTime->date.year = TempTime->tm_year + 1900; DestTime->date.month = TempTime->tm_mon + 1; - DestTime->date.day = TempTime->tm_mday; + DestTime->date.day = TempTime->tm_mday; /* BACnet is 1 to 7 = Monday to Sunday * Windows is days from Sunday 0 - 6 so we * have to adjust */ - if(TempTime->tm_wday == 0) + if (TempTime->tm_wday == 0) DestTime->date.wday = 7; else - DestTime->date.wday = TempTime->tm_wday; - DestTime->time.hour = TempTime->tm_hour; - DestTime->time.min = TempTime->tm_min; - DestTime->time.sec = TempTime->tm_sec; + DestTime->date.wday = TempTime->tm_wday; + DestTime->time.hour = TempTime->tm_hour; + DestTime->time.min = TempTime->tm_min; + DestTime->time.sec = TempTime->tm_sec; DestTime->time.hundredths = 0; } @@ -1014,29 +1079,31 @@ void TL_Local_Time_To_BAC(BACNET_DATE_TIME *DestTime, time_t SourceTime) * + 3 bytes for the status flags + 4 for the context tags to give 23. * ****************************************************************************/ -#define TL_MAX_ENC 23 /* Maximum size of encoded log entry, see above */ +#define TL_MAX_ENC 23 /* Maximum size of encoded log entry, see above */ int rr_trend_log_encode( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest) + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest) { /* Initialise result flags to all false */ bitstring_init(&pRequest->ResultFlags); bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, false); - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, false); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, false); bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, false); - pRequest->ItemCount = 0; /* Start out with nothing */ + 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) - return(0); + /* 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) + return (0); - if((pRequest->RequestType == RR_BY_POSITION) || (pRequest->RequestType == RR_READ_ALL)) - return(TL_encode_by_position(apdu, pRequest)); - else if(pRequest->RequestType == RR_BY_SEQUENCE) - return(TL_encode_by_sequence(apdu, pRequest)); + if ((pRequest->RequestType == RR_BY_POSITION) || + (pRequest->RequestType == RR_READ_ALL)) + return (TL_encode_by_position(apdu, pRequest)); + else if (pRequest->RequestType == RR_BY_SEQUENCE) + return (TL_encode_by_sequence(apdu, pRequest)); - return(TL_encode_by_time(apdu, pRequest)); + return (TL_encode_by_time(apdu, pRequest)); } /**************************************************************************** @@ -1044,37 +1111,37 @@ int rr_trend_log_encode( * Does All option by converting to a By Position request starting at index * * 1 and of maximum log size length. * ****************************************************************************/ - + int TL_encode_by_position( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest) + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest) { int log_index = 0; int iLen = 0; int32_t iTemp = 0; TL_LOG_INFO *CurrentLog = NULL; - uint32_t uiIndex = 0; /* Current entry number */ - uint32_t uiFirst = 0; /* Entry number we started encoding from */ - uint32_t uiLast = 0; /* Entry number we finished encoding on */ - uint32_t uiTarget = 0; /* Last entry we are required to encode */ - uint32_t uiRemaining = 0; /* Amount of unused space in packet */ - + uint32_t uiIndex = 0; /* Current entry number */ + uint32_t uiFirst = 0; /* Entry number we started encoding from */ + uint32_t uiLast = 0; /* Entry number we finished encoding on */ + uint32_t uiTarget = 0; /* Last entry we are required to encode */ + uint32_t uiRemaining = 0; /* Amount of unused space in packet */ + /* See how much space we have */ - uiRemaining = MAX_APDU - pRequest->Overhead; + uiRemaining = MAX_APDU - pRequest->Overhead; log_index = Trend_Log_Instance_To_Index(pRequest->object_instance); CurrentLog = &LogInfo[log_index]; - if(pRequest->RequestType == RR_READ_ALL) { + if (pRequest->RequestType == RR_READ_ALL) { /* * Read all the list or as much as will fit in the buffer by selecting * a range that covers the whole list and falling through to the next * section of code */ - pRequest->Count = CurrentLog->ulRecordCount; /* Full list */ - pRequest->Range.RefIndex = 1; /* Starting at the beginning */ + pRequest->Count = CurrentLog->ulRecordCount; /* Full list */ + pRequest->Range.RefIndex = 1; /* Starting at the beginning */ } - if(pRequest->Count < 0) { /* negative count means work from index backwards */ + if (pRequest->Count < 0) { /* negative count means work from index backwards */ /* * Convert from end index/negative count to * start index/positive count and then process as @@ -1087,57 +1154,58 @@ int TL_encode_by_position( * try to optimise the code unless you understand all the * implications of the data type conversions! */ - - iTemp = pRequest->Range.RefIndex; /* pull out and convert to signed */ - iTemp += pRequest->Count + 1; /* Adjust backwards, remember count is -ve */ - if(iTemp < 1) { /* if count is too much, return from 1 to start index */ + + iTemp = pRequest->Range.RefIndex; /* pull out and convert to signed */ + iTemp += pRequest->Count + 1; /* Adjust backwards, remember count is -ve */ + if (iTemp < 1) { /* if count is too much, return from 1 to start index */ pRequest->Count = pRequest->Range.RefIndex; pRequest->Range.RefIndex = 1; - } - else { /* Otherwise adjust the start index and make count +ve */ + } else { /* Otherwise adjust the start index and make count +ve */ pRequest->Range.RefIndex = iTemp; pRequest->Count = -pRequest->Count; } } - + /* From here on in we only have a starting point and a positive count */ - - if(pRequest->Range.RefIndex > CurrentLog->ulRecordCount) /* Nothing to return as we are past the end of the list */ - return(0); - - uiTarget = pRequest->Range.RefIndex + pRequest->Count - 1; /* Index of last required entry */ - if(uiTarget > CurrentLog->ulRecordCount) /* Capped at end of list if necessary */ + + if (pRequest->Range.RefIndex > CurrentLog->ulRecordCount) /* Nothing to return as we are past the end of the list */ + return (0); + + uiTarget = pRequest->Range.RefIndex + pRequest->Count - 1; /* Index of last required entry */ + if (uiTarget > CurrentLog->ulRecordCount) /* Capped at end of list if necessary */ uiTarget = CurrentLog->ulRecordCount; - + uiIndex = pRequest->Range.RefIndex; - uiFirst = uiIndex; /* Record where we started from */ - while(uiIndex <= uiTarget) { - if(uiRemaining < TL_MAX_ENC) { + uiFirst = uiIndex; /* Record where we started from */ + while (uiIndex <= uiTarget) { + if (uiRemaining < TL_MAX_ENC) { /* * Can't fit any more in! We just set the result flag to say there * was more and drop out of the loop early */ - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, true); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, + true); break; - } - - iTemp = TL_encode_entry(&apdu[iLen], log_index, uiIndex); - - uiRemaining -= iTemp; /* Reduce the remaining space */ - iLen += iTemp; /* and increase the length consumed */ + } + + iTemp = TL_encode_entry(&apdu[iLen], log_index, uiIndex); + + uiRemaining -= iTemp; /* Reduce the remaining space */ + iLen += iTemp; /* and increase the length consumed */ uiLast = uiIndex; /* Record the last entry encoded */ - uiIndex++; /* and get ready for next one */ + uiIndex++; /* and get ready for next one */ pRequest->ItemCount++; /* Chalk up another one for the response count */ } - + /* Set remaining result flags if necessary */ - if(uiFirst == 1) - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, true); - - if(uiLast == CurrentLog->ulRecordCount) - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); - -return(iLen); + if (uiFirst == 1) + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, + true); + + if (uiLast == CurrentLog->ulRecordCount) + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); + + return (iLen); } @@ -1149,89 +1217,90 @@ return(iLen); ****************************************************************************/ int TL_encode_by_sequence( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest) + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest) { int log_index = 0; int iLen = 0; int32_t iTemp = 0; TL_LOG_INFO *CurrentLog = NULL; - uint32_t uiIndex = 0; /* Current entry number */ - uint32_t uiFirst = 0; /* Entry number we started encoding from */ - uint32_t uiLast = 0; /* Entry number we finished encoding on */ - uint32_t uiSequence = 0; /* Tracking sequenc number when encoding */ - uint32_t uiRemaining = 0; /* Amount of unused space in packet */ - uint32_t uiFirstSeq = 0; /* Sequence number for 1st record in log */ + uint32_t uiIndex = 0; /* Current entry number */ + uint32_t uiFirst = 0; /* Entry number we started encoding from */ + uint32_t uiLast = 0; /* Entry number we finished encoding on */ + uint32_t uiSequence = 0; /* Tracking sequenc number when encoding */ + uint32_t uiRemaining = 0; /* Amount of unused space in packet */ + uint32_t uiFirstSeq = 0; /* Sequence number for 1st record in log */ - uint32_t uiBegin = 0; /* Starting Sequence number for request */ - uint32_t uiEnd = 0; /* Ending Sequence number for request */ - bool bWrapReq = false; /* Has request sequence range spanned the max for uint32_t? */ - bool bWrapLog = false; /* Has log sequence range spanned the max for uint32_t? */ + uint32_t uiBegin = 0; /* Starting Sequence number for request */ + uint32_t uiEnd = 0; /* Ending Sequence number for request */ + bool bWrapReq = false; /* Has request sequence range spanned the max for uint32_t? */ + bool bWrapLog = false; /* Has log sequence range spanned the max for uint32_t? */ /* See how much space we have */ - uiRemaining = MAX_APDU - pRequest->Overhead; + uiRemaining = MAX_APDU - pRequest->Overhead; log_index = Trend_Log_Instance_To_Index(pRequest->object_instance); CurrentLog = &LogInfo[log_index]; /* Figure out the sequence number for the first record, last is ulTotalRecordCount */ - uiFirstSeq = CurrentLog->ulTotalRecordCount - (CurrentLog->ulRecordCount - 1); + uiFirstSeq = + CurrentLog->ulTotalRecordCount - (CurrentLog->ulRecordCount - 1); /* Calculate start and end sequence numbers from request */ - if(pRequest->Count < 0) { + if (pRequest->Count < 0) { uiBegin = pRequest->Range.RefSeqNum + pRequest->Count + 1; - uiEnd = pRequest->Range.RefSeqNum; + uiEnd = pRequest->Range.RefSeqNum; } else { uiBegin = pRequest->Range.RefSeqNum; - uiEnd = pRequest->Range.RefSeqNum + pRequest->Count - 1; + uiEnd = pRequest->Range.RefSeqNum + pRequest->Count - 1; } /* See if we have any wrap around situations */ - if(uiBegin > uiEnd) + if (uiBegin > uiEnd) bWrapReq = true; - if(uiFirstSeq > CurrentLog->ulTotalRecordCount) + if (uiFirstSeq > CurrentLog->ulTotalRecordCount) bWrapLog = true; - - if((bWrapReq == false) && (bWrapLog == false)) { /* Simple case no wraps */ + + if ((bWrapReq == false) && (bWrapLog == false)) { /* Simple case no wraps */ /* If no overlap between request range and buffer contents bail out */ - if((uiEnd < uiFirstSeq) || (uiBegin > CurrentLog->ulTotalRecordCount)) - return(0); - + if ((uiEnd < uiFirstSeq) || (uiBegin > CurrentLog->ulTotalRecordCount)) + return (0); + /* Truncate range if necessary so it is guaranteed to lie * between the first and last sequence numbers in the buffer * inclusive. */ - if(uiBegin < uiFirstSeq) + if (uiBegin < uiFirstSeq) uiBegin = uiFirstSeq; - - if(uiEnd > CurrentLog->ulTotalRecordCount) + + if (uiEnd > CurrentLog->ulTotalRecordCount) uiEnd = CurrentLog->ulTotalRecordCount; - } else { /* There are wrap arounds to contend with */ + } else { /* There are wrap arounds to contend with */ /* First check for non overlap condition as it is common to all */ - if((uiBegin > CurrentLog->ulTotalRecordCount) && (uiEnd < uiFirstSeq)) - return(0); - - if(bWrapLog == false) { /* Only request range wraps */ - if(uiEnd < uiFirstSeq) { + if ((uiBegin > CurrentLog->ulTotalRecordCount) && (uiEnd < uiFirstSeq)) + return (0); + + if (bWrapLog == false) { /* Only request range wraps */ + if (uiEnd < uiFirstSeq) { uiEnd = CurrentLog->ulTotalRecordCount; - if(uiBegin < uiFirstSeq) + if (uiBegin < uiFirstSeq) uiBegin = uiFirstSeq; } else { uiBegin = uiFirstSeq; - if(uiEnd > CurrentLog->ulTotalRecordCount) + if (uiEnd > CurrentLog->ulTotalRecordCount) uiEnd = CurrentLog->ulTotalRecordCount; } - } else if(bWrapReq == false) { /* Only log wraps */ - if(uiBegin > CurrentLog->ulTotalRecordCount) { - if(uiBegin > uiFirstSeq) + } else if (bWrapReq == false) { /* Only log wraps */ + if (uiBegin > CurrentLog->ulTotalRecordCount) { + if (uiBegin > uiFirstSeq) uiBegin = uiFirstSeq; } else { - if(uiEnd > CurrentLog->ulTotalRecordCount) + if (uiEnd > CurrentLog->ulTotalRecordCount) uiEnd = CurrentLog->ulTotalRecordCount; } - } else { /* Both wrap */ - if(uiBegin < uiFirstSeq) + } else { /* Both wrap */ + if (uiBegin < uiFirstSeq) uiBegin = uiFirstSeq; - - if(uiEnd > CurrentLog->ulTotalRecordCount) + + if (uiEnd > CurrentLog->ulTotalRecordCount) uiEnd = CurrentLog->ulTotalRecordCount; } } @@ -1241,37 +1310,39 @@ int TL_encode_by_sequence( */ uiIndex = uiBegin - uiFirstSeq + 1; uiSequence = uiBegin; - uiFirst = uiIndex; /* Record where we started from */ - while(uiSequence != uiEnd + 1) { - if(uiRemaining < TL_MAX_ENC) { + uiFirst = uiIndex; /* Record where we started from */ + while (uiSequence != uiEnd + 1) { + if (uiRemaining < TL_MAX_ENC) { /* * Can't fit any more in! We just set the result flag to say there * was more and drop out of the loop early */ - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, true); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, + true); break; - } - - iTemp = TL_encode_entry(&apdu[iLen], log_index, uiIndex); - - uiRemaining -= iTemp; /* Reduce the remaining space */ - iLen += iTemp; /* and increase the length consumed */ + } + + iTemp = TL_encode_entry(&apdu[iLen], log_index, uiIndex); + + uiRemaining -= iTemp; /* Reduce the remaining space */ + iLen += iTemp; /* and increase the length consumed */ uiLast = uiIndex; /* Record the last entry encoded */ - uiIndex++; /* and get ready for next one */ + uiIndex++; /* and get ready for next one */ uiSequence++; pRequest->ItemCount++; /* Chalk up another one for the response count */ } - + /* Set remaining result flags if necessary */ - if(uiFirst == 1) - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, true); - - if(uiLast == CurrentLog->ulRecordCount) - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); - + if (uiFirst == 1) + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, + true); + + if (uiLast == CurrentLog->ulRecordCount) + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); + pRequest->FirstSequence = uiBegin; - - return(iLen); + + return (iLen); } /**************************************************************************** @@ -1282,8 +1353,8 @@ int TL_encode_by_sequence( ****************************************************************************/ int TL_encode_by_time( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest) + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest) { int log_index = 0; int iLen = 0; @@ -1291,60 +1362,61 @@ int TL_encode_by_time( int iCount = 0; TL_LOG_INFO *CurrentLog = NULL; - uint32_t uiIndex = 0; /* Current entry number */ - uint32_t uiFirst = 0; /* Entry number we started encoding from */ - uint32_t uiLast = 0; /* Entry number we finished encoding on */ - uint32_t uiRemaining = 0; /* Amount of unused space in packet */ - uint32_t uiFirstSeq = 0; /* Sequence number for 1st record in log */ - time_t tRefTime = 0; /* The time from the request in local format */ - + uint32_t uiIndex = 0; /* Current entry number */ + uint32_t uiFirst = 0; /* Entry number we started encoding from */ + uint32_t uiLast = 0; /* Entry number we finished encoding on */ + uint32_t uiRemaining = 0; /* Amount of unused space in packet */ + uint32_t uiFirstSeq = 0; /* Sequence number for 1st record in log */ + time_t tRefTime = 0; /* The time from the request in local format */ + /* See how much space we have */ - uiRemaining = MAX_APDU - pRequest->Overhead; + uiRemaining = MAX_APDU - pRequest->Overhead; log_index = Trend_Log_Instance_To_Index(pRequest->object_instance); CurrentLog = &LogInfo[log_index]; - + tRefTime = TL_BAC_Time_To_Local(&pRequest->Range.RefTime); /* Find correct position for oldest entry in log */ - if(CurrentLog->ulRecordCount < TL_MAX_ENTRIES) + if (CurrentLog->ulRecordCount < TL_MAX_ENTRIES) uiIndex = 0; else uiIndex = CurrentLog->iIndex; - - if(pRequest->Count < 0) { + + if (pRequest->Count < 0) { /* Start at end of log and look for record which has * timestamp greater than or equal to the reference. */ iCount = CurrentLog->ulRecordCount - 1; /* Start out with the sequence number for the last record */ uiFirstSeq = CurrentLog->ulTotalRecordCount; - for(;;) { - if(Logs[pRequest->object_instance][(uiIndex + iCount) % TL_MAX_ENTRIES].tTimeStamp < tRefTime) + for (;;) { + if (Logs[pRequest->object_instance][(uiIndex + + iCount) % TL_MAX_ENTRIES].tTimeStamp < tRefTime) break; - + uiFirstSeq--; iCount--; - if(iCount < 0) - return(0); + if (iCount < 0) + return (0); } - + /* We have an and point for our request, * now work backwards to find where we should start from */ - - pRequest->Count = -pRequest->Count; /* Conveert to +ve count */ + + pRequest->Count = -pRequest->Count; /* Conveert to +ve count */ /* If count would bring us back beyond the limits * Of the buffer then pin it to the start of the buffer * otherwise adjust starting point and sequence number * appropriately. */ - iTemp = pRequest->Count - 1; - if(iTemp > iCount) { - uiFirstSeq -= iCount; - pRequest->Count = iCount + 1; + iTemp = pRequest->Count - 1; + if (iTemp > iCount) { + uiFirstSeq -= iCount; + pRequest->Count = iCount + 1; iCount = 0; } else { uiFirstSeq -= iTemp; - iCount -= iTemp; + iCount -= iTemp; } } else { /* Start at beginning of log and look for 1st record which has @@ -1352,139 +1424,170 @@ int TL_encode_by_time( */ iCount = 0; /* Figure out the sequence number for the first record, last is ulTotalRecordCount */ - uiFirstSeq = CurrentLog->ulTotalRecordCount - (CurrentLog->ulRecordCount - 1); - for(;;) { - if(Logs[pRequest->object_instance][(uiIndex + iCount) % TL_MAX_ENTRIES].tTimeStamp > tRefTime) + uiFirstSeq = + CurrentLog->ulTotalRecordCount - (CurrentLog->ulRecordCount - 1); + for (;;) { + if (Logs[pRequest->object_instance][(uiIndex + + iCount) % TL_MAX_ENTRIES].tTimeStamp > tRefTime) break; - + uiFirstSeq++; iCount++; - if((uint32_t)iCount == CurrentLog->ulRecordCount) - return(0); + if ((uint32_t) iCount == CurrentLog->ulRecordCount) + return (0); } } /* We now have a starting point for the operation and a +ve count */ - - uiIndex = iCount + 1; /* Convert to BACnet 1 based reference */ - uiFirst = uiIndex; /* Record where we started from */ - iCount = pRequest->Count; - while(iCount != 0) { - if(uiRemaining < TL_MAX_ENC) { + + uiIndex = iCount + 1; /* Convert to BACnet 1 based reference */ + uiFirst = uiIndex; /* Record where we started from */ + iCount = pRequest->Count; + while (iCount != 0) { + if (uiRemaining < TL_MAX_ENC) { /* * Can't fit any more in! We just set the result flag to say there * was more and drop out of the loop early */ - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, true); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, + true); break; - } - - iTemp = TL_encode_entry(&apdu[iLen], log_index, uiIndex); - - uiRemaining -= iTemp; /* Reduce the remaining space */ - iLen += iTemp; /* and increase the length consumed */ - uiLast = uiIndex; /* Record the last entry encoded */ - uiIndex++; /* and get ready for next one */ - pRequest->ItemCount++; /* Chalk up another one for the response count */ - iCount--; /* And finally cross another one off the requested count */ + } - if(uiIndex > CurrentLog->ulRecordCount) /* Finish up if we hit the end of the log */ + iTemp = TL_encode_entry(&apdu[iLen], log_index, uiIndex); + + uiRemaining -= iTemp; /* Reduce the remaining space */ + iLen += iTemp; /* and increase the length consumed */ + uiLast = uiIndex; /* Record the last entry encoded */ + uiIndex++; /* and get ready for next one */ + pRequest->ItemCount++; /* Chalk up another one for the response count */ + iCount--; /* And finally cross another one off the requested count */ + + if (uiIndex > CurrentLog->ulRecordCount) /* Finish up if we hit the end of the log */ break; } - + /* Set remaining result flags if necessary */ - if(uiFirst == 1) - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, true); - - if(uiLast == CurrentLog->ulRecordCount) - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); - + if (uiFirst == 1) + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, + true); + + if (uiLast == CurrentLog->ulRecordCount) + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); + pRequest->FirstSequence = uiFirstSeq; - - return(iLen); + + return (iLen); } -int TL_encode_entry(uint8_t *apdu, int iLog, int iEntry) +int TL_encode_entry( + uint8_t * apdu, + int iLog, + int iEntry) { int iLen = 0; TL_DATA_REC *pSource = NULL; - BACNET_BIT_STRING TempBits; + BACNET_BIT_STRING TempBits; int iCount = 0; BACNET_DATE_TIME TempTime; - + /* Convert from BACnet 1 based to 0 based array index and then * handle wrap around of the circular buffer */ - - if(LogInfo[iLog].ulRecordCount < TL_MAX_ENTRIES) + + if (LogInfo[iLog].ulRecordCount < TL_MAX_ENTRIES) pSource = &Logs[iLog][(iEntry - 1) % TL_MAX_ENTRIES]; else - pSource = &Logs[iLog][(LogInfo[iLog].iIndex + iEntry - 1) % TL_MAX_ENTRIES]; - + pSource = + &Logs[iLog][(LogInfo[iLog].iIndex + iEntry - 1) % TL_MAX_ENTRIES]; + iLen = 0; /* First stick the time stamp in with tag [0] */ TL_Local_Time_To_BAC(&TempTime, pSource->tTimeStamp); iLen += bacapp_encode_context_datetime(apdu, 0, &TempTime); - + /* Next comes the actual entry with tag [1] */ iLen += encode_opening_tag(&apdu[iLen], 1); /* The data entry is tagged individually [0] - [10] to indicate which type */ - switch(pSource->ucRecType) { + switch (pSource->ucRecType) { case TL_TYPE_STATUS: /* Build bit string directly from the stored octet */ bitstring_init(&TempBits); bitstring_set_bits_used(&TempBits, 1, 5); bitstring_set_octet(&TempBits, 0, pSource->Datum.ucLogStatus); - iLen += encode_context_bitstring(&apdu[iLen], pSource->ucRecType, &TempBits); + iLen += + encode_context_bitstring(&apdu[iLen], pSource->ucRecType, + &TempBits); break; - + case TL_TYPE_BOOL: - iLen += encode_context_boolean(&apdu[iLen], pSource->ucRecType, pSource->Datum.ucBoolean); + iLen += + encode_context_boolean(&apdu[iLen], pSource->ucRecType, + pSource->Datum.ucBoolean); break; - + case TL_TYPE_REAL: - iLen += encode_context_real(&apdu[iLen], pSource->ucRecType, pSource->Datum.fReal); + iLen += + encode_context_real(&apdu[iLen], pSource->ucRecType, + pSource->Datum.fReal); break; - + case TL_TYPE_ENUM: - iLen += encode_context_enumerated(&apdu[iLen], pSource->ucRecType, pSource->Datum.ulEnum); + iLen += + encode_context_enumerated(&apdu[iLen], pSource->ucRecType, + pSource->Datum.ulEnum); break; - + case TL_TYPE_UNSIGN: - iLen += encode_context_unsigned(&apdu[iLen], pSource->ucRecType, pSource->Datum.ulUValue); + iLen += + encode_context_unsigned(&apdu[iLen], pSource->ucRecType, + pSource->Datum.ulUValue); break; - + case TL_TYPE_SIGN: - iLen += encode_context_signed(&apdu[iLen], pSource->ucRecType, pSource->Datum.lSValue); + iLen += + encode_context_signed(&apdu[iLen], pSource->ucRecType, + pSource->Datum.lSValue); break; - + case TL_TYPE_BITS: /* Rebuild bitstring directly from stored octets - which we * have limited to 32 bits maximum as allowed by the standard */ bitstring_init(&TempBits); - bitstring_set_bits_used(&TempBits, (pSource->Datum.Bits.ucLen >> 4) & 0x0F, pSource->Datum.Bits.ucLen & 0x0F); - for(iCount = pSource->Datum.Bits.ucLen >> 4; iCount > 0; iCount--) - bitstring_set_octet(&TempBits, iCount - 1, pSource->Datum.Bits.ucStore[iCount-1]); - - iLen += encode_context_bitstring(&apdu[iLen], pSource->ucRecType, &TempBits); + bitstring_set_bits_used(&TempBits, + (pSource->Datum.Bits.ucLen >> 4) & 0x0F, + pSource->Datum.Bits.ucLen & 0x0F); + for (iCount = pSource->Datum.Bits.ucLen >> 4; iCount > 0; iCount--) + bitstring_set_octet(&TempBits, iCount - 1, + pSource->Datum.Bits.ucStore[iCount - 1]); + + iLen += + encode_context_bitstring(&apdu[iLen], pSource->ucRecType, + &TempBits); break; - + case TL_TYPE_NULL: iLen += encode_context_null(&apdu[iLen], pSource->ucRecType); break; - + case TL_TYPE_ERROR: iLen += encode_opening_tag(&apdu[iLen], TL_TYPE_ERROR); - iLen += encode_application_enumerated(&apdu[iLen], pSource->Datum.Error.usClass); - iLen += encode_application_enumerated(&apdu[iLen], pSource->Datum.Error.usCode); + iLen += + encode_application_enumerated(&apdu[iLen], + pSource->Datum.Error.usClass); + iLen += + encode_application_enumerated(&apdu[iLen], + pSource->Datum.Error.usCode); iLen += encode_closing_tag(&apdu[iLen], TL_TYPE_ERROR); break; - + case TL_TYPE_DELTA: - iLen += encode_context_real(&apdu[iLen], pSource->ucRecType, pSource->Datum.fTime); + iLen += + encode_context_real(&apdu[iLen], pSource->ucRecType, + pSource->Datum.fTime); break; - + case TL_TYPE_ANY: /* Should never happen as we don't support this at the moment */ break; @@ -1492,7 +1595,7 @@ int TL_encode_entry(uint8_t *apdu, int iLog, int iEntry) iLen += encode_closing_tag(&apdu[iLen], 1); /* Check if status bit string is required and insert with tag [2] */ - if((pSource->ucStatus & 128) == 128) { + if ((pSource->ucStatus & 128) == 128) { bitstring_init(&TempBits); bitstring_set_bits_used(&TempBits, 1, 4); /* only insert the 1st 4 bits */ @@ -1500,16 +1603,15 @@ int TL_encode_entry(uint8_t *apdu, int iLog, int iEntry) iLen += encode_context_bitstring(&apdu[iLen], 2, &TempBits); } - return(iLen); + return (iLen); } static int local_read_property( uint8_t * value, uint8_t * status, - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *Source, + BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * Source, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code) - { int len = 0; BACNET_READ_PROPERTY_DATA rpdata; @@ -1523,19 +1625,19 @@ static int local_read_property( rpdata.object_property = Source->propertyIdentifier; rpdata.array_index = Source->arrayIndex; /* Try to fetch the required property */ - len = Device_Read_Property(&rpdata); + len = Device_Read_Property(&rpdata); if (len < 0) { *error_class = rpdata.error_class; *error_code = rpdata.error_code; } } - if((len >= 0) && (status != NULL)){ + if ((len >= 0) && (status != NULL)) { /* Fetch the status flags if required */ rpdata.application_data = status; rpdata.application_data_len = MAX_APDU; rpdata.object_property = PROP_STATUS_FLAGS; rpdata.array_index = BACNET_ARRAY_ALL; - len = Device_Read_Property(&rpdata); + len = Device_Read_Property(&rpdata); if (len < 0) { *error_class = rpdata.error_class; *error_code = rpdata.error_code; @@ -1544,16 +1646,16 @@ static int local_read_property( *error_class = rpdata.error_class; *error_code = rpdata.error_code; } - - return(len); + + return (len); } /**************************************************************************** * Attempt to fetch the logged property and store it in the Trend Log * ****************************************************************************/ - -void TL_fetch_property(int iLog) - + +void TL_fetch_property( + int iLog) { uint8_t ValueBuf[MAX_APDU]; /* This is a big buffer in case someone selects the device object list for example */ uint8_t StatusBuf[3]; /* Should be tag, bits unused in last octet and 1 byte of data */ @@ -1562,29 +1664,33 @@ void TL_fetch_property(int iLog) int iLen; int iCount; TL_LOG_INFO *CurrentLog; - TL_DATA_REC TempRec; - uint8_t tag_number = 0; + TL_DATA_REC TempRec; + uint8_t tag_number = 0; uint32_t len_value_type = 0; BACNET_BIT_STRING TempBits; - + CurrentLog = &LogInfo[iLog]; - + /* Record the current time in the log entry and also in the info block * for the log so we can figure out when the next reading is due */ TempRec.tTimeStamp = time(NULL); CurrentLog->tLastDataTime = TempRec.tTimeStamp; - TempRec.ucStatus = 0; - - iLen = local_read_property(ValueBuf, StatusBuf, &LogInfo[iLog].Source, &error_class, &error_code); - if(iLen < 0) { + TempRec.ucStatus = 0; + + iLen = + local_read_property(ValueBuf, StatusBuf, &LogInfo[iLog].Source, + &error_class, &error_code); + if (iLen < 0) { /* Insert error code into log */ TempRec.Datum.Error.usClass = error_class; - TempRec.Datum.Error.usCode = error_code; - TempRec.ucRecType = TL_TYPE_ERROR; + TempRec.Datum.Error.usCode = error_code; + TempRec.ucRecType = TL_TYPE_ERROR; } else { /* Decode data returned and see if we can fit it into the log */ - iLen = decode_tag_number_and_value(ValueBuf, &tag_number, &len_value_type); - switch(tag_number) { + iLen = + decode_tag_number_and_value(ValueBuf, &tag_number, + &len_value_type); + switch (tag_number) { case BACNET_APPLICATION_TAG_NULL: TempRec.ucRecType = TL_TYPE_NULL; break; @@ -1596,70 +1702,81 @@ void TL_fetch_property(int iLog) case BACNET_APPLICATION_TAG_UNSIGNED_INT: TempRec.ucRecType = TL_TYPE_UNSIGN; - decode_unsigned(&ValueBuf[iLen], len_value_type, &TempRec.Datum.ulUValue); + decode_unsigned(&ValueBuf[iLen], len_value_type, + &TempRec.Datum.ulUValue); break; - + case BACNET_APPLICATION_TAG_SIGNED_INT: TempRec.ucRecType = TL_TYPE_SIGN; - decode_signed(&ValueBuf[iLen], len_value_type, &TempRec.Datum.lSValue); + decode_signed(&ValueBuf[iLen], len_value_type, + &TempRec.Datum.lSValue); break; - + case BACNET_APPLICATION_TAG_REAL: TempRec.ucRecType = TL_TYPE_REAL; - decode_real_safe(&ValueBuf[iLen], len_value_type, &TempRec.Datum.fReal); + decode_real_safe(&ValueBuf[iLen], len_value_type, + &TempRec.Datum.fReal); break; - + case BACNET_APPLICATION_TAG_BIT_STRING: TempRec.ucRecType = TL_TYPE_BITS; decode_bitstring(&ValueBuf[iLen], len_value_type, &TempBits); /* We truncate any bitstrings at 32 bits to conserve space */ - if(bitstring_bits_used(&TempBits) < 32) { + if (bitstring_bits_used(&TempBits) < 32) { /* Store the bytes used and the bits free in the last byte */ - TempRec.Datum.Bits.ucLen = bitstring_bytes_used(&TempBits) << 4; - TempRec.Datum.Bits.ucLen |= (8 - (bitstring_bits_used(&TempBits) % 8)) & 7; + TempRec.Datum.Bits.ucLen = + bitstring_bytes_used(&TempBits) << 4; + TempRec.Datum.Bits.ucLen |= + (8 - (bitstring_bits_used(&TempBits) % 8)) & 7; /* Fetch the octets with the bits directly */ - for(iCount = 0; iCount < bitstring_bytes_used(&TempBits); iCount++) - TempRec.Datum.Bits.ucStore[iCount] = bitstring_octet(&TempBits, iCount); + for (iCount = 0; iCount < bitstring_bytes_used(&TempBits); + iCount++) + TempRec.Datum.Bits.ucStore[iCount] = + bitstring_octet(&TempBits, iCount); } else { /* We will only use the first 4 octets to save space */ TempRec.Datum.Bits.ucLen = 4 << 4; - for(iCount = 0; iCount < 4; iCount++) - TempRec.Datum.Bits.ucStore[iCount] = bitstring_octet(&TempBits, iCount); + for (iCount = 0; iCount < 4; iCount++) + TempRec.Datum.Bits.ucStore[iCount] = + bitstring_octet(&TempBits, iCount); } break; - + case BACNET_APPLICATION_TAG_ENUMERATED: TempRec.ucRecType = TL_TYPE_ENUM; - decode_enumerated(&ValueBuf[iLen], len_value_type, &TempRec.Datum.ulEnum); + decode_enumerated(&ValueBuf[iLen], len_value_type, + &TempRec.Datum.ulEnum); break; default: /* Fake an error response for any types we cannot handle */ TempRec.Datum.Error.usClass = ERROR_CLASS_PROPERTY; - TempRec.Datum.Error.usCode = ERROR_CODE_DATATYPE_NOT_SUPPORTED; - TempRec.ucRecType = TL_TYPE_ERROR; + TempRec.Datum.Error.usCode = ERROR_CODE_DATATYPE_NOT_SUPPORTED; + TempRec.ucRecType = TL_TYPE_ERROR; break; } /* Finally insert the status flags into the record */ - iLen = decode_tag_number_and_value(StatusBuf, &tag_number, &len_value_type); + iLen = + decode_tag_number_and_value(StatusBuf, &tag_number, + &len_value_type); decode_bitstring(&StatusBuf[iLen], len_value_type, &TempBits); - TempRec.ucStatus = 128 | bitstring_octet(&TempBits,0); + TempRec.ucStatus = 128 | bitstring_octet(&TempBits, 0); } Logs[iLog][CurrentLog->iIndex++] = TempRec; - if(CurrentLog->iIndex >= TL_MAX_ENTRIES) + if (CurrentLog->iIndex >= TL_MAX_ENTRIES) CurrentLog->iIndex = 0; - + CurrentLog->ulTotalRecordCount++; - if(CurrentLog->ulRecordCount < TL_MAX_ENTRIES) + if (CurrentLog->ulRecordCount < TL_MAX_ENTRIES) CurrentLog->ulRecordCount++; } /**************************************************************************** * Check each log to see if any data needs to be recorded. * ****************************************************************************/ - + void trend_log_timer( uint16_t uSeconds) { @@ -1671,14 +1788,14 @@ void trend_log_timer( uSeconds = uSeconds; /* use OS to get the current time */ tNow = time(NULL); - for(iCount = 0; iCount < MAX_TREND_LOGS; iCount++) { + for (iCount = 0; iCount < MAX_TREND_LOGS; iCount++) { CurrentLog = &LogInfo[iCount]; - if(TL_Is_Enabled(iCount)) { - if(CurrentLog->LoggingType == LOGGING_TYPE_POLLED) { + if (TL_Is_Enabled(iCount)) { + if (CurrentLog->LoggingType == LOGGING_TYPE_POLLED) { /* For polled logs we first need to see if they are clock * aligned or not. */ - if(CurrentLog->bAlignIntervals == true) { + if (CurrentLog->bAlignIntervals == true) { /* Aligned logging so use the combination of the interval * and the offset to decide when to log. Also log a reading if * more than interval time has elapsed since last reading to ensure @@ -1687,12 +1804,15 @@ void trend_log_timer( */ /* if(((tNow % CurrentLog->ulLogInterval) >= (CurrentLog->ulIntervalOffset % CurrentLog->ulLogInterval)) && */ /* ((tNow - CurrentLog->tLastDataTime) >= CurrentLog->ulLogInterval)) { */ - if((tNow % CurrentLog->ulLogInterval) == (CurrentLog->ulIntervalOffset % CurrentLog->ulLogInterval)) { + if ((tNow % CurrentLog->ulLogInterval) == + (CurrentLog->ulIntervalOffset % + CurrentLog->ulLogInterval)) { /* Record value if time synchronised trigger condition is met * and at least one period has elapsed. */ TL_fetch_property(iCount); - } else if((tNow - CurrentLog->tLastDataTime) > CurrentLog->ulLogInterval) { + } else if ((tNow - CurrentLog->tLastDataTime) > + CurrentLog->ulLogInterval) { /* Also record value if we have waited more than a period * since the last reading. This ensures we take a reading as * soon as possible after a power down if we have been off for @@ -1700,20 +1820,21 @@ void trend_log_timer( */ TL_fetch_property(iCount); } - } else if(((tNow - CurrentLog->tLastDataTime) >= CurrentLog->ulLogInterval) || - (CurrentLog->bTrigger == true)) { + } else if (((tNow - CurrentLog->tLastDataTime) >= + CurrentLog->ulLogInterval) || + (CurrentLog->bTrigger == true)) { /* If not aligned take a reading when we have either waited long * enough or a trigger is set. */ TL_fetch_property(iCount); } - - CurrentLog->bTrigger = false; /* Clear this every time */ - } else if(CurrentLog->LoggingType == LOGGING_TYPE_TRIGGERED) { + + CurrentLog->bTrigger = false; /* Clear this every time */ + } else if (CurrentLog->LoggingType == LOGGING_TYPE_TRIGGERED) { /* Triggered logs take a reading when the trigger is set and * then reset the trigger to wait for the next event */ - if(CurrentLog->bTrigger == true) { + if (CurrentLog->bTrigger == true) { TL_fetch_property(iCount); CurrentLog->bTrigger = false; } diff --git a/bacnet-stack/demo/readfile/main.c b/bacnet-stack/demo/readfile/main.c index 21f4e684..17315f91 100644 --- a/bacnet-stack/demo/readfile/main.c +++ b/bacnet-stack/demo/readfile/main.c @@ -136,7 +136,7 @@ static void AtomicReadFileAckHandler( fprintf(stderr, "Unable to write data to file \"%s\".\n", Local_File_Name); } else if (octets_written == 0) { - fprintf(stderr, "Received 0 byte octet string!.\n"); + fprintf(stderr, "Received 0 byte octet string!.\n"); } else { printf("\r%u bytes", (data.type.stream.fileStartPosition + octets_written)); diff --git a/bacnet-stack/demo/readrange/main.c b/bacnet-stack/demo/readrange/main.c index f28700a7..4f7752d2 100644 --- a/bacnet-stack/demo/readrange/main.c +++ b/bacnet-stack/demo/readrange/main.c @@ -281,15 +281,17 @@ int main( /* at least one second has passed */ if (current_seconds != last_seconds) { putchar('.'); /* Just to show that time is passing... */ - tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); + tsm_timer_milliseconds(((current_seconds - + last_seconds) * 1000)); address_cache_timer(current_seconds - last_seconds); trend_log_timer(current_seconds - last_seconds); last_seconds = current_seconds; /* Change the analog input PVs for testing purposes */ - for(iCount = 0; iCount < Analog_Input_Count(); iCount++) { - Analog_Input_Present_Value_Set(iCount, iSecondsRun * (iCount + 1)); + for (iCount = 0; iCount < Analog_Input_Count(); iCount++) { + Analog_Input_Present_Value_Set(iCount, + iSecondsRun * (iCount + 1)); } - + iSecondsRun++; } #if defined(WIN32) || defined(__BORLANDC__) @@ -326,7 +328,8 @@ int main( } /* at least one second has passed */ if (current_seconds != last_seconds) { - tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); + tsm_timer_milliseconds(((current_seconds - + last_seconds) * 1000)); address_cache_timer(current_seconds - last_seconds); trend_log_timer(current_seconds - last_seconds); last_seconds = current_seconds; @@ -341,138 +344,162 @@ int main( if (found) { if (invoke_id == 0) { /* Safe to send a new request */ switch (iCount) { - case 0: /* Pass - should read up to 1st 10 */ - Request.RequestType = RR_BY_POSITION; - Request.Range.RefIndex = 1; - Request.Count = 10; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 0; - break; + case 0: /* Pass - should read up to 1st 10 */ + Request.RequestType = RR_BY_POSITION; + Request.Range.RefIndex = 1; + Request.Count = 10; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 0; + break; - case 1: /* Pass - should read entries 2 and 3 */ - Request.RequestType = RR_BY_POSITION; - Request.Range.RefSeqNum = 3; - Request.Count = -2; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 0; - break; + case 1: /* Pass - should read entries 2 and 3 */ + Request.RequestType = RR_BY_POSITION; + Request.Range.RefSeqNum = 3; + Request.Count = -2; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 0; + break; - case 2: /* Fail - By Time not supported */ - Request.RequestType = RR_BY_TIME; - Request.Range.RefTime.date.year = 2009; - Request.Range.RefTime.date.month = 9; - Request.Range.RefTime.date.day = 23; - Request.Range.RefTime.date.wday = 0xFF; - Request.Range.RefTime.time.hour = 22; - Request.Range.RefTime.time.min = 23; - Request.Range.RefTime.time.sec = 24; - Request.Range.RefTime.time.hundredths = 0; - - Request.Count = 10; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 0; - break; + case 2: /* Fail - By Time not supported */ + Request.RequestType = RR_BY_TIME; + Request.Range.RefTime.date.year = 2009; + Request.Range.RefTime.date.month = 9; + Request.Range.RefTime.date.day = 23; + Request.Range.RefTime.date.wday = 0xFF; + Request.Range.RefTime.time.hour = 22; + Request.Range.RefTime.time.min = 23; + Request.Range.RefTime.time.sec = 24; + Request.Range.RefTime.time.hundredths = 0; - case 3: /* Fail - array not supported */ - Request.RequestType = RR_BY_POSITION; - Request.Range.RefIndex = 1; - Request.Count = 10; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 1; - break; + Request.Count = 10; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 0; + break; - case 4: /* Fail - By Sequence not supported */ - Request.RequestType = RR_BY_SEQUENCE; - Request.Range.RefSeqNum = 1; - Request.Count = 10; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 0; - break; + case 3: /* Fail - array not supported */ + Request.RequestType = RR_BY_POSITION; + Request.Range.RefIndex = 1; + Request.Count = 10; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 1; + break; - case 5: /* Fail Bytime not supported and array not supported */ - Request.RequestType = RR_BY_TIME; - Request.Range.RefTime.date.year = 2009; - Request.Range.RefTime.date.month = 9; - Request.Range.RefTime.date.day = 23; - Request.Range.RefTime.date.wday = 0xFF; /* Day of week unspecified */ - Request.Range.RefTime.time.hour = 22; - Request.Range.RefTime.time.min = 23; - Request.Range.RefTime.time.sec = 24; - Request.Range.RefTime.time.hundredths = 0; - - Request.Count = 10; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 1; - break; + case 4: /* Fail - By Sequence not supported */ + Request.RequestType = RR_BY_SEQUENCE; + Request.Range.RefSeqNum = 1; + Request.Count = 10; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 0; + break; - case 6: /* Pass - should try to return all entries */ - Request.RequestType = RR_READ_ALL; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 0; - break; + case 5: /* Fail Bytime not supported and array not supported */ + Request.RequestType = RR_BY_TIME; + Request.Range.RefTime.date.year = 2009; + Request.Range.RefTime.date.month = 9; + Request.Range.RefTime.date.day = 23; + Request.Range.RefTime.date.wday = 0xFF; /* Day of week unspecified */ + Request.Range.RefTime.time.hour = 22; + Request.Range.RefTime.time.min = 23; + Request.Range.RefTime.time.sec = 24; + Request.Range.RefTime.time.hundredths = 0; - case 7: /* Fail - array not supported */ - Request.RequestType = RR_READ_ALL; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 1; - break; + Request.Count = 10; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 1; + break; - case 8: /* Pass - should read 1st 1 */ - Request.RequestType = RR_BY_POSITION; - Request.Range.RefIndex = 1; - Request.Count = 1; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 0; - break; + case 6: /* Pass - should try to return all entries */ + Request.RequestType = RR_READ_ALL; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 0; + break; - case 9: /* Pass - should read 1st 2 */ - Request.RequestType = RR_BY_POSITION; - Request.Range.RefIndex = 1; - Request.Count = 2; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 0; - break; + case 7: /* Fail - array not supported */ + Request.RequestType = RR_READ_ALL; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 1; + break; - case 10: /* Pass - should read 2nd and 3rd */ - Request.RequestType = RR_BY_POSITION; - Request.Range.RefIndex = 2; - Request.Count = 2; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 0; - break; + case 8: /* Pass - should read 1st 1 */ + Request.RequestType = RR_BY_POSITION; + Request.Range.RefIndex = 1; + Request.Count = 1; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 0; + break; - case 11: /* Pass - should read 2nd up to 11th */ - Request.RequestType = RR_BY_POSITION; - Request.Range.RefIndex = 2; - Request.Count = 10; - Request.object_type = OBJECT_DEVICE; - Request.object_instance = Target_Device_Object_Instance; - Request.object_property = PROP_DEVICE_ADDRESS_BINDING; - Request.array_index = 0; - break; - } + case 9: /* Pass - should read 1st 2 */ + Request.RequestType = RR_BY_POSITION; + Request.Range.RefIndex = 1; + Request.Count = 2; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 0; + break; + + case 10: /* Pass - should read 2nd and 3rd */ + Request.RequestType = RR_BY_POSITION; + Request.Range.RefIndex = 2; + Request.Count = 2; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 0; + break; + + case 11: /* Pass - should read 2nd up to 11th */ + Request.RequestType = RR_BY_POSITION; + Request.Range.RefIndex = 2; + Request.Count = 10; + Request.object_type = OBJECT_DEVICE; + Request.object_instance = + Target_Device_Object_Instance; + Request.object_property = + PROP_DEVICE_ADDRESS_BINDING; + Request.array_index = 0; + break; + } invoke_id = Send_ReadRange_Request(Target_Device_Object_Instance, diff --git a/bacnet-stack/demo/server/main.c b/bacnet-stack/demo/server/main.c index b01cfadc..6f26f23d 100644 --- a/bacnet-stack/demo/server/main.c +++ b/bacnet-stack/demo/server/main.c @@ -55,7 +55,7 @@ /* (Doxygen note: The next two lines pull all the following Javadoc * into the ServerDemo module.) */ -/** @addtogroup ServerDemo */ +/** @addtogroup ServerDemo */ /*@{*/ /** Buffer used for receiving */ @@ -184,4 +184,4 @@ int main( } } -/* @} */ /* End group ServerDemo */ + /* @} *//* End group ServerDemo */ diff --git a/bacnet-stack/demo/ucov/main.c b/bacnet-stack/demo/ucov/main.c index 1ea22fd5..e4479013 100644 --- a/bacnet-stack/demo/ucov/main.c +++ b/bacnet-stack/demo/ucov/main.c @@ -160,8 +160,7 @@ int main( } if (cov_data.monitoredObjectIdentifier.type >= MAX_BACNET_OBJECT_TYPE) { fprintf(stderr, "object-type=%u - it must be less than %u\r\n", - cov_data.monitoredObjectIdentifier.type, - MAX_BACNET_OBJECT_TYPE); + cov_data.monitoredObjectIdentifier.type, MAX_BACNET_OBJECT_TYPE); return 1; } if (cov_data.monitoredObjectIdentifier.instance > BACNET_MAX_INSTANCE) { diff --git a/bacnet-stack/include/address.h b/bacnet-stack/include/address.h index 2437f601..06d45058 100644 --- a/bacnet-stack/include/address.h +++ b/bacnet-stack/include/address.h @@ -95,8 +95,8 @@ extern "C" { unsigned apdu_len); int rr_address_list_encode( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest); + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest); void address_set_device_TTL( uint32_t device_id, diff --git a/bacnet-stack/include/ai.h b/bacnet-stack/include/ai.h index c7a71fef..4c07e52f 100644 --- a/bacnet-stack/include/ai.h +++ b/bacnet-stack/include/ai.h @@ -69,7 +69,7 @@ extern "C" { uint32_t instance); int Analog_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Analog_Input_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); @@ -78,7 +78,7 @@ extern "C" { void Analog_Input_Present_Value_Set( uint32_t object_instance, float value); - + void Analog_Input_Init( void); diff --git a/bacnet-stack/include/ao.h b/bacnet-stack/include/ao.h index d2c4685b..707eb5e1 100644 --- a/bacnet-stack/include/ao.h +++ b/bacnet-stack/include/ao.h @@ -86,7 +86,7 @@ extern "C" { void); int Analog_Output_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Analog_Output_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/apdu.h b/bacnet-stack/include/apdu.h index 947a86f9..838be38b 100644 --- a/bacnet-stack/include/apdu.h +++ b/bacnet-stack/include/apdu.h @@ -163,8 +163,8 @@ extern "C" { */ bool apdu_service_supported_to_index( BACNET_SERVICES_SUPPORTED service_supported, - size_t *index, - bool *bIsConfirmed ); + size_t * index, + bool * bIsConfirmed); void apdu_set_error_handler( diff --git a/bacnet-stack/include/av.h b/bacnet-stack/include/av.h index 38ec2fd9..2486a551 100644 --- a/bacnet-stack/include/av.h +++ b/bacnet-stack/include/av.h @@ -49,7 +49,7 @@ extern "C" { uint32_t object_instance); int Analog_Value_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Analog_Value_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/bacdevobjpropref.h b/bacnet-stack/include/bacdevobjpropref.h index 27f57bd5..769a3406 100644 --- a/bacnet-stack/include/bacdevobjpropref.h +++ b/bacnet-stack/include/bacdevobjpropref.h @@ -48,7 +48,7 @@ typedef struct { * to an object inside this Device. */ typedef struct { - BACNET_OBJECT_ID deviceIndentifier; /**< Optional, for external device. */ + BACNET_OBJECT_ID deviceIndentifier; /**< Optional, for external device. */ BACNET_OBJECT_ID objectIdentifier; } BACNET_DEVICE_OBJECT_REFERENCE; diff --git a/bacnet-stack/include/bacenum.h b/bacnet-stack/include/bacenum.h index d3c37645..2c228c8d 100644 --- a/bacnet-stack/include/bacenum.h +++ b/bacnet-stack/include/bacenum.h @@ -636,10 +636,10 @@ typedef enum { UNITS_SQUARE_METERS_PER_NEWTON = 185, UNITS_WATTS_PER_METER_PER_DEGREE_KELVIN = 189, UNITS_WATTS_PER_SQUARE_METER_DEGREE_KELVIN = 141, - /* Enumerated values 0-255 are reserved for definition by ASHRAE. */ - /* Enumerated values 256-65535 may be used by others subject to */ - /* the procedures and constraints described in Clause 23. */ - /* The last enumeration used in this version is 189. */ + /* Enumerated values 0-255 are reserved for definition by ASHRAE. */ + /* Enumerated values 256-65535 may be used by others subject to */ + /* the procedures and constraints described in Clause 23. */ + /* The last enumeration used in this version is 189. */ MAX_UNITS = 190 } BACNET_ENGINEERING_UNITS; diff --git a/bacnet-stack/include/bacfile.h b/bacnet-stack/include/bacfile.h index ca64b3e8..2ef6a529 100644 --- a/bacnet-stack/include/bacfile.h +++ b/bacnet-stack/include/bacfile.h @@ -81,7 +81,7 @@ extern "C" { /* handling for read property service */ int bacfile_read_property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); /* handling for write property service */ bool bacfile_write_property( diff --git a/bacnet-stack/include/bi.h b/bacnet-stack/include/bi.h index 6c82f75f..d8bfc93d 100644 --- a/bacnet-stack/include/bi.h +++ b/bacnet-stack/include/bi.h @@ -84,7 +84,7 @@ extern "C" { BACNET_PROPERTY_VALUE * value_list); int Binary_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Binary_Input_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/bip.h b/bacnet-stack/include/bip.h index 542cdc3e..38d4bb05 100644 --- a/bacnet-stack/include/bip.h +++ b/bacnet-stack/include/bip.h @@ -122,7 +122,6 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup DLBIP BACnet/IP DataLink Network Layer * @ingroup DataLink * Implementation of the Network Layer using BACnet/IP as the transport, as @@ -131,5 +130,4 @@ extern "C" { * DataLink level by serving as the implementation of the function templates. * */ - #endif diff --git a/bacnet-stack/include/bo.h b/bacnet-stack/include/bo.h index a55abafe..a9d89776 100644 --- a/bacnet-stack/include/bo.h +++ b/bacnet-stack/include/bo.h @@ -79,7 +79,7 @@ extern "C" { char *new_name); int Binary_Output_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Binary_Output_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/bv.h b/bacnet-stack/include/bv.h index 9184a4f3..c3ca354f 100644 --- a/bacnet-stack/include/bv.h +++ b/bacnet-stack/include/bv.h @@ -53,7 +53,7 @@ extern "C" { void); int Binary_Value_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Binary_Value_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/cov.h b/bacnet-stack/include/cov.h index e89a32f8..ea645b45 100644 --- a/bacnet-stack/include/cov.h +++ b/bacnet-stack/include/cov.h @@ -126,7 +126,6 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup DSCOV Data Sharing - Change of Value Service (DS-COV) * @ingroup DataShare * 13.1 Change of Value Reporting
@@ -140,5 +139,4 @@ extern "C" { * devices or to operators or logging devices. Any object, proprietary or * standard, may support COV reporting at the implementor's option. */ - #endif diff --git a/bacnet-stack/include/datalink.h b/bacnet-stack/include/datalink.h index bca2f574..e3b41d60 100644 --- a/bacnet-stack/include/datalink.h +++ b/bacnet-stack/include/datalink.h @@ -83,7 +83,7 @@ #define datalink_get_broadcast_address bip_get_broadcast_address #define datalink_get_my_address bip_get_my_address -#else /* Ie, BACDL_ALL */ +#else /* Ie, BACDL_ALL */ #include "npdu.h" #define MAX_HEADER (8) @@ -118,7 +118,6 @@ extern "C" { } #endif /* __cplusplus */ #endif - /** @defgroup DataLink The BACnet Network (DataLink) Layer * 6 THE NETWORK LAYER
* The purpose of the BACnet network layer is to provide the means by which @@ -140,13 +139,10 @@ 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 * at runtime. */ - #endif diff --git a/bacnet-stack/include/dcc.h b/bacnet-stack/include/dcc.h index 11dec57b..7f5cc0e5 100644 --- a/bacnet-stack/include/dcc.h +++ b/bacnet-stack/include/dcc.h @@ -97,14 +97,11 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup RDMS Remote Device Management Services BIBBs * These device management BIBBs prescribe the BACnet capabilities required * to interoperably perform the device management functions enumerated in * 22.2.1.5 for the BACnet devices defined therein. - */ - -/** @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 @@ -118,5 +115,4 @@ extern "C" { * DeviceCommunicationControl or, if supported, ReinitializeDevice service, * not by time. */ - #endif diff --git a/bacnet-stack/include/device.h b/bacnet-stack/include/device.h index 95809869..f0b6d767 100644 --- a/bacnet-stack/include/device.h +++ b/bacnet-stack/include/device.h @@ -106,7 +106,7 @@ typedef bool( * == 1) to indicate no more objects found. */ typedef unsigned ( - *object_iterate_function)( + *object_iterate_function) ( unsigned current_index); @@ -116,11 +116,12 @@ extern "C" { void Device_Init( void); - + bool Device_Reinitialize( - BACNET_REINITIALIZE_DEVICE_DATA *rd_data); - - BACNET_REINITIALIZED_STATE Device_Reinitialized_State(void); + BACNET_REINITIALIZE_DEVICE_DATA * rd_data); + + BACNET_REINITIALIZED_STATE Device_Reinitialized_State( + void); rr_info_function Device_Objects_RR_Info( BACNET_OBJECT_TYPE object_type); @@ -146,7 +147,8 @@ extern "C" { int *object_type, uint32_t * instance); - unsigned Device_Count(void); + unsigned Device_Count( + void); uint32_t Device_Index_To_Instance( unsigned index); char *Device_Name( @@ -221,19 +223,18 @@ extern "C" { uint32_t object_instance); int Device_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Device_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); - + bool DeviceGetRRInfo( - BACNET_READ_RANGE_DATA *pRequest, /* Info on the request */ - RR_PROP_INFO *pInfo); /* Where to put the information */ + BACNET_READ_RANGE_DATA * pRequest, /* Info on the request */ + RR_PROP_INFO * pInfo); /* Where to put the information */ #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup ObjFrmwk Object Framework * The modules in this section describe the BACnet-stack's framework for * BACnet-defined Objects (Device, Analog Input, etc). There are two submodules @@ -243,15 +244,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 @@ -266,6 +263,4 @@ extern "C" { * eg Object_Read_Property() for the RP handler. * */ - - #endif diff --git a/bacnet-stack/include/event.h b/bacnet-stack/include/event.h index 34a8e587..d3757c31 100644 --- a/bacnet-stack/include/event.h +++ b/bacnet-stack/include/event.h @@ -209,14 +209,11 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup ALMEVNT Alarm and Event Management BIBBs * 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 @@ -233,9 +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 @@ -246,5 +241,4 @@ extern "C" { * This service may be used in conjunction with either the * ConfirmedEventNotification service or the UnconfirmedEventNotification service. */ - #endif /* BACNET_EVENT_H_ */ diff --git a/bacnet-stack/include/fifo.h b/bacnet-stack/include/fifo.h index 41a8f062..4a4a4333 100755 --- a/bacnet-stack/include/fifo.h +++ b/bacnet-stack/include/fifo.h @@ -59,10 +59,10 @@ extern "C" { unsigned FIFO_Count( FIFO_BUFFER const *b); - + bool FIFO_Full( FIFO_BUFFER const *b); - + bool FIFO_Empty( FIFO_BUFFER const *b); diff --git a/bacnet-stack/include/handlers.h b/bacnet-stack/include/handlers.h index d921cf41..3d875f31 100644 --- a/bacnet-stack/include/handlers.h +++ b/bacnet-stack/include/handlers.h @@ -63,7 +63,7 @@ extern "C" { uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src); - + void handler_who_has( uint8_t * service_request, uint16_t service_len, @@ -84,7 +84,7 @@ extern "C" { uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data); - + void handler_read_property_ack( uint8_t * service_request, uint16_t service_len, @@ -98,14 +98,14 @@ extern "C" { BACNET_CONFIRMED_SERVICE_DATA * service_data); bool WPValidateString( - BACNET_APPLICATION_DATA_VALUE *pValue, + BACNET_APPLICATION_DATA_VALUE * pValue, int iMaxLen, bool bEmptyAllowed, BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode); bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE *pValue, + BACNET_APPLICATION_DATA_VALUE * pValue, uint8_t ucExpectedType, BACNET_ERROR_CLASS * pErrorClass, BACNET_ERROR_CODE * pErrorCode); @@ -256,10 +256,7 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup MISCHNDLR Miscellaneous Handler Utilities * Various utilities and functions to support the Handlers. */ - - #endif diff --git a/bacnet-stack/include/lc.h b/bacnet-stack/include/lc.h index 62d70f84..0172b882 100644 --- a/bacnet-stack/include/lc.h +++ b/bacnet-stack/include/lc.h @@ -56,7 +56,7 @@ extern "C" { void); int Load_Control_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Load_Control_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/lo.h b/bacnet-stack/include/lo.h index e6f03389..523e2d06 100644 --- a/bacnet-stack/include/lo.h +++ b/bacnet-stack/include/lo.h @@ -58,7 +58,7 @@ extern "C" { /* ReadProperty service support */ int Lighting_Output_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); /* WriteProperty service support */ bool Lighting_Output_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/lsp.h b/bacnet-stack/include/lsp.h index 63ceb856..f0144930 100644 --- a/bacnet-stack/include/lsp.h +++ b/bacnet-stack/include/lsp.h @@ -52,7 +52,7 @@ extern "C" { void); int Life_Safety_Point_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Life_Safety_Point_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/ms-input.h b/bacnet-stack/include/ms-input.h index e79c5181..3dc84dcf 100644 --- a/bacnet-stack/include/ms-input.h +++ b/bacnet-stack/include/ms-input.h @@ -51,7 +51,7 @@ extern "C" { uint32_t instance); int Multistate_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Multistate_Input_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/mso.h b/bacnet-stack/include/mso.h index 6829bd56..659724dc 100644 --- a/bacnet-stack/include/mso.h +++ b/bacnet-stack/include/mso.h @@ -53,7 +53,7 @@ extern "C" { void); int Multistate_Output_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Multistate_Output_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); diff --git a/bacnet-stack/include/rd.h b/bacnet-stack/include/rd.h index 521774e6..18b83a69 100644 --- a/bacnet-stack/include/rd.h +++ b/bacnet-stack/include/rd.h @@ -44,9 +44,9 @@ typedef struct BACnet_Reinitialize_Device_Data { BACNET_ERROR_CODE error_code; } BACNET_REINITIALIZE_DEVICE_DATA; -typedef bool ( +typedef bool( *reinitialize_device_function) ( - BACNET_REINITIALIZE_DEVICE_DATA *rd_data); + BACNET_REINITIALIZE_DEVICE_DATA * rd_data); #ifdef __cplusplus @@ -83,7 +83,6 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup DMRD Device Management-ReinitializeDevice (DM-RD) * @ingroup RDMS * 16.4 ReinitializeDevice Service
@@ -98,5 +97,4 @@ extern "C" { * to executing the service. * */ - #endif diff --git a/bacnet-stack/include/readrange.h b/bacnet-stack/include/readrange.h index 04749970..eeeaf8c0 100644 --- a/bacnet-stack/include/readrange.h +++ b/bacnet-stack/include/readrange.h @@ -103,26 +103,27 @@ typedef enum { #define RR_OVERHEAD 16 #define RR_1ST_SEQ_OVERHEAD 5 -#define RR_INDEX_OVERHEAD 3 /* or 5 if paranoid */ - +#define RR_INDEX_OVERHEAD 3 /* or 5 if paranoid */ + /** Define pointer to function type for handling ReadRange request. This function will take the following parameters: - 1. A pointer to a buffer of at least MAX_APDU bytes to build the response in. - 2. A pointer to a BACNET_READ_RANGE_DATA structure with all the request information in it. The function is responsible for applying the request to the property in question and returning the response. */ - -typedef int (*rr_handler_function) ( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest); + +typedef int ( + *rr_handler_function) ( + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest); /** Structure to return the type of requests a given object property can * accept and the address of the function to handle the request */ - + typedef struct rrpropertyinfo { int RequestTypes; rr_handler_function Handler; - } RR_PROP_INFO; +} RR_PROP_INFO; /** Function template for ReadRange information retrieval function. * A function template; @see device.c for assignment to object types. @@ -131,9 +132,10 @@ typedef struct rrpropertyinfo { * @param pInfo [out] Where to write the response to. * @return True on success, False on error or failure. */ -typedef bool (*rr_info_function) ( - BACNET_READ_RANGE_DATA *pRequest, /* Info on the request */ - RR_PROP_INFO *pInfo); /* Where to write the response to */ +typedef bool( + *rr_info_function) ( + BACNET_READ_RANGE_DATA * pRequest, /* Info on the request */ + RR_PROP_INFO * pInfo); /* Where to write the response to */ int rr_encode_apdu( uint8_t * apdu, @@ -158,7 +160,7 @@ int rr_ack_decode_service_request( uint8_t Send_ReadRange_Request( uint32_t device_id, /* destination device */ BACNET_READ_RANGE_DATA * read_access_data); - + /** @defgroup Trend Trending BIBBs * These BIBBs prescribe the BACnet capabilities required to interoperably @@ -176,4 +178,3 @@ uint8_t Send_ReadRange_Request( */ #endif - diff --git a/bacnet-stack/include/ringbuf.h b/bacnet-stack/include/ringbuf.h index 5f28aa99..a5d45dfe 100644 --- a/bacnet-stack/include/ringbuf.h +++ b/bacnet-stack/include/ringbuf.h @@ -43,11 +43,11 @@ #include struct ring_buffer_t { - uint8_t *data; /* block of memory or array of data */ + uint8_t *data; /* block of memory or array of data */ unsigned element_size; /* how many bytes for each chunk */ unsigned element_count; /* number of chunks of data */ - unsigned head; /* where the writes go */ - unsigned tail; /* where the reads come from */ + unsigned head; /* where the writes go */ + unsigned tail; /* where the reads come from */ }; typedef struct ring_buffer_t RING_BUFFER; @@ -55,9 +55,9 @@ typedef struct ring_buffer_t RING_BUFFER; extern "C" { #endif /* __cplusplus */ - unsigned Ringbuf_Count ( + unsigned Ringbuf_Count( RING_BUFFER const *b); - bool Ringbuf_Full ( + bool Ringbuf_Full( RING_BUFFER const *b); bool Ringbuf_Empty( RING_BUFFER const *b); @@ -67,13 +67,13 @@ extern "C" { RING_BUFFER * b); bool Ringbuf_Put( RING_BUFFER * b, /* ring buffer structure */ - uint8_t *data_element); /* one element to add to the ring */ + uint8_t * data_element); /* one element to add to the ring */ uint8_t *Ringbuf_Alloc( - RING_BUFFER *b); + RING_BUFFER * b); /* Note: element_count must be a power of two */ void Ringbuf_Init( RING_BUFFER * b, /* ring buffer structure */ - uint8_t *data, /* data block or array of data */ + uint8_t * data, /* data block or array of data */ unsigned element_size, /* size of one element in the data block */ unsigned element_count); /* number of elements in the data block */ diff --git a/bacnet-stack/include/rp.h b/bacnet-stack/include/rp.h index dc720308..65eadd88 100644 --- a/bacnet-stack/include/rp.h +++ b/bacnet-stack/include/rp.h @@ -64,7 +64,7 @@ struct BACnet_Read_Access_Data; */ typedef int ( *read_property_function) ( - BACNET_READ_PROPERTY_DATA *rp_data); + BACNET_READ_PROPERTY_DATA * rp_data); #ifdef __cplusplus extern "C" { @@ -106,7 +106,7 @@ extern "C" { int rp_ack_fully_decode_service_request( uint8_t * apdu, int apdu_len, - struct BACnet_Read_Access_Data * read_access_data); + struct BACnet_Read_Access_Data *read_access_data); #ifdef TEST #include "ctest.h" @@ -131,19 +131,15 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup DataShare Data Sharing BIBBs * 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 * value of one property of one BACnet Object. This service allows read access * to any property of any object, whether a BACnet-defined object or not. */ - #endif diff --git a/bacnet-stack/include/rpm.h b/bacnet-stack/include/rpm.h index 6c2aaf33..54f29056 100644 --- a/bacnet-stack/include/rpm.h +++ b/bacnet-stack/include/rpm.h @@ -79,7 +79,7 @@ struct special_property_list_t { typedef void ( *rpm_object_property_lists_function) ( BACNET_OBJECT_TYPE object_type, - struct special_property_list_t *pPropertyList); + struct special_property_list_t * pPropertyList); #ifdef __cplusplus extern "C" { @@ -201,7 +201,6 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup DSRPM Data Sharing -Read Property Multiple Service (DS-RPM) * @ingroup DataShare * 15.7 ReadPropertyMultiple Service
@@ -214,5 +213,4 @@ extern "C" { * A 'Read Access Specification' with the property identifier ALL can be used to * learn the implemented properties of an object along with their values. */ - #endif diff --git a/bacnet-stack/include/trendlog.h b/bacnet-stack/include/trendlog.h index 5538aa49..9c8b85a9 100644 --- a/bacnet-stack/include/trendlog.h +++ b/bacnet-stack/include/trendlog.h @@ -27,7 +27,7 @@ #include #include -#include /* for time_t */ +#include /* for time_t */ #include "bacdef.h" #include "cov.h" #include "rp.h" @@ -38,17 +38,17 @@ extern "C" { #endif /* __cplusplus */ /* Error code for Trend Log storage */ -typedef struct tl_error { - uint16_t usClass; - uint16_t usCode; -} TL_ERROR; + typedef struct tl_error { + uint16_t usClass; + uint16_t usCode; + } TL_ERROR; /* Bit string of up to 32 bits for Trend Log storage */ -typedef struct tl_bits { - uint8_t ucLen; /* bytes used in upper nibble/bits free in lower nibble */ - uint8_t ucStore[4]; -} TL_BITS; + typedef struct tl_bits { + uint8_t ucLen; /* bytes used in upper nibble/bits free in lower nibble */ + uint8_t ucStore[4]; + } TL_BITS; /* Storage structure for Trend Log data * @@ -60,49 +60,49 @@ typedef struct tl_bits { * logging capacity as possible every little byte counts! */ -typedef struct tl_data_record { - time_t tTimeStamp; /* When the event occurred */ - uint8_t ucRecType; /* What type of Event */ - uint8_t ucStatus; /* Optional Status for read value in b0-b2, b7 = 1 if status is used */ - union { - uint8_t ucLogStatus; /* Change of log state flags */ - uint8_t ucBoolean; /* Stored boolean value */ - float fReal; /* Stored floating point value */ - uint32_t ulEnum; /* Stored enumerated value - max 32 bits */ - uint32_t ulUValue; /* Stored unsigned value - max 32 bits */ - int32_t lSValue; /* Stored signed value - max 32 bits */ - TL_BITS Bits; /* Stored bitstring - max 32 bits */ - TL_ERROR Error; /* Two part error class/code combo */ - float fTime; /* Interval value for change of time - seconds */ - } Datum; -} TL_DATA_REC; + typedef struct tl_data_record { + time_t tTimeStamp; /* When the event occurred */ + uint8_t ucRecType; /* What type of Event */ + uint8_t ucStatus; /* Optional Status for read value in b0-b2, b7 = 1 if status is used */ + union { + uint8_t ucLogStatus; /* Change of log state flags */ + uint8_t ucBoolean; /* Stored boolean value */ + float fReal; /* Stored floating point value */ + uint32_t ulEnum; /* Stored enumerated value - max 32 bits */ + uint32_t ulUValue; /* Stored unsigned value - max 32 bits */ + int32_t lSValue; /* Stored signed value - max 32 bits */ + TL_BITS Bits; /* Stored bitstring - max 32 bits */ + TL_ERROR Error; /* Two part error class/code combo */ + float fTime; /* Interval value for change of time - seconds */ + } Datum; + } TL_DATA_REC; -#define TL_T_START_WILD 1 /* Start time is wild carded */ -#define TL_T_STOP_WILD 2 /* Stop Time is wild carded */ +#define TL_T_START_WILD 1 /* Start time is wild carded */ +#define TL_T_STOP_WILD 2 /* Stop Time is wild carded */ -#define TL_MAX_ENTRIES 1000 /* Entries per datalog */ +#define TL_MAX_ENTRIES 1000 /* Entries per datalog */ /* Structure containing config and status info for a Trend Log */ -typedef struct tl_log_info { - bool bEnable; /* Trend log is active when this is true */ - BACNET_DATE_TIME StartTime; /* BACnet format start time */ - time_t tStartTime; /* Local time working copy of start time */ - BACNET_DATE_TIME StopTime; /* BACnet format stop time */ - time_t tStopTime; /* Local time working copy of stop time */ - uint8_t ucTimeFlags; /* Shorthand info on times */ - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE Source; /* Where the data comes from */ - uint32_t ulLogInterval; /* Time between entries in seconds */ - bool bStopWhenFull; /* Log halts when full if true */ - uint32_t ulRecordCount; /* Count of items currently in the buffer */ - uint32_t ulTotalRecordCount; /* Count of all items that have ever been inserted into the buffer */ - BACNET_LOGGING_TYPE LoggingType; /* Polled/cov/triggered */ - bool bAlignIntervals; /* If true align to the clock */ - uint32_t ulIntervalOffset; /* Offset from start of period for taking reading in seconds */ - bool bTrigger; /* Set to 1 to cause a reading to be taken */ - int iIndex; /* Current insertion point */ - time_t tLastDataTime; -} TL_LOG_INFO; + typedef struct tl_log_info { + bool bEnable; /* Trend log is active when this is true */ + BACNET_DATE_TIME StartTime; /* BACnet format start time */ + time_t tStartTime; /* Local time working copy of start time */ + BACNET_DATE_TIME StopTime; /* BACnet format stop time */ + time_t tStopTime; /* Local time working copy of stop time */ + uint8_t ucTimeFlags; /* Shorthand info on times */ + BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE Source; /* Where the data comes from */ + uint32_t ulLogInterval; /* Time between entries in seconds */ + bool bStopWhenFull; /* Log halts when full if true */ + uint32_t ulRecordCount; /* Count of items currently in the buffer */ + uint32_t ulTotalRecordCount; /* Count of all items that have ever been inserted into the buffer */ + BACNET_LOGGING_TYPE LoggingType; /* Polled/cov/triggered */ + bool bAlignIntervals; /* If true align to the clock */ + uint32_t ulIntervalOffset; /* Offset from start of period for taking reading in seconds */ + bool bTrigger; /* Set to 1 to cause a reading to be taken */ + int iIndex; /* Current insertion point */ + time_t tLastDataTime; + } TL_LOG_INFO; /* * Data types associated with a BACnet Log Record. We use these for managing the @@ -120,7 +120,7 @@ typedef struct tl_log_info { #define TL_TYPE_NULL 7 #define TL_TYPE_ERROR 8 #define TL_TYPE_DELTA 9 -#define TL_TYPE_ANY 10 /* We don't support this particular can of worms! */ +#define TL_TYPE_ANY 10 /* We don't support this particular can of worms! */ void Trend_Log_Property_Lists( @@ -143,7 +143,7 @@ typedef struct tl_log_info { uint32_t object_instance); int Trend_Log_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Trend_Log_Write_Property( BACNET_WRITE_PROPERTY_DATA * wp_data); @@ -154,44 +154,44 @@ typedef struct tl_log_info { int iLog, BACNET_LOG_STATUS eStatus, bool bState); - + bool TL_Is_Enabled( int iLog); - + time_t TL_BAC_Time_To_Local( - BACNET_DATE_TIME *SourceTime); + BACNET_DATE_TIME * SourceTime); void TL_Local_Time_To_BAC( - BACNET_DATE_TIME *DestTime, + BACNET_DATE_TIME * DestTime, time_t SourceTime); int TL_encode_entry( - uint8_t *apdu, + uint8_t * apdu, int iLog, int iEntry); - + int TL_encode_by_position( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest); - + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest); + int TL_encode_by_sequence( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest); + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest); int TL_encode_by_time( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest); + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest); bool TrendLogGetRRInfo( - BACNET_READ_RANGE_DATA *pRequest, /* Info on the request */ - RR_PROP_INFO *pInfo); /* Where to put the information */ + BACNET_READ_RANGE_DATA * pRequest, /* Info on the request */ + RR_PROP_INFO * pInfo); /* Where to put the information */ - int rr_trend_log_encode( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest); + int rr_trend_log_encode( + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest); - void trend_log_timer( - uint16_t uSeconds); + void trend_log_timer( + uint16_t uSeconds); #ifdef __cplusplus } diff --git a/bacnet-stack/include/tsm.h b/bacnet-stack/include/tsm.h index 643fe89c..05087cde 100644 --- a/bacnet-stack/include/tsm.h +++ b/bacnet-stack/include/tsm.h @@ -106,7 +106,8 @@ extern "C" { /* use these in tandem */ uint8_t tsm_next_free_invokeID( void); - void tsm_invokeID_set(uint8_t invokeID); + void tsm_invokeID_set( + uint8_t invokeID); /* returns the same invoke ID that was given */ void tsm_set_confirmed_unsegmented_transaction( uint8_t invokeID, diff --git a/bacnet-stack/include/whohas.h b/bacnet-stack/include/whohas.h index e3fd6746..b86da356 100644 --- a/bacnet-stack/include/whohas.h +++ b/bacnet-stack/include/whohas.h @@ -76,7 +76,6 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup DMDOB Device Management-Dynamic Object Binding (DM-DOB) * @ingroup RDMS * 16.9 Who-Has and I-Have Services
diff --git a/bacnet-stack/include/whois.h b/bacnet-stack/include/whois.h index eeb5d407..4b93c49e 100644 --- a/bacnet-stack/include/whois.h +++ b/bacnet-stack/include/whois.h @@ -67,7 +67,6 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup DMDDB Device Management-Dynamic Device Binding (DM-DDB) * @ingroup RDMS * 16.10 Who-Is and I-Am Services
@@ -87,5 +86,4 @@ extern "C" { * issuing the request is on the local network, or from the NPCI if the device * is on a remote network. */ - #endif diff --git a/bacnet-stack/include/wp.h b/bacnet-stack/include/wp.h index b2ce2a02..2179468e 100644 --- a/bacnet-stack/include/wp.h +++ b/bacnet-stack/include/wp.h @@ -102,7 +102,6 @@ extern "C" { #ifdef __cplusplus } #endif /* __cplusplus */ - /** @defgroup DSWP Data Sharing - Write Property Service (DS-WP) * @ingroup DataShare * 15.9 WriteProperty Service
@@ -114,5 +113,4 @@ extern "C" { * to modify a restricted property shall result in the return of an error of * 'Error Class' PROPERTY and 'Error Code' WRITE_ACCESS_DENIED. */ - #endif diff --git a/bacnet-stack/ports/at91sam7s/ai.c b/bacnet-stack/ports/at91sam7s/ai.c index 6c89903e..60b4f962 100644 --- a/bacnet-stack/ports/at91sam7s/ai.c +++ b/bacnet-stack/ports/at91sam7s/ai.c @@ -143,15 +143,14 @@ void Analog_Input_Present_Value_Set( /* return apdu length, or -1 on error */ /* assumption - object has already exists */ int Analog_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -205,8 +204,7 @@ int Analog_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; diff --git a/bacnet-stack/ports/at91sam7s/av.c b/bacnet-stack/ports/at91sam7s/av.c index 05d1b5d4..d08c0503 100644 --- a/bacnet-stack/ports/at91sam7s/av.c +++ b/bacnet-stack/ports/at91sam7s/av.c @@ -181,7 +181,7 @@ char *Analog_Value_Name( /* return apdu len, or -1 on error */ int Analog_Value_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; @@ -195,8 +195,7 @@ int Analog_Value_Read_Property( #endif uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -236,7 +235,8 @@ int Analog_Value_Read_Property( break; case PROP_OUT_OF_SERVICE: #if 0 - object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Analog_Value_Instance_To_Index(rpdata->object_instance); state = Analog_Value_Out_Of_Service[object_index]; #endif apdu_len = encode_application_boolean(&apdu[0], false); @@ -253,7 +253,8 @@ int Analog_Value_Read_Property( /* if no index was specified, then try to encode the entire list */ /* into one packet. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { - object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Analog_Value_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 (Present_Value[object_index][i] == ANALOG_LEVEL_NULL) @@ -282,7 +283,8 @@ int Analog_Value_Read_Property( apdu_len = encode_application_null(&apdu[0]); else { real_value = - Present_Value[object_index][rpdata->array_index - 1]; + Present_Value[object_index][rpdata->array_index - + 1]; apdu_len = encode_application_real(&apdu[0], real_value); } @@ -353,8 +355,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 @@ -420,4 +422,3 @@ bool Analog_Value_Write_Property( return status; } - diff --git a/bacnet-stack/ports/at91sam7s/bi.c b/bacnet-stack/ports/at91sam7s/bi.c index 055db9be..b5008b06 100644 --- a/bacnet-stack/ports/at91sam7s/bi.c +++ b/bacnet-stack/ports/at91sam7s/bi.c @@ -160,7 +160,7 @@ char *Binary_Input_Name( /* return apdu length, or -1 on error */ /* assumption - object already exists, and has been bounds checked */ int Binary_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; @@ -169,8 +169,7 @@ int Binary_Input_Read_Property( BACNET_BINARY_PV value = BINARY_INACTIVE; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -224,8 +223,7 @@ int Binary_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; @@ -233,4 +231,3 @@ int Binary_Input_Read_Property( return apdu_len; } - diff --git a/bacnet-stack/ports/at91sam7s/bv.c b/bacnet-stack/ports/at91sam7s/bv.c index 6b6b74b1..674151fb 100644 --- a/bacnet-stack/ports/at91sam7s/bv.c +++ b/bacnet-stack/ports/at91sam7s/bv.c @@ -154,7 +154,7 @@ char *Binary_Value_Name( /* return apdu len, or -1 on error */ int Binary_Value_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; @@ -164,8 +164,7 @@ int Binary_Value_Read_Property( uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -190,7 +189,8 @@ int Binary_Value_Read_Property( encode_application_enumerated(&apdu[0], OBJECT_BINARY_VALUE); break; case PROP_PRESENT_VALUE: - present_value = Binary_Value_Present_Value(rpdata->object_instance); + present_value = + Binary_Value_Present_Value(rpdata->object_instance); apdu_len = encode_application_enumerated(&apdu[0], present_value); break; case PROP_STATUS_FLAGS: @@ -221,8 +221,7 @@ int Binary_Value_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; @@ -266,8 +265,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; @@ -312,4 +311,3 @@ bool Binary_Value_Write_Property( return status; } - diff --git a/bacnet-stack/ports/at91sam7s/device.c b/bacnet-stack/ports/at91sam7s/device.c index 3da0ad99..301fe0f3 100644 --- a/bacnet-stack/ports/at91sam7s/device.c +++ b/bacnet-stack/ports/at91sam7s/device.c @@ -51,12 +51,11 @@ static uint32_t Object_Instance_Number = 12345; static char My_Object_Name[32] = "ARM7 Device"; static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL; -static BACNET_REINITIALIZED_STATE Reinitialize_State = - BACNET_REINIT_IDLE; +static BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_IDLE; /* forward prototypes */ int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Device_Write_Property_Local( BACNET_WRITE_PROPERTY_DATA * wp_data); @@ -70,55 +69,30 @@ static struct object_functions { read_property_function Object_Read_Property; write_property_function Object_Write_Property; rpm_property_lists_function Object_RPM_List; -} Object_Table[] = -{ - {OBJECT_DEVICE, - NULL,/* don't init - recursive! */ - Device_Count, - Device_Index_To_Instance, - Device_Valid_Object_Instance_Number, - Device_Name, - Device_Read_Property_Local, - Device_Write_Property_Local, - Device_Property_Lists}, - {OBJECT_ANALOG_INPUT, - Analog_Input_Init, - Analog_Input_Count, - Analog_Input_Index_To_Instance, - Analog_Input_Valid_Instance, - Analog_Input_Name, - Analog_Input_Read_Property, - NULL, - Analog_Input_Property_Lists}, - {OBJECT_ANALOG_VALUE, - Analog_Value_Init, - Analog_Value_Count, - Analog_Value_Index_To_Instance, - Analog_Value_Valid_Instance, - Analog_Value_Name, - Analog_Value_Read_Property, - Analog_Value_Write_Property, - Analog_Value_Property_Lists}, - {OBJECT_BINARY_INPUT, - Binary_Input_Init, - Binary_Input_Count, - Binary_Input_Index_To_Instance, - Binary_Input_Valid_Instance, - Binary_Input_Name, - Binary_Input_Read_Property, - NULL, - Binary_Input_Property_Lists}, - {OBJECT_BINARY_VALUE, - Binary_Value_Init, - Binary_Value_Count, - Binary_Value_Index_To_Instance, - Binary_Value_Valid_Instance, - Binary_Value_Name, - Binary_Value_Read_Property, - Binary_Value_Write_Property, - Binary_Value_Property_Lists}, - - {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL} +} Object_Table[] = { + { + OBJECT_DEVICE, NULL, /* don't init - recursive! */ + Device_Count, Device_Index_To_Instance, + Device_Valid_Object_Instance_Number, Device_Name, + Device_Read_Property_Local, Device_Write_Property_Local, + Device_Property_Lists}, { + OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count, + Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance, + Analog_Input_Name, Analog_Input_Read_Property, NULL, + Analog_Input_Property_Lists}, { + OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count, + Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance, + Analog_Value_Name, Analog_Value_Read_Property, + Analog_Value_Write_Property, Analog_Value_Property_Lists}, { + OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count, + Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance, + Binary_Input_Name, Binary_Input_Read_Property, NULL, + Binary_Input_Property_Lists}, { + OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count, + Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance, + Binary_Value_Name, Binary_Value_Read_Property, + Binary_Value_Write_Property, Binary_Value_Property_Lists}, { + MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL} }; /* These three arrays are used by the ReadPropertyMultiple handler */ @@ -176,7 +150,7 @@ void Device_Property_Lists( /* Encodes the property APDU and returns the length, or sets the error, and returns -1 */ int Device_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = -1; unsigned index = 0; @@ -294,10 +268,8 @@ void Device_Objects_Property_List( pObject = &Object_Table[index]; } if (found && object_property_list) { - object_property_list( - &pPropertyList->Required.pList, - &pPropertyList->Optional.pList, - &pPropertyList->Proprietary.pList); + object_property_list(&pPropertyList->Required.pList, + &pPropertyList->Optional.pList, &pPropertyList->Proprietary.pList); } /* fill the count */ if (pPropertyList->Required.pList) { @@ -328,7 +300,7 @@ unsigned Device_Object_List_Count( void) { unsigned count = 0; /* number of objects */ - unsigned index = 0; /* loop counter */ + unsigned index = 0; /* loop counter */ struct object_functions *pObject = NULL; /* initialize the default return values */ @@ -363,8 +335,7 @@ bool Device_Object_List_Identifier( /* initialize the default return values */ pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { - if (pObject->Object_Count && - pObject->Object_Index_To_Instance) { + if (pObject->Object_Count && pObject->Object_Index_To_Instance) { object_index -= count; count = pObject->Object_Count(); if (object_index < count) { @@ -425,8 +396,7 @@ char *Device_Valid_Object_Id( pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { - if ((pObject->Object_Type == object_type) && - (pObject->Object_Name)) { + if ((pObject->Object_Type == object_type) && (pObject->Object_Name)) { name = pObject->Object_Name(object_instance); break; } @@ -437,7 +407,8 @@ char *Device_Valid_Object_Id( return name; } -unsigned Device_Count(void) +unsigned Device_Count( + void) { return 1; } @@ -459,7 +430,7 @@ char *Device_Name( } bool Device_Reinitialize( - BACNET_REINITIALIZE_DEVICE_DATA *rd_data) + BACNET_REINITIALIZE_DEVICE_DATA * rd_data) { bool status = false; @@ -547,7 +518,7 @@ int Device_Set_System_Status( BACNET_DEVICE_STATUS status, bool local) { - int result = 0; /*return value - 0 = ok, -1 = bad value, -2 = not allowed */ + int result = 0; /*return value - 0 = ok, -1 = bad value, -2 = not allowed */ if (status < MAX_DEVICE_STATUS) { System_Status = status; @@ -588,7 +559,7 @@ uint32_t Device_Database_Revision( /* return the length of the apdu encoded or -1 for error */ int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ int len = 0; /* apdu len intermediate value */ @@ -604,8 +575,7 @@ int Device_Read_Property_Local( struct object_functions *pObject = NULL; bool found = false; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } @@ -702,8 +672,7 @@ int Device_Read_Property_Local( i = 0; pObject = &Object_Table[i]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { - if ((pObject->Object_Count) && - (pObject->Object_Count() > 0)) { + if ((pObject->Object_Count) && (pObject->Object_Count() > 0)) { bitstring_set_bit(&bit_string, pObject->Object_Type, true); } i++; @@ -722,8 +691,9 @@ int Device_Read_Property_Local( /* your maximum APDU size. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 1; i <= count; i++) { - found = Device_Object_List_Identifier(i, &object_type, - &instance); + found = + Device_Object_List_Identifier(i, &object_type, + &instance); if (found) { len = encode_application_object_id(&apdu[apdu_len], @@ -733,7 +703,8 @@ int Device_Read_Property_Local( /* can we all fit into the APDU? */ if ((apdu_len + len) >= MAX_APDU) { 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 = -1; break; } @@ -746,8 +717,8 @@ int Device_Read_Property_Local( } } } else { - if (Device_Object_List_Identifier(rpdata->array_index, &object_type, - &instance)) + if (Device_Object_List_Identifier(rpdata->array_index, + &object_type, &instance)) apdu_len = encode_application_object_id(&apdu[0], object_type, instance); @@ -825,8 +796,7 @@ int Device_Read_Property_Local( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->object_property != PROP_OBJECT_LIST) && + if ((apdu_len >= 0) && (rpdata->object_property != PROP_OBJECT_LIST) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -858,8 +828,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 { @@ -918,11 +888,13 @@ bool Device_Write_Property_Local( the device. */ } else { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; + wp_data->error_code = + ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED; + wp_data->error_code = + ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED; } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; diff --git a/bacnet-stack/ports/at91sam7s/main.c b/bacnet-stack/ports/at91sam7s/main.c index 8010561c..40336e5b 100644 --- a/bacnet-stack/ports/at91sam7s/main.c +++ b/bacnet-stack/ports/at91sam7s/main.c @@ -147,8 +147,7 @@ static inline void bacnet_init( /* set up our confirmed service unrecognized service handler - required! */ apdu_set_unrecognized_service_handler_handler (handler_unrecognized_service); - apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS, - handler_who_has); + apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS, handler_who_has); /* we need to handle who-is to support dynamic device binding */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* Set the handlers for any confirmed services that we support. */ diff --git a/bacnet-stack/ports/atmega168/ai.c b/bacnet-stack/ports/atmega168/ai.c index 558b2d3e..3eea933d 100644 --- a/bacnet-stack/ports/atmega168/ai.c +++ b/bacnet-stack/ports/atmega168/ai.c @@ -155,8 +155,7 @@ int Analog_Input_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; diff --git a/bacnet-stack/ports/atmega168/av.c b/bacnet-stack/ports/atmega168/av.c index 04b44225..af379e4f 100644 --- a/bacnet-stack/ports/atmega168/av.c +++ b/bacnet-stack/ports/atmega168/av.c @@ -152,8 +152,7 @@ int Analog_Value_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; diff --git a/bacnet-stack/ports/atmega168/bv.c b/bacnet-stack/ports/atmega168/bv.c index fd3f93ac..f0b15b68 100644 --- a/bacnet-stack/ports/atmega168/bv.c +++ b/bacnet-stack/ports/atmega168/bv.c @@ -169,8 +169,7 @@ int Binary_Value_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; @@ -207,8 +206,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 3b7b547c..c8cb3c3f 100644 --- a/bacnet-stack/ports/atmega168/device.c +++ b/bacnet-stack/ports/atmega168/device.c @@ -337,8 +337,7 @@ int Device_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (property != PROP_OBJECT_LIST) && + if ((apdu_len >= 0) && (property != PROP_OBJECT_LIST) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -372,8 +371,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/atmega168/device.h b/bacnet-stack/ports/atmega168/device.h index 24d6407e..6516d6bc 100644 --- a/bacnet-stack/ports/atmega168/device.h +++ b/bacnet-stack/ports/atmega168/device.h @@ -161,13 +161,13 @@ extern "C" { BACNET_WRITE_PROPERTY_DATA * wp_data, BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code); - + bool DeviceGetRRInfo( - uint32_t Object, /* Which particular object - obviously not important for device object */ - BACNET_PROPERTY_ID Property, /* Which property */ - RR_PROP_INFO *pInfo, /* Where to put the information */ - BACNET_ERROR_CLASS *error_class, - BACNET_ERROR_CODE *error_code); + uint32_t Object, /* Which particular object - obviously not important for device object */ + BACNET_PROPERTY_ID Property, /* Which property */ + RR_PROP_INFO * pInfo, /* Where to put the information */ + BACNET_ERROR_CLASS * error_class, + BACNET_ERROR_CODE * error_code); #ifdef __cplusplus diff --git a/bacnet-stack/ports/atmega8/ai.c b/bacnet-stack/ports/atmega8/ai.c index 43494d58..76cbd213 100644 --- a/bacnet-stack/ports/atmega8/ai.c +++ b/bacnet-stack/ports/atmega8/ai.c @@ -153,8 +153,7 @@ int Analog_Input_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; diff --git a/bacnet-stack/ports/atmega8/av.c b/bacnet-stack/ports/atmega8/av.c index 04b44225..af379e4f 100644 --- a/bacnet-stack/ports/atmega8/av.c +++ b/bacnet-stack/ports/atmega8/av.c @@ -152,8 +152,7 @@ int Analog_Value_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; diff --git a/bacnet-stack/ports/atmega8/bv.c b/bacnet-stack/ports/atmega8/bv.c index fd3f93ac..f0b15b68 100644 --- a/bacnet-stack/ports/atmega8/bv.c +++ b/bacnet-stack/ports/atmega8/bv.c @@ -169,8 +169,7 @@ int Binary_Value_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; @@ -207,8 +206,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/atmega8/device.c b/bacnet-stack/ports/atmega8/device.c index 5122a3e7..d2c5819d 100644 --- a/bacnet-stack/ports/atmega8/device.c +++ b/bacnet-stack/ports/atmega8/device.c @@ -328,8 +328,7 @@ int Device_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (property != PROP_OBJECT_LIST) && + if ((apdu_len >= 0) && (property != PROP_OBJECT_LIST) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/ai.c b/bacnet-stack/ports/bdk-atxx4-mstp/ai.c index 43bfdc67..f95c31f0 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/ai.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/ai.c @@ -146,20 +146,19 @@ void Analog_Input_Present_Value_Set( /* return apdu length, or -1 on error */ /* assumption - object already exists */ int Analog_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; uint8_t *apdu = NULL; - if ((rpdata == NULL) || - (rpdata->application_data == NULL) || + if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { return 0; } apdu = rpdata->application_data; switch (rpdata->object_property) { - /* object id, object name, object type are handled in Device object */ + /* object id, object name, object type are handled in Device object */ case PROP_PRESENT_VALUE: apdu_len = encode_application_real(&apdu[0], @@ -190,8 +189,7 @@ int Analog_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/av.c b/bacnet-stack/ports/bdk-atxx4-mstp/av.c index 918ebd8a..b786eed1 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/av.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/av.c @@ -196,7 +196,7 @@ char *Analog_Value_Name( /* return apdu len, or -1 on error */ int Analog_Value_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; @@ -214,7 +214,7 @@ int Analog_Value_Read_Property( } apdu = rpdata->application_data; switch (rpdata->object_property) { - /* object id, object name, object type are handled in Device object */ + /* object id, object name, object type are handled in Device object */ case PROP_PRESENT_VALUE: real_value = Analog_Value_Present_Value(rpdata->object_instance); apdu_len = encode_application_real(&apdu[0], real_value); @@ -233,7 +233,8 @@ int Analog_Value_Read_Property( break; case PROP_OUT_OF_SERVICE: #if 0 - object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Analog_Value_Instance_To_Index(rpdata->object_instance); state = Analog_Value_Out_Of_Service[object_index]; #endif apdu_len = encode_application_boolean(&apdu[0], false); @@ -272,14 +273,16 @@ int Analog_Value_Read_Property( } } } else { - object_index = Analog_Value_Instance_To_Index(rpdata->object_instance); + object_index = + Analog_Value_Instance_To_Index(rpdata->object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { if (Present_Value[object_index][rpdata->array_index - 1] == ANALOG_LEVEL_NULL) apdu_len = encode_application_null(&apdu[0]); else { real_value = - Present_Value[object_index][rpdata->array_index - 1]; + Present_Value[object_index][rpdata->array_index - + 1]; apdu_len = encode_application_real(&apdu[0], real_value); } @@ -336,13 +339,12 @@ bool Analog_Value_Write_Property( /* FIXME: len == 0: unable to decode? */ switch (wp_data->object_property) { case PROP_PRESENT_VALUE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, + &wp_data->error_class, &wp_data->error_code); if (status) { - status = Analog_Value_Present_Value_Set( - wp_data->object_instance, + status = + Analog_Value_Present_Value_Set(wp_data->object_instance, value.type.Real, wp_data->priority); if (!status) { if (wp_data->priority == 6) { @@ -370,10 +372,9 @@ bool Analog_Value_Write_Property( break; #if 0 case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bi.c b/bacnet-stack/ports/bdk-atxx4-mstp/bi.c index ead7c3f8..f1a7d585 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bi.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bi.c @@ -173,7 +173,7 @@ char *Binary_Input_Name( /* return apdu length, or -1 on error */ /* assumption - object already exists, and has been bounds checked */ int Binary_Input_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; @@ -187,7 +187,7 @@ int Binary_Input_Read_Property( } apdu = rpdata->application_data; switch (rpdata->object_property) { - /* object id, object name, object type are handled in Device object */ + /* object id, object name, object type are handled in Device object */ case PROP_PRESENT_VALUE: value = Binary_Input_Present_Value(rpdata->object_instance); apdu_len = encode_application_enumerated(&apdu[0], value); @@ -219,8 +219,7 @@ int Binary_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c index 9cd3b422..8fefaf90 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c @@ -201,10 +201,10 @@ static void Binary_Output_Level_Sync( bool Binary_Output_Present_Value_Set( uint32_t instance, BACNET_BINARY_PV binary_value, - unsigned priority) /* 0..15 */ -{ + unsigned priority) +{ /* 0..15 */ bool status = false; - + if (instance < MAX_BINARY_OUTPUTS) { if (priority < BACNET_MAX_PRIORITY) { Binary_Output_Level[instance][priority] = (uint8_t) binary_value; @@ -215,7 +215,7 @@ bool Binary_Output_Present_Value_Set( status = true; } } - + return status; } @@ -239,8 +239,7 @@ void Binary_Output_Out_Of_Service_Set( if (instance < MAX_BINARY_OUTPUTS) { Out_Of_Service[instance] = flag; seeprom_bytes_write(NV_SEEPROM_BINARY_OUTPUT(instance, - NV_SEEPROM_BO_OUT_OF_SERVICE), &Out_Of_Service[instance], - 1); + NV_SEEPROM_BO_OUT_OF_SERVICE), &Out_Of_Service[instance], 1); } } @@ -260,7 +259,7 @@ char *Binary_Output_Name( /* return apdu len, or -1 on error */ int Binary_Output_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int len = 0; int apdu_len = 0; /* return value */ @@ -278,9 +277,10 @@ int Binary_Output_Read_Property( } apdu = rpdata->application_data; switch (rpdata->object_property) { - /* object id, object name, object type are handled in Device object */ + /* object id, object name, object type are handled in Device object */ case PROP_PRESENT_VALUE: - present_value = Binary_Output_Present_Value(rpdata->object_instance); + present_value = + Binary_Output_Present_Value(rpdata->object_instance); apdu_len = encode_application_enumerated(&apdu[0], present_value); break; case PROP_STATUS_FLAGS: @@ -298,12 +298,14 @@ int Binary_Output_Read_Property( encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: - object_index = Binary_Output_Instance_To_Index(rpdata->object_instance); + object_index = + Binary_Output_Instance_To_Index(rpdata->object_instance); state = Out_Of_Service[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; case PROP_POLARITY: - object_index = Binary_Output_Instance_To_Index(rpdata->object_instance); + object_index = + Binary_Output_Instance_To_Index(rpdata->object_instance); apdu_len = encode_application_enumerated(&apdu[0], Polarity[object_index]); @@ -343,7 +345,8 @@ int Binary_Output_Read_Property( Binary_Output_Instance_To_Index(rpdata->object_instance); if (rpdata->array_index <= BACNET_MAX_PRIORITY) { present_value = - Binary_Output_Level[object_index][rpdata->array_index - 1]; + Binary_Output_Level[object_index][rpdata->array_index - + 1]; if (present_value == BINARY_NULL) { apdu_len = encode_application_null(&apdu[apdu_len]); } else { @@ -379,8 +382,7 @@ int Binary_Output_Read_Property( 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->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -408,10 +410,9 @@ bool Binary_Output_Write_Property( /* FIXME: len == 0: unable to decode? */ switch (wp_data->object_property) { case PROP_PRESENT_VALUE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); if (status) { priority = wp_data->priority; /* Command priority 6 is reserved for use by Minimum On/Off @@ -422,8 +423,7 @@ bool Binary_Output_Write_Property( (value.type.Enumerated <= MAX_BINARY_PV)) { level = (BACNET_BINARY_PV) value.type.Enumerated; priority--; - Binary_Output_Present_Value_Set( - wp_data->object_instance, + Binary_Output_Present_Value_Set(wp_data->object_instance, level, priority); } else if (priority == 6) { /* Command priority 6 is reserved for use by Minimum On/Off @@ -438,18 +438,16 @@ bool Binary_Output_Write_Property( wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } } else { - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_NULL, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, + &wp_data->error_class, &wp_data->error_code); if (status) { level = BINARY_NULL; 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 @@ -466,26 +464,22 @@ bool Binary_Output_Write_Property( } break; case PROP_OUT_OF_SERVICE: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); if (status) { - Binary_Output_Out_Of_Service_Set( - wp_data->object_instance, + Binary_Output_Out_Of_Service_Set(wp_data->object_instance, value.type.Boolean); Binary_Output_Level_Sync(wp_data->object_instance); } break; case PROP_POLARITY: - status = WPValidateArgType(&value, - BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, - &wp_data->error_code); + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Enumerated < MAX_POLARITY) { - Binary_Output_Polarity_Set( - wp_data->object_instance, + Binary_Output_Polarity_Set(wp_data->object_instance, value.type.Enumerated); Binary_Output_Level_Sync(wp_data->object_instance); } else { diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/device.c b/bacnet-stack/ports/bdk-atxx4-mstp/device.c index 2f1a7e96..539dba5a 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/device.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/device.c @@ -48,7 +48,7 @@ /* forward prototype */ int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA *rpdata); + BACNET_READ_PROPERTY_DATA * rpdata); bool Device_Write_Property_Local( BACNET_WRITE_PROPERTY_DATA * wp_data); @@ -62,55 +62,30 @@ static struct object_functions { read_property_function Object_Read_Property; write_property_function Object_Write_Property; rpm_property_lists_function Object_RPM_List; -} Object_Table[] = -{ - {OBJECT_DEVICE, - NULL,/* don't init - recursive! */ - Device_Count, - Device_Index_To_Instance, - Device_Valid_Object_Instance_Number, - Device_Name, - Device_Read_Property_Local, - Device_Write_Property_Local, - Device_Property_Lists}, - {OBJECT_ANALOG_INPUT, - Analog_Input_Init, - Analog_Input_Count, - Analog_Input_Index_To_Instance, - Analog_Input_Valid_Instance, - Analog_Input_Name, - Analog_Input_Read_Property, - NULL, - Analog_Input_Property_Lists}, - {OBJECT_ANALOG_VALUE, - Analog_Value_Init, - Analog_Value_Count, - Analog_Value_Index_To_Instance, - Analog_Value_Valid_Instance, - Analog_Value_Name, - Analog_Value_Read_Property, - Analog_Value_Write_Property, - Analog_Value_Property_Lists}, - {OBJECT_BINARY_INPUT, - Binary_Input_Init, - Binary_Input_Count, - Binary_Input_Index_To_Instance, - Binary_Input_Valid_Instance, - Binary_Input_Name, - Binary_Input_Read_Property, - NULL, - Binary_Input_Property_Lists}, - {OBJECT_BINARY_OUTPUT, - Binary_Output_Init, - Binary_Output_Count, - Binary_Output_Index_To_Instance, - Binary_Output_Valid_Instance, - Binary_Output_Name, - Binary_Output_Read_Property, - Binary_Output_Write_Property, - Binary_Output_Property_Lists}, - - {MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL} +} Object_Table[] = { + { + OBJECT_DEVICE, NULL, /* don't init - recursive! */ + Device_Count, Device_Index_To_Instance, + Device_Valid_Object_Instance_Number, Device_Name, + Device_Read_Property_Local, Device_Write_Property_Local, + Device_Property_Lists}, { + OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count, + Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance, + Analog_Input_Name, Analog_Input_Read_Property, NULL, + Analog_Input_Property_Lists}, { + OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count, + Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance, + Analog_Value_Name, Analog_Value_Read_Property, + Analog_Value_Write_Property, Analog_Value_Property_Lists}, { + OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count, + Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance, + Binary_Input_Name, Binary_Input_Read_Property, NULL, + Binary_Input_Property_Lists}, { + OBJECT_BINARY_OUTPUT, Binary_Output_Init, Binary_Output_Count, + Binary_Output_Index_To_Instance, Binary_Output_Valid_Instance, + Binary_Output_Name, Binary_Output_Read_Property, + Binary_Output_Write_Property, Binary_Output_Property_Lists}, { + MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL} }; /* note: you really only need to define variables for @@ -120,8 +95,7 @@ static struct object_functions { static uint32_t Object_Instance_Number; static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL; -static BACNET_REINITIALIZED_STATE Reinitialize_State = - BACNET_REINIT_IDLE; +static BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_IDLE; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Device_Properties_Required[] = { @@ -159,7 +133,7 @@ static const int Device_Properties_Proprietary[] = { -1 }; -static struct object_functions * Device_Objects_Find_Functions( +static struct object_functions *Device_Objects_Find_Functions( BACNET_OBJECT_TYPE Object_Type) { struct object_functions *pObject = NULL; @@ -168,18 +142,18 @@ static struct object_functions * Device_Objects_Find_Functions( while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { /* handle each object type */ if (pObject->Object_Type == Object_Type) { - return(pObject); + return (pObject); } pObject++; } - return(NULL); + return (NULL); } static int Read_Property_Common( struct object_functions *pObject, - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = -1; BACNET_CHARACTER_STRING char_string; @@ -199,9 +173,8 @@ static int Read_Property_Common( rpdata->object_instance = Object_Instance_Number; } apdu_len = - encode_application_object_id(&apdu[0], - rpdata->object_type, - rpdata->object_instance); + encode_application_object_id(&apdu[0], rpdata->object_type, + rpdata->object_instance); break; case PROP_OBJECT_NAME: if (pObject->Object_Name) { @@ -212,8 +185,8 @@ static int Read_Property_Common( encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = encode_application_enumerated(&apdu[0], - rpdata->object_type); + apdu_len = + encode_application_enumerated(&apdu[0], rpdata->object_type); break; default: if (pObject->Object_Read_Property) { @@ -228,7 +201,7 @@ static int Read_Property_Common( /* Encodes the property APDU and returns the length, or sets the error, and returns -1 */ int Device_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = -1; struct object_functions *pObject = NULL; @@ -313,21 +286,22 @@ void Device_Objects_Property_List( pObject = Device_Objects_Find_Functions(object_type); if ((pObject != NULL) && (pObject->Object_RPM_List != NULL)) { - pObject->Object_RPM_List( - &pPropertyList->Required.pList, - &pPropertyList->Optional.pList, - &pPropertyList->Proprietary.pList); + pObject->Object_RPM_List(&pPropertyList->Required.pList, + &pPropertyList->Optional.pList, &pPropertyList->Proprietary.pList); } /* Fetch the counts if available otherwise zero them */ - pPropertyList->Required.count = pPropertyList->Required.pList == NULL - ? 0 : property_list_count(pPropertyList->Required.pList); + pPropertyList->Required.count = + pPropertyList->Required.pList == + NULL ? 0 : property_list_count(pPropertyList->Required.pList); - pPropertyList->Optional.count = pPropertyList->Optional.pList == NULL - ? 0 : property_list_count(pPropertyList->Optional.pList); + pPropertyList->Optional.count = + pPropertyList->Optional.pList == + NULL ? 0 : property_list_count(pPropertyList->Optional.pList); - pPropertyList->Proprietary.count = pPropertyList->Proprietary.pList == NULL - ? 0 : property_list_count(pPropertyList->Proprietary.pList); + pPropertyList->Proprietary.count = + pPropertyList->Proprietary.pList == + NULL ? 0 : property_list_count(pPropertyList->Proprietary.pList); return; } @@ -347,7 +321,8 @@ void Device_Property_Lists( return; } -unsigned Device_Count(void) +unsigned Device_Count( + void) { return 1; } @@ -363,7 +338,7 @@ char *Device_Name( { uint8_t encoding = 0; uint8_t length = 0; - static char name[NV_EEPROM_DEVICE_NAME_SIZE+1] = ""; + static char name[NV_EEPROM_DEVICE_NAME_SIZE + 1] = ""; char *pName = NULL; if (object_instance == Object_Instance_Number) { @@ -372,14 +347,12 @@ char *Device_Name( eeprom_bytes_read(NV_EEPROM_DEVICE_NAME_0, (uint8_t *) & name, NV_EEPROM_DEVICE_NAME_SIZE); if ((encoding >= MAX_CHARACTER_STRING_ENCODING) || - (length > NV_EEPROM_DEVICE_NAME_SIZE) || - (length < 1)) { + (length > NV_EEPROM_DEVICE_NAME_SIZE) || (length < 1)) { encoding = CHARACTER_ANSI_X34; - eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_ENCODING, - &encoding, 1); + eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_ENCODING, &encoding, 1); sprintf(name, "DEVICE-%lu", Object_Instance_Number); - eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_0, - (uint8_t *) & name[0], NV_EEPROM_DEVICE_NAME_SIZE); + eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_0, (uint8_t *) & name[0], + NV_EEPROM_DEVICE_NAME_SIZE); length = strlen(name); eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_LENGTH, &length, 1); } @@ -395,7 +368,7 @@ char *Device_Name( } bool Device_Reinitialize( - BACNET_REINITIALIZE_DEVICE_DATA *rd_data) + BACNET_REINITIALIZE_DEVICE_DATA * rd_data) { bool status = false; @@ -438,7 +411,7 @@ void Device_Init( (uint8_t *) & Object_Instance_Number, sizeof(Object_Instance_Number)); } - (void)Device_Name(Object_Instance_Number); + (void) Device_Name(Object_Instance_Number); } /* methods to manipulate the data */ @@ -549,8 +522,7 @@ bool Device_Object_List_Identifier( /* initialize the default return values */ pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { - if (pObject->Object_Count && - pObject->Object_Index_To_Instance) { + if (pObject->Object_Count && pObject->Object_Index_To_Instance) { object_index -= count; count = pObject->Object_Count(); if (object_index < count) { @@ -617,7 +589,7 @@ char *Device_Valid_Object_Id( /* return the length of the apdu encoded or -1 for error */ int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA *rpdata) + BACNET_READ_PROPERTY_DATA * rpdata) { int apdu_len = 0; /* return value */ int len = 0; /* apdu len intermediate value */ @@ -652,8 +624,7 @@ int Device_Read_Property_Local( encode_application_character_string(&apdu[0], &char_string); break; case PROP_VENDOR_IDENTIFIER: - apdu_len = - encode_application_unsigned(&apdu[0], BACNET_VENDOR_ID); + apdu_len = encode_application_unsigned(&apdu[0], BACNET_VENDOR_ID); break; case PROP_MODEL_NAME: characterstring_init_ansi(&char_string, "bdk-atxx4-mstp"); @@ -671,12 +642,10 @@ int Device_Read_Property_Local( encode_application_character_string(&apdu[0], &char_string); break; case PROP_PROTOCOL_VERSION: - apdu_len = - encode_application_unsigned(&apdu[0], 1); + apdu_len = encode_application_unsigned(&apdu[0], 1); break; case PROP_PROTOCOL_REVISION: - apdu_len = - encode_application_unsigned(&apdu[0], 5); + apdu_len = encode_application_unsigned(&apdu[0], 5); break; case PROP_PROTOCOL_SERVICES_SUPPORTED: /* Note: list of services that are executed, not initiated. */ @@ -701,8 +670,7 @@ int Device_Read_Property_Local( i = 0; pObject = &Object_Table[i]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { - if ((pObject->Object_Count) && - (pObject->Object_Count() > 0)) { + if ((pObject->Object_Count) && (pObject->Object_Count() > 0)) { bitstring_set_bit(&bit_string, pObject->Object_Type, true); } pObject++; @@ -730,7 +698,8 @@ int Device_Read_Property_Local( /* can we all fit into the APDU? */ if ((apdu_len + len) >= MAX_APDU) { 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 = -1; break; } @@ -743,8 +712,8 @@ int Device_Read_Property_Local( } } } else { - if (Device_Object_List_Identifier(rpdata->array_index, &object_type, - &instance)) + if (Device_Object_List_Identifier(rpdata->array_index, + &object_type, &instance)) apdu_len = encode_application_object_id(&apdu[0], object_type, instance); @@ -803,8 +772,7 @@ int Device_Read_Property_Local( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (rpdata->object_property != PROP_OBJECT_LIST) && + if ((apdu_len >= 0) && (rpdata->object_property != PROP_OBJECT_LIST) && (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -831,8 +799,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 { @@ -892,18 +860,20 @@ bool Device_Write_Property_Local( eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_LENGTH, &small_length, 1); pCharString = - characterstring_value(&value. - type.Character_String); + characterstring_value(&value.type. + Character_String); eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_0, (uint8_t *) pCharString, length); status = true; } else { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED; + wp_data->error_code = + ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED; } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; + wp_data->error_code = + ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/led.c b/bacnet-stack/ports/bdk-atxx4-mstp/led.c index 4fcfd12f..9750b559 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/led.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/led.c @@ -151,8 +151,8 @@ void led_off_delay( void led_task( void) { - uint8_t i; /* loop counter */ - + uint8_t i; /* loop counter */ + for (i = 0; i < MAX_LEDS; i++) { if (timer_interval_expired(&Off_Delay_Timer[i])) { timer_interval_no_expire(&Off_Delay_Timer[i]); @@ -169,8 +169,8 @@ void led_task( void led_init( void) { - uint8_t i; /* loop counter */ - + uint8_t i; /* loop counter */ + /* configure the port pins as outputs */ BIT_SET(DDRC, DDC7); BIT_SET(DDRC, DDC6); @@ -178,5 +178,5 @@ void led_init( BIT_SET(DDRD, DDD6); for (i = 0; i < MAX_LEDS; i++) { led_off(i); - } + } } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/main.c b/bacnet-stack/ports/bdk-atxx4-mstp/main.c index 62e837aa..f004da5d 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/main.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/main.c @@ -102,10 +102,8 @@ static void bacnet_init( apdu_set_unrecognized_service_handler_handler (handler_unrecognized_service); /* we need to handle who-is to support dynamic device binding */ - apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, - handler_who_is); - apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS, - handler_who_has); + apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); + apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS, handler_who_has); /* Set the handlers for any confirmed services that we support. */ /* We must implement read property - it's required! */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c b/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c index ccb9d604..fcfbc85e 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/rs485.c @@ -51,12 +51,14 @@ static FIFO_BUFFER Receive_Buffer; static struct etimer Silence_Timer; -bool rs485_silence_time_elapsed(uint32_t milliseconds) +bool rs485_silence_time_elapsed( + uint32_t milliseconds) { return timer_elapsed_milliseconds(&Silence_Timer, milliseconds); } -void rs485_silence_time_reset(void) +void rs485_silence_time_reset( + void) { timer_elapsed_start(&Silence_Timer); } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/rs485.h b/bacnet-stack/ports/bdk-atxx4-mstp/rs485.h index 290e1a7d..7d3146af 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/rs485.h +++ b/bacnet-stack/ports/bdk-atxx4-mstp/rs485.h @@ -60,8 +60,10 @@ extern "C" { void rs485_turnaround_delay( void); - void rs485_silence_time_reset(void); - bool rs485_silence_time_elapsed(uint32_t milliseconds); + void rs485_silence_time_reset( + void); + bool rs485_silence_time_elapsed( + uint32_t milliseconds); #ifdef __cplusplus } diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/seeprom.c b/bacnet-stack/ports/bdk-atxx4-mstp/seeprom.c index 76229f7c..e623f035 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/seeprom.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/seeprom.c @@ -425,13 +425,13 @@ int seeprom_bytes_write_page( * first byte of the same page. **************************************************************************/ int seeprom_bytes_write( - uint16_t off, /* SEEPROM starting memory address */ - uint8_t * buf, /* data to send */ - int len) /* number of bytes of data */ -{ + uint16_t off, /* SEEPROM starting memory address */ + uint8_t * buf, /* data to send */ + int len) +{ /* number of bytes of data */ int status = 0; int rv = 0; - + while (len) { status = seeprom_bytes_write_page(off, buf, len); if (status <= 0) { diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/timer.c b/bacnet-stack/ports/bdk-atxx4-mstp/timer.c index 9d5bdf96..3671ec09 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/timer.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/timer.c @@ -52,11 +52,11 @@ uint32_t timer_elapsed_time( { uint32_t now = timer_milliseconds(); uint32_t delta = 0; - + if (t) { delta = now - t->start; } - + return delta; } @@ -94,13 +94,13 @@ bool timer_elapsed_milliseconds( * Notes: none *************************************************************************/ bool timer_elapsed_seconds( - struct etimer *t, + struct etimer * t, uint32_t seconds) { uint32_t milliseconds = seconds; milliseconds *= 1000L; - + return timer_elapsed_milliseconds(t, milliseconds); } @@ -110,14 +110,14 @@ bool timer_elapsed_seconds( * Notes: none *************************************************************************/ bool timer_elapsed_minutes( - struct etimer *t, + struct etimer * t, uint32_t minutes) { uint32_t milliseconds = minutes; milliseconds *= 1000L; milliseconds *= 60L; - + return timer_elapsed_milliseconds(t, milliseconds); } @@ -148,7 +148,7 @@ void timer_interval_start_seconds( uint32_t interval = seconds; interval *= 1000L; - timer_interval_start(t, interval); + timer_interval_start(t, interval); } /************************************************************************* @@ -164,7 +164,7 @@ void timer_interval_start_minutes( interval *= 1000L; interval *= 60L; - timer_interval_start(t, interval); + timer_interval_start(t, interval); } /************************************************************************* @@ -177,11 +177,11 @@ uint32_t timer_interval_elapsed( { uint32_t now = timer_milliseconds(); uint32_t delta = 0; - + if (t) { delta = now - t->start; } - + return delta; } @@ -191,14 +191,14 @@ uint32_t timer_interval_elapsed( * Notes: none *************************************************************************/ uint32_t timer_interval( - struct itimer *t) + struct itimer * t) { uint32_t interval = 0; - + if (t) { interval = t->interval; } - + return interval; } @@ -208,16 +208,16 @@ uint32_t timer_interval( * Notes: none *************************************************************************/ bool timer_interval_expired( - struct itimer *t) + struct itimer * t) { bool expired = false; - + if (t) { if (t->interval) { expired = timer_interval_elapsed(t) >= t->interval; } } - + return expired; } @@ -242,7 +242,7 @@ void timer_interval_no_expire( *************************************************************************/ void timer_interval_reset( struct itimer *t) -{ +{ if (t) { t->start += t->interval; } @@ -269,7 +269,8 @@ void timer_interval_restart( static uint32_t Milliseconds; -uint32_t timer_milliseconds(void) +uint32_t timer_milliseconds( + void) { return Milliseconds; } @@ -289,15 +290,15 @@ void testElapsedTimer( { struct etimer t; uint32_t test_time = 0; - - timer_milliseconds_set(test_time); + + timer_milliseconds_set(test_time); timer_elapsed_start(&t); ct_test(pTest, timer_elapsed_time(&t) == test_time); test_time = 0xffff; - timer_milliseconds_set(test_time); + timer_milliseconds_set(test_time); ct_test(pTest, timer_elapsed_time(&t) == test_time); test_time = 0xffffffff; - timer_milliseconds_set(test_time); + timer_milliseconds_set(test_time); ct_test(pTest, timer_elapsed_time(&t) == test_time); } @@ -307,19 +308,19 @@ void testIntervalTimer( struct itimer t; uint32_t interval = 0; uint32_t test_time = 0; - - timer_milliseconds_set(test_time); + + timer_milliseconds_set(test_time); timer_interval_start(&t, interval); test_time = 0xffff; - timer_milliseconds_set(test_time); + timer_milliseconds_set(test_time); ct_test(pTest, timer_interval(&t) == interval); ct_test(pTest, timer_interval_elapsed(&t) == test_time); test_time = 0xffffffff; - timer_milliseconds_set(test_time); + timer_milliseconds_set(test_time); ct_test(pTest, timer_interval(&t) == interval); ct_test(pTest, timer_interval_elapsed(&t) == test_time); test_time = 0; - timer_milliseconds_set(test_time); + timer_milliseconds_set(test_time); interval = 0xffff; timer_interval_start(&t, interval); ct_test(pTest, timer_interval(&t) == interval); @@ -334,7 +335,7 @@ void testIntervalTimer( timer_interval_start_seconds(&t, interval); interval *= 1000L; ct_test(pTest, timer_interval(&t) == interval); - + } @@ -364,4 +365,3 @@ int main( } #endif #endif - diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/timer.h b/bacnet-stack/ports/bdk-atxx4-mstp/timer.h index 38f6eefe..5a6dd810 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/timer.h +++ b/bacnet-stack/ports/bdk-atxx4-mstp/timer.h @@ -46,12 +46,13 @@ extern "C" { /* these 3 functions are created in the hardware specific module */ void timer_init( void); - uint32_t timer_milliseconds(void); + uint32_t timer_milliseconds( + void); uint32_t timer_milliseconds_set( uint32_t value); /* these functions are in the generic timer.c module */ - + /* elapsed timer */ void timer_elapsed_start( struct etimer *t); diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c b/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c index 4253f4e9..85b9cbae 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/timer2.c @@ -59,7 +59,7 @@ uint32_t timer_milliseconds_set( uint32_t value) { uint8_t sreg = 0; /* holds interrupts pending */ - uint32_t old_value = 0; /* return value */ + uint32_t old_value = 0; /* return value */ sreg = SREG; __disable_interrupt(); @@ -75,9 +75,10 @@ uint32_t timer_milliseconds_set( * Returns: none * Notes: none *************************************************************************/ -uint32_t timer_milliseconds(void) +uint32_t timer_milliseconds( + void) { - uint32_t timer_value = 0; /* return value */ + uint32_t timer_value = 0; /* return value */ uint8_t sreg = 0; /* holds interrupts pending */ sreg = SREG; @@ -93,7 +94,8 @@ uint32_t timer_milliseconds(void) * Returns: none * Notes: none *************************************************************************/ -void timer_init(void) +void timer_init( + void) { /* Normal Operation */ TCCR2A = 0; diff --git a/bacnet-stack/ports/linux/bip-init.c b/bacnet-stack/ports/linux/bip-init.c index 5d94e63e..d52031ee 100644 --- a/bacnet-stack/ports/linux/bip-init.c +++ b/bacnet-stack/ports/linux/bip-init.c @@ -209,12 +209,12 @@ bool bip_init( * @return 0 on success, else the error from the ioctl() call. */ int bip_get_local_netmask( - struct in_addr *netmask ) + struct in_addr *netmask) { - int rv; - char *ifname = getenv("BACNET_IFACE"); /* will probably be null */ - if ( ifname == NULL ) - ifname = "eth0"; + int rv; + char *ifname = getenv("BACNET_IFACE"); /* will probably be null */ + if (ifname == NULL) + ifname = "eth0"; rv = get_local_address_ioctl(ifname, netmask, SIOCGIFNETMASK); return rv; } diff --git a/bacnet-stack/ports/linux/net.h b/bacnet-stack/ports/linux/net.h index 99b04f85..f5edeb6a 100644 --- a/bacnet-stack/ports/linux/net.h +++ b/bacnet-stack/ports/linux/net.h @@ -98,8 +98,7 @@ /* Local helper functions for this port */ extern int bip_get_local_netmask( - struct in_addr *netmask ); + struct in_addr *netmask); #endif - diff --git a/bacnet-stack/ports/linux/timer.h b/bacnet-stack/ports/linux/timer.h index 153bb1c4..a2fff783 100644 --- a/bacnet-stack/ports/linux/timer.h +++ b/bacnet-stack/ports/linux/timer.h @@ -26,7 +26,7 @@ #include #include -#include /* for timeval */ +#include /* for timeval */ /* Timer Module */ #ifndef MAX_MILLISECOND_TIMERS diff --git a/bacnet-stack/ports/pic18f6720/ai.c b/bacnet-stack/ports/pic18f6720/ai.c index c3d9219d..64383cdf 100644 --- a/bacnet-stack/ports/pic18f6720/ai.c +++ b/bacnet-stack/ports/pic18f6720/ai.c @@ -161,8 +161,7 @@ int Analog_Input_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; diff --git a/bacnet-stack/ports/pic18f6720/av.c b/bacnet-stack/ports/pic18f6720/av.c index e495ba00..6e2c296b 100644 --- a/bacnet-stack/ports/pic18f6720/av.c +++ b/bacnet-stack/ports/pic18f6720/av.c @@ -320,8 +320,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/bi.c b/bacnet-stack/ports/pic18f6720/bi.c index c6e7ffa0..6b8e2c1a 100644 --- a/bacnet-stack/ports/pic18f6720/bi.c +++ b/bacnet-stack/ports/pic18f6720/bi.c @@ -185,8 +185,7 @@ int Binary_Input_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; diff --git a/bacnet-stack/ports/pic18f6720/bv.c b/bacnet-stack/ports/pic18f6720/bv.c index b00f4f34..bb0ca381 100644 --- a/bacnet-stack/ports/pic18f6720/bv.c +++ b/bacnet-stack/ports/pic18f6720/bv.c @@ -186,8 +186,7 @@ int Binary_Value_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = -1; @@ -233,8 +232,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 7b94092d..b15be9c6 100644 --- a/bacnet-stack/ports/pic18f6720/device.c +++ b/bacnet-stack/ports/pic18f6720/device.c @@ -50,8 +50,7 @@ static uint32_t Object_Instance_Number = 12345; static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL; -BACNET_REINITIALIZED_STATE Reinitialize_State = - BACNET_REINIT_IDLE; +BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_IDLE; void Device_Reinit( void) @@ -476,8 +475,7 @@ int Device_Encode_Property_APDU( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && - (property != PROP_OBJECT_LIST) && + if ((apdu_len >= 0) && (property != PROP_OBJECT_LIST) && (array_index != BACNET_ARRAY_ALL)) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; @@ -511,8 +509,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/win32/bip-init.c b/bacnet-stack/ports/win32/bip-init.c index c2ff4b0f..a125ec4b 100644 --- a/bacnet-stack/ports/win32/bip-init.c +++ b/bacnet-stack/ports/win32/bip-init.c @@ -74,10 +74,10 @@ static long gethostaddr( return -1; if (BIP_Debug) { printf("host: %s at %u.%u.%u.%u\n", host_name, - (unsigned)((uint8_t *) host_ent->h_addr)[0], - (unsigned)((uint8_t *) host_ent->h_addr)[1], - (unsigned)((uint8_t *) host_ent->h_addr)[2], - (unsigned)((uint8_t *) host_ent->h_addr)[3]); + (unsigned) ((uint8_t *) host_ent->h_addr)[0], + (unsigned) ((uint8_t *) host_ent->h_addr)[1], + (unsigned) ((uint8_t *) host_ent->h_addr)[2], + (unsigned) ((uint8_t *) host_ent->h_addr)[3]); } /* note: network byte order */ return *(long *) host_ent->h_addr; diff --git a/bacnet-stack/ports/win32/dlmstp.c b/bacnet-stack/ports/win32/dlmstp.c index ea80b656..c465af44 100644 --- a/bacnet-stack/ports/win32/dlmstp.c +++ b/bacnet-stack/ports/win32/dlmstp.c @@ -664,7 +664,8 @@ bool dlmstp_init( #if PRINT_ENABLED fprintf(stderr, "MS/TP MAC: %02X\n", MSTP_Port.This_Station); fprintf(stderr, "MS/TP Max_Master: %02X\n", MSTP_Port.Nmax_master); - fprintf(stderr, "MS/TP Max_Info_Frames: %u\n", (unsigned)MSTP_Port.Nmax_info_frames); + fprintf(stderr, "MS/TP Max_Info_Frames: %u\n", + (unsigned) MSTP_Port.Nmax_info_frames); #endif /* start the threads */ hThread = _beginthread(dlmstp_millisecond_task, 4096, &arg_value); diff --git a/bacnet-stack/src/address.c b/bacnet-stack/src/address.c index f501f530..3d252d6a 100644 --- a/bacnet-stack/src/address.c +++ b/bacnet-stack/src/address.c @@ -149,8 +149,7 @@ 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; @@ -169,10 +168,9 @@ 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))) { + ((uint8_t) (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ))) { if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */ ulTime = pMatch->TimeToLive; pCandidate = pMatch; @@ -242,7 +240,7 @@ void address_file_init( } } address_add((uint32_t) device_id, max_apdu, &src); - address_set_device_TTL((uint32_t)device_id, 0, true); /* Mark as static entry */ + address_set_device_TTL((uint32_t) device_id, 0, true); /* Mark as static entry */ } } } @@ -498,10 +496,10 @@ bool address_bind_request( while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) == 0) { /* In use and awaiting binding */ - pMatch->Flags = (uint8_t)(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ); + pMatch->Flags = (uint8_t) (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ); pMatch->device_id = device_id; /* No point in leaving bind requests in for long haul */ - pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; + pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* now would be a good time to do a Who-Is request */ return (false); } @@ -511,7 +509,7 @@ bool address_bind_request( /* No free entries, See if we can squeeze it in by dropping an existing one */ pMatch = address_remove_oldest(); if (pMatch != NULL) { - pMatch->Flags = (uint8_t)(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ); + pMatch->Flags = (uint8_t) (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ); pMatch->device_id = device_id; /* No point in leaving bind requests in for long haul */ pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; @@ -537,7 +535,7 @@ void address_add_binding( /* Clear bind request flag in case it was set */ pMatch->Flags &= ~BAC_ADDR_BIND_REQ; /* Only update TTL if not static */ - if ((pMatch->Flags & BAC_ADDR_STATIC) == 0) { + if ((pMatch->Flags & BAC_ADDR_STATIC) == 0) { /* and set it on a long fuse */ pMatch->TimeToLive = BAC_ADDR_LONG_TIME; } @@ -580,7 +578,8 @@ unsigned address_count( pMatch = Address_Cache; while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { /* Only count bound entries */ - if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) + if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == + BAC_ADDR_IN_USE) count++; pMatch++; @@ -660,47 +659,47 @@ int address_list_encode( * oct string to give 17 bytes (the minimum possible is 5 + 2 + 3 = 10). * ****************************************************************************/ -#define ACACHE_MAX_ENC 17 /* Maximum size of encoded cache entry, see above */ +#define ACACHE_MAX_ENC 17 /* Maximum size of encoded cache entry, see above */ int rr_address_list_encode( - uint8_t *apdu, - BACNET_READ_RANGE_DATA *pRequest) + uint8_t * apdu, + BACNET_READ_RANGE_DATA * pRequest) { int iLen = 0; int32_t iTemp = 0; - struct Address_Cache_Entry *pMatch = NULL; + struct Address_Cache_Entry *pMatch = NULL; BACNET_OCTET_STRING MAC_Address; - uint32_t uiTotal = 0; /* Number of bound entries in the cache */ - uint32_t uiIndex = 0; /* Current entry number */ - uint32_t uiFirst = 0; /* Entry number we started encoding from */ - uint32_t uiLast = 0; /* Entry number we finished encoding on */ - uint32_t uiTarget = 0; /* Last entry we are required to encode */ - uint32_t uiRemaining = 0; /* Amount of unused space in packet */ - + uint32_t uiTotal = 0; /* Number of bound entries in the cache */ + uint32_t uiIndex = 0; /* Current entry number */ + uint32_t uiFirst = 0; /* Entry number we started encoding from */ + uint32_t uiLast = 0; /* Entry number we finished encoding on */ + uint32_t uiTarget = 0; /* Last entry we are required to encode */ + uint32_t uiRemaining = 0; /* Amount of unused space in packet */ + /* Initialise result flags to all false */ - bitstring_init(&pRequest->ResultFlags); + bitstring_init(&pRequest->ResultFlags); bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, false); - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, false); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, false); bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, false); /* See how much space we have */ - uiRemaining = (uint32_t)(MAX_APDU - pRequest->Overhead); + uiRemaining = (uint32_t) (MAX_APDU - pRequest->Overhead); pRequest->ItemCount = 0; /* Start out with nothing */ uiTotal = address_count(); /* What do we have to work with here ? */ - if(uiTotal == 0) /* Bail out now if nowt */ - return(0); + if (uiTotal == 0) /* Bail out now if nowt */ + return (0); - if(pRequest->RequestType == RR_READ_ALL) { + if (pRequest->RequestType == RR_READ_ALL) { /* * Read all the array or as much as will fit in the buffer by selecting * a range that covers the whole list and falling through to the next * section of code */ - pRequest->Count = uiTotal; /* Full list */ - pRequest->Range.RefIndex = 1; /* Starting at the beginning */ - } + pRequest->Count = uiTotal; /* Full list */ + pRequest->Range.RefIndex = 1; /* Starting at the beginning */ + } - if(pRequest->Count < 0) { /* negative count means work from index backwards */ + if (pRequest->Count < 0) { /* negative count means work from index backwards */ /* * Convert from end index/negative count to * start index/positive count and then process as @@ -713,91 +712,97 @@ int rr_address_list_encode( * try to optimise the code unless you understand all the * implications of the data type conversions! */ - - iTemp = pRequest->Range.RefIndex; /* pull out and convert to signed */ - iTemp += pRequest->Count + 1; /* Adjust backwards, remember count is -ve */ - if(iTemp < 1) { /* if count is too much, return from 1 to start index */ + + iTemp = pRequest->Range.RefIndex; /* pull out and convert to signed */ + iTemp += pRequest->Count + 1; /* Adjust backwards, remember count is -ve */ + if (iTemp < 1) { /* if count is too much, return from 1 to start index */ pRequest->Count = pRequest->Range.RefIndex; pRequest->Range.RefIndex = 1; - } - else { /* Otherwise adjust the start index and make count +ve */ + } else { /* Otherwise adjust the start index and make count +ve */ pRequest->Range.RefIndex = iTemp; pRequest->Count = -pRequest->Count; } } - + /* From here on in we only have a starting point and a positive count */ - - if(pRequest->Range.RefIndex > uiTotal) /* Nothing to return as we are past the end of the list */ - return(0); - - uiTarget = pRequest->Range.RefIndex + pRequest->Count - 1; /* Index of last required entry */ - if(uiTarget > uiTotal) /* Capped at end of list if necessary */ + + if (pRequest->Range.RefIndex > uiTotal) /* Nothing to return as we are past the end of the list */ + return (0); + + uiTarget = pRequest->Range.RefIndex + pRequest->Count - 1; /* Index of last required entry */ + if (uiTarget > uiTotal) /* Capped at end of list if necessary */ uiTarget = uiTotal; - - pMatch = Address_Cache; + + pMatch = Address_Cache; uiIndex = 1; - while((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) != BAC_ADDR_IN_USE) /* Find first bound entry */ + while ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) != BAC_ADDR_IN_USE) /* Find first bound entry */ pMatch++; - + /* Seek to start position */ - while(uiIndex != pRequest->Range.RefIndex) { - if((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) { /* Only count bound entries */ + while (uiIndex != pRequest->Range.RefIndex) { + if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) { /* Only count bound entries */ pMatch++; uiIndex++; - } - else + } else pMatch++; } - - uiFirst = uiIndex; /* Record where we started from */ - while(uiIndex <= uiTarget) { - if(uiRemaining < ACACHE_MAX_ENC) { + + uiFirst = uiIndex; /* Record where we started from */ + while (uiIndex <= uiTarget) { + if (uiRemaining < ACACHE_MAX_ENC) { /* * Can't fit any more in! We just set the result flag to say there * was more and drop out of the loop early */ - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, true); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, + true); break; - } - - iTemp = (int32_t)encode_application_object_id(&apdu[iLen], - OBJECT_DEVICE, + } + + iTemp = + (int32_t) encode_application_object_id(&apdu[iLen], OBJECT_DEVICE, pMatch->device_id); - iTemp += encode_application_unsigned(&apdu[iLen + iTemp], + iTemp += + encode_application_unsigned(&apdu[iLen + iTemp], pMatch->address.net); - + /* pick the appropriate type of entry from the cache */ - - if(pMatch->address.len != 0) { - octetstring_init(&MAC_Address, pMatch->address.adr, pMatch->address.len); - iTemp += encode_application_octet_string(&apdu[iLen + iTemp], &MAC_Address); + + if (pMatch->address.len != 0) { + octetstring_init(&MAC_Address, pMatch->address.adr, + pMatch->address.len); + iTemp += + encode_application_octet_string(&apdu[iLen + iTemp], + &MAC_Address); + } else { + octetstring_init(&MAC_Address, pMatch->address.mac, + pMatch->address.mac_len); + iTemp += + encode_application_octet_string(&apdu[iLen + iTemp], + &MAC_Address); } - else { - octetstring_init(&MAC_Address, pMatch->address.mac, pMatch->address.mac_len); - iTemp += encode_application_octet_string(&apdu[iLen + iTemp], &MAC_Address); - } - - uiRemaining -= iTemp; /* Reduce the remaining space */ - iLen += iTemp; /* and increase the length consumed */ - + + uiRemaining -= iTemp; /* Reduce the remaining space */ + iLen += iTemp; /* and increase the length consumed */ + uiLast = uiIndex; /* Record the last entry encoded */ - uiIndex++; /* and get ready for next one */ + uiIndex++; /* and get ready for next one */ pMatch++; pRequest->ItemCount++; /* Chalk up another one for the response count */ - - while((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) != BAC_ADDR_IN_USE) /* Find next bound entry */ + + while ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) != BAC_ADDR_IN_USE) /* Find next bound entry */ pMatch++; } - + /* Set remaining result flags if necessary */ - if(uiFirst == 1) - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, true); - - if(uiLast == uiTotal) - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); - - return(iLen); + if (uiFirst == 1) + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, + true); + + if (uiLast == uiTotal) + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); + + return (iLen); } /**************************************************************************** diff --git a/bacnet-stack/src/alarm_ack.c b/bacnet-stack/src/alarm_ack.c index 629d89c7..b68f1ef9 100644 --- a/bacnet-stack/src/alarm_ack.c +++ b/bacnet-stack/src/alarm_ack.c @@ -126,10 +126,10 @@ int alarm_ack_decode_service_request( int len = 0; int section_len; uint32_t enumValue; - + /* unused parameter */ apdu_len = apdu_len; - + if (-1 == (section_len = decode_context_unsigned(&apdu[len], 0, &data->ackProcessIdentifier))) { @@ -149,7 +149,7 @@ int alarm_ack_decode_service_request( decode_context_enumerated(&apdu[len], 2, &enumValue))) { return -1; } - data->eventStateAcked = (BACNET_EVENT_STATE)enumValue; + data->eventStateAcked = (BACNET_EVENT_STATE) enumValue; len += section_len; if (-1 == (section_len = diff --git a/bacnet-stack/src/apdu.c b/bacnet-stack/src/apdu.c index d73d1262..8ac5f82b 100644 --- a/bacnet-stack/src/apdu.c +++ b/bacnet-stack/src/apdu.c @@ -178,8 +178,8 @@ bool apdu_service_supported( */ bool apdu_service_supported_to_index( BACNET_SERVICES_SUPPORTED service_supported, - size_t *index, - bool *bIsConfirmed ) + size_t * index, + bool * bIsConfirmed) { int i = 0; bool found = false; diff --git a/bacnet-stack/src/bacapp.c b/bacnet-stack/src/bacapp.c index f59970a1..a2ae4e8b 100644 --- a/bacnet-stack/src/bacapp.c +++ b/bacnet-stack/src/bacapp.c @@ -517,7 +517,7 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type( } break; case PROP_LIST_OF_GROUP_MEMBERS: - /* Sequence of ReadAccessSpecification */ + /* Sequence of ReadAccessSpecification */ switch (tag_number) { case 0: tag = BACNET_APPLICATION_TAG_OBJECT_ID; @@ -542,31 +542,31 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type( break; case PROP_LOG_DEVICE_OBJECT_PROPERTY: switch (tag_number) { - case 0: /* Object ID */ - case 3: /* Device ID */ - tag = BACNET_APPLICATION_TAG_OBJECT_ID; + case 0: /* Object ID */ + case 3: /* Device ID */ + tag = BACNET_APPLICATION_TAG_OBJECT_ID; break; - case 1: /* Property ID */ + case 1: /* Property ID */ tag = BACNET_APPLICATION_TAG_ENUMERATED; break; - case 2: /* Array index */ + case 2: /* Array index */ tag = BACNET_APPLICATION_TAG_UNSIGNED_INT; break; default: break; } break; - case PROP_SUBORDINATE_LIST: - /* BACnetARRAY[N] of BACnetDeviceObjectReference */ - switch (tag_number) { - case 0: /* Optional Device ID */ - case 1: /* Object ID */ - tag = BACNET_APPLICATION_TAG_OBJECT_ID; - break; - default: - break; - } - break; + case PROP_SUBORDINATE_LIST: + /* BACnetARRAY[N] of BACnetDeviceObjectReference */ + switch (tag_number) { + case 0: /* Optional Device ID */ + case 1: /* Object ID */ + tag = BACNET_APPLICATION_TAG_OBJECT_ID; + break; + default: + break; + } + break; default: break; @@ -837,10 +837,11 @@ bool bacapp_print_value( fprintf(stream, "%s", value->type.Boolean ? "TRUE" : "FALSE"); break; case BACNET_APPLICATION_TAG_UNSIGNED_INT: - fprintf(stream, "%lu", (unsigned long)value->type.Unsigned_Int); + fprintf(stream, "%lu", + (unsigned long) value->type.Unsigned_Int); break; case BACNET_APPLICATION_TAG_SIGNED_INT: - fprintf(stream, "%ld", (long)value->type.Signed_Int); + fprintf(stream, "%ld", (long) value->type.Signed_Int); break; case BACNET_APPLICATION_TAG_REAL: fprintf(stream, "%f", (double) value->type.Real); @@ -890,14 +891,14 @@ 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); + (unsigned long) value->type.Enumerated); } else { fprintf(stream, "proprietary %lu", - (unsigned long)value->type.Enumerated); + (unsigned long) value->type.Enumerated); } break; case PROP_EVENT_STATE: @@ -907,22 +908,22 @@ 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); + (unsigned long) value->type.Enumerated); } 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: fprintf(stream, "%s", - bactext_binary_present_value_name(value-> - type.Enumerated)); + bactext_binary_present_value_name(value->type. + Enumerated)); break; case PROP_RELIABILITY: fprintf(stream, "%s", @@ -930,8 +931,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", @@ -942,7 +943,8 @@ bool bacapp_print_value( bactext_node_type_name(value->type.Enumerated)); break; default: - fprintf(stream, "%lu", (unsigned long)value->type.Enumerated); + fprintf(stream, "%lu", + (unsigned long) value->type.Enumerated); break; } break; @@ -988,15 +990,15 @@ bool bacapp_print_value( if (value->type.Object_Id.type < MAX_ASHRAE_OBJECT_TYPE) { fprintf(stream, "(%s, %lu)", bactext_object_type_name(value->type.Object_Id.type), - (unsigned long)value->type.Object_Id.instance); + (unsigned long) value->type.Object_Id.instance); } else if (value->type.Object_Id.type < 128) { fprintf(stream, "(reserved %u, %lu)", - (unsigned)value->type.Object_Id.type, - (unsigned long)value->type.Object_Id.instance); + (unsigned) value->type.Object_Id.type, + (unsigned long) value->type.Object_Id.instance); } else { fprintf(stream, "(proprietary %u, %lu)", - (unsigned)value->type.Object_Id.type, - (unsigned long)value->type.Object_Id.instance); + (unsigned) value->type.Object_Id.type, + (unsigned long) value->type.Object_Id.instance); } break; default: @@ -1294,15 +1296,15 @@ void testBACnetApplicationData_Safe( case BACNET_APPLICATION_TAG_OCTET_STRING: { - uint8_t test_octet[5] = {"Karg"}; + uint8_t test_octet[5] = { "Karg" }; octetstring_init(&input_value[i].type.Octet_String, test_octet, sizeof(test_octet)); } 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 ef39616c..d836ca2f 100644 --- a/bacnet-stack/src/bacdcode.c +++ b/bacnet-stack/src/bacdcode.c @@ -1190,7 +1190,7 @@ int encode_context_unsigned( len = 4; } - len = encode_tag(&apdu[0], tag_number, true, (uint32_t)len); + len = encode_tag(&apdu[0], tag_number, true, (uint32_t) len); len += encode_bacnet_unsigned(&apdu[len], value); return len; @@ -1563,7 +1563,7 @@ int decode_bacnet_time_safe( btime->hundredths = 0; btime->min = 0; btime->sec = 0; - return (int)len_value; + return (int) len_value; } else { return decode_bacnet_time(apdu, btime); } @@ -1696,7 +1696,7 @@ int decode_date_safe( bdate->month = 0; bdate->wday = 0; bdate->year = 0; - return (int)len_value; + return (int) len_value; } else { return decode_date(apdu, bdate); } @@ -2010,7 +2010,8 @@ void testBACDCodeUnsignedValue( len = decode_unsigned(&array[len], len_value, &decoded_value); ct_test(pTest, decoded_value == value); if (decoded_value != value) { - printf("value=%lu decoded_value=%lu\n", (unsigned long)value, (unsigned long)decoded_value); + printf("value=%lu decoded_value=%lu\n", (unsigned long) value, + (unsigned long) decoded_value); print_apdu(&array[0], sizeof(array)); } encode_application_unsigned(&encoded_array[0], decoded_value); @@ -2078,14 +2079,16 @@ void testBACDCodeSignedValue( ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_SIGNED_INT); ct_test(pTest, decoded_value == value); if (decoded_value != value) { - printf("value=%ld decoded_value=%ld\n", (long)value, (long)decoded_value); + printf("value=%ld decoded_value=%ld\n", (long) value, + (long) decoded_value); print_apdu(&array[0], sizeof(array)); } encode_application_signed(&encoded_array[0], decoded_value); diff = memcmp(&array[0], &encoded_array[0], sizeof(array)); ct_test(pTest, diff == 0); if (diff) { - printf("value=%ld decoded_value=%ld\n", (long)value, (long)decoded_value); + printf("value=%ld decoded_value=%ld\n", (long) value, + (long) decoded_value); print_apdu(&array[0], sizeof(array)); print_apdu(&encoded_array[0], sizeof(array)); } diff --git a/bacnet-stack/src/bacdevobjpropref.c b/bacnet-stack/src/bacdevobjpropref.c index 3c65a386..63e72598 100644 --- a/bacnet-stack/src/bacdevobjpropref.c +++ b/bacnet-stack/src/bacdevobjpropref.c @@ -85,8 +85,8 @@ int bacapp_encode_device_obj_property_ref( /* Likewise, device id is optional so see if needed * (set type to non device to omit */ - - if(value->deviceIndentifier.type == OBJECT_DEVICE) { + + if (value->deviceIndentifier.type == OBJECT_DEVICE) { len = encode_context_object_id(&apdu[apdu_len], 3, (int) value->deviceIndentifier.type, @@ -206,7 +206,7 @@ int bacapp_encode_device_obj_ref( /* Device id is optional so see if needed * (set type to non device to omit */ - if(value->deviceIndentifier.type == OBJECT_DEVICE) { + if (value->deviceIndentifier.type == OBJECT_DEVICE) { len = encode_context_object_id(&apdu[apdu_len], 0, (int) value->deviceIndentifier.type, @@ -264,8 +264,7 @@ int bacapp_decode_context_device_obj_ref( if (decode_is_opening_tag_number(&apdu[len], tag_number)) { len++; - section_length = - bacapp_decode_device_obj_ref(&apdu[len], value); + section_length = bacapp_decode_device_obj_ref(&apdu[len], value); if (section_length == -1) { len = -1; @@ -330,8 +329,8 @@ void testDevIdPropRef( void testDevIdRef( Test * pTest) { - BACNET_DEVICE_OBJECT_REFERENCE inData; - BACNET_DEVICE_OBJECT_REFERENCE outData; + BACNET_DEVICE_OBJECT_REFERENCE inData; + BACNET_DEVICE_OBJECT_REFERENCE outData; uint8_t buffer[MAX_APDU]; int inLen; int outLen; diff --git a/bacnet-stack/src/bacreal.c b/bacnet-stack/src/bacreal.c index bad79b40..e6e44bb9 100644 --- a/bacnet-stack/src/bacreal.c +++ b/bacnet-stack/src/bacreal.c @@ -86,7 +86,7 @@ int decode_real_safe( { if (len_value != 4) { *real_value = 0.0f; - return (int)len_value; + return (int) len_value; } else { return decode_real(apdu, real_value); } @@ -182,7 +182,7 @@ int decode_double_safe( { if (len_value != 8) { *double_value = 0.0; - return (int)len_value; + return (int) len_value; } else { return decode_double(apdu, double_value); } diff --git a/bacnet-stack/src/bacstr.c b/bacnet-stack/src/bacstr.c index d02c95a0..f55c6ae9 100644 --- a/bacnet-stack/src/bacstr.c +++ b/bacnet-stack/src/bacstr.c @@ -206,7 +206,7 @@ bool bitstring_same( if (bitstring1 && bitstring1) { if ((bitstring1->bits_used == bitstring2->bits_used) && (bitstring1->bits_used / 8 <= MAX_BITSTRING_BYTES)) { - bytes_used = (int)(bitstring1->bits_used / 8); + bytes_used = (int) (bitstring1->bits_used / 8); compare_mask = 0xFF >> (8 - (bitstring1->bits_used % 8)); for (i = 0; i < bytes_used; i++) { diff --git a/bacnet-stack/src/bactext.c b/bacnet-stack/src/bactext.c index 76b19d98..b8e05b42 100644 --- a/bacnet-stack/src/bactext.c +++ b/bacnet-stack/src/bactext.c @@ -348,7 +348,7 @@ INDTEXT_DATA bacnet_property_names[] = { {PROP_FILE_TYPE, "file-type"} , {PROP_FIRMWARE_REVISION, "firmware-revision"} - , /* VTS wants "revision", not "version" */ + , /* VTS wants "revision", not "version" */ {PROP_HIGH_LIMIT, "high-limit"} , {PROP_INACTIVE_TEXT, "inactive-text"} diff --git a/bacnet-stack/src/bvlc.c b/bacnet-stack/src/bvlc.c index 3f31e876..6541e6c6 100644 --- a/bacnet-stack/src/bvlc.c +++ b/bacnet-stack/src/bvlc.c @@ -677,8 +677,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 = - htonl(((~BBMD_Table[i].broadcast_mask. - s_addr) | BBMD_Table[i].dest_address.s_addr)); + htonl(((~BBMD_Table[i].broadcast_mask.s_addr) | BBMD_Table[i]. + dest_address.s_addr)); bip_dest.sin_port = htons(BBMD_Table[i].dest_port); /* don't send to my broadcast address and same port */ if ((bip_dest.sin_addr.s_addr == htonl(bip_get_broadcast_addr())) diff --git a/bacnet-stack/src/datetime.c b/bacnet-stack/src/datetime.c index 515d250e..5a6d58d8 100644 --- a/bacnet-stack/src/datetime.c +++ b/bacnet-stack/src/datetime.c @@ -412,8 +412,8 @@ bool datetime_wildcard_present( if (bdatetime) { if ((bdatetime->date.year == (1900 + 0xFF)) || (bdatetime->date.month > 12) || (bdatetime->date.day > 31) || - (bdatetime->time.hour == 0xFF) || - (bdatetime->time.min == 0xFF) || (bdatetime->time.sec == 0xFF) || + (bdatetime->time.hour == 0xFF) || (bdatetime->time.min == 0xFF) || + (bdatetime->time.sec == 0xFF) || (bdatetime->time.hundredths == 0xFF)) { wildcard_present = true; } @@ -421,6 +421,7 @@ bool datetime_wildcard_present( return wildcard_present; } + void datetime_date_wildcard_set( BACNET_DATE * bdate) { diff --git a/bacnet-stack/src/event.c b/bacnet-stack/src/event.c index a8cd7399..b3556d8f 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); @@ -559,10 +559,10 @@ int event_notify_decode_service_request( len += section_length; } break; - /* In cases other than alarm and event - there's no data, so do not return an error - but continue normally */ - case NOTIFY_ACK_NOTIFICATION: + /* In cases other than alarm and event + there's no data, so do not return an error + but continue normally */ + case NOTIFY_ACK_NOTIFICATION: default: break; @@ -595,18 +595,16 @@ 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; @@ -617,16 +615,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; @@ -644,9 +642,8 @@ 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; } @@ -657,9 +654,8 @@ 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; } @@ -677,8 +673,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; @@ -687,31 +683,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; @@ -720,31 +716,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; @@ -772,9 +768,8 @@ 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; @@ -784,8 +779,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; @@ -794,24 +789,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; @@ -820,24 +815,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; @@ -858,10 +853,10 @@ int event_notify_decode_service_request( return -1; } break; - /* In cases other than alarm and event - there's no data, so do not return an error - but continue normally */ - case NOTIFY_ACK_NOTIFICATION: + /* In cases other than alarm and event + there's no data, so do not return an error + but continue normally */ + case NOTIFY_ACK_NOTIFICATION: default: break; } @@ -1096,16 +1091,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); @@ -1191,16 +1186,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); @@ -1440,12 +1435,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; @@ -1470,34 +1465,34 @@ void testEventEventState( ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty. - deviceIndentifier.type == - data2.notificationParams.bufferReady.bufferProperty. - deviceIndentifier.type); + 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); ct_test(pTest, data.notificationParams.bufferReady.bufferProperty. - deviceIndentifier.instance == + propertyIdentifier == 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); - - ct_test(pTest, - data.notificationParams.bufferReady. - bufferProperty.propertyIdentifier == - data2.notificationParams.bufferReady. - bufferProperty.propertyIdentifier); + propertyIdentifier); ct_test(pTest, data.notificationParams.bufferReady.bufferProperty.arrayIndex == diff --git a/bacnet-stack/src/getevent.c b/bacnet-stack/src/getevent.c index 4827f480..2d0e5aa0 100644 --- a/bacnet-stack/src/getevent.c +++ b/bacnet-stack/src/getevent.c @@ -58,7 +58,7 @@ int getevent_encode_apdu( if (lastReceivedObjectIdentifier) { len = encode_context_object_id(&apdu[apdu_len], 0, - (int)lastReceivedObjectIdentifier->type, + (int) lastReceivedObjectIdentifier->type, lastReceivedObjectIdentifier->instance); apdu_len += len; } @@ -125,7 +125,7 @@ int getevent_ack_encode_apdu_data( /* Tag 0: objectIdentifier */ apdu_len += encode_context_object_id(&apdu[apdu_len], 0, - (int)event_data->objectIdentifier.type, + (int) event_data->objectIdentifier.type, event_data->objectIdentifier.instance); /* Tag 1: eventState */ apdu_len += @@ -262,8 +262,7 @@ int getevent_ack_decode_service_request( len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); - len += - decode_enumerated(&apdu[len], len_value, &enum_value); + len += decode_enumerated(&apdu[len], len_value, &enum_value); event_data->notifyType = enum_value; } else { return -1; @@ -314,10 +313,10 @@ int getevent_ack_decode_service_request( len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); - if (len_value == 1) - *moreEvents = decode_context_boolean(&apdu[len++]); - else - *moreEvents = false; + if (len_value == 1) + *moreEvents = decode_context_boolean(&apdu[len++]); + else + *moreEvents = false; } else { return -1; } @@ -430,13 +429,15 @@ void testGetEventInformationAck( ct_test(pTest, len != 0); ct_test(pTest, len != -1); apdu_len = len; - len = getevent_ack_encode_apdu_data(&apdu[apdu_len], - sizeof(apdu)-apdu_len, &event_data); + len = + getevent_ack_encode_apdu_data(&apdu[apdu_len], sizeof(apdu) - apdu_len, + &event_data); ct_test(pTest, len != 0); ct_test(pTest, len != -1); apdu_len += len; - len = getevent_ack_encode_apdu_end(&apdu[apdu_len], - sizeof(apdu)-apdu_len, moreEvents); + len = + getevent_ack_encode_apdu_end(&apdu[apdu_len], sizeof(apdu) - apdu_len, + moreEvents); ct_test(pTest, len != 0); ct_test(pTest, len != -1); apdu_len += len; diff --git a/bacnet-stack/src/mstp.c b/bacnet-stack/src/mstp.c index 1953fa4f..ff50c862 100644 --- a/bacnet-stack/src/mstp.c +++ b/bacnet-stack/src/mstp.c @@ -351,7 +351,7 @@ void MSTP_Receive_Frame_FSM( /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; printf_receive_error("MSTP: Rx Header: SilenceTimer %u > %d\n", - (unsigned)mstp_port->SilenceTimer(), Tframe_abort); + (unsigned) mstp_port->SilenceTimer(), Tframe_abort); } /* Error */ else if (mstp_port->ReceiveError == true) { @@ -441,7 +441,7 @@ void MSTP_Receive_Frame_FSM( if (mstp_port->DataLength) { printf_receive_error ("MSTP: Rx Header: FrameTooLong %u\n", - (unsigned)mstp_port->DataLength); + (unsigned) mstp_port->DataLength); /* indicate that a frame with an illegal or */ /* unacceptable data length has been received */ mstp_port->ReceivedInvalidFrame = true; @@ -449,7 +449,8 @@ void MSTP_Receive_Frame_FSM( /* NoData */ else if (mstp_port->DataLength == 0) { printf_receive_data("%s", - mstptext_frame_type((unsigned)mstp_port->FrameType)); + mstptext_frame_type((unsigned) mstp_port-> + FrameType)); if ((mstp_port->DestinationAddress == mstp_port->This_Station) || (mstp_port->DestinationAddress == @@ -474,7 +475,7 @@ void MSTP_Receive_Frame_FSM( /* the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; printf_receive_error("MSTP: Rx Data: BadIndex %u\n", - (unsigned)mstp_port->Index); + (unsigned) mstp_port->Index); /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } @@ -491,7 +492,7 @@ void MSTP_Receive_Frame_FSM( mstp_port->ReceivedInvalidFrame = true; printf_receive_error ("MSTP: Rx Data: SilenceTimer %ums > %dms\n", - (unsigned)mstp_port->SilenceTimer(), Tframe_abort); + (unsigned) mstp_port->SilenceTimer(), Tframe_abort); /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } @@ -530,7 +531,7 @@ void MSTP_Receive_Frame_FSM( mstp_port->DataCRC); mstp_port->DataCRCActualLSB = mstp_port->DataRegister; printf_receive_data("%s", - mstptext_frame_type((unsigned)mstp_port->FrameType)); + mstptext_frame_type((unsigned) mstp_port->FrameType)); /* STATE DATA CRC - no need for new state */ /* indicate the complete reception of a valid frame */ if (mstp_port->DataCRC == 0xF0B8) { @@ -636,7 +637,7 @@ bool MSTP_Master_Node_FSM( mstp_port->SourceAddress, mstp_port->DestinationAddress, mstp_port->DataLength, mstp_port->FrameCount, mstp_port->SilenceTimer(), - mstptext_frame_type((unsigned)mstp_port->FrameType)); + mstptext_frame_type((unsigned) mstp_port->FrameType)); /* destined for me! */ if ((mstp_port->DestinationAddress == mstp_port->This_Station) || (mstp_port->DestinationAddress == @@ -665,12 +666,12 @@ bool MSTP_Master_Node_FSM( break; case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY: /* indicate successful reception to the higher layers */ - (void)MSTP_Put_Receive(mstp_port); + (void) MSTP_Put_Receive(mstp_port); break; case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY: /*mstp_port->ReplyPostponedTimer = 0; */ /* indicate successful reception to the higher layers */ - (void)MSTP_Put_Receive(mstp_port); + (void) MSTP_Put_Receive(mstp_port); /* broadcast DER just remains IDLE */ if (mstp_port->DestinationAddress != MSTP_BROADCAST_ADDRESS) { @@ -703,7 +704,7 @@ bool MSTP_Master_Node_FSM( /* more data frames. These may be BACnet Data frames or */ /* proprietary frames. */ /* FIXME: We could wait for up to Tusage_delay */ - length = (unsigned)MSTP_Get_Send(mstp_port, 0); + length = (unsigned) MSTP_Get_Send(mstp_port, 0); if (length < 1) { /* NothingToSend */ mstp_port->FrameCount = mstp_port->Nmax_info_frames; @@ -780,7 +781,7 @@ bool MSTP_Master_Node_FSM( /* ReceivedReply */ /* or a proprietary type that indicates a reply */ /* indicate successful reception to the higher layers */ - (void)MSTP_Put_Receive(mstp_port); + (void) MSTP_Put_Receive(mstp_port); mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; break; @@ -1038,7 +1039,7 @@ bool MSTP_Master_Node_FSM( /* BACnet Data Expecting Reply, a Test_Request, or */ /* a proprietary frame that expects a reply is received. */ /* FIXME: we could wait for up to Treply_delay */ - length = (unsigned)MSTP_Get_Reply(mstp_port, 0); + length = (unsigned) MSTP_Get_Reply(mstp_port, 0); if (length > 0) { /* Reply */ /* If a reply is available from the higher layers */ diff --git a/bacnet-stack/src/ptransfer.c b/bacnet-stack/src/ptransfer.c index 5f37f3a5..2f2274fe 100644 --- a/bacnet-stack/src/ptransfer.c +++ b/bacnet-stack/src/ptransfer.c @@ -93,7 +93,8 @@ int ptransfer_encode_apdu( apdu[3] = SERVICE_CONFIRMED_PRIVATE_TRANSFER; apdu_len = 4; len = - pt_encode_apdu(&apdu[apdu_len], (uint16_t)(MAX_APDU - apdu_len), private_data); + pt_encode_apdu(&apdu[apdu_len], (uint16_t) (MAX_APDU - apdu_len), + private_data); apdu_len += len; } @@ -112,7 +113,8 @@ int uptransfer_encode_apdu( apdu[1] = SERVICE_UNCONFIRMED_PRIVATE_TRANSFER; apdu_len = 2; len = - pt_encode_apdu(&apdu[apdu_len], (uint16_t)(MAX_APDU - apdu_len), private_data); + pt_encode_apdu(&apdu[apdu_len], (uint16_t) (MAX_APDU - apdu_len), + private_data); apdu_len += len; } diff --git a/bacnet-stack/src/rd.c b/bacnet-stack/src/rd.c index 29f0c2db..73f8db74 100644 --- a/bacnet-stack/src/rd.c +++ b/bacnet-stack/src/rd.c @@ -37,7 +37,7 @@ #include "bacdef.h" #include "rd.h" -/** @file rd.c Encode/Decode Reinitialize Device APDUs */ +/** @file rd.c Encode/Decode Reinitialize Device APDUs */ /* encode service */ int rd_encode_apdu( diff --git a/bacnet-stack/src/readrange.c b/bacnet-stack/src/readrange.c index de884a88..1b2300fc 100644 --- a/bacnet-stack/src/readrange.c +++ b/bacnet-stack/src/readrange.c @@ -72,7 +72,7 @@ int rr_encode_apdu( uint8_t invoke_id, BACNET_READ_RANGE_DATA * rrdata) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; @@ -180,14 +180,14 @@ int rr_decode_service_request( rrdata->array_index = BACNET_ARRAY_ALL; /* Assuming this is the most common outcome... */ if (len < apdu_len) { TagLen = - (unsigned)decode_tag_number_and_value(&apdu[len], &tag_number, + (unsigned) decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); if (tag_number == 2) { len += TagLen; len += decode_unsigned(&apdu[len], len_value_type, &UnsignedTemp); rrdata->array_index = UnsignedTemp; - rrdata->Overhead += RR_INDEX_OVERHEAD; /* Allow for this in the response */ + rrdata->Overhead += RR_INDEX_OVERHEAD; /* Allow for this in the response */ } } /* And/or optional range selection- Tags 3, 6 and 7 */ @@ -240,7 +240,7 @@ int rr_decode_service_request( len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); - rrdata->Overhead += RR_1ST_SEQ_OVERHEAD; /* Allow for this in the response */ + rrdata->Overhead += RR_1ST_SEQ_OVERHEAD; /* Allow for this in the response */ break; case 7: /* ReadRange by time stamp */ @@ -265,7 +265,7 @@ int rr_decode_service_request( len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); - rrdata->Overhead += RR_1ST_SEQ_OVERHEAD; /* Allow for this in the response */ + rrdata->Overhead += RR_1ST_SEQ_OVERHEAD; /* Allow for this in the response */ break; default: /* If we don't recognise the tag then we do nothing here and try to return @@ -301,7 +301,7 @@ int rr_ack_encode_apdu( BACNET_READ_RANGE_DATA * rrdata) { int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ diff --git a/bacnet-stack/src/ringbuf.c b/bacnet-stack/src/ringbuf.c index 81f0dc35..35a85cba 100644 --- a/bacnet-stack/src/ringbuf.c +++ b/bacnet-stack/src/ringbuf.c @@ -47,7 +47,7 @@ * ALGORITHM: none * NOTES: none *****************************************************************************/ -unsigned Ringbuf_Count ( +unsigned Ringbuf_Count( RING_BUFFER const *b) { return (b ? (b->head - b->tail) : 0); @@ -59,7 +59,7 @@ unsigned Ringbuf_Count ( * ALGORITHM: none * NOTES: none *****************************************************************************/ -bool Ringbuf_Full ( +bool Ringbuf_Full( RING_BUFFER const *b) { return (b ? (Ringbuf_Count(b) == b->element_count) : true); @@ -87,7 +87,8 @@ uint8_t *Ringbuf_Get_Front( RING_BUFFER const *b) { if (b) { - return (!Ringbuf_Empty(b) ? &(b->data[(b->tail % b->element_count) * b->element_size]) : NULL); + return (!Ringbuf_Empty(b) ? &(b->data[(b->tail % b->element_count) * + b->element_size]) : NULL); } return NULL; } @@ -101,7 +102,7 @@ uint8_t *Ringbuf_Get_Front( uint8_t *Ringbuf_Pop_Front( RING_BUFFER * b) { - uint8_t *data = NULL; /* return value */ + uint8_t *data = NULL; /* return value */ if (!Ringbuf_Empty(b)) { data = &(b->data[(b->tail % b->element_count) * b->element_size]); @@ -119,16 +120,17 @@ uint8_t *Ringbuf_Pop_Front( *****************************************************************************/ bool Ringbuf_Put( RING_BUFFER * b, /* ring buffer structure */ - uint8_t *data_element) + uint8_t * data_element) { /* one element to add to the ring */ bool status = false; /* return value */ - uint8_t *ring_data = NULL; /* used to help point ring data */ + uint8_t *ring_data = NULL; /* used to help point ring data */ unsigned i; /* loop counter */ if (b && data_element) { /* limit the amount of elements that we accept */ if (!Ringbuf_Full(b)) { - ring_data = b->data + ((b->head % b->element_count) * b->element_size); + ring_data = + b->data + ((b->head % b->element_count) * b->element_size); for (i = 0; i < b->element_size; i++) { ring_data[i] = data_element[i]; } @@ -147,14 +149,15 @@ bool Ringbuf_Put( * NOTES: none *****************************************************************************/ uint8_t *Ringbuf_Alloc( - RING_BUFFER *b) + RING_BUFFER * b) { - uint8_t *ring_data = NULL; /* used to help point ring data */ + uint8_t *ring_data = NULL; /* used to help point ring data */ if (b) { /* limit the amount of elements that we accept */ if (!Ringbuf_Full(b)) { - ring_data = b->data + ((b->head % b->element_count) * b->element_size); + ring_data = + b->data + ((b->head % b->element_count) * b->element_size); b->head++; } } @@ -171,7 +174,7 @@ uint8_t *Ringbuf_Alloc( *****************************************************************************/ void Ringbuf_Init( RING_BUFFER * b, /* ring buffer structure */ - uint8_t *data, /* data block or array of data */ + uint8_t * data, /* data block or array of data */ unsigned element_size, /* size of one element in the data block */ unsigned element_count) { /* number of elements in the data block */ @@ -195,8 +198,8 @@ void Ringbuf_Init( /* test the ring buffer */ void testRingBuf( Test * pTest, - uint8_t *data_store, - uint8_t *data_element, + uint8_t * data_store, + uint8_t * data_element, unsigned element_size, unsigned element_count) { @@ -273,8 +276,7 @@ void testRingBuf( for (index = 0; index < element_count; index++) { for (count = 1; count < 4; count++) { dummy = index * count; - for (data_index = 0; data_index < element_size; - data_index++) { + for (data_index = 0; data_index < element_size; data_index++) { data_element[data_index] = dummy; } status = Ringbuf_Put(&test_buffer, data_element); @@ -286,8 +288,7 @@ void testRingBuf( test_data = Ringbuf_Get_Front(&test_buffer); ct_test(pTest, test_data); if (test_data) { - for (data_index = 0; data_index < element_size; - data_index++) { + for (data_index = 0; data_index < element_size; data_index++) { ct_test(pTest, test_data[data_index] == dummy); } } @@ -295,8 +296,7 @@ void testRingBuf( test_data = Ringbuf_Pop_Front(&test_buffer); ct_test(pTest, test_data); if (test_data) { - for (data_index = 0; data_index < element_size; - data_index++) { + for (data_index = 0; data_index < element_size; data_index++) { ct_test(pTest, test_data[data_index] == dummy); } } @@ -314,9 +314,8 @@ void testRingBufSize16( uint8_t data_element[5]; uint8_t data_store[sizeof(data_element) * 16]; - testRingBuf(pTest,data_store,data_element, - sizeof(data_element), - sizeof(data_store)/sizeof(data_element)); + testRingBuf(pTest, data_store, data_element, sizeof(data_element), + sizeof(data_store) / sizeof(data_element)); } void testRingBufSize32( @@ -325,9 +324,8 @@ void testRingBufSize32( uint8_t data_element[16]; uint8_t data_store[sizeof(data_element) * 32]; - testRingBuf(pTest,data_store,data_element, - sizeof(data_element), - sizeof(data_store)/sizeof(data_element)); + testRingBuf(pTest, data_store, data_element, sizeof(data_element), + sizeof(data_store) / sizeof(data_element)); } diff --git a/bacnet-stack/src/tsm.c b/bacnet-stack/src/tsm.c index 9de55fd8..8b2c0047 100644 --- a/bacnet-stack/src/tsm.c +++ b/bacnet-stack/src/tsm.c @@ -133,12 +133,13 @@ uint8_t tsm_transaction_idle_count( /* sets the invokeID */ -void tsm_invokeID_set(uint8_t invokeID) +void tsm_invokeID_set( + uint8_t invokeID) { - if(invokeID == 0) { - invokeID = 1; - } - Current_Invoke_ID=invokeID; + if (invokeID == 0) { + invokeID = 1; + } + Current_Invoke_ID = invokeID; } /* gets the next free invokeID,